use of javax.xml.xpath.XPathFunctionResolver in project camel by apache.
the class XPathTest method testUsingJavaExtensions.
public void testUsingJavaExtensions() throws Exception {
Object instance = null;
// we may not have Xalan on the classpath
try {
instance = Class.forName("org.apache.xalan.extensions.XPathFunctionResolverImpl").newInstance();
} catch (Throwable e) {
log.debug("Could not find Xalan on the classpath so ignoring this test case: " + e);
}
if (instance instanceof XPathFunctionResolver) {
XPathFunctionResolver functionResolver = (XPathFunctionResolver) instance;
XPathBuilder builder = xpath("java:" + getClass().getName() + ".func(string(/header/value))").namespace("java", "http://xml.apache.org/xalan/java").functionResolver(functionResolver).stringResult();
String xml = "<header><value>12</value></header>";
// it can throw the exception if we put the xalan into the test class path
assertExpression(builder, xml, "modified12");
}
}
use of javax.xml.xpath.XPathFunctionResolver in project camel by apache.
the class XPathBuilder method createXPathExpression.
/**
* Creates a new xpath expression as there we no available in the pool.
* <p/>
* This implementation must be synchronized to ensure thread safety, as this XPathBuilder instance may not have been
* started prior to being used.
*/
protected synchronized XPathExpression createXPathExpression() throws XPathExpressionException, XPathFactoryConfigurationException {
// ensure we are started
try {
start();
} catch (Exception e) {
throw new RuntimeExpressionException("Error starting XPathBuilder", e);
}
// XPathFactory is not thread safe
XPath xPath = getXPathFactory().newXPath();
if (!logNamespaces && LOG.isTraceEnabled()) {
LOG.trace("Creating new XPath expression in pool. Namespaces on XPath expression: {}", getNamespaceContext().toString());
} else if (logNamespaces && LOG.isInfoEnabled()) {
LOG.info("Creating new XPath expression in pool. Namespaces on XPath expression: {}", getNamespaceContext().toString());
}
xPath.setNamespaceContext(getNamespaceContext());
xPath.setXPathVariableResolver(getVariableResolver());
XPathFunctionResolver parentResolver = getFunctionResolver();
if (parentResolver == null) {
parentResolver = xPath.getXPathFunctionResolver();
}
xPath.setXPathFunctionResolver(createDefaultFunctionResolver(parentResolver));
return xPath.compile(text);
}
Aggregations