Java Code Examples for org.w3c.dom.Element#lookupNamespaceURI()

The following examples show how to use org.w3c.dom.Element#lookupNamespaceURI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAXWSBindingExtensionHandler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context
 * @param jaxwsBinding
 * @param e
 */
private void parseParameter(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
    String part = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.PART_ATTR);
    Element msgPartElm = evaluateXPathNode(e.getOwnerDocument(), part, new NamespaceContextImpl(e));
    Node msgElm = msgPartElm.getParentNode();
    //MessagePart msgPart = new MessagePart();

    String partName = XmlUtil.getAttributeOrNull(msgPartElm, "name");
    String msgName = XmlUtil.getAttributeOrNull((Element)msgElm, "name");
    if ((partName == null) || (msgName == null)) {
        return;
    }

    String element = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.ELEMENT_ATTR);
    String name = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);

    QName elementName = null;
    if(element != null){
        String uri = e.lookupNamespaceURI(XmlUtil.getPrefix(element));
        elementName = (uri == null)?null:new QName(uri, XmlUtil.getLocalPart(element));
    }

    jaxwsBinding.addParameter(new Parameter(msgName, partName, elementName, name));
}
 
Example 2
Source File: JAXWSBindingExtensionHandler.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context
 * @param jaxwsBinding
 * @param e
 */
private void parseParameter(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
    String part = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.PART_ATTR);
    Element msgPartElm = evaluateXPathNode(e.getOwnerDocument(), part, new NamespaceContextImpl(e));
    Node msgElm = msgPartElm.getParentNode();
    //MessagePart msgPart = new MessagePart();

    String partName = XmlUtil.getAttributeOrNull(msgPartElm, "name");
    String msgName = XmlUtil.getAttributeOrNull((Element)msgElm, "name");
    if ((partName == null) || (msgName == null)) {
        return;
    }

    String element = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.ELEMENT_ATTR);
    String name = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);

    QName elementName = null;
    if(element != null){
        String uri = e.lookupNamespaceURI(XmlUtil.getPrefix(element));
        elementName = (uri == null)?null:new QName(uri, XmlUtil.getLocalPart(element));
    }

    jaxwsBinding.addParameter(new Parameter(msgName, partName, elementName, name));
}
 
Example 3
Source File: JAXWSBindingExtensionHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context
 * @param jaxwsBinding
 * @param e
 */
private void parseParameter(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
    String part = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.PART_ATTR);
    Element msgPartElm = evaluateXPathNode(e.getOwnerDocument(), part, new NamespaceContextImpl(e));
    Node msgElm = msgPartElm.getParentNode();
    //MessagePart msgPart = new MessagePart();

    String partName = XmlUtil.getAttributeOrNull(msgPartElm, "name");
    String msgName = XmlUtil.getAttributeOrNull((Element)msgElm, "name");
    if ((partName == null) || (msgName == null)) {
        return;
    }

    String element = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.ELEMENT_ATTR);
    String name = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);

    QName elementName = null;
    if(element != null){
        String uri = e.lookupNamespaceURI(XmlUtil.getPrefix(element));
        elementName = (uri == null)?null:new QName(uri, XmlUtil.getLocalPart(element));
    }

    jaxwsBinding.addParameter(new Parameter(msgName, partName, elementName, name));
}
 
Example 4
Source File: JAXWSBindingExtensionHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context
 * @param jaxwsBinding
 * @param e
 */
private void parseParameter(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
    String part = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.PART_ATTR);
    Element msgPartElm = evaluateXPathNode(e.getOwnerDocument(), part, new NamespaceContextImpl(e));
    Node msgElm = msgPartElm.getParentNode();
    //MessagePart msgPart = new MessagePart();

    String partName = XmlUtil.getAttributeOrNull(msgPartElm, "name");
    String msgName = XmlUtil.getAttributeOrNull((Element)msgElm, "name");
    if ((partName == null) || (msgName == null)) {
        return;
    }

    String element = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.ELEMENT_ATTR);
    String name = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);

    QName elementName = null;
    if(element != null){
        String uri = e.lookupNamespaceURI(XmlUtil.getPrefix(element));
        elementName = (uri == null)?null:new QName(uri, XmlUtil.getLocalPart(element));
    }

    jaxwsBinding.addParameter(new Parameter(msgName, partName, elementName, name));
}
 
Example 5
Source File: JAXWSBindingExtensionHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context
 * @param jaxwsBinding
 * @param e
 */
private void parseParameter(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
    String part = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.PART_ATTR);
    Element msgPartElm = evaluateXPathNode(e.getOwnerDocument(), part, new NamespaceContextImpl(e));
    Node msgElm = msgPartElm.getParentNode();
    //MessagePart msgPart = new MessagePart();

    String partName = XmlUtil.getAttributeOrNull(msgPartElm, "name");
    String msgName = XmlUtil.getAttributeOrNull((Element)msgElm, "name");
    if ((partName == null) || (msgName == null)) {
        return;
    }

    String element = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.ELEMENT_ATTR);
    String name = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);

    QName elementName = null;
    if(element != null){
        String uri = e.lookupNamespaceURI(XmlUtil.getPrefix(element));
        elementName = (uri == null)?null:new QName(uri, XmlUtil.getLocalPart(element));
    }

    jaxwsBinding.addParameter(new Parameter(msgName, partName, elementName, name));
}
 
Example 6
Source File: JAXWSBindingExtensionHandler.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context
 * @param jaxwsBinding
 * @param e
 */
private void parseParameter(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
    String part = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.PART_ATTR);
    Element msgPartElm = evaluateXPathNode(e.getOwnerDocument(), part, new NamespaceContextImpl(e));
    Node msgElm = msgPartElm.getParentNode();
    //MessagePart msgPart = new MessagePart();

    String partName = XmlUtil.getAttributeOrNull(msgPartElm, "name");
    String msgName = XmlUtil.getAttributeOrNull((Element)msgElm, "name");
    if ((partName == null) || (msgName == null)) {
        return;
    }

    String element = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.ELEMENT_ATTR);
    String name = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);

    QName elementName = null;
    if(element != null){
        String uri = e.lookupNamespaceURI(XmlUtil.getPrefix(element));
        elementName = (uri == null)?null:new QName(uri, XmlUtil.getLocalPart(element));
    }

    jaxwsBinding.addParameter(new Parameter(msgName, partName, elementName, name));
}
 
Example 7
Source File: JAXWSBindingExtensionHandler.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context
 * @param jaxwsBinding
 * @param e
 */
private void parseParameter(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
    String part = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.PART_ATTR);
    Element msgPartElm = evaluateXPathNode(e.getOwnerDocument(), part, new NamespaceContextImpl(e));
    Node msgElm = msgPartElm.getParentNode();
    //MessagePart msgPart = new MessagePart();

    String partName = XmlUtil.getAttributeOrNull(msgPartElm, "name");
    String msgName = XmlUtil.getAttributeOrNull((Element)msgElm, "name");
    if ((partName == null) || (msgName == null)) {
        return;
    }

    String element = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.ELEMENT_ATTR);
    String name = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);

    QName elementName = null;
    if(element != null){
        String uri = e.lookupNamespaceURI(XmlUtil.getPrefix(element));
        elementName = (uri == null)?null:new QName(uri, XmlUtil.getLocalPart(element));
    }

    jaxwsBinding.addParameter(new Parameter(msgName, partName, elementName, name));
}
 
Example 8
Source File: JAXWSBindingExtensionHandler.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param context
 * @param jaxwsBinding
 * @param e
 */
private void parseParameter(com.sun.tools.internal.ws.api.wsdl.TWSDLParserContext context, JAXWSBinding jaxwsBinding, Element e) {
    String part = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.PART_ATTR);
    Element msgPartElm = evaluateXPathNode(e.getOwnerDocument(), part, new NamespaceContextImpl(e));
    Node msgElm = msgPartElm.getParentNode();
    //MessagePart msgPart = new MessagePart();

    String partName = XmlUtil.getAttributeOrNull(msgPartElm, "name");
    String msgName = XmlUtil.getAttributeOrNull((Element)msgElm, "name");
    if ((partName == null) || (msgName == null)) {
        return;
    }

    String element = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.ELEMENT_ATTR);
    String name = XmlUtil.getAttributeOrNull(e, JAXWSBindingsConstants.NAME_ATTR);

    QName elementName = null;
    if(element != null){
        String uri = e.lookupNamespaceURI(XmlUtil.getPrefix(element));
        elementName = (uri == null)?null:new QName(uri, XmlUtil.getLocalPart(element));
    }

    jaxwsBinding.addParameter(new Parameter(msgName, partName, elementName, name));
}
 
Example 9
Source File: XMLHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Looks up the namespace prefix associated with the given URI starting at the given element. This method differs
 * from the {@link Node#lookupPrefix(java.lang.String)} in that it only those namespaces declared by an xmlns
 * attribute are inspected. The Node method also checks the namespace a particular node was created in by way of a
 * call like {@link Document#createElementNS(java.lang.String, java.lang.String)} even if the resulting element
 * doesn't have an namespace delcaration attribute.
 * 
 * @param startingElement the starting element
 * @param stopingElement the ancestor of the starting element that serves as the upper-bound, inclusive, for the
 *            search
 * @param namespaceURI the uri to look up
 * 
 * @return the prefix for the given namespace URI
 */
public static String lookupPrefix(Element startingElement, Element stopingElement, String namespaceURI) {
    String namespace;

    // This code is a modified version of the lookup code within Xerces
    if (startingElement.hasAttributes()) {
        NamedNodeMap map = startingElement.getAttributes();
        int length = map.getLength();
        for (int i = 0; i < length; i++) {
            Node attr = map.item(i);
            String attrPrefix = attr.getPrefix();
            String value = attr.getNodeValue();
            namespace = attr.getNamespaceURI();
            if (namespace != null && namespace.equals(XMLConstants.XMLNS_NS)) {
                // DOM Level 2 nodes
                if (attr.getNodeName().equals(XMLConstants.XMLNS_PREFIX)
                        || (attrPrefix != null && attrPrefix.equals(XMLConstants.XMLNS_PREFIX))
                        && value.equals(namespaceURI)) {

                    String localname = attr.getLocalName();
                    String foundNamespace = startingElement.lookupNamespaceURI(localname);
                    if (foundNamespace != null && foundNamespace.equals(namespaceURI)) {
                        return localname;
                    }
                }

            }
        }
    }

    if (startingElement != stopingElement) {
        Element ancestor = getElementAncestor(startingElement);
        if (ancestor != null) {
            return lookupPrefix(ancestor, stopingElement, namespaceURI);
        }
    }

    return null;
}
 
Example 10
Source File: CustomizationParser.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void copyJaxbAttributes(Node childNode, Element schemaNode) {
    if (childNode instanceof Element) {
        Element el = (Element)childNode;
        if (el.getParentNode() != null) {
            copyJaxbAttributes(el.getParentNode(), schemaNode);
        }
        NamedNodeMap atts = el.getAttributes();
        for (int x = 0; x < atts.getLength(); x++) {
            Attr attr = (Attr)atts.item(x);
            if (ToolConstants.NS_JAXB_BINDINGS.equals(attr.getNamespaceURI())) {
                Attr attrnew = schemaNode.getOwnerDocument().createAttributeNS(attr.getNamespaceURI(),
                                                                            attr.getName());
                attrnew.setValue(attr.getValue());
                schemaNode.setAttributeNodeNS(attrnew);

                if ("extensionBindingPrefixes".equals(attr.getLocalName())) {
                    String pfxs = attr.getValue();
                    while (pfxs.length() > 0) {
                        String pfx = pfxs;
                        int idx = pfx.indexOf(' ');
                        if (idx != -1) {
                            pfxs = pfxs.substring(idx + 1);
                            pfx = pfx.substring(0, idx);
                        } else {
                            pfxs = "";
                        }
                        String ns = el.lookupNamespaceURI(pfx);
                        schemaNode.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
                                                  "xmlns:" + pfx,
                                                  ns);
                    }
                }
            }
        }
    }

}
 
Example 11
Source File: AnnotationHandlerChainBuilder.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean patternMatches(Element el, QName comp) {
    if (comp == null) {
        return true;
    }
    String namePattern = el.getTextContent().trim();
    if ("*".equals(namePattern)) {
        return true;
    }
    final int idx = namePattern.indexOf(':');
    if (idx < 0) {
        String xml = StaxUtils.toString(el);
        throw new WebServiceException(
            BundleUtils.getFormattedString(BUNDLE,
                                           "NOT_A_QNAME_PATTER",
                                           namePattern, xml));
    }
    String pfx = namePattern.substring(0, idx);
    String ns = el.lookupNamespaceURI(pfx);
    if (ns == null) {
        ns = pfx;
    }
    if (!ns.equals(comp.getNamespaceURI())) {
        return false;
    }
    String localPart = namePattern.substring(idx + 1,
                                             namePattern.length());
    if (localPart.contains("*")) {
        //wildcard pattern matching
        return Pattern.matches(mapPattern(localPart), comp.getLocalPart());
    } else if (!localPart.equals(comp.getLocalPart())) {
        return false;
    }
    return true;
}
 
Example 12
Source File: WadlGeneratorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private boolean checkTypeName(Element el, String typeName, String name) {
    String pfx = "";
    String tn = typeName;
    if (tn.contains(":")) {
        pfx = tn.substring(0, tn.indexOf(':'));
        tn = tn.substring(tn.indexOf(':') + 1);
    }
    pfx = el.lookupNamespaceURI(pfx);

    return tn.equals(name) && pfx.length() > 5;
}
 
Example 13
Source File: Suite.java    From teamengine with Apache License 2.0 4 votes vote down vote up
public Suite(Element suiteElement) {
    String name = suiteElement.getAttribute("name");
    this.version = suiteElement.getAttribute("version");

    int colon = name.indexOf(":");
    prefix = name.substring(0, colon);
    localName = name.substring(colon + 1);
    namespaceUri = suiteElement.lookupNamespaceURI(prefix);

    NodeList titleElements = suiteElement.getElementsByTagNameNS(
            Test.CTL_NS, "title");
    title = ((Element) titleElements.item(0)).getTextContent();

    NodeList descElements = suiteElement.getElementsByTagNameNS(
            Test.CTL_NS, "description");
    if (descElements.getLength() > 0) {
        description = ((Element) descElements.item(0)).getTextContent();
    } else {
        description = null;
    }

    NodeList linkElements = suiteElement.getElementsByTagNameNS(
            Test.CTL_NS, "link");
    for (int i = 0; i < linkElements.getLength(); i++) {
        Element linkElem = (Element) linkElements.item(i);
        String linkText = linkElem.getTextContent();
        if (linkText.startsWith("data")) {
            this.dataLink = linkText;
        } else {
            this.link = linkText;
        }
    }

    NodeList startingTestElements = suiteElement.getElementsByTagNameNS(
            Test.CTL_NS, "starting-test");
    name = ((Element) startingTestElements.item(0)).getTextContent();
    colon = name.indexOf(":");
    startingTestPrefix = name.substring(0, colon);
    startingTestLocalName = name.substring(colon + 1);
    startingTestNamespaceUri = suiteElement
            .lookupNamespaceURI(startingTestPrefix);
}