Example usage for org.w3c.dom Element hasAttribute

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

Introduction

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

Prototype

public boolean hasAttribute(String name);

Source Link

Document

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

Usage

From source file:DomUtils.java

/**
 * Get attribute value, returning <code>null</code> if unset.
 * <p/>// w  w w.j  a  v  a  2 s  .  c  o m
 * Some DOM implementations return an empty string for an unset
 * attribute.
 * @param element The DOM element.
 * @param attributeName The attribute to get.
 * @param namespaceURI Namespace URI of the required attribute, or null
 * to perform a non-namespaced get.
 * @return The attribute value, or <code>null</code> if unset.
 */
public static String getAttributeValue(Element element, String attributeName, String namespaceURI) {

    String attributeValue;

    if (namespaceURI == null) {
        attributeValue = element.getAttribute(attributeName);
    } else {
        attributeValue = element.getAttributeNS(namespaceURI, attributeName);
    }

    if (attributeValue.length() == 0 && !element.hasAttribute(attributeName)) {
        return null;
    }

    return attributeValue;
}

From source file:com.predic8.membrane.annot.parser.BlueprintElementParser.java

protected void setPropertyIfSet(ParserContext context, String xmlPropertyName, String springPropertyName,
        Element element, MutableBeanMetadata mcm, boolean flexibleEnum) {
    if (element.hasAttribute(xmlPropertyName))
        setProperty(context, xmlPropertyName, springPropertyName, element, mcm, flexibleEnum);
}

From source file:org.jboss.windup.config.spring.namespace.simple.GlobalBeanParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder.rootBeanDefinition(GlobalDecorator.class);
    beanBuilder.addPropertyValue("description", element.getAttribute("description"));

    if (element.hasAttribute("effort")) {
        beanBuilder.addPropertyValue("effort", Integer.parseInt(element.getAttribute("effort")));
    }/*from www. j a v a  2 s.  com*/

    return beanBuilder.getBeanDefinition();
}

From source file:org.jboss.windup.config.spring.namespace.simple.SummaryBeanParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder.rootBeanDefinition(SummaryDecorator.class);
    beanBuilder.addPropertyValue("description", element.getAttribute("description"));

    if (element.hasAttribute("effort")) {
        beanBuilder.addPropertyValue("effort", Integer.parseInt(element.getAttribute("effort")));
    }//from  w  ww .  j a  v  a2  s .c o m

    return beanBuilder.getBeanDefinition();
}

From source file:org.jboss.windup.config.spring.namespace.gate.RegexFileGateBeanParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder.rootBeanDefinition(RegexFileGateDecorator.class);
    beanBuilder.addPropertyValue("regexPattern", element.getAttribute("regex"));

    if (element.hasAttribute("full-path")) {
        beanBuilder.addPropertyValue("fullPath", element.getAttribute("full-path"));
    }/* w w  w  . j  av  a2 s . c o  m*/

    SpringNamespaceHandlerUtil.setNestedList(beanBuilder, element, "decorators", parserContext);

    return beanBuilder.getBeanDefinition();
}

From source file:org.jboss.windup.config.spring.namespace.simple.ClassificationBeanParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder.rootBeanDefinition(ClassificationDecorator.class);
    beanBuilder.addPropertyValue("description", element.getAttribute("description"));

    if (element.hasAttribute("effort")) {
        beanBuilder.addPropertyValue("effort", Integer.parseInt(element.getAttribute("effort")));
    }/*www  .  j  a  v a  2 s. c o  m*/

    return beanBuilder.getBeanDefinition();
}

From source file:org.urbantower.j4s.spring.ServletContextHandlerParser.java

/**
 * method creates servlet mapping/*  www.j  a v a  2 s  . c  om*/
 */
private ServletMapping createMapping(Element servletElm, ServletHandler handler, String servletName) {
    List<String> paths = new LinkedList<>();
    if (servletElm.hasAttribute("url-pattern")) {
        paths.add(servletElm.getAttribute("url-pattern"));
    }

    List<Element> mappings = DomUtils.getChildElementsByTagName(servletElm, "url-pattern");
    for (Element m : mappings) {
        paths.add(m.getAttribute("url-pattern"));
    }

    if (paths.isEmpty()) {
        paths.add("/*");
    }

    ServletMapping mapping = new ServletMapping();
    mapping.setPathSpecs(paths.toArray(new String[] {}));
    mapping.setServletName(servletName);

    return mapping;
}

From source file:pl.bristleback.server.bristle.conf.namespace.BristlebackSecurityBeanDefinitionParser.java

private void addAuthenticationBeans(Element element, ParserContext parserContext) {
    addInterceptorBeans(parserContext);/*w w w  .j  ava 2 s. co  m*/

    boolean useDefaultAuthenticationAction = element.hasAttribute("userDetailsService");
    if (useDefaultAuthenticationAction) {
        registerAuthenticationActionBean(element, parserContext);
    }
    boolean useDefaultLogoutAction = Boolean.valueOf(element.getAttribute("useDefaultLogoutAction"));
    if (useDefaultLogoutAction) {
        registerLogoutAction(parserContext);
    }
    registerAuthenticationInformer(parserContext);

    registerUserDisconnectionListener(parserContext);
}

From source file:com.predic8.membrane.annot.parser.BlueprintElementParser.java

protected void setIdIfNeeded(Element element, ParserContext context, String defaultId) {
    if (!isInlined() && !element.hasAttribute("id")) {
        Set<String> names = context.getComponentDefinitionRegistry().getComponentDefinitionNames();
        for (int i = 0;; i++) {
            String id = defaultId + (i == 0 ? "" : i);
            if (!names.contains(id)) {
                element.setAttribute("id", id);
                return;
            }//from w  ww .  jav a2  s .co  m
        }
    }
}

From source file:org.urbantower.j4s.spring.WebAppContextParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SpringWebAppContext.class);
    builder.addPropertyValue("contextPath", element.getAttribute("context-path"));

    if (element.hasAttribute("war")) {
        builder.addPropertyValue("war", element.getAttribute("war"));
    } else {/*w w  w .  j  av  a2  s . c om*/
        builder.addPropertyValue("descriptor", element.getAttribute("descriptor"));
        builder.addPropertyValue("resourceBase", element.getAttribute("resource-base"));
    }

    return builder.getBeanDefinition();
}