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;
}
Aggregations