Example usage for org.w3c.dom Element setTextContent

List of usage examples for org.w3c.dom Element setTextContent

Introduction

In this page you can find the example usage for org.w3c.dom Element setTextContent.

Prototype

public void setTextContent(String textContent) throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:com.mirth.connect.model.util.ImportConverter.java

private static void updateFilterFor2_0(Document document) {
    // Convert Rule Builder steps using "Reject" to JavaScript steps
    NodeList rules = getElements(document, "rule", "com.mirth.connect.model.Rule");

    for (int i = 0; i < rules.getLength(); i++) {
        Element rule = (Element) rules.item(i);

        if (rule.getElementsByTagName("type").item(0).getTextContent().equalsIgnoreCase("Rule Builder")) {
            boolean reject = false;
            NodeList entries = rule.getElementsByTagName("entry");
            for (int j = 0; j < entries.getLength(); j++) {
                NodeList entry = ((Element) entries.item(j)).getElementsByTagName("string");

                if ((entry.getLength() == 2) && entry.item(0).getTextContent().equalsIgnoreCase("Accept")
                        && entry.item(1).getTextContent().equalsIgnoreCase("0")) {
                    reject = true;/* www .ja  v a  2  s  . co m*/
                }
            }

            if (reject) {
                rule.getElementsByTagName("type").item(0).setTextContent("JavaScript");
                rule.removeChild(rule.getElementsByTagName("data").item(0));

                Element dataElement = document.createElement("data");
                dataElement.setAttribute("class", "map");

                Element entryElement = document.createElement("entry");
                Element keyElement = document.createElement("string");
                Element valueElement = document.createElement("string");

                keyElement.setTextContent("Script");
                valueElement.setTextContent(rule.getElementsByTagName("script").item(0).getTextContent());

                entryElement.appendChild(keyElement);
                entryElement.appendChild(valueElement);

                dataElement.appendChild(entryElement);

                rule.appendChild(dataElement);
            }
        }
    }
}

From source file:gov.nij.bundles.intermediaries.ers.EntityResolutionMessageHandler.java

/**
 * This method takes the ER response and converts the Java objects to the Merge Response XML.
 * /*w w w .  ja va  2s .co m*/
 * @param entityContainerNode
 * @param results
 * @param recordLimit
 * @param attributeParametersNode
 * @return
 * @throws ParserConfigurationException
 * @throws XPathExpressionException
 * @throws TransformerException
 */
private Document createResponseMessage(Node entityContainerNode, EntityResolutionResults results,
        Node attributeParametersNode, int recordLimit) throws Exception {

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);

    Document resultDocument = dbf.newDocumentBuilder().newDocument();

    Element entityMergeResultMessageElement = resultDocument.createElementNS(
            EntityResolutionNamespaceContext.MERGE_RESULT_NAMESPACE, "EntityMergeResultMessage");
    resultDocument.appendChild(entityMergeResultMessageElement);

    Element entityContainerElement = resultDocument
            .createElementNS(EntityResolutionNamespaceContext.MERGE_RESULT_NAMESPACE, "EntityContainer");
    entityMergeResultMessageElement.appendChild(entityContainerElement);

    NodeList inputEntityNodes = (NodeList) xpath.evaluate("er-ext:Entity", entityContainerNode,
            XPathConstants.NODESET);
    Collection<Element> inputEntityElements = null;
    if (attributeParametersNode == null) {
        inputEntityElements = new ArrayList<Element>();
    } else {
        inputEntityElements = TreeMultiset
                .create(new EntityElementComparator((Element) attributeParametersNode));
        //inputEntityElements = new ArrayList<Element>();
    }

    for (int i = 0; i < inputEntityNodes.getLength(); i++) {
        inputEntityElements.add((Element) inputEntityNodes.item(i));
    }

    if (attributeParametersNode == null) {
        LOG.warn("Attribute Parameters element was null, so records will not be sorted");
    }
    //Collections.sort((List<Element>) inputEntityElements, new EntityElementComparator((Element) attributeParametersNode));

    if (inputEntityElements.size() != inputEntityNodes.getLength()) {
        LOG.error("Lost elements in ER output sorting.  Input count=" + inputEntityNodes.getLength()
                + ", output count=" + inputEntityElements.size());
    }

    for (Element e : inputEntityElements) {
        Node clone = resultDocument.adoptNode(e.cloneNode(true));
        resultDocument.renameNode(clone, EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                e.getLocalName());
        entityContainerElement.appendChild(clone);
    }

    Element mergedRecordsElement = resultDocument
            .createElementNS(EntityResolutionNamespaceContext.MERGE_RESULT_NAMESPACE, "MergedRecords");
    entityMergeResultMessageElement.appendChild(mergedRecordsElement);

    if (results != null) {

        List<RecordWrapper> records = results.getRecords();

        // Loop through RecordWrappers to extract info to create merged records
        for (RecordWrapper record : records) {
            LOG.debug("  !#!#!#!# Record 1, id=" + record.getExternalId() + ", externals="
                    + record.getRelatedIds());

            // Create Merged Record Container
            Element mergedRecordElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "MergedRecord");
            mergedRecordsElement.appendChild(mergedRecordElement);

            // Create Original Record Reference for 'first record'
            Element originalRecordRefElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "OriginalRecordReference");
            originalRecordRefElement.setAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE,
                    "ref", record.getExternalId());
            mergedRecordElement.appendChild(originalRecordRefElement);

            // Loop through and add any related records
            for (String relatedRecordId : record.getRelatedIds()) {
                originalRecordRefElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "OriginalRecordReference");
                originalRecordRefElement.setAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE,
                        "ref", relatedRecordId);
                mergedRecordElement.appendChild(originalRecordRefElement);
            }

            // Create Merge Quality Element
            Element mergeQualityElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "MergeQuality");
            mergedRecordElement.appendChild(mergeQualityElement);
            Set<AttributeStatistics> stats = results.getStatisticsForRecord(record.getExternalId());
            for (AttributeStatistics stat : stats) {
                Element stringDistanceStatsElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceStatistics");
                mergeQualityElement.appendChild(stringDistanceStatsElement);
                Element xpathElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "AttributeXPath");
                stringDistanceStatsElement.appendChild(xpathElement);
                Node contentNode = resultDocument.createTextNode(stat.getAttributeName());
                xpathElement.appendChild(contentNode);
                Element meanElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceMeanInRecord");
                stringDistanceStatsElement.appendChild(meanElement);
                contentNode = resultDocument.createTextNode(String.valueOf(stat.getAverageStringDistance()));
                meanElement.appendChild(contentNode);
                Element sdElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceStandardDeviationInRecord");
                stringDistanceStatsElement.appendChild(sdElement);
                contentNode = resultDocument
                        .createTextNode(String.valueOf(stat.getStandardDeviationStringDistance()));
                sdElement.appendChild(contentNode);

            }
        }

    } else {

        for (Element e : inputEntityElements) {

            String id = e.getAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE, "id");

            Element mergedRecordElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "MergedRecord");
            mergedRecordsElement.appendChild(mergedRecordElement);

            Element originalRecordRefElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "OriginalRecordReference");
            originalRecordRefElement.setAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE,
                    "ref", id);
            mergedRecordElement.appendChild(originalRecordRefElement);

            Element mergeQualityElement = resultDocument.createElementNS(
                    EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "MergeQuality");
            mergedRecordElement.appendChild(mergeQualityElement);
            XPath xp = XPathFactory.newInstance().newXPath();
            xp.setNamespaceContext(new EntityResolutionNamespaceContext());
            NodeList attributeParameterNodes = (NodeList) xp.evaluate("er-ext:AttributeParameter",
                    attributeParametersNode, XPathConstants.NODESET);
            for (int i = 0; i < attributeParameterNodes.getLength(); i++) {
                String attributeName = xp.evaluate("er-ext:AttributeXPath", attributeParametersNode);
                Element stringDistanceStatsElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceStatistics");
                mergeQualityElement.appendChild(stringDistanceStatsElement);
                Element xpathElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE, "AttributeXPath");
                stringDistanceStatsElement.appendChild(xpathElement);
                Node contentNode = resultDocument.createTextNode(attributeName);
                xpathElement.appendChild(contentNode);
                Element meanElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceMeanInRecord");
                stringDistanceStatsElement.appendChild(meanElement);
                contentNode = resultDocument.createTextNode("0.0");
                meanElement.appendChild(contentNode);
                Element sdElement = resultDocument.createElementNS(
                        EntityResolutionNamespaceContext.MERGE_RESULT_EXT_NAMESPACE,
                        "StringDistanceStandardDeviationInRecord");
                stringDistanceStatsElement.appendChild(sdElement);
                contentNode = resultDocument.createTextNode("0.0");
                sdElement.appendChild(contentNode);
            }

        }

    }

    Element recordLimitExceededElement = resultDocument.createElementNS(
            EntityResolutionNamespaceContext.MERGE_RESULT_NAMESPACE, "RecordLimitExceededIndicator");
    recordLimitExceededElement.setTextContent(new Boolean(results == null).toString());
    entityMergeResultMessageElement.appendChild(recordLimitExceededElement);

    return resultDocument;

}

From source file:com.msopentech.odatajclient.engine.data.AbstractODataBinder.java

protected Element toPrimitivePropertyElement(final String name, final ODataPrimitiveValue value,
        final Document doc, final boolean setType) {

    final Element element = doc.createElement(ODataConstants.PREFIX_DATASERVICES + name);
    if (setType) {
        element.setAttribute(ODataConstants.ATTR_M_TYPE, value.getTypeName());
    }// w w  w .  ja  va 2 s  . c om

    if (value instanceof ODataGeospatialValue) {
        element.appendChild(doc.importNode(((ODataGeospatialValue) value).toTree(), true));
    } else {
        element.setTextContent(value.toString());
    }

    return element;
}

From source file:io.fabric8.tooling.archetype.builder.ArchetypeBuilder.java

/**
 * This method:<ul>//from w ww  .  j  a va2 s. c  o  m
 *     <li>Copies POM from original project to archetype-resources</li>
 *     <li>Generates <code></code>archetype-descriptor.xml</code></li>
 *     <li>Generates Archetype's <code>pom.xml</code> if not present in target directory.</li>
 * </ul>
 *
 * @param projectPom POM file of original project
 * @param archetypeDir target directory of created Maven Archetype project
 * @param archetypePom created POM file for Maven Archetype project
 * @param metadataXmlOutFile generated archetype-metadata.xml file
 * @param replaceFn replace function
 * @throws IOException
 */
private void createArchetypeDescriptors(File projectPom, File archetypeDir, File archetypePom,
        File metadataXmlOutFile, Replacement replaceFn) throws IOException {
    LOG.debug("Parsing " + projectPom);
    String text = replaceFn.replace(FileUtils.readFileToString(projectPom));

    // lets update the XML
    Document doc = archetypeUtils.parseXml(new InputSource(new StringReader(text)));
    Element root = doc.getDocumentElement();

    // let's get some values from the original project
    String originalArtifactId, originalName, originalDescription;
    Element artifactIdEl = (Element) findChild(root, "artifactId");

    Element nameEl = (Element) findChild(root, "name");
    Element descriptionEl = (Element) findChild(root, "description");
    if (artifactIdEl != null && artifactIdEl.getTextContent() != null
            && artifactIdEl.getTextContent().trim().length() > 0) {
        originalArtifactId = artifactIdEl.getTextContent().trim();
    } else {
        originalArtifactId = archetypeDir.getName();
    }
    if (nameEl != null && nameEl.getTextContent() != null && nameEl.getTextContent().trim().length() > 0) {
        originalName = nameEl.getTextContent().trim();
    } else {
        originalName = originalArtifactId;
    }
    if (descriptionEl != null && descriptionEl.getTextContent() != null
            && descriptionEl.getTextContent().trim().length() > 0) {
        originalDescription = descriptionEl.getTextContent().trim();
    } else {
        originalDescription = originalName;
    }

    Set<String> propertyNameSet = new TreeSet<String>();

    if (root != null) {
        // remove the parent element and the following text Node
        NodeList parents = root.getElementsByTagName("parent");
        if (parents.getLength() > 0) {
            if (parents.item(0).getNextSibling().getNodeType() == Node.TEXT_NODE) {
                root.removeChild(parents.item(0).getNextSibling());
            }
            root.removeChild(parents.item(0));
        }

        // lets load all the properties defined in the <properties> element in the pom.
        Set<String> pomPropertyNames = new LinkedHashSet<String>();

        NodeList propertyElements = root.getElementsByTagName("properties");
        if (propertyElements.getLength() > 0) {
            Element propertyElement = (Element) propertyElements.item(0);
            NodeList children = propertyElement.getChildNodes();
            for (int cn = 0; cn < children.getLength(); cn++) {
                Node e = children.item(cn);
                if (e instanceof Element) {
                    pomPropertyNames.add(e.getNodeName());
                }
            }
        }
        LOG.debug("Found <properties> in the pom: {}", pomPropertyNames);

        // lets find all the property names
        NodeList children = root.getElementsByTagName("*");
        for (int cn = 0; cn < children.getLength(); cn++) {
            Node e = children.item(cn);
            if (e instanceof Element) {
                //val text = e.childrenText
                String cText = e.getTextContent();
                String prefix = "${";
                if (cText.startsWith(prefix)) {
                    int offset = prefix.length();
                    int idx = cText.indexOf("}", offset + 1);
                    if (idx > 0) {
                        String name = cText.substring(offset, idx);
                        if (!pomPropertyNames.contains(name) && isValidRequiredPropertyName(name)) {
                            propertyNameSet.add(name);
                        }
                    }
                }
            }
        }

        // now lets replace the contents of some elements (adding new elements if they are not present)
        List<String> beforeNames = Arrays.asList("artifactId", "version", "packaging", "name", "properties");
        replaceOrAddElementText(doc, root, "version", "${version}", beforeNames);
        replaceOrAddElementText(doc, root, "artifactId", "${artifactId}", beforeNames);
        replaceOrAddElementText(doc, root, "groupId", "${groupId}", beforeNames);
    }
    archetypePom.getParentFile().mkdirs();

    archetypeUtils.writeXmlDocument(doc, archetypePom);

    // lets update the archetype-metadata.xml file
    String archetypeXmlText = defaultArchetypeXmlText();

    Document archDoc = archetypeUtils.parseXml(new InputSource(new StringReader(archetypeXmlText)));
    Element archRoot = archDoc.getDocumentElement();

    // replace @name attribute on root element
    archRoot.setAttribute("name", archetypeDir.getName());

    LOG.debug(("Found property names: {}"), propertyNameSet);
    // lets add all the properties
    Element requiredProperties = replaceOrAddElement(archDoc, archRoot, "requiredProperties",
            Arrays.asList("fileSets"));

    // lets add the various properties in
    for (String propertyName : propertyNameSet) {
        requiredProperties.appendChild(archDoc.createTextNode("\n" + indent + indent));
        Element requiredProperty = archDoc.createElement("requiredProperty");
        requiredProperties.appendChild(requiredProperty);
        requiredProperty.setAttribute("key", propertyName);
        requiredProperty.appendChild(archDoc.createTextNode("\n" + indent + indent + indent));
        Element defaultValue = archDoc.createElement("defaultValue");
        requiredProperty.appendChild(defaultValue);
        defaultValue.appendChild(archDoc.createTextNode("${" + propertyName + "}"));
        requiredProperty.appendChild(archDoc.createTextNode("\n" + indent + indent));
    }
    requiredProperties.appendChild(archDoc.createTextNode("\n" + indent));

    metadataXmlOutFile.getParentFile().mkdirs();
    archetypeUtils.writeXmlDocument(archDoc, metadataXmlOutFile);

    File archetypeProjectPom = new File(archetypeDir, "pom.xml");
    // now generate Archetype's pom
    if (!archetypeProjectPom.exists()) {
        StringWriter sw = new StringWriter();
        IOUtils.copy(getClass().getResourceAsStream("default-archetype-pom.xml"), sw, "UTF-8");
        Document pomDocument = archetypeUtils.parseXml(new InputSource(new StringReader(sw.toString())));

        List<String> emptyList = Collections.emptyList();

        // artifactId = original artifactId with "-archetype"
        Element artifactId = replaceOrAddElement(pomDocument, pomDocument.getDocumentElement(), "artifactId",
                emptyList);
        artifactId.setTextContent(archetypeDir.getName());

        // name = "Fabric8 :: Qickstarts :: xxx" -> "Fabric8 :: Archetypes :: xxx"
        Element name = replaceOrAddElement(pomDocument, pomDocument.getDocumentElement(), "name", emptyList);
        if (originalName.contains(" :: ")) {
            String[] originalNameTab = originalName.split(" :: ");
            if (originalNameTab.length > 2) {
                StringBuilder sb = new StringBuilder();
                sb.append("Fabric8 :: Archetypes");
                for (int idx = 2; idx < originalNameTab.length; idx++) {
                    sb.append(" :: ").append(originalNameTab[idx]);
                }
                name.setTextContent(sb.toString());
            } else {
                name.setTextContent("Fabric8 :: Archetypes :: " + originalNameTab[1]);
            }
        } else {
            name.setTextContent("Fabric8 :: Archetypes :: " + originalName);
        }

        // description = "Creates a new " + originalDescription
        Element description = replaceOrAddElement(pomDocument, pomDocument.getDocumentElement(), "description",
                emptyList);
        description.setTextContent("Creates a new " + originalDescription);

        archetypeUtils.writeXmlDocument(pomDocument, archetypeProjectPom);
    }
}

From source file:com.haulmont.cuba.restapi.XMLConverter.java

protected Element encodeRef(Element parent, Entity entity) {
    Element ref = parent.getOwnerDocument().createElement(entity == null ? ELEMENT_NULL_REF : ELEMENT_REF);
    if (entity != null)
        ref.setAttribute(ATTR_ID, ior(entity));

    // IMPORTANT: for xml transformer not to omit the closing tag, otherwise dojo is confused
    ref.setTextContent(EMPTY_TEXT);
    parent.appendChild(ref);/* w  ww .j  av a 2 s.  c o  m*/
    return ref;
}

From source file:com.mirth.connect.model.util.ImportConverter.java

private static Element createRegexElement(Document document) {
    Element entryElement = document.createElement("entry");
    Element regexElement = document.createElement("string");
    // Element stringArrayElement = document.createElement("string-array");
    Element listElement = document.createElement("list");

    regexElement.setTextContent("RegularExpressions");

    entryElement.appendChild(regexElement);
    entryElement.appendChild(listElement);

    return entryElement;
}

From source file:clus.statistic.ClassificationStat.java

@Override
public Element getPredictElement(Document doc) {
    NumberFormat fr = ClusFormat.SIX_AFTER_DOT;
    Element stats = doc.createElement("ClassificationStat");
    Attr examples = doc.createAttribute("examples");
    examples.setValue(fr.format(m_SumWeight));
    stats.setAttributeNode(examples);//  w  ww .  j av  a2 s. co m
    Element majorities = doc.createElement("MajorityClasses");
    stats.appendChild(majorities);
    if (m_MajorityClasses != null) {
        for (int i = 0; i < m_NbTarget; i++) {
            Element majority = doc.createElement("Target");
            majorities.appendChild(majority);

            majority.setTextContent(m_Attrs[i].getValue(m_MajorityClasses[i]));

            Attr name = doc.createAttribute("name");
            name.setValue(m_Attrs[i].getName());
            majority.setAttributeNode(name);
        }
    } else {
        Element majority = doc.createElement("Attribute");
        majorities.appendChild(majority);
    }
    Element distribution = doc.createElement("Distributions");
    stats.appendChild(distribution);
    for (int j = 0; j < m_NbTarget; j++) {
        Element target = doc.createElement("Target");
        distribution.appendChild(target);
        Attr name = doc.createAttribute("name");
        name.setValue(m_Attrs[j] + "");
        target.setAttributeNode(name);
        for (int i = 0; i < m_ClassCounts[j].length; i++) {
            Element value = doc.createElement("Value");
            target.appendChild(value);
            name = doc.createAttribute("name");
            name.setValue(m_Attrs[j].getValue(i));
            value.setAttributeNode(name);
            value.setTextContent(m_ClassCounts[j][i] + "");
        }
    }
    return stats;
}

From source file:com.bluexml.xforms.controller.mapping.MappingToolAlfrescoToClassForms.java

/**
 * Fill x forms document.//from  w w  w.ja v a 2s  .com
 * 
 * @param transaction
 *            the login
 * @param xformsDocument
 *            the xforms document
 * @param alfrescoClass
 *            the alfresco class
 * @param type
 *            the type
 * @param initParams
 *            the init params
 * @param stack
 *            the stack
 * @param isServletRequest
 */
private void fillXFormsDocument(Document xformsDocument, GenericClass alfrescoClass, String type,
        Map<String, String> initParams, boolean formIsReadOnly, boolean isServletRequest) {
    ClassType classType = getClassType(type);

    Element classElement = xformsDocument.createElement(classTypeToString(classType));
    Element typeElement = xformsDocument.createElement(MsgId.INT_INSTANCE_SIDE_DATATYPE.getText());
    typeElement.setTextContent(classTypeToString(getClassTypeAlfrescoName(alfrescoClass.getQualifiedName())));

    List<ClassType> allClasses = getParentClassTypes(classType);

    Map<String, AttributeType> attributes = new TreeMap<String, AttributeType>();
    Map<String, AspectType> aspects = new TreeMap<String, AspectType>();
    Map<String, AssociationType> associations = new TreeMap<String, AssociationType>();
    for (ClassType fakeClassType : allClasses) {
        ClassType aClassType = getClassType(fakeClassType);
        List<AttributeType> subAttributes = aClassType.getAttribute();
        for (AttributeType attributeType : subAttributes) {
            String alfrescoName = attributeType.getAlfrescoName();
            if (alfrescoName != null) {
                // this case happens when using retroengineered alfresco models that do not have
                // the tags they are supposed to have
                attributes.put(alfrescoName, attributeType);
            }
        }
        List<AspectType> subAspects = aClassType.getAspect();
        for (AspectType aspectDecl : subAspects) {
            aspects.put(aspectDecl.getAlfrescoName(), getAspectType(aspectDecl));
        }
        List<AssociationType> subAssociations = aClassType.getAssociation();
        for (AssociationType associationType : subAssociations) {
            associations.put(associationType.getAlfrescoName(), associationType);
        }
    }

    String alfrescoId = StringUtils.trimToNull(alfrescoClass.getId());

    List<GenericAttribute> alfrescoAttributes = null;
    if (alfrescoClass.getAttributes() != null) {
        if (alfrescoClass.getAttributes().getAttribute() != null) {
            alfrescoAttributes = alfrescoClass.getAttributes().getAttribute();

            if (alfrescoId != null) {
                GenericAttribute idAttribute = alfrescoObjectFactory.createGenericAttribute();
                idAttribute.setQualifiedName(MsgId.INT_INSTANCE_SIDEID.getText());
                ValueType valueType = alfrescoObjectFactory.createValueType();
                valueType.setValue(alfrescoId);
                idAttribute.getValue().add(valueType);
                alfrescoAttributes.add(idAttribute);
            }

        }
    }

    Set<Entry<String, AttributeType>> attributesEntrySet = attributes.entrySet();
    for (Entry<String, AttributeType> entry : attributesEntrySet) {
        AttributeType attribute = entry.getValue();
        fillXFormsAttribute(xformsDocument, classElement, attribute, alfrescoAttributes, initParams,
                formIsReadOnly, isServletRequest);
    }
    Set<Entry<String, AspectType>> aspectsEntrySet = aspects.entrySet();
    for (Entry<String, AspectType> entry : aspectsEntrySet) {
        AspectType aspect = entry.getValue();
        if (aspect != null) { // aspects from Alfresco models yield a null here
            fillXFormsAspect(xformsDocument, classElement, aspect, alfrescoAttributes,
                    subMap(initParams, aspect.getName()), formIsReadOnly, isServletRequest);
        }
    }
    Set<Entry<String, AssociationType>> associationsEntrySet = associations.entrySet();
    for (Entry<String, AssociationType> entry : associationsEntrySet) {
        AssociationType association = entry.getValue();
        // fillXFormsAssociationType(transaction, xformsDocument, classElement, association,
        // alfrescoClass, subMap(initParams, association.getName()), stack,
        // formIsReadOnly, isServletRequest);
        fillXFormsAssociationTypeSelect(xformsDocument, classElement, alfrescoClass, association,
                subMap(initParams, association.getName()));
    }

    classElement.appendChild(typeElement);
    addId(xformsDocument, classElement, alfrescoId);
    xformsDocument.appendChild(classElement);
}

From source file:com.hin.hl7messaging.InvoiceSvgService.java

public Element createServiceElement(Document document, Element subG, HashMap<String, String> serviceMap,
        HashMap<String, String> xCoordinatesMap, String y, String style) {
    List<String> sortedKeys = new ArrayList<String>(serviceMap.size());
    sortedKeys.addAll(serviceMap.keySet());
    Collections.sort(sortedKeys, Collections.reverseOrder());

    int xService = 115;
    int xCost = 1150;

    for (String key : sortedKeys) {
        Element text = document.createElement("text");
        text.setAttribute("x", "223.8");
        text.setAttribute("y", "781.76");
        text.setAttribute("id", "legendTitle");
        Element tspan = document.createElement("tspan");
        tspan.setAttribute("id", "optimumTitle");
        tspan.setAttribute("x", String.valueOf(xService));
        tspan.setAttribute("y", y);
        tspan.setAttribute("style", style);
        tspan.setTextContent((String) key);
        text.appendChild(tspan);//www. j a  v a  2s  .  c om
        subG.appendChild(text);

        Element text1 = document.createElement("text");
        text1.setAttribute("x", "223.8");
        text1.setAttribute("y", "781.76");
        text1.setAttribute("id", "legendTitle");
        Element tspan1 = document.createElement("tspan");
        tspan1.setAttribute("id", "optimumTitle");
        tspan1.setAttribute("x", String.valueOf(xCost));
        tspan1.setAttribute("y", y);
        tspan1.setAttribute("style", style);
        tspan1.setTextContent((String) serviceMap.get(key));
        text1.appendChild(tspan1);
        subG.appendChild(text1);

        int yAxis = Integer.parseInt(y);
        y = String.valueOf(yAxis + 30);
    }

    return subG;
}

From source file:com.mirth.connect.model.util.ImportConverter.java

private static void updateTransformerFor1_5(Document document) {
    Element inboundPropertiesElement, outboundPropertiesElement;

    NodeList transformers = document.getElementsByTagName("transformer");

    for (int i = 0; i < transformers.getLength(); i++) {
        Element transformerRoot = (Element) transformers.item(i);

        if (transformerRoot.getElementsByTagName("inboundProtocol").item(0).getTextContent().equals("HL7V2")
                && transformerRoot.getElementsByTagName("inboundProperties").getLength() == 0) {
            inboundPropertiesElement = document.createElement("inboundProperties");

            Element handleRepetitionsProperty = document.createElement("property");
            handleRepetitionsProperty.setAttribute("name", "handleRepetitions");
            handleRepetitionsProperty.setTextContent("false");

            Element useStrictValidationProperty = document.createElement("property");
            useStrictValidationProperty.setAttribute("name", "useStrictValidation");
            useStrictValidationProperty.setTextContent("false");

            Element useStrictParserProperty = document.createElement("property");
            useStrictParserProperty.setAttribute("name", "useStrictParser");
            useStrictParserProperty.setTextContent("false");

            inboundPropertiesElement.appendChild(handleRepetitionsProperty);
            inboundPropertiesElement.appendChild(useStrictValidationProperty);
            inboundPropertiesElement.appendChild(useStrictParserProperty);

            transformerRoot.appendChild(inboundPropertiesElement);
        }/*from ww  w.j  a va  2  s. c om*/

        if (transformerRoot.getElementsByTagName("outboundProtocol").item(0).getTextContent().equals("HL7V2")
                && transformerRoot.getElementsByTagName("outboundProperties").getLength() == 0) {
            outboundPropertiesElement = document.createElement("outboundProperties");

            Element handleRepetitionsProperty = document.createElement("property");
            handleRepetitionsProperty.setAttribute("name", "handleRepetitions");
            handleRepetitionsProperty.setTextContent("false");

            Element useStrictValidationProperty = document.createElement("property");
            useStrictValidationProperty.setAttribute("name", "useStrictValidation");
            useStrictValidationProperty.setTextContent("false");

            Element useStrictParserProperty = document.createElement("property");
            useStrictParserProperty.setAttribute("name", "useStrictParser");
            useStrictParserProperty.setTextContent("false");

            outboundPropertiesElement.appendChild(handleRepetitionsProperty);
            outboundPropertiesElement.appendChild(useStrictValidationProperty);
            outboundPropertiesElement.appendChild(useStrictParserProperty);

            transformerRoot.appendChild(outboundPropertiesElement);
        }
    }
}