Java Code Examples for org.jsoup.nodes.Element#classNames()

The following examples show how to use org.jsoup.nodes.Element#classNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Mf2Parser.java    From indigenous-android with GNU General Public License v3.0 5 votes vote down vote up
private JsonList getRootClasses(Element elem) {
    JsonList rootClasses = null;
    for (String className : elem.classNames()) {
        if (isRootClass(className)) {
            if (rootClasses == null) {
                rootClasses = new JsonList();
            }
            rootClasses.add(className);
        }
    }
    return rootClasses;
}
 
Example 2
Source File: Mf2Parser.java    From indigenous-android with GNU General Public License v3.0 5 votes vote down vote up
private boolean hasRootClass(Element elem) {
    for (String className : elem.classNames()) {
        if (isRootClass(className)) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: AbstractMarkerPageRuleImplementation.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * To sort marker elements, we extract for each of them the value of the
 * "id" attribute the value of the "class" attribute and the value of the
 * "role" attribute. If one of these three values belongs to the marker
 * value list set by the user, we consider that the element is characterised
 * and we add it to the "elementMarkerList".
 *
 * @param nodeList
 */
private void sortMarkerElements() {
    if ((CollectionUtils.isEmpty(markerList) && CollectionUtils.isEmpty(inverseMarkerList))
            || selectionWithoutMarkerHandler.isEmpty()) {
        return;
    }
    Iterator<Element> iter = selectionWithoutMarkerHandler.get().iterator();
    Element el;
    while (iter.hasNext()) {
        el = iter.next();
        String id = el.id();
        Collection<String> classNames = el.classNames();
        String role = el.attr(ROLE_ATTR);
        // if the element does contain an "id" OR a "class" attribute OR
        // a "role" attribute AND one the values belongs to the marker list, 
        // it is removed from the global selection and added to the 
        // marker element selection.
        if (StringUtils.isNotBlank(id) || CollectionUtils.isNotEmpty(classNames)
                || StringUtils.isNotBlank(role)) {
            if (checkAttributeBelongsToMarkerList(id, classNames, role, markerList)) {
                selectionWithMarkerHandler.add(el);
                iter.remove();
            }
            // if the element belongs to the inverse marker list, it is
            // removed from the global collection
            if (checkAttributeBelongsToMarkerList(id, classNames, role, inverseMarkerList)) {
                iter.remove();
            }
        }
    }
}
 
Example 4
Source File: Mf2Parser.java    From indigenous-android with GNU General Public License v3.0 4 votes vote down vote up
private void parseProperties(Element elem, URI baseUri, JsonDict itemDict) {
    boolean isProperty = false, isMicroformat = false;

    JsonDict valueObj = null;
    if (hasRootClass(elem)) {
        valueObj = parseMicroformat(elem, baseUri);
        isMicroformat = true;
    }

    for (String className : elem.classNames()) {
        String propName = null;
        Object value = null;
        if (className.startsWith("p-")) {
            propName = className.substring(2);
            value = parseTextProperty(elem);
            isProperty = true;
        }
        else if (className.startsWith("u-")) {
            propName = className.substring(2);
            value = parseUrlProperty(elem, baseUri);
            isProperty = true;
        }

        if (propName != null) {
            if (isMicroformat && valueObj != null) {
                valueObj.put("value", parseChildValue(className, valueObj, value));
                value = valueObj;
            }
            itemDict.getDict("properties").getOrCreateList(propName).add(value);
        }
    }

    if (!isProperty && isMicroformat) {
        itemDict.getOrCreateList("children").add(valueObj);
    }

    if (!isMicroformat) {
        for (Element child : elem.children()) {
            parseProperties(child, baseUri, itemDict);
        }
    }
}