Examples of ParentNode


Examples of nu.xom.ParentNode

      try {
        Element elem = (Element) stacks[i].remove(stacks[i].size()-1); // pop
        if (elem == null) {
          continue; // skip element
        }
        ParentNode parent = elem.getParent();
        if (parent == null) throwTamperedWithParent();
        currents[i] = parent; // recurse up
       
        Nodes nodes = receivers[i].finishMakingElement(elem);
        if (nodes.size()==1 && nodes.get(0)==elem) { // same node? (common case)
          if (parent instanceof Document) hasRootElement[i] = true;
          continue; // optimization: no need to remove and then readd same element
        }

        if (parent.getChildCount()-1 < 0) throwTamperedWithParent();       
        if (parent instanceof Element) { // can't remove root element
          parent.removeChild(parent.getChildCount()-1);
        }
        appendNodes(parent, nodes, i);
      } catch (RuntimeException e) {
        onException(i, e);
      }
View Full Code Here

Examples of nu.xom.ParentNode

        private static Document convert(XMLStreamReader streamReader) throws XMLStreamException {
            NodeFactory nodeFactory = new NodeFactory();
            Document document = null;
            Element element = null;
            ParentNode parent = null;
            boolean documentFinished = false;
            while (streamReader.hasNext()) {
                int event = streamReader.next();
                switch (event) {
                    case XMLStreamConstants.START_DOCUMENT:
                        document = nodeFactory.startMakingDocument();
                        parent = document;
                        break;
                    case XMLStreamConstants.END_DOCUMENT:
                        nodeFactory.finishMakingDocument(document);
                        documentFinished = true;
                        break;
                    case XMLStreamConstants.START_ELEMENT:
                        if (document == null) {
                            document = nodeFactory.startMakingDocument();
                            parent = document;
                        }
                        String name = QNameUtils.toQualifiedName(streamReader.getName());
                        if (element == null) {
                            element = nodeFactory.makeRootElement(name, streamReader.getNamespaceURI());
                            document.setRootElement(element);
                        }
                        else {
                            element = nodeFactory.startMakingElement(name, streamReader.getNamespaceURI());
                            parent.appendChild(element);
                        }
                        convertNamespaces(streamReader, element);
                        convertAttributes(streamReader, nodeFactory);
                        parent = element;
                        break;
                    case XMLStreamConstants.END_ELEMENT:
                        nodeFactory.finishMakingElement(element);
                        parent = parent.getParent();
                        break;
                    case XMLStreamConstants.ATTRIBUTE:
                        convertAttributes(streamReader, nodeFactory);
                        break;
                    case XMLStreamConstants.CHARACTERS:
View Full Code Here

Examples of nu.xom.ParentNode

        if (parents.isEmpty()) {
            // won't append until finishMakingElement()
            current = element;
        }
        else {
            ParentNode parent = (ParentNode) parents.get(parents.size()-1);
            parent.appendChild(element);
        }
        parents.add(element);
       
        // Attach the attributes
        length = attributes.getLength();
View Full Code Here

Examples of nu.xom.ParentNode

            }
            current = null;
        }
        else {
            Nodes nodes = factory.finishMakingElement(element);
            ParentNode parent = element.getParent();
            element.detach();
            for (int i = 0; i < nodes.size(); i++) {
                Node node = nodes.get(i);
                if (node instanceof Attribute) {
                    ((Element) parent).addAttribute((Attribute) node);
                }
                else {
                    parent.appendChild(node);
                }
            }
        }

    }
View Full Code Here

Examples of nu.xom.ParentNode

            for (int i = 0; i < nodes.size(); i++) {
                result.append(nodes.get(i));         
            }           
        }
        else {
            ParentNode parent = (ParentNode) parents.get(parents.size()-1);
            for (int i = 0; i < nodes.size(); i++) {
                Node node = nodes.get(i);
                if (node instanceof Attribute) {
                    ((Element) parent).addAttribute((Attribute) node);
                }
                else {
                    parent.appendChild(node);
                }           
            }
        }
       
    }
View Full Code Here

Examples of nu.xom.ParentNode

            if (node.getValue().trim().length() == 0) {
                node.detach();
            }
            else {
                Element dummy = new Element("dummy");
                ParentNode parent = node.getParent();
                parent.insertChild(dummy, parent.indexOf(node));
                node.detach();
                dummy.appendChild(node);
            }
            return;
        }
View Full Code Here

Examples of nu.xom.ParentNode

    public static void processNode(Node current) { 
   
        if (current instanceof Comment
          || current instanceof ProcessingInstruction) {      
            Document document = current.getDocument();
            ParentNode root = document.getRootElement();
            current.detach();
            document.insertChild(current, document.indexOf(root));     
        }
        else {
            for (int i = 0; i < current.getChildCount(); i++) {
View Full Code Here

Examples of nu.xom.ParentNode

   
    private static class AttributeFactory extends NodeFactory {

        public Nodes finishMakingElement(Element element) {
            ParentNode parent = element.getParent();
            if (parent == null || parent instanceof Document) {
                return new Nodes(element);
            }       
            return new Nodes(new Attribute(element.getQualifiedName(),
                    element.getNamespaceURI(), element.getValue()));
View Full Code Here

Examples of nu.xom.ParentNode

   
    public static void strip(Element element) {
       
       if (element.getNamespaceURI().equals(RDDL_NAMESPACE)) {
           
            ParentNode parent = element.getParent();
            int position = 0;
            for (; position < parent.getChildCount(); position++) {
                if (parent.getChild(position) == element) break;
            }
            parent.removeChild(position);
            while (element.getChildCount() > 0) {
                Node child = element.getChild(0);
                element.removeChild(0);
                parent.insertChild(child, position);
                position++;
                if (child instanceof Element) strip((Element) child);
            }    
           
        }
View Full Code Here

Examples of nu.xom.ParentNode

            Document doc = node.getDocument();
            Element pseudoRoot = null;
            if (doc == null) {
                pseudoRoot = new Element("pseudo");
                doc = new Document(pseudoRoot);
                ParentNode root = (ParentNode) node;
                while (root.getParent() != null) root = root.getParent();
                pseudoRoot.appendChild(root);
            }
            try {
                write(node.query(".//. | .//@* | .//namespace::*"));
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.