Search in sources :

Example 56 with Element

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()));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.jsoup.nodes.Element) Test(org.junit.Test)

Example 57 with Element

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.jsoup.nodes.Element) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) VaadinRequest(com.vaadin.flow.server.VaadinRequest) Test(org.junit.Test)

Example 58 with Element

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.jsoup.nodes.Element) Test(org.junit.Test)

Example 59 with Element

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);
}
Also used : Element(org.jsoup.nodes.Element) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) VaadinRequest(com.vaadin.flow.server.VaadinRequest) Test(org.junit.Test)

Example 60 with Element

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);
    }
}
Also used : Element(org.jsoup.nodes.Element) GalleryInfo(com.hippo.ehviewer.client.data.GalleryInfo) ArrayList(java.util.ArrayList) ParseException(com.hippo.ehviewer.client.exception.ParseException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) ParseException(com.hippo.ehviewer.client.exception.ParseException)

Aggregations

Element (org.jsoup.nodes.Element)1237 Document (org.jsoup.nodes.Document)559 Elements (org.jsoup.select.Elements)529 ArrayList (java.util.ArrayList)316 IOException (java.io.IOException)220 Test (org.junit.Test)144 ElementHandlerImpl (org.asqatasun.ruleimplementation.ElementHandlerImpl)90 File (java.io.File)87 URL (java.net.URL)82 Matcher (java.util.regex.Matcher)73 List (java.util.List)60 HashMap (java.util.HashMap)57 Pattern (java.util.regex.Pattern)54 Node (org.jsoup.nodes.Node)50 TextNode (org.jsoup.nodes.TextNode)48 InputStream (java.io.InputStream)38 JSONException (org.json.JSONException)36 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)35 Map (java.util.Map)34 JSONObject (org.json.JSONObject)34