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 updateTransformerFor1_8_1(Document document) {
    Element inboundPropertiesElement, outboundPropertiesElement;

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

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

        // Update the inbound protocol properties.
        if (transformerRoot.getElementsByTagName("inboundProtocol").item(0).getTextContent().equals("XML")
                || transformerRoot.getElementsByTagName("inboundProtocol").item(0).getTextContent()
                        .equals("HL7V2")
                || transformerRoot.getElementsByTagName("inboundProtocol").item(0).getTextContent()
                        .equals("HL7V3")) {

            if (transformerRoot.getElementsByTagName("inboundProperties").getLength() == 0) {
                inboundPropertiesElement = document.createElement("inboundProperties");
                transformerRoot.appendChild(inboundPropertiesElement);
            }//from  www  . j  a v a2s .  c  o  m

            inboundPropertiesElement = (Element) transformerRoot.getElementsByTagName("inboundProperties")
                    .item(0);

            Element stripNamespacesProperty = document.createElement("property");
            stripNamespacesProperty.setAttribute("name", "stripNamespaces");
            stripNamespacesProperty.setTextContent("true");

            // Override stripNamespaces on inbound if the old
            // removeNamespace was set to false
            NodeList propertyNames = document.getElementsByTagName("property");
            for (int j = 0; j < propertyNames.getLength(); j++) {
                Node nameAttribute = propertyNames.item(j).getAttributes().getNamedItem("name");
                if (propertyNames.item(j).getAttributes().getLength() > 0 && nameAttribute != null) {
                    if (nameAttribute.getNodeValue().equals("removeNamespace")) {
                        stripNamespacesProperty.setTextContent(propertyNames.item(j).getTextContent());
                    }
                }
            }

            inboundPropertiesElement.appendChild(stripNamespacesProperty);
        }

        // Update the outbound protocol properties.
        if (transformerRoot.getElementsByTagName("outboundProtocol").item(0).getTextContent().equals("XML")
                || transformerRoot.getElementsByTagName("outboundProtocol").item(0).getTextContent()
                        .equals("HL7V2")
                || transformerRoot.getElementsByTagName("outboundProtocol").item(0).getTextContent()
                        .equals("HL7V3")) {

            if (transformerRoot.getElementsByTagName("outboundProperties").getLength() == 0) {
                outboundPropertiesElement = document.createElement("outboundProperties");
                transformerRoot.appendChild(outboundPropertiesElement);
            }

            outboundPropertiesElement = (Element) transformerRoot.getElementsByTagName("outboundProperties")
                    .item(0);

            Element stripNamespacesProperty = document.createElement("property");
            stripNamespacesProperty.setAttribute("name", "stripNamespaces");
            stripNamespacesProperty.setTextContent("true");

            outboundPropertiesElement.appendChild(stripNamespacesProperty);
        }
    }
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

private void copyNode(Node sourceNode, Node destinationNode) {
    Document destinationDoc = destinationNode.getOwnerDocument();

    switch (sourceNode.getNodeType()) {
    case Node.TEXT_NODE:
        Text text = destinationDoc.createTextNode(sourceNode.getNodeValue());
        destinationNode.appendChild(text);
        break;/*from   w ww  .j  av a  2 s.  c o m*/
    case Node.ELEMENT_NODE:
        Element element = destinationDoc.createElement(sourceNode.getNodeName());
        destinationNode.appendChild(element);

        element.setTextContent(sourceNode.getNodeValue());

        // Copy attributes
        NamedNodeMap attributes = sourceNode.getAttributes();
        int nbAttributes = attributes.getLength();

        for (int i = 0; i < nbAttributes; i++) {
            Node attribute = attributes.item(i);
            element.setAttribute(attribute.getNodeName(), attribute.getNodeValue());
        }

        // Copy children nodes
        NodeList children = sourceNode.getChildNodes();
        int nbChildren = children.getLength();
        for (int i = 0; i < nbChildren; i++) {
            Node child = children.item(i);
            copyNode(child, element);
        }
    }
}

From source file:com.ephesoft.dcma.ibm.IBMCMExporter.java

private void updateDocumentOffsetValue(final String batchInstanceID, final String filePath)
        throws DCMAApplicationException {
    try {//from   www  .j  av a  2 s  .  com
        org.w3c.dom.Document document = XMLUtil.createDocumentFrom(new File(filePath));
        NodeList documentList = document.getElementsByTagName(IBMCMConstant.DOCUMENT);
        for (int documentIndex = 0; documentIndex < documentList.getLength(); documentIndex++) {
            Element documentTag = (Element) documentList.item(documentIndex);
            Element docTag = (Element) documentTag.getElementsByTagName(IBMCMConstant.DOC_ID).item(0);
            Element offset = (Element) documentTag.getElementsByTagName(IBMCMConstant.OFFSET).item(0);
            String docIdentifier = docTag.getTextContent();
            if (docIdentifier != null & !docIdentifier.isEmpty()) {
                offset.setTextContent(String.valueOf(getOffsetValue(batchInstanceID, docIdentifier)));
            }
        }
        Source source = new DOMSource(document);
        File batchXmlFile = new File(filePath);
        OutputStream outputStream = new FileOutputStream(batchXmlFile);
        Result result = new StreamResult(outputStream);
        Transformer xformer = null;
        try {
            xformer = TransformerFactory.newInstance().newTransformer();
        } catch (TransformerConfigurationException e) {
            String msg = "Exception in transforming configuration file";
            LOGGER.error(msg + e.getMessage(), e);
            throw new DCMAApplicationException(msg + e.getMessage(), e);
        } catch (TransformerFactoryConfigurationError e) {
            String msg = "Exception in transforming factory file";
            LOGGER.error(msg + e.getMessage(), e);
            throw new DCMAApplicationException(msg + e.getMessage(), e);
        }
        try {
            xformer.transform(source, result);
        } catch (TransformerException e) {
            String msg = "Exception in transforming file";
            LOGGER.error(msg + e.getMessage(), e);
            throw new DCMAApplicationException(msg + e.getMessage(), e);
        }
    } catch (Exception e) {
        String msg = "Exception in updating offset into file";
        LOGGER.error(msg + e.getMessage(), e);
        throw new DCMAApplicationException(msg + e.getMessage(), e);
    }
}

From source file:com.phresco.pom.util.PomProcessor.java

/**
 * Sets the property.//w  w  w. j  a v  a  2 s  . c om
 *
 * @param name the name
 * @param value the value
 * @throws ParserConfigurationException the parser configuration exception
 */

public void setProperty(String name, String value) throws ParserConfigurationException {

    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    Element element = doc.createElement(name);
    element.setTextContent(value);

    if (model.getProperties() == null) {
        Properties properties = new Properties();
        model.setProperties(properties);
    }
    for (Element proElement : model.getProperties().getAny()) {
        if (proElement.getTagName().equals(name)) {
            proElement.setTextContent(value);
            return;
        }
    }
    model.getProperties().getAny().add(element);
}

From source file:com.photon.phresco.framework.rest.api.ParameterService.java

private static boolean saveCofiguration(String appDirName, String module, Publication config)
        throws PhrescoException {
    boolean fileSaved = false;
    try {//from  w  ww  .ja va2  s  .c  o m
        String rootModulePath = "";
        String subModuleName = "";
        if (StringUtils.isNotEmpty(module)) {
            rootModulePath = Utility.getProjectHome() + appDirName;
            subModuleName = module;
        } else {
            rootModulePath = Utility.getProjectHome() + appDirName;
        }
        String appDirPath = Utility.getProjectHome() + appDirName;
        String dotPhrescoFolderPath = Utility.getDotPhrescoFolderPath(appDirPath, subModuleName);

        String publicationConfigPath = dotPhrescoFolderPath + File.separator + PUBLICATION_CONFIG_FILE;

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = docFactory.newDocumentBuilder();
        Document doc = documentBuilder.newDocument();

        Element rootElement = doc.createElement(PUBLICATIONS);
        doc.appendChild(rootElement);

        Element publication = doc.createElement(PUBLICATION);
        publication.setAttribute(PUBLICATION_NAME, config.getPublicationName());
        publication.setAttribute(PUBLICATION_TYPE, config.getPublicationType());
        rootElement.appendChild(publication);

        Element publicationPath = doc.createElement(PUBLICATION_PATH);
        publicationPath.setTextContent(config.getPublicationPath());
        rootElement.appendChild(publicationPath);

        Element publicationUrl = doc.createElement(PUBLICATION_URL);
        publicationUrl.setTextContent(config.getPublicationUrl());
        rootElement.appendChild(publicationUrl);

        Element imageUrl = doc.createElement(IMAGE_URL);
        imageUrl.setTextContent(config.getImageUrl());
        rootElement.appendChild(imageUrl);

        Element imagePath = doc.createElement(IMAGE_PATH);
        imagePath.setTextContent(config.getImagePath());
        rootElement.appendChild(imagePath);

        Element environment = doc.createElement(ENVIRONMENT);
        environment.setTextContent(config.getEnvironment());
        rootElement.appendChild(environment);

        Element publicationKey = doc.createElement(PUBLICATION_KEY);
        publicationKey.setTextContent(config.getPublicationKey());
        rootElement.appendChild(publicationKey);

        Element parentPublications = doc.createElement(PARENT_PUBLICATIONS);
        List<Map<String, String>> subPublications = config.getParentPublications();
        if (CollectionUtils.isNotEmpty(subPublications)) {
            for (Map<String, String> map : subPublications) {
                Element parentPublication = doc.createElement(PARENT_SUB_PUBLICATION);
                Set<String> keySet = map.keySet();
                if (CollectionUtils.isNotEmpty(keySet)) {
                    for (String keys : keySet) {
                        if (keys.equalsIgnoreCase(PARENT_NAME)) {
                            parentPublication.setAttribute(PARENT_NAME, map.get(keys));
                            parentPublications.appendChild(parentPublication);
                        } else if (keys.equalsIgnoreCase(PRIORITY)) {
                            parentPublication.setAttribute(PRIORITY, map.get(keys));
                            parentPublications.appendChild(parentPublication);
                        }
                    }
                }
            }
        }

        rootElement.appendChild(parentPublications);

        // write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, YES);

        Pattern p = Pattern.compile("%20");
        p.matcher(publicationConfigPath);
        File path = new File(publicationConfigPath);

        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(path.toString());

        transformer.transform(source, result);
        fileSaved = true;

    } catch (ParserConfigurationException e) {
        throw new PhrescoException(e);
    } catch (TransformerConfigurationException e) {
        throw new PhrescoException(e);
    } catch (TransformerException e) {
        throw new PhrescoException(e);
    } catch (PhrescoException e) {
        throw new PhrescoException(e);
    }
    return fileSaved;
}

From source file:es.upm.fi.dia.oeg.sitemap4rdf.Generator.java

/**
 * Generates the semantic sitemap section 
 * @param doc the XML Document//w  w  w .  ja v a 2  s.  c  o m
 * @param elem the Element for the semantic sitemap
 */
protected void generateSemanticSection(Document doc, Element root) {
    if (!semanticSectionGenerated) {
        Element dataSetElement = doc.createElement(PREFIX_SEMANTIC_SITEMAP + ":" + datasetTag);
        Element linkedDataPrefixElement = doc
                .createElement(PREFIX_SEMANTIC_SITEMAP + ":" + linkedDataPrefixTag);
        Element sparqlEndPointLocationElement = doc
                .createElement(PREFIX_SEMANTIC_SITEMAP + ":" + sparqlEndPointLocation);

        linkedDataPrefixElement.setTextContent(uriPattern);
        sparqlEndPointLocationElement.setTextContent(endPoint);
        dataSetElement.appendChild(linkedDataPrefixElement);
        dataSetElement.appendChild(sparqlEndPointLocationElement);

        if (datasetDumpLocation != null && !datasetDumpLocation.isEmpty()) {
            for (String dmp : datasetDumpLocation) {
                Element dataDumpLocationElement = doc
                        .createElement(PREFIX_SEMANTIC_SITEMAP + ":" + dataDumpLocationTag);
                dataDumpLocationElement.setTextContent(dmp);
                dataSetElement.appendChild(dataDumpLocationElement);
            }
        }

        root.appendChild(dataSetElement);

        semanticSectionGenerated = true; //we want to generate the semantic section only once
    }
}

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

public static Document convertCodeTemplates(String codeTemplatesXML) throws Exception {
    codeTemplatesXML = convertPackageNames(codeTemplatesXML);
    codeTemplatesXML = runStringConversions(codeTemplatesXML);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document document;/*from  w  w w .  j ava 2  s.  c  o  m*/
    DocumentBuilder builder;

    builder = factory.newDocumentBuilder();
    document = builder.parse(new InputSource(new StringReader(codeTemplatesXML)));

    NodeList codeTemplates = getElements(document, "codeTemplate", "com.mirth.connect.model.CodeTemplate");
    int length = codeTemplates.getLength();

    for (int i = 0; i < length; i++) {
        Element codeTemplate = (Element) codeTemplates.item(i);
        codeTemplate.getOwnerDocument().renameNode(codeTemplate, codeTemplate.getNamespaceURI(),
                "codeTemplate");
        NodeList versions = codeTemplate.getElementsByTagName("version");

        // If there is no version, then this is a migration to 2.0 and the
        // scope should be incremented by 1 if its value is not currently 0
        // (global map). Global Channel Map was added in position 1 for 2.0.
        if (versions.getLength() == 0) {
            Element scope = (Element) codeTemplate.getElementsByTagName("scope").item(0);
            int scopeValue = Integer.parseInt(scope.getTextContent());
            if (scopeValue != 0) {
                scopeValue++;
                scope.setTextContent(Integer.toString(scopeValue));
            }
        }
    }

    return document;
}

From source file:marytts.tools.install.ComponentDescription.java

public Document createComponentXML() throws ParserConfigurationException {
    DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
    fact.setNamespaceAware(true);//www.j a  va  2  s  .c om
    Document doc = fact.newDocumentBuilder().newDocument();
    Element root = (Element) doc.appendChild(doc.createElementNS(installerNamespaceURI, "marytts-install"));
    Element desc = (Element) root
            .appendChild(doc.createElementNS(installerNamespaceURI, getComponentTypeString()));
    desc.setAttribute("locale", MaryUtils.locale2xmllang(locale));
    desc.setAttribute("name", name);
    desc.setAttribute("version", version);
    Element descriptionElt = (Element) desc
            .appendChild(doc.createElementNS(installerNamespaceURI, "description"));
    descriptionElt.setTextContent(description);
    Element licenseElt = (Element) desc.appendChild(doc.createElementNS(installerNamespaceURI, "license"));
    if (license != null) {
        licenseElt.setAttribute("href", license.toString());
    }
    Element packageElt = (Element) desc.appendChild(doc.createElementNS(installerNamespaceURI, "package"));
    packageElt.setAttribute("size", Integer.toString(packageSize));
    packageElt.setAttribute("md5sum", packageMD5);
    packageElt.setAttribute("filename", packageFilename);
    for (URL l : locations) {
        // Serialize the location without the filename:
        String urlString = l.toString();
        boolean isFolder = false;
        if (urlString.endsWith(packageFilename)) {
            urlString = urlString.substring(0, urlString.length() - packageFilename.length());
            isFolder = true;
        }
        Element lElt = (Element) packageElt.appendChild(doc.createElementNS(installerNamespaceURI, "location"));
        lElt.setAttribute("href", urlString);
        lElt.setAttribute("folder", String.valueOf(isFolder));
    }
    if (installedFilesNames != null) {
        Element filesElement = (Element) desc.appendChild(doc.createElementNS(installerNamespaceURI, "files"));
        filesElement.setTextContent(installedFilesNames);
    }
    return doc;
}

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

private static String convertChannel(Document document) throws Exception {
    String channelXML = "";
    Element channelRoot = document.getDocumentElement();

    String version = channelRoot.getElementsByTagName("version").item(0).getTextContent();

    int majorVersion = Integer.parseInt(version.split("\\.")[0]);
    int minorVersion = Integer.parseInt(version.split("\\.")[1]);
    int patchVersion = Integer.parseInt(version.split("\\.")[2]);

    if (majorVersion < 2) {
        if (minorVersion < 4) {
            Direction direction = null;//from   www. j ava2  s.c om
            Element sourceConnectorRoot = (Element) document.getDocumentElement()
                    .getElementsByTagName("sourceConnector").item(0);
            Element destinationConnectorRoot = (Element) document.getDocumentElement()
                    .getElementsByTagName("destinationConnectors").item(0);
            NodeList destinationsConnectors = getElements(destinationConnectorRoot, "connector",
                    "com.mirth.connect.model.Connector");

            Node channelDirection = channelRoot.getElementsByTagName("direction").item(0);

            if (channelDirection.getTextContent().equals("INBOUND"))
                direction = Direction.INBOUND;
            else if (channelDirection.getTextContent().equals("OUTBOUND"))
                direction = Direction.OUTBOUND;

            channelRoot.removeChild(channelDirection);

            NodeList modeElements = channelRoot.getElementsByTagName("mode");

            for (int i = 0; i < modeElements.getLength(); i++) {
                if (((Element) modeElements.item(i)).getParentNode() == channelRoot) {
                    channelRoot.removeChild(modeElements.item(i));
                }
            }

            channelRoot.removeChild(channelRoot.getElementsByTagName("protocol").item(0));

            NodeList transportNames = channelRoot.getElementsByTagName("transportName");
            for (int i = 0; i < transportNames.getLength(); i++) {
                if (transportNames.item(i).getTextContent().equals("PDF Writer")) {
                    transportNames.item(i).setTextContent("Document Writer");
                }
            }

            NodeList properyNames = channelRoot.getElementsByTagName("property");
            for (int i = 0; i < properyNames.getLength(); i++) {
                Node nameAttribute = properyNames.item(i).getAttributes().getNamedItem("name");
                if (properyNames.item(i).getAttributes().getLength() > 0 && nameAttribute != null) {
                    if (nameAttribute.getNodeValue().equals("DataType")) {
                        if (properyNames.item(i).getTextContent().equals("PDF Writer")) {
                            properyNames.item(i).setTextContent("Document Writer");
                        }
                    }
                }
            }

            Element modeElement = document.createElement("mode");
            modeElement.setTextContent("SOURCE");
            sourceConnectorRoot.appendChild(modeElement);

            updateFilterFor1_4((Element) sourceConnectorRoot.getElementsByTagName("filter").item(0));
            if (direction == Direction.OUTBOUND)
                updateTransformerFor1_4(document,
                        (Element) sourceConnectorRoot.getElementsByTagName("transformer").item(0), XML, XML);
            else
                updateTransformerFor1_4(document,
                        (Element) sourceConnectorRoot.getElementsByTagName("transformer").item(0), HL7V2,
                        HL7V2);

            for (int i = 0; i < destinationsConnectors.getLength(); i++) {
                modeElement = document.createElement("mode");
                modeElement.setTextContent("DESTINATION");

                Element destinationsConnector = (Element) destinationsConnectors.item(i);
                destinationsConnector.appendChild(modeElement);

                updateFilterFor1_4((Element) destinationsConnector.getElementsByTagName("filter").item(0));

                if (direction == Direction.OUTBOUND)
                    updateTransformerFor1_4(document,
                            (Element) destinationsConnector.getElementsByTagName("transformer").item(0), XML,
                            HL7V2);
                else
                    updateTransformerFor1_4(document,
                            (Element) destinationsConnector.getElementsByTagName("transformer").item(0), HL7V2,
                            HL7V2);

            }
        }

        if (minorVersion < 5) {
            updateTransformerFor1_5(document);
        }

        if (minorVersion < 6) {
            // Go through each connector and set it to enabled if that
            // property doesn't exist.

            Element sourceConnectorRoot = (Element) document.getDocumentElement()
                    .getElementsByTagName("sourceConnector").item(0);
            Element destinationConnectorRoot = (Element) document.getDocumentElement()
                    .getElementsByTagName("destinationConnectors").item(0);
            NodeList destinationsConnectors = getElements(destinationConnectorRoot, "connector",
                    "com.mirth.connect.model.Connector");

            // Check SOURCE CONNECTOR node for "enabled" element which is
            // added by migration automatically. Add it if not found.
            if (!nodeChildrenContains(sourceConnectorRoot, "enabled")) {
                Element enabledSource = document.createElement("enabled");
                enabledSource.setTextContent("true");
                sourceConnectorRoot.appendChild(enabledSource);
            } else {
                // set it anyway, in case xstream auto set it to false.
                setBooleanNode(sourceConnectorRoot, "enabled", true);
            }

            // Check CONNECTOR node for "enabled" element which is added by
            // migration automatically. Add it if not found.
            for (int i = 0; i < destinationsConnectors.getLength(); i++) {
                Element destinationConnector = (Element) destinationsConnectors.item(i);

                if (!nodeChildrenContains(destinationConnector, "enabled")) {
                    Element enabledDestination = document.createElement("enabled");
                    enabledDestination.setTextContent("true");
                    destinationConnector.appendChild(enabledDestination);
                } else {
                    // set it anyway, in case xstream auto set it to false.
                    setBooleanNode(destinationConnector, "enabled", true);
                }
            }

            if (!nodeChildrenContains(channelRoot, "deployScript")) {
                Element deployScript = document.createElement("deployScript");
                deployScript.setTextContent(
                        "// This script executes once when the channel is deployed\n// You only have access to the globalMap and globalChannelMap here to persist data\nreturn;");
                channelRoot.appendChild(deployScript);
            }

            if (!nodeChildrenContains(channelRoot, "shutdownScript")) {
                Element shutdownScript = document.createElement("shutdownScript");
                shutdownScript.setTextContent(
                        "// This script executes once when the channel is undeployed\n// You only have access to the globalMap and globalChannelMap here to persist data\nreturn;");
                channelRoot.appendChild(shutdownScript);
            }

            if (!nodeChildrenContains(channelRoot, "postprocessingScript")) {
                Element postprocessorScript = document.createElement("postprocessingScript");
                postprocessorScript.setTextContent(
                        "// This script executes once after a message has been processed\nreturn;");
                channelRoot.appendChild(postprocessorScript);
            }
        }

        if (minorVersion < 7) {
            if (!nodeChildrenContains(channelRoot, "lastModified")) {
                Element lastModified = document.createElement("lastModified");
                Element time = document.createElement("time");
                Element timezone = document.createElement("timezone");

                Calendar calendar = Calendar.getInstance();
                time.setTextContent(calendar.getTimeInMillis() + "");
                timezone.setTextContent(calendar.getTimeZone().getDisplayName());

                lastModified.appendChild(time);
                lastModified.appendChild(timezone);

                channelRoot.appendChild(lastModified);
            }

            updateFilterFor1_7(document);
            updateTransformerFor1_7(document);
        }

        if (minorVersion < 8) {
            // Run for all versions prior to 1.7.1
            if (minorVersion < 7 || (minorVersion == 7 && patchVersion < 1)) {
                updateTransformerFor1_7_1(document);
            }
            convertChannelConnectorsFor1_8(document, channelRoot);
        }

        // Run for all versions prior to 1.8.2
        if (minorVersion < 8 || (minorVersion == 8 && patchVersion < 1)) {
            updateTransformerFor1_8_1(document);
        }

        // Run for all versions prior to 2.0

        // MIRTH-1402 - Fix old channels from oracle that did not have
        // description because they were blank
        if (channelRoot.getElementsByTagName("description").getLength() == 0) {
            Element descriptionElement = document.createElement("description");
            channelRoot.appendChild(descriptionElement);
        }

        convertChannelConnectorsFor2_0(document, channelRoot);
        updateFilterFor2_0(document);
    }

    // Run for all versions prior to 3.x
    if (majorVersion < 3) {
        // Run for all versions prior to 2.2
        if (minorVersion < 2) {
            convertChannelConnectorsFor2_2(document, channelRoot);
        }
    }

    DocumentSerializer docSerializer = new DocumentSerializer();
    channelXML = docSerializer.toXML(document);

    return updateLocalAndGlobalVariables(channelXML);
}

From source file:de.qucosa.webapi.v1.DocumentResource.java

private void handleFileElement(String pid, int itemIndex, Element fileElement)
        throws URISyntaxException, IOException, FedoraClientException, XPathExpressionException {
    Node tempFile = fileElement.getElementsByTagName("TempFile").item(0);
    Node pathName = fileElement.getElementsByTagName("PathName").item(0);
    if (tempFile == null || pathName == null) {
        return;//from www .  j av  a2 s.  c o  m
    }

    String id = pid.substring("qucosa:".length());
    String tmpFileName = tempFile.getTextContent();
    String targetFilename = pathName.getTextContent();
    URI fileUri = fileHandlingService.copyTempfileToTargetFileSpace(tmpFileName, targetFilename, id);

    Node labelNode = fileElement.getElementsByTagName("Label").item(0);
    String label = (labelNode != null) ? labelNode.getTextContent() : "";

    final Path filePath = new File(fileUri).toPath();

    String detectedContentType = Files.probeContentType(filePath);
    if (!(Boolean) xPath.evaluate("MimeType[text()!='']", fileElement, XPathConstants.BOOLEAN)) {
        if (detectedContentType != null) {
            Element mimeTypeElement = fileElement.getOwnerDocument().createElement("MimeType");
            mimeTypeElement.setTextContent(detectedContentType);
            fileElement.appendChild(mimeTypeElement);
        }
    }

    if (!(Boolean) xPath.evaluate("FileSize[text()!='']", fileElement, XPathConstants.BOOLEAN)) {
        Element fileSizeElement = fileElement.getOwnerDocument().createElement("FileSize");
        fileSizeElement.setTextContent(String.valueOf(Files.size(filePath)));
        fileElement.appendChild(fileSizeElement);
    }

    String dsid = DSID_QUCOSA_ATT + (itemIndex);
    String state = determineDatastreamState(fileElement);
    DatastreamProfile dsp = fedoraRepository.createExternalReferenceDatastream(pid, dsid, label, fileUri,
            detectedContentType, state);
    fileElement.setAttribute("id", String.valueOf(itemIndex));
    addHashValue(fileElement, dsp);

    fileElement.removeChild(tempFile);
}