Example usage for org.dom4j Element indexOf

List of usage examples for org.dom4j Element indexOf

Introduction

In this page you can find the example usage for org.dom4j Element indexOf.

Prototype

int indexOf(Node node);

Source Link

Document

Returns the index of the given node if it is a child node of this branch or -1 if the given node is not a child node.

Usage

From source file:com.cladonia.xngreditor.actions.ToolsSortNodeAction.java

License:Open Source License

private Vector treeWalk(Element element, List nodeList, Vector nodes) throws Exception {

    for (int i = 0, size = element.nodeCount(); i < size; i++) {
        Node node = element.node(i);

        //search to see if this node is in the nodelist
        for (int cnt = 0; cnt < nodeList.size(); ++cnt) {
            if (node == (Node) nodeList.get(cnt)) {

                //make sure it doesn't already exist in the nodes vector
                boolean wasFound = false;
                for (int icnt = 0; icnt < nodes.size(); ++icnt) {
                    if (node == ((NodeInfo) nodes.get(icnt)).getNode()) {
                        wasFound = true;
                    }/*  www.  j  a v  a 2 s. c om*/
                }
                if (!wasFound) {
                    //set this to the next id
                    Element parent = node.getParent();
                    int index = parent.indexOf(node);
                    NodeInfo ni = new NodeInfo(originalCounter, parent, node, index);
                    nodes.add(ni);
                    originalCounter++;
                }
            }
        }

        if (node instanceof Element) {
            treeWalk((Element) node, nodeList, nodes);
        }

    }

    return (nodes);
}

From source file:com.globalsight.cxe.adapter.msoffice.WordRepairer.java

License:Apache License

private static void forTextInWp(Element element) {
    @SuppressWarnings("unchecked")
    List<Node> ts = element.selectNodes("//w:p/text()");

    for (Node t : ts) {
        String c = t.getText();/*from   ww  w .  java2s. c o  m*/
        if (c.matches("[\n\r]*")) {
            continue;
        }

        Element wp = t.getParent();
        Element wr = DocumentHelper.createElement("w:r");
        wp.content().add(wp.indexOf(t), wr);
        Element wt = wr.addElement("w:t");
        wt.setText(t.getText());
        wp.remove(t);
    }
}

From source file:com.globalsight.everest.edit.offline.page.TmxUtil.java

License:Apache License

/**
 * Removes the given <sub> element from the segment. <sub> is special since
 * it does not only surround embedded tags but also text, which must be
 * pulled out of the <sub> and added to the parent tag.
 *///ww  w.j  av a 2  s  . c  om
public static void replaceNbsp(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <sub>'s textual
    // content instead of the <sub> (this clears any embedded TMX
    // tags in the subflow).

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.addText("\u00A0");
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.everest.edit.offline.page.TmxUtil.java

License:Apache License

/**
 * Removes the given <sub> element from the segment. <sub> is special since
 * it does not only surround embedded tags but also text, which must be
 * pulled out of the <sub> and added to the parent tag.
 *///from   w  w w. ja  v a  2 s .com
public static void removeSubElement(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <sub>'s textual
    // content instead of the <sub> (this clears any embedded TMX
    // tags in the subflow).

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.addText(p_element.getText());
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.everest.edit.offline.page.TmxUtil.java

License:Apache License

/**
 * Removes the given TMX 1.4 <hi> element from the segment. <hi> is special
 * since it does not surround embedded tags but text, which must be pulled
 * out of the <hi> and added to the parent segment.
 *//* w  ww  .j  a  v a  2  s . co  m*/
private static void removeHiElement(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <hi>'s content
    // instead of the <hi>.

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.appendContent(p_element);
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.everest.projecthandler.ProjectTmTuvT.java

License:Apache License

/**
 * Removes the given TMX 1.4 <hi> element from the segment. <hi> is special
 * since it does not surround embedded tags but text, which must be pulled
 * out of the <hi> and added to the parent segment.
 *//*from w ww.  j a  va2 s  .  co  m*/
private void removeHiElement(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <hi>'s content
    // instead of the <hi>.

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.appendContent(p_element);
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.everest.tm.exporter.TmxWriter.java

License:Apache License

/**
 * Removes the given <sub> element from the segment. <sub> is special since
 * it does not only surround embedded tags but also text, which must be
 * pulled out of the <sub> and added to the parent tag.
 *///from  w ww .j  av  a 2 s  .c  o m
private static void removeSubElement(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <sub>'s textual
    // content instead of the <sub> (this clears any embedded TMX
    // tags in the subflow).

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.addText(p_element.getText());
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.everest.tm.exporter.TmxWriter.java

License:Apache License

/**
 * Removes the given <sub> element from the segment. <sub> is special since
 * it does not only surround embedded tags but also text, which must be
 * pulled out of the <sub> and added to the parent tag.
 *//*from w  ww. j  a  v a2 s. c  o  m*/
private static void replaceNbsp(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <sub>'s textual
    // content instead of the <sub> (this clears any embedded TMX
    // tags in the subflow).

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.addText("\u00A0");
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.everest.tm.importer.TmxReaderThread.java

License:Apache License

/**
 * Removes the given TMX 1.4 <sub> element from the segment. <sub>
 * is special since it does not only surround embedded tags but
 * also text, which must be pulled out of the <sub> and added to
 * the parent tag.//  w ww .  j ava  2 s . c  o m
 */
private void removeSubElement(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <sub>'s textual
    // content instead of the <sub> (this clears any embedded TMX
    // tags in the subflow).

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.addText(p_element.getText());
        } else {
            parent.add(node);
        }
    }
}

From source file:com.globalsight.everest.tm.util.trados.TradosTmxToRtf.java

License:Apache License

/**
 * Removes the given TMX 1.4 <ut> element from the segment. <ut> is special
 * since it does not surround embedded tags but text, witch must be pulled
 * out of the <ut> and added to the parent segment.
 *//*from www  .j a v a2s  .c o m*/
private void removeUtElement(Element p_element) {
    Element parent = p_element.getParent();
    int index = parent.indexOf(p_element);

    // We copy the current content, clear out the parent, and then
    // re-add the old content, inserting the <ut>'s content
    // instead of the <ut>.

    ArrayList newContent = new ArrayList();
    List content = parent.content();

    for (int i = content.size() - 1; i >= 0; --i) {
        Node node = (Node) content.get(i);

        newContent.add(node.detach());
    }

    Collections.reverse(newContent);
    parent.clearContent();

    for (int i = 0, max = newContent.size(); i < max; ++i) {
        Node node = (Node) newContent.get(i);

        if (i == index) {
            parent.appendContent(p_element);
        } else {
            parent.add(node);
        }
    }
}