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:com.mtgi.analytics.aop.config.v11.BtJdbcPersisterBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    //configure ID generator settings
    NodeList children = element.getElementsByTagNameNS("*", ELT_ID_SQL);
    if (children.getLength() == 1) {
        BeanDefinition def = builder.getRawBeanDefinition();
        MutablePropertyValues props = def.getPropertyValues();

        Element child = (Element) children.item(0);
        String sql = child.getTextContent();
        if (StringUtils.hasText(sql))
            props.addPropertyValue("idSql", sql);

        if (child.hasAttribute(ATT_INCREMENT))
            props.addPropertyValue("idIncrement", child.getAttribute(ATT_INCREMENT));
    }//from   w  w w. jav  a 2 s.c o  m

    //configure nested dataSource
    NodeList nodes = element.getElementsByTagNameNS("*", "data-source");
    if (nodes.getLength() == 1) {
        Element ds = (Element) nodes.item(0);
        ds.setAttribute("name", "dataSource");
        parserContext.getDelegate().parsePropertyElement(ds, builder.getRawBeanDefinition());
    }

    //push persister into parent manager bean, if applicable
    if (parserContext.isNested()) {
        AbstractBeanDefinition def = builder.getBeanDefinition();
        String id = element.hasAttribute("id") ? element.getAttribute("id")
                : BeanDefinitionReaderUtils.generateBeanName(def,
                        parserContext.getReaderContext().getRegistry(), true);
        BeanDefinitionHolder holder = new BeanDefinitionHolder(def, id);
        BtManagerBeanDefinitionParser.registerNestedBean(holder, "persister", parserContext);
    }
}

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

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(JavaWhitelistPatternProcessor.class);
    beanBuilder.addPropertyValue("regexPattern", element.getAttribute("regex"));
    if (element.hasAttribute("source-type")) {
        beanBuilder.addPropertyValue("sourceType", element.getAttribute("source-type"));
    }//from   w w w .  j  a  v a  2  s .c  om

    return beanBuilder.getBeanDefinition();
}

From source file:matteroverdrive.gui.pages.PageGuideDescription.java

private Map<String, String> loadStyleSheetMap(Element element) {
    if (element.hasAttribute("stylesheet")) {
        try {//from w w  w  .  jav  a2s  . co  m
            Map<String, String> styleMap = new HashMap<>();
            InputStream stylesheetStream = Minecraft.getMinecraft().getResourceManager()
                    .getResource(new ResourceLocation(element.getAttribute("stylesheet"))).getInputStream();
            String rawStyle = IOUtils.toString(stylesheetStream, "UTF-8");
            rawStyle = rawStyle.replaceAll("\\r|\\n|\\s+", "");
            rawStyle = rawStyle.replaceAll("(?s)/\\*.*?\\*/", ""); //remove comments
            Matcher matcher = Pattern.compile("([^\\}\\{]+)(\\{[^\\}]+\\})", Pattern.DOTALL | Pattern.MULTILINE)
                    .matcher(rawStyle);
            while (matcher.find()) {
                styleMap.put(matcher.group(1), matcher.group(2).substring(1, matcher.group(2).length() - 1));
            }
            return styleMap;
        } catch (IOException e) {
            MatterOverdrive.log.log(Level.ERROR, e, "There was a problem loading the stylesheet");
        }
    }
    return null;
}

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

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

    if (element.hasAttribute("source-type")) {
        beanBuilder.addPropertyValue("sourceType", element.getAttribute("source-type"));
    }//  ww  w . j  a v  a  2 s.  c o  m

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

    return beanBuilder.getBeanDefinition();
}

From source file:io.wcm.tooling.commons.contentpackagebuilder.XmlContentBuilder.java

private boolean hasAttributeNamespaceAware(Element element, String key) {
    String namespace = getNamespace(key);
    if (namespace == null) {
        return element.hasAttribute(key);
    } else {/*from  w  w  w .j  a v a 2  s  . c  o m*/
        return element.hasAttributeNS(namespace, key);
    }
}

From source file:org.xmatthew.spy2servers.component.config.SunJVMJmxSpyComponentParser.java

protected void doParse(Element element, BeanDefinitionBuilder builder) {
    super.doParse(element, builder);

    String host = element.getAttribute("host");
    builder.addPropertyValue("host", host);

    if (element.hasAttribute("port")) {
        String port = element.getAttribute("port");
        builder.addPropertyValue("port", port);
    }//from w w  w  .  jav  a 2  s  .  c  o m
    if (element.hasAttribute("detectInterval")) {
        String detectInterval = element.getAttribute("detectInterval");
        builder.addPropertyValue("detectInterval", detectInterval);
    }
    if (element.hasAttribute("queueSuspendNotifyTime")) {
        String queueSuspendNotifyTime = element.getAttribute("queueSuspendNotifyTime");
        builder.addPropertyValue("queueSuspendNotifyTime", queueSuspendNotifyTime);
    }

    MemorySpy heapMemorySpy = null;
    MemorySpy noneHeapMemorySpy = null;
    FileSpy fileSpy = null;

    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            String localName = child.getLocalName();
            if (HEAP_MEMORY_ELEMENT.equals(localName)) {
                heapMemorySpy = IntegrationNamespaceUtils.parseMemorySpy((Element) child);
            } else if (NONE_HEAP_MEMORY_ELEMENT.equals(localName)) {
                noneHeapMemorySpy = IntegrationNamespaceUtils.parseMemorySpy((Element) child);
            } else if (FILE_SPY_ELEMENT.equals(localName)) {
                fileSpy = IntegrationNamespaceUtils.parseFileSpy((Element) child);
            }
        }
    }

    if (heapMemorySpy != null) {
        builder.addPropertyValue("heapMemorySpy", heapMemorySpy);
    }
    if (noneHeapMemorySpy != null) {
        builder.addPropertyValue("noneHeapMemorySpy", noneHeapMemorySpy);
    }
    if (fileSpy != null) {
        builder.addPropertyValue(FILE_SPY_ELEMENT, fileSpy);
    }
    builder.setScope(BeanDefinition.SCOPE_SINGLETON);
}

From source file:biz.webgate.domino.mywebgate.util.URLFetcher.java

private void check4OpenGraphTags(NodeList ndlMeta, String strBaseURL) {
    for (int nCounter = 0; nCounter < ndlMeta.getLength(); nCounter++) {
        Element elMeta = (Element) ndlMeta.item(nCounter);
        // Test if property is available
        if (elMeta.hasAttribute("property")) {
            String strProperty = elMeta.getAttribute("property");
            // CHECK if we have a OpenGraphProperty
            if (strProperty.toLowerCase().startsWith("og:")) {
                m_OpenGraph.put(strProperty, elMeta.getAttribute("content"));
            }/*ww w . j  a  v a2s . co  m*/
            if ("og:image".equalsIgnoreCase(strProperty)) {
                String strImage = checkIMAGEURL(elMeta.getAttribute("content"), strBaseURL);
                m_ThumbNails.add(strImage);
            }
            if ("og:title".equalsIgnoreCase(strProperty)) {
                m_Title = elMeta.getAttribute("content");
            }
            if ("og:url".equalsIgnoreCase(strProperty)) {
                m_URLContent = elMeta.getAttribute("content");
            }
            if ("og:description".equalsIgnoreCase(strProperty)) {
                m_Description = elMeta.getAttribute("content");
            }
        }
    }
}

From source file:org.jmxtrans.embedded.spring.EmbeddedJmxTransBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    builder.setRole(BeanDefinition.ROLE_APPLICATION);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));

    if (element.hasAttribute(IGNORE_CONFIGURATION_NOT_FOUND_ATTRIBUTE)) {
        builder.addPropertyValue("ignoreConfigurationNotFound",
                element.getAttribute(IGNORE_CONFIGURATION_NOT_FOUND_ATTRIBUTE));
    }// w w  w.j  a va2s. c  om
    List<String> configurationUrls = new ArrayList<String>();
    if (element.hasAttribute(CONFIGURATION_ATTRIBUTE)) {
        String configurationUrl = element.getAttribute(CONFIGURATION_ATTRIBUTE);
        logger.debug("Add configuration from attribute {}", configurationUrl);
        configurationUrls.add(configurationUrl);
    }

    NodeList configurationNodeList = element.getElementsByTagNameNS(element.getNamespaceURI(),
            CONFIGURATION_ATTRIBUTE);
    for (int i = 0; i < configurationNodeList.getLength(); i++) {
        Node node = configurationNodeList.item(i);
        if (node instanceof Element) {
            String configurationUrl = node.getTextContent();
            logger.debug("Add configuration from attribute {}", configurationUrl);
            configurationUrls.add(configurationUrl);
        } else {
            throw new EmbeddedJmxTransException("Invalid configuration child element " + node);
        }

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

From source file:cz.incad.kramerius.service.replication.ExternalReferencesFormat.java

private void processDataStreamVersions(Document document, Element dataStreamElm) throws ReplicateException {
    List<Element> versions = XMLUtils.getElements(dataStreamElm, new XMLUtils.ElementsFilter() {

        @Override/*from  w w w. j  a  va2  s .  c  o m*/
        public boolean acceptElement(Element element) {
            String locName = element.getLocalName();
            return locName.endsWith("datastreamVersion");
        }
    });

    for (Element version : versions) {
        Element found = XMLUtils.findElement(version, "contentLocation", version.getNamespaceURI());
        if (found != null && found.hasAttribute("REF")) {
            try {
                URL url = new URL(found.getAttribute("REF"));
                String protocol = url.getProtocol();
                if (protocol.equals("file")) {
                    changeDatastreamVersion(document, dataStreamElm, version, url);
                }
            } catch (MalformedURLException e) {
                throw new ReplicateException(e);
            } catch (IOException e) {
                throw new ReplicateException(e);
            }
        }
    }
}

From source file:fitnesse.wiki.WikiPageProperties.java

private void LoadElement(WikiPageProperty context, Element element, String key) {
    WikiPageProperty newProperty = new WikiPageProperty();
    context.set(key, newProperty);//from w  ww . jav a  2 s .c  o  m

    NodeList nodes = element.getChildNodes();
    if (element.hasAttribute("value"))
        newProperty.setValue(element.getAttribute("value"));
    else if (nodes.getLength() == 1)
        newProperty.setValue(nodes.item(0).getNodeValue());

    for (int i = 0; i < nodes.getLength(); i++) {
        Node childNode = nodes.item(i);
        if (childNode instanceof Element)
            LoadElement(newProperty, (Element) childNode, childNode.getNodeName());
    }
}