Example usage for org.dom4j Element nodeIterator

List of usage examples for org.dom4j Element nodeIterator

Introduction

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

Prototype

Iterator<Node> nodeIterator();

Source Link

Document

Returns an iterator through the content nodes of this branch

Usage

From source file:org.springfield.lou.application.ApplicationManager.java

License:Open Source License

private void readJumpersForApp(String filename) {
    //      System.out.println("SCANPATH="+filename);
    //      String filename = basepath+File.separator+"apps"+File.separator+part+File.separator+"components"+File.separator+"app.xml";
    File file = new File(filename);
    if (file.exists()) {
        try {/*from   ww  w .j  a  va2 s  .  c  o m*/
            BufferedReader br = new BufferedReader(new FileReader(filename));
            StringBuffer str = new StringBuffer();
            String line = br.readLine();
            while (line != null) {
                str.append(line);
                str.append("\n");
                line = br.readLine();
            }
            br.close();

            String body = str.toString();
            Document result = DocumentHelper.parseText(body);
            for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) {

                Node child = (Node) iter.next();
                //System.out.println("C="+child.getName());
                if (child.getName() != null && child.getName().equals("jumper")) {
                    Element model = (Element) child;
                    String sid = model.attributeValue("id");

                    //FsNode modelnode = new FsNode("model",modelid);
                    for (Iterator<Node> iter2 = model.nodeIterator(); iter2.hasNext();) {
                        Node child2 = (Node) iter2.next();
                        String id = child2.getName();
                        if (id != null) {
                            //System.out.println("JUMPER="+sid+" "+id+" "+child2.getText());
                            LouServlet.addUrlTrigger(sid + "," + child2.getText(), "newscreen");

                        }
                    }
                    //   putNode("/app/component",modelnode);
                    //   System.out.println("MIDELNODE="+modelnode.asXML());
                } else if (child.getName() != null && child.getName().equals("jumpers")) {
                    Element model = (Element) child;
                    String sid = model.attributeValue("id");

                    //FsNode modelnode = new FsNode("model",modelid);
                    for (Iterator<Node> iter2 = model.nodeIterator(); iter2.hasNext();) {
                        Node child2 = (Node) iter2.next();
                        String id = child2.getName();
                        if (id != null) {
                            System.out.println("JUMPERS=" + sid + " " + id + " " + child2.getText());
                            FSList fslist = FSListManager.get(child2.getText(), false);
                            if (fslist != null) {
                                List<FsNode> nodes = fslist.getNodes();
                                if (nodes != null) {
                                    for (Iterator<FsNode> iter3 = nodes.iterator(); iter3.hasNext();) {
                                        FsNode node = (FsNode) iter3.next();
                                        String jumper = node.getId();
                                        String target = node.getProperty("target");
                                        String domain = node.getProperty("domain");
                                        System.out
                                                .println("JUMPER=/lou/" + domain + "/" + jumper + "," + target);
                                        LouServlet.addUrlTrigger("/lou/" + domain + "/" + jumper + "," + target,
                                                "newscreen");

                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

From source file:org.springfield.lou.application.components.types.debugger.Ls.java

License:Open Source License

public static boolean execute(List<String> buffer, String currentpath, String[] params, String[] ignorelist) {
    buffer.add("> dir");
    String xml = "<fsxml><properties><depth>0</depth></properties></fsxml>";
    ServiceInterface smithers = ServiceManager.getService("smithers");
    if (smithers == null) {
        buffer.add("> Error smithers down");
        return false;
    }/*from   w w w  . j av  a  2 s.co m*/
    String nodes = smithers.get(currentpath, xml, "text/xml");
    List<String> dirs = new ArrayList<String>();
    try {
        Document result = DocumentHelper.parseText(nodes);

        for (Iterator<Node> iter = result.getRootElement().nodeIterator(); iter.hasNext();) {
            Element main = (Element) iter.next();
            if (currentpath.endsWith(main.getName() + "/")) {
                String dir = main.attributeValue("id");
                if (!dirs.contains(dir)) {
                    if (!Arrays.asList(ignorelist).contains(dir)) {
                        dirs.add(dir);
                    }
                }
            } else if (currentpath.endsWith("/properties/")) {
                for (Iterator<Node> iter2 = main.nodeIterator(); iter2.hasNext();) {
                    Element child = (Element) iter2.next();
                    if (child.getName().equals("properties")) {
                        for (Iterator<Node> iter3 = child.nodeIterator(); iter3.hasNext();) {
                            Element prop = (Element) iter3.next();
                            String dir = prop.getName();
                            if (!dirs.contains(dir)) {
                                if (!Arrays.asList(ignorelist).contains(dir)) {
                                    dirs.add(dir);
                                }
                            }
                        }
                    }
                }
            } else {
                for (Iterator<Node> iter2 = main.nodeIterator(); iter2.hasNext();) {
                    Element child = (Element) iter2.next();
                    String dir = child.getName();
                    if (!dirs.contains(dir)) {
                        if (!Arrays.asList(ignorelist).contains(dir)) {
                            dirs.add(dir);
                        }
                    }
                }
            }
        }
        // ok loop all the results
        String body = "";
        for (int i = 0; i < dirs.size(); i++) {
            if (dirs.size() < 10) {
                body += dirs.get(i) + " \n";
            } else {
                body += dirs.get(i) + " \t";
            }
        }
        buffer.add(body);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}

From source file:org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobJavaScriptsManager.java

License:Open Source License

protected void removeComments(Element ele) {
    // remove comments.
    Iterator commentIterator = ele.nodeIterator();
    while (commentIterator.hasNext()) {
        Object commentObj = commentIterator.next();
        if (commentObj instanceof Comment) {
            Comment comment = (Comment) commentObj;
            if (comment.getNodeType() == Node.COMMENT_NODE) {
                commentIterator.remove();
            }/*from  w w w .  j a  v  a 2  s  .  co m*/
        }
    }
}

From source file:org.unitime.banner.ant.MergeXml.java

License:Apache License

private void merge(Element target, Element source) {
    for (Iterator i = source.attributeIterator(); i.hasNext();) {
        Attribute attribute = (Attribute) i.next();
        target.addAttribute(attribute.getName(), attribute.getValue());
    }/*w ww  .  j  a  v a2s  . com*/
    for (Iterator i = source.nodeIterator(); i.hasNext();) {
        Node node = (Node) i.next();
        if (node instanceof Element) {
            Element element = (Element) node;
            if ("property".equals(element.getName())) {
                String name = element.attributeValue("name", "noname");
                Element targetProperty = null;
                for (Iterator j = target.elementIterator("property"); j.hasNext();) {
                    Element property = (Element) j.next();
                    if (name.equals(property.attributeValue("name"))) {
                        targetProperty = property;
                        break;
                    }
                }
                if (targetProperty != null) {
                    target.remove(targetProperty);
                }
                if (element.getText() != null && element.getText().trim().length() > 0) {
                    target.addElement("property").addAttribute("name", name).setText(element.getText());
                }
            } else {
                if (target.elements(element.getName()).size() == 1
                        && source.elements(element.getName()).size() == 1)
                    merge(target.element(element.getName()), element);
                else
                    merge(target.addElement(element.getName()), element);
            }
        } else if (node instanceof Comment) {
            Comment comment = (Comment) node;
            target.addComment(comment.getText());
        } else if (node instanceof CDATA) {
            CDATA data = (CDATA) node;
            target.add((CDATA) data.clone());
        } else if (node instanceof Text) {
            Text text = (Text) node;
            if (text.getText() != null && text.getText().trim().length() > 0)
                target.addText(text.getText());
        } else if (node instanceof Namespace) {
        } else {
            log("Unknown node " + node);
        }
    }
}

From source file:org.zenonpagetemplates.onePhaseImpl.PageTemplateImpl.java

License:Open Source License

@SuppressWarnings({ "unchecked" })
private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler,
        EvaluationHelper evaluationHelper, Stack<Map<String, Slot>> slotStack)
        throws SAXException, PageTemplateException, IOException, EvaluationException {
    // Use default template content
    for (Iterator<Node> i = element.nodeIterator(); i.hasNext();) {
        Node node = i.next();//from  www.j  a  va2  s.  co  m
        switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
            processElement((Element) node, contentHandler, lexicalHandler, evaluationHelper, slotStack);
            break;

        case Node.TEXT_NODE:
            char[] text = node.getText().toCharArray();
            contentHandler.characters(text, 0, text.length);
            break;

        case Node.COMMENT_NODE:
            char[] comment = node.getText().toCharArray();
            lexicalHandler.comment(comment, 0, comment.length);
            break;

        case Node.CDATA_SECTION_NODE:
            lexicalHandler.startCDATA();
            char[] cdata = node.getText().toCharArray();
            contentHandler.characters(cdata, 0, cdata.length);
            lexicalHandler.endCDATA();
            break;

        case Node.NAMESPACE_NODE:
            Namespace declared = (Namespace) node;
            //System.err.println( "Declared namespace: " + declared.getPrefix() + ":" + declared.getURI() );
            this.namespaces.put(declared.getPrefix(), declared.getURI());
            //if ( declared.getURI().equals( TAL_NAMESPACE_URI ) ) {
            //    this.talNamespacePrefix = declared.getPrefix();
            //} 
            //else if (declared.getURI().equals( METAL_NAMESPACE_URI ) ) {
            //    this.metalNamespacePrefix = declared.getPrefix();
            //}
            break;

        case Node.ATTRIBUTE_NODE:
            // Already handled
            break;

        case Node.DOCUMENT_TYPE_NODE:
        case Node.ENTITY_REFERENCE_NODE:
        case Node.PROCESSING_INSTRUCTION_NODE:
        default:
            //System.err.println( "WARNING: Node type not supported: " + node.getNodeTypeName() );       
        }
    }
}

From source file:org.zenonpagetemplates.twoPhasesImpl.ZPTDocumentFactory.java

License:Open Source License

@SuppressWarnings({ "unchecked" })
static private void mapContent(Element element, ZPTElement zptElement, ZPTDocument zptDocument,
        Stack<Map<String, Slot>> slotStack) throws SAXException, PageTemplateException, IOException {

    // Use default template content
    for (Iterator<Node> i = element.nodeIterator(); i.hasNext();) {
        Node node = i.next();//from  ww  w.  j a va2  s . co m
        switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
            zptElement.addContent(getNewZPTElement((Element) node, zptDocument, slotStack));
            break;

        case Node.TEXT_NODE:
            zptElement.addContent(new TextNode(node.getText()));
            break;

        case Node.CDATA_SECTION_NODE:
            zptElement.addContent(new CDATANode(node.getText()));
            break;

        case Node.NAMESPACE_NODE: // Already handled
            /*
             Namespace declared = (Namespace)node;
             if (zptDocument.isNamespaceToDeclare(declared)){
                zptDocument.addNamespace(declared);
             } else {
                zptElement.addNamespaceStaticAttribute(declared);
             }
             break;*/

        case Node.ATTRIBUTE_NODE: // Already handled
        case Node.COMMENT_NODE: // Remove all comments
        case Node.DOCUMENT_TYPE_NODE:
        case Node.ENTITY_REFERENCE_NODE:
        case Node.PROCESSING_INSTRUCTION_NODE:
        default:
            // Nothing to do
        }
    }
}

From source file:org.zenonpagetemplates.twoPhasesImpl.ZPTDocumentFactory.java

License:Open Source License

@SuppressWarnings("unchecked")
static private void mapNamespaces(Element element, ZPTElement zptElement, ZPTDocument zptDocument)
        throws PageTemplateException {

    for (Iterator<Attribute> i = element.nodeIterator(); i.hasNext();) {
        Node node = i.next();//  w  w  w  . jav  a  2 s .c o  m
        if (node.getNodeType() == Node.NAMESPACE_NODE) {
            Namespace declared = (Namespace) node;
            if (zptDocument.isNamespaceToDeclare(declared)) {
                zptDocument.addNamespace(declared);
            } else {
                zptElement.addNamespaceStaticAttribute(declared);
            }
        }
    }
}

From source file:org.zenonpagetemplates.twoPhasesImpl.ZPTXMLWriter.java

License:Open Source License

public void writeHTML(Element element) throws IOException {

    for (@SuppressWarnings("unchecked")
    Iterator<Node> i = element.nodeIterator(); i.hasNext();) {
        Node node = (Node) i.next();
        this.write(node);
    }/*from   w  w  w.ja v a2  s.  c  o m*/
}