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.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReader.java

private QName extractQName(Node node) {
    QName qname;//from w  w  w . j  a  v  a2  s  .c  o  m
    String localName = node.getLocalName();
    if (localName == null) {
        qname = new QName(node.getNodeName());
    } else {
        if (node.getPrefix() == null) {
            qname = new QName(node.getNamespaceURI(), localName);
        } else {
            qname = new QName(node.getNamespaceURI(), localName, node.getPrefix());
        }

    }
    return qname;
}

From source file:org.apache.ode.axis2.soapbinding.SoapMessageConverter.java

public void createSoapHeaders(SOAPEnvelope soapEnv, List<SOAPHeader> headerDefs, Message msgdef,
        org.apache.ode.bpel.iapi.Message message) throws AxisFault {
    for (SOAPHeader sh : headerDefs)
        handleSoapHeaderDef(soapEnv, sh, msgdef, message);

    org.apache.axiom.soap.SOAPHeader soaphdr = soapEnv.getHeader();
    if (soaphdr == null)
        soaphdr = _soapFactory.createSOAPHeader(soapEnv);

    for (Node headerNode : message.getHeaderParts().values())
        if (headerNode.getNodeType() == Node.ELEMENT_NODE) {
            if (soaphdr.getFirstChildWithName(
                    new QName(headerNode.getNamespaceURI(), headerNode.getLocalName())) == null) {
                OMElement omHeaderNode = OMUtils.toOM((Element) headerNode, _soapFactory);
                SOAPHeaderBlock hb = soaphdr.addHeaderBlock(omHeaderNode.getLocalName(),
                        omHeaderNode.getNamespace());

                // add child elements
                OMNode omNode = null;/*from  w ww  .  j  a  v  a2  s. c  o  m*/
                for (Iterator iter = omHeaderNode.getChildren(); iter.hasNext();) {
                    omNode = (OMNode) iter.next();
                    hb.addChild(omNode);
                }

                OMAttribute omatribute = null;
                // add attributes
                for (Iterator iter = omHeaderNode.getAllAttributes(); iter.hasNext();) {
                    omatribute = (OMAttribute) iter.next();
                    hb.addAttribute(omatribute);
                }
            }
        } else {
            throw new OdeFault(__msgs.msgSoapHeaderMustBeAnElement(headerNode));
        }
}

From source file:org.apache.ode.axis2.util.SoapMessageConverter.java

public void createSoapHeaders(SOAPEnvelope soapEnv, List<SOAPHeader> headerDefs, Message msgdef,
        Map<String, Node> headers) throws AxisFault {
    if (msgdef == null)
        return;/*from  ww  w .j  a va  2 s.c o  m*/

    for (SOAPHeader sh : headerDefs)
        handleSoapHeaderDef(soapEnv, sh, msgdef, headers);

    org.apache.axiom.soap.SOAPHeader soaphdr = soapEnv.getHeader();
    if (soaphdr == null)
        soaphdr = _soapFactory.createSOAPHeader(soapEnv);

    for (Node headerNode : headers.values())
        if (headerNode.getNodeType() == Node.ELEMENT_NODE) {
            if (soaphdr.getFirstChildWithName(
                    new QName(headerNode.getNamespaceURI(), headerNode.getLocalName())) == null)
                soaphdr.addChild(OMUtils.toOM((Element) headerNode, _soapFactory));
        } else {
            throw new OdeFault(__msgs.msgSoapHeaderMustBeAnElement(headerNode));
        }
}

From source file:org.apache.ode.bpel.elang.xpath20.runtime.XPath20ExpressionRuntime.java

private Object evaluate(OExpression cexp, EvaluationContext ctx, QName type)
        throws FaultException, EvaluationException {
    try {//  www  .  j  a va 2s.  c  o  m
        OXPath20ExpressionBPEL20 oxpath20 = ((OXPath20ExpressionBPEL20) cexp);

        JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(ctx, oxpath20);
        JaxpVariableResolver varResolver = new JaxpVariableResolver(ctx, oxpath20,
                ((XPathFactoryImpl) _xpf).getConfiguration());
        XPath xpe = _xpf.newXPath();
        xpe.setXPathFunctionResolver(funcResolver);
        xpe.setXPathVariableResolver(varResolver);
        xpe.setNamespaceContext(oxpath20.namespaceCtx);
        String xpath = ((OXPath10Expression) cexp).xpath;
        XPathExpression expr = xpe.compile(xpath);
        Node contextNode = ctx.getRootNode();
        if (contextNode == null) {
            contextNode = DOMUtils.newDocument();
        }
        // Create step nodes in XPath in case it is incompletely instantiated
        if (oxpath20.insertMissingData) {
            XPath20ExpressionModifier modifier = new XPath20ExpressionModifier(oxpath20.namespaceCtx,
                    ((XPathFactoryImpl) _xpf).getConfiguration().getNamePool());

            Node temp = ctx.getRootNode();
            if (temp.getLocalName().equals("message") && temp.getNamespaceURI() == null) {
                int startind = xpath.indexOf('.');
                int endind = xpath.indexOf('/');
                if (startind != -1) {
                    String part = null;
                    if (endind != -1) {
                        part = xpath.substring(startind + 1, endind);
                    } else {
                        part = xpath.substring(startind + 1);
                    }
                    Element partElem = DOMUtils.findChildByName((Element) temp, new QName(null, part));

                    if (partElem != null && partElem.getFirstChild() != null) {
                        temp = partElem.getFirstChild();
                    }
                }
            }

            modifier.insertMissingData(expr, temp);
        }
        Object evalResult = expr.evaluate(contextNode, type);
        if (evalResult != null && __log.isDebugEnabled()) {
            __log.debug("Expression " + cexp.toString() + " generated result " + evalResult + " - type="
                    + evalResult.getClass().getName());
            if (ctx.getRootNode() != null)
                __log.debug("Was using context node " + DOMUtils.domToString(ctx.getRootNode()));
        }
        return evalResult;
    } catch (XPathExpressionException e) {
        // Extracting the real cause from all this wrapping isn't a simple task
        Throwable cause = e.getCause() != null ? e.getCause() : e;
        if (cause instanceof XPathException) {
            Throwable th = ((XPathException) cause).getException();
            if (th != null) {
                cause = th;
                if (cause.getCause() != null)
                    cause = cause.getCause();
            }
        }
        throw new EvaluationException("Error while executing an XPath expression: " + cause.toString(), cause);
    } catch (WrappedResolverException wre) {
        __log.debug("Could not evaluate expression because of ", wre);
        throw (FaultException) wre.getCause();
    } catch (Throwable t) {
        __log.debug("Could not evaluate expression because of ", t);
        throw new EvaluationException("Error while executing an XPath expression: ", t);
    }
}

From source file:org.apache.ode.bpel.engine.BpelRuntimeContextImpl.java

public Node convertEndpointReference(Element sourceNode, Node targetNode) {
    QName nodeQName;/*from  ww w.  j  av  a2s . com*/
    if (targetNode.getNodeType() == Node.TEXT_NODE) {
        nodeQName = new QName(Namespaces.XML_SCHEMA, "string");
    } else {
        // We have an element
        nodeQName = new QName(targetNode.getNamespaceURI(), targetNode.getLocalName());
    }
    return _bpelProcess._engine._contexts.eprContext.convertEndpoint(nodeQName, sourceNode).toXML();
}

From source file:org.apache.ode.bpel.epr.WSAEndpoint.java

public void set(Node node) {
    if (node.getNamespaceURI().equals(SERVICE_REF_QNAME.getNamespaceURI()))
        _eprElmt = DOMUtils.getFirstChildElement((Element) node);
    else//from  w  w  w . j  av  a2s  . co  m
        _eprElmt = (Element) node;
    if (__log.isDebugEnabled())
        __log.debug("Setting a WSAEndpoint value: " + DOMUtils.domToString(_eprElmt));
}

From source file:org.apache.ode.bpel.rtrep.v2.xpath20.XPath20ExpressionRuntime.java

private Object evaluate(OExpression cexp, EvaluationContext ctx, QName type) throws FaultException {
    try {//  w w w .  j  a va2s .  c  o  m
        OXPath20ExpressionBPEL20 oxpath20 = ((OXPath20ExpressionBPEL20) cexp);
        System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_SAXON,
                "net.sf.saxon.xpath.XPathFactoryImpl");
        // JAXP based XPath 1.0 runtime does not work anymore after a XPath 2.0 has been evaluated if this is set.
        // System.setProperty("javax.xml.xpath.XPathFactory:"+XPathConstants.DOM_OBJECT_MODEL,
        //        "net.sf.saxon.xpath.XPathFactoryImpl");
        System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_JDOM,
                "net.sf.saxon.xpath.XPathFactoryImpl");
        System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_XOM,
                "net.sf.saxon.xpath.XPathFactoryImpl");
        System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_DOM4J,
                "net.sf.saxon.xpath.XPathFactoryImpl");

        XPathFactory xpf = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
        JaxpFunctionResolver funcResolver = new JaxpFunctionResolver(ctx, oxpath20);
        JaxpVariableResolver varResolver = new JaxpVariableResolver(ctx, oxpath20,
                ((XPathFactoryImpl) xpf).getConfiguration());
        xpf.setXPathFunctionResolver(funcResolver);
        xpf.setXPathVariableResolver(varResolver);
        XPath xpe = xpf.newXPath();
        xpe.setNamespaceContext(oxpath20.namespaceCtx);
        XPathExpression expr = xpe.compile(((OXPath10Expression) cexp).xpath);
        Node contextNode = ctx.getRootNode() == null ? DOMUtils.newDocument() : ctx.getRootNode();
        // Create step nodes in XPath in case it is incompletely instantiated 
        if (oxpath20.insertMissingData) {
            XPath20ExpressionModifier modifier = new XPath20ExpressionModifier(oxpath20.namespaceCtx,
                    ((XPathFactoryImpl) xpf).getConfiguration().getNamePool());
            Node temp = ctx.getRootNode();
            if (temp.getLocalName().equals("message") && temp.getNamespaceURI() == null
                    && temp.getFirstChild() != null && temp.getFirstChild().getFirstChild() != null) {
                modifier.insertMissingData(expr, temp.getFirstChild().getFirstChild());
            } else {
                modifier.insertMissingData(expr, temp);
            }
        }

        Object evalResult = expr.evaluate(contextNode, type);
        if (evalResult != null && __log.isDebugEnabled()) {
            __log.debug("Expression " + cexp.toString() + " generated result " + evalResult + " - type="
                    + evalResult.getClass().getName());
            if (ctx.getRootNode() != null)
                __log.debug("Was using context node " + DOMUtils.domToString(ctx.getRootNode()));
        }
        return evalResult;
    } catch (XPathExpressionException e) {
        // Extracting the real cause from all this wrapping isn't a simple task
        Throwable cause = e.getCause() != null ? e.getCause() : e;
        if (cause instanceof DynamicError) {
            Throwable th = ((DynamicError) cause).getException();
            if (th != null) {
                cause = th;
                if (cause.getCause() != null)
                    cause = cause.getCause();
            }
        }
        throw new FaultException(cexp.getOwner().constants.qnSubLanguageExecutionFault, cause.getMessage(),
                cause);
    } catch (WrappedFaultException wre) {
        __log.debug("Could not evaluate expression because of ", wre);
        throw (FaultException) wre.getCause();
    } catch (Throwable t) {
        __log.debug("Could not evaluate expression because of ", t);
        throw new FaultException(cexp.getOwner().constants.qnSubLanguageExecutionFault, t.getMessage(), t);
    }

}

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

public static QName getNodeQName(Node el) {
    String localName = el.getLocalName();
    String namespaceUri = el.getNamespaceURI();
    if (localName == null) {
        String nodeName = el.getNodeName();
        int colonIndex = nodeName.indexOf(":");
        if (colonIndex > 0) {
            localName = nodeName.substring(0, colonIndex);
            namespaceUri = nodeName.substring(colonIndex + 1);
        } else {//from   w w w .  ja v  a2s .c o  m
            localName = nodeName;
            namespaceUri = null;
        }
    }
    return new QName(namespaceUri, localName);
}

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

public static Element findChildByName(Element parent, QName name, boolean recurse) {
    if (parent == null)
        throw new IllegalArgumentException("null parent");
    if (name == null)
        throw new IllegalArgumentException("null name");

    NodeList nl = parent.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i) {
        Node c = nl.item(i);
        if (c.getNodeType() != Node.ELEMENT_NODE)
            continue;
        // For a reason that I can't fathom, when using in-mem DAO we actually get elements with
        // no localname.
        String nodeName = c.getLocalName() != null ? c.getLocalName() : c.getNodeName();
        if (new QName(c.getNamespaceURI(), nodeName).equals(name))
            return (Element) c;
    }//from  w w w  .ja v  a  2 s .  com

    if (recurse) {
        NodeList cnl = parent.getChildNodes();
        for (int i = 0; i < cnl.getLength(); ++i) {
            Node c = cnl.item(i);
            if (c.getNodeType() != Node.ELEMENT_NODE)
                continue;
            Element result = findChildByName((Element) c, name, recurse);
            if (result != null)
                return result;
        }
    }
    return null;
}

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

public static List<Element> findChildrenByName(Element parent, QName name) {
    if (parent == null)
        throw new IllegalArgumentException("null parent");
    if (name == null)
        throw new IllegalArgumentException("null name");

    LinkedList<Element> ret = new LinkedList<Element>();
    NodeList nl = parent.getChildNodes();
    for (int i = 0; i < nl.getLength(); ++i) {
        Node c = nl.item(i);
        if (c.getNodeType() != Node.ELEMENT_NODE)
            continue;
        // For a reason that I can't fathom, when using in-mem DAO we actually get elements with
        // no localname.
        String nodeName = c.getLocalName() != null ? c.getLocalName() : c.getNodeName();
        if (new QName(c.getNamespaceURI(), nodeName).equals(name))
            ret.add((Element) c);
    }/*from   w w w .j a  v a  2s  . c  o  m*/

    return ret;
}