Example usage for org.w3c.dom Element getTextContent

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

Introduction

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

Prototype

public String getTextContent() 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

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

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document document;// ww  w . j  a  va  2s.  co 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:eu.europa.ec.markt.dss.validation.xades.XAdESSignature.java

private TimestampToken makeTimestampToken(Element el, TimestampToken.TimestampType timestampType)
        throws XPathExpressionException {
    Element timestampTokenNode = XMLUtils.getElement(el, "./xades:EncapsulatedTimeStamp");
    try {//from   w  w  w  .ja va 2s  .c o m
        byte[] tokenbytes = Base64.decodeBase64(timestampTokenNode.getTextContent());
        TimeStampToken tstoken = new TimeStampToken(new CMSSignedData(tokenbytes));
        return new TimestampToken(tstoken, timestampType);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.pentaho.marketplace.domain.services.PluginService.java

private String discoverInstalledVersion(IPlugin plugin) {

    String versionPath = PentahoSystem.getApplicationContext()
            .getSolutionPath("system/" + plugin.getId() + "/version.xml");
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    FileReader reader = null;//from  ww w. j  a  va  2  s  . co  m
    try {
        File file = new File(versionPath);
        if (!file.exists()) {
            return "Unknown";
        }
        DocumentBuilder db = dbf.newDocumentBuilder();
        reader = new FileReader(versionPath);
        Document dom = db.parse(new InputSource(reader));
        NodeList versionElements = dom.getElementsByTagName("version");
        if (versionElements.getLength() >= 1) {
            Element versionElement = (Element) versionElements.item(0);

            plugin.setInstalledBuildId(versionElement.getAttribute("buildId"));
            plugin.setInstalledBranch(versionElement.getAttribute("branch"));
            plugin.setInstalledVersion(versionElement.getTextContent());

            return versionElement.getTextContent();
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (Exception e) {
            // do nothing
        }
    }
    return "Unknown";
}

From source file:eu.europa.ec.markt.dss.validation.xades.XAdESSignature.java

@Override
public X509Certificate getSigningCertificate() {
    try {//w  w w .  j  a  va2  s  .c  o  m
        NodeList list = XMLUtils.getNodeList(signatureElement,
                "./ds:Object/xades:QualifyingProperties/xades:SignedProperties/xades:SignedSignatureProperties/"
                        + "xades:SigningCertificate/xades:Cert");

        for (int i = 0; i < list.getLength(); i++) {
            Element el = (Element) list.item(i);
            Element issuerSubjectNameEl = XMLUtils.getElement(el, "./xades:IssuerSerial/ds:X509IssuerName");
            X500Name issuerName = new X500Name(issuerSubjectNameEl.getTextContent());
            for (X509Certificate c : getCertificateSource().getCertificates()) {
                X500Name cIssuer = new X500Name(c.getIssuerX500Principal().getName());
                if (cIssuer.equals(issuerName)) {
                    return c;
                }
            }
        }

        return null;
    } catch (XPathExpressionException e) {
        throw new EncodingException(MSG.SIGNING_CERTIFICATE_ENCODING);
    }
}

From source file:com.microsoft.windowsazure.management.compute.OperatingSystemOperationsImpl.java

/**
* The List Operating Systems operation lists the versions of the guest
* operating system that are currently available in Windows Azure. The
* 2010-10-28 version of List Operating Systems also indicates what family
* an operating system version belongs to. Currently Azure supports two
* operating system families: the Azure guest operating system that is
* substantially compatible with Windows Server 2008 SP2, and the Azure
* guest operating system that is substantially compatible with Windows
* Server 2008 R2.  (see//from   ww w  . ja v  a  2  s  .c  o  m
* http://msdn.microsoft.com/en-us/library/windowsazure/ff684168.aspx for
* more information)
*
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @throws URISyntaxException Thrown if there was an error parsing a URI in
* the response.
* @return The List Operating Systems operation response.
*/
@Override
public OperatingSystemListResponse list()
        throws IOException, ServiceException, ParserConfigurationException, SAXException, URISyntaxException {
    // Validate

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        CloudTracing.enter(invocationId, this, "listAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/operatingsystems";
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2015-04-01");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        OperatingSystemListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new OperatingSystemListResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element operatingSystemsSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "OperatingSystems");
            if (operatingSystemsSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(operatingSystemsSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "OperatingSystem")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element operatingSystemsElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(operatingSystemsSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "OperatingSystem")
                            .get(i1));
                    OperatingSystemListResponse.OperatingSystem operatingSystemInstance = new OperatingSystemListResponse.OperatingSystem();
                    result.getOperatingSystems().add(operatingSystemInstance);

                    Element versionElement = XmlUtility.getElementByTagNameNS(operatingSystemsElement,
                            "http://schemas.microsoft.com/windowsazure", "Version");
                    if (versionElement != null) {
                        String versionInstance;
                        versionInstance = versionElement.getTextContent();
                        operatingSystemInstance.setVersion(versionInstance);
                    }

                    Element labelElement = XmlUtility.getElementByTagNameNS(operatingSystemsElement,
                            "http://schemas.microsoft.com/windowsazure", "Label");
                    if (labelElement != null) {
                        String labelInstance;
                        labelInstance = labelElement.getTextContent() != null
                                ? new String(Base64.decode(labelElement.getTextContent()))
                                : null;
                        operatingSystemInstance.setLabel(labelInstance);
                    }

                    Element isDefaultElement = XmlUtility.getElementByTagNameNS(operatingSystemsElement,
                            "http://schemas.microsoft.com/windowsazure", "IsDefault");
                    if (isDefaultElement != null) {
                        boolean isDefaultInstance;
                        isDefaultInstance = DatatypeConverter
                                .parseBoolean(isDefaultElement.getTextContent().toLowerCase());
                        operatingSystemInstance.setIsDefault(isDefaultInstance);
                    }

                    Element isActiveElement = XmlUtility.getElementByTagNameNS(operatingSystemsElement,
                            "http://schemas.microsoft.com/windowsazure", "IsActive");
                    if (isActiveElement != null) {
                        boolean isActiveInstance;
                        isActiveInstance = DatatypeConverter
                                .parseBoolean(isActiveElement.getTextContent().toLowerCase());
                        operatingSystemInstance.setIsActive(isActiveInstance);
                    }

                    Element familyElement = XmlUtility.getElementByTagNameNS(operatingSystemsElement,
                            "http://schemas.microsoft.com/windowsazure", "Family");
                    if (familyElement != null) {
                        int familyInstance;
                        familyInstance = DatatypeConverter.parseInt(familyElement.getTextContent());
                        operatingSystemInstance.setFamily(familyInstance);
                    }

                    Element familyLabelElement = XmlUtility.getElementByTagNameNS(operatingSystemsElement,
                            "http://schemas.microsoft.com/windowsazure", "FamilyLabel");
                    if (familyLabelElement != null) {
                        String familyLabelInstance;
                        familyLabelInstance = familyLabelElement.getTextContent() != null
                                ? new String(Base64.decode(familyLabelElement.getTextContent()))
                                : null;
                        operatingSystemInstance.setFamilyLabel(familyLabelInstance);
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.microsoft.windowsazure.management.sql.RecoverableDatabaseOperationsImpl.java

/**
* Returns a collection of databases that can be recovered from a specified
* server./*from   w ww  .  j a  v a2 s.  c o  m*/
*
* @param serverName Required. The name of the Azure SQL Database Server on
* which the databases were hosted.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @throws ParserConfigurationException Thrown if there was a serious
* configuration error with the document parser.
* @throws SAXException Thrown if there was an error parsing the XML
* response.
* @return Contains the response to the List Recoverable Databases request.
*/
@Override
public RecoverableDatabaseListResponse list(String serverName)
        throws IOException, ServiceException, ParserConfigurationException, SAXException {
    // Validate
    if (serverName == null) {
        throw new NullPointerException("serverName");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("serverName", serverName);
        CloudTracing.enter(invocationId, this, "listAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    url = url + "/";
    if (this.getClient().getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getClient().getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/services/sqlservers/servers/";
    url = url + URLEncoder.encode(serverName, "UTF-8");
    url = url + "/recoverabledatabases";
    ArrayList<String> queryParameters = new ArrayList<String>();
    queryParameters.add("contentview=generic");
    if (queryParameters.size() > 0) {
        url = url + "?" + CollectionStringBuilder.join(queryParameters, "&");
    }
    String baseUrl = this.getClient().getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpGet httpRequest = new HttpGet(url);

    // Set Headers
    httpRequest.setHeader("x-ms-version", "2012-03-01");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getClient().getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, null, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        RecoverableDatabaseListResponse result = null;
        // Deserialize Response
        if (statusCode == HttpStatus.SC_OK) {
            InputStream responseContent = httpResponse.getEntity().getContent();
            result = new RecoverableDatabaseListResponse();
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document responseDoc = documentBuilder.parse(new BOMInputStream(responseContent));

            Element serviceResourcesSequenceElement = XmlUtility.getElementByTagNameNS(responseDoc,
                    "http://schemas.microsoft.com/windowsazure", "ServiceResources");
            if (serviceResourcesSequenceElement != null) {
                for (int i1 = 0; i1 < com.microsoft.windowsazure.core.utils.XmlUtility
                        .getElementsByTagNameNS(serviceResourcesSequenceElement,
                                "http://schemas.microsoft.com/windowsazure", "ServiceResource")
                        .size(); i1 = i1 + 1) {
                    org.w3c.dom.Element serviceResourcesElement = ((org.w3c.dom.Element) com.microsoft.windowsazure.core.utils.XmlUtility
                            .getElementsByTagNameNS(serviceResourcesSequenceElement,
                                    "http://schemas.microsoft.com/windowsazure", "ServiceResource")
                            .get(i1));
                    RecoverableDatabase serviceResourceInstance = new RecoverableDatabase();
                    result.getDatabases().add(serviceResourceInstance);

                    Element entityIdElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "EntityId");
                    if (entityIdElement != null) {
                        String entityIdInstance;
                        entityIdInstance = entityIdElement.getTextContent();
                        serviceResourceInstance.setEntityId(entityIdInstance);
                    }

                    Element serverNameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "ServerName");
                    if (serverNameElement != null) {
                        String serverNameInstance;
                        serverNameInstance = serverNameElement.getTextContent();
                        serviceResourceInstance.setServerName(serverNameInstance);
                    }

                    Element editionElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "Edition");
                    if (editionElement != null) {
                        String editionInstance;
                        editionInstance = editionElement.getTextContent();
                        serviceResourceInstance.setEdition(editionInstance);
                    }

                    Element lastAvailableBackupDateElement = XmlUtility.getElementByTagNameNS(
                            serviceResourcesElement, "http://schemas.microsoft.com/windowsazure",
                            "LastAvailableBackupDate");
                    if (lastAvailableBackupDateElement != null) {
                        Calendar lastAvailableBackupDateInstance;
                        lastAvailableBackupDateInstance = DatatypeConverter
                                .parseDateTime(lastAvailableBackupDateElement.getTextContent());
                        serviceResourceInstance.setLastAvailableBackupDate(lastAvailableBackupDateInstance);
                    }

                    Element nameElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "Name");
                    if (nameElement != null) {
                        String nameInstance;
                        nameInstance = nameElement.getTextContent();
                        serviceResourceInstance.setName(nameInstance);
                    }

                    Element typeElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "Type");
                    if (typeElement != null) {
                        String typeInstance;
                        typeInstance = typeElement.getTextContent();
                        serviceResourceInstance.setType(typeInstance);
                    }

                    Element stateElement = XmlUtility.getElementByTagNameNS(serviceResourcesElement,
                            "http://schemas.microsoft.com/windowsazure", "State");
                    if (stateElement != null) {
                        String stateInstance;
                        stateInstance = stateElement.getTextContent();
                        serviceResourceInstance.setState(stateInstance);
                    }
                }
            }

        }
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:crawlercommons.sitemaps.SiteMapParser.java

/**
 * Parse XML that contains a Sitemap Index. Example Sitemap Index:
 * <p/>/*from  w w  w  . ja  v  a  2 s. com*/
 * <?xml version="1.0" encoding="UTF-8"?> <sitemapindex
 * xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemap>
 * <loc>http://www.example.com/sitemap1.xml.gz</loc>
 * <lastmod>2004-10-01T18:23:17+00:00</lastmod> </sitemap> <sitemap>
 * <loc>http://www.example.com/sitemap2.xml.gz</loc>
 * <lastmod>2005-01-01</lastmod> </sitemap> </sitemapindex>
 * 
 * @param url
 *            - URL of Sitemap Index
 * @param nodeList
 * @return The site map index
 */
protected SiteMapIndex parseSitemapIndex(URL url, NodeList nodeList) {

    LOG.debug("Parsing Sitemap Index");

    SiteMapIndex sitemapIndex = new SiteMapIndex(url);
    sitemapIndex.setType(SitemapType.INDEX);

    // Loop through the <sitemap>s
    for (int i = 0; i < nodeList.getLength() && i < MAX_URLS; i++) {

        Node firstNode = nodeList.item(i);

        if (firstNode.getNodeType() == Node.ELEMENT_NODE) {
            Element elem = (Element) firstNode;
            String loc = getElementValue(elem, "loc");

            // try the text content when no loc element
            // has been specified
            if (loc == null) {
                loc = elem.getTextContent().trim();
            }

            try {
                URL sitemapUrl = new URL(loc);
                String lastmod = getElementValue(elem, "lastmod");
                Date lastModified = SiteMap.convertToDate(lastmod);

                // Right now we are not worried about sitemapUrls that point
                // to different websites.

                SiteMap s = new SiteMap(sitemapUrl, lastModified);
                sitemapIndex.addSitemap(s);
                LOG.debug("  {}. {}", (i + 1), s);
            } catch (MalformedURLException e) {
                LOG.trace("Don't create an entry with a bad URL", e);
                LOG.debug("Bad url: [{}]", loc);
            }
        }
    }
    sitemapIndex.setProcessed(true);
    return sitemapIndex;
}

From source file:com.autentia.mvn.plugin.changes.BugzillaChangesMojo.java

/**
 * Addapts bugzilla XML document for transformations
 * /*from  w  ww  . j a v  a  2  s. co m*/
 * @param docBugzilla
 */
private void cleanBugzillaDocument(final Document docBugzilla) {

    // quitamos el DTD
    final Node docType = docBugzilla.getDoctype();
    docBugzilla.removeChild(docType);

    // ponemos el ttulo
    final Element title = docBugzilla.createElement(ELEMENT_TITLE);
    title.appendChild(docBugzilla.createTextNode(this.project.getName()));
    docBugzilla.getDocumentElement().appendChild(title);

    // ponemos los atributos de version para la ordenacin
    final NodeList target_milestones = docBugzilla.getElementsByTagName(ELEMENT_TARGET_MILESTONE);
    for (int i = 0; i < target_milestones.getLength(); i++) {
        final Element target_milestone = (Element) target_milestones.item(i);
        final String version = target_milestone.getTextContent();
        final String[] versions = version.split("\\.");
        // solo tenemos en cuenta las dos primeras
        // (ej. para version="1.23" tenemos la version1="1" y version2="23";
        // y para version="1.23.3" se tiene lo mismo)
        String version1 = "";
        if (versions.length > 0) {
            version1 = versions[0];
        }
        String version2 = "";
        if (versions.length >= 2) {
            version2 = versions[1];
        }
        target_milestone.setAttribute(ATTRIBUTE_VERSION1, version1);
        target_milestone.setAttribute(ATTRIBUTE_VERSION2, version2);
    }

    // si hay que ajustar los desarrolladores lo procesamos
    if (this.fitDevelopers) {
        final NodeList assigned_tos = docBugzilla.getElementsByTagName(ELEMENT_ASSIGNED_TO);
        for (int i = 0; i < assigned_tos.getLength(); i++) {
            final Element assigned_to = (Element) assigned_tos.item(i);
            String developer = assigned_to.getTextContent();
            final int index = developer.indexOf("@");
            if (index != -1) {
                developer = developer.substring(0, index);
            }
            // quitamos el texto
            final NodeList childs = assigned_to.getChildNodes();
            for (int j = 0; j < childs.getLength(); j++) {
                final Node child = childs.item(j);
                assigned_to.removeChild(child);
                // disminuimos j debido a que tambin se quita del nodelist
                j--;
            }
            assigned_to.appendChild(docBugzilla.createTextNode(developer));
        }
    }

    // eliminamos los nodos que no son necesarios
    final String[] nodes2Clean = { "creation_ts", "reporter_accessible", "cclist_accessible",
            "classification_id", "classification", "product", "component", "version", "rep_platform", "op_sys",
            "bug_status", "resolution", "priority", "everconfirmed", "estimated_time", "remaining_time",
            "actual_time", "who", "thetext" };
    for (final String node2clean : nodes2Clean) {
        this.removeNodes(docBugzilla.getElementsByTagName(node2clean));
    }
}

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

/**
 * Xforms attribute to alfresco. //$$ TRACE LOG
 * // ww w  .  j  ava2s.c o  m
 * @param child
 *            the child
 * @param attributeType
 *            the xforms attribute
 * @param isServletRequest
 * 
 * @return the attribute
 */
private GenericAttribute xformsAttributeToAlfresco(Element child, AttributeType attributeType,
        boolean isServletRequest, Map<String, String> initParams) {
    GenericAttribute result = alfrescoObjectFactory.createGenericAttribute();
    String alfrescoName = attributeType.getAlfrescoName();
    result.setQualifiedName(alfrescoName);
    String enumName = isDynamicEnum(attributeType) ? null : attributeType.getEnumQName();

    String inputTextContent = child.getTextContent();
    String type = attributeType.getType();
    if (isMultiple(attributeType)) {
        convertXformsMultipleAttributeToAlfresco(result, inputTextContent, child, type, enumName, initParams,
                false);
    } else {
        String value = null;
        boolean attributeIsReadOnly = isReadOnly(attributeType);
        if (loggertrace.isTraceEnabled()) {
            logger.debug(
                    "Received value '" + inputTextContent + "' for attribute '" + alfrescoName + "' with type '"
                            + type + "'. Read-only status '" + attributeIsReadOnly + "'. isFileField: "
                            + isFileField(attributeType) + " . isServletRequest: " + isServletRequest);
        }
        if (isAmendable(type, attributeIsReadOnly, isServletRequest)) {
            inputTextContent = getReadOnlyDateOrTimeModifiedValue(type, inputTextContent);
        }
        if (type.equalsIgnoreCase(MsgId.INT_TYPE_XSD_DATETIME.getText())) {
            String date;
            String time;
            if (attributeIsReadOnly) {
                date = extractDateFromDateTimeModified(inputTextContent);
                time = extractTimeFromDateTimeModified(inputTextContent);
            } else {
                date = DOMUtil.getChild(child, "date").getTextContent();
                time = DOMUtil.getChild(child, "time").getTextContent();
            }
            value = getDateTimeFromDateAndTime(date, time);
        } else {
            value = convertXformsAttributeToAlfresco(inputTextContent, type, enumName, initParams, false);
        }
        result.getValue().clear();
        ValueType valueType = alfrescoObjectFactory.createValueType();
        valueType.setValue(value);
        result.getValue().add(valueType);
        if (isRepositoryContent(attributeType)) {
            // we need a name for the node when uploaded in the repository
            ValueType valueTypeNameAndExt = alfrescoObjectFactory.createValueType();
            String nameAndExt = child.getAttribute("file");
            valueTypeNameAndExt.setValue(nameAndExt);
            result.getValue().add(valueTypeNameAndExt);
            // we also need the MIME type
            ValueType valueTypeMIME = alfrescoObjectFactory.createValueType();
            String mimetype = child.getAttribute("type");
            valueTypeMIME.setValue(mimetype);
            result.getValue().add(valueTypeMIME);
        }
    }

    return result;
}

From source file:it.ciroppina.idol.generic.tunnel.IdolOEMTunnel.java

/**
 * Method that returns a List<Map> where every map contains hit's fields 
 *  and the autn:content text, BUT it do not contains <DOCUMENT> structure !
 *  <br/>/*from w  ww.  j a  v  a2  s .c  om*/
 *  Notice that: this method M^UST be invoked only for a print=indexText query !
 *  
 * @return ArrayList<Hit> list of Hit, each containing a Map (of dreFields)
 * 
 */
@WebMethod(operationName = "getQueryHitsNoDocumentMap")
public ArrayList<Hit> getQueryHitsNoDocumentMap(String xml) {
    ArrayList<Hit> result = new ArrayList<Hit>();
    Document document = getDocumentFrom(xml);

    NodeList temp = null;
    temp = document.getElementsByTagName("response");
    String response = (temp.getLength() > 0)
            ? document.getElementsByTagName("response").item(0).getTextContent()
            : "FAILURE";
    temp = document.getElementsByTagName("autn:numhits");
    String numHits = (temp.getLength() > 0)
            ? document.getElementsByTagName("autn:numhits").item(0).getTextContent()
            : "0";
    temp = document.getElementsByTagName("autn:totalhits");
    String totalHits = (temp.getLength() > 0)
            ? document.getElementsByTagName("autn:totalhits").item(0).getTextContent()
            : "0";

    NodeList hits = document.getElementsByTagName("autn:hit");

    for (int i = 0; i < hits.getLength(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        Node nodo = hits.item(i);
        NodeList hitChilds = nodo.getChildNodes();

        for (int j = 0; j < hitChilds.getLength(); j++) {
            Node n = hitChilds.item(j);
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                Element e2 = (Element) n;
                if (!e2.getNodeName().equals("autn:content")) {
                    String value = "";
                    if (map.containsKey(e2.getNodeName())) {
                        value = map.get(e2.getNodeName()) + "," + e2.getTextContent();
                        map.put(e2.getNodeName(), value);
                    } else {
                        map.put(e2.getNodeName(), e2.getTextContent());
                    }

                } else {
                    if (e2.getNodeType() == Node.ELEMENT_NODE) {
                        String nodeValue = e2.getFirstChild().getTextContent();
                        //Element el = (Element) content;
                        String value = "";
                        if (map.containsKey(e2.getNodeName())) {
                            value = map.get(e2.getNodeName()) + "," + nodeValue;
                            map.put(e2.getNodeName(), value);
                        } else {
                            map.put(e2.getNodeName(), nodeValue);
                        }
                    }
                }
            }
        }
        Hit hit = new Hit(map);
        hit.getDreFields().put("response", response);
        hit.getDreFields().put("numhits", numHits);
        hit.getDreFields().put("totalhits", totalHits);

        result.add(hit);
    }
    return result;
}