Example usage for org.jsoup.nodes Element siblingElements

List of usage examples for org.jsoup.nodes Element siblingElements

Introduction

In this page you can find the example usage for org.jsoup.nodes Element siblingElements.

Prototype

public Elements siblingElements() 

Source Link

Document

Get sibling elements.

Usage

From source file:com.kantenkugel.discordbot.jdocparser.JDocParser.java

private static Map<String, String> getInheritedMethods(Element summaryAnchor) {
    Map<String, String> inherited = new HashMap<>();
    if (summaryAnchor == null)
        return inherited;
    summaryAnchor = summaryAnchor.parent();
    Elements inheritAnchors = summaryAnchor.select("a[name^=\"methods.inherited.from.class\"]");
    for (Element inheritAnchor : inheritAnchors) {
        if (inheritAnchor.siblingElements().size() != 2)
            throw new RuntimeException("Got unexpected html while parsing inherited methods from class "
                    + inheritAnchor.attr("name"));
        Element next = inheritAnchor.nextElementSibling();
        if (!next.tagName().equals("h3"))
            throw new RuntimeException("Got unexpected html while parsing inherited methods from class "
                    + inheritAnchor.attr("name"));
        Element sub = next.children().last();
        if (sub == null || !sub.tagName().equals("a"))
            continue;
        String parent = sub.text().toLowerCase();
        next = next.nextElementSibling();
        if (!next.tagName().equals("code"))
            throw new RuntimeException("Got unexpected html while parsing inherited methods from class "
                    + inheritAnchor.attr("name"));
        for (sub = next.children().first(); sub != null; sub = sub.nextElementSibling()) {
            if (sub.tagName().equals("a")) {
                inherited.putIfAbsent(sub.text().toLowerCase(), parent);
            }/*from  w w  w.  j a v  a  2 s  .co m*/
        }
    }
    return inherited;
}

From source file:de.geeksfactory.opacclient.apis.Open.java

@Override
public List<SearchField> getSearchFields() throws IOException, OpacErrorException, JSONException {
    String url = opac_url + "/" + data.getJSONObject("urls").getString("advanced_search") + NO_MOBILE;
    Document doc = Jsoup.parse(httpGet(url, getDefaultEncoding()));

    Element table = doc.select(".ModOPENExtendedSearchModuleC table").first();

    List<SearchField> fields = new ArrayList<>();

    JSONObject selectable = new JSONObject();
    selectable.put("selectable", true);

    JSONObject notSelectable = new JSONObject();
    notSelectable.put("selectable", false);

    // Selectable search criteria
    Elements options = table.select("select[id$=FirstSearchField] option");
    for (Element option : options) {
        TextSearchField field = new TextSearchField();
        field.setId(option.val());
        field.setDisplayName(option.text());
        field.setData(selectable);//from   w  w  w  . jav  a2s .c  o  m
        fields.add(field);
    }

    // More criteria
    Element moreHeader = table.select("span[id$=LblMoreCriterias]").parents().select("tr").first();
    if (moreHeader != null) {
        Elements siblings = moreHeader.siblingElements();
        int startIndex = moreHeader.elementSiblingIndex();
        for (int i = startIndex; i < siblings.size(); i++) {
            Element tr = siblings.get(i);
            if (tr.select("input, select").size() == 0)
                continue;

            if (tr.select("input[type=text]").size() == 1) {
                Element input = tr.select("input[type=text]").first();
                TextSearchField field = new TextSearchField();
                field.setId(input.attr("name"));
                field.setDisplayName(tr.select("span[id*=Lbl]").first().text());
                field.setData(notSelectable);
                if (tr.text().contains("nur Ziffern"))
                    field.setNumber(true);
                fields.add(field);
            } else if (tr.select("input[type=text]").size() == 2) {
                Element input1 = tr.select("input[type=text]").get(0);
                Element input2 = tr.select("input[type=text]").get(1);

                TextSearchField field1 = new TextSearchField();
                field1.setId(input1.attr("name"));
                field1.setDisplayName(tr.select("span[id*=Lbl]").first().text());
                field1.setData(notSelectable);
                if (tr.text().contains("nur Ziffern"))
                    field1.setNumber(true);
                fields.add(field1);

                TextSearchField field2 = new TextSearchField();
                field2.setId(input2.attr("name"));
                field2.setDisplayName(tr.select("span[id*=Lbl]").first().text());
                field2.setData(notSelectable);
                field2.setHalfWidth(true);
                if (tr.text().contains("nur Ziffern"))
                    field2.setNumber(true);
                fields.add(field2);
            } else if (tr.select("select").size() == 1) {
                Element select = tr.select("select").first();
                DropdownSearchField dropdown = new DropdownSearchField();
                dropdown.setId(select.attr("name"));
                dropdown.setDisplayName(tr.select("span[id*=Lbl]").first().text());
                List<DropdownSearchField.Option> values = new ArrayList<>();
                for (Element option : select.select("option")) {
                    DropdownSearchField.Option opt = new DropdownSearchField.Option(option.val(),
                            option.text());
                    values.add(opt);
                }
                dropdown.setDropdownValues(values);
                fields.add(dropdown);
            } else if (tr.select("input[type=checkbox]").size() == 1) {
                Element checkbox = tr.select("input[type=checkbox]").first();
                CheckboxSearchField field = new CheckboxSearchField();
                field.setId(checkbox.attr("name"));
                field.setDisplayName(tr.select("span[id*=Lbl]").first().text());
                fields.add(field);
            }
        }
    }
    return fields;
}

From source file:org.asqatasun.rules.elementselector.CaptchaElementSelector.java

/**
 * //  w  w  w  .java2  s.c o m
 * @param el
 * @return all the parents and the siblings of the element
 */
private Elements getSiblingsAndParents(Element el) {
    Elements siblingsAndParents = new Elements();
    siblingsAndParents.addAll(el.siblingElements());
    siblingsAndParents.addAll(el.parents());
    return siblingsAndParents;
}