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.opencredo.esper.config.xml.EsperListenerParser.java

/**
 * Parses out a set of configured esper statement listeners.
 * // w  ww. j a  v  a2  s . c om
 * @param element
 *            the esper listeners element
 * @param parserContext
 *            the parser's current context
 * @return a list of configured esper statement listeners
 */
@SuppressWarnings("unchecked")
public ManagedSet parseListeners(Element element, ParserContext parserContext) {
    ManagedSet listeners = new ManagedSet();
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element childElement = (Element) child;
            String localName = child.getLocalName();
            if ("bean".equals(localName)) {
                BeanDefinitionHolder holder = parserContext.getDelegate()
                        .parseBeanDefinitionElement(childElement);
                parserContext.registerBeanComponent(new BeanComponentDefinition(holder));
                listeners.add(new RuntimeBeanReference(holder.getBeanName()));
            } else if ("ref".equals(localName)) {
                String ref = childElement.getAttribute("bean");
                listeners.add(new RuntimeBeanReference(ref));
            }
        }
    }
    return listeners;
}

From source file:be.fedict.eid.dss.spi.utils.TimeStampDigestInput.java

/**
 * Adds a {@code Node} to the input. The node is canonicalized.
 * /*from ww w.j a  v a 2  s . c  o  m*/
 * @param n
 *            the node to be added
 * @throws IllegalArgumentException
 *             if {@code n} is {@code null}
 */
public void addNode(Node n) {
    if (null == n) {
        throw new IllegalArgumentException("DOM node is null");
    }
    LOG.debug("adding digest node: " + n.getLocalName());
    this.nodes.add(n);
}

From source file:com.clican.pluto.dataprocess.spring.parser.JdbcExecProcessorParser.java

@SuppressWarnings("unchecked")

public void customiseBeanDefinition(BeanDefinition beanDef, Element element, ParserContext parserContext) {
    String jdbcTemplate = element.getAttribute("jdbcTemplate");
    beanDef.getPropertyValues().addPropertyValue("jdbcTemplate", new RuntimeBeanReference(jdbcTemplate));
    List jdbcExecBeanList = new ManagedList();
    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();
            if ("exec".equals(localName)) {
                RootBeanDefinition bean = new RootBeanDefinition();
                bean.setAbstract(false);
                bean.setBeanClass(JdbcExecBean.class);
                bean.setLazyInit(false);
                bean.setAutowireMode(Autowire.BY_NAME.value());

                Element jdbcExecElement = (Element) node;
                String batch = jdbcExecElement.getAttribute("batch");
                String paramName = jdbcExecElement.getAttribute("paramName");
                String resultName = jdbcExecElement.getAttribute("resultName");
                String paramNameMap = jdbcExecElement.getAttribute("paramNameMap");
                String singleRow = jdbcExecElement.getAttribute("singleRow");
                String clazz = jdbcExecElement.getAttribute("clazz");
                String sql = jdbcExecElement.getTextContent();
                if (StringUtils.isNotEmpty(paramNameMap)) {
                    Map<String, String> map = new HashMap<String, String>();
                    for (String pnm : paramNameMap.split(";")) {
                        String contextName = pnm.split("=>")[0].trim();
                        String ibatisName = pnm.split("=>")[1].trim();
                        map.put(contextName, ibatisName);
                    }//from  w w  w  . ja va2 s .com
                    bean.getPropertyValues().addPropertyValue("paramNameMap", map);
                }
                if (StringUtils.isNotEmpty(batch)) {
                    bean.getPropertyValues().addPropertyValue("batch", Boolean.parseBoolean(batch));
                }
                if (StringUtils.isNotEmpty(singleRow)) {
                    bean.getPropertyValues().addPropertyValue("singleRow", Boolean.parseBoolean(singleRow));
                }
                if (StringUtils.isNotEmpty(clazz)) {
                    try {
                        bean.getPropertyValues().addPropertyValue("clazz", Class.forName(clazz));
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
                bean.getPropertyValues().addPropertyValue("paramName", paramName);
                bean.getPropertyValues().addPropertyValue("resultName", resultName);
                bean.getPropertyValues().addPropertyValue("sql", sql);
                jdbcExecBeanList.add(bean);
            }
        }
    }
    beanDef.getPropertyValues().addPropertyValue("jdbcExecBeanList", jdbcExecBeanList);
}

From source file:com.hp.autonomy.searchcomponents.idol.view.IdolViewServerServiceTest.java

private GetContentResponseData mockResponseData() {
    final GetContentResponseData responseData = new GetContentResponseData();

    final Hit hit = new Hit();
    responseData.getHit().add(hit);/*from   w w  w.  j  a  va  2s . c  o  m*/

    final DocContent content = new DocContent();
    hit.setContent(content);

    final Node node = mock(Node.class);
    content.getContent().add(node);

    final NodeList childNodes = mock(NodeList.class);
    when(childNodes.getLength()).thenReturn(1);
    when(node.getChildNodes()).thenReturn(childNodes);

    final Node referenceNode = mock(Node.class);
    when(referenceNode.getLocalName()).thenReturn(SAMPLE_REFERENCE_FIELD_NAME);

    final Node textNode = mock(Node.class);
    when(textNode.getNodeValue()).thenReturn("http://en.wikipedia.org/wiki/Car");
    when(referenceNode.getFirstChild()).thenReturn(textNode);
    when(childNodes.item(0)).thenReturn(referenceNode);

    return responseData;
}

From source file:cz.incad.kramerius.virtualcollections.VirtualCollectionsManager.java

public static List<VirtualCollection> getVirtualCollectionsFromFedora(FedoraAccess fedoraAccess,
        ArrayList<String> languages) throws Exception {
    try {// w  w w  .  ja  v  a2  s . c o  m
        IResourceIndex g = ResourceIndexService.getResourceIndexImpl();
        Document doc = g.getVirtualCollections();

        NodeList nodes = doc.getDocumentElement().getElementsByTagNameNS(SPARQL_NS, "result");
        NodeList children;
        Node child;
        String name;
        String pid;
        boolean canLeave;

        ArrayList<String> langs = new ArrayList<String>();

        if (languages == null || languages.isEmpty()) {
            String[] ls = KConfiguration.getInstance().getPropertyList("interface.languages");
            for (int i = 0; i < ls.length; i++) {
                String lang = ls[++i];
                langs.add(lang);
            }
        } else {
            langs = new ArrayList<String>(languages);
        }

        List<VirtualCollection> vcs = new ArrayList<VirtualCollection>();
        for (int i = 0; i < nodes.getLength(); i++) {
            canLeave = false;
            name = null;
            pid = null;
            Node node = nodes.item(i);
            children = node.getChildNodes();
            for (int j = 0; j < children.getLength(); j++) {
                child = children.item(j);
                if ("title".equals(child.getLocalName())) {
                    name = child.getFirstChild().getNodeValue();
                } else if ("object".equals(child.getLocalName())) {
                    pid = ((Element) child).getAttribute("uri").replaceAll("info:fedora/", "");
                } else if ("canLeave".equals(child.getLocalName())) {
                    canLeave = Boolean.parseBoolean(child.getFirstChild().getNodeValue().replaceAll("\"", "")
                            .substring(("canLeave:").length()));
                }
            }

            if (name != null && pid != null) {
                try {
                    VirtualCollection vc = new VirtualCollection(name, pid, canLeave);

                    for (String lang : langs) {
                        String dsName = TEXT_DS_PREFIX + lang;
                        String value = IOUtils.readAsString(fedoraAccess.getDataStream(pid, dsName),
                                Charset.forName("UTF8"), true);
                        vc.addDescription(lang, value);
                    }
                    vcs.add(vc);
                } catch (Exception vcex) {
                    logger.log(Level.WARNING,
                            "Could not get virtual collection for  " + pid + ": " + vcex.toString());

                }
            }
        }
        return vcs;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Error getting virtual collections", ex);
        throw new Exception(ex);
    }
}

From source file:com.gargoylesoftware.htmlunit.xml.XmlUtil.java

private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML) {
    if (source.getNodeType() == Node.TEXT_NODE) {
        return new DomText(page, source.getNodeValue());
    }/*from   w  ww .j  a v a 2  s.  c o m*/
    if (source.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        return new DomProcessingInstruction(page, source.getNodeName(), source.getNodeValue());
    }
    if (source.getNodeType() == Node.COMMENT_NODE) {
        return new DomComment(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        final DocumentType documentType = (DocumentType) source;
        return new DomDocumentType(page, documentType.getName(), documentType.getPublicId(),
                documentType.getSystemId());
    }
    final String ns = source.getNamespaceURI();
    String localName = source.getLocalName();
    if (handleXHTMLAsHTML && HTMLParser.XHTML_NAMESPACE.equals(ns)) {
        final ElementFactory factory = HTMLParser.getFactory(localName);
        return factory.createElementNS(page, ns, localName,
                namedNodeMapToSaxAttributes(source.getAttributes()));
    }
    final NamedNodeMap nodeAttributes = source.getAttributes();
    if (page != null && page.isHtmlPage()) {
        localName = localName.toUpperCase(Locale.ROOT);
    }
    final String qualifiedName;
    if (source.getPrefix() == null) {
        qualifiedName = localName;
    } else {
        qualifiedName = source.getPrefix() + ':' + localName;
    }

    final String namespaceURI = source.getNamespaceURI();
    if (HTMLParser.SVG_NAMESPACE.equals(namespaceURI)) {
        return HTMLParser.SVG_FACTORY.createElementNS(page, namespaceURI, qualifiedName,
                namedNodeMapToSaxAttributes(nodeAttributes));
    }

    final Map<String, DomAttr> attributes = new LinkedHashMap<>();
    for (int i = 0; i < nodeAttributes.getLength(); i++) {
        final Attr attribute = (Attr) nodeAttributes.item(i);
        final String attributeNamespaceURI = attribute.getNamespaceURI();
        final String attributeQualifiedName;
        if (attribute.getPrefix() != null) {
            attributeQualifiedName = attribute.getPrefix() + ':' + attribute.getLocalName();
        } else {
            attributeQualifiedName = attribute.getLocalName();
        }
        final String value = attribute.getNodeValue();
        final boolean specified = attribute.getSpecified();
        final DomAttr xmlAttribute = new DomAttr(page, attributeNamespaceURI, attributeQualifiedName, value,
                specified);
        attributes.put(attribute.getNodeName(), xmlAttribute);
    }
    return new DomElement(namespaceURI, qualifiedName, page, attributes);
}

From source file:biz.c24.io.spring.integration.config.XPathHeaderEnricherParser.java

protected void processHeaders(Element element, ManagedMap<String, Object> headers,
        ParserContext parserContext) {/*from w  ww .  j a  va  2 s. co  m*/
    Object source = parserContext.extractSource(element);
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element headerElement = (Element) node;
            String elementName = node.getLocalName();
            if ("header".equals(elementName)) {
                BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
                        "biz.c24.io.spring.integration.transformer.C24XPathHeaderEnricher$XPathExpressionEvaluatingHeaderValueMessageProcessor");
                String expressionString = headerElement.getAttribute("xpath-statement");
                String expressionRef = headerElement.getAttribute("xpath-statement-ref");
                boolean isExpressionString = StringUtils.hasText(expressionString);
                boolean isExpressionRef = StringUtils.hasText(expressionRef);
                if (!(isExpressionString ^ isExpressionRef)) {
                    parserContext.getReaderContext().error(
                            "Exactly one of the 'xpath-statement' or 'xpath-statement-ref' attributes is required.",
                            source);
                }
                if (isExpressionString) {
                    builder.addConstructorArgValue(expressionString);
                } else {
                    builder.addConstructorArgReference(expressionRef);
                }
                IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, headerElement, "evaluation-type");
                IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, headerElement, "overwrite");
                String headerName = headerElement.getAttribute("name");
                headers.put(headerName, builder.getBeanDefinition());
            }
        }
    }
}

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

/**
 * Crawls all the collected KeyInfo elements and extracts certificates
 */// w w  w.ja va2 s  . c o  m
private void crawlKeyInfoElements() {
    for (Node ki : keyInfoElements) {
        List<Element> l = DomUtilities.findChildren(ki, "X509Certificate", NamespaceConstants.URI_NS_DS, true);
        if (l.size() > 0) {
            Node x509cert = l.get(0);
            if (x509cert != null && x509cert.getLocalName().equals("X509Certificate")) {
                certificates.add(x509cert.getTextContent());
            }
        }
    }
}

From source file:gov.nih.nci.cabig.caaers2adeers.track.Tracker.java

private void captureLogDetails(Exchange exchange, IntegrationLog integrationLog) {
    if (caputureLogDetails) {
        //Check for soap fault
        String faultString = XPathBuilder.xpath("//faultstring/text()").evaluate(exchange, String.class);
        if (!StringUtils.isBlank(faultString)) {
            integrationLog.setNotes(SOAP_FAULT_STATUS);
            integrationLog.addIntegrationLogDetail(new IntegrationLogDetail(null, faultString, true));
        }//from ww w.  j  ava  2 s.c o  m

        //check for caaers error message in response
        String errorString = XPathBuilder.xpath("//error/text()").evaluate(exchange, String.class);
        if (!StringUtils.isBlank(errorString)) {
            integrationLog.setNotes(CAAERS_RESPONSE_ERROR);
            integrationLog.addIntegrationLogDetail(new IntegrationLogDetail(null, errorString, true));
        }

        //check for 'com:entityProcessingOutcomes'
        NodeList nodes = XPathBuilder.xpath("//com:entityProcessingOutcomes")
                .namespace("com", "http://schema.integration.caaers.cabig.nci.nih.gov/common").nodeResult()
                .evaluate(exchange, NodeList.class);

        if (nodes != null) {

            for (int i = 0; i < nodes.getLength(); i++) {
                Node outcome = nodes.item(i);
                if (StringUtils.equals(outcome.getLocalName(), "entityProcessingOutcome")) {
                    NodeList children = outcome.getChildNodes();
                    String businessIdentifier = null;
                    String outcomeMsg = null;
                    boolean failed = false;
                    for (int j = 0; j < children.getLength(); j++) {
                        Node child = children.item(j);
                        String childLocalName = child.getLocalName();
                        if (!StringUtils.isBlank(childLocalName)
                                && childLocalName.equals("businessIdentifier")) {
                            businessIdentifier = child.getFirstChild().getNodeValue();
                        } else if (!StringUtils.isBlank(childLocalName) && childLocalName.equals("message")) {
                            outcomeMsg = child.getFirstChild() != null ? child.getFirstChild().getNodeValue()
                                    : null;
                        } else if (!StringUtils.isBlank(childLocalName) && childLocalName.equals("failed")) {
                            failed = new Boolean(
                                    child.getFirstChild() != null ? child.getFirstChild().getNodeValue()
                                            : "false");
                        }
                    }
                    if (businessIdentifier != null) {
                        integrationLog.addIntegrationLogDetail(
                                new IntegrationLogDetail(businessIdentifier, outcomeMsg, failed));
                    }
                }
            }
        }
    }
}

From source file:org.jboss.seam.spring.namespace.CdiBeanImportBeanDefinitionParser.java

@Override
public AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder cdiBeanFactoryBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(FACTORY_BEAN_CLASS_NAME);
    String beanManagerReference = element.getAttribute(BEAN_MANAGER_REFERENCE);
    if (StringUtils.hasText(beanManagerReference)) {
        cdiBeanFactoryBuilder.addPropertyReference("beanManager", beanManagerReference);
    } else {//w ww.  jav a  2 s .  c om
        cdiBeanFactoryBuilder.addPropertyReference("beanManager", DEFAULT_BEAN_MANAGER_ID);
    }

    String name = element.getAttribute(NAME_ATTRIBUTE);

    String type = element.getAttribute("type");

    if (!StringUtils.hasText(name) && !StringUtils.hasText(type)) {
        parserContext.getReaderContext()
                .error("A CDI bean reference must specify at least a name or the bean type", element);
    }

    ArrayList<Qualifier> qualifiers = new ArrayList<Qualifier>();

    NodeList children = element.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node childNode = children.item(i);
        if (childNode.getNodeType() == Node.ELEMENT_NODE && "qualifier".equals(childNode.getLocalName())) {
            Element qualifierElement = (Element) childNode;
            Qualifier qualifier = new Qualifier();
            Map<String, Object> attributes = new HashMap<String, Object>();
            qualifier.setClassName(qualifierElement.getAttribute("type"));

            if (qualifierElement.hasChildNodes()) {
                NodeList attributeNodes = qualifierElement.getChildNodes();
                for (int j = 0; j < attributeNodes.getLength(); j++) {
                    Node attributeNode = attributeNodes.item(j);
                    if (attributeNode.getNodeType() == Node.ELEMENT_NODE
                            && "attribute".equals(attributeNode.getLocalName())) {
                        Element attributeElement = (Element) attributeNode;
                        String attributeName = attributeElement.getAttribute("name");
                        String attributeValue = attributeElement.getAttribute("value");
                        if (!StringUtils.hasText(attributeName) || !StringUtils.hasText(attributeValue)) {
                            parserContext.getReaderContext().error(
                                    "Qualifier attributes must have both a name and a value", attributeElement);
                        }
                        attributes.put(attributeName, attributeValue);
                    }
                }
            }
            qualifier.setAttributes(attributes);
            qualifiers.add(qualifier);
        }
    }
    if (StringUtils.hasText(name) && !qualifiers.isEmpty()) {
        parserContext.getReaderContext()
                .error("A bean reference must either specify a name or qualifiers but not both", element);
    }

    BeanDefinitionBuilder lookupBuilder = BeanDefinitionBuilder
            .rootBeanDefinition(TYPE_SAFE_BEAN_LOOKUP_CLASS_NAME);
    lookupBuilder.addConstructorArgValue(type);
    lookupBuilder.addPropertyValue("qualifiers", qualifiers);
    AbstractBeanDefinition lookupBeanDefinition = lookupBuilder.getBeanDefinition();
    String lookupBeanName = parserContext.getReaderContext().generateBeanName(lookupBeanDefinition);
    BeanDefinitionReaderUtils.registerBeanDefinition(
            new BeanDefinitionHolder(lookupBeanDefinition, lookupBeanName), parserContext.getRegistry());
    cdiBeanFactoryBuilder.addPropertyReference("cdiBeanLookup", lookupBeanName);

    return cdiBeanFactoryBuilder.getBeanDefinition();
}