Example usage for org.w3c.dom Node getNamespaceURI

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

Introduction

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

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:com.centeractive.ws.builder.soap.XmlUtils.java

public static QName getQName(Node node) {
    if (node == null)
        return null;
    else if (node.getNamespaceURI() == null)
        return new QName(node.getNodeName());
    else//  www .  j ava 2s  .c o m
        return new QName(node.getNamespaceURI(), node.getLocalName());
}

From source file:microsoft.exchange.webservices.data.core.EwsServiceXmlWriter.java

/**
 * @param element DOM element//from w w  w  .j  a  v a 2 s  . co  m
 * @param writer XML stream writer
 * @throws XMLStreamException the XML stream exception
 */
public static void addElement(Element element, XMLStreamWriter writer) throws XMLStreamException {
    String nameSpace = element.getNamespaceURI();
    String prefix = element.getPrefix();
    String localName = element.getLocalName();
    if (prefix == null) {
        prefix = "";
    }
    if (localName == null) {
        localName = element.getNodeName();

        if (localName == null) {
            throw new IllegalStateException("Element's local name cannot be null!");
        }
    }

    String decUri = writer.getNamespaceContext().getNamespaceURI(prefix);
    boolean declareNamespace = decUri == null || !decUri.equals(nameSpace);

    if (nameSpace == null || nameSpace.length() == 0) {
        writer.writeStartElement(localName);
    } else {
        writer.writeStartElement(prefix, localName, nameSpace);
    }

    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node attr = attrs.item(i);

        String name = attr.getNodeName();
        String attrPrefix = "";
        int prefixIndex = name.indexOf(':');
        if (prefixIndex != -1) {
            attrPrefix = name.substring(0, prefixIndex);
            name = name.substring(prefixIndex + 1);
        }

        if ("xmlns".equals(attrPrefix)) {
            writer.writeNamespace(name, attr.getNodeValue());
            if (name.equals(prefix) && attr.getNodeValue().equals(nameSpace)) {
                declareNamespace = false;
            }
        } else {
            if ("xmlns".equals(name) && "".equals(attrPrefix)) {
                writer.writeNamespace("", attr.getNodeValue());
                if (attr.getNodeValue().equals(nameSpace)) {
                    declareNamespace = false;
                }
            } else {
                writer.writeAttribute(attrPrefix, attr.getNamespaceURI(), name, attr.getNodeValue());
            }
        }
    }

    if (declareNamespace) {
        if (nameSpace == null) {
            writer.writeNamespace(prefix, "");
        } else {
            writer.writeNamespace(prefix, nameSpace);
        }
    }

    NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        writeNode(n, writer);
    }

    writer.writeEndElement();

}

From source file:de.elbe5.base.data.XmlData.java

public List<String> getPropertiesFromXML(Node propNode) {
    List<String> properties;
    properties = new ArrayList<>();
    NodeList childList = propNode.getChildNodes();
    for (int i = 0; i < childList.getLength(); i++) {
        Node currentNode = childList.item(i);
        if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
            String nodeName = currentNode.getLocalName();
            String namespace = currentNode.getNamespaceURI();
            properties.add(namespace + ':' + nodeName);
        }/* w  w w.  j a v  a  2  s .com*/
    }
    return properties;
}

From source file:de.betterform.xml.xforms.ui.Switch.java

/**
 * Initializes the Case elements.//from w w  w  .  j av a2 s  . c  o m
 * <p/>
 * If multiple Cases within a Switch are selected, the first selected Case
 * remains and all others are deselected. If none are selected, the first
 * becomes selected.
 */
protected final void initializeSwitch() throws XFormsException {
    NodeList childNodes = getElement().getChildNodes();
    List cases = new ArrayList(childNodes.getLength());

    Node node;
    Case caseElement;
    String selectedAttribute;
    int selection = -1;

    for (int index = 0; index < childNodes.getLength(); index++) {
        node = childNodes.item(index);

        if (node.getNodeType() == Node.ELEMENT_NODE
                && NamespaceConstants.XFORMS_NS.equals(node.getNamespaceURI())
                && CASE.equals(node.getLocalName())) {
            caseElement = (Case) ((Node) node).getUserData("");
            cases.add(caseElement);

            selectedAttribute = caseElement.getXFormsAttribute(SELECTED_ATTRIBUTE);
            if ((selection == -1) && ("true").equals(selectedAttribute)) {
                // keep *first* selected case position
                selection = cases.size() - 1;
            }
        }
    }

    if (selection == -1) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(this + " init: choosing first case for selection by default");
        }

        // select first case if none is selected
        selection = 0;
    }

    // perform selection/deselection
    for (int index = 0; index < cases.size(); index++) {
        caseElement = (Case) cases.get(index);

        if (index == selection) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug(this + " init: selecting case '" + caseElement.getId() + "'");
            }
            caseElement.select();
        } else {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug(this + " init: deselecting case '" + caseElement.getId() + "'");
            }
            caseElement.deselect();
        }
    }

    // set state for updateSwitch()
    this.initAfterReady = this.model.isReady();
}

From source file:com.centeractive.ws.builder.soap.XmlUtils.java

private static int findNodeIndex(Node node) {
    String nm = node.getLocalName();
    String ns = node.getNamespaceURI();
    short nt = node.getNodeType();

    Node parentNode = node.getParentNode();
    if (parentNode.getNodeType() != Node.ELEMENT_NODE)
        return 1;

    Node child = parentNode.getFirstChild();

    int ix = 0;//from ww w .jav a2s. c o  m
    while (child != null) {
        if (child == node)
            return ix + 1;

        if (child.getNodeType() == nt && nm.equals(child.getLocalName())
                && ((ns == null && child.getNamespaceURI() == null)
                        || (ns != null && ns.equals(child.getNamespaceURI()))))
            ix++;

        child = child.getNextSibling();
    }

    throw new SoapBuilderException("Child node not found in parent!?");
}

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

@SuppressWarnings("unchecked")
private XTeeHeader parseXteeHeader(SOAPMessage paringMessage) throws SOAPException {
    XTeeHeader pais = new XTeeHeader();
    if (paringMessage.getSOAPHeader() == null) {
        return pais;
    }/* w  w w. j  a  v a2  s . c o  m*/

    SOAPHeader header = paringMessage.getSOAPHeader();
    for (Iterator<Node> headerElemendid = header.getChildElements(); headerElemendid.hasNext();) {
        Node headerElement = headerElemendid.next();
        if (!SOAPUtil.isTextNode(headerElement) && headerElement.getFirstChild() != null) {
            String localName = headerElement.getLocalName();
            String value = headerElement.getFirstChild().getNodeValue();
            pais.addElement(new QName(headerElement.getNamespaceURI(), localName), value);
        }
    }
    return pais;
}

From source file:com.mtgi.analytics.aop.config.v11.BtManagerBeanDefinitionParser.java

@Override
protected void transform(ConfigurableListableBeanFactory factory, BeanDefinition template, Element element,
        ParserContext parserContext) {//from ww w.  ja v  a 2  s . com

    ManagerComponentDefinition def = (ManagerComponentDefinition) parserContext.getContainingComponent();

    String managerId = overrideAttribute(ATT_ID, template, element);
    if (managerId == null)
        template.setAttribute(ATT_ID, managerId = "defaultTrackingManager");

    if ("false".equals(element.getAttribute(ATT_ENABLED))) {
        //manager is disabled.  replace definition with dummy instance.
        template.setBeanClassName(DisabledBehaviorTrackingManager.class.getName());
        //clear properties and attributes.
        for (String att : template.attributeNames())
            if (!ATT_ID.equals(att))
                template.removeAttribute(att);
        template.getPropertyValues().clear();
        //terminate immediately, do not parse any nested definitions (persisters, AOP config, context beans, etc)
        return;
    }

    overrideProperty(ATT_APPLICATION, template, element, false);
    overrideProperty(ATT_FLUSH_THRESHOLD, template, element, false);

    //wake up MBeanExporter if we're going to be doing MBean registration.
    if ("true".equalsIgnoreCase(element.getAttribute(ATT_REGISTER_MBEANS))) {
        AbstractBeanDefinition exporter = (AbstractBeanDefinition) factory
                .getBeanDefinition(CONFIG_MBEAN_EXPORTER);
        exporter.setLazyInit(false);

        //append manager ID to mbean name, in case of multiple managers in a single application.
        BeanDefinition naming = factory.getBeanDefinition(CONFIG_NAMING_STRATEGY);
        naming.getPropertyValues().addPropertyValue("value", managerId);
    }

    //prefer references to beans in the parent factory if they've been specified
    if (element.hasAttribute(ATT_MBEAN_SERVER))
        factory.registerAlias(element.getAttribute(ATT_MBEAN_SERVER), CONFIG_MBEAN_SERVER);

    if (element.hasAttribute(ATT_SCHEDULER))
        factory.registerAlias(element.getAttribute(ATT_SCHEDULER), CONFIG_SCHEDULER);

    if (element.hasAttribute(ATT_TASK_EXECUTOR))
        factory.registerAlias(element.getAttribute(ATT_TASK_EXECUTOR), CONFIG_EXECUTOR);

    //make note of external persister element so that we don't activate log rotation.
    if (element.hasAttribute(ATT_PERSISTER)) {
        def.addNestedProperty(ATT_PERSISTER);
        MutablePropertyValues props = template.getPropertyValues();
        props.removePropertyValue(ATT_PERSISTER);
        props.addPropertyValue(ATT_PERSISTER, new RuntimeBeanReference(element.getAttribute(ATT_PERSISTER)));
    }

    if (element.hasAttribute(ATT_SESSION_CONTEXT)) {
        //override default session context with reference
        def.addNestedProperty("sessionContext");
        factory.registerAlias(element.getAttribute(ATT_SESSION_CONTEXT), CONFIG_SESSION_CONTEXT);
    }

    //handle AOP configuration if needed
    if (element.hasAttribute(ATT_METHOD_EXPRESSION)) {
        //activate global AOP proxying if it hasn't already been done (borrowed logic from AopNamespaceHandler / config element parser)
        activateAopProxies(parserContext, element);

        //register pointcut definition for the provided expression.
        RootBeanDefinition pointcut = new RootBeanDefinition(AspectJExpressionPointcut.class);
        //rely on deprecated method to maintain spring 2.0 support
        pointcut.setSingleton(false);
        pointcut.setSynthetic(true);
        pointcut.getPropertyValues().addPropertyValue("expression",
                element.getAttribute(ATT_METHOD_EXPRESSION));

        //create implicit pointcut advice bean.
        RootBeanDefinition advice = new RootBeanDefinition(BehaviorTrackingAdvice.class);
        advice.getPropertyValues().addPropertyValue("trackingManager", new RuntimeBeanReference(managerId));

        //register advice, pointcut, and advisor entry to bind the two together.
        XmlReaderContext ctx = parserContext.getReaderContext();
        String pointcutId = ctx.registerWithGeneratedName(pointcut);
        String adviceId = ctx.registerWithGeneratedName(advice);

        RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class);
        advisorDefinition.getPropertyValues().addPropertyValue("adviceBeanName",
                new RuntimeBeanNameReference(adviceId));
        advisorDefinition.getPropertyValues().addPropertyValue("pointcut",
                new RuntimeBeanReference(pointcutId));
        ctx.registerWithGeneratedName(advisorDefinition);
    }

    //configure flush trigger and job to be globally unique based on manager name.
    BeanDefinition flushTrigger = factory.getBeanDefinition("com.mtgi.analytics.btFlushTrigger");
    SchedulerActivationPostProcessor.configureTriggerDefinition(flushTrigger,
            element.getAttribute(ATT_FLUSH_SCHEDULE), managerId + "_flush");

    //set up a post-processor to register the flush job with the selected scheduler instance.  the job and scheduler
    //come from the template factory, but the post-processor runs when the currently-parsing factory is finished.
    SchedulerActivationPostProcessor.registerPostProcessor(parserContext, factory, CONFIG_SCHEDULER,
            CONFIG_NAMESPACE + ".btFlushTrigger");

    //ManagerComponentDefinition is a flag to nested parsers that they should push their parsed bean definitions into
    //the manager bean definition.  for example, see BtPersisterBeanDefinitionParser.
    //descend on nested child nodes to pick up persister and session context configuration
    NodeList children = element.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String namespaceUri = node.getNamespaceURI();
            NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver()
                    .resolve(namespaceUri);
            ParserContext nestedCtx = new ParserContext(parserContext.getReaderContext(),
                    parserContext.getDelegate(), template);
            nestedCtx.pushContainingComponent(def);
            handler.parse((Element) node, nestedCtx);
        }
    }

    if (!def.nestedProperties.contains(ATT_PERSISTER)) {
        //no persister registered.  schedule default log rotation trigger.
        BtXmlPersisterBeanDefinitionParser.configureLogRotation(parserContext, factory, null);
    }

    if (!def.nestedProperties.contains("sessionContext")) {
        //custom session context not registered.  select appropriate default class
        //depending on whether we are in a web context or not.
        if (parserContext.getReaderContext().getReader().getResourceLoader() instanceof WebApplicationContext) {
            BeanDefinition scDef = factory.getBeanDefinition(CONFIG_SESSION_CONTEXT);
            scDef.setBeanClassName(SpringSessionContext.class.getName());
        }
    }
}

From source file:org.jdal.vaadin.beans.TableBeanDefinitionParser.java

/**
 * {@inheritDoc}/*  w  w  w  .j a  v a2  s  .co m*/
 */
@SuppressWarnings("rawtypes")
public BeanDefinition parse(Element element, ParserContext parserContext) {
    // Defaults
    String entity = null;

    if (element.hasAttribute(ENTITY))
        entity = element.getAttribute(ENTITY);

    String name = StringUtils.uncapitalize(StringUtils.substringAfterLast(entity, "."));

    if (element.hasAttribute(ID))
        name = element.getAttribute(ID);

    parserContext.pushContainingComponent(
            new CompositeComponentDefinition(name, parserContext.extractSource(element)));

    // Bean names
    String pageableTableBeanName = name + PAGEABLE_TABLE_SUFFIX;
    String tableBeanName = name + TABLE_SUFFIX;
    String dataSource = name + SERVICE_SUFFIX;
    String paginator = PAGINATOR_VIEW;
    String editor = name + EDITOR_SUFFIX;
    String actions = DefaultsBeanDefinitionParser.DEFAULT_TABLE_ACTIONS;
    String guiFactory = DefaultsBeanDefinitionParser.DEFAULT_GUI_FACTORY;
    String scope = BeanDefinition.SCOPE_PROTOTYPE;
    String pageableTableClass = DEFAULT_PAGEABLE_TABLE_CLASS;
    String tableClass = DEFAULT_TABLE_CLASS;

    if (element.hasAttribute(DATA_SOURCE))
        dataSource = element.getAttribute(DATA_SOURCE);

    if (element.hasAttribute(PAGINATOR))
        paginator = element.getAttribute(PAGINATOR);

    if (element.hasAttribute(ACTIONS))
        actions = element.getAttribute(ACTIONS);

    if (element.hasAttribute(GUI_FACTORY))
        guiFactory = element.getAttribute(GUI_FACTORY);

    if (element.hasAttribute(EDITOR))
        editor = element.getAttribute(EDITOR);

    if (element.hasAttribute(SCOPE))
        scope = element.getAttribute(SCOPE);

    if (element.hasAttribute(PAGEABLE_TABLE_CLASS))
        pageableTableClass = element.getAttribute(PAGEABLE_TABLE_CLASS);

    if (element.hasAttribute(TABLE_CLASS))
        tableClass = element.getAttribute(TABLE_CLASS);

    // create PageableTable
    BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(pageableTableClass);
    bdb.setScope(scope);
    bdb.addPropertyReference(DATA_SOURCE, dataSource);
    bdb.addPropertyReference(PAGINATOR_VIEW, paginator);
    bdb.addPropertyValue(NAME, pageableTableBeanName);
    bdb.addPropertyReference(TABLE, tableBeanName);
    bdb.addPropertyReference(GUI_FACTORY, guiFactory);
    bdb.addPropertyValue(EDITOR_NAME, editor);
    bdb.addPropertyValue(ENTITY_CLASS, entity);

    BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, TABLE_SERVICE);
    BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER);
    BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, MESSAGE_SOURCE);
    BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FILTER_FORM);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, SORT_PROPERTY);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, ORDER);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PAGE_SIZE);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, NATIVE_BUTTONS);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, PROPAGATE_SERVICE);

    if (!element.hasAttribute(USE_ACTIONS) || "true".equals(element.getAttribute(USE_ACTIONS)))
        bdb.addPropertyReference(ACTIONS, actions);

    parserContext.getDelegate().parseBeanDefinitionAttributes(element, pageableTableBeanName, null,
            bdb.getBeanDefinition());

    BeanDefinitionHolder holder = new BeanDefinitionHolder(bdb.getBeanDefinition(), pageableTableBeanName);

    // Test Decorators like aop:scoped-proxy
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node n = childNodes.item(i);
        if (Node.ELEMENT_NODE != n.getNodeType() || COLUMNS.equals(n.getLocalName()))
            continue;

        NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver()
                .resolve(n.getNamespaceURI());
        if (handler != null) {
            holder = handler.decorate(n, holder, parserContext);
        }
    }

    parserContext.registerBeanComponent(new BeanComponentDefinition(holder));

    // create ConfigurableTable
    bdb = BeanDefinitionBuilder.genericBeanDefinition(tableClass);
    bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);

    BeanDefinitionUtils.addPropertyReferenceIfNeeded(bdb, element, FIELD_FACTORY);
    BeanDefinitionUtils.addPropertyValueIfNeeded(bdb, element, MULTISELECT);

    if (element.hasAttribute(SELECTABLE)) {
        bdb.addPropertyValue(SELECTABLE, element.getAttribute(SELECTABLE));
    } else {
        // set selectable by default
        bdb.addPropertyValue(SELECTABLE, true);
    }

    // parse columns
    NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), COLUMNS);

    if (nl.getLength() > 0) {
        List columns = parserContext.getDelegate().parseListElement((Element) nl.item(0),
                bdb.getRawBeanDefinition());
        bdb.addPropertyValue(COLUMNS, columns);
    }

    registerBeanDefinition(element, parserContext, tableBeanName, bdb);

    parserContext.popAndRegisterContainingComponent();

    return null;
}

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

/**
 * Tests namespace.//  w ww. j  av  a2 s .com
 * @throws Exception if the test fails
 */
@Test
public void namespace() throws Exception {
    final String content = "<?xml version='1.0'?>\n"
            + "<RDF xmlns='http://www.w3.org/1999/02/22-rdf-syntax-ns#' "
            + "xmlns:em='http://www.mozilla.org/2004/em-rdf#'>"
            + "<Description about='urn:mozilla:install-manifest'>" + "<em:name>My Plugin</em:name>"
            + "</Description>\n" + "</RDF>";

    final XmlPage xmlPage = testDocument(content, "text/xml");
    final Node node = xmlPage.getXmlDocument().getFirstChild().getFirstChild().getFirstChild();
    assertEquals("em:name", node.getNodeName());
    assertEquals("name", node.getLocalName());
    assertEquals("http://www.mozilla.org/2004/em-rdf#", node.getNamespaceURI());
}

From source file:cz.muni.fi.mir.mathmlunificator.MathMLUnificator.java

/**
 * Replace the given node with unification element containing unification
 * representing symbol {@code &#x25CD;} (for Presentation MathML, see
 * {@link Constants#PMATHML_UNIFICATOR}) or {@code &#x25D0;} (for Content
 * MathML, see {@link Constants#CMATHML_UNIFICATOR}).
 *
 * @param oldNode The node to be replaced with the unification representing
 * element./*  w  w  w.j  a  v  a 2s .co  m*/
 * @throws IllegalArgumentException If the given node does not have parent.
 */
public static void replaceNodeWithUnificator(Node oldNode) {

    Node parentNode = oldNode.getParentNode();

    if (parentNode == null) {
        throw new IllegalArgumentException("Cannot replace node [" + oldNode + "] that has no parent.");
    } else {
        if (!Constants.CMATHML_ANNOTATIONS.contains(oldNode.getNodeName())) { // Do not modify annotation elements!
            String unificator = PMATHML_UNIFICATOR;
            String unificatorElementType = oldNode.getNodeName().equals(PMATHML_OPERATOR) ? PMATHML_OPERATOR
                    : PMATHML_IDENTIFIER;
            if (MathMLTools.isContentMathMLNode(oldNode)) {
                unificator = CMATHML_UNIFICATOR;
                unificatorElementType = Constants.CMATHML_IDENTIFIER_OR_NUMBER.contains(oldNode.getNodeName())
                        ? CMATHML_IDENTIFIER
                        : CMATHML_SYMBOL;
            }
            Node newNode = oldNode.getOwnerDocument().createElementNS(oldNode.getNamespaceURI(),
                    unificatorElementType);
            newNode.setTextContent(unificator);
            parentNode.replaceChild(newNode, oldNode);
        }
    }

}