Search in sources :

Example 76 with Elements

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

the class TemplateParser method getRootElement.

private static Element getRootElement(Document bodyFragment, TemplateResolver templateResolver) {
    Elements children = bodyFragment.body().children();
    int childNodeSize = children.size();
    if (childNodeSize != 1) {
        if (childNodeSize == 0) {
            throw new TemplateParseException("AngularTemplate must not be empty. " + ROOT_CLARIFICATION);
        } else {
            throw new TemplateParseException("AngularTemplate must not have multiple root elements. " + ROOT_CLARIFICATION);
        }
    }
    Element rootElement = children.get(0);
    populateIncludes(rootElement, templateResolver);
    return rootElement;
}
Also used : TemplateParseException(com.vaadin.flow.template.angular.TemplateParseException) Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Example 77 with Elements

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

the class TemplateDataAnalyzer method parseTemplate.

/**
 * Gets the template data for the template initializer.
 *
 * @return the template data
 */
ParserData parseTemplate() {
    TemplateData templateData = parser.getTemplateContent(templateClass, tag);
    templateRoot = templateData.getTemplateElement();
    htmlImportUri = templateData.getHtmlImportUri();
    Elements templates = templateRoot.getElementsByTag("template");
    for (org.jsoup.nodes.Element element : templates) {
        org.jsoup.nodes.Element parent = element.parent();
        if (parent != null && tag.equals(parent.id())) {
            inspectCustomElements(element, element);
            inspectTwoWayBindings(element);
        }
    }
    collectInjectedIds(templateClass);
    return readData();
}
Also used : TemplateData(com.vaadin.flow.component.polymertemplate.TemplateParser.TemplateData) Elements(org.jsoup.select.Elements)

Example 78 with Elements

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

the class TemplateDataAnalyzer method indexOf.

/**
 * Returns the index of the {@code child} in the collection of
 * {@link org.jsoup.nodes.Element} children of the {@code parent} ignoring
 * "style" elements.
 * <p>
 * "style" elements are handled differently depending on ES5/ES6. Also
 * "style" tag can be moved on the top in the resulting client side DOM
 * regardless of its initial position (e.g. Chrome does this).
 *
 * @param parent
 *            the parent of the {@code child}
 * @param child
 *            the child element whose index is calculated
 * @return the index of the {@code child} in the {@code parent}
 */
private static int indexOf(org.jsoup.nodes.Element parent, org.jsoup.nodes.Element child) {
    Elements children = parent.children();
    int index = -1;
    for (org.jsoup.nodes.Element nextChild : children) {
        if (!"style".equals(nextChild.tagName())) {
            index++;
        }
        if (nextChild.equals(child)) {
            break;
        }
    }
    return index;
}
Also used : Elements(org.jsoup.select.Elements)

Example 79 with Elements

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

the class EhEngine method commentGallery.

public static GalleryComment[] commentGallery(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url, String comment) throws Exception {
    FormBody.Builder builder = new FormBody.Builder().add("commenttext_new", comment);
    Log.d(TAG, url);
    Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).post(builder.build()).build();
    Call call = okHttpClient.newCall(request);
    // Put call
    if (null != task) {
        task.setCall(call);
    }
    String body = null;
    Headers headers = null;
    int code = -1;
    try {
        Response response = call.execute();
        code = response.code();
        headers = response.headers();
        body = response.body().string();
        Document document = Jsoup.parse(body);
        Elements elements = document.select("#chd + p");
        if (elements.size() > 0) {
            throw new EhException(elements.get(0).text());
        }
        return GalleryDetailParser.parseComments(document);
    } catch (Exception e) {
        throwException(call, code, headers, body, e);
        throw e;
    }
}
Also used : Call(okhttp3.Call) Headers(okhttp3.Headers) FormBody(okhttp3.FormBody) Request(okhttp3.Request) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) CancelledException(com.hippo.ehviewer.client.exception.CancelledException) NoHAtHClientException(com.hippo.ehviewer.client.exception.NoHAtHClientException) StatusCodeException(com.hippo.network.StatusCodeException) Response(okhttp3.Response) EhException(com.hippo.ehviewer.client.exception.EhException)

Example 80 with Elements

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

the class FavoritesParser method parse.

public static Result parse(String body) throws Exception {
    if (body.contains("This page requires you to log on.</p>")) {
        throw new EhException(GetText.getString(R.string.need_sign_in));
    }
    String[] catArray = new String[10];
    int[] countArray = new int[10];
    try {
        Document d = Jsoup.parse(body);
        Element ido = JsoupUtils.getElementByClass(d, "ido");
        // noinspection ConstantConditions
        Elements fps = ido.getElementsByClass("fp");
        // Last one is "fp fps"
        Assert.assertEquals(11, fps.size());
        for (int i = 0; i < 10; i++) {
            Element fp = fps.get(i);
            countArray[i] = ParserUtils.parseInt(fp.child(0).text());
            catArray[i] = ParserUtils.trim(fp.child(2).text());
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new ParseException("Parse favorites error", body);
    }
    GalleryListParser.Result result = GalleryListParser.parse(body);
    Result re = new Result();
    re.catArray = catArray;
    re.countArray = countArray;
    re.pages = result.pages;
    re.galleryInfoList = result.galleryInfoList;
    return re;
}
Also used : Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException) EhException(com.hippo.ehviewer.client.exception.EhException) ParseException(com.hippo.ehviewer.client.exception.ParseException)

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