Package org.apache.xerces.dom

Examples of org.apache.xerces.dom.NodeImpl


            super.startElement(qName, xmlAttributes, augmentations);
            setLocation();
        }

        private final void setLocation() {
            NodeImpl node = null;
            try {
                node = (NodeImpl) this.getProperty("http://apache.org/xml/properties/dom/current-element-node");
            } catch (org.xml.sax.SAXException ex) {
                System.err.println("except" + ex);
            }
            if (node != null) {
                String location = locator.getLiteralSystemId() + ":" + locator.getLineNumber() + ":" + locator.getColumnNumber();
                node.setUserData("location", location, null);
            }
        }
View Full Code Here


        }
        if (fCreateEntityRefNodes) {
            if (!fDeferNodeExpansion) {
                if (fDocumentType != null) {
                    NamedNodeMap entities = fDocumentType.getEntities();
                    NodeImpl entity = (NodeImpl)entities.getNamedItem(name);
                    if (entity != null && entity.getFirstChild() == null) {
                        entity.setReadOnly(false, true);
                        Node child = fCurrentNode.getFirstChild();
                        while (child != null) {
                            Node copy = child.cloneNode(true);
                            entity.appendChild(copy);
                            child = child.getNextSibling();
                        }
                        entity.setReadOnly(true, true);
                        entities.setNamedItem(entity);
                    }
                }
                // Make entity ref node read only
                ((NodeImpl)fCurrentNode).setReadOnly(true, true);
View Full Code Here

        Assertion.verify(((NodeImpl) dt).getTextContent() == null);
        // no-ops:
        ((NodeImpl) doc).setTextContent("foo");
        ((NodeImpl) dt).setTextContent("foo");

        NodeImpl el = (NodeImpl) doc.getDocumentElement();
        Assertion.equals(((NodeImpl) el).getTextContent(), "");
        el.setTextContent("yo!");
        Node t = el.getFirstChild();
        Assertion.verify(t != null && t.getNodeType() == Node.TEXT_NODE &&
                         t.getNodeValue().equals("yo!"));
        Assertion.equals(el.getTextContent(), "yo!");

        Comment c = doc.createComment("dummy");
        el.appendChild(c);
       
        NodeImpl el2 = (NodeImpl) doc.createElement("bar");
        el2.setTextContent("bye now");
        el.appendChild(el2);
        Assertion.equals(el.getTextContent(), "yo!bye now");
       
        // check that empty element does not produce null value
    NodeImpl el3 = (NodeImpl) doc.createElement("test");
    el.appendChild(el3);
    NodeImpl empty = (NodeImpl) doc.createElement("empty");
    el3.appendChild(empty);
    Assertion.verify(el3.getTextContent() != null);
   
    empty.setTextContent("hello");
    Assertion.verify(empty.getChildNodes().getLength() == 1);
    // check that setting to empty string or null, does not produce
    // any text node
    empty.setTextContent(null);
    Assertion.verify(empty.getChildNodes().getLength() == 0);
    empty.setTextContent("");
    Assertion.verify(empty.getChildNodes().getLength() == 0);
   
   


        class MyHandler implements UserDataHandler {
            boolean fCalled;
            Node fNode;
            String fKey;
            Object fData;

            MyHandler(String key, Object data, Node node) {
                fCalled = false;
                fKey = key;
                fData = data;
                fNode = node;
            }
            public void handle(short operation, String key,
                               Object data, Node src, Node dst) {
                Assertion.verify(operation == UserDataHandler.NODE_CLONED);
                Assertion.verify(key == fKey && data == fData && src == fNode);
                Assertion.verify(dst != null &&
                                 dst.getNodeType() == fNode.getNodeType());
                fCalled = true;
            }
        }

        el.setUserData("mykey", c, null);
        el.setUserData("mykey2", el2, null);
        Assertion.verify(el.getUserData("mykey") == c);
        Assertion.verify(el.getUserData("mykey2") == el2);
        el.setUserData("mykey", null, null);
        Assertion.verify(el.getUserData("mykey") == null);
        el.setUserData("mykey2", null, null);
        Assertion.verify(el.getUserData("mykey2") == null);
        MyHandler h = new MyHandler("mykey", c, el);
        el.setUserData("mykey", c, h);
        MyHandler h2 = new MyHandler("mykey2", el2, el);
        el.setUserData("mykey2", el2, h2);
        Node cl = el.cloneNode(false);
        Assertion.verify(h.fCalled == true);
        Assertion.verify(h2.fCalled == true);


        el.setTextContent("zapped!");
        Node t2 = el.getFirstChild();
        Assertion.verify(t2.getNodeValue().equals("zapped!"));
        Assertion.verify(t2.getNextSibling() == null);
    }


    //
    // isEqualNode
    // Note: we rely on setTextContent to work properly, in case of errors
    // make sure it is the case first.

    {
        DOMImplementation impl = DOMImplementationImpl.getDOMImplementation();

        Document doc = impl.createDocument(null, "root", null);
        NodeImpl root = (NodeImpl) doc.getDocumentElement();

        NodeImpl n1 = (NodeImpl) doc.createElement("el");
        n1.setTextContent("yo!");

        NodeImpl n2 = (NodeImpl) doc.createElement("el");
        n2.setTextContent("yo!");

        Assertion.verify(n1.isEqualNode(n2) == true);

        n2.setTextContent("yoyo!");
        Assertion.verify(n1.isEqualNode(n2) == false);

        n1.setTextContent("yoyo!");
        ((Element) n1).setAttribute("a1", "v1");
        ((Element) n1).setAttributeNS("uri", "a2", "v2");
        ((Element) n2).setAttribute("a1", "v1");
        ((Element) n2).setAttributeNS("uri", "a2", "v2");
        Assertion.verify(n1.isEqualNode(n2) == true);
       
        Element elem = doc.createElementNS(null, "e2");
        root.appendChild(elem);
        Attr attr = doc.createAttributeNS("http://attr", "attr1");
        elem.setAttributeNode(attr);
       
        // check that setAttribute sets both name and value
        elem.setAttributeNS("http://attr","p:attr1","v2");
        Attr attr2 = elem.getAttributeNodeNS("http://attr", "attr1");
        Assertion.verify(attr2.getNodeName().equals("p:attr1"), "p:attr1");
        Assertion.verify(attr2.getNodeValue().equals("v2"), "value v2");
       
        // check that prefix is not null
        elem.setAttributeNS("http://attr","attr1","v2");
        attr2 = elem.getAttributeNodeNS("http://attr", "attr1");
        Assertion.verify(attr2.getNodeName().equals("attr1"), "attr1");
       

        ((Element) n2).setAttribute("a1", "v2");
        Assertion.verify(n1.isEqualNode(n2) == false);

        root.appendChild(n1);
        root.appendChild(n2);

        NodeImpl clone = (NodeImpl) root.cloneNode(true);
        Assertion.verify(clone.isEqualNode(root) == true);

    }

    System.out.println("done.");
    };
View Full Code Here

            {

                Document doc = builder.parseURI("tests/dom/dom3/input.xml");
                NodeList ls = doc.getElementsByTagName("a:elem_a");

                NodeImpl elem = (NodeImpl)ls.item(0);
                if (namespaces) {
                    //System.out.println("[a:elem_a].lookupPrefix('http://www.example.com', true) == null");
                    Assertion.verify(elem.lookupPrefix("http://www.example.com").equals("ns1"),
                                     "[a:elem_a].lookupPrefix(http://www.example.com)==null");


                    //System.out.println("[a:elem_a].isDefaultNamespace('http://www.example.com') == true");
                    Assertion.verify(elem.isDefaultNamespace("http://www.example.com") == true,
                                     "[a:elem_a].isDefaultNamespace(http://www.example.com)==true");


                    //System.out.println("[a:elem_a].lookupPrefix('http://www.example.com', false) == ns1");
                    Assertion.verify(elem.lookupPrefix("http://www.example.com").equals("ns1"),
                                     "[a:elem_a].lookupPrefix(http://www.example.com)==ns1");


                    Assertion.verify(elem.lookupNamespaceURI("xsi").equals("http://www.w3.org/2001/XMLSchema-instance"),
                                     "[a:elem_a].lookupNamespaceURI('xsi') == 'http://www.w3.org/2001/XMLSchema-instance'" );

                } else {
                    Assertion.verify( elem.lookupPrefix("http://www.example.com") == null,"lookupPrefix(http://www.example.com)==null");
                }

                ls = doc.getElementsByTagName("bar:leaf");
                elem = (NodeImpl)ls.item(0);
                Assertion.verify(elem.lookupPrefix("url1:").equals("foo"),
                                 "[bar:leaf].lookupPrefix('url1:', false) == foo");
                //System.out.println("[bar:leaf].lookupPrefix('url1:', false) == "+ );

                //System.out.println("==>Create b:baz with namespace 'b:' and xmlns:x='b:'");
                ls = doc.getElementsByTagName("baz");
                elem = (NodeImpl)ls.item(0);
                ls = doc.getElementsByTagName("elem8");
                elem = (NodeImpl)ls.item(0);
                Element e1 = doc.createElementNS("b:","p:baz");
                e1.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:x", "b:");
                elem.appendChild(e1);


                Assertion.verify(((NodeImpl)e1).lookupPrefix("b:").equals("p"),
                                 "[p:baz].lookupPrefix('b:', false) == p");



                //System.out.println("[p:baz].lookupPrefix('b:', false) == "+ ((NodeImpl)e1).lookupPrefix("b:",false));

                Assertion.verify(elem.lookupNamespaceURI("xsi").equals("http://www.w3.org/2001/XMLSchema-instance"),
                                 "[bar:leaf].lookupNamespaceURI('xsi') == 'http://www.w3.org/2001/XMLSchema-instance'" );

           
            }
View Full Code Here

        int length      = nl.getLength();

        if ( length == 0 )
            System.out.println(argv[1] + ": is not in the document!");

        NodeImpl node = null;
        for ( int i = 0;i<length;i++ ){
            node                = (NodeImpl) nl.item(i);
            Node childOfElement = node.getFirstChild();
            if ( childOfElement != null ){
                System.out.println( node.getNodeName() + ": " +
                                    childOfElement.getNodeValue() );
            }
        }
        try {
           Writer prettyWriter = new Writer( false );
View Full Code Here

                throw new RuntimeException(
                        "Error: locator is null. Check that you have the" +
                        " correct version of Xerces (such as the one that" +
                        " comes with Cocoon) in your endorsed library path.");
            }
            NodeImpl node = null;
            try {
                node = (NodeImpl)this.getProperty(
                        "http://apache.org/xml/properties/dom/current-element-node");
            } catch (org.xml.sax.SAXException ex) {
                System.err.println("except" + ex);
            }
            if (node != null) {
                Integer[] location = new Integer[] {locator.getLineNumber(), locator.getColumnNumber()};
                node.setUserData("location", location, (UserDataHandler)null);
            }
        }
View Full Code Here

            super.startElement(qName, xmlAttributes, augmentations);
            setLocation();
        }

        private final void setLocation() {
            NodeImpl node = null;
            try {
                node = (NodeImpl) this.getProperty("http://apache.org/xml/properties/dom/current-element-node");
            } catch (org.xml.sax.SAXException ex) {
                System.err.println("except" + ex);
            }
            if (node != null) {
                String location = locator.getLiteralSystemId() + ": line " + locator.getLineNumber();
                node.setUserData("location", location, null);
            }
        }
View Full Code Here

        }
        if (fCreateEntityRefNodes) {
            if (!fDeferNodeExpansion) {
                if (fDocumentType != null) {
                    NamedNodeMap entities = fDocumentType.getEntities();
                    NodeImpl entity = (NodeImpl)entities.getNamedItem(name);
                    if (entity != null && entity.getFirstChild() == null) {
                        entity.setReadOnly(false, true);
                        Node child = fCurrentNode.getFirstChild();
                        while (child != null) {
                            Node copy = child.cloneNode(true);
                            entity.appendChild(copy);
                            child = child.getNextSibling();
                        }
                        entity.setReadOnly(true, true);
                        entities.setNamedItem(entity);
                    }
                }
                // Make entity ref node read only
                ((NodeImpl)fCurrentNode).setReadOnly(true, true);
View Full Code Here


    public Node cloneNode( boolean deep )
    {
        HTMLDocumentImpl    clone;
        NodeImpl            node;

        clone = new HTMLDocumentImpl();
        if ( deep ) {
            node = (NodeImpl) getFirstChild();
            while ( node != null ) {
                clone.appendChild( clone.importNode( node, true ) );
                node = (NodeImpl) node.getNextSibling();
            }
        }
        return clone;
    }
View Full Code Here

TOP

Related Classes of org.apache.xerces.dom.NodeImpl

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.