List of usage examples for javax.xml.xpath XPathFactory setXPathFunctionResolver
public abstract void setXPathFunctionResolver(XPathFunctionResolver resolver);
Establish a default function resolver.
Any XPath
objects constructed from this factory will use the specified resolver by default.
A NullPointerException
is thrown if resolver
is null
.
From source file:org.apache.ode.bpel.rtrep.v1.xpath20.XPath20ExpressionRuntime.java
private Object evaluate(OExpression cexp, EvaluationContext ctx, QName type) throws FaultException { try {/*ww w .ja v a2 s . com*/ 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(); 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.bpel.rtrep.v2.xpath20.XPath20ExpressionRuntime.java
private Object evaluate(OExpression cexp, EvaluationContext ctx, QName type) throws FaultException { try {/*from w ww .j av a2 s. c om*/ 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.wso2.carbon.humantask.core.engine.runtime.xpath.XPathExpressionRuntime.java
private Object evaluate(String exp, EvaluationContext evalCtx, QName type) { try {//from w w w. j a v a2 s . com XPathFactory xpf = new XPathFactoryImpl(); JaxpFunctionResolver funcResolve = new JaxpFunctionResolver(evalCtx); xpf.setXPathFunctionResolver(funcResolve); XPathEvaluator xpe = (XPathEvaluator) xpf.newXPath(); xpe.setXPathFunctionResolver(funcResolve); xpe.setBackwardsCompatible(true); xpe.setNamespaceContext(evalCtx.getNameSpaceContextOfTask()); XPathExpression xpathExpression = xpe.compile(exp); Node contextNode = evalCtx.getRootNode() == null ? DOMUtils.newDocument() : evalCtx.getRootNode(); Object evalResult = xpathExpression.evaluate(contextNode, type); if (evalResult != null && log.isDebugEnabled()) { log.debug("Expression " + exp + " generate result " + evalResult + " - type=" + evalResult.getClass().getName()); if (evalCtx.getRootNode() != null) { log.debug("Was using context node " + DOMUtils.domToString(evalCtx.getRootNode())); } } return evalResult; } catch (XPathFactoryConfigurationException e) { log.error("Exception occurred while creating XPathFactory.", e); throw new XPathProcessingException("Exception occurred while creating XPathFactory.", e); } catch (XPathExpressionException e) { String msg = "Error evaluating XPath expression: " + exp; log.error(msg, e); throw new XPathProcessingException(msg, e); } catch (ParserConfigurationException e) { String msg = "XML Parsing error."; log.error(msg, e); throw new XPathProcessingException(msg, e); } catch (Exception e) { log.error(e.getMessage(), e); throw new XPathProcessingException(e.getMessage(), e); } }