Commit 516ff331 authored by yihua.huang's avatar yihua.huang

add failfast

parent 7ee567b8
......@@ -13,6 +13,8 @@ import java.lang.annotation.Target;
@Target({ElementType.FIELD})
public @interface ExtractBy {
//TODO: add list support
String value();
public enum Type {XPath, Regex, Css};
......
......@@ -42,6 +42,9 @@ class PageModelExtractor {
fieldExtractors = new ArrayList<FieldExtractor>();
for (Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
if (!field.getType().isAssignableFrom(String.class)){
throw new IllegalStateException("Field "+field.getName()+" must be string");
}
ExtractBy extractBy = field.getAnnotation(ExtractBy.class);
if (extractBy != null) {
String value = extractBy.value();
......
......@@ -14,7 +14,7 @@ import us.codecraft.webmagic.annotation.TargetUrl;
public class IteyeBlog implements Blog{
@ExtractBy("//title")
private String title;
private int title;
@ExtractBy(value = "div#blog_content",type = ExtractBy.Type.Css)
private String content;
......@@ -32,7 +32,7 @@ public class IteyeBlog implements Blog{
}
public String getTitle() {
return title;
return null;
}
public String getContent() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment