Example usage for org.w3c.dom Element hasAttributeNS

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

Introduction

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

Prototype

public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException;

Source Link

Document

Returns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise.

Usage

From source file:net.shibboleth.idp.profile.spring.relyingparty.metadata.impl.AbstractDynamicHTTPMetadataProviderParser.java

/**
 * Build the definition of the HTTPClientBuilder which contains all our configuration.
 * //from  ww w.  j  a va2  s.c  om
 * @param element the HTTPMetadataProvider parser.
 * @param parserContext thee context
 * @param haveTLSTrustEngine whether have a TLS TrustEngine configured
 * @return the bean definition with the parameters.
 */
// Checkstyle: CyclomaticComplexity OFF
// Checkstyle: MethodLength OFF
private BeanDefinition buildHttpClient(Element element, ParserContext parserContext,
        boolean haveTLSTrustEngine) {
    String caching = DEFAULT_CACHING;
    if (element.hasAttributeNS(null, "httpCaching")) {
        caching = StringSupport.trimOrNull(element.getAttributeNS(null, "httpCaching"));
    }

    BeanDefinitionBuilder clientBuilder = null;
    switch (caching) {
    case "none":
        clientBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpClientFactoryBean.class);
        break;
    case "file":
        clientBuilder = BeanDefinitionBuilder.genericBeanDefinition(FileCachingHttpClientFactoryBean.class);
        if (element.hasAttributeNS(null, "httpCacheDirectory")) {
            clientBuilder.addPropertyValue("cacheDirectory",
                    StringSupport.trimOrNull(element.getAttributeNS(null, "httpCacheDirectory")));
        }
        if (element.hasAttributeNS(null, "httpMaxCacheEntries")) {
            clientBuilder.addPropertyValue("maxCacheEntries",
                    StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntries")));
        }
        if (element.hasAttributeNS(null, "httpMaxCacheEntrySize")) {
            clientBuilder.addPropertyValue("maxCacheEntrySize",
                    StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntrySize")));
        }
        break;
    case "memory":
        clientBuilder = BeanDefinitionBuilder.genericBeanDefinition(InMemoryCachingHttpClientFactoryBean.class);
        if (element.hasAttributeNS(null, "httpMaxCacheEntries")) {
            clientBuilder.addPropertyValue("maxCacheEntries",
                    StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntries")));
        }
        if (element.hasAttributeNS(null, "httpMaxCacheEntrySize")) {
            clientBuilder.addPropertyValue("maxCacheEntrySize",
                    StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntrySize")));
        }
        break;
    default:
        throw new BeanDefinitionParsingException(
                new Problem(String.format("Caching value '%s' is unsupported", caching),
                        new Location(parserContext.getReaderContext().getResource())));
    }

    clientBuilder.setLazyInit(true);

    if (element.hasAttributeNS(null, "requestTimeout")) {
        clientBuilder.addPropertyValue("connectionTimeout",
                StringSupport.trimOrNull(element.getAttributeNS(null, "requestTimeout")));
    }

    if (haveTLSTrustEngine) {
        clientBuilder.addPropertyValue("tLSSocketFactory", new SecurityEnhancedTLSSocketFactory(
                HttpClientSupport.buildNoTrustTLSSocketFactory(), new StrictHostnameVerifier()));
    }

    if (element.hasAttributeNS(null, "disregardTLSCertificate")) {
        clientBuilder.addPropertyValue("connectionDisregardTLSCertificate",
                StringSupport.trimOrNull(element.getAttributeNS(null, "disregardTLSCertificate")));
    } else if (element.hasAttributeNS(null, "disregardSslCertificate")) {
        log.warn("disregardSslCertificate is deprecated, please switch to disregardTLSCertificate");
        clientBuilder.addPropertyValue("connectionDisregardTLSCertificate",
                StringSupport.trimOrNull(element.getAttributeNS(null, "disregardSslCertificate")));
    }

    if (element.hasAttributeNS(null, "proxyHost")) {
        clientBuilder.addPropertyValue("connectionProxyHost",
                StringSupport.trimOrNull(element.getAttributeNS(null, "proxyHost")));
    }

    if (element.hasAttributeNS(null, "proxyPort")) {
        clientBuilder.addPropertyValue("connectionProxyPort",
                StringSupport.trimOrNull(element.getAttributeNS(null, "proxyPort")));
    }

    if (element.hasAttributeNS(null, "proxyUser")) {
        clientBuilder.addPropertyValue("connectionProxyUsername",
                StringSupport.trimOrNull(element.getAttributeNS(null, "proxyUser")));
    }

    if (element.hasAttributeNS(null, "proxyPassword")) {
        clientBuilder.addPropertyValue("connectionProxyPassword",
                element.getAttributeNS(null, "proxyPassword"));
    }

    return clientBuilder.getBeanDefinition();
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.attributeDefinition.RegexSplitAttributeDefinitionBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren,
        BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) {
    super.doParse(pluginId, pluginConfig, pluginConfigChildren, pluginBuilder, parserContext);

    pluginBuilder.addPropertyValue("regex",
            DatatypeHelper.safeTrimOrNullString(pluginConfig.getAttributeNS(null, "regex")));

    boolean caseSensitive = true;
    if (pluginConfig.hasAttributeNS(null, "caseSensitive")) {
        caseSensitive = XMLHelper//from   ww w . j av a 2s.com
                .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "caseSensitive"));
    }
    pluginBuilder.addPropertyValue("caseSensitive", caseSensitive);
}

From source file:net.shibboleth.idp.profile.spring.relyingparty.metadata.impl.AbstractDynamicHTTPMetadataProviderParser.java

/** {@inheritDoc} */
// Checkstyle: CyclomaticComplexity OFF -- more readable not split up
@Override/*  www  . jav a 2 s .  com*/
protected void doNativeParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doNativeParse(element, parserContext, builder);

    boolean haveTLSTrustEngine = false;
    if (element.hasAttributeNS(null, "tlsTrustEngineRef")) {
        builder.addPropertyReference("tLSTrustEngine",
                StringSupport.trimOrNull(element.getAttributeNS(null, "tlsTrustEngineRef")));
        haveTLSTrustEngine = true;
    } else {
        BeanDefinition tlsTrustEngine = parseTLSTrustEngine(element, parserContext);
        if (tlsTrustEngine != null) {
            builder.addPropertyValue("tLSTrustEngine", tlsTrustEngine);
            haveTLSTrustEngine = true;
        }
    }

    if (element.hasAttributeNS(null, "httpClientRef")) {
        builder.addConstructorArgReference(
                StringSupport.trimOrNull(element.getAttributeNS(null, "httpClientRef")));
        if (element.hasAttributeNS(null, "requestTimeout")
                || element.hasAttributeNS(null, "disregardSslCertificate")
                || element.hasAttributeNS(null, "disregardTLSCertificate")
                || element.hasAttributeNS(null, "proxyHost") || element.hasAttributeNS(null, "proxyPort")
                || element.hasAttributeNS(null, "proxyUser") || element.hasAttributeNS(null, "proxyPassword")) {
            log.warn("httpClientRef overrides settings for requestTimeout, disregardSslCertificate, "
                    + "disregardTLSCertificate, proxyHost, proxyPort, proxyUser and proxyPassword");
        }
    } else {
        builder.addConstructorArgValue(buildHttpClient(element, parserContext, haveTLSTrustEngine));
    }

    if (element.hasAttributeNS(null, "credentialsProviderRef")) {
        builder.addPropertyReference("credentialsProviderRef",
                StringSupport.trimOrNull(element.getAttributeNS(null, "credentialsProviderRef")));
        if (element.hasAttributeNS(null, BASIC_AUTH_USER)
                || element.hasAttributeNS(null, BASIC_AUTH_PASSWORD)) {
            log.warn("credentialsProviderRef overrides settings for basicAuthUser and basicAuthPassword");
        }
    } else {
        if (element.hasAttributeNS(null, BASIC_AUTH_USER)
                || element.hasAttributeNS(null, BASIC_AUTH_PASSWORD)) {
            builder.addPropertyValue("basicCredentials", buildBasicCredentials(element));
        }
    }

    if (element.hasAttributeNS(null, "supportedContentTypes")) {
        List<String> supportedContentTypes = StringSupport.stringToList(
                StringSupport.trimOrNull(element.getAttributeNS(null, "supportedContentTypes")),
                XMLConstants.LIST_DELIMITERS);
        builder.addPropertyValue("supportedContentTypes", supportedContentTypes);
    }

}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.principalConnector.StoredIDPrincipalConnectorBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren,
        BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) {
    super.doParse(pluginId, pluginConfig, pluginConfigChildren, pluginBuilder, parserContext);

    pluginBuilder.addPropertyReference("idProducer",
            DatatypeHelper.safeTrimOrNullString(pluginConfig.getAttributeNS(null, "storedIdDataConnectorRef")));

    boolean noResultsIsError = false;
    if (pluginConfig.hasAttributeNS(null, "noResultIsError")) {
        noResultsIsError = XMLHelper//from   w w  w.j ava 2 s.c  om
                .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "noResultIsError"));
    }
    pluginBuilder.addPropertyValue("noResultIsError", noResultsIsError);
}

From source file:edu.internet2.middleware.psp.spring.PsoAttributeBeanDefinitionParser.java

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

    String name = element.getAttributeNS(null, "name");
    builder.addPropertyValue("name", name);

    String ref = element.getAttributeNS(null, "ref");
    if (ref.equals("")) {
        ref = name;/*from   www. j av a2s . co m*/
    }
    builder.addPropertyValue("ref", ref);

    boolean isMultiValued = false;
    if (element.hasAttributeNS(null, "isMultiValued")) {
        isMultiValued = XMLHelper.getAttributeValueAsBoolean(element.getAttributeNodeNS(null, "isMultiValued"));
    }
    builder.addPropertyValue("isMultiValued", isMultiValued);

    boolean replaceValues = false;
    if (element.hasAttributeNS(null, "replaceValues")) {
        replaceValues = XMLHelper.getAttributeValueAsBoolean(element.getAttributeNodeNS(null, "replaceValues"));
    }
    builder.addPropertyValue("replaceValues", replaceValues);

    boolean retainAll = false;
    if (element.hasAttributeNS(null, "retainAll")) {
        retainAll = XMLHelper.getAttributeValueAsBoolean(element.getAttributeNodeNS(null, "retainAll"));
    }
    builder.addPropertyValue("retainAll", retainAll);
}

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

/**
 * Processes the cache configuration options.
 * //from  w ww.  j  ava2 s  .c  o  m
 * @param pluginId ID of the data connector
 * @param pluginConfig configuration element for the data connector
 * @param pluginConfigChildren child config elements for the data connect
 * @param pluginBuilder builder of the data connector
 * @param parserContext current configuration parsing context
 */
protected void processCacheConfig(String pluginId, Element pluginConfig,
        Map<QName, List<Element>> pluginConfigChildren, BeanDefinitionBuilder pluginBuilder,
        ParserContext parserContext) {
    boolean cacheResults = false;
    String cacheManagerId = "shibboleth.CacheManager";
    long cacheElementTtl = 4 * 60 * 60 * 1000;
    int maximumCachedElements = 500;

    List<Element> cacheConfigs = XMLHelper.getChildElementsByTagNameNS(pluginConfig,
            DataConnectorNamespaceHandler.NAMESPACE, "ResultCache");
    if (cacheConfigs != null && !cacheConfigs.isEmpty()) {
        Element cacheConfig = cacheConfigs.get(0);

        cacheResults = true;

        if (cacheConfig.hasAttributeNS(null, "cacheManagerRef")) {
            cacheManagerId = DatatypeHelper.safeTrim(cacheConfig.getAttributeNS(null, "cacheManagerRef"));
        }

        if (cacheConfig.hasAttributeNS(null, "elementTimeToLive")) {
            cacheElementTtl = SpringConfigurationUtils.parseDurationToMillis(
                    "elementTimeToLive on data connector " + pluginId,
                    cacheConfig.getAttributeNS(null, "elementTimeToLive"), 0);
        }

        if (cacheConfig.hasAttributeNS(null, "maximumCachedElements")) {
            maximumCachedElements = Integer.parseInt(
                    DatatypeHelper.safeTrim(cacheConfig.getAttributeNS(null, "maximumCachedElements")));
        }
    }

    if (pluginConfig.hasAttributeNS(null, "cacheResults")) {
        log.warn(
                "Data connection {}: use of 'cacheResults' attribute is deprecated.  Use <ResultCache> instead.",
                pluginId);
        cacheResults = XMLHelper
                .getAttributeValueAsBoolean(pluginConfig.getAttributeNodeNS(null, "cacheResults"));
    }

    if (cacheResults) {
        log.debug("Data connector {} is caching results: {}", pluginId, cacheResults);

        pluginBuilder.addPropertyReference("cacheManager", cacheManagerId);

        log.debug("Data connector {} cache element time to live: {}ms", pluginId, cacheElementTtl);
        pluginBuilder.addPropertyValue("cacheElementTimeToLive", cacheElementTtl);

        log.debug("Data connector {} maximum number of caches elements: {}", pluginId, maximumCachedElements);
        pluginBuilder.addPropertyValue("maximumCachedElements", maximumCachedElements);
    }

}

From source file:edu.internet2.middleware.shibboleth.common.config.metadata.HTTPMetadataProviderBeanDefinitionParser.java

/**
 * Sets the HTTP proxy properties, if any, for the HTTP client used to fetch metadata.
 * /*from ww w .ja  va2 s .c o m*/
 * @param builder the HTTP client builder
 * @param config the metadata provider configuration
 * @param providerId the ID of the metadata provider
 */
protected void setHttpProxySettings(HttpClientBuilder builder, Element config, String providerId) {
    String proxyHost = DatatypeHelper.safeTrimOrNullString(config.getAttributeNS(null, "proxyHost"));
    if (proxyHost == null) {
        return;
    }
    log.debug("Metadata provider '{}' HTTP proxy host: {}", providerId, proxyHost);
    builder.setProxyHost(proxyHost);

    if (config.hasAttributeNS(null, "proxyPort")) {
        int proxyPort = Integer.parseInt(config.getAttributeNS(null, "proxyPort"));
        log.debug("Metadata provider '{}' HTTP proxy port: ", providerId, proxyPort);
        builder.setProxyPort(proxyPort);
    }

    String proxyUser = DatatypeHelper.safeTrimOrNullString(config.getAttributeNS(null, "proxyUser"));
    if (proxyUser != null) {
        log.debug("Metadata provider '{}' HTTP proxy username: ", providerId, proxyUser);
        builder.setProxyUsername(proxyUser);
        log.debug("Metadata provider '{}' HTTP proxy password not shown", providerId);
        builder.setProxyPassword(
                DatatypeHelper.safeTrimOrNullString(config.getAttributeNS(null, "proxyPassword")));
    }
}

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

/**
 * Gets the value of the {@value #CTX_TIMEOUT_ATTRIB_NAME} attribute.
 * // www .jav  a2 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.
 * //from   w  w w . java2  s. c  om
 * @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:edu.internet2.middleware.shibboleth.common.config.resource.SVNResourceBeanDefinitionParser.java

/**
 * Gets the value of the {@value #PASSWORD_ATTRIB_NAME} attribute.
 * /*  w w w.  j  ava 2s .co m*/
 * @param configElement resource configuration element
 * 
 * @return value of the attribute
 * 
 * @throws BeanCreationException thrown if the attribute is present but contains an empty string
 */
protected String getPassword(Element configElement) throws BeanCreationException {
    if (configElement.hasAttributeNS(null, PASSWORD_ATTRIB_NAME)) {
        String password = DatatypeHelper
                .safeTrimOrNullString(configElement.getAttributeNS(null, PASSWORD_ATTRIB_NAME));
        if (password == null) {
            log.error("SVN resource definition attribute '" + PASSWORD_ATTRIB_NAME
                    + "' may not be an empty string");
            throw new BeanCreationException("SVN resource definition attribute '" + PASSWORD_ATTRIB_NAME
                    + "' may not be an empty string");
        }
        return password;
    }
    return null;
}