Search in sources :

Example 1 with PrefixResolverDefault

use of org.apache.xml.utils.PrefixResolverDefault in project OpenAM by OpenRock.

the class Utils method convertStringToQName.

/**
     * Converts a string value to a QName. The prefix of the string value
     * is resolved to a namespace relative to the element.
     *
     * @param str the String to be converted.
     * @param element the Element object.
     * @return the QName Object.
     * @supported.api
     */
public static QName convertStringToQName(String str, Element element) {
    if (str == null) {
        return null;
    }
    String prefix = "";
    String localPart;
    int index = str.indexOf(":");
    if (index == -1) {
        localPart = str;
    } else {
        prefix = str.substring(0, index);
        localPart = str.substring(index + 1);
    }
    PrefixResolverDefault prd = new PrefixResolverDefault(element.getOwnerDocument());
    String ns = prd.getNamespaceForPrefix(prefix, element);
    return new QName(ns, localPart);
}
Also used : QName(javax.xml.namespace.QName) PrefixResolverDefault(org.apache.xml.utils.PrefixResolverDefault)

Example 2 with PrefixResolverDefault

use of org.apache.xml.utils.PrefixResolverDefault in project robovm by robovm.

the class XPathAPI method eval.

/**
   *  Evaluate XPath string to an XObject.
   *  XPath namespace prefixes are resolved from the namespaceNode.
   *  The implementation of this is a little slow, since it creates
   *  a number of objects each time it is called.  This could be optimized
   *  to keep the same objects around, but then thread-safety issues would arise.
   *
   *  @param contextNode The node to start searching from.
   *  @param str A valid XPath string.
   *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
   *  @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
   *  @see org.apache.xpath.objects.XObject
   *  @see org.apache.xpath.objects.XNull
   *  @see org.apache.xpath.objects.XBoolean
   *  @see org.apache.xpath.objects.XNumber
   *  @see org.apache.xpath.objects.XString
   *  @see org.apache.xpath.objects.XRTreeFrag
   *
   * @throws TransformerException
   */
public static XObject eval(Node contextNode, String str, Node namespaceNode) throws TransformerException {
    // Since we don't have a XML Parser involved here, install some default support
    // for things like namespaces, etc.
    // (Changed from: XPathContext xpathSupport = new XPathContext();
    //    because XPathContext is weak in a number of areas... perhaps
    //    XPathContext should be done away with.)
    // Create an XPathContext that doesn't support pushing and popping of
    // variable resolution scopes.  Sufficient for simple XPath 1.0 expressions.
    XPathContext xpathSupport = new XPathContext(false);
    // Create an object to resolve namespace prefixes.
    // XPath namespaces are resolved from the input context node's document element
    // if it is a root node, or else the current context node (for lack of a better
    // resolution space, given the simplicity of this sample code).
    PrefixResolverDefault prefixResolver = new PrefixResolverDefault((namespaceNode.getNodeType() == Node.DOCUMENT_NODE) ? ((Document) namespaceNode).getDocumentElement() : namespaceNode);
    // Create the XPath object.
    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
    // Execute the XPath, and have it return the result
    // return xpath.execute(xpathSupport, contextNode, prefixResolver);
    int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
    return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
Also used : PrefixResolverDefault(org.apache.xml.utils.PrefixResolverDefault) Document(org.w3c.dom.Document)

Example 3 with PrefixResolverDefault

use of org.apache.xml.utils.PrefixResolverDefault in project santuario-java by apache.

the class XalanXPathAPI method eval.

private XObject eval(Node contextNode, Node xpathnode, String str, Node namespaceNode) throws TransformerException {
    if (context == null) {
        context = new XPathContext(xpathnode);
        context.setSecureProcessing(true);
    }
    // Create an object to resolve namespace prefixes.
    // XPath namespaces are resolved from the input context node's document element
    // if it is a root node, or else the current context node (for lack of a better
    // resolution space, given the simplicity of this sample code).
    Node resolverNode = (namespaceNode.getNodeType() == Node.DOCUMENT_NODE) ? ((Document) namespaceNode).getDocumentElement() : namespaceNode;
    PrefixResolverDefault prefixResolver = new PrefixResolverDefault(resolverNode);
    if (!str.equals(xpathStr)) {
        if (str.indexOf("here()") > 0) {
            context.reset();
        }
        xpath = createXPath(str, prefixResolver);
        xpathStr = str;
    }
    // Execute the XPath, and have it return the result
    int ctxtNode = context.getDTMHandleFromNode(contextNode);
    return xpath.execute(context, ctxtNode, prefixResolver);
}
Also used : Node(org.w3c.dom.Node) XPathContext(org.apache.xpath.XPathContext) PrefixResolverDefault(org.apache.xml.utils.PrefixResolverDefault)

Example 4 with PrefixResolverDefault

use of org.apache.xml.utils.PrefixResolverDefault in project webtools.sourceediting by eclipse.

the class XSLTXPathHelper method eval.

/**
 * Evaluate XPath string to an XObject. XPath namespace prefixes are
 * resolved from the namespaceNode. The implementation of this is a little
 * slow, since it creates a number of objects each time it is called. This
 * could be optimized to keep the same objects around, but then
 * thread-safety issues would arise.
 *
 * @param contextNode
 *            The node to start searching from.
 * @param str
 *            A valid XPath string.
 * @param namespaceNode
 *            The node from which prefixes in the XPath will be resolved to
 *            namespaces.
 * @return An XObject, which can be used to obtain a string, number,
 *         nodelist, etc, should never be null.
 * @see org.apache.xpath.objects.XObject
 * @see org.apache.xpath.objects.XNull
 * @see org.apache.xpath.objects.XBoolean
 * @see org.apache.xpath.objects.XNumber
 * @see org.apache.xpath.objects.XString
 * @see org.apache.xpath.objects.XRTreeFrag
 *
 * @throws TransformerException
 */
public static XObject eval(Node contextNode, String str, Node namespaceNode) throws TransformerException {
    // Since we don't have a XML Parser involved here, install some default
    // support
    // for things like namespaces, etc.
    // (Changed from: XPathContext xpathSupport = new XPathContext();
    // because XPathContext is weak in a number of areas... perhaps
    // XPathContext should be done away with.)
    XPathContext xpathSupport = new XPathContext();
    // Create an object to resolve namespace prefixes.
    // XPath namespaces are resolved from the input context node's document
    // element
    // if it is a root node, or else the current context node (for lack of a
    // better
    // resolution space, given the simplicity of this sample code).
    PrefixResolverDefault prefixResolver = new PrefixResolverDefault((namespaceNode.getNodeType() == Node.DOCUMENT_NODE) ? ((Document) namespaceNode).getDocumentElement() : namespaceNode);
    // Create the XPath object.
    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null, getFunctionTable());
    // Execute the XPath, and have it return the result
    // return xpath.execute(xpathSupport, contextNode, prefixResolver);
    int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
    return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
Also used : XPath(org.apache.xpath.XPath) XPathContext(org.apache.xpath.XPathContext) PrefixResolverDefault(org.apache.xml.utils.PrefixResolverDefault) Document(org.w3c.dom.Document)

Example 5 with PrefixResolverDefault

use of org.apache.xml.utils.PrefixResolverDefault in project j2objc by google.

the class XPathAPI method eval.

/**
 *  Evaluate XPath string to an XObject.
 *  XPath namespace prefixes are resolved from the namespaceNode.
 *  The implementation of this is a little slow, since it creates
 *  a number of objects each time it is called.  This could be optimized
 *  to keep the same objects around, but then thread-safety issues would arise.
 *
 *  @param contextNode The node to start searching from.
 *  @param str A valid XPath string.
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 *  @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
 *  @see org.apache.xpath.objects.XObject
 *  @see org.apache.xpath.objects.XNull
 *  @see org.apache.xpath.objects.XBoolean
 *  @see org.apache.xpath.objects.XNumber
 *  @see org.apache.xpath.objects.XString
 *  @see org.apache.xpath.objects.XRTreeFrag
 *
 * @throws TransformerException
 */
public static XObject eval(Node contextNode, String str, Node namespaceNode) throws TransformerException {
    // Since we don't have a XML Parser involved here, install some default support
    // for things like namespaces, etc.
    // (Changed from: XPathContext xpathSupport = new XPathContext();
    // because XPathContext is weak in a number of areas... perhaps
    // XPathContext should be done away with.)
    // Create an XPathContext that doesn't support pushing and popping of
    // variable resolution scopes.  Sufficient for simple XPath 1.0 expressions.
    XPathContext xpathSupport = new XPathContext(false);
    // Create an object to resolve namespace prefixes.
    // XPath namespaces are resolved from the input context node's document element
    // if it is a root node, or else the current context node (for lack of a better
    // resolution space, given the simplicity of this sample code).
    PrefixResolverDefault prefixResolver = new PrefixResolverDefault((namespaceNode.getNodeType() == Node.DOCUMENT_NODE) ? ((Document) namespaceNode).getDocumentElement() : namespaceNode);
    // Create the XPath object.
    XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
    // Execute the XPath, and have it return the result
    // return xpath.execute(xpathSupport, contextNode, prefixResolver);
    int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
    return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
Also used : PrefixResolverDefault(org.apache.xml.utils.PrefixResolverDefault) Document(org.w3c.dom.Document)

Aggregations

PrefixResolverDefault (org.apache.xml.utils.PrefixResolverDefault)8 Document (org.w3c.dom.Document)5 XPath (org.apache.xpath.XPath)2 XPathContext (org.apache.xpath.XPathContext)2 Node (org.w3c.dom.Node)2 QName (javax.xml.namespace.QName)1 TransformerException (javax.xml.transform.TransformerException)1 DTM (org.apache.xml.dtm.DTM)1 DTMIterator (org.apache.xml.dtm.DTMIterator)1 DTMNodeProxy (org.apache.xml.dtm.ref.DTMNodeProxy)1 PrefixResolver (org.apache.xml.utils.PrefixResolver)1 Debugger (org.intellij.plugins.xsltDebugger.rt.engine.Debugger)1