本文整理汇总了Java中org.jsoup.nodes.Element.before方法的典型用法代码示例。如果您正苦于以下问题:Java Element.before方法的具体用法?Java Element.before怎么用?Java Element.before使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.nodes.Element
的用法示例。
在下文中一共展示了Element.before方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: action
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
public void action(JSONObject data) throws EventException {
final JSONObject article = data.optJSONObject(Article.ARTICLE);
String content = article.optString(Article.ARTICLE_CONTENT);
final Document doc = Jsoup.parse(content, StringUtils.EMPTY, Parser.htmlParser());
doc.outputSettings().prettyPrint(false);
final StringBuilder listBuilder = new StringBuilder();
listBuilder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + Latkes.getStaticServePath()
+ "/plugins/list/style.css\" />");
final Elements hs = doc.select("h1, h2, h3, h4, h5");
listBuilder.append("<ul class='b3-solo-list'>");
for (int i = 0; i < hs.size(); i++) {
final Element element = hs.get(i);
final String tagName = element.tagName().toLowerCase();
final String text = element.text();
final String id = "b3_solo_" + tagName + "_" + i;
element.before("<span id='" + id + "'></span>");
listBuilder.append("<li class='b3-solo-list-").append(tagName).append("'><a href='#").append(id)
.append("'>").append(text).append("</a></li>");
}
listBuilder.append("</ul>");
final Element body = doc.getElementsByTag("body").get(0);
content = listBuilder.toString() + body.html();
article.put(Article.ARTICLE_CONTENT, content);
}
示例2: getUpdatedFileContent
import org.jsoup.nodes.Element; //导入方法依赖的package包/类
private String getUpdatedFileContent(List<Vacancy> vacancies) {
Document document = null;
try {
document = getDocument();
Element templateOriginal = document.getElementsByClass("template").first();
Element copyTemplate = templateOriginal.clone();
copyTemplate.removeAttr("style");
copyTemplate.removeClass("template");
document.select("tr[class=vacancy]").remove().not("tr[class=vacancy template");
for (Vacancy vacancy : vacancies) {
Element localClone = copyTemplate.clone();
localClone.getElementsByClass("city").first().text(vacancy.getCity());
localClone.getElementsByClass("companyName").first().text(vacancy.getCompanyName());
localClone.getElementsByClass("salary").first().text(vacancy.getSalary());
Element link =localClone.getElementsByTag("a").first();
link.text(vacancy.getTitle());
link.attr("href", vacancy.getUrl());
templateOriginal.before(localClone.outerHtml());
}
} catch (IOException e) {
e.printStackTrace();
return "Some exception occurred";
}
return document.html();
}