Example usage for org.w3c.dom Node getLocalName

List of usage examples for org.w3c.dom Node getLocalName

Introduction

In this page you can find the example usage for org.w3c.dom Node getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:org.deegree.portal.cataloguemanager.control.FullMetadataSetListener.java

private void writePDF(WebEvent event, ResponseHandler responseHandler, XMLFragment resultXML)
        throws IOException {
    Properties p = Messages.getProperties(loc);
    XSLTDocument xsl = null;/*from  w  ww  . j  a v a 2 s . co m*/
    try {
        xsl = new XSLTDocument(config.getPdfXSL());
        XMLFragment xml = xsl.transform(resultXML);
        List<Node> nodes = XMLTools.getNodes(xml.getRootElement(), "./*",
                CommonNamespaces.getNamespaceContext());
        for (Node node : nodes) {
            if (node instanceof Element) {
                String key = node.getLocalName();
                String value = XMLTools.getStringValue(node);
                p.put(key, value);
            }
        }

        JRDataSource ds = new JREmptyDataSource();
        String path = event.getAbsolutePath("./WEB-INF/conf/cataloguemanager/reports/report1.jasper");
        byte[] result = JasperRunManager.runReportToPdf(path, p, ds);
        HttpServletResponse resp = responseHandler.getHttpServletResponse();
        resp.setContentType("application/pdf");
        resp.setContentLength(result.length);
        OutputStream os = resp.getOutputStream();
        os.write(result);
        os.flush();
        os.close();
    } catch (Exception e) {
        LOG.logError(e);
        ExceptionBean bean = new ExceptionBean(this.getClass().getName(), e.getMessage());
        responseHandler.writeAndClose(true, bean);
        return;
    }

}

From source file:org.docx4j.XmlUtils.java

/**
 * Copy a node from one DOM document to another.  Used
 * to avoid relying on an underlying implementation which might 
 * not support importNode /* w ww . ja v  a  2s . c  om*/
 * (eg Xalan's org.apache.xml.dtm.ref.DTMNodeProxy).
 * 
 * WARNING: doesn't fully support namespaces!
 * 
 * @param sourceNode
 * @param destParent
 */
public static void treeCopy(Node sourceNode, Node destParent) {

    // http://osdir.com/ml/text.xml.xerces-j.devel/2004-04/msg00066.html
    // suggests the problem has been fixed?

    // source node maybe org.apache.xml.dtm.ref.DTMNodeProxy
    // (if its xslt output we are copying)
    // or com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl
    // (if its marshalled JAXB)

    log.debug("node type" + sourceNode.getNodeType());

    switch (sourceNode.getNodeType()) {

    case Node.DOCUMENT_NODE: // type 9
    case Node.DOCUMENT_FRAGMENT_NODE: // type 11

        //              log.debug("DOCUMENT:" + w3CDomNodeToString(sourceNode) );
        //              if (sourceNode.getChildNodes().getLength()==0) {
        //                 log.debug("..no children!");
        //              }

        // recurse on each child
        NodeList nodes = sourceNode.getChildNodes();
        if (nodes != null) {
            for (int i = 0; i < nodes.getLength(); i++) {
                log.debug("child " + i + "of DOCUMENT_NODE");
                //treeCopy((DTMNodeProxy)nodes.item(i), destParent);
                treeCopy((Node) nodes.item(i), destParent);
            }
        }
        break;
    case Node.ELEMENT_NODE:

        // Copy of the node itself
        log.debug("copying: " + sourceNode.getNodeName());
        Node newChild;
        if (destParent instanceof Document) {
            newChild = ((Document) destParent).createElementNS(sourceNode.getNamespaceURI(),
                    sourceNode.getLocalName());
        } else if (sourceNode.getNamespaceURI() != null) {
            newChild = destParent.getOwnerDocument().createElementNS(sourceNode.getNamespaceURI(),
                    sourceNode.getLocalName());
        } else {
            newChild = destParent.getOwnerDocument().createElement(sourceNode.getNodeName());
        }
        destParent.appendChild(newChild);

        // .. its attributes
        NamedNodeMap atts = sourceNode.getAttributes();
        for (int i = 0; i < atts.getLength(); i++) {

            Attr attr = (Attr) atts.item(i);

            //                  log.debug("attr.getNodeName(): " + attr.getNodeName());
            //                  log.debug("attr.getNamespaceURI(): " + attr.getNamespaceURI());
            //                  log.debug("attr.getLocalName(): " + attr.getLocalName());
            //                  log.debug("attr.getPrefix(): " + attr.getPrefix());

            if (attr.getNodeName().startsWith("xmlns:")) {
                /* A document created from a dom4j document using dom4j 1.6.1's io.domWriter
                 does this ?!
                 attr.getNodeName(): xmlns:w 
                 attr.getNamespaceURI(): null
                 attr.getLocalName(): null
                 attr.getPrefix(): null
                         
                 unless i'm doing something wrong, this is another reason to
                 remove use of dom4j from docx4j
                */
                ;
                // this is a namespace declaration. not our problem
            } else if (attr.getNamespaceURI() == null) {
                //log.debug("attr.getLocalName(): " + attr.getLocalName() + "=" + attr.getValue());
                ((org.w3c.dom.Element) newChild).setAttribute(attr.getName(), attr.getValue());
            } else if (attr.getNamespaceURI().equals("http://www.w3.org/2000/xmlns/")) {
                ; // this is a namespace declaration. not our problem
            } else if (attr.getNodeName() != null) {
                // && attr.getNodeName().equals("xml:space")) {
                // restrict this fix to xml:space only, if necessary

                // Necessary when invoked from BindingTraverserXSLT,
                // com.sun.org.apache.xerces.internal.dom.AttrNSImpl
                // otherwise it was becoming w:space="preserve"!

                /* eg xml:space
                 * 
                   attr.getNodeName(): xml:space
                   attr.getNamespaceURI(): http://www.w3.org/XML/1998/namespace
                   attr.getLocalName(): space
                   attr.getPrefix(): xml
                 */

                ((org.w3c.dom.Element) newChild).setAttributeNS(attr.getNamespaceURI(), attr.getNodeName(),
                        attr.getValue());
            } else {
                ((org.w3c.dom.Element) newChild).setAttributeNS(attr.getNamespaceURI(), attr.getLocalName(),
                        attr.getValue());
            }
        }

        // recurse on each child
        NodeList children = sourceNode.getChildNodes();
        if (children != null) {
            for (int i = 0; i < children.getLength(); i++) {
                //treeCopy( (DTMNodeProxy)children.item(i), newChild);
                treeCopy((Node) children.item(i), newChild);
            }
        }

        break;

    case Node.TEXT_NODE:

        // Where destParent is com.sun.org.apache.xerces.internal.dom.DocumentImpl,
        // destParent.getOwnerDocument() returns null.
        // #document ; com.sun.org.apache.xerces.internal.dom.DocumentImpl

        //               System.out.println(sourceNode.getNodeValue());

        //System.out.println(destParent.getNodeName() + " ; " + destParent.getClass().getName() );
        if (destParent.getOwnerDocument() == null && destParent.getNodeName().equals("#document")) {
            Node textNode = ((Document) destParent).createTextNode(sourceNode.getNodeValue());
            destParent.appendChild(textNode);
        } else {
            Node textNode = destParent.getOwnerDocument().createTextNode(sourceNode.getNodeValue());
            // Warning: If you attempt to write a single "&" character, it will be converted to &amp; 
            // even if it doesn't look like that with getNodeValue() or getTextContent()!
            // So avoid any tricks with entities! See notes in docx2xhtmlNG2.xslt
            Node appended = destParent.appendChild(textNode);

        }
        break;

    //                case Node.CDATA_SECTION_NODE:
    //                    writer.write("<![CDATA[" +
    //                                 node.getNodeValue() + "]]>");
    //                    break;
    //
    //                case Node.COMMENT_NODE:
    //                    writer.write(indentLevel + "<!-- " +
    //                                 node.getNodeValue() + " -->");
    //                    writer.write(lineSeparator);
    //                    break;
    //
    //                case Node.PROCESSING_INSTRUCTION_NODE:
    //                    writer.write("<?" + node.getNodeName() +
    //                                 " " + node.getNodeValue() +
    //                                 "?>");
    //                    writer.write(lineSeparator);
    //                    break;
    //
    //                case Node.ENTITY_REFERENCE_NODE:
    //                    writer.write("&" + node.getNodeName() + ";");
    //                    break;
    //
    //                case Node.DOCUMENT_TYPE_NODE:
    //                    DocumentType docType = (DocumentType)node;
    //                    writer.write("<!DOCTYPE " + docType.getName());
    //                    if (docType.getPublicId() != null)  {
    //                        System.out.print(" PUBLIC \"" +
    //                            docType.getPublicId() + "\" ");
    //                    } else {
    //                        writer.write(" SYSTEM ");
    //                    }
    //                    writer.write("\"" + docType.getSystemId() + "\">");
    //                    writer.write(lineSeparator);
    //                    break;
    }
}

From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAIntfUtil.java

/**
 * Gets the service version from wsdl./*from   w w w . j  ava 2  s . co m*/
 *
 * @param wsdl the wsdl
 * @param publicServiceName the public service name
 * @return the service version from wsdl
 */
public static String getServiceVersionFromWsdl(Definition wsdl, String publicServiceName) {
    if (wsdl == null) {
        return "";
    }

    for (Object obj : wsdl.getServices().values()) {
        final Service service = (Service) obj;
        if (service.getQName().getLocalPart().equals(publicServiceName)) {
            if (service.getDocumentationElement() != null) {
                final Element elem = service.getDocumentationElement();
                for (int i = 0; i < elem.getChildNodes().getLength(); i++) {
                    Node node = elem.getChildNodes().item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE
                            && (node.getLocalName().equals(ELEM_NAME_VERSION_V2_CAMEL_CASE)
                                    || node.getLocalName().equals(ELEM_NAME_VERSION_V3_CAMEL_CASE))) {
                        if (node.hasChildNodes()) {
                            return node.getFirstChild().getNodeValue();
                        }
                    }
                }
            }
        }
    }

    return "";
}

From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAIntfUtil.java

/**
 * The format should be the following//from w w w  .j a  v a  2s.c o m
 * &lt;wsdl:service name="CreativeService">
 * &lt;wsdl:documentation>
 *    &lt;version>1.0&lt;/version>
 * &lt;/wsdl:documentation>
 * ...
 *
 * @param project the project
 * @param newVersion the new version
 * @param monitor the monitor
 * @throws Exception the exception
 */
public static void modifyWsdlAppInfoVersion(final IProject project, final String newVersion,
        IProgressMonitor monitor) throws Exception {
    monitor.setTaskName("Modifying service WSDL...");
    final String serviceName = project.getName();
    final IFile wsdlFile = SOAServiceUtil.getWsdlFile(project, serviceName);
    InputStream ins = null;
    Definition wsdl = null;
    try {
        ins = wsdlFile.getContents();
        wsdl = WSDLUtil.readWSDL(ins);
    } finally {
        IOUtils.closeQuietly(ins);
    }
    monitor.worked(10);
    if (wsdl == null)
        return;

    DOMParser domParser = new DOMParser();
    Document doc = null;
    try {
        ins = wsdlFile.getContents();
        domParser.parse(new InputSource(ins));
        doc = domParser.getDocument();
    } finally {
        IOUtils.closeQuietly(ins);
    }
    monitor.worked(10);
    if (doc == null)
        return;

    Node wsdlNode = doc.getFirstChild();
    Node serviceNode = null;
    for (int i = wsdlNode.getChildNodes().getLength() - 1; i >= 0; i--) {
        Node node = wsdlNode.getChildNodes().item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE && ELEM_NAME_SERVICE.equals(node.getLocalName())) {
            serviceNode = node;
            break;
        }
    }
    monitor.worked(10);
    if (serviceNode == null)
        return;

    Node documentationNode = null;
    for (int i = 0; i < serviceNode.getChildNodes().getLength(); i++) {
        Node node = serviceNode.getChildNodes().item(i);
        if (ELEM_NAME_DOCUMENTATION.equals(node.getLocalName())) {
            documentationNode = node;
        }
    }
    monitor.worked(10);

    boolean needUpdateWsdl = false;

    if (documentationNode != null) {
        //we found the documentation node
        Node verNode = null;
        for (int i = 0; i < documentationNode.getChildNodes().getLength(); i++) {
            Node node = documentationNode.getChildNodes().item(i);
            if (ELEM_NAME_VERSION_V2_CAMEL_CASE.equals(node.getLocalName())
                    || ELEM_NAME_VERSION_V3_CAMEL_CASE.equals(node.getLocalName())) {
                verNode = node;
                break;
            }
        }

        if (verNode == null) {
            // add version node to document node if there is no version
            // node.
            Element v3Version = doc.createElement("version");
            Text versionText = doc.createTextNode(newVersion);
            v3Version.appendChild(versionText);
            documentationNode.appendChild(v3Version);
            needUpdateWsdl = true;
        } else {
            if (ELEM_NAME_VERSION_V2_CAMEL_CASE.equals(verNode.getLocalName())) {
                // if current version node is V2 format, replace it with V3
                // format
                Element v3Version = doc.createElement("version");
                Text versionText = doc.createTextNode(newVersion);
                v3Version.appendChild(versionText);
                documentationNode.replaceChild(v3Version, verNode);
                needUpdateWsdl = true;
            } else {
                // current version format is V3, update version value.
                for (int i = 0; i < verNode.getChildNodes().getLength(); i++) {
                    Node node = verNode.getChildNodes().item(i);
                    if (node.getNodeType() == Node.TEXT_NODE
                            && newVersion.equals(node.getNodeValue()) == false) {
                        logger.warning("Version defined in WSDL's service section->", node.getNodeValue(),
                                " is older than the new version->", newVersion);
                        node.setNodeValue(newVersion);
                        needUpdateWsdl = true;
                        break;
                    }
                }
            }
        }
    }

    monitor.worked(10);
    if (needUpdateWsdl == true) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(wsdlFile.getLocation().toFile());
            XMLUtil.writeXML(wsdlNode, writer);
        } finally {
            IOUtils.closeQuietly(writer);
            wsdlFile.refreshLocal(IResource.DEPTH_ONE, monitor);
        }
    } else {
        logger.info("WSDL already have the correct version '", newVersion,
                "', skip the modification for WSDL->", wsdlFile.getLocation());
    }
    monitor.worked(10);
}

From source file:org.eclipse.swordfish.internal.core.integration.nmr.SwordfishExchangeListener.java

@SuppressWarnings("unchecked")
private void processOutgoingResponseHeaders(Exchange exchange) {
    Message inMessage = exchange.getIn(false);
    Message outMessage = exchange.getOut(false);

    if (inMessage == null || outMessage == null) {
        LOG.debug("Skip processing of SOAP headers for outgoing response.");
        return;/*from   w ww  . java 2 s.  c o m*/
    }

    Map<QName, DocumentFragment> outHeaders = (Map<QName, DocumentFragment>) outMessage
            .getHeader(JbiConstants.SOAP_HEADERS);
    if (outHeaders == null) {
        outHeaders = new HashMap<QName, DocumentFragment>();
    }

    Map<QName, DocumentFragment> inHeaders = (Map<QName, DocumentFragment>) inMessage
            .getHeader(JbiConstants.SOAP_HEADERS);
    if (inHeaders != null && inHeaders.containsKey(JbiConstants.WSA_REPLY_TO_QNAME)) {
        // include all elements from wsa:ReferenceParameters
        // to SOAP headers of outgoing message
        DocumentFragment replyToFrag = inHeaders.get(JbiConstants.WSA_REPLY_TO_QNAME);
        Node refParams = XPathUtil.getElementByName(replyToFrag, JbiConstants.WSA_REFERENCE_PARAMS_QNAME);
        NodeList params = refParams.getChildNodes();

        for (int i = 0; i < params.getLength(); i++) {
            DocumentFragment fragment = XmlUtil.wrapWithDocumentFragment(params.item(i));
            Node fragmentNode = fragment.getFirstChild();
            QName fragmentName = new QName(fragmentNode.getNamespaceURI(), fragmentNode.getLocalName());
            outHeaders.put(fragmentName, fragment);
        }
    }
    outMessage.setHeader(JbiConstants.SOAP_HEADERS, outHeaders);
}

From source file:org.eclipse.uomo.xml.test.XMLTestCase.java

private String compareAttributes(Element e1, Element e2, String p) {
    NamedNodeMap n1 = e1.getAttributes();
    NamedNodeMap n2 = e2.getAttributes();

    for (int i = 0; i < n1.getLength(); i++) {
        Node a1 = n1.item(0);
        Node a2 = n2.getNamedItemNS(a1.getNamespaceURI(), a1.getLocalName());
        if (a2 == null)
            return "Unable to find attribute " + a1.getNodeName() + " @ " + p;
        if (a1.getNodeValue() != null || a2.getNodeValue() != null) {
            if (a1.getNodeValue() == null || a2.getNodeValue() == null
                    || !a1.getNodeValue().equals(a2.getNodeValue()))
                return "Attribute text differs @ " + p + "/@" + a1.getNodeName() + ": '" + a1.getNodeValue()
                        + "' / '" + a2.getNodeValue() + "'";
        }//  w w  w. j av a  2s  .  c  o  m
    }

    for (int i = 0; i < n2.getLength(); i++) {
        Node a2 = n2.item(0);
        Node a1 = n1.getNamedItemNS(a2.getNamespaceURI(), a2.getLocalName());
        if (a1 == null)
            return "Unable to find attribute " + a2.getNodeName() + " @ " + p;
        if (a1.getNodeValue() != null || a2.getNodeValue() != null) {
            if (a1.getNodeValue() == null || a2.getNodeValue() == null
                    || !a1.getNodeValue().equals(a2.getNodeValue()))
                return "Attribute text differs @ " + p + "/@" + a1.getNodeName() + ": '" + a1.getNodeValue()
                        + "' / '" + a2.getNodeValue() + "'";
        }
    }

    return null;
}

From source file:org.eclipse.winery.common.ModelUtilities.java

/**
 * This is a special method for Winery. Winery allows to define a property by specifying
 * name/value values. Instead of parsing the XML contained in TNodeType, this method is a
 * convenience method to access this information
 * //w w w .  j ava  2  s.  c  o  m
 * The return type "Properties" is used because of the key/value properties.
 * 
 * @param template the node template to get the associated properties
 */
public static Properties getPropertiesKV(TEntityTemplate template) {
    Properties properties = new Properties();
    org.eclipse.winery.model.tosca.TEntityTemplate.Properties tprops = template.getProperties();
    if (tprops != null) {
        // no checking for validity, just reading
        Element el = (Element) tprops.getAny();
        if (el == null) {
            // somehow invalid .tosca. We return empty properties instead of throwing a NPE
            return properties;
        }
        NodeList childNodes = el.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node item = childNodes.item(i);
            if (item instanceof Element) {
                String key = item.getLocalName();
                String value = item.getTextContent();
                properties.put(key, value);
            }
        }
    }
    return properties;
}

From source file:org.eclipse.winery.common.ModelUtilities.java

public static Map<String, String> resolvePropertiesElement(Element propRootElement) {
    Map<String, String> map = new HashMap<String, String>();
    NodeList childList = propRootElement.getChildNodes();
    for (int i = 0; i < childList.getLength(); i++) {
        Node child = childList.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            String propertyName = child.getLocalName();
            String propertyValue = child.getTextContent();
            map.put(propertyName, propertyValue);
        }/*from w  w  w . j a va 2s  .  c o m*/
    }
    return map;
}

From source file:org.exist.dom.ElementImpl.java

private Node appendChild(Txn transaction, NodeId newNodeId, NodeImplRef last, NodePath lastPath, Node child,
        StreamListener listener) throws DOMException {
    if (last == null || last.getNode() == null)
    //TODO : same test as above ? -pb
    {/*from ww  w . j  a  v  a 2 s . co  m*/
        throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "invalid node");
    }
    final DocumentImpl owner = (DocumentImpl) getOwnerDocument();
    DBBroker broker = null;
    try {
        broker = ownerDocument.getBrokerPool().get(null);
        switch (child.getNodeType()) {
        case Node.DOCUMENT_FRAGMENT_NODE:
            appendChildren(transaction, newNodeId, null, last, lastPath, child.getChildNodes(), listener);
            return null; // TODO: implement document fragments so
        //we can return all newly appended children
        case Node.ELEMENT_NODE:
            // create new element
            final ElementImpl elem = new ElementImpl(
                    new QName(child.getLocalName() == null ? child.getNodeName() : child.getLocalName(),
                            child.getNamespaceURI(), child.getPrefix()),
                    broker.getBrokerPool().getSymbols());
            elem.setNodeId(newNodeId);
            elem.setOwnerDocument(owner);
            final NodeListImpl ch = new NodeListImpl();
            final NamedNodeMap attribs = child.getAttributes();
            int numActualAttribs = 0;
            for (int i = 0; i < attribs.getLength(); i++) {
                final Attr attr = (Attr) attribs.item(i);
                if (!attr.getNodeName().startsWith("xmlns")) {
                    ch.add(attr);
                    numActualAttribs++;
                } else {
                    final String xmlnsDecl = attr.getNodeName();
                    final String prefix = xmlnsDecl.length() == 5 ? "" : xmlnsDecl.substring(6);
                    elem.addNamespaceMapping(prefix, attr.getNodeValue());
                }
            }
            final NodeList cl = child.getChildNodes();
            for (int i = 0; i < cl.getLength(); i++) {
                final Node n = cl.item(i);
                if (n.getNodeType() != Node.ATTRIBUTE_NODE) {
                    ch.add(n);
                }
            }
            elem.setChildCount(ch.getLength());
            if (numActualAttribs != (short) numActualAttribs) {
                throw new DOMException(DOMException.INVALID_MODIFICATION_ERR, "Too many attributes");
            }
            elem.setAttributes((short) numActualAttribs);
            lastPath.addComponent(elem.getQName());
            // insert the node
            broker.insertNodeAfter(transaction, last.getNode(), elem);
            broker.indexNode(transaction, elem, lastPath);
            broker.getIndexController().indexNode(transaction, elem, lastPath, listener);
            elem.setChildCount(0);
            last.setNode(elem);
            //process child nodes
            elem.appendChildren(transaction, newNodeId.newChild(), null, last, lastPath, ch, listener);
            broker.endElement(elem, lastPath, null);
            broker.getIndexController().endElement(transaction, elem, lastPath, listener);
            lastPath.removeLastComponent();
            return elem;
        case Node.TEXT_NODE:
            final TextImpl text = new TextImpl(newNodeId, ((Text) child).getData());
            text.setOwnerDocument(owner);
            // insert the node
            broker.insertNodeAfter(transaction, last.getNode(), text);
            broker.indexNode(transaction, text, lastPath);
            broker.getIndexController().indexNode(transaction, text, lastPath, listener);
            last.setNode(text);
            return text;
        case Node.CDATA_SECTION_NODE:
            final CDATASectionImpl cdata = new CDATASectionImpl(newNodeId, ((CDATASection) child).getData());
            cdata.setOwnerDocument(owner);
            // insert the node
            broker.insertNodeAfter(transaction, last.getNode(), cdata);
            broker.indexNode(transaction, cdata, lastPath);
            last.setNode(cdata);
            return cdata;
        case Node.ATTRIBUTE_NODE:
            final Attr attr = (Attr) child;
            final String ns = attr.getNamespaceURI();
            final String prefix = (Namespaces.XML_NS.equals(ns) ? "xml" : attr.getPrefix());
            String name = attr.getLocalName();
            if (name == null) {
                name = attr.getName();
            }
            final QName attrName = new QName(name, ns, prefix);
            final AttrImpl attrib = new AttrImpl(attrName, attr.getValue(),
                    broker.getBrokerPool().getSymbols());
            attrib.setNodeId(newNodeId);
            attrib.setOwnerDocument(owner);
            if (ns != null && attrName.compareTo(Namespaces.XML_ID_QNAME) == Constants.EQUAL) {
                // an xml:id attribute. Normalize the attribute and set its type to ID
                attrib.setValue(StringValue.trimWhitespace(StringValue.collapseWhitespace(attrib.getValue())));
                attrib.setType(AttrImpl.ID);
            } else {
                attrName.setNameType(ElementValue.ATTRIBUTE);
            }
            broker.insertNodeAfter(transaction, last.getNode(), attrib);
            broker.indexNode(transaction, attrib, lastPath);
            broker.getIndexController().indexNode(transaction, attrib, lastPath, listener);
            last.setNode(attrib);
            return attrib;
        case Node.COMMENT_NODE:
            final CommentImpl comment = new CommentImpl(((Comment) child).getData());
            comment.setNodeId(newNodeId);
            comment.setOwnerDocument(owner);
            // insert the node
            broker.insertNodeAfter(transaction, last.getNode(), comment);
            broker.indexNode(transaction, comment, lastPath);
            last.setNode(comment);
            return comment;
        case Node.PROCESSING_INSTRUCTION_NODE:
            final ProcessingInstructionImpl pi = new ProcessingInstructionImpl(newNodeId,
                    ((ProcessingInstruction) child).getTarget(), ((ProcessingInstruction) child).getData());
            pi.setOwnerDocument(owner);
            //insert the node
            broker.insertNodeAfter(transaction, last.getNode(), pi);
            broker.indexNode(transaction, pi, lastPath);
            last.setNode(pi);
            return pi;
        default:
            throw new DOMException(DOMException.INVALID_MODIFICATION_ERR,
                    "Unknown node type: " + child.getNodeType() + " " + child.getNodeName());
        }
    } catch (final EXistException e) {
        LOG.warn("Exception while appending node: " + e.getMessage(), e);
    } finally {
        if (broker != null)
            broker.release();
    }
    return null;
}