Example usage for org.w3c.dom Element getNamespaceURI

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

Introduction

In this page you can find the example usage for org.w3c.dom Element 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.ode.il.epr.WSAEndpoint.java

public boolean accept(Node node) {
    if (node == null) {
        return false;
    }//w ww  .ja  va2s  .  c  o m
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element elmt = (Element) node;
        if (elmt.getLocalName().equals(SERVICE_REF_QNAME.getLocalPart())
                && elmt.getNamespaceURI().equals(SERVICE_REF_QNAME.getNamespaceURI()))
            elmt = DOMUtils.getFirstChildElement(elmt);
        if (elmt != null && elmt.getLocalName().equals("EndpointReference")
                && elmt.getNamespaceURI().equals(Namespaces.WS_ADDRESSING_NS))
            return true;
    }
    return false;
}

From source file:org.apache.ode.il.OMUtils.java

public static OMElement toOM(Element src, OMFactory omf, OMContainer parent) {
    OMElement omElement = parent == null ? omf.createOMElement(src.getLocalName(), null)
            : omf.createOMElement(src.getLocalName(), null, parent);
    if (src.getNamespaceURI() != null) {
        if (src.getPrefix() != null)
            omElement.setNamespace(omf.createOMNamespace(src.getNamespaceURI(), src.getPrefix()));
        else/*from   w w w .  j ava  2s.com*/
            omElement.declareDefaultNamespace(src.getNamespaceURI());
    }

    if (parent == null) {
        NSContext nscontext = DOMUtils.getMyNSContext(src);
        injectNamespaces(omElement, nscontext.toMap());
    } else {
        Map<String, String> nss = DOMUtils.getMyNamespaces(src);
        injectNamespaces(omElement, nss);
    }

    NamedNodeMap attrs = src.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        Attr attr = (Attr) attrs.item(i);
        if (attr.getLocalName().equals("xmlns")
                || (attr.getNamespaceURI() != null && attr.getNamespaceURI().equals(DOMUtils.NS_URI_XMLNS)))
            continue;
        OMNamespace attrOmNs = null;
        String attrNs = attr.getNamespaceURI();
        String attrPrefix = attr.getPrefix();
        if (attrNs != null)
            attrOmNs = omElement.findNamespace(attrNs, null);
        if (attrOmNs == null && attrPrefix != null)
            attrOmNs = omElement.findNamespace(null, attrPrefix);
        omElement.addAttribute(attr.getLocalName(), attr.getValue(), attrOmNs);
    }

    NodeList children = src.getChildNodes();
    for (int i = 0; i < children.getLength(); ++i) {
        Node n = children.item(i);

        switch (n.getNodeType()) {
        case Node.CDATA_SECTION_NODE:
            omElement.addChild(omf.createOMText(((CDATASection) n).getTextContent(), XMLStreamConstants.CDATA));
            break;
        case Node.TEXT_NODE:
            omElement.addChild(omf.createOMText(((Text) n).getTextContent(), XMLStreamConstants.CHARACTERS));
            break;
        case Node.ELEMENT_NODE:
            toOM((Element) n, omf, omElement);
            break;
        }

    }

    return omElement;
}

From source file:org.apache.ode.jbi.EndpointReferenceContextImpl.java

public EndpointReference resolveEndpointReference(Element epr) {
    QName elname = new QName(epr.getNamespaceURI(), epr.getLocalName());

    if (__log.isDebugEnabled()) {
        __log.debug("resolveEndpointReference:\n" + prettyPrint(epr));
    }//from w w  w  .ja v a  2s  .c  om
    if (!elname.equals(EndpointReference.SERVICE_REF_QNAME))
        throw new IllegalArgumentException(
                "EPR root element " + elname + " should be " + EndpointReference.SERVICE_REF_QNAME);

    Document doc = DOMUtils.newDocument();
    DocumentFragment fragment = doc.createDocumentFragment();
    NodeList children = epr.getChildNodes();
    for (int i = 0; i < children.getLength(); ++i)
        if (children.item(i) instanceof Element)
            fragment.appendChild(doc.importNode(children.item(i), true));
    ServiceEndpoint se = _ode.getContext().resolveEndpointReference(fragment);
    if (se == null)
        return null;
    return new JbiEndpointReference(se);
}

From source file:org.apache.ode.jbi.util.SchemaCollection.java

protected void handleImports(Schema schema) throws Exception {
    NodeList children = schema.getRoot().getChildNodes();
    List imports = new ArrayList();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            Element ce = (Element) child;
            if ("http://www.w3.org/2001/XMLSchema".equals(ce.getNamespaceURI())
                    && "import".equals(ce.getLocalName())) {
                imports.add(ce);/*from  ww w. ja va 2 s  .  c om*/
            }
        }
    }
    for (Iterator iter = imports.iterator(); iter.hasNext();) {
        Element ce = (Element) iter.next();
        String namespace = ce.getAttribute("namespace");
        if (schemas.get(namespace) == null) {
            String location = ce.getAttribute("schemaLocation");
            if (location != null && !"".equals(location)) {
                read(location, schema.getSourceUri());
            }
        }
        schema.addImport(namespace);
        schema.getRoot().removeChild(ce);
    }
}

From source file:org.apache.ode.utils.DOMUtils.java

/**
 * Perform a naive check to see if a document is a WSDL document
 * based on the root element name and namespace URI.
 * @param d the {@link Document} to check
 * @return <code>true</code> if the root element appears correct
 *//*from ww w.j a va 2 s .c o m*/
public static boolean isWsdlDocument(Document d) {
    Element e = d.getDocumentElement();
    String uri = e.getNamespaceURI();
    String localName = e.getLocalName();
    if (uri == null || localName == null) {
        return false;
    }
    return uri.equals(WSDL_NS) && localName.equals(WSDL_ROOT_ELEMENT);
}

From source file:org.apache.ode.utils.DOMUtils.java

/**
 * Perform a naive check to see if a document is an XML schema document
 * based on the root element name and namespace URI.
 * @param d the {@link Document} to check
 * @return <code>true</code> if the root element appears correct
 *//*ww  w.jav a 2  s . co  m*/
public static boolean isXmlSchemaDocument(Document d) {
    Element e = d.getDocumentElement();
    String uri = e.getNamespaceURI();
    String localName = e.getLocalName();
    if (uri == null || localName == null) {
        return false;
    }
    return uri.equals(XSD_NS) && localName.equals(XSD_ROOT_ELEMENT);
}

From source file:org.apache.ode.utils.wsdl.WsdlUtils.java

/**
 * ODE extends the wsdl spec by allowing definition of the HTTP verb at the operation level.
 * <br/> If you do so, an {@link UnknownExtensibilityElement} will be added to the list of extensibility elements of the {@link javax.wsdl.BindingOperation}.
 * <br/> This method looks up for such an element and return the value of the verb attribute if the underlying {@link org.w3c.dom.Element} is {@literal <binding xmlns="http://schemas.xmlsoap.org/wsdl/http/"/>}
 * or null./*from w ww .j  av a 2  s.  c o m*/
 *
 * @param bindingOperation
 */
public static String getOperationVerb(BindingOperation bindingOperation) {
    final Collection<UnknownExtensibilityElement> unknownExtElements = CollectionsX
            .filter(bindingOperation.getExtensibilityElements(), UnknownExtensibilityElement.class);
    for (UnknownExtensibilityElement extensibilityElement : unknownExtElements) {
        final Element e = extensibilityElement.getElement();
        if (Namespaces.ODE_HTTP_EXTENSION_NS.equalsIgnoreCase(e.getNamespaceURI())
                && "binding".equals(extensibilityElement.getElement().getLocalName())
                && e.hasAttribute("verb")) {
            return e.getAttribute("verb");
        }
    }
    return null;
}

From source file:org.apache.ode.utils.wsdl.WsdlUtils.java

/**
 * @param fault//from  w w  w  . ja v a  2  s.  c  om
 * @return true if the given fault is bound with the {@link org.apache.ode.utils.Namespaces.ODE_HTTP_EXTENSION_NS}:fault element.
 */
public static boolean isOdeFault(BindingFault fault) {
    final Collection<UnknownExtensibilityElement> unknownExtElements = CollectionsX
            .filter(fault.getExtensibilityElements(), UnknownExtensibilityElement.class);
    for (UnknownExtensibilityElement extensibilityElement : unknownExtElements) {
        final Element e = extensibilityElement.getElement();
        if (Namespaces.ODE_HTTP_EXTENSION_NS.equalsIgnoreCase(e.getNamespaceURI())
                && "fault".equals(extensibilityElement.getElement().getLocalName())) {
            // name attribute is optional, but if any it must match the fault name
            if (e.hasAttribute("name")) {
                return fault.getName().equals(e.getAttribute("name"));
            } else {
                return true;
            }
        }
    }
    return false;
}

From source file:org.apache.ode.utils.wsdl.WsdlUtils.java

@SuppressWarnings("unchecked")
public static Collection<UnknownExtensibilityElement> getHttpHeaders(List extensibilityElements) {
    final Collection<UnknownExtensibilityElement> unknownExtElements = CollectionsX
            .filter(extensibilityElements, UnknownExtensibilityElement.class);
    for (UnknownExtensibilityElement extensibilityElement : unknownExtElements) {
        final Element e = extensibilityElement.getElement();
        // keep only the header elements
        if (!Namespaces.ODE_HTTP_EXTENSION_NS.equalsIgnoreCase(e.getNamespaceURI())
                || !"header".equals(extensibilityElement.getElement().getLocalName())) {
            unknownExtElements.remove(extensibilityElement);
        }//  w w  w . ja  va2  s.  c o  m
    }
    return unknownExtElements;
}

From source file:org.apache.openaz.xacml.util.XACMLPolicyScanner.java

/**
 * readPolicy - does the work to read in policy data from a file.
 *
 * @param policy - The path to the policy file.
 * @return - The policy data object. This *should* be either a PolicySet or a Policy.
 *//* w ww .ja  va  2 s  .co m*/
public static Object readPolicy(InputStream is) {
    try {
        //
        // Parse the policy file
        //
        DocumentBuilder db = DOMUtil.getDocumentBuilder();
        Document doc = db.parse(is);
        //
        // Because there is no root defined in xacml,
        // find the first element
        //
        NodeList nodes = doc.getChildNodes();
        Node node = nodes.item(0);
        Element e = null;
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            e = (Element) node;
            //
            // Is it a 3.0 policy?
            //
            if (e.getNamespaceURI().equals("urn:oasis:names:tc:xacml:3.0:core:schema:wd-17")) {
                //
                // A policyset or policy could be the root
                //
                if (e.getNodeName().endsWith("Policy")) {
                    //
                    // Now we can create the context for the policy set
                    // and unmarshall the policy into a class.
                    //
                    JAXBContext context = JAXBContext.newInstance(PolicyType.class);
                    Unmarshaller um = context.createUnmarshaller();
                    JAXBElement<PolicyType> root = um.unmarshal(e, PolicyType.class);
                    //
                    // Here is our policy set class
                    //
                    return root.getValue();
                } else if (e.getNodeName().endsWith("PolicySet")) {
                    //
                    // Now we can create the context for the policy set
                    // and unmarshall the policy into a class.
                    //
                    JAXBContext context = JAXBContext.newInstance(PolicySetType.class);
                    Unmarshaller um = context.createUnmarshaller();
                    JAXBElement<PolicySetType> root = um.unmarshal(e, PolicySetType.class);
                    //
                    // Here is our policy set class
                    //
                    return root.getValue();
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Not supported yet: " + e.getNodeName());
                    }
                }
            } else {
                logger.warn("unsupported namespace: " + e.getNamespaceURI());
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("No root element contained in policy " + " Name: " + node.getNodeName() + " type: "
                        + node.getNodeType() + " Value: " + node.getNodeValue());
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    return null;
}