Package org.apache.excalibur.xml.dom

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


     * @return
     * @throws ProcessingException
     */
    private Document loadDocumentFromSource(Source documentSrc)
        throws ProcessingException {
        DOMParser parser = null;
        try {
            parser =
                (DOMParser) this.serviceManager.lookup(DOMParser.ROLE);
            getLogger().debug(
                "request to load file " + documentSrc.getURI());
            InputSource input = new InputSource(documentSrc.getURI());
            return parser.parseDocument(input);
        } catch (Exception e) {
            throw new ProcessingException(
                "failed to load file to bind to: ",
                e);
        } finally {
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);
                                    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 (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

            }
        sendEndElementEvent(RESULT_ELEMENT);
    }

    private Document newDocument() throws SAXException, ServiceException {
        DOMParser parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
        try {
            return parser.createDocument();
        } finally {
            this.manager.release(parser);
        }
    }
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(list.item(i),
                                               this.filter,
View Full Code Here

   
    public void testCreateDOMHandler()
    {
        try
        {
            final DOMParser parser = (DOMParser)manager.lookup( DOMParser.ROLE );

            final Document document = parser.parseDocument( new InputSource( IN ) );           
           
            final Element root = document.getDocumentElement();
            assertEquals( "Wrong root element", "test:root", root.getNodeName() );
            assertEquals( "Wrong namespace uri", "http://localhost/test", root.getNamespaceURI() );
           
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

    /* (non-Javadoc)
     * @see org.apache.cocoon.components.repository.Repository#getContentDOM(java.lang.String)
     */
    public Document getContentDOM(String uri) throws ProcessingException {

        DOMParser parser = null;

        try {
            parser = (DOMParser)this.manager.lookup( DOMParser.ROLE);
            return parser.parseDocument(new InputSource(this.getContentStream(uri)));

        } catch (SAXException se) {
            throw new ProcessingException ("Error parsing: " + this.repoBaseUrl + uri, se);
        } catch (IOException ioe) {
            throw new ProcessingException ("Error getting: " + this.repoBaseUrl + uri, ioe);
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(list.item(i),
                                               this.filter,
View Full Code Here

                        }
                        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

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.