Example usage for org.w3c.dom Node getLocalName

List of usage examples for org.w3c.dom Node getLocalName

Introduction

In this page you can find the example usage for org.w3c.dom Node getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:org.solmix.runtime.support.spring.AbstractRootBeanDefinitionParser.java

protected void parseAttributes(Element element, ParserContext parserContext, String id,
        RootBeanDefinition beanDefinition) {
    Set<String> props = new HashSet<String>();
    ManagedMap<String, Object> parameters = null;
    for (Method setter : this.type.getMethods()) {
        String name = setter.getName();
        if (name.length() > 3 && name.startsWith("set") && Modifier.isPublic(setter.getModifiers())
                && setter.getParameterTypes().length == 1) {
            Class<?> type = setter.getParameterTypes()[0];
            String property = StringUtils
                    .camelToSplitName(name.substring(3, 4).toLowerCase() + name.substring(4), "-");
            props.add(property);/*from w ww. jav  a 2s .com*/
            Method getter = null;
            try {
                getter = this.type.getMethod("get" + name.substring(3), new Class<?>[0]);
            } catch (NoSuchMethodException e) {
                try {
                    getter = this.type.getMethod("is" + name.substring(3), new Class<?>[0]);
                } catch (NoSuchMethodException e2) {
                }
            }
            if (getter == null || !Modifier.isPublic(getter.getModifiers())
                    || !type.equals(getter.getReturnType())) {
                continue;
            }
            if ("properties".equals(property)) {
                parameters = parseProperties(element.getChildNodes(), beanDefinition);
            } else if ("arguments".equals(property)) {
                parseArguments(id, element.getChildNodes(), beanDefinition, parserContext);
            } else {
                String value = element.getAttribute(property);
                if (value != null && value.trim().length() > 0) {
                    value = value.trim();
                    parserValue(beanDefinition, property, type, value, parserContext);
                }
            }
        }
    }
    NamedNodeMap attributes = element.getAttributes();
    int len = attributes.getLength();
    for (int i = 0; i < len; i++) {
        Node node = attributes.item(i);
        String name = node.getLocalName();
        if (!props.contains(name)) {
            if (parameters == null) {
                parameters = new ManagedMap<String, Object>();
            }
            String value = node.getNodeValue();
            parameters.put(name, new TypedStringValue(value, String.class));
        }
    }
    if (parameters != null) {
        beanDefinition.getPropertyValues().addPropertyValue("properties", parameters);
    }
}

From source file:org.synyx.hades.dao.config.DaoConfigContext.java

/**
 * Creates an instance of {@code XmlDaoConfigContext}.
 * //ww w. j a v  a 2s.  c  om
 * @param daoConfigElement
 */
public DaoConfigContext(final Element daoConfigElement) {

    Assert.notNull(daoConfigElement, "Element must not be null!");

    this.element = daoConfigElement;

    daoContexts = new HashSet<DaoContext>();
    NodeList nodes = daoConfigElement.getChildNodes();

    for (int i = 0; i < nodes.getLength(); i++) {

        Node node = nodes.item(i);

        boolean isElement = Node.ELEMENT_NODE == node.getNodeType();
        boolean isDao = "dao".equals(node.getLocalName());

        if (isElement && isDao) {

            DaoContext daoContext = new DaoContext((Element) node, this);
            daoContext.validate();

            daoContexts.add(daoContext);
        }
    }
}

From source file:org.eclipse.lyo.testsuite.oslcv2.QueryTests.java

public void checkInequalityProperty(NodeList resultList, String queryProperty, String qVal, Document doc) {
    String queryPropertyNS = "*";
    String queryPropertyName = queryProperty;
    if (queryProperty.contains(":")) {
        queryPropertyNS = queryProperty.substring(0, queryProperty.indexOf(':'));
        queryPropertyName = queryProperty.substring(queryProperty.indexOf(':') + 1);
    }// w ww  .  ja v a2  s.c o m
    for (int i = 0; i < resultList.getLength(); i++) {
        NodeList elements = resultList.item(i).getChildNodes();
        for (int j = 0; j < elements.getLength(); j++) {
            Node element = elements.item(j);
            if (element.getLocalName() != null && element.getLocalName().equals(queryPropertyName)
                    && (element.getNamespaceURI().equals(doc.lookupNamespaceURI(queryPropertyNS))
                            || queryPropertyNS.equals("*"))) {
                assertTrue(!element.getTextContent().equals(qVal));
            }
        }
    }
}

From source file:org.eclipse.lyo.testsuite.oslcv2.QueryTests.java

public void checkLessThanProperty(NodeList resultList, String queryProperty, String qVal, Document doc) {
    String queryPropertyNS = "*";
    String queryPropertyName = queryProperty;
    if (queryProperty.contains(":")) {
        queryPropertyNS = queryProperty.substring(0, queryProperty.indexOf(':'));
        queryPropertyName = queryProperty.substring(queryProperty.indexOf(':') + 1);
    }//from  w w w  . j  a v  a2  s.c om
    for (int i = 0; i < resultList.getLength(); i++) {
        NodeList elements = resultList.item(i).getChildNodes();
        for (int j = 0; j < elements.getLength(); j++) {
            Node element = elements.item(j);
            if (element.getLocalName() != null && element.getLocalName().equals(queryPropertyName)
                    && (element.getNamespaceURI().equals(doc.lookupNamespaceURI(queryPropertyNS))
                            || queryPropertyNS.equals("*"))) {
                assertTrue(element.getTextContent().compareTo(qVal) < 0);
            }
        }
    }
}

From source file:org.eclipse.lyo.testsuite.oslcv2.QueryTests.java

public void checkGreaterThanProperty(NodeList resultList, String queryProperty, String qVal, Document doc) {
    String queryPropertyNS = "*";
    String queryPropertyName = queryProperty;
    if (queryProperty.contains(":")) {
        queryPropertyNS = queryProperty.substring(0, queryProperty.indexOf(':'));
        queryPropertyName = queryProperty.substring(queryProperty.indexOf(':') + 1);
    }//  www .  j a v  a 2s. c  om
    for (int i = 0; i < resultList.getLength(); i++) {
        NodeList elements = resultList.item(i).getChildNodes();
        for (int j = 0; j < elements.getLength(); j++) {
            Node element = elements.item(j);
            if (element.getLocalName() != null && element.getLocalName().equals(queryPropertyName)
                    && (element.getNamespaceURI().equals(doc.lookupNamespaceURI(queryPropertyNS))
                            || queryPropertyNS.equals("*"))) {
                assertTrue(element.getTextContent().compareTo(qVal) >= 0);
            }
        }
    }
}

From source file:org.eclipse.lyo.testsuite.oslcv2.QueryTests.java

public void checkEqualityProperty(NodeList resultList, String queryProperty, String qVal, Document doc) {
    String queryPropertyNS = "*";
    String queryPropertyName = queryProperty;
    if (queryProperty.contains(":")) {
        queryPropertyNS = queryProperty.substring(0, queryProperty.indexOf(':'));
        queryPropertyName = queryProperty.substring(queryProperty.indexOf(':') + 1);
    }/*from  w w  w  .jav  a 2 s.com*/
    for (int i = 0; i < resultList.getLength(); i++) {
        NodeList elements = resultList.item(i).getChildNodes();
        for (int j = 0; j < elements.getLength(); j++) {
            Node element = elements.item(j);
            if (element.getLocalName() != null && element.getLocalName().equals(queryPropertyName)
                    && (element.getNamespaceURI().equals(doc.lookupNamespaceURI(queryPropertyNS))
                            || queryPropertyNS.equals("*"))) {
                // TODO: Determine if OSLC queries are case-sensitive.
                assertTrue(qVal.equalsIgnoreCase(element.getTextContent()));
            }
        }
    }
}

From source file:com.googlecode.ehcache.annotations.config.EhCacheConfigBeanDefinitionParser.java

/**
 * @param evictExpiredElement//from  w ww  .  j  a v  a  2 s  . co m
 * @return The list of {@link CacheNameMatcher}s to use for finding caches to evict
 */
protected List<CacheNameMatcher> parseEvictExpiredElement(final Element evictExpiredElement) {
    List<CacheNameMatcher> cacheNameMatchers = new ArrayList<CacheNameMatcher>();
    final NodeList childNodes = evictExpiredElement.getChildNodes();
    final int childNodesLength = childNodes.getLength();
    boolean configContainsExcludes = false;
    boolean configContainsIncludes = false;
    if (0 != childNodesLength) {
        for (int index = 0; index < childNodesLength; index++) {
            final Node childNode = childNodes.item(index);
            if (Node.ELEMENT_NODE == childNode.getNodeType()) {
                final String childName = childNode.getLocalName();
                NamedNodeMap childAttributes = childNode.getAttributes();
                Node nameAttr = childAttributes.getNamedItem(XSD_ATTRIBUTE__NAME);
                CacheNameMatcher matcher = null;
                if (null != nameAttr) {
                    String matcherValue = nameAttr.getTextContent();
                    matcher = new ExactCacheNameMatcherImpl(matcherValue);
                } else {
                    Node patternAttr = childAttributes.getNamedItem(XSD_ATTRIBUTE__PATTERN);
                    if (null != patternAttr) {
                        String matcherValue = patternAttr.getTextContent();
                        matcher = new PatternCacheNameMatcherImpl(matcherValue);
                    }
                }

                if (null != matcher) {
                    if (XSD_ELEMENT__INCLUDE.equals(childName)) {
                        cacheNameMatchers.add(matcher);
                        configContainsIncludes = true;
                    } else if (XSD_ELEMENT__EXCLUDE.equals(childName)) {
                        cacheNameMatchers.add(new NotCacheNameMatcherImpl(matcher));
                        configContainsExcludes = true;
                    }
                }
            }
        }
    }

    if (0 == cacheNameMatchers.size()) {
        // no include/exclude elements found
        cacheNameMatchers = Collections.singletonList(INCLUDE_ALL_CACHE_NAME_MATCHER);
    } else if (!configContainsIncludes && configContainsExcludes) {
        //config contains excludes only
        // create a new list with a Include all matcher at the front
        List<CacheNameMatcher> newList = new ArrayList<CacheNameMatcher>();
        newList.add(INCLUDE_ALL_CACHE_NAME_MATCHER);
        newList.addAll(cacheNameMatchers);
        cacheNameMatchers = newList;
    }

    return Collections.unmodifiableList(cacheNameMatchers);
}

From source file:org.hdiv.config.xml.EditableValidationsBeanDefinitionParser.java

protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) {

    Object source = parserContext.extractSource(element);

    Map map = new Hashtable();
    bean.addPropertyValue("rawUrls", map);
    bean.setInitMethodName("init");

    // Register default editable validation
    boolean registerDefaults = true;
    String registerDefaultsValue = element.getAttributes().getNamedItem("registerDefaults").getTextContent();
    if (registerDefaultsValue != null) {
        registerDefaults = Boolean.TRUE.toString().equalsIgnoreCase(registerDefaultsValue);
    }// w w  w .j  a  v  a 2  s . co  m

    if (registerDefaults) {
        // Create beans for default validations
        createDefaultEditableValidations(element, parserContext);
    }

    NodeList list = element.getChildNodes();

    for (int i = 0; i < list.getLength(); i++) {
        Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            if (node.getLocalName().equalsIgnoreCase("validationRule")) {

                this.processValidationRule(node, bean, map);
            }
        }
    }

    if (this.springMvcPresent) {
        parserContext.getRegistry().registerBeanDefinition("hdivEditableValidator",
                this.createValidator(element, source, parserContext));
    }
}

From source file:de.fau.cs.osr.hddiff.perfsuite.RunXyDiff.java

private Edit evaluateUpdate(Node node) {
    int ins = 0;/*from ww  w .  j  a  va  2 s. c  om*/
    int del = 0;

    NodeList children = node.getChildNodes();
    int len = children.getLength();
    for (int i = 0; i < len; ++i) {
        Node child = children.item(i);

        String localName = child.getLocalName();
        if (localName == null) {
            String str = ((Text) child).getNodeValue();
            // Ignore whitespace in between tags
            if (!str.trim().isEmpty())
                xyDiffConfusesMe();
        } else {
            String namespaceURI = child.getNamespaceURI();
            if (!"urn:schemas-xydiff:xydelta".equals(namespaceURI))
                xyDiffConfusesMe();

            if ("td".equals(localName)) {
                Node namedItem = child.getAttributes().getNamedItem("len");
                if (namedItem == null)
                    xyDiffConfusesMe();
                del += Integer.valueOf(namedItem.getNodeValue());
            } else if ("ti".equals(localName)) {
                ins += child.getTextContent().length();
            } else if ("tr".equals(localName)) {
                Node namedItem = child.getAttributes().getNamedItem("len");
                if (namedItem == null)
                    xyDiffConfusesMe();
                del += Integer.valueOf(namedItem.getNodeValue());
                ins += child.getTextContent().length();
            } else
                xyDiffConfusesMe();
        }
    }

    return new Edit(GenericEditOp.UPD, ins, del);
}

From source file:de.rub.nds.burp.utilities.attacks.signatureFaking.SignatureFakingOracle.java

private void crawlSignatureElements() throws SignatureFakingException {
    // TODO replace with DOMUtilities
    NodeList nl = getSignatureElements();
    for (int i = 0; i < nl.getLength(); i++) {
        Node n = nl.item(i);/*from  w  w w .j a v a 2s.co  m*/
        NodeList children = n.getChildNodes();
        for (int j = 0; j < children.getLength(); j++) {
            Node current = children.item(j);
            if (current.getNodeType() == Node.ELEMENT_NODE) {
                if (current.getLocalName().equals("SignedInfo")) {
                    Element signatureMethod = DomUtilities
                            .findChildren(current, "SignatureMethod", NamespaceConstants.URI_NS_DS, false)
                            .get(0);
                    if (signatureMethod != null && (!isSignatureMethodSupported(signatureMethod))) {
                        throw new SignatureFakingException("Signature " + "Algorithm not yet supported");
                    }
                } else if (current.getLocalName().equals("SignatureValue")) {
                    signatureValueElements.add(current);
                } else if (current.getLocalName().equals("KeyInfo")) {
                    keyInfoElements.add(current);
                }
            }
        }
    }
}