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:net.bpelunit.test.unit.TestSOAPEncoder.java

@Test
public void testEncodeRPCLiteResponseUnwrapped() throws Exception {
    Element literal = TestUtil.readLiteralData(PATH_TO_FILES + "rpclit1.xmlfrag");
    SOAPOperationCallIdentifier operation = TestUtil.getCall(PATH_TO_FILES, PARTNER_WSDL, PARTNER_OPERATION,
            SOAPOperationDirectionIdentifier.OUTPUT);
    ISOAPEncoder encoder = new RPCLiteralEncoder();
    SOAPMessage message = encoder.construct(operation, literal, BPELUnitConstants.SOAP_FAULT_CODE_CLIENT,
            BPELUnitConstants.SOAP_FAULT_DESCRIPTION);

    final Node firstChild = message.getSOAPBody().getFirstChild();
    assertEquals(XMLConstants.NULL_NS_URI, firstChild.getNamespaceURI());
    assertEquals(operation.getName() + "Response", firstChild.getLocalName());
}

From source file:de.betterform.xml.dom.DOMUtil.java

/**
 * __UNDOCUMENTED__/* w  w w . ja v a2  s. c  o m*/
 *
 * @param nodeToCompare __UNDOCUMENTED__
 * @param nsuri         __UNDOCUMENTED__
 * @param tagName       __UNDOCUMENTED__
 * @return __UNDOCUMENTED__
 */
public static boolean isNodeInNS(Node nodeToCompare, String nsuri, String tagName) {
    String ntcnsuri = nodeToCompare.getNamespaceURI();

    if ((ntcnsuri != null) && (ntcnsuri.length() > 0)) {
        return (tagName.equals(nodeToCompare.getLocalName()) && ntcnsuri.equals(nsuri));
    } else {
        return (tagName.equals(nodeToCompare.getNodeName()));
    }
}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static QName getQName(Node node) {
    if (node.getLocalName() == null) {
        if (node.getNodeName() == null) {
            return null;
        } else {//ww w. j a v  a  2  s. c om
            return new QName(null, node.getNodeName());
        }
    }
    if (node.getPrefix() == null) {
        return new QName(node.getNamespaceURI(), node.getLocalName());
    }
    return new QName(node.getNamespaceURI(), node.getLocalName(), node.getPrefix());
}

From source file:org.codehaus.grepo.core.config.GenericRepositoryScanBeanDefinitionParser.java

/**
 * @param element The element.//from  ww  w.  j  a  va2 s.co m
 * @param scanner The scanner.
 * @param readerContext The reader context.
 */
protected void parseTypeFilters(Element element, GenericRepositoryBeanDefinitionScanner scanner,
        XmlReaderContext readerContext) {

    // Parse exclude and include filter elements.
    ClassLoader classLoader = scanner.getResourceLoader().getClassLoader();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String localName = node.getLocalName();
            try {
                if (INCLUDE_FILTER_ELEMENT.equals(localName)) {
                    // Note: that we use the composite type filter for include-filter,
                    // because we always want repositories of appropriate interface type...
                    CompositeTypeFilter typeFilter = new CompositeTypeFilter();
                    typeFilter.addTypeFilter(new AssignableTypeFilter(requiredGenericRepositoryType));
                    typeFilter.addTypeFilter(createTypeFilter((Element) node, classLoader));
                    scanner.addIncludeFilter(typeFilter);
                } else if (EXCLUDE_FILTER_ELEMENT.equals(localName)) {
                    TypeFilter typeFilter = createTypeFilter((Element) node, classLoader);
                    scanner.addExcludeFilter(typeFilter);
                }
            } catch (Exception ex) {
                readerContext.error(ex.getMessage(), readerContext.extractSource(element), ex.getCause());
            }
        }
    }
}

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

/**
 * Validate an evict-expired-elements Element with a single include element.
 *//*from www  .  jav a  2s. co m*/
@Test
public void testParseEvictExpiredSingleInclude() {
    Node nameAttribute = EasyMock.createMock(Node.class);
    EasyMock.expect(nameAttribute.getTextContent()).andReturn("foo");
    NamedNodeMap includeAttributes = EasyMock.createMock(NamedNodeMap.class);
    EasyMock.expect(includeAttributes.getNamedItem(EhCacheConfigBeanDefinitionParser.XSD_ATTRIBUTE__NAME))
            .andReturn(nameAttribute);

    Node includeNode = EasyMock.createMock(Node.class);
    EasyMock.expect(includeNode.getNodeType()).andReturn(Node.ELEMENT_NODE);
    EasyMock.expect(includeNode.getLocalName()).andReturn("include");
    EasyMock.expect(includeNode.getAttributes()).andReturn(includeAttributes);

    NodeList childNodes = EasyMock.createMock(NodeList.class);
    EasyMock.expect(childNodes.getLength()).andReturn(1);
    EasyMock.expect(childNodes.item(0)).andReturn(includeNode);

    Element evictExpired = EasyMock.createMock(Element.class);
    EasyMock.expect(evictExpired.getChildNodes()).andReturn(childNodes);
    EasyMock.replay(nameAttribute, includeAttributes, includeNode, childNodes, evictExpired);

    EhCacheConfigBeanDefinitionParser parser = new EhCacheConfigBeanDefinitionParser();
    List<CacheNameMatcher> matchers = parser.parseEvictExpiredElement(evictExpired);
    Assert.assertNotNull(matchers);
    Assert.assertEquals(1, matchers.size());
    CacheNameMatcher matcher = matchers.get(0);
    Assert.assertTrue(matcher instanceof ExactCacheNameMatcherImpl);
    ExactCacheNameMatcherImpl casted = (ExactCacheNameMatcherImpl) matcher;
    Assert.assertEquals("foo", casted.getName());

    EasyMock.verify(nameAttribute, includeAttributes, includeNode, childNodes, evictExpired);
}

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

/**
 * Validate an evict-expired-elements Element with a single exclude element.
 * Presence of exclude element will prepend a Include All matcher to the front of the list.
 *///  w w  w.  j a va  2 s  .  co m
@Test
public void testParseEvictExpiredSingleExclude() {
    Node nameAttribute = EasyMock.createMock(Node.class);
    EasyMock.expect(nameAttribute.getTextContent()).andReturn("foo");
    NamedNodeMap excludeAttributes = EasyMock.createMock(NamedNodeMap.class);
    EasyMock.expect(excludeAttributes.getNamedItem(EhCacheConfigBeanDefinitionParser.XSD_ATTRIBUTE__NAME))
            .andReturn(nameAttribute);

    Node excludeNode = EasyMock.createMock(Node.class);
    EasyMock.expect(excludeNode.getNodeType()).andReturn(Node.ELEMENT_NODE);
    EasyMock.expect(excludeNode.getLocalName()).andReturn("exclude");
    EasyMock.expect(excludeNode.getAttributes()).andReturn(excludeAttributes);

    NodeList childNodes = EasyMock.createMock(NodeList.class);
    EasyMock.expect(childNodes.getLength()).andReturn(1);
    EasyMock.expect(childNodes.item(0)).andReturn(excludeNode);

    Element evictExpired = EasyMock.createMock(Element.class);
    EasyMock.expect(evictExpired.getChildNodes()).andReturn(childNodes);
    EasyMock.replay(nameAttribute, excludeAttributes, excludeNode, childNodes, evictExpired);

    EhCacheConfigBeanDefinitionParser parser = new EhCacheConfigBeanDefinitionParser();
    List<CacheNameMatcher> matchers = parser.parseEvictExpiredElement(evictExpired);
    Assert.assertNotNull(matchers);
    Assert.assertEquals(2, matchers.size());
    Assert.assertEquals(EhCacheConfigBeanDefinitionParser.INCLUDE_ALL_CACHE_NAME_MATCHER, matchers.get(0));

    CacheNameMatcher matcher = matchers.get(1);
    Assert.assertTrue(matcher instanceof NotCacheNameMatcherImpl);
    NotCacheNameMatcherImpl casted = (NotCacheNameMatcherImpl) matcher;
    ExactCacheNameMatcherImpl wrapped = (ExactCacheNameMatcherImpl) casted.getWrapped();
    Assert.assertEquals("foo", wrapped.getName());

    EasyMock.verify(nameAttribute, excludeAttributes, excludeNode, childNodes, evictExpired);
}

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

/**
 * @param childNodes//from   ww w.  j  a  v a  2s  . c  o m
 * @param beanDefinition
 * @return
 */
protected ManagedMap<String, Object> parseProperties(NodeList nodeList, RootBeanDefinition beanDefinition) {
    if (nodeList != null && nodeList.getLength() > 0) {
        ManagedMap<String, Object> parameters = null;
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node instanceof Element) {
                if ("parameter".equals(node.getNodeName()) || "parameter".equals(node.getLocalName())) {
                    if (parameters == null) {
                        parameters = new ManagedMap<String, Object>();
                    }
                    String key = ((Element) node).getAttribute("key");
                    String value = ((Element) node).getAttribute("value");
                    parameters.put(key, new TypedStringValue(value, String.class));
                }
            }
        }
        return parameters;
    }
    return null;
}

From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java

@SuppressWarnings("unchecked")
private XRoadProtocolVersion parseProtocolVersion(SOAPMessage requestMessage) throws SOAPException {
    XRoadProtocolVersion version = null;
    // Extract protocol version by headers
    if (requestMessage.getSOAPHeader() != null) {
        NodeList reqHeaders = requestMessage.getSOAPHeader().getChildNodes();
        for (int i = 0; i < reqHeaders.getLength(); i++) {
            Node reqHeader = reqHeaders.item(i);
            if (reqHeader.getNodeType() != Node.ELEMENT_NODE
                    || !reqHeader.getLocalName().equals(XTeeHeader.PROTOCOL_VERSION.getLocalPart())) {
                continue;
            }//from   w  w  w  .j  av a2 s  .  co  m

            if ((version = XRoadProtocolVersion
                    .getValueByVersionCode(SOAPUtil.getTextContent(reqHeader))) != null) {
                return version;
            }
        }
    }

    // Extract protocol version by namespaces
    SOAPEnvelope soapEnv = requestMessage.getSOAPPart().getEnvelope();
    Iterator<String> prefixes = soapEnv.getNamespacePrefixes();
    while (prefixes.hasNext()) {
        String nsPrefix = (String) prefixes.next();
        String nsURI = soapEnv.getNamespaceURI(nsPrefix).toLowerCase();
        if ((version = XRoadProtocolVersion.getValueByNamespaceURI(nsURI)) != null) {
            return version;
        }
    }
    throw new IllegalStateException("Unsupported protocol version");
}

From source file:com.amalto.core.history.accessor.AttributeAccessor.java

public void delete() {
    if (exist()) {
        Node parentNode = parent.getNode();
        Node attribute = getAttribute();
        if (attribute != null) {
            parentNode.getAttributes().removeNamedItemNS(attribute.getNamespaceURI(), attribute.getLocalName());
        } else {//from w  w w  .  j ava2s.co  m
            logger.warn("Attempt to delete the attribute '" + attributeName + "'that does not exist."); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
}

From source file:com.clican.pluto.fsm.spring.parser.AbstractStateParser.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionRegistry bdr = parserContext.getRegistry();
    RootBeanDefinition beanDef = new RootBeanDefinition();
    beanDef.setDestroyMethodName("destroy");
    beanDef.setAbstract(false);/*www .ja v  a 2 s . co  m*/
    beanDef.setBeanClass(getStateClass(element));
    beanDef.setLazyInit(false);
    beanDef.setAutowireMode(Autowire.BY_NAME.value());
    String name = element.getAttribute("name");
    if (bdr.containsBeanDefinition(name)) {
        throw new RuntimeException("name[" + name + "]is defined duplicated");
    }
    bdr.registerBeanDefinition(name, beanDef);
    beanDef.getPropertyValues().addPropertyValue("name", name);
    String value = element.getAttribute("value");
    beanDef.getPropertyValues().addPropertyValue("value", value);

    String propagation = element.getAttribute("propagation");
    beanDef.getPropertyValues().addPropertyValue("propagation", propagation);
    String nextStates = element.getAttribute("nextStates");
    if (StringUtils.isNotEmpty(nextStates)) {
        List nextStateList = new ManagedList();
        for (String nextState : nextStates.split(",")) {
            nextStateList.add(new RuntimeBeanReference(nextState.trim()));
        }
        beanDef.getPropertyValues().addPropertyValue("nextStates", nextStateList);
    }

    String previousStates = element.getAttribute("previousStates");
    if (StringUtils.isNotEmpty(previousStates)) {
        List previousStateList = new ManagedList();
        for (String previousState : previousStates.split(",")) {
            previousStateList.add(new RuntimeBeanReference(previousState.trim()));
        }
        beanDef.getPropertyValues().addPropertyValue("previousStates", previousStateList);
    }

    NodeList nodeList = element.getChildNodes();
    Map nextCondStates = new ManagedMap();
    Map params = new ManagedMap();
    List stateListeners = new ManagedList();
    List taskListeners = new ManagedList();
    Map timeoutListeners = new ManagedMap();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String localName = node.getLocalName();
            Element e = (Element) node;
            if ("nextCondStates".equals(localName)) {
                String expr = e.getAttribute("expr");
                nextStates = e.getAttribute("nextStates");
                List nextStateList = new ManagedList();
                if (StringUtils.isNotEmpty(nextStates)) {
                    for (String nextState : nextStates.split(",")) {
                        nextStateList.add(new RuntimeBeanReference(nextState.trim()));
                    }
                }
                nextCondStates.put(expr, nextStateList);
            } else if ("param".equals(localName)) {
                String paramName = e.getAttribute("name");
                String paramValue = e.getAttribute("value");
                params.put(paramName, paramValue);
            } else if ("stateListener".equals(localName) || "timeoutListener".equals(localName)
                    || "taskListener".equals(localName)) {
                String clazz = e.getAttribute("clazz");
                String listener = e.getAttribute("listener");
                Object obj;
                if (StringUtils.isNotEmpty(clazz)) {
                    try {
                        RootBeanDefinition bean = new RootBeanDefinition();
                        bean.setAbstract(false);
                        bean.setBeanClass(Class.forName(clazz));
                        bean.setLazyInit(false);
                        bean.setAutowireMode(Autowire.BY_NAME.value());
                        if ("timeoutListener".equals(localName)) {
                            String timeoutName = e.getAttribute("name");
                            String startTime = e.getAttribute("startTime");
                            String dueTime = e.getAttribute("dueTime");
                            String repeatTime = e.getAttribute("repeatTime");
                            String repeatDuration = e.getAttribute("repeatDuration");
                            String businessCalendarName = e.getAttribute("businessCalendarName");
                            bean.getPropertyValues().addPropertyValue("name", timeoutName);
                            bean.getPropertyValues().addPropertyValue("startTime", startTime);
                            bean.getPropertyValues().addPropertyValue("dueTime", dueTime);
                            bean.getPropertyValues().addPropertyValue("repeatTime", repeatTime);
                            bean.getPropertyValues().addPropertyValue("repeatDuration", repeatDuration);
                            bean.getPropertyValues().addPropertyValue("businessCalendarName",
                                    businessCalendarName);
                        }
                        NodeList nodeList2 = element.getChildNodes();
                        Map params2 = new ManagedMap();
                        for (int j = 0; j < nodeList2.getLength(); j++) {
                            Node node2 = nodeList2.item(j);
                            if (node2.getNodeType() == Node.ELEMENT_NODE) {
                                String localName2 = node2.getLocalName();
                                if ("param".equals(localName2)) {
                                    String paramName = ((Element) node2).getAttribute("name");
                                    String paramValue = ((Element) node2).getAttribute("value");
                                    params2.put(paramName, paramValue);
                                }
                            }
                        }
                        obj = bean;
                    } catch (Exception ex) {
                        throw new RuntimeException(ex);
                    }
                } else if (StringUtils.isNotEmpty(listener)) {
                    obj = new RuntimeBeanReference(listener.trim());
                } else {
                    throw new RuntimeException("There must be clazz or listener parameter setting");
                }
                if ("stateListener".equals(localName)) {
                    stateListeners.add(obj);
                } else if ("taskListeners".equals(localName)) {
                    taskListeners.add(obj);
                } else {
                    String timeoutName = e.getAttribute("name");
                    timeoutListeners.put(timeoutName, obj);
                }
            }
        }
    }
    beanDef.getPropertyValues().addPropertyValue("nextCondStates", nextCondStates);
    beanDef.getPropertyValues().addPropertyValue("params", params);
    beanDef.getPropertyValues().addPropertyValue("stateListeners", stateListeners);
    if (element.getNodeName().equals("task")) {
        beanDef.getPropertyValues().addPropertyValue("taskListeners", taskListeners);
    }
    beanDef.getPropertyValues().addPropertyValue("timeoutListeners", timeoutListeners);

    customiseBeanDefinition(beanDef, element, parserContext);
    return beanDef;
}