Search in sources :

Example 86 with Elements

use of org.jsoup.select.Elements in project EhViewer by seven332.

the class GalleryDetailParser method parseComments.

/**
 * Parse comments with html parser
 */
@NonNull
public static GalleryComment[] parseComments(Document document) {
    try {
        Element cdiv = document.getElementById("cdiv");
        Elements c1s = cdiv.getElementsByClass("c1");
        List<GalleryComment> list = new ArrayList<>(c1s.size());
        for (int i = 0, n = c1s.size(); i < n; i++) {
            GalleryComment comment = parseComment(c1s.get(i));
            if (null != comment) {
                list.add(comment);
            }
        }
        return list.toArray(new GalleryComment[list.size()]);
    } catch (Exception e) {
        e.printStackTrace();
        return EMPTY_GALLERY_COMMENT_ARRAY;
    }
}
Also used : Element(org.jsoup.nodes.Element) GalleryComment(com.hippo.ehviewer.client.data.GalleryComment) ArrayList(java.util.ArrayList) Elements(org.jsoup.select.Elements) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) OffensiveException(com.hippo.ehviewer.client.exception.OffensiveException) PiningException(com.hippo.ehviewer.client.exception.PiningException) NonNull(android.support.annotation.NonNull)

Example 87 with Elements

use of org.jsoup.select.Elements 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)

Example 88 with Elements

use of org.jsoup.select.Elements in project charts by vaadin.

the class ChartDesignReaderTest method readConfiguration_enumValueDefinedInFragment_theSameValueIsInConfiguration.

@Test
public void readConfiguration_enumValueDefinedInFragment_theSameValueIsInConfiguration() {
    Elements elements = createElements("<legend layout=\"vertical\"></legend>");
    Configuration configuration = new Configuration();
    ChartDesignReader.readConfigurationFromElements(elements, configuration);
    assertEquals(LayoutDirection.VERTICAL, configuration.getLegend().getLayout());
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 89 with Elements

use of org.jsoup.select.Elements in project charts by vaadin.

the class ChartDesignReaderTest method readConfiguration_plotOptionsWithReservedTagName_plotOptionsIsAddedToConfiguration.

@Test
public void readConfiguration_plotOptionsWithReservedTagName_plotOptionsIsAddedToConfiguration() {
    Elements elements = createElements("<plot-options><chart-area></chart-area></plot-options>");
    Configuration configuration = new Configuration();
    ChartDesignReader.readConfigurationFromElements(elements, configuration);
    assertEquals(1, configuration.getPlotOptions().size());
    assertThat(configuration.getPlotOptions(ChartType.AREA), instanceOf(PlotOptionsArea.class));
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 90 with Elements

use of org.jsoup.select.Elements in project charts by vaadin.

the class ChartDesignReaderTest method readConfiguration_arrayType_theNewValueIsAddedToArrayInConfiguration.

@Test
public void readConfiguration_arrayType_theNewValueIsAddedToArrayInConfiguration() {
    Elements elements = createElements("<plot-options><treemap><levels level=\"1\"></levels></treemap></plot-options>");
    Configuration configuration = new Configuration();
    ChartDesignReader.readConfigurationFromElements(elements, configuration);
    PlotOptionsTreemap lineOptions = (PlotOptionsTreemap) configuration.getPlotOptions(ChartType.TREEMAP);
    assertEquals(1, lineOptions.getLevels().length);
    assertEquals(1L, lineOptions.getLevels()[0].getLevel());
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsTreemap(com.vaadin.addon.charts.model.PlotOptionsTreemap) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Aggregations

Elements (org.jsoup.select.Elements)709 Element (org.jsoup.nodes.Element)490 Document (org.jsoup.nodes.Document)362 ArrayList (java.util.ArrayList)213 IOException (java.io.IOException)151 Test (org.junit.Test)110 URL (java.net.URL)58 List (java.util.List)47 Matcher (java.util.regex.Matcher)42 Pattern (java.util.regex.Pattern)34 HashMap (java.util.HashMap)30 InputStream (java.io.InputStream)29 Jsoup (org.jsoup.Jsoup)28 Configuration (com.vaadin.addon.charts.model.Configuration)27 File (java.io.File)26 JSONObject (org.json.JSONObject)26 JSONException (org.json.JSONException)25 Collectors (java.util.stream.Collectors)23 URISyntaxException (java.net.URISyntaxException)22 BootstrapContext (com.vaadin.flow.server.BootstrapHandler.BootstrapContext)20