Package nu.xom

Examples of nu.xom.Node$EmptyNamespaceContext


         public final void write(Document doc) throws IOException {
           
            inScope = new NamespaceSupport();
            int position = 0;       
            while (true) {
                Node child = doc.getChild(position);
                if (nodes == null || child instanceof Element || nodes.contains(child)) {
                    writeChild(child);
                    if (child instanceof ProcessingInstruction) breakLine();
                    else if (child instanceof Comment && withComments) {
                        breakLine();
                    }
                }
                position++;
                if (child instanceof Element) break;
            }      
           
            for (int i = position; i < doc.getChildCount(); i++) {
                Node child = doc.getChild(i);
                if (nodes == null || child instanceof Element || nodes.contains(child)) {
                    if (child instanceof ProcessingInstruction) breakLine();
                    else if (child instanceof Comment && withComments) {
                        breakLine();
                    }
View Full Code Here


            if (element.getChildCount() == 0) {
                writeStartTag(element, false);
                writeEndTag(element);               
            }
            else {
                Node current = element;
                boolean end = false;
                int index = -1;
                int[] indexes = new int[10];
                int top = 0;
                indexes[0] = -1;
                while (true) {                  
                    if (!end && current.getChildCount() > 0) {
                       writeStartTag((Element) current, false);
                       current = current.getChild(0);
                       index = 0;
                       top++;
                       indexes = grow(indexes, top);
                       indexes[top] = 0;
                    }
                    else {
                        if (end) {
                            writeEndTag((Element) current);
                            if (current == element) break;
                        }
                        else {
                            writeChild(current);
                        }
                        end = false;
                        ParentNode parent = current.getParent();
                        if (parent.getChildCount() - 1 == index) {
                            current = parent;
                            top--;
                            if (current != element) {
                                index = indexes[top];
View Full Code Here

                        }
                    }
                }
               
                for (int i = position+1; i < nodes.size(); i++) {
                    Node next = nodes.get(i);
                    if ( !(next instanceof Namespace) ) break;
                    Namespace namespace = (Namespace) next;
                    String prefix = namespace.getPrefix();
                    String uri = namespace.getValue();
                   
View Full Code Here

            Element tr = new Element("tr", XHTML_NAMESPACE);
            Element td = new Element("td", XHTML_NAMESPACE);
            td.addAttribute(new Attribute("colspan", "2"));
            tr.appendChild(td);
            while (element.getChildCount() > 0) {
                Node child = element.getChild(0);
                child.detach();
                td.appendChild(child);
                if (child instanceof Element) convert((Element) child);
            }       
            table.appendChild(tr)
           
View Full Code Here

        // treat empty elements specially to avoid an instance of test
        if (element.getChildCount() == 0) {
            super.writeEmptyElementTag(element);               
        }
        else {
            Node current = element;
            boolean end = false;
            int index = -1;
            while (true) {                  
                if (!end && current.getChildCount() > 0) {
                   writeStartTag((Element) current);
                   current = current.getChild(0);
                   index = 0;
                }
                else {
                    if (end) {
                        writeEndTag((Element) current);
                        if (current == element) break;
                    }
                    else {
                        writeChild(current);
                    }
                    end = false;
                    ParentNode parent = current.getParent();
                    if (parent.getChildCount() - 1 == index) {
                        current = parent;
                        if (current != element) {
                            parent = current.getParent();
                            index = parent.indexOf(current);
                        }
                        end = true;
                    }
                    else {
View Full Code Here

        TreeReporter iterator = new TreeReporter();
        try {
          Builder parser = new Builder();
         
          // Read the entire document into memory
          Node document = parser.build(args[0]);
         
          // Process it starting at the root
          iterator.followNode(document);
   
        }
View Full Code Here

          new File(outputDir, "c2.xml")
        );
        assertEquals(expectedResult, result);
        Element root = result.getRootElement();
        for (int i = 0; i < root.getChildCount(); i++) {
            Node node = root.getChild(i);
            if (node instanceof Text) {
                assertTrue(node instanceof TextSubclass);
            }
        }
       
View Full Code Here

            Document doc = parser.build(systemID);
           
            boolean follow = true;
            boolean index = true;
            for (int i = 0; i < doc.getChildCount(); i++) {
                Node child = doc.getChild(i);
                if (child instanceof Element) break
                if (child instanceof ProcessingInstruction){
                    ProcessingInstruction instruction
                      = (ProcessingInstruction) child;
                    if (instruction.getTarget().equals("robots")) {
View Full Code Here

                        // original document does not contain a fragment ID,
                        // therefore its base URI after inclusion shouldn't,
                        // and this special case is unnecessary. Base URI fixup
                        // should not add the fragment ID.
                        for (int i = 0; i < replacements.size(); i++) {
                            Node child = replacements.get(i);
                            if (child instanceof Element) {
                                String noFragment = child.getBaseURI();
                                if (noFragment.indexOf('#') >= 0) {
                                    noFragment = noFragment.substring(
                                      0, noFragment.indexOf('#'));
                                }
                                Element baseless = (Element) child;
                               
                                // parent is null here; need to get real parent
                                String parentBase = parent.getBaseURI();
                                if (parentBase != null && ! "".equals(parentBase)) {
                                    parentBase = getDirectoryBase(parentBase);
                                }
                               
                                if (noFragment.startsWith(parentBase)) {
                                    noFragment = noFragment.substring(parentBase.length());
                                }
                                Attribute baseAttribute = new Attribute(
                                  "xml:base",
                                  "http://www.w3.org/XML/1998/namespace",
                                  noFragment
                                );
                                baseless.addAttribute(baseAttribute);
                               
                            }
                        } 
                    }
                    else {
                        Document parentDoc = element.getDocument();
                        if (parentDoc == null) {
                            parentDoc = originalDoc;
                        }
                        Nodes originals = XPointer.query(parentDoc, xpointer);
                        replacements = new Nodes();
                        for (int i = 0; i < originals.size(); i++) {
                            Node original = originals.get(i);
                            // current implementation of XPointer never returns non-elements
                            if (contains((Element) original, element)) {
                                throw new InclusionLoopException(
                                  "Element tried to include itself"
                                );
                           
                            Node copy = original.copy();
                            replacements.append(copy);       
                       
                        replacements = resolveXPointerSelection(
                          replacements, builder, baseURLs, parentDoc)
                                                
                    }
                     
                    // Will fail if we're replacing the root element with
                    // a node list containing zero or multiple elements,
                    // but that should fail. However, I may wish to
                    // adjust the type of exception thrown. This is only
                    // relevant if I add support for the xpointer scheme
                    // since otherwise you can only point at one element
                    // or document.
                    if (parent instanceof Element) {
                        int position = parent.indexOf(element);
                        for (int i = 0; i < replacements.size(); i++) {
                            Node child = replacements.get(i);
                            parent.insertChild(child, position+i);
                        }
                        element.detach();
                    }
                    else // root element needs special treatment
                        // I am assuming here that it is not possible
                        // for parent to be null. I think this is true
                        // in the current version, but it could change
                        // if I made it possible to directly resolve an
                        // element or a Nodes.
                        Document doc = (Document) parent;
                        int i = 0;
                        // prolog and root
                        while (true) {
                            Node child = replacements.get(i);
                            i++;
                            if (child instanceof Element) {
                                doc.setRootElement((Element) child);
                                break;  
                            }
                            else {
                                doc.insertChild(
                                  child, doc.indexOf(element)
                                );
                            }

                        }
                        // epilog
                        Element root = doc.getRootElement();
                        int position = doc.indexOf(root);
                        for (int j=i; j < replacements.size(); j++) {
                            doc.insertChild(
                              replacements.get(j), position+1+j-i
                            );                            
                        }
                    }
                }
                else if (parse.equals("text")) {                  
                    Nodes replacements
                      = downloadTextDocument(url, encoding, builder, accept, acceptLanguage);
                    for (int j = 0; j < replacements.size(); j++) {
                        Node replacement = replacements.get(j);
                        if (replacement instanceof Attribute) {
                            ((Element) parent).addAttribute((Attribute) replacement);
                        }
                        else {
                            parent.insertChild(replacement, parent.indexOf(element));
View Full Code Here

                ex2.initCause(ex);
                throw ex2;
           }
            
           while (fallback.getChildCount() > 0) {
                Node child = fallback.getChild(0);
                if (child instanceof Element) {
                    resolve((Element) child, builder, baseURLs);
                }
                child = fallback.getChild(0);
                child.detach();
                parent.insertChild(child, parent.indexOf(includeElement));
           }
           includeElement.detach();
          
    }
View Full Code Here

TOP

Related Classes of nu.xom.Node$EmptyNamespaceContext

Copyright © 2018 www.massapicom. 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.