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:edu.internet2.middleware.shibboleth.common.config.relyingparty.saml.AbstractSAMLProfileConfigurationBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    builder.setLazyInit(true);/*from w ww . j a v  a  2  s.c  o m*/
    Map<QName, List<Element>> children = XMLHelper.getChildElements(element);

    List<Element> audienceElems = children
            .get(new QName(SAMLRelyingPartyNamespaceHandler.NAMESPACE, "Audience"));
    if (audienceElems != null && audienceElems.size() > 0) {
        LazyList<String> audiences = new LazyList<String>();
        for (Element audienceElem : audienceElems) {
            audiences.add(DatatypeHelper.safeTrimOrNullString(audienceElem.getTextContent()));
        }
        builder.addPropertyValue("audiences", audiences);
    }

    String secCredRef = DatatypeHelper
            .safeTrimOrNullString(element.getAttributeNS(null, "signingCredentialRef"));
    if (secCredRef != null) {
        builder.addDependsOn(secCredRef);
        builder.addPropertyReference("signingCredential", secCredRef);
    }

    long lifetime = 300000L;
    if (element.hasAttributeNS(null, "assertionLifetime")) {
        lifetime = SpringConfigurationUtils.parseDurationToMillis(
                "'assertionLifetime' on profile configuration of type " + XMLHelper.getXSIType(element),
                element.getAttributeNS(null, "assertionLifetime"), 0);
    }
    builder.addPropertyValue("assertionLifetime", lifetime);

    String artifactType = DatatypeHelper
            .safeTrimOrNullString(element.getAttributeNS(null, "outboundArtifactType"));
    if (artifactType != null) {
        byte[] artifactTypeBytes = DatatypeHelper.intToByteArray(Integer.parseInt(artifactType));
        byte[] trimmedArtifactTypeBytes = { artifactTypeBytes[2], artifactTypeBytes[3] };
        builder.addPropertyValue("outboundArtifactType", trimmedArtifactTypeBytes);
    }

    CryptoOperationRequirementLevel signRequests = CryptoOperationRequirementLevel.conditional;
    if (element.hasAttributeNS(null, "signRequests")) {
        signRequests = CryptoOperationRequirementLevel.valueOf(element.getAttributeNS(null, "signRequests"));
    }
    builder.addPropertyValue("signRequests", signRequests);

    CryptoOperationRequirementLevel signResponses = getSignResponsesDefault();
    if (element.hasAttributeNS(null, "signResponses")) {
        signResponses = CryptoOperationRequirementLevel.valueOf(element.getAttributeNS(null, "signResponses"));
    }
    builder.addPropertyValue("signResponses", signResponses);

    CryptoOperationRequirementLevel signAssertions = getSignAssertionsDefault();
    if (element.hasAttributeNS(null, "signAssertions")) {
        signAssertions = CryptoOperationRequirementLevel
                .valueOf(element.getAttributeNS(null, "signAssertions"));
    }
    builder.addPropertyValue("signAssertions", signAssertions);

    String secPolRef = DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null, "securityPolicyRef"));
    if (secPolRef != null) {
        builder.addDependsOn(secPolRef);
        builder.addPropertyReference("profileSecurityPolicy", secPolRef);
    }
}

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

public Object getField(final String name) {
    String propertyName = toPropertyName(name);
    Method readMethod = NaiveProperties.getterOrNull(getClass(), propertyName);
    if (readMethod != null) {
        return getProperty(readMethod);
    }//from   w ww.j  av  a  2 s . c o m

    Element element = getElement(this, name);
    return element != null ? element.getTextContent() : null;
}

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

/**
 * Parses the CRLs from the validation info configuration.
 * //from   ww  w .  ja  v a2s . c  o m
 * @param configChildren children of the validation info element
 * @param builder validation info 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 PKIX validation info 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 PKIX validation info, unable to parse CRLs", e);
        }
    }

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

From source file:com.opengamma.web.bundle.BundleParser.java

private void processFragment(Bundle bundle, Element element) {
    String fragment = element.getTextContent();
    if (isValidFragment(fragment)) {
        bundle.addChildNode(createBundleFragment(fragment));
    }// www  .j  a v  a 2s.  c  o  m
}

From source file:eu.optimis.sm.gui.server.XmlUtil.java

public String getObjXml(String xml) {
    try {// ww w  .ja  v a2s.  co  m
        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:eu.europa.esig.dss.xades.validation.XAdESCertificateSource.java

/**
 * @param xPathQuery XPath query/*w  ww.  ja  v a2 s  .  com*/
 * @return
 */
private List<CertificateToken> getCertificates(final String xPathQuery) {

    final List<CertificateToken> list = new ArrayList<CertificateToken>();
    final NodeList nodeList = DSSXMLUtils.getNodeList(signatureElement, xPathQuery);
    for (int ii = 0; ii < nodeList.getLength(); ii++) {

        final Element certificateElement = (Element) nodeList.item(ii);

        final byte[] derEncoded = Base64.decodeBase64(certificateElement.getTextContent());
        final CertificateToken cert = DSSUtils.loadCertificate(derEncoded);
        final CertificateToken certToken = addCertificate(cert);
        if (!list.contains(certToken)) {

            final String idIdentifier = DSSXMLUtils.getIDIdentifier(certificateElement);
            certToken.setXmlId(idIdentifier);
            list.add(certToken);
        }
    }
    return list;
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.dataConnector.StaticDataConnectorBeanDefinitionParser.java

/**
 * Parses the configuration elements defining the static {@link BaseAttribute}s.
 * //from  w  w w. jav  a2s  . c  o  m
 * @param attributeElems configuration elements defining the static {@link BaseAttribute}s
 * 
 * @return the static {@link BaseAttribute}s
 */
protected List<BaseAttribute<String>> processAttributes(List<Element> attributeElems) {
    if (attributeElems == null || attributeElems.size() == 0) {
        return null;
    }

    List<BaseAttribute<String>> attributes = new ArrayList<BaseAttribute<String>>();
    BasicAttribute<String> attribute;
    for (Element attributeElem : attributeElems) {
        attribute = new BasicAttribute<String>(
                DatatypeHelper.safeTrimOrNullString(attributeElem.getAttributeNS(null, "id")));
        for (Element valueElem : XMLHelper.getChildElementsByTagNameNS(attributeElem,
                DataConnectorNamespaceHandler.NAMESPACE, "Value")) {
            attribute.getValues().add(valueElem.getTextContent());
        }

        attributes.add(attribute);
    }

    return attributes;
}

From source file:com.evolveum.midpoint.model.common.expression.functions.BasicExpressionFunctionsXPath.java

public String determineLdapSingleAttributeValue(Element dn, String attributeName, Element valueElement)
        throws NamingException {
    // Trivial case: the value is a single element therefore it has a single value.
    return valueElement.getTextContent();
}

From source file:com.fluidops.iwb.wiki.WikiBot.java

/**
    * InputStream contains a document with at least one page
    * /*from w  w  w .j  a  v  a 2  s  .c om*/
    * <code>
    * ...
    * <page pageid="15580374" ns="0" title="Main Page">
    *     <revisions>
    *        <rev revid="464887589" parentid="447996010" timestamp="2011-12-09T03:08:20Z"
    *              xml:space="preserve">
    *        Content
    *        </rev>
    *     </revisions>
    * </page>
    * ...
    * </code>
    * 
    * Content is html decoded
    * 
    * @param page
    * @return
    * @throws IOException 
    * @throws SAXException 
    */
private String parsePage(InputStream in) throws Exception {

    DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document d = documentBuilder.parse(in);

    NodeList pages = d.getElementsByTagName("page");

    if (pages == null || pages.getLength() == 0)
        throw new IllegalArgumentException("InputStream does not have the expected 'page' section");

    NodeList revs = getChild(pages.item(0), "revisions").getElementsByTagName("rev");

    if (revs.getLength() != 1)
        throw new IllegalArgumentException(
                "Page does not have the expected structure, exactly one revision expected.");

    Element rev = (Element) revs.item(0);

    return StringEscapeUtils.unescapeHtml(rev.getTextContent());

}

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

/**
 * Parses the secret key from the credential configuration.
 * // w w w. ja v  a  2 s . co  m
 * @param configChildren children of the credential element
 * @param builder credential build
 */
protected void parseSecretKey(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) {
    List<Element> keyElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "SecretKey"));
    if (keyElems == null || keyElems.isEmpty()) {
        return;
    }

    log.debug("Parsing credential secret key");
    Element secretKeyElem = keyElems.get(0);
    byte[] encodedKey = getEncodedSecretKey(
            DatatypeHelper.safeTrimOrNullString(secretKeyElem.getTextContent()));
    String keyPassword = DatatypeHelper.safeTrimOrNullString(secretKeyElem.getAttributeNS(null, "password"));
    try {
        SecretKey key = SecurityHelper.decodeSecretKey(encodedKey, keyPassword.toCharArray());
        builder.addPropertyValue("secretKey", key);
    } catch (KeyException e) {
        throw new FatalBeanException("Unable to create credential, unable to parse secret key", e);
    }
}