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.attribute.resolver.dataConnector.RDBMSDataConnectorBeanDefinitionParser.java

/**
 * Builds a JDBC {@link javax.sql.DataSource} from a ContainerManagedConnection configuration element.
 * //from  w  w w  . j av a  2  s .c  om
 * @param pluginId ID of this data connector
 * @param cmc the container managed configuration element
 * 
 * @return the built data source
 */
protected DataSource buildContainerManagedConnection(String pluginId, Element cmc) {
    String jndiResource = cmc.getAttributeNS(null, "resourceName");
    jndiResource = DatatypeHelper.safeTrim(jndiResource);

    Hashtable<String, String> initCtxProps = buildProperties(XMLHelper.getChildElementsByTagNameNS(cmc,
            DataConnectorNamespaceHandler.NAMESPACE, "JNDIConnectionProperty"));
    try {
        InitialContext initCtx = new InitialContext(initCtxProps);
        DataSource dataSource = (DataSource) initCtx.lookup(jndiResource);
        if (dataSource == null) {
            log.error("DataSource " + jndiResource + " did not exist in JNDI directory");
            throw new BeanCreationException("DataSource " + jndiResource + " did not exist in JNDI directory");
        }
        if (log.isDebugEnabled()) {
            log.debug("Retrieved data source for data connector {} from JNDI location {} using properties ",
                    pluginId, initCtxProps);
        }
        return dataSource;
    } catch (NamingException e) {
        log.error("Unable to retrieve data source for data connector " + pluginId + " from JNDI location "
                + jndiResource + " using properties " + initCtxProps, e);
        return null;
    }
}

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

/** {@inheritDoc} */
protected void doParse(Element config, ParserContext parserContext, BeanDefinitionBuilder builder) {
    String rpId = getRelyingPartyId(config);
    log.info("Parsing configuration for relying party with id: {}", rpId);
    builder.addPropertyValue("relyingPartyId", rpId);

    String provider = DatatypeHelper.safeTrimOrNullString(config.getAttributeNS(null, "provider"));
    log.debug("Relying party configuration - provider ID: {}", provider);
    builder.addPropertyValue("providerId", provider);

    String authnMethod = DatatypeHelper
            .safeTrimOrNullString(config.getAttributeNS(null, "defaultAuthenticationMethod"));
    log.debug("Relying party configuration - default authentication method: {}", authnMethod);
    builder.addPropertyValue("defaultAuthenticationMethod", authnMethod);

    String secCredRef = DatatypeHelper
            .safeTrimOrNullString(config.getAttributeNS(null, "defaultSigningCredentialRef"));
    if (secCredRef != null) {
        log.debug("Relying party configuration - default signing credential: {}", secCredRef);
        builder.addPropertyReference("defaultSigningCredential", secCredRef);
    }//from w  w w . java 2s .  co m

    Attr precedenceAttr = config.getAttributeNodeNS(null, "nameIDFormatPrecedence");
    if (precedenceAttr != null) {
        List<String> precedence = XMLHelper.getAttributeValueAsList(precedenceAttr);
        log.debug("Relying party configuration - NameID format precedence: {}", precedence);
        builder.addPropertyValue("nameIdFormatPrecedence", precedence);
    }

    List<Element> profileConfigs = XMLHelper.getChildElementsByTagNameNS(config,
            RelyingPartyNamespaceHandler.NAMESPACE, "ProfileConfiguration");
    if (profileConfigs != null && profileConfigs.size() > 0) {
        log.debug("Relying party configuration - {} profile configurations", profileConfigs.size());
        builder.addPropertyValue("profileConfigurations",
                SpringConfigurationUtils.parseInnerCustomElements(profileConfigs, parserContext));
    }
}

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

/**
 * Builds a JDBC {@link javax.sql.DataSource} from an ApplicationManagedConnection configuration element.
 * //www.j  a  v a2s.  c o m
 * @param pluginId ID of this data connector
 * @param amc the application managed configuration element
 * 
 * @return the built data source
 */
protected DataSource buildApplicationManagedConnection(String pluginId, Element amc) {
    ComboPooledDataSource datasource = new ComboPooledDataSource();

    String driverClass = DatatypeHelper.safeTrim(amc.getAttributeNS(null, "jdbcDriver"));
    ClassLoader classLoader = this.getClass().getClassLoader();
    try {
        classLoader.loadClass(driverClass);
    } catch (ClassNotFoundException e) {
        log.error(
                "Unable to create relational database connector, JDBC driver can not be found on the classpath");
        throw new BeanCreationException(
                "Unable to create relational database connector, JDBC driver can not be found on the classpath");
    }

    try {
        datasource.setDriverClass(driverClass);
        datasource.setJdbcUrl(DatatypeHelper.safeTrim(amc.getAttributeNS(null, "jdbcURL")));
        datasource.setUser(DatatypeHelper.safeTrim(amc.getAttributeNS(null, "jdbcUserName")));
        datasource.setPassword(DatatypeHelper.safeTrim(amc.getAttributeNS(null, "jdbcPassword")));

        if (amc.hasAttributeNS(null, "poolAcquireIncrement")) {
            datasource.setAcquireIncrement(Integer
                    .parseInt(DatatypeHelper.safeTrim(amc.getAttributeNS(null, "poolAcquireIncrement"))));
        } else {
            datasource.setAcquireIncrement(3);
        }

        if (amc.hasAttributeNS(null, "poolAcquireRetryAttempts")) {
            datasource.setAcquireRetryAttempts(Integer
                    .parseInt(DatatypeHelper.safeTrim(amc.getAttributeNS(null, "poolAcquireRetryAttempts"))));
        } else {
            datasource.setAcquireRetryAttempts(36);
        }

        if (amc.hasAttributeNS(null, "poolAcquireRetryDelay")) {
            datasource.setAcquireRetryDelay(Integer
                    .parseInt(DatatypeHelper.safeTrim(amc.getAttributeNS(null, "poolAcquireRetryDelay"))));
        } else {
            datasource.setAcquireRetryDelay(5000);
        }

        if (amc.hasAttributeNS(null, "poolBreakAfterAcquireFailure")) {
            datasource.setBreakAfterAcquireFailure(XMLHelper
                    .getAttributeValueAsBoolean(amc.getAttributeNodeNS(null, "poolBreakAfterAcquireFailure")));
        } else {
            datasource.setBreakAfterAcquireFailure(true);
        }

        if (amc.hasAttributeNS(null, "poolMinSize")) {
            datasource.setMinPoolSize(
                    Integer.parseInt(DatatypeHelper.safeTrim(amc.getAttributeNS(null, "poolMinSize"))));
        } else {
            datasource.setMinPoolSize(2);
        }

        if (amc.hasAttributeNS(null, "poolMaxSize")) {
            datasource.setMaxPoolSize(
                    Integer.parseInt(DatatypeHelper.safeTrim(amc.getAttributeNS(null, "poolMaxSize"))));
        } else {
            datasource.setMaxPoolSize(50);
        }

        if (amc.hasAttributeNS(null, "poolMaxIdleTime")) {
            datasource.setMaxIdleTime(
                    Integer.parseInt(DatatypeHelper.safeTrim(amc.getAttributeNS(null, "poolMaxIdleTime"))));
        } else {
            datasource.setMaxIdleTime(600);
        }

        if (amc.hasAttributeNS(null, "poolIdleTestPeriod")) {
            datasource.setIdleConnectionTestPeriod(
                    Integer.parseInt(DatatypeHelper.safeTrim(amc.getAttributeNS(null, "poolIdleTestPeriod"))));
        } else {
            datasource.setIdleConnectionTestPeriod(180);
        }

        datasource.setMaxStatementsPerConnection(10);

        log.debug("Created application managed data source for data connector {}", pluginId);
        return datasource;
    } catch (PropertyVetoException e) {
        log.error("Unable to create data source for data connector {} with JDBC driver class {}", pluginId,
                driverClass);
        return null;
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.attributeDefinition.ScriptedAttributeDefinitionBeanDefinitionParser.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);

    String scriptLanguage = "javascript";
    if (pluginConfig.hasAttributeNS(null, "language")) {
        scriptLanguage = pluginConfig.getAttributeNS(null, "language");
    }/* ww w .jav a 2  s .  c om*/
    log.debug("Attribute definition {} scripting language: {}", pluginId, scriptLanguage);
    pluginBuilder.addPropertyValue("language", scriptLanguage);

    String script = null;
    List<Element> scriptElem = pluginConfigChildren
            .get(new QName(AttributeDefinitionNamespaceHandler.NAMESPACE, "Script"));
    if (scriptElem != null && scriptElem.size() > 0) {
        script = scriptElem.get(0).getTextContent();
    } else {
        List<Element> scriptFileElem = pluginConfigChildren
                .get(new QName(AttributeDefinitionNamespaceHandler.NAMESPACE, "ScriptFile"));
        if (scriptFileElem != null && scriptFileElem.size() > 0) {
            String scriptFile = scriptFileElem.get(0).getTextContent();
            try {
                script = DatatypeHelper.inputstreamToString(new FileInputStream(scriptFile), null);
            } catch (IOException e) {
                throw new BeanCreationException("Unable to read script file " + scriptFile, e);
            }
        }
    }

    if (script == null) {
        throw new BeanCreationException("No script specified for this attribute definition");
    }
    log.debug("Attribute definition {} script: {}", pluginId, script);
    pluginBuilder.addPropertyValue("script", script);
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.attributeDefinition.TransientIdAttributeDefinitionBeanDefinitionParser.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);

    if (pluginConfig.hasAttributeNS(null, "lifetime")) {
        long lifetime = SpringConfigurationUtils.parseDurationToMillis(
                "lifetime on attribute definition " + pluginId, pluginConfig.getAttributeNS(null, "lifetime"),
                0);/*w  w  w . j  a  va2 s . c o  m*/
        pluginBuilder.addPropertyValue("identifierLifetime", lifetime);
    }

    pluginBuilder.addPropertyReference("identifierStore",
            DatatypeHelper.safeTrimOrNullString(pluginConfig.getAttributeNS(null, "storageServiceRef")));
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.attributeDefinition.SAML1NameIdentifierAttributeDefinitionBeanDefinitionParser.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);

    String nameIdFormat = "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified";
    if (pluginConfig.hasAttributeNS(null, "nameIdFormat")) {
        nameIdFormat = DatatypeHelper.safeTrimOrNullString(pluginConfig.getAttributeNS(null, "nameIdFormat"));
    }/*from   w  w w  .  j a  v a  2s .c  om*/
    pluginBuilder.addPropertyValue("nameIdFormat", nameIdFormat);

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

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

/**
 * Builds a hash from PropertyType elements.
 * // ww  w.j a v  a2 s  .  c om
 * @param propertyElements properties elements
 * 
 * @return properties extracted from elements, key is the property name.
 */
protected Hashtable<String, String> buildProperties(List<Element> propertyElements) {
    if (propertyElements == null || propertyElements.size() < 1) {
        return null;
    }

    Hashtable<String, String> properties = new Hashtable<String, String>();

    String propName;
    String propValue;
    for (Element propertyElement : propertyElements) {
        propName = DatatypeHelper.safeTrim(propertyElement.getAttributeNS(null, "name"));
        propValue = DatatypeHelper.safeTrim(propertyElement.getAttributeNS(null, "value"));
        properties.put(propName, propValue);
    }

    return properties;
}

From source file:de.betterform.agent.web.flux.FluxProcessor.java

/**
 * listen to processor with XMLEvents and add a xmlEvent object to the
 * EventQueue for every incoming DOM Event from the processor.
 *
 * @param event the handled DOMEvent//from ww  w.j  a  v a  2 s  .c o m
 */
public void handleEvent(Event event) {
    super.handleEvent(event);
    try {
        if (event instanceof XMLEvent) {
            XMLEvent xmlEvent = (XMLEvent) event;
            String type = xmlEvent.getType();

            if (BetterFormEventNames.REPLACE_ALL.equals(type)
                    || BetterFormEventNames.REPLACE_ALL_XFORMS.equals(type)) {
                // get event context and store it in session
                Map submissionResponse = new HashMap();
                submissionResponse.put("header", xmlEvent.getContextInfo("header"));
                submissionResponse.put("body", xmlEvent.getContextInfo("body"));
                this.xformsProcessor.setContextParam(WebFactory.BETTERFORM_SUBMISSION_RESPONSE,
                        submissionResponse);

                // add event properties to log
                xmlEvent.addProperty("webcontext", (String) getContextParam("contextroot"));
                this.eventQueue.add(xmlEvent);

                this.exitEvent = xmlEvent;
                shutdown();
                return;
            } else if (BetterFormEventNames.LOAD_URI.equals(type)) {
                // get event properties
                String show = (String) xmlEvent.getContextInfo("show");
                if ("embed".equals(show)) {
                    Element targetElement = (Element) xmlEvent.getContextInfo("targetElement");
                    StringWriter result = new StringWriter();
                    generateUI(targetElement, result);
                    xmlEvent.addProperty("targetElement", result.toString());
                    /*
                                            if(LOGGER.isDebugEnabled()) {
                    DOMUtil.prettyPrintDOM(targetElement);
                    LOGGER.debug("xf:load show=\"embed\" Markup: \n" + result.toString() +"\n");
                                            }
                                            DOMUtil.prettyPrintDOM(targetElement);
                                            System.out.println("xf:load show=\"embed\" Markup: \n" + result.toString() +"\n");
                    */
                }

                // add event to log
                this.eventQueue.add(xmlEvent);
                if ("replace".equals(show)) {
                    this.exitEvent = xmlEvent;
                    shutdown();
                    //this.xformsSession.getManager().deleteXFormsSession(this.xformsSession.getKey());
                    WebUtil.removeSession(getKey());
                }

                return;
            } else if (BetterFormEventNames.STATE_CHANGED.equals(type)) {
                /*
                todo: This is a HACK cause BETTERFORM_STATE_CHANGED events are not sent consistently. For some reason
                todo: datatype changes are not always signalled e.g. when the datatype changes from a 'date' to
                todo: a 'string'. This should be fixed in betterForm Core - after that this branch should be removed again.
                 */

                // get event properties
                Element target = (Element) event.getTarget();
                String targetId = target.getAttributeNS(null, "id");
                String targetName = target.getLocalName();
                String dataType = (String) xmlEvent.getContextInfo("type");
                if (dataType == null) {
                    XFormsElement control = lookup(targetId);

                    //todo: this is copied from EventLog code - this is really a HACK!
                    if (EventQueue.HELPER_ELEMENTS.contains(targetName)) {
                        String parentId = ((Element) target.getParentNode()).getAttributeNS(null, "id");
                        xmlEvent.addProperty("parentId", parentId);
                    } else if (control instanceof BindingElement) {
                        if (LOGGER.isDebugEnabled()) {
                            DOMUtil.prettyPrintDOM(control.getElement());
                        }

                        Element bfData = DOMUtil.getChildElement(control.getElement(),
                                NamespaceConstants.BETTERFORM_PREFIX + ":data");
                        if (bfData != null) {
                            String internalType = bfData.getAttributeNS(NamespaceConstants.BETTERFORM_NS,
                                    "type");
                            xmlEvent.addProperty("type", internalType);
                        }
                    }
                }
                this.eventQueue.add(xmlEvent);
                return;
            } else if (XFormsEventNames.VERSION_EXCEPTION.equals(type)) {
                WebUtil.removeSession(getKey());
                xmlEvent.addProperty("errorinformation", xmlEvent.getContextInfo().get("error-information"));
            }
            this.eventQueue.add(xmlEvent);
        }
    } catch (Exception e) {
        handleEventException(e);
    }
}

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

/**
 * Build the POJO with the username and password.
 * //  w ww. jav  a2s.  c  om
 * @param element the HTTPMetadataProvider parser.
 * @return the bean definition with the username and password.
 */
private BeanDefinition buildBasicCredentials(Element element) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder
            .genericBeanDefinition(UsernamePasswordCredentials.class);

    builder.setLazyInit(true);

    builder.addConstructorArgValue(StringSupport.trimOrNull(element.getAttributeNS(null, BASIC_AUTH_USER)));
    builder.addConstructorArgValue(StringSupport.trimOrNull(element.getAttributeNS(null, BASIC_AUTH_PASSWORD)));

    return builder.getBeanDefinition();
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.attributeDefinition.SAML2NameIDAttributeDefinitionBeanDefinitionParser.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);

    String nameIdFormat = "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified";
    if (pluginConfig.hasAttributeNS(null, "nameIdFormat")) {
        nameIdFormat = DatatypeHelper.safeTrimOrNullString(pluginConfig.getAttributeNS(null, "nameIdFormat"));
    }/*ww w  .  j  a  v  a2 s  .  c  o  m*/
    pluginBuilder.addPropertyValue("nameIdFormat", nameIdFormat);

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

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