Example usage for org.dom4j Node getParent

List of usage examples for org.dom4j Node getParent

Introduction

In this page you can find the example usage for org.dom4j Node getParent.

Prototype

Element getParent();

Source Link

Document

getParent returns the parent Element if this node supports the parent relationship or null if it is the root element or does not support the parent relationship.

Usage

From source file:org.xwiki.tool.xar.XWikiXMLWriter.java

License:Open Source License

@Override
protected void writeNodeText(Node node) throws IOException {
    if (this.useFormat && node.getText().trim().length() == 0) {
        // Check if parent node contains non text nodes
        boolean containsNonTextNode = false;
        for (Object object : node.getParent().content()) {
            Node objectNode = (Node) object;
            if (objectNode.getNodeType() != Node.TEXT_NODE) {
                containsNonTextNode = true;
                break;
            }// ww  w . ja va  2  s  . co m
        }
        if (containsNonTextNode) {
            // Don't do anything, i.e. don't print the current text node
        } else {
            super.writeNodeText(node);
        }
    } else {
        super.writeNodeText(node);
    }
}

From source file:ru.gelin.fictionbook.reader.models.FBSimpleDocument.java

License:Open Source License

public Element getParagraphElement(int pos) {
    FBSimpleElement element = positionToElement[pos];
    Node node = element.getNode();
    while (fb.isInline(node)) { //find first not inline parent
        node = node.getParent();
    }/* ww w  .  j  a va 2 s.c  o m*/
    return getElement(node);
}

From source file:service.SerTimerHandler.java

License:Open Source License

public static void deleteOldTimer() {
    Element root = getTimerDocument().getRootElement();
    List nodes = SerXPathHandling.getNodes("/timerList/localTimer/stopTime", getTimerDocument());
    boolean edited = false;

    for (int i = 0; i < nodes.size(); i++) {
        Node node = (Node) nodes.get(i);
        long localTimerStop = Long.parseLong(node.getText());
        long now = new GregorianCalendar().getTimeInMillis();

        if (now > localTimerStop) {
            Node localTimer = node.getParent();
            Element repeatId = (Element) localTimer.selectSingleNode("mainTimer/eventRepeatId");
            if (repeatId != null && repeatId.getText().equals("0")) {
                root.remove(localTimer);
                edited = true;// ww  w .j  a  v a2  s . c  om
            }
        }
    }
    if (edited) {
        try {
            SerXMLHandling.saveXMLFile(new File(timerFile), getTimerDocument());
        } catch (IOException e) {
            Logger.getLogger("SerTimerHandler").error(e.getMessage());
        }
    }
}

From source file:service.SerTimerHandler.java

License:Open Source License

/**
 * @param mainTimer//from w w  w  .  j  av a 2s  . c  om
 * @return XML-Timer-Node
 * Sucht anhand des Start-Datums die passende XML-Node
 */
public static Node findTimerNode(BOTimer mainTimer) {
    List nodes = SerXPathHandling.getNodes("/timerList/localTimer/startTime", getTimerDocument());
    long mainTimerStart = mainTimer.getUnformattedStartTime().getTimeInMillis();
    for (int i = 0; i < nodes.size(); i++) {
        Node node = (Node) nodes.get(i);
        long localTimerStart = Long.parseLong(node.getText());
        if (mainTimerStart == localTimerStart) {
            return node.getParent();
        }
    }
    return null;
}

From source file:service.SerTimerHandler.java

License:Open Source License

public static BOTimerList readLocalTimer() {
    BOTimerList list = new BOTimerList();
    Element root = getTimerDocument().getRootElement();
    List nodes = SerXPathHandling.getNodes("/timerList/localTimer/mainTimer", getTimerDocument());

    for (int i = 0; i < nodes.size(); i++) {
        Node mainTimerNode = (Node) nodes.get(i);
        Node localTimerNode = mainTimerNode.getParent();

        BOTimer timer = buildMainTimer(mainTimerNode);
        buildLocalTimer(localTimerNode, new BOLocalTimer(timer));
        list.getRecordTimerList().add(timer);
    }/*w ww.  ja va  2  s  .  com*/
    return list;
}

From source file:treesim.TreeSim.java

private static void preParentOrderFirstDOM(Node n) {
    if (n != null) {
        if (n.getParent() == null) {
            System.out.println("ROOT -- \"" + n.getName() + "\"");

            elementNodes.add(n.getName());
        } else {//from  www . jav a2 s  .c om
            System.out.println("\"" + n.getParent().getName() + "\" -- \"" + n.getName() + "\"");

            elementNodes.add(n.getName());
        }

        for (Object a : ((Element) n).attributes()) {
            System.out.println("\"" + n.getName() + "\" -- \"" + ((Attribute) a).getName() + "  "
                    + ((Attribute) a).getValue() + "\"");

            attributeParentNodes.add(n.getName());
            attributeNodes.add(((Attribute) a).getName());
        }

        if (!n.getText().trim().equals("")) {
            System.out.println("\"" + n.getName() + "\" -- \"" + n.getText().trim() + "\"");

            textNodeConnections.add(n.getName());
        }

        for (Object o : n.selectNodes("child::*")) {
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                preParentOrderFirstDOM((Node) o);
            }
        }
    }
}

From source file:treesim.TreeSim.java

private static void preParentOrderSecondDOM(Node n) {
    if (n != null) {
        if (n.getParent() == null) {
            System.out.println("ROOT -- \"" + n.getName() + "\"");

            elementNodes2.add(n.getName());
        } else {//  w ww  .  j  a  v  a  2  s.  c o m
            System.out.println("\"" + n.getParent().getName() + "\" -- \"" + n.getName() + "\"");

            elementNodes2.add(n.getName());
        }

        for (Object a : ((Element) n).attributes()) {
            System.out.println("\"" + n.getName() + "\" -- \"" + ((Attribute) a).getName() + "  "
                    + ((Attribute) a).getValue() + "\"");

            attributeParentNodes2.add(n.getName());
            attributeNodes2.add(((Attribute) a).getName());
        }

        if (!n.getText().trim().equals("")) {
            System.out.println("\"" + n.getName() + "\" -- \"" + n.getText().trim() + "\"");

            textNodeConnections2.add(n.getName());
        }

        for (Object o : n.selectNodes("child::*")) {
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                preParentOrderSecondDOM((Node) o);
            }
        }
    }
}