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:org.apache.axis.message.MessageElement.java

/**
 * recursive copy/*from  w  w w  .j  av a 2  s . c  o m*/
 * @param dest element to copy into
 * @param source child element
 */
private void copyNode(MessageElement dest, org.w3c.dom.Node source) {
    dest.setPrefix(source.getPrefix());
    if (source.getLocalName() != null) {
        dest.setQName(new QName(source.getNamespaceURI(), source.getLocalName()));
    } else {
        dest.setQName(new QName(source.getNamespaceURI(), source.getNodeName()));
    }

    NamedNodeMap attrs = source.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Node att = attrs.item(i);
        if (att.getNamespaceURI() != null && att.getPrefix() != null
                && att.getNamespaceURI().equals(Constants.NS_URI_XMLNS) && "xmlns".equals(att.getPrefix())) {
            Mapping map = new Mapping(att.getNodeValue(), att.getLocalName());
            dest.addMapping(map);
        }
        if (att.getLocalName() != null) {
            dest.addAttribute(att.getPrefix(), (att.getNamespaceURI() != null ? att.getNamespaceURI() : ""),
                    att.getLocalName(), att.getNodeValue());
        } else if (att.getNodeName() != null) {
            dest.addAttribute(att.getPrefix(), (att.getNamespaceURI() != null ? att.getNamespaceURI() : ""),
                    att.getNodeName(), att.getNodeValue());
        }
    }

    NodeList children = source.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child.getNodeType() == TEXT_NODE || child.getNodeType() == CDATA_SECTION_NODE
                || child.getNodeType() == COMMENT_NODE) {
            org.apache.axis.message.Text childElement = new org.apache.axis.message.Text((CharacterData) child);
            dest.appendChild(childElement);
        } else {
            MessageElement childElement = new MessageElement();
            dest.appendChild(childElement);
            copyNode(childElement, child);
        }
    }
}

From source file:org.apache.axis.wsdl.toJava.Utils.java

/**
* Determines if the DOM Node represents an xs:<node>
*/// www  .  j a  v  a  2  s .co  m
public static boolean isXsNode(Node node, String nameName) {
    return (node.getLocalName().equals(nameName) && Constants.isSchemaXSD(node.getNamespaceURI()));
}

From source file:org.apache.axis2.jaxws.client.dispatch.BaseDispatch.java

/**
 * Given a JAXWS Message Context which contains an outbound service-requester Message for a Dispatch client,
 * determine the QName of the first body element contained in that message.
 * /*from ww  w .  j av a  2 s  . c  o m*/
 * @param requestMessageCtx requestMessageCtx JAXWS Message Context containing the outbound Dispatch message
 * @return the QName of the first body element contained in the outbound Dispatch message, or null if it 
 * can not be determined.
 */
QName getBodyElementQNameFromDispatchMessage(MessageContext requestMessageCtx) {
    QName bodyElementQName = null;
    Message dispatchMessage = requestMessageCtx.getMessage();
    SOAPMessage soapMessage = dispatchMessage.getAsSOAPMessage();
    try {
        SOAPBody soapBody = soapMessage.getSOAPBody();
        Node firstElement = soapBody.getFirstChild();
        // A Doc/Lit/Bare message may not have a firsElement.  The soap:Body element may be empty if there 
        // are no arguments to the operation.
        if (firstElement != null) {
            String ns = firstElement.getNamespaceURI();
            String lp = firstElement.getLocalName();
            // A Doc/Lit/Bare message may not have a localPart on the element.  That can happen if the first element
            // is the argument value and there is no wrapper element surrounding it.
            if (lp != null) {
                bodyElementQName = new QName(ns, lp);
            }
        }
    } catch (SOAPException e) {
        if (log.isDebugEnabled()) {
            log.debug("Unabled to get the first body element from the outbound dispatch message", e);
        }
    }
    return bodyElementQName;
}

From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java

protected void replacePrefixForNode(Node node, Input input) {
    if (XMLSignature.XMLNS.equals(node.getNamespaceURI())) {
        node.setPrefix(input.getPrefixForXmlSignatureNamespace());
    } else if (findNamespace(input.getMessage()).equals(node.getNamespaceURI())) {
        node.setPrefix(findPrefix(input.getMessage()));
    }//  w ww .  j av a  2  s  .co  m
}

From source file:org.apache.camel.spring.handler.CamelNamespaceHandler.java

public static void renameNamespaceRecursive(Node node) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Document doc = node.getOwnerDocument();
        if (node.getNamespaceURI().startsWith(SPRING_NS + "/v")) {
            doc.renameNode(node, SPRING_NS, node.getNodeName());
        }//from  ww w  .j  a v  a  2 s  . c  o  m
    }
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); ++i) {
        renameNamespaceRecursive(list.item(i));
    }
}

From source file:org.apache.cocoon.forms.util.DomHelper.java

/**
 * Returns all Element children of an Element that belong to the given
 * namespace.//from   w  w w .  j a v  a  2  s .  com
 */
public static Element[] getChildElements(Element element, String namespace) {
    ArrayList elements = new ArrayList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI()))
            elements.add(node);
    }
    return (Element[]) elements.toArray(new Element[elements.size()]);
}

From source file:org.apache.cocoon.forms.util.DomHelper.java

/**
 * Returns all Element children of an Element that belong to the given
 * namespace and have the given local name.
 *///from w  w  w .ja  va2  s  . c o  m
public static Element[] getChildElements(Element element, String namespace, String localName) {
    ArrayList elements = new ArrayList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI())
                && localName.equals(node.getLocalName())) {
            elements.add(node);
        }
    }
    return (Element[]) elements.toArray(new Element[elements.size()]);
}

From source file:org.apache.cocoon.forms.util.DomHelper.java

/**
 * Returns the first child element with the given namespace and localName,
 * or null if there is no such element and required flag is unset or
 * throws an Exception if the "required" flag is set.
 *//*  ww w  .  j a  v  a2 s .c  o  m*/
public static Element getChildElement(Element element, String namespace, String localName, boolean required)
        throws Exception {
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI())
                && localName.equals(node.getLocalName())) {
            return (Element) node;
        }
    }
    if (required) {
        throw new Exception("Missing element \"" + localName + "\" as child of element \""
                + element.getTagName() + "\" at " + DomHelper.getLocation(element));
    } else {
        return null;
    }
}

From source file:org.apache.cocoon.woody.util.DomHelper.java

/**
 * Returns all Element children of an Element that belong to the given
 * namespace.// w  ww .  j ava 2  s. c  o  m
 */
public static Element[] getChildElements(Element element, String namespace) {
    ArrayList elements = new ArrayList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI()))
            elements.add(node);
    }
    return (Element[]) elements.toArray(new Element[0]);
}

From source file:org.apache.cocoon.woody.util.DomHelper.java

/**
 * Returns all Element children of an Element that belong to the given
 * namespace and have the given local name.
 *//*from   ww  w  . j  a v a 2s  .c om*/
public static Element[] getChildElements(Element element, String namespace, String localName) {
    ArrayList elements = new ArrayList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI())
                && localName.equals(node.getLocalName())) {
            elements.add(node);
        }
    }
    return (Element[]) elements.toArray(new Element[0]);
}