use of org.jsoup.nodes.Element in project flow by vaadin.
the class DefaultTemplateParserTest method defaultParser_removesComments.
@Test
public void defaultParser_removesComments() {
Mockito.when(servletContext.getResourceAsStream("/bar.html")).thenReturn(new ByteArrayInputStream("<!-- comment1 --><dom-module id='foo'><!-- comment2 --></dom-module>".getBytes(StandardCharsets.UTF_8)));
Element element = DefaultTemplateParser.getInstance().getTemplateContent(ImportsInspectTemplate.class, "foo").getTemplateElement();
Assert.assertTrue(element.getElementById("foo") != null);
assertThat("No comments should be present in the parsing result", extractCommentNodes(element), is(empty()));
}
use of org.jsoup.nodes.Element in project flow by vaadin.
the class DefaultTemplateParserTest method defaultParser_servletPathIsNotEmpty_returnsContent.
@Test
public void defaultParser_servletPathIsNotEmpty_returnsContent() {
VaadinServletRequest request = (VaadinServletRequest) CurrentInstance.get(VaadinRequest.class);
Mockito.when(resolver.resolveVaadinUri("bar.html")).thenReturn("./../bar.html");
Mockito.when(resolver.resolveVaadinUri("bar1.html")).thenReturn("./../bar1.html");
Mockito.when(request.getServletPath()).thenReturn("/run/");
Mockito.when(servletContext.getResourceAsStream("/run/./../bar.html")).thenReturn(new ByteArrayInputStream("<dom-module id='bar'></dom-module>".getBytes(StandardCharsets.UTF_8)));
Mockito.when(servletContext.getResourceAsStream("/run/./../bar1.html")).thenReturn(new ByteArrayInputStream("<dom-module id='foo'></dom-module>".getBytes(StandardCharsets.UTF_8)));
Element element = DefaultTemplateParser.getInstance().getTemplateContent(ImportsInspectTemplate.class, "foo").getTemplateElement();
Assert.assertTrue(element.getElementById("foo") != null);
}
use of org.jsoup.nodes.Element in project flow by vaadin.
the class DefaultTemplateParserTest method defaultParser_templateWithLeadingSlash_returnsContent.
@Test
public void defaultParser_templateWithLeadingSlash_returnsContent() {
Mockito.when(resolver.resolveVaadinUri("/bar.html")).thenReturn("/foo.html");
Mockito.when(servletContext.getResourceAsStream("/foo.html")).thenReturn(new ByteArrayInputStream("<dom-module id='foo'></dom-module>".getBytes(StandardCharsets.UTF_8)));
Element element = DefaultTemplateParser.getInstance().getTemplateContent(RootImportsInspectTemplate.class, "foo").getTemplateElement();
Assert.assertTrue(element.getElementById("foo") != null);
}
use of org.jsoup.nodes.Element in project flow by vaadin.
the class DefaultTemplateParserTest method defaultParser_servletPathIsEmpty_returnsContent.
@Test
public void defaultParser_servletPathIsEmpty_returnsContent() {
VaadinServletRequest request = (VaadinServletRequest) CurrentInstance.get(VaadinRequest.class);
Mockito.when(request.getServletPath()).thenReturn("");
Element element = DefaultTemplateParser.getInstance().getTemplateContent(ImportsInspectTemplate.class, "foo").getTemplateElement();
Assert.assertTrue(element.getElementById("foo") != null);
}
use of org.jsoup.nodes.Element in project EhViewer by seven332.
the class WhatsHotParser method parse.
@SuppressWarnings("ConstantConditions")
public static List<GalleryInfo> parse(String body) throws ParseException {
try {
List<GalleryInfo> galleryInfoList = new ArrayList<>(15);
Document d = Jsoup.parse(body);
Element pp = d.getElementById("pp");
Elements id1List = pp.getElementsByClass("id1");
for (int i = 0, n = id1List.size(); i < n; i++) {
GalleryInfo galleryInfo = new GalleryInfo();
Element id1 = id1List.get(i);
Element id3 = JsoupUtils.getElementByClass(id1, "id3");
Element temp = JsoupUtils.getElementByTag(id3, "a");
String url = temp.attr("href");
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(url);
galleryInfo.gid = result.gid;
galleryInfo.token = result.token;
temp = JsoupUtils.getElementByTag(temp, "img");
galleryInfo.thumb = EhUtils.handleThumbUrlResolution(temp.attr("src"));
galleryInfo.title = temp.attr("title");
galleryInfo.generateSLang();
galleryInfoList.add(galleryInfo);
}
return galleryInfoList;
} catch (Exception e) {
throw new ParseException("Parse whats hot error", body);
}
}
Aggregations