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;
}
Aggregations