Search in sources :

Example 1 with JAXPExtensionsProvider

use of org.apache.xpath.jaxp.JAXPExtensionsProvider in project nokogiri by sparklemotion.

the class XmlXpathContext method getXPathContext.

private XPathContext getXPathContext(final NokogiriXPathFunctionResolver fnResolver) {
    Node doc = context.getNode().getOwnerDocument();
    if (doc == null)
        doc = context.getNode();
    XPathContext xpathContext = (XPathContext) doc.getUserData(XPATH_CONTEXT);
    if (xpathContext == null) {
        xpathContext = newXPathContext(fnResolver);
        if (variableResolver == null) {
            // NOTE: only caching without variables - could be improved by more sophisticated caching
            doc.setUserData(XPATH_CONTEXT, xpathContext, null);
        }
    } else {
        Object owner = xpathContext.getOwnerObject();
        if ((owner == null && fnResolver == null) || (owner instanceof JAXPExtensionsProvider && ((JAXPExtensionsProvider) owner).hasSameResolver(fnResolver))) {
            // can be re-used assuming it has the same variable-stack (for now only cached if no variables)
            if (variableResolver == null)
                return xpathContext;
        }
        // otherwise we can not use the cached xpath-context
        xpathContext = newXPathContext(fnResolver);
    }
    if (variableResolver != null) {
        xpathContext.setVarStack(new JAXPVariableStack(variableResolver));
    }
    return xpathContext;
}
Also used : JAXPVariableStack(org.apache.xpath.jaxp.JAXPVariableStack) Node(org.w3c.dom.Node) JAXPExtensionsProvider(org.apache.xpath.jaxp.JAXPExtensionsProvider) XPathContext(org.apache.xpath.XPathContext) RubyObject(org.jruby.RubyObject) IRubyObject(org.jruby.runtime.builtin.IRubyObject) XObject(org.apache.xpath.objects.XObject)

Aggregations

XPathContext (org.apache.xpath.XPathContext)1 JAXPExtensionsProvider (org.apache.xpath.jaxp.JAXPExtensionsProvider)1 JAXPVariableStack (org.apache.xpath.jaxp.JAXPVariableStack)1 XObject (org.apache.xpath.objects.XObject)1 RubyObject (org.jruby.RubyObject)1 IRubyObject (org.jruby.runtime.builtin.IRubyObject)1 Node (org.w3c.dom.Node)1