Search in sources :

Example 1 with NodeChild

use of groovy.util.slurpersupport.NodeChild in project groovity by disney.

the class Parse method convert.

@SuppressWarnings({ "rawtypes", "unchecked" })
protected static Object convert(GPathResult node) {
    if (!node.childNodes().hasNext() && (node instanceof NodeChild) && ((NodeChild) node).attributes().isEmpty()) {
        return ((NodeChild) node).localText().stream().collect(Collectors.joining("\n"));
    }
    Map model = new LinkedHashMap<>();
    node.childNodes().forEachRemaining(child -> {
        handleChildNode(model, (Node) child);
    });
    if (node instanceof NodeChild) {
        ((NodeChild) node).attributes().forEach((k, v) -> {
            model.put(k.toString(), v.toString());
        });
        if (!((NodeChild) node).localText().isEmpty()) {
            model.put("text", ((NodeChild) node).localText().stream().collect(Collectors.joining("\n")));
        }
    }
    return model;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NodeChild(groovy.util.slurpersupport.NodeChild) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

NodeChild (groovy.util.slurpersupport.NodeChild)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1