com.geccocrawler.gecco.annotation.Text Java Examples

The following examples show how to use com.geccocrawler.gecco.annotation.Text. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HtmlParser.java    From gecco with MIT License 5 votes vote down vote up
public Object $basic(String selector, Field field) throws Exception {
	if (field.isAnnotationPresent(Text.class)) {// @Text
		Text text = field.getAnnotation(Text.class);
		String value = $text(selector, text.own());
		return Conversion.getValue(field.getType(), value);
	} else if (field.isAnnotationPresent(Image.class)) {// @Image
		Image image = field.getAnnotation(Image.class);
		String imageSrc = $image(selector, image.value());
		/*String localPath = DownloadImage.download(image.download(), imageSrc);
		if (StringUtils.isNotEmpty(localPath)) {
			return localPath;
		}*/
		return imageSrc;
	} else if (field.isAnnotationPresent(Href.class)) {// @Href
		Href href = field.getAnnotation(Href.class);
		String url = $href(selector, href.value());
		return url;
	} else if (field.isAnnotationPresent(Attr.class)) {// @Attr
		Attr attr = field.getAnnotation(Attr.class);
		String name = attr.value();
		return Conversion.getValue(field.getType(), $attr(selector, name));
	} else if (field.isAnnotationPresent(Html.class)) {// @Html
		Html html = field.getAnnotation(Html.class);
		return $html(selector, html.outer());
	} else {// @Html
		return $html(selector);
	}
}
 
Example #2
Source File: HtmlParser.java    From gecco with MIT License 5 votes vote down vote up
public List<Object> $basicList(String selector, Field field) throws Exception {
	List<Object> list = new ArrayList<Object>();
	Elements els = $(selector);
	for (Element el : els) {
		if (field.isAnnotationPresent(Text.class)) {// @Text
			Text text = field.getAnnotation(Text.class);
			list.add(Conversion.getValue(field.getType(), $text(el, text.own())));
		} else if (field.isAnnotationPresent(Image.class)) {// @Image
			Image image = field.getAnnotation(Image.class);
			String imageSrc = $image(el, image.value());
			/*String localPath = DownloadImage.download(image.download(), imageSrc);
			if (StringUtils.isNotEmpty(localPath)) {
				list.add(localPath);
			}*/
			list.add(imageSrc);
		} else if (field.isAnnotationPresent(Href.class)) {// @Href
			Href href = field.getAnnotation(Href.class);
			String url = $href(el, href.value());
			list.add(url);
		} else if (field.isAnnotationPresent(Attr.class)) {// @Attr
			Attr attr = field.getAnnotation(Attr.class);
			String name = attr.value();
			list.add(Conversion.getValue(field.getType(), $attr(el, name)));
		} else if (field.isAnnotationPresent(Html.class)) {// @Html
			Html html = field.getAnnotation(Html.class);
			list.add(html.outer() ? el.outerHtml() : el.html());
		} else {// Other
			list.add(el.html());
		}
	}
	return list;
}
 
Example #3
Source File: JavassistDynamicField.java    From gecco with MIT License 5 votes vote down vote up
@Override
public DynamicField text(boolean own) {
       Annotation annot = new Annotation(Text.class.getName(), cpool);
       annot.addMemberValue("own", new BooleanMemberValue(own, cpool));
       attr.addAnnotation(annot);
	return this;
}