Search in sources :

Example 1 with Cursor

use of pl.themolka.arcade.dom.Cursor in project Arcade2 by ShootGame.

the class JDOMEngine method convert.

// 
// Converting
// 
public static Node convert(org.jdom2.Element jdom) {
    List<Element> children = jdom.getChildren();
    Node node = Node.of(JDOMEngine.convert(jdom.getNamespace()), jdom.getName());
    String maybeValue = jdom.getValue();
    if (children.isEmpty() && maybeValue != null) {
        // primitive value
        node.setValue(jdom.getValue());
    } else {
        // children
        List<Node> parsed = new ArrayList<>();
        for (org.jdom2.Element child : children) {
            parsed.add(JDOMEngine.convert(child));
        }
        node.add(parsed);
    }
    // properties
    for (org.jdom2.Attribute attribute : jdom.getAttributes()) {
        node.setProperty(JDOMEngine.convert(attribute));
    }
    // location
    if (jdom instanceof JDOMElement) {
        JDOMElement located = (JDOMElement) jdom;
        Cursor start = located.getStartCursor();
        Cursor end = located.getEndCursor();
        if (start != null && end != null) {
            node.locate(start, end);
        }
    }
    return node;
}
Also used : Element(org.jdom2.Element) Node(pl.themolka.arcade.dom.Node) ArrayList(java.util.ArrayList) Cursor(pl.themolka.arcade.dom.Cursor) Element(org.jdom2.Element)

Aggregations

ArrayList (java.util.ArrayList)1 Element (org.jdom2.Element)1 Cursor (pl.themolka.arcade.dom.Cursor)1 Node (pl.themolka.arcade.dom.Node)1