Example usage for org.w3c.dom Node appendChild

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

Introduction

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

Prototype

public Node appendChild(Node newChild) throws DOMException;

Source Link

Document

Adds the node newChild to the end of the list of children of this node.

Usage

From source file:org.alfresco.web.config.ConfigRuntime.java

/**
 * @param parent/* w w  w. j  a  va  2  s. com*/
 * @param child
 */
protected void appendChild(Node parent, Node child) {
    parent.appendChild(child);
    Node previousNode = child.getPreviousSibling();
    if (previousNode != null && previousNode instanceof org.w3c.dom.Text) {
        previousNode.getParentNode().removeChild(previousNode);
    }
}

From source file:com.amalto.core.save.context.UpdateReportDocument.java

private MutableDocument setField(String field, String value) {
    if (index++ % 2 == 0) {
        currentNewValue = value;/* ww  w. java 2 s . c  o m*/
    } else {
        Element item = updateReportDocument.createElement("Item"); //$NON-NLS-1$
        {
            // Path
            Node pathNode = updateReportDocument.createElement("path"); //$NON-NLS-1$
            pathNode.appendChild(updateReportDocument.createTextNode(field));
            item.appendChild(pathNode);
            // Old value
            Node oldValueNode = updateReportDocument.createElement("oldValue"); //$NON-NLS-1$
            oldValueNode.appendChild(updateReportDocument.createTextNode(value));
            item.appendChild(oldValueNode);
            // New value
            Node newValueNode = updateReportDocument.createElement("newValue"); //$NON-NLS-1$
            if (currentNewValue != null) {
                newValueNode.appendChild(updateReportDocument.createTextNode(currentNewValue));
            }
            item.appendChild(newValueNode);
        }
        updateReportDocument.getDocumentElement().appendChild(item);
        currentNewValue = null;
    }
    return this;
}

From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java

private void copyParing(Document paring, Node response) throws Exception {
    Node paringElement = response.appendChild(response.getOwnerDocument().createElement("paring"));
    Node kehaNode = response.getOwnerDocument().importNode(paring.getDocumentElement(), true);

    NamedNodeMap attrs = kehaNode.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        paringElement.getAttributes().setNamedItem(attrs.item(i).cloneNode(true));
    }//from   w  w w  .jav a2  s. c  o m

    while (kehaNode.hasChildNodes()) {
        paringElement.appendChild(kehaNode.getFirstChild());
    }
}

From source file:com.photon.phresco.framework.commons.QualityUtil.java

private static void appendCollectionProp(Document document, Node elementProp, String contextType,
        String contextPostData) { // collection append in prop
    String argumentValue = null;//ww  w .ja  v  a 2  s .  co  m
    if (contextType.equals(FrameworkConstants.POST)) {
        argumentValue = contextPostData;
    }
    Node collectionProp = document.createElement("collectionProp");
    NamedNodeMap attributes = collectionProp.getAttributes();
    attributes.setNamedItem(createAttribute(document, "name", "Arguments.arguments"));

    Node subElementProp = document.createElement("elementProp");
    NamedNodeMap subElementAttributes = subElementProp.getAttributes();
    subElementAttributes.setNamedItem(createAttribute(document, "name", ""));
    subElementAttributes.setNamedItem(createAttribute(document, "elementType", "HTTPArgument"));
    collectionProp.appendChild(subElementProp);
    appendTypeProp(document, subElementProp, "boolProp", "HTTPArgument.always_encode", "false");
    appendTypeProp(document, subElementProp, "stringProp", "Argument.value", argumentValue);
    appendTypeProp(document, subElementProp, "stringProp", "Argument.metadata", "=");
    appendTypeProp(document, subElementProp, "boolProp", "HTTPArgument.use_equals", "true");

    elementProp.setTextContent(null);
    elementProp.appendChild(collectionProp);
}

From source file:de.juwimm.cms.util.SmallSiteConfigReader.java

public void saveValue(String xmlPath, String value) {
    String[] pathComponents = xmlPath.split("/");
    String itemTag = pathComponents[pathComponents.length - 1];
    Node parentNode = buildXmlPathToLeaf(xmlPath);
    if (parentNode == null) {
        return;// w  ww  .j  av a  2 s .  c  o m
    }

    if (value == null) {
        return;
    }

    //delete old value
    try {
        Node oldNode = XercesHelper.findNode(parentNode, "//" + itemTag);
        parentNode.removeChild(oldNode);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("SmalSiteConfigReader: old value at path " + xmlPath + " does not exist");
        }
    }
    //create new value
    Document document = this.getConfdoc();
    Node valueNode = document.createElement(itemTag);
    valueNode.appendChild(document.createTextNode(value));
    parentNode.appendChild(valueNode);

}

From source file:de.juwimm.cms.util.SmallSiteConfigReader.java

public void saveValues(String xmlPath, List<String> values) {
    String[] pathComponents = xmlPath.split("/");
    String itemTag = pathComponents[pathComponents.length - 1];
    Node parentNode = buildXmlPathToLeaf(xmlPath);

    if (parentNode == null) {
        return;//w  w  w  . j av  a  2s. com
    }
    //remove old values
    int oldLength = parentNode.getChildNodes().getLength();
    for (int i = 0; i < oldLength; i++) {
        parentNode.removeChild(parentNode.getChildNodes().item(0));
    }

    if (values == null || values.size() == 0) {
        return;
    }

    //save new values
    Document document = this.getConfdoc();
    for (String value : values) {
        Node valueNode = document.createElement(itemTag);
        valueNode.appendChild(document.createTextNode(value));
        parentNode.appendChild(valueNode);
    }
}

From source file:Sax2Dom.java

/**
 * Lexical Handler method to create comment node in DOM tree.
 *///from   ww  w.  j  ava2  s  .  com
public void comment(char[] ch, int start, int length) {
    final Node last = (Node) _nodeStk.peek();
    Comment comment = _document.createComment(new String(ch, start, length));
    if (comment != null)
        last.appendChild(comment);
}

From source file:Sax2Dom.java

/**
 * adds processing instruction node to DOM.
 *///w  w w .j ava  2s. c o m
public void processingInstruction(String target, String data) {
    final Node last = (Node) _nodeStk.peek();
    ProcessingInstruction pi = _document.createProcessingInstruction(target, data);
    if (pi != null)
        last.appendChild(pi);
}

From source file:fi.vrk.xroad.catalog.lister.WsdlCdataInterceptor.java

@Override
public boolean handleResponse(MessageContext messageContext, Object o) throws Exception {

    WebServiceMessage response = messageContext.getResponse();

    SaajSoapMessage saajSoapMessage = (SaajSoapMessage) response;
    SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPBody body = envelope.getBody();
    Iterator responses = body/* w ww .j  a  v a 2  s  . c om*/
            .getChildElements(new QName("http://xroad.vrk.fi/xroad-catalog-lister", "GetWsdlResponse"));
    while (responses.hasNext()) {
        Node wsdlResponse = (Node) responses.next();
        NodeList children = wsdlResponse.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getLocalName().equals("wsdl")) {
                CDATASection cdat = soapPart.createCDATASection(child.getFirstChild().getNodeValue());
                child.removeChild(child.getFirstChild());
                child.appendChild(cdat);
            }
        }
    }
    return true;
}

From source file:de.betterform.xml.dom.DOMUtil.java

/**
 * Moves a child the given index in a nodelist for a given number of steps.
 *
 * @param nodelist the nodelist to work on. if the nodelist is empty, nothing is done
 * @param index    index pointing to the child to move.  if the index is not in the list range nothing is done.
 * @param step     the amount of slots to move the child.  if step is negative the child is moved up (towards the list
 *                 start), if it is positive it is moved down (towards the list end). if the step is zero nothing is done.
 *///  ww w  .j av a 2  s .c om
public static void moveChild(NodeList nodelist, int index, int step) {
    if ((nodelist == null) || (nodelist.getLength() == 0)) {
        return;
    }

    if ((index >= nodelist.getLength()) || (index < 0)) {
        return;
    }

    if (step == 0) {
        return;
    }

    Node parent = nodelist.item(0).getParentNode();
    Node deletedElt = parent.removeChild(nodelist.item(index));

    if ((index + step) == (nodelist.getLength() - 1)) {
        parent.appendChild(deletedElt);
    } else {
        // SURE? it seems that after a removeChild the indices of the nodes
        // in the nodelist seem not to change.  Checking the DOM spec the
        // nodelist is live, but this seems not to be true for index changes
        // is this a bug, or correct?
        // Due to this behaviour the following seperation betweem step forward
        // and backward is necessary.
        if (step < 0) {
            parent.insertBefore(deletedElt, nodelist.item(index + step));
        } else {
            parent.insertBefore(deletedElt, nodelist.item(index + step + 1));
        }
    }
}