Example usage for org.w3c.dom Element getAttributeNS

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

Introduction

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

Prototype

public String getAttributeNS(String namespaceURI, String localName) throws DOMException;

Source Link

Document

Retrieves an attribute value by local name and namespace URI.

Usage

From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java

/**
 * Gets the value of the {@value #REVISION_ATTRIB_NAME} attribute.
 * /* w  w w .  jav  a 2 s . com*/
 * @param configElement resource configuration element
 * 
 * @return value of the attribute
 * 
 * @throws BeanCreationException thrown if the attribute is missing or contains an invalid number
 */
protected long getRevision(Element configElement) throws BeanCreationException {
    if (!configElement.hasAttributeNS(null, REVISION_ATTRIB_NAME)) {
        return -1;
    } else {
        try {
            return Long.parseLong(DatatypeHelper
                    .safeTrimOrNullString(configElement.getAttributeNS(null, WORKING_COPY_DIR_ATTRIB_NAME)));
        } catch (NumberFormatException e) {
            log.error("SVN resource definition attribute '" + REVISION_ATTRIB_NAME
                    + "' contains an invalid number");
            throw new BeanCreationException("SVN resource definition attribute '" + REVISION_ATTRIB_NAME
                    + "' contains an invalid number");
        }
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java

/**
 * Gets the value of the {@value #CTX_TIMEOUT_ATTRIB_NAME} attribute.
 * /*from   ww w  . j  a  v a  2 s . c  o  m*/
 * @param configElement resource configuration element
 * 
 * @return value of the attribute, or {@value #DEFAULT_CTX_TIMEOUT} if the attribute is not defined
 * 
 * @throws BeanCreationException thrown if the attribute is present but contains an empty string
 */
protected int getConnectionTimeout(Element configElement) throws BeanCreationException {
    if (!configElement.hasAttributeNS(null, CTX_TIMEOUT_ATTRIB_NAME)) {
        return DEFAULT_CTX_TIMEOUT;
    }

    return (int) SpringConfigurationUtils.parseDurationToMillis(CTX_TIMEOUT_ATTRIB_NAME + " on SVN resource",
            configElement.getAttributeNS(null, CTX_TIMEOUT_ATTRIB_NAME), 0);
}

From source file:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java

/**
 * Gets the value of the {@value #READ_TIMEOUT_ATTRIB_NAME} attribute.
 * // ww  w  . j ava 2s . co  m
 * @param configElement resource configuration element
 * 
 * @return value of the attribute, or {@value #DEFAULT_READ_TIMEOUT} if the attribute is not defined
 * 
 * @throws BeanCreationException thrown if the attribute is present but contains an empty string
 */
protected int getReadTimeout(Element configElement) throws BeanCreationException {
    if (!configElement.hasAttributeNS(null, READ_TIMEOUT_ATTRIB_NAME)) {
        return DEFAULT_READ_TIMEOUT;
    }

    return (int) SpringConfigurationUtils.parseDurationToMillis(READ_TIMEOUT_ATTRIB_NAME + " on SVN resource",
            configElement.getAttributeNS(null, CTX_TIMEOUT_ATTRIB_NAME), 0);
}

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

/**
 * This method takes the entity and attribute parameter nodes as arguments and converts the XML to Java Objects so Entity Resolution can be performed.
 * /*w  w w.j a  va 2s .  c  om*/
 * @param entityContainerNode
 * @param attributeParametersNode
 * @return
 * @throws Exception
 */

List<RecordWrapper> createRecordsFromRequestMessage(NodeList entityNodeList, Node attributeParametersNode)
        throws Exception {

    List<RecordWrapper> records = new ArrayList<RecordWrapper>();

    Set<AttributeParametersXpathSupport> attributeParametersXpathSupport = getAttributeParameters(
            attributeParametersNode);

    for (int i = 0; i < entityNodeList.getLength(); i++) {
        Element entityElement = (Element) entityNodeList.item(i);

        // The following lines will first check for an ID, if none is found, one is generated
        String entityId = entityElement.getAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE,
                "id");

        if (StringUtils.isEmpty(entityId)) {
            entityId = "E" + UUID.randomUUID().toString();
            entityElement.setAttributeNS(EntityResolutionNamespaceContext.STRUCTURES_NAMESPACE, "s:id",
                    entityId);
        }

        entityElement = createOrphanElement(entityElement);

        Map<String, AttributeWrapper> attributeMap = new HashMap<String, AttributeWrapper>();

        for (AttributeParametersXpathSupport parameter : attributeParametersXpathSupport) {
            String attributeName = parameter.getAttributeName();
            AttributeWrapper attribute = new AttributeWrapper(attributeName);

            XPath attributeParameterXpath = parameter.getXpath();
            String value = attributeParameterXpath.evaluate(attributeName, entityElement);

            attribute.addValue(value);
            LOG.debug("Adding attribute to record with entityId=" + entityId + ", type=" + attributeName
                    + ", value=" + value);
            attributeMap.put(attribute.getType(), attribute);
        }

        RecordWrapper record = new RecordWrapper(attributeMap, entityId);
        records.add(record);
    }

    return records;

}

From source file:edu.internet2.middleware.shibboleth.common.config.relyingparty.saml.SAML2SSOProfileConfigurationBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(element, parserContext, builder);

    if (element.hasAttributeNS(null, "includeAttributeStatement")) {
        builder.addPropertyValue("includeAttributeStatement", XMLHelper
                .getAttributeValueAsBoolean(element.getAttributeNodeNS(null, "includeAttributeStatement")));
    } else {/*from  www.  j  av a  2  s. co m*/
        builder.addPropertyValue("includeAttributeStatement", true);
    }

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

From source file:de.betterform.agent.web.WebProcessor.java

private URI getTransformURI() throws XFormsException, URISyntaxException {
    URI uri;/*from ww  w  .  j a v a 2s. co m*/

    //if we find a xsl param on the request URI this takes precedence over all
    String xslFile = request.getParameter(XSL_PARAM_NAME);
    String xsltPath = RESOURCE_DIR + "xslt";
    if (xslFile != null) {
        return new File(WebFactory.getRealPath(xsltPath, getContext())).toURI().resolve(new URI(xslFile));
    }

    //if we find a 'bf:transform' attribute on the root element of a form this takes priority over the global configuration in betterform-config.xml
    Element e = this.xformsProcessor.getXForms().getDocumentElement();
    if (e.hasAttributeNS(NamespaceConstants.BETTERFORM_NS, "transform")) {
        String transformValue = e.getAttributeNS(NamespaceConstants.BETTERFORM_NS, "transform");
        return new URI(WebUtil.getRequestURI(request) + transformValue);
    }

    //finally use the configuration
    //        String configuredTransform = configuration.getStylesheet(this.useragent);
    String configuredTransform = configuration.getProperty("ui-transform");

    //todo: this forces to load the transform from filesystem - should be changed
    if (configuredTransform != null) {
        return new File(WebFactory.getRealPath(xsltPath, getContext())).toURI()
                .resolve(new URI(configuredTransform));
    }

    throw new XFormsConfigException(
            "There was no xslt stylesheet found on the request URI, the root element of the form or in the configfile");
}

From source file:edu.internet2.middleware.shibboleth.common.config.relyingparty.saml.AbstractSAML2ProfileConfigurationBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(element, parserContext, builder);

    List<Element> proxyAudiences = XMLHelper.getChildElementsByTagNameNS(element,
            SAMLRelyingPartyNamespaceHandler.NAMESPACE, "ProxyAudience");
    if (proxyAudiences != null && proxyAudiences.size() > 0) {
        LazyList<String> audiences = new LazyList<String>();
        for (Element proxyAudience : proxyAudiences) {
            audiences.add(DatatypeHelper.safeTrimOrNullString(proxyAudience.getTextContent()));
        }/*from ww  w.  j av  a2 s . c  om*/

        builder.addPropertyValue("proxyAudiences", audiences);
    }

    builder.addPropertyReference("attributeAuthority",
            DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null, "attributeAuthority")));

    if (element.hasAttributeNS(null, "encryptNameIds")) {
        builder.addPropertyValue("encryptNameIds",
                CryptoOperationRequirementLevel.valueOf(element.getAttributeNS(null, "encryptNameIds")));
    } else {
        builder.addPropertyValue("encryptNameIds", CryptoOperationRequirementLevel.never);
    }

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

    if (element.hasAttributeNS(null, "assertionProxyCount")) {
        builder.addPropertyValue("assertionProxyCount", Integer.parseInt(
                DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null, "assertionProxyCount"))));
    } else {
        builder.addPropertyValue("assertionProxyCount", 0);
    }
}

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

/**
 * Process the LDAP result handling configuration for the LDAP data connector.
 * //from   w w w  .  j  a  v  a2 s. c o m
 * @param pluginId ID of the LDAP plugin
 * @param pluginConfig LDAP plugin configuration element
 * @param pluginConfigChildren child elements of the plugin
 * @param pluginBuilder plugin builder
 * @param parserContext current parsing context
 */
protected void processResultHandlingConfig(String pluginId, Element pluginConfig,
        Map<QName, List<Element>> pluginConfigChildren, BeanDefinitionBuilder pluginBuilder,
        ParserContext parserContext) {
    int searchTimeLimit = 3000;
    if (pluginConfig.hasAttributeNS(null, "searchTimeLimit")) {
        searchTimeLimit = (int) SpringConfigurationUtils.parseDurationToMillis(
                "'searchTimeLimit' on data connector " + pluginId,
                pluginConfig.getAttributeNS(null, "searchTimeLimit"), 0);
    }
    log.debug("Data connector {} search timeout: {}ms", pluginId, searchTimeLimit);
    pluginBuilder.addPropertyValue("searchTimeLimit", searchTimeLimit);

    int maxResultSize = 1;
    if (pluginConfig.hasAttributeNS(null, "maxResultSize")) {
        maxResultSize = Integer.parseInt(pluginConfig.getAttributeNS(null, "maxResultSize"));
    }
    log.debug("Data connector {} max search result size: {}", pluginId, maxResultSize);
    pluginBuilder.addPropertyValue("maxResultSize", maxResultSize);

    boolean mergeResults = false;
    if (pluginConfig.hasAttributeNS(null, "mergeResults")) {
        mergeResults = XMLHelper
                .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "mergeResults"));
    }
    log.debug("Data connector {} merge results: {}", pluginId, mergeResults);
    pluginBuilder.addPropertyValue("mergeResults", mergeResults);

    boolean noResultsIsError = false;
    if (pluginConfig.hasAttributeNS(null, "noResultIsError")) {
        noResultsIsError = XMLHelper
                .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "noResultIsError"));
    }
    log.debug("Data connector {} no results is error: {}", pluginId, noResultsIsError);
    pluginBuilder.addPropertyValue("noResultsIsError", noResultsIsError);

    boolean lowercaseAttributeNames = false;
    if (pluginConfig.hasAttributeNS(null, "lowercaseAttributeNames")) {
        lowercaseAttributeNames = XMLHelper
                .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "lowercaseAttributeNames"));
    }
    log.debug("Data connector {} will lower case attribute IDs: {}", pluginId, lowercaseAttributeNames);
    pluginBuilder.addPropertyValue("lowercaseAttributeNames", lowercaseAttributeNames);
}

From source file:com.evolveum.midpoint.prism.lex.dom.DomLexicalProcessor.java

private void extractCommonMetadata(Element element, XNode xnode) throws SchemaException {
    QName xsiType = DOMUtil.resolveXsiType(element);
    if (xsiType != null) {
        xnode.setTypeQName(xsiType);/*  w ww .j a  va  2 s. c  om*/
        xnode.setExplicitTypeDeclaration(true);
    }

    String maxOccursString = element.getAttributeNS(PrismConstants.A_MAX_OCCURS.getNamespaceURI(),
            PrismConstants.A_MAX_OCCURS.getLocalPart());
    if (!StringUtils.isBlank(maxOccursString)) {
        int maxOccurs = parseMultiplicity(maxOccursString, element);
        xnode.setMaxOccurs(maxOccurs);
    }
}