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:eu.optimis.mi.gui.server.XmlUtil.java

public String getObjXml(String xml) {
    try {/*from w ww  .  j  a v a2  s. c  om*/
        // Create a builder factory
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
        NodeList timestampList = doc.getElementsByTagName("metric_timestamp");
        for (int i = 0; i < timestampList.getLength(); i++) {
            Element ts = (Element) timestampList.item(i);
            String tsLangType = ts.getTextContent();
            try {
                long millis = 0;
                millis = Long.parseLong(tsLangType);
                Date udate = new Date(millis * 1000);
                String timestamp = DateFormatUtils.ISO_DATETIME_FORMAT.format(udate);
                ts.setTextContent(timestamp);
            } catch (NumberFormatException e) {

            }
        }
        String rs = xmlToString(doc);
        return rs;

    } catch (SAXException e) {
        return null;
    } catch (ParserConfigurationException e) {
        return null;
    } catch (IOException e) {
        return null;
    }
}

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

protected Set<String> loadArchetypesPomArtifactIds(File archetypesPomFile) throws IOException {
    Set<String> answer = new TreeSet<>();
    if (!archetypesPomFile.isFile() || !archetypesPomFile.exists()) {
        LOG.warn("archetypes pom.xml file does not exist!: " + archetypesPomFile);
        return null;

    }// w w  w .  j a va 2 s.co m
    try {
        Document doc = archetypeUtils.parseXml(new InputSource(new FileReader(archetypesPomFile)));
        Element root = doc.getDocumentElement();

        // lets load all the properties defined in the <properties> element in the bom pom.
        NodeList moduleElements = root.getElementsByTagName("module");
        for (int i = 0, size = moduleElements.getLength(); i < size; i++) {
            Element moduleElement = (Element) moduleElements.item(i);
            String module = moduleElement.getTextContent();
            if (Strings.isNotBlank(module)) {
                answer.add(module);
            }
        }
        LOG.info("Loaded archetypes module names: " + answer);
        return answer;
    } catch (FileNotFoundException e) {
        throw new IOException("Failed to parse " + archetypesPomFile + ". " + e, e);
    }
}

From source file:org.jasig.springframework.security.portlet.authentication.PortletXmlMappableAttributesRetriever.java

/**
 * Loads the portlet.xml file using the configured <tt>ResourceLoader</tt> and
 * parses the role-name elements from it, using these as the set of <tt>mappableAttributes</tt>.
 *//*from  w ww. j  a va2  s. c  o m*/
public void afterPropertiesSet() throws Exception {
    Resource portletXml = resourceLoader.getResource("/WEB-INF/portlet.xml");
    Document doc = getDocument(portletXml.getInputStream());

    final XPathExpression roleNamesExpression;
    if (portletConfig == null) {
        final XPathFactory xPathFactory = XPathFactory.newInstance();

        final XPath xPath = xPathFactory.newXPath();
        roleNamesExpression = xPath.compile("/portlet-app/portlet/security-role-ref/role-name");
    } else {
        final XPathFactory xPathFactory = XPathFactory.newInstance();
        xPathFactory.setXPathVariableResolver(new XPathVariableResolver() {
            @Override
            public Object resolveVariable(QName variableName) {
                if ("portletName".equals(variableName.getLocalPart())) {
                    return portletConfig.getPortletName();
                }

                return null;
            }
        });
        final XPath xPath = xPathFactory.newXPath();
        roleNamesExpression = xPath
                .compile("/portlet-app/portlet[portlet-name=$portletName]/security-role-ref/role-name");
    }

    final NodeList securityRoles = (NodeList) roleNamesExpression.evaluate(doc, XPathConstants.NODESET);
    final Set<String> roleNames = new HashSet<String>();

    for (int i = 0; i < securityRoles.getLength(); i++) {
        Element secRoleElt = (Element) securityRoles.item(i);
        String roleName = secRoleElt.getTextContent().trim();
        roleNames.add(roleName);
        logger.info("Retrieved role-name '" + roleName + "' from portlet.xml");
    }

    if (roleNames.isEmpty()) {
        logger.info("No security-role-ref elements found in " + portletXml
                + (portletConfig == null ? "" : " for portlet " + portletConfig.getPortletName()));
    }

    mappableAttributes = Collections.unmodifiableSet(roleNames);
}

From source file:fr.aliasource.webmail.server.proxy.client.http.FetchMessagesMethod.java

public ClientMessage[] fetchMessages(Folder folder, List<MessageId> mids, String defaultTimeZone) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("token", token);
    params.put("folder", folder.getName());
    String joined = join(mids, ',');
    params.put("messageIds", joined);

    if (logger.isDebugEnabled()) {
        logger.debug("fetching from " + folder.getName() + ": " + joined);
    }// w  w  w  .ja va  2s. com

    Document doc = execute(params);
    ClientMessage[] ret = null;
    if (doc != null) {
        if (logger.isDebugEnabled()) {
            DOMUtils.logDom(doc);
        }

        Element root = doc.getDocumentElement();
        List<ClientMessage> cml = new ArrayList<ClientMessage>(mids.size());

        NodeList mnl = root.getElementsByTagName("m");
        Calendar cal = Calendar.getInstance();
        for (int i = 0; i < mnl.getLength(); i++) {
            Element m = (Element) mnl.item(i);
            ClientMessage cMess = parseMessage(cal, m);

            Element invitation = DOMUtils.getUniqueElement(m, "invitation");
            if (invitation != null) {
                cMess.setHasInvitation(Boolean.parseBoolean(invitation.getTextContent()));
            }

            fetchFwdMessage(cMess, cal, m);
            cml.add(cMess);
            cMess.setFolderName(folder.getName());
        }
        ret = cml.toArray(new ClientMessage[cml.size()]);
    }
    return ret;
}

From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractPKIXValidationInformationBeanDefinitionParser.java

/**
 * Parses the certificates from the validation info configuration.
 * /*  ww w  .ja v  a  2 s  .  c o  m*/
 * @param configChildren children of the validation set element
 * @param builder validation set build
 */
protected void parseCertificates(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) {
    List<Element> certElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "Certificate"));
    if (certElems == null || certElems.isEmpty()) {
        return;
    }

    log.debug("Parsing PKIX validation info certificates");
    ArrayList<X509Certificate> certs = new ArrayList<X509Certificate>();
    byte[] encodedCert;
    Collection<X509Certificate> decodedCerts;
    for (Element certElem : certElems) {
        encodedCert = getEncodedCertificate(DatatypeHelper.safeTrimOrNullString(certElem.getTextContent()));
        if (encodedCert == null) {
            continue;
        }

        try {
            decodedCerts = X509Util.decodeCertificate(encodedCert);
            certs.addAll(decodedCerts);
        } catch (CertificateException e) {
            throw new FatalBeanException("Unable to create PKIX validation info, unable to parse certificates",
                    e);
        }
    }

    builder.addPropertyValue("certificates", certs);
}

From source file:com.zuora.api.object.Dynamic.java

/**
 * Answers the name and values of the dynamic properties of this object
 * @return the dynamic properties, as string-object pairs
 *///www . j a  va 2  s  .c om
public Collection<Entry<String, Object>> dynamicProperties() {
    return CollectionUtils.collect(getAny(), new Transformer() {
        public Object transform(Object input) {
            Element e = (Element) input;
            return new DefaultMapEntry(e.getLocalName(), e.getTextContent());
        }
    });
}

From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractX509CredentialBeanDefinitionParser.java

/**
 * Parses the CRLs from the credential configuration.
 * // w  w  w . j  a  v a 2s  .com
 * @param configChildren children of the credential element
 * @param builder credential build
 */
protected void parseCRLs(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) {
    List<Element> crlElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "CRL"));
    if (crlElems == null || crlElems.isEmpty()) {
        return;
    }

    log.debug("Parsing x509 credential CRLs");
    ArrayList<X509CRL> crls = new ArrayList<X509CRL>();
    byte[] encodedCRL;
    Collection<X509CRL> decodedCRLs;
    for (Element crlElem : crlElems) {
        encodedCRL = getEncodedCRL(DatatypeHelper.safeTrimOrNullString(crlElem.getTextContent()));
        if (encodedCRL == null) {
            continue;
        }

        try {
            decodedCRLs = X509Util.decodeCRLs(encodedCRL);
            crls.addAll(decodedCRLs);
        } catch (CRLException e) {
            throw new FatalBeanException("Unable to create X509 credential, unable to parse CRLs", e);
        }
    }

    builder.addPropertyValue("crls", crls);
}

From source file:chat.viska.android.Application.java

private void initializeIceServers() {
    final Document xml;
    try {/*from  w  w w . j av a2s  .c  o m*/
        xml = DomUtils.readDocument(getResources().openRawResource(R.raw.ice));
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    synchronized (iceServers) {
        iceServers.clear();
        for (Node it : DomUtils.convertToList(xml.getDocumentElement().getElementsByTagName("url"))) {
            final Element element = (Element) it;
            final PeerConnection.IceServer.Builder builder = PeerConnection.IceServer
                    .builder(element.getTextContent());
            final String username = element.getAttribute("username");
            if (StringUtils.isNotBlank(username)) {
                builder.setUsername(username);
            }
            final String password = element.getAttribute("password");
            if (StringUtils.isNotBlank(password)) {
                builder.setPassword(password);
            }
            iceServers.add(builder.createIceServer());
        }
    }
}

From source file:com.cisco.dvbu.ps.common.adapters.config.AdapterConfig.java

private void parseAdapterCommon(Document doc) throws AdapterException {
    log.debug("Root element :" + doc.getDocumentElement().getNodeName());
    XPath xpath = XPathFactory.newInstance().newXPath();
    try {// w w w  .  j a  va2s .  c  o m
        Attr a = (Attr) xpath.evaluate(AdapterConstants.XPATH_CONFIG_VERSION, doc, XPathConstants.NODE);
        log.debug(a.getName() + ": " + a.getValue());
        Element e = (Element) xpath.evaluate(AdapterConstants.XPATH_NAME, doc, XPathConstants.NODE);
        name = e.getTextContent();
        log.debug(e.getNodeName() + ": " + e.getTextContent());
        e = (Element) xpath.evaluate(AdapterConstants.XPATH_DESC, doc, XPathConstants.NODE);
        desc = e.getTextContent();
        log.debug(e.getNodeName() + ": " + e.getTextContent());
        e = (Element) xpath.evaluate(AdapterConstants.XPATH_CIS_VERSION, doc, XPathConstants.NODE);
        cisVersion = e.getTextContent();
        log.debug(e.getNodeName() + ": " + e.getTextContent());
        e = (Element) xpath.evaluate(AdapterConstants.XPATH_CONN_RETRYATTMPTS, doc, XPathConstants.NODE);
        retryAttempts = (e != null && e.getTextContent() != null) ? Integer.parseInt(e.getTextContent()) : -1;
        log.debug("retryAttempts: " + retryAttempts);
        e = (Element) xpath.evaluate(AdapterConstants.XPATH_CONN_MAXCLIENTS, doc, XPathConstants.NODE);
        maxClients = (e != null && e.getTextContent() != null) ? Integer.parseInt(e.getTextContent()) : -1;
        log.debug("maxclients: " + maxClients);
        e = (Element) xpath.evaluate(AdapterConstants.XPATH_CONN_MINCLIENTS, doc, XPathConstants.NODE);
        minClients = (e != null && e.getTextContent() != null) ? Integer.parseInt(e.getTextContent()) : -1;
        log.debug("minclients: " + minClients);
    } catch (Exception e) {
        log.error("Configuration File Error! One or more mandatory configuration options are missing");
        throw new AdapterException(302,
                "Configuration File Error! One or more mandatory configuration options are missing.", e);
    }
}

From source file:com.moviejukebox.reader.MovieNFOReader.java

/**
 * Parse Trailers from the XML NFO file/*w ww  .  j a  va2s  . co m*/
 *
 * @param nlElements
 * @param movie
 */
private static void parseTrailers(NodeList nlElements, Movie movie) {
    Node nElements;
    for (int looper = 0; looper < nlElements.getLength(); looper++) {
        nElements = nlElements.item(looper);
        if (nElements.getNodeType() == Node.ELEMENT_NODE) {
            Element eTrailer = (Element) nElements;

            String trailer = eTrailer.getTextContent().trim();
            if (!trailer.isEmpty()) {
                ExtraFile ef = new ExtraFile();
                ef.setNewFile(Boolean.FALSE);
                ef.setFilename(trailer);
                movie.addExtraFile(ef);
            }
        }
    }
}