use of org.jsoup.nodes.Element in project LeMondeRssReader by MBach.
the class ArticleActivity method extractComments.
private List<Model> extractComments(Element doc, boolean loadMoreComments) {
List<Model> commentList = new ArrayList<>();
// Extract header
if (!loadMoreComments) {
Elements header = doc.select("[itemprop='InteractionCount']");
if (atLeastOneChild(header)) {
TextView commentHeader = new TextView(getBaseContext());
commentHeader.setText(String.format("Commentaires %s", header.text()));
commentHeader.setTypeface(null, Typeface.BOLD);
commentHeader.setTextColor(Color.WHITE);
commentHeader.setPadding(0, 0, 0, Constants.PADDING_COMMENT_ANSWER);
commentList.add(new Model(commentHeader, 0));
}
}
// Extract comments
Elements comments = doc.select("[itemprop='commentText']");
for (Element comment : comments) {
Elements refs = comment.select("p.references");
if (atLeastOneChild(refs)) {
// Clear date
refs.select("span").remove();
TextView author = new TextView(getBaseContext());
author.setTypeface(null, Typeface.BOLD);
author.setText(refs.text());
author.setTextColor(Color.WHITE);
Elements commentComment = refs.next();
if (atLeastOneChild(commentComment)) {
TextView content = new TextView(getBaseContext());
content.setText(commentComment.first().text());
content.setTextColor(Color.WHITE);
if (comment.hasClass("reponse")) {
author.setPadding(Constants.PADDING_COMMENT_ANSWER, 0, 0, 12);
content.setPadding(Constants.PADDING_COMMENT_ANSWER, 0, 0, 16);
} else {
author.setPadding(0, 0, 0, 12);
content.setPadding(0, 0, 0, 16);
}
Integer commentId = Integer.valueOf(comment.attr("data-reaction_id"));
commentList.add(new Model(author, commentId));
commentList.add(new Model(content, commentId));
}
}
}
// Extract full comments page URI
Elements div = doc.select("div.reactions");
if (atLeastOneChild(div)) {
Element fullComments = div.first().nextElementSibling();
Elements next = fullComments.select("a");
if (atLeastOneChild(next)) {
commentsURI = next.first().attr("href");
}
}
return commentList;
}
use of org.jsoup.nodes.Element in project anton-pavlovich-bot by wyvie.
the class SlovnikCommand method parseHtml.
private List<List<String>> parseHtml(String source) {
List<List<String>> blocks = new ArrayList<>();
Document document = Jsoup.parse(source);
Elements results = document.select("div#results");
// #results > div > h1 - subject itself or nothing have been found message
List<String> headFastDefLine = new ArrayList<>();
headFastDefLine.add(String.format("<b>%s</b>", results.select("h1").text()));
results.select("#fastMeanings a").forEach(element -> {
String hrefNew = BASE_SLOVNIK_URL + element.attr("href");
element = element.attr("href", hrefNew);
headFastDefLine.add(element.toString());
});
// extended grammatics
List<String> extDefs = new ArrayList<>();
results.select("ol li dl").forEach(dl -> {
Element dt = dl.selectFirst("dt");
String def = dt.text();
String aTagsDefs = dt.select("a").stream().map(e -> {
String hrefNew = BASE_SLOVNIK_URL + e.attr("href");
return e.attr("href", hrefNew).toString();
}).collect(Collectors.joining(","));
extDefs.add(String.format("%s %s", aTagsDefs, def));
dl.select("dd").forEach(dd -> {
extDefs.add(dd.wholeText());
});
});
// additional definitions links
List<String> moreDefs = new ArrayList<>();
results.select("ul.moreResults li").forEach(li -> {
Element aTag = li.selectFirst("a");
li.selectFirst("a").remove();
String hrefNew = BASE_SLOVNIK_URL + aTag.attr("href");
aTag = aTag.attr("href", hrefNew);
String liText = li.text();
moreDefs.add(String.format("%s <i>%s</i>", aTag, liText));
});
// synonyms/antonyms
List<String> synDefs = new ArrayList<>();
results.select("div.other-meaning a").forEach(a -> {
String hrefNew = BASE_SLOVNIK_URL + a.attr("href");
synDefs.add(a.attr("href", hrefNew).toString());
});
// additional definitions links
List<String> addDefs = new ArrayList<>();
results.select("#fulltext li").forEach(li -> {
Element aTag = li.selectFirst("a");
li.selectFirst("a").remove();
String hrefNew = BASE_SLOVNIK_URL + aTag.attr("href");
aTag = aTag.attr("href", hrefNew);
String liText = li.text();
addDefs.add(String.format("%s <i>%s</i>", aTag, liText));
});
blocks.add(headFastDefLine);
blocks.add(extDefs);
blocks.add(synDefs);
blocks.add(moreDefs);
blocks.add(addDefs);
return blocks;
}
use of org.jsoup.nodes.Element in project flow by vaadin.
the class BootstrapHandlerTest method no_body_size_or_page_configurator_still_adds_margin_for_body.
// 2344
@Test
public void no_body_size_or_page_configurator_still_adds_margin_for_body() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(RootNavigationTarget.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Elements allElements = page.head().getAllElements();
Optional<Element> styleTag = allElements.stream().filter(element -> element.tagName().equals("style")).findFirst();
Assert.assertTrue("Expected a style element in head.", styleTag.isPresent());
Assert.assertTrue("The first style tag should start with body style containing margin", styleTag.get().toString().startsWith("<style type=\"text/css\">body {margin:0;}"));
}
use of org.jsoup.nodes.Element in project flow by vaadin.
the class BootstrapHandlerTest method es6NotSupported_webcomponentsPolyfillBasePresent_polyfillsLoaded.
@Test
public void es6NotSupported_webcomponentsPolyfillBasePresent_polyfillsLoaded() {
Mockito.when(browser.isEs6Supported()).thenReturn(false);
Element head = initTestUI();
checkInlinedScript(head, "es6-collections.js", true);
checkInlinedScript(head, "babel-helpers.min.js", true);
}
use of org.jsoup.nodes.Element in project flow by vaadin.
the class BootstrapHandler method createInlineJavaScriptElement.
private static Element createInlineJavaScriptElement(String javaScriptContents) {
// defer makes no sense without src:
// https://developer.mozilla.org/en/docs/Web/HTML/Element/script
Element wrapper = createJavaScriptElement(null, false);
wrapper.appendChild(new DataNode(javaScriptContents, wrapper.baseUri()));
return wrapper;
}
Aggregations