Example usage for org.jsoup.parser Tag isBlock

List of usage examples for org.jsoup.parser Tag isBlock

Introduction

In this page you can find the example usage for org.jsoup.parser Tag isBlock.

Prototype

boolean isBlock

To view the source code for org.jsoup.parser Tag isBlock.

Click Source Link

Usage

From source file:org.structr.web.common.microformat.MicroformatParser.java

private void recurse(final Element element, final Map<String, Object> values, final int depth) {

    final Tag tag = element.tag();
    final Set<String> classes = element.classNames();
    final String link = element.attr("href");
    final Object content = extractChildContent(element);

    if (!classes.isEmpty()) {

        removeEmpty(classes);//from  w  ww. ja  v  a  2s.c o m

        // toplevel classes define type
        if (tag.isBlock()) {

            if (depth == 0) {

                // store type attribute
                values.put("type", classes);

                for (final Element child : element.children()) {
                    recurse(child, values, depth + 1);
                }

            } else {

                final Map<String, Object> childMap = new LinkedHashMap<>();
                values.put(classes.iterator().next(), childMap);

                if (content != null) {
                    childMap.put("name", content);
                }

                for (final Element child : element.children()) {
                    recurse(child, childMap, depth + 1);
                }
            }

        } else if (tag.isInline()) {

            // extract href and store as URL
            if (classes.contains("url") && StringUtils.isNotBlank(link)) {

                values.put("url", link);
                classes.remove("url");
            }

            if (content != null) {

                for (final String type : classes) {
                    values.put(type, content);
                }
            }

        }
    }
}