Package org.apache.excalibur.xml.dom

Examples of org.apache.excalibur.xml.dom.DOMParser


                        }
                        if (replaceNode != null) {
                            if (overwrite == true) {
                                if (parent.getNodeType() == Node.DOCUMENT_NODE) {
                                    // replacing of the document element is not allowed
                                    DOMParser parser = (DOMParser)this.manager.lookup(DOMParser.ROLE);
                                    try {
                                        resource = parser.createDocument();
                                    } finally {
                                        this.manager.release( (Component)parser );
                                    }

                                    resource.appendChild(resource.importNode(importNode, true));
                                    parent = resource;
                                    replaceNode = resource.importNode(replaceNode, true);
                                } else {
                                    parent.replaceChild(importNode, replaceNode);
                                }
                                message += ", replacing: " + replacePath;
                                if (reinsertPath != null) {
                                    Node insertAt = DOMUtil.getSingleNode(parent, reinsertPath);
                                    if (insertAt != null) {
                                        while (replaceNode.hasChildNodes() == true) {
                                            insertAt.appendChild(replaceNode.getFirstChild());
                                        }
                                    } else { // reinsert point null
                                        message = "replace failed, could not find your reinsert path: " + reinsertPath;
                                        resource = null;
                                    }
                                }
                            } else { // overwrite was false
                                message = "replace failed, no overwrite allowed.";
                                resource = null;
                            }
                        } else { // specified replaceNode was not found
                            parent.appendChild(importNode);
                        }
                    } catch (javax.xml.transform.TransformerException sax) {
                        throw new ProcessingException("TransformerException: " + sax, sax);
                    }
                } else { // no replace path, just do an insert at end
                    parent.appendChild(importNode);
                }
            } else if (create == true) {
                DOMParser parser = (DOMParser)this.manager.lookup(DOMParser.ROLE);
                try {
                    resource = parser.createDocument();
                } finally {
                    this.manager.release( (Component)parser );
                }
                // import the fragment
                Node importNode = resource.importNode(fragment, true);
View Full Code Here


            source = this.resolver.resolveURI(src);

            if (!"".equals(select)) {

               
                DOMParser parser = null;
                XPathProcessor processor = null;
               
                try {
                    parser = (DOMParser)this.manager.lookup(DOMParser.ROLE);
                    processor = (XPathProcessor)this.manager.lookup(XPathProcessor.ROLE);

                    InputSource input = SourceUtil.getInputSource(source);

                    Document document = parser.parseDocument(input);
                    NodeList list = processor.selectNodeList(document, select);
                    int length = list.getLength();
                    for (int i=0; i<length; i++) {
                          IncludeXMLConsumer.includeNode((Node)list.item(i),
                                               (ContentHandler)this, 
View Full Code Here

                try {

                    InputSource input = SourceUtil.getInputSource(url);

                    if (suffix.startsWith("xpointer(") && suffix.endsWith(")")) {
                        DOMParser parser = null;
                        try {
                            parser = (DOMParser)manager.lookup(DOMParser.ROLE);
                            String xpath = suffix.substring(9,suffix.length()-1);
                            getLogger().debug("XPath is "+xpath);
                            Document document = parser.parseDocument(input);
                            NodeList list = processor.selectNodeList(document,xpath);
                            DOMStreamer streamer = new DOMStreamer(super.contentHandler,super.lexicalHandler);
                            int length = list.getLength();
                            for (int i=0; i<length; i++) {
                                streamer.stream(list.item(i));
                            }
                        } finally {
                            this.manager.release((Component)parser);
                        }
                    } else {
                        SAXParser parser = null;
                        try {
                            parser = (SAXParser)manager.lookup(SAXParser.ROLE);
                            IncludeXMLConsumer xinclude_handler = new IncludeXMLConsumer(super.contentHandler,super.lexicalHandler);
                            parser.parse(input, xinclude_handler);
                        } finally {
                            this.manager.release((Component)parser);
                        }
                    }
                } catch(SAXException e) {
View Full Code Here

        throws SourceException {

        if ((namespace.equals(propertynamespace)) && (name.equals(propertyname)) &&
            (source.getURI().endsWith(extension))) {

                DOMParser parser = null;
            Document doc = null;
            try {
                parser = (DOMParser)manager.lookup(DOMParser.ROLE);

                doc = parser.parseDocument(new InputSource(source.getInputStream()));
            } catch (SAXException se) {
                this.getLogger().error(source.getURI()
                                        + " is not a valid XML file");
            } catch (IOException ioe) {
                this.getLogger().error("Could not read file", ioe);
View Full Code Here

        StringReader reader = new StringReader(pre+property.getValue().toString()+
                                               post);
        InputSource src = new InputSource(reader);

        DOMParser parser = null;
        Document doc = null;

        try {
            parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
            doc = parser.parseDocument(src);
        } catch (Exception e) {
            throw new SourceException("Could not parse property", e);
        } finally {
            this.manager.release((Component) parser);
        }
View Full Code Here

            return new SourceProperty[0];
        }

        Vector sourceproperties = new Vector();

        DOMParser parser = null;
        String xml = "";

        try {
            parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
            final String quote = "\"";

            for (Enumeration e = revisionDescriptor.enumerateProperties();
                e.hasMoreElements(); ) {
                NodeProperty property = (NodeProperty) e.nextElement();
                String name = property.getName();
                String namespace = property.getNamespace();
                String pre = "<"+name+" xmlns="+quote+namespace+quote+" >";
                String post = "</"+name+" >";

                xml = pre+property.getValue().toString()+post;
                StringReader reader = new StringReader(xml);

                Document doc = parser.parseDocument(new InputSource(reader));

                SourceProperty srcProperty = new SourceProperty(doc.getDocumentElement());

                sourceproperties.addElement(srcProperty);
            }
View Full Code Here

        int length = httpReq.getContentLength();
        PostInputStream reqContent = new PostInputStream(httpReq.getInputStream(), length);

        // construct DOM document from the request contents
        DOMParser parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
        InputSource saxSource = new InputSource(reqContent);
        Document requestDoc = parser.parseDocument(saxSource);

        // get the root element (should be "request") and its attributes ---> FixMe: Add error handling
        Element root = requestDoc.getDocumentElement();
        getLogger().debug(".act(): Root element (should be 'request'): " + root.getTagName());
View Full Code Here

                        }
                        if (replaceNode != null) {
                            if (overwrite) {
                                if (parent.getNodeType() == Node.DOCUMENT_NODE) {
                                    // replacing of the document element is not allowed
                                    DOMParser parser = (DOMParser)this.manager.lookup(DOMParser.ROLE);
                                    try {
                                        resource = parser.createDocument();
                                    } finally {
                                        this.manager.release( parser );
                                    }

                                    resource.appendChild(resource.importNode(importNode, true));
                                    parent = resource;
                                    replaceNode = resource.importNode(replaceNode, true);
                                } else {
                                    parent.replaceChild(importNode, replaceNode);
                                }
                                message += ", replacing: " + replacePath;
                                if (reinsertPath != null) {
                                    Node insertAt = DOMUtil.getSingleNode(parent, reinsertPath, this.xpathProcessor);
                                    if (insertAt != null) {
                                        while (replaceNode.hasChildNodes()) {
                                            insertAt.appendChild(replaceNode.getFirstChild());
                                        }
                                    } else { // reinsert point null
                                        message = "replace failed, could not find your reinsert path: " + reinsertPath;
                                        resource = null;
                                    }
                                }
                            } else { // overwrite was false
                                message = "replace failed, no overwrite allowed.";
                                resource = null;
                            }
                        } else { // specified replaceNode was not found
                            parent.appendChild(importNode);
                        }
                    } catch (javax.xml.transform.TransformerException sax) {
                        throw new ProcessingException("TransformerException: " + sax, sax);
                    }
                } else { // no replace path, just do an insert at end
                    parent.appendChild(importNode);
                }
            } else if (create) {
                DOMParser parser = (DOMParser)this.manager.lookup(DOMParser.ROLE);
                try {
                    resource = parser.createDocument();
                } finally {
                    this.manager.release( parser );
                }
                // import the fragment
                Node importNode = resource.importNode(fragment, true);
View Full Code Here

        if ((namespace.equals(m_namespace)) &&
                (name.equals(m_propertyname)) &&
                (source.getURI().endsWith(m_extension))) {

            DOMParser parser = null;
            Document doc = null;
            try {
                parser = (DOMParser) manager.lookup(DOMParser.ROLE);
                doc = parser.parseDocument(new InputSource(source.getInputStream()));
            } catch (SAXException se) {
                this.getLogger().error(source.getURI() + " is not a valid XML file");
            } catch (IOException ioe) {
                this.getLogger().error("Could not read file", ioe);
            } catch (ServiceException ce) {
View Full Code Here

    public XPathTestCase(String name) {
        super(name);
    }

    public void testXPath() throws Exception {
        DOMParser parser = null;
        XPathProcessor processor = null;
        try {
            parser = (DOMParser)manager.lookup(DOMParser.ROLE);
            processor = (XPathProcessor)manager.lookup(XPathProcessor.ROLE);

            Document document1 = parser.parseDocument(new InputSource(new StringReader(CONTENT1)));
            Document document2 = parser.parseDocument(new InputSource(new StringReader(CONTENT2)));

            // 1. Test single node expression
            String expr = "/test:root/test:element1";
            Node node = processor.selectSingleNode(document1, expr);
            assertNotNull("Must select <test:element1/> node, but got null", node);
View Full Code Here

TOP

Related Classes of org.apache.excalibur.xml.dom.DOMParser

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.