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.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl.java

/**
 * This method handles converting the DocumentRouteHeaderValue into an XML representation.  The reason we can't just use
 * propertiesToXml like we have elsewhere is because the doc header has a String attached to it that has the XML document
 * content in it.  The default serialization of this will serialize this as a String so we will end up with escaped XML
 * in our output which we won't be able to process with the email stylesheet.  So we need to read the xml content from
 * the document and parse it into a DOM object so it can be appended to our output.
 *///from w w w. j  ava 2 s  .c  o m
protected void addDocumentHeaderXML(Document document, DocumentRouteHeaderValue documentHeader, Node node,
        String elementName) throws Exception {
    Element element = XmlHelper.propertiesToXml(document, documentHeader, elementName);
    // now we need to "fix" the xml document content because it's going to be in there as escaped XML
    Element docContentElement = (Element) element.getElementsByTagName("docContent").item(0);
    String documentContent = docContentElement.getTextContent();

    if (!StringUtils.isBlank(documentContent) && documentContent.startsWith("<")) {
        Document documentContentXML = XmlHelper.readXml(documentContent);
        Element documentContentElement = documentContentXML.getDocumentElement();
        documentContentElement = (Element) document.importNode(documentContentElement, true);

        // remove the old, bad text content
        docContentElement.removeChild(docContentElement.getFirstChild());

        // replace with actual XML
        docContentElement.appendChild(documentContentElement);
    } else {
        // in this case it means that the XML is encrypted, unfortunately, we have no way to decrypt it since
        // the key is stored in the client application.  We will just include the doc content since none of our
        // current IU clients will be using this feature right away

        // remove the old, bad text content
        docContentElement.removeChild(docContentElement.getFirstChild());
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug(XmlJotter.jotNode(element));
    }

    node.appendChild(element);
}

From source file:org.kuali.rice.kns.workflow.attribute.KualiXmlAttributeHelper.java

/**
 * This method overrides the super class and modifies the XML that it operates on to put the name and the title in the place
 * where the super class expects to see them, overwriting the original title in the XML.
 *
 * @see org.kuali.rice.kew.rule.xmlrouting.StandardGenericXMLRuleAttribute#getConfigXML()
 *//*from w  w  w.j  ava 2 s . c om*/

public Element processConfigXML(Element root, String[] xpathExpressionElements) {

    NodeList fields = root.getElementsByTagName("fieldDef");
    Element theTag = null;
    String docContent = "";

    /**
     * This section will check to see if document content has been defined in the configXML for the document type, by running an
     * XPath. If this is an empty list the xpath expression in the fieldDef is used to define the xml document content that is
     * added to the configXML. The xmldocument content is of this form, when in the document configXML. <xmlDocumentContent>
     * <org.kuali.rice.krad.bo.SourceAccountingLine> <amount> <value>%totaldollarAmount%</value> </amount>
     * </org.kuali.rice.krad.bo.SourceAccountingLine> </xmlDocumentContent> This class generates this on the fly, by creating an XML
     * element for each term in the XPath expression. When this doesn't apply XML can be coded in the configXML for the
     * ruleAttribute.
     *
     * @see org.kuali.rice.kew.plugin.attributes.WorkflowAttribute#getDocContent()
     */

    org.w3c.dom.Document xmlDoc = null;
    if (!xmlDocumentContentExists(root)) { // XML Document content is given because the xpath is non standard
        fields = root.getElementsByTagName("fieldDef");
        xmlDoc = root.getOwnerDocument();
    }
    for (int i = 0; i < fields.getLength(); i++) { // loop over each fieldDef
        String name = null;
        if (!xmlDocumentContentExists(root)) {
            theTag = (Element) fields.item(i);

            /*
             * Even though there may be multiple xpath test, for example one for source lines and one for target lines, the
             * xmlDocumentContent only needs one, since it is used for formatting. The first one is arbitrarily selected, since
             * they are virtually equivalent in structure, most of the time.
             */

            List<String> xPathTerms = getXPathTerms(theTag);
            if (xPathTerms.size() != 0) {
                Node iterNode = xmlDoc.createElement("xmlDocumentContent");

                xmlDoc.normalize();

                iterNode.normalize();

                /*
                 * Since this method is run once per attribute and there may be multiple fieldDefs, the first fieldDef is used
                 * to create the configXML.
                 */
                for (int j = 0; j < xPathTerms.size(); j++) {// build the configXML based on the Xpath
                    // TODO - Fix the document content element generation
                    iterNode.appendChild(xmlDoc.createElement(xPathTerms.get(j)));
                    xmlDoc.normalize();

                    iterNode = iterNode.getFirstChild();
                    iterNode.normalize();

                }
                iterNode.setTextContent("%" + xPathTerms.get(xPathTerms.size() - 1) + "%");
                root.appendChild(iterNode);
            }
        }
        theTag = (Element) fields.item(i);
        // check to see if a values finder is being used to set valid values for a field
        NodeList displayTagElements = theTag.getElementsByTagName("display");
        if (displayTagElements.getLength() == 1) {
            Element displayTag = (Element) displayTagElements.item(0);
            List valuesElementsToAdd = new ArrayList();
            for (int w = 0; w < displayTag.getChildNodes().getLength(); w++) {
                Node displayTagChildNode = (Node) displayTag.getChildNodes().item(w);
                if ((displayTagChildNode != null) && ("values".equals(displayTagChildNode.getNodeName()))) {
                    if (displayTagChildNode.getChildNodes().getLength() > 0) {
                        String valuesNodeText = displayTagChildNode.getFirstChild().getNodeValue();
                        String potentialClassName = getPotentialKualiClassName(valuesNodeText,
                                KUALI_VALUES_FINDER_REFERENCE_PREFIX, KUALI_VALUES_FINDER_REFERENCE_SUFFIX);
                        if (StringUtils.isNotBlank(potentialClassName)) {
                            try {
                                Class finderClass = Class.forName((String) potentialClassName);
                                KeyValuesFinder finder = (KeyValuesFinder) finderClass.newInstance();
                                NamedNodeMap valuesNodeAttributes = displayTagChildNode.getAttributes();
                                Node potentialSelectedAttribute = (valuesNodeAttributes != null)
                                        ? valuesNodeAttributes.getNamedItem("selected")
                                        : null;
                                for (Iterator iter = finder.getKeyValues().iterator(); iter.hasNext();) {
                                    KeyValue keyValue = (KeyValue) iter.next();
                                    Element newValuesElement = root.getOwnerDocument().createElement("values");
                                    newValuesElement.appendChild(
                                            root.getOwnerDocument().createTextNode(keyValue.getKey()));
                                    // newValuesElement.setNodeValue(KeyValue.getKey().toString());
                                    newValuesElement.setAttribute("title", keyValue.getValue());
                                    if (potentialSelectedAttribute != null) {
                                        newValuesElement.setAttribute("selected",
                                                potentialSelectedAttribute.getNodeValue());
                                    }
                                    valuesElementsToAdd.add(newValuesElement);
                                }
                            } catch (ClassNotFoundException cnfe) {
                                String errorMessage = "Caught an exception trying to find class '"
                                        + potentialClassName + "'";
                                LOG.error(errorMessage, cnfe);
                                throw new RuntimeException(errorMessage, cnfe);
                            } catch (InstantiationException ie) {
                                String errorMessage = "Caught an exception trying to instantiate class '"
                                        + potentialClassName + "'";
                                LOG.error(errorMessage, ie);
                                throw new RuntimeException(errorMessage, ie);
                            } catch (IllegalAccessException iae) {
                                String errorMessage = "Caught an access exception trying to instantiate class '"
                                        + potentialClassName + "'";
                                LOG.error(errorMessage, iae);
                                throw new RuntimeException(errorMessage, iae);
                            }
                        } else {
                            valuesElementsToAdd.add(displayTagChildNode.cloneNode(true));
                        }
                        displayTag.removeChild(displayTagChildNode);
                    }
                }
            }
            for (Iterator iter = valuesElementsToAdd.iterator(); iter.hasNext();) {
                Element valuesElementToAdd = (Element) iter.next();
                displayTag.appendChild(valuesElementToAdd);
            }
        }
        if ((xpathExpressionElements != null) && (xpathExpressionElements.length > 0)) {
            NodeList fieldEvaluationElements = theTag.getElementsByTagName("fieldEvaluation");
            if (fieldEvaluationElements.getLength() == 1) {
                Element fieldEvaluationTag = (Element) fieldEvaluationElements.item(0);
                List tagsToAdd = new ArrayList();
                for (int w = 0; w < fieldEvaluationTag.getChildNodes().getLength(); w++) {
                    Node fieldEvaluationChildNode = (Node) fieldEvaluationTag.getChildNodes().item(w);
                    Element newTagToAdd = null;
                    if ((fieldEvaluationChildNode != null)
                            && ("xpathexpression".equals(fieldEvaluationChildNode.getNodeName()))) {
                        newTagToAdd = root.getOwnerDocument().createElement("xpathexpression");
                        newTagToAdd.appendChild(root.getOwnerDocument()
                                .createTextNode(generateNewXpathExpression(
                                        fieldEvaluationChildNode.getFirstChild().getNodeValue(),
                                        xpathExpressionElements)));
                        tagsToAdd.add(newTagToAdd);
                        fieldEvaluationTag.removeChild(fieldEvaluationChildNode);
                    }
                }
                for (Iterator iter = tagsToAdd.iterator(); iter.hasNext();) {
                    Element elementToAdd = (Element) iter.next();
                    fieldEvaluationTag.appendChild(elementToAdd);
                }
            }
        }
        theTag.setAttribute("title", getBusinessObjectTitle(theTag));

    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(XmlJotter.jotNode(root));
        StringWriter xmlBuffer = new StringWriter();
        try {

            root.normalize();
            Source source = new DOMSource(root);
            Result result = new StreamResult(xmlBuffer);
            TransformerFactory.newInstance().newTransformer().transform(source, result);
        } catch (Exception e) {
            LOG.debug(" Exception when printing debug XML output " + e);
        }
        LOG.debug(xmlBuffer.getBuffer());
    }

    return root;
}

From source file:org.kuali.rice.krad.devtools.maintainablexml.MaintainableXMLConversionServiceImpl.java

private void transformNode(Document document, Node node, Class<?> currentClass,
        Map<String, String> propertyMappings) throws ClassNotFoundException, XPathExpressionException,
        IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException {
    for (Node childNode = node.getFirstChild(); childNode != null;) {
        Node nextChild = childNode.getNextSibling();
        String propertyName = childNode.getNodeName();
        if (childNode.hasAttributes()) {
            XPath xpath = XPathFactory.newInstance().newXPath();
            Node serializationAttribute = childNode.getAttributes().getNamedItem(SERIALIZATION_ATTRIBUTE);
            if (serializationAttribute != null
                    && StringUtils.equals(serializationAttribute.getNodeValue(), "custom")) {
                Node classAttribute = childNode.getAttributes().getNamedItem(CLASS_ATTRIBUTE);
                if (classAttribute != null && StringUtils.equals(classAttribute.getNodeValue(),
                        "org.kuali.rice.kns.util.TypedArrayList")) {
                    ((Element) childNode).removeAttribute(SERIALIZATION_ATTRIBUTE);
                    ((Element) childNode).removeAttribute(CLASS_ATTRIBUTE);
                    XPathExpression listSizeExpression = xpath.compile("//" + propertyName
                            + "/org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl/default/size/text()");
                    String size = (String) listSizeExpression.evaluate(childNode, XPathConstants.STRING);
                    List<Node> nodesToAdd = new ArrayList<Node>();
                    if (StringUtils.isNotBlank(size) && Integer.valueOf(size) > 0) {
                        XPathExpression listTypeExpression = xpath.compile("//" + propertyName
                                + "/org.kuali.rice.kns.util.TypedArrayList/default/listObjectType/text()");
                        String listType = (String) listTypeExpression.evaluate(childNode,
                                XPathConstants.STRING);
                        XPathExpression listContentsExpression = xpath.compile("//" + propertyName
                                + "/org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl/" + listType);
                        NodeList listContents = (NodeList) listContentsExpression.evaluate(childNode,
                                XPathConstants.NODESET);
                        for (int i = 0; i < listContents.getLength(); i++) {
                            Node tempNode = listContents.item(i);
                            transformClassNode(document, tempNode);
                            nodesToAdd.add(tempNode);
                        }/*from ww w.  j  ava  2s . co  m*/
                    }
                    for (Node removeNode = childNode.getFirstChild(); removeNode != null;) {
                        Node nextRemoveNode = removeNode.getNextSibling();
                        childNode.removeChild(removeNode);
                        removeNode = nextRemoveNode;
                    }
                    for (Node nodeToAdd : nodesToAdd) {
                        childNode.appendChild(nodeToAdd);
                    }
                } else {
                    ((Element) childNode).removeAttribute(SERIALIZATION_ATTRIBUTE);

                    XPathExpression mapContentsExpression = xpath.compile("//" + propertyName + "/map/string");
                    NodeList mapContents = (NodeList) mapContentsExpression.evaluate(childNode,
                            XPathConstants.NODESET);
                    List<Node> nodesToAdd = new ArrayList<Node>();
                    if (mapContents.getLength() > 0 && mapContents.getLength() % 2 == 0) {
                        for (int i = 0; i < mapContents.getLength(); i++) {
                            Node keyNode = mapContents.item(i);
                            Node valueNode = mapContents.item(++i);
                            Node entryNode = document.createElement("entry");
                            entryNode.appendChild(keyNode);
                            entryNode.appendChild(valueNode);
                            nodesToAdd.add(entryNode);
                        }
                    }
                    for (Node removeNode = childNode.getFirstChild(); removeNode != null;) {
                        Node nextRemoveNode = removeNode.getNextSibling();
                        childNode.removeChild(removeNode);
                        removeNode = nextRemoveNode;
                    }
                    for (Node nodeToAdd : nodesToAdd) {
                        childNode.appendChild(nodeToAdd);
                    }
                }
            }
        }
        if (propertyMappings != null && propertyMappings.containsKey(propertyName)) {
            String newPropertyName = propertyMappings.get(propertyName);
            if (StringUtils.isNotBlank(newPropertyName)) {
                document.renameNode(childNode, null, newPropertyName);
                propertyName = newPropertyName;
            } else {
                // If there is no replacement name then the element needs
                // to be removed and skip all other processing
                node.removeChild(childNode);
                childNode = nextChild;
                continue;
            }
        }

        if (dateRuleMap != null && dateRuleMap.containsKey(propertyName)) {
            String newDateValue = dateRuleMap.get(propertyName);
            if (StringUtils.isNotBlank(newDateValue)) {
                if (childNode.getTextContent().length() == 10) {
                    childNode.setTextContent(childNode.getTextContent() + " " + newDateValue);

                }
            }
        }

        if (currentClass != null) {
            if (childNode.hasChildNodes() && !(Collection.class.isAssignableFrom(currentClass)
                    || Map.class.isAssignableFrom(currentClass))) {
                Class<?> propertyClass = PropertyUtils.getPropertyType(currentClass.newInstance(),
                        propertyName);
                if (propertyClass != null && classPropertyRuleMap.containsKey(propertyClass.getName())) {
                    transformNode(document, childNode, propertyClass,
                            this.classPropertyRuleMap.get(propertyClass.getName()));
                }
                transformNode(document, childNode, propertyClass, classPropertyRuleMap.get("*"));
            }
        }
        childNode = nextChild;
    }
}

From source file:org.kuali.rice.krad.service.impl.MaintainableXMLConversionServiceImpl.java

private void transformNode(Document document, Node node, Class<?> currentClass,
        Map<String, String> propertyMappings) throws ClassNotFoundException, XPathExpressionException,
        IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException {
    for (Node childNode = node.getFirstChild(); childNode != null;) {
        Node nextChild = childNode.getNextSibling();
        String propertyName = childNode.getNodeName();
        if (childNode.hasAttributes()) {
            XPath xpath = XPathFactory.newInstance().newXPath();
            Node serializationAttribute = childNode.getAttributes().getNamedItem(SERIALIZATION_ATTRIBUTE);
            if (serializationAttribute != null
                    && StringUtils.equals(serializationAttribute.getNodeValue(), "custom")) {
                Node classAttribute = childNode.getAttributes().getNamedItem(CLASS_ATTRIBUTE);
                if (classAttribute != null && StringUtils.equals(classAttribute.getNodeValue(),
                        "org.kuali.rice.kns.util.TypedArrayList")) {
                    ((Element) childNode).removeAttribute(SERIALIZATION_ATTRIBUTE);
                    ((Element) childNode).removeAttribute(CLASS_ATTRIBUTE);
                    XPathExpression listSizeExpression = xpath.compile("//" + propertyName
                            + "/org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl/default/size/text()");
                    String size = (String) listSizeExpression.evaluate(childNode, XPathConstants.STRING);
                    List<Node> nodesToAdd = new ArrayList<Node>();
                    if (StringUtils.isNotBlank(size) && Integer.valueOf(size) > 0) {
                        XPathExpression listTypeExpression = xpath.compile("//" + propertyName
                                + "/org.kuali.rice.kns.util.TypedArrayList/default/listObjectType/text()");
                        String listType = (String) listTypeExpression.evaluate(childNode,
                                XPathConstants.STRING);
                        XPathExpression listContentsExpression = xpath.compile("//" + propertyName
                                + "/org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl/" + listType);
                        NodeList listContents = (NodeList) listContentsExpression.evaluate(childNode,
                                XPathConstants.NODESET);
                        for (int i = 0; i < listContents.getLength(); i++) {
                            Node tempNode = listContents.item(i);
                            transformClassNode(document, tempNode);
                            nodesToAdd.add(tempNode);
                        }//from w  w  w. j a va 2 s  . c o  m
                    }
                    for (Node removeNode = childNode.getFirstChild(); removeNode != null;) {
                        Node nextRemoveNode = removeNode.getNextSibling();
                        childNode.removeChild(removeNode);
                        removeNode = nextRemoveNode;
                    }
                    for (Node nodeToAdd : nodesToAdd) {
                        childNode.appendChild(nodeToAdd);
                    }
                } else {
                    ((Element) childNode).removeAttribute(SERIALIZATION_ATTRIBUTE);

                    XPathExpression mapContentsExpression = xpath.compile("//" + propertyName + "/map/string");
                    NodeList mapContents = (NodeList) mapContentsExpression.evaluate(childNode,
                            XPathConstants.NODESET);
                    List<Node> nodesToAdd = new ArrayList<Node>();
                    if (mapContents.getLength() > 0 && mapContents.getLength() % 2 == 0) {
                        for (int i = 0; i < mapContents.getLength(); i++) {
                            Node keyNode = mapContents.item(i);
                            Node valueNode = mapContents.item(++i);
                            Node entryNode = document.createElement("entry");
                            entryNode.appendChild(keyNode);
                            entryNode.appendChild(valueNode);
                            nodesToAdd.add(entryNode);
                        }
                    }
                    for (Node removeNode = childNode.getFirstChild(); removeNode != null;) {
                        Node nextRemoveNode = removeNode.getNextSibling();
                        childNode.removeChild(removeNode);
                        removeNode = nextRemoveNode;
                    }
                    for (Node nodeToAdd : nodesToAdd) {
                        childNode.appendChild(nodeToAdd);
                    }
                }
            }
        }
        if (propertyMappings != null && propertyMappings.containsKey(propertyName)) {
            String newPropertyName = propertyMappings.get(propertyName);
            if (StringUtils.isNotBlank(newPropertyName)) {
                document.renameNode(childNode, null, newPropertyName);
                propertyName = newPropertyName;
            } else {
                // If there is no replacement name then the element needs
                // to be removed and skip all other processing
                node.removeChild(childNode);
                childNode = nextChild;
                continue;
            }
        }
        if (childNode.hasChildNodes() && !(Collection.class.isAssignableFrom(currentClass)
                || Map.class.isAssignableFrom(currentClass))) {
            if (propertyName.equals("principalId") && (node.getNodeName().equals("dataManagerUser")
                    || node.getNodeName().equals("dataStewardUser"))) {
                currentClass = new org.kuali.rice.kim.impl.identity.PersonImpl().getClass();
            }
            Class<?> propertyClass = PropertyUtils.getPropertyType(currentClass.newInstance(), propertyName);
            if (propertyClass != null && classPropertyRuleMap.containsKey(propertyClass.getName())) {
                transformNode(document, childNode, propertyClass,
                        this.classPropertyRuleMap.get(propertyClass.getName()));
            }
            transformNode(document, childNode, propertyClass, classPropertyRuleMap.get("*"));
        }
        childNode = nextChild;
    }
}

From source file:org.miradi.xml.TestXmpz2ForwardMigration.java

public void testRenameWhenAssignedFieldsMigration() throws Exception {
    getProject().createAndPopulateObjectTreeTableConfiguration();

    Document document = convertProjectToDocument();
    Element rootElement = document.getDocumentElement();

    NodeList planningViewConfigurationColumnNamesContainer = rootElement
            .getElementsByTagName(PREFIX + Xmpz2XmlConstants.OBJECT_TREE_TABLE_CONFIGURATION
                    + Xmpz2XmlConstants.COLUMN_CONFIGURATION_CODES + Xmpz2XmlConstants.CONTAINER_ELEMENT_TAG);
    for (int index = 0; index < planningViewConfigurationColumnNamesContainer.getLength(); ++index) {
        Node container = planningViewConfigurationColumnNamesContainer.item(index);

        Element codeWhenTotalNode = document.createElement(PREFIX + CODE_ELEMENT_NAME);
        codeWhenTotalNode.setTextContent(MigrationTo20.LEGACY_READABLE_ASSIGNED_WHEN_TOTAL_CODE);
        container.appendChild(codeWhenTotalNode);
    }//  w ww.  ja v a 2s.c om

    verifyMigratedXmpz2(document);
}

From source file:org.miradi.xml.TestXmpz2ForwardMigration.java

public void testRemoveWhoAssignedFieldsMigration() throws Exception {
    getProject().createAndPopulateObjectTreeTableConfiguration();

    Document document = convertProjectToDocument();
    Element rootElement = document.getDocumentElement();

    NodeList planningViewConfigurationColumnNamesContainer = rootElement
            .getElementsByTagName(PREFIX + Xmpz2XmlConstants.OBJECT_TREE_TABLE_CONFIGURATION
                    + Xmpz2XmlConstants.COLUMN_CONFIGURATION_CODES + Xmpz2XmlConstants.CONTAINER_ELEMENT_TAG);
    for (int index = 0; index < planningViewConfigurationColumnNamesContainer.getLength(); ++index) {
        Node container = planningViewConfigurationColumnNamesContainer.item(index);

        Element codeWhoTotalNode = document.createElement(PREFIX + CODE_ELEMENT_NAME);
        codeWhoTotalNode.setTextContent(MigrationTo20.LEGACY_READABLE_ASSIGNED_WHO_TOTAL_CODE);
        container.appendChild(codeWhoTotalNode);
    }//ww w .j a  v  a  2s  .  c  o  m

    verifyMigratedXmpz2(document);
}

From source file:org.miradi.xml.TestXmpz2ForwardMigration.java

private void appendChildNodeWithSampleText(Document document, Node node, final String childElementName,
        final String value) {
    Element childNode = document.createElement(PREFIX + childElementName);
    childNode.setTextContent(value);/*from  ww w  . ja v  a 2 s .c  o  m*/
    node.appendChild(childNode);
}

From source file:org.miradi.xml.TestXmpz2ForwardMigration.java

public void testLegacyHumanWellbeingTargetCalculatedThreatRating() throws Exception {
    getProject().createHumanWelfareTarget();
    Document document = convertProjectToDocument();
    Element rootElement = document.getDocumentElement();
    NodeList humanWellBeingTargets = rootElement.getElementsByTagName(PREFIX + HUMAN_WELFARE_TARGET);
    for (int index = 0; index < humanWellBeingTargets.getLength(); ++index) {
        Node node = humanWellBeingTargets.item(index);
        Element nodeToBeRemovedByMigration = document
                .createElement(PREFIX + HUMAN_WELFARE_TARGET + CALCULATED_THREAT_RATING);
        node.appendChild(nodeToBeRemovedByMigration);
    }/*w  w w  .ja va 2 s .  c o  m*/

    verifyMigratedXmpz2(document);
}

From source file:org.miradi.xml.TestXmpz2ForwardMigration.java

private void appendContainerWithSampleCode(Document document, Node node, final String containerName) {
    Element containerNode = document.createElement(PREFIX + containerName);
    Element codeNode = document.createElement(CODE_ELEMENT_NAME);
    codeNode.setTextContent("Some value");
    containerNode.appendChild(codeNode);
    node.appendChild(containerNode);
}

From source file:org.ojbc.intermediaries.sn.FbiSubscriptionProcessor.java

/**
 * Anticipated to be received from the portal manual subscriptions (not from intermediary auto subscriptions)
 *///  w w w . j a  va  2s  .  c o m
public Document appendFbiUcnIdToUnsubscribeDoc(Document unsubscribeDoc, String fbiUcnId) throws Exception {

    logger.info("\n\n\n appendFbiUcnIdToUnsubscribeDoc... \n\n\n");

    Node unsubMsgElement = XmlUtils.xPathNodeSearch(unsubscribeDoc,
            "/b-2:Unsubscribe/unsubmsg-exch:UnsubscriptionMessage");

    Node subjNode = XmlUtils.xPathNodeSearch(unsubMsgElement, "submsg-ext:Subject");
    if (subjNode != null) {
        throw new Exception(
                "Unexpected existance of Subject node.  Appending fbi data would have created duplicate subject node"
                        + "(corrupting doc). Requirements must have changed to arrive here.");
    }

    if (StringUtils.isNotEmpty(fbiUcnId)) {

        Element subjectElement = unsubscribeDoc.createElementNS(OjbcNamespaceContext.NS_SUB_MSG_EXT, "Subject");
        subjectElement.setPrefix(OjbcNamespaceContext.NS_PREFIX_SUB_MSG_EXT);
        unsubMsgElement.appendChild(subjectElement);

        Element personAugmentElement = XmlUtils.appendElement(subjectElement, OjbcNamespaceContext.NS_JXDM_41,
                "PersonAugmentation");

        Element personFbiIdElement = XmlUtils.appendElement(personAugmentElement,
                OjbcNamespaceContext.NS_JXDM_41, "PersonFBIIdentification");

        Element personFbiIdValElement = XmlUtils.appendElement(personFbiIdElement, OjbcNamespaceContext.NS_NC,
                "IdentificationID");

        personFbiIdValElement.setTextContent(fbiUcnId);
    }

    OjbcNamespaceContext ojbNsCtxt = new OjbcNamespaceContext();
    ojbNsCtxt.populateRootNamespaceDeclarations(unsubscribeDoc.getDocumentElement());

    return unsubscribeDoc;
}