public Object evaluate(final ProcessContext context) throws Exception { XPathFactory factory = XPathFactory.newInstance(); XPath xpathEvaluator = factory.newXPath(); xpathEvaluator.setXPathFunctionResolver( new XPathFunctionResolver() { public XPathFunction resolveFunction(QName functionName, int arity)
private static XPath internalXpath() { XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setXPathFunctionResolver(resolver); return xPath; }
public void setXPathFunctionResolver(XPathFunctionResolver resolver) { getXPath().setXPathFunctionResolver(resolver); }
/** * Make a given {@link XPath} object "xalan-extension aware", if Xalan is on * the classpath. */ static final void xalanExtensionAware(XPath xpath) { // Load xalan extensions thread-safely for all of jOOX if (!xalanExtensionLoaded) { synchronized (Util.class) { if (!xalanExtensionLoaded) { xalanExtensionLoaded = true; try { xalanNamespaceContext = (NamespaceContext) Class.forName("org.apache.xalan.extensions.ExtensionNamespaceContext").newInstance(); xalanFunctionResolver = (XPathFunctionResolver) Class.forName("org.apache.xalan.extensions.XPathFunctionResolverImpl").newInstance(); } catch (Exception ignore) { } } } } if (xalanNamespaceContext != null && xalanFunctionResolver != null) { xpath.setNamespaceContext(xalanNamespaceContext); xpath.setXPathFunctionResolver(xalanFunctionResolver); } }
XmlFile() { this.namespaces.put(WINDUP_NS_PREFIX, WINDUP_NS_URI); this.xpathEngine = factory.newXPath(); final XPathFunctionResolver originalResolver = this.xpathEngine.getXPathFunctionResolver(); xmlFileFunctionResolver = new XmlFileFunctionResolver(originalResolver); this.xpathEngine.setXPathFunctionResolver(xmlFileFunctionResolver); }
public XmlFileXpathValidator() { this.namespaces.put(WINDUP_NS_PREFIX, WINDUP_NS_URI); this.xpathEngine = factory.newXPath(); final XPathFunctionResolver originalResolver = this.xpathEngine.getXPathFunctionResolver(); xmlFileFunctionResolver = new XmlFileFunctionResolver(originalResolver); this.xpathEngine.setXPathFunctionResolver(xmlFileFunctionResolver); }
/** * Create a new {@link XPath} with the passed variable resolver, function * resolver and namespace context. * * @param aXPathFactory * The XPath factory object to use. May not be <code>null</code>. * @param aVariableResolver * Variable resolver to be used. May be <code>null</code>. * @param aFunctionResolver * Function resolver to be used. May be <code>null</code>. * @param aNamespaceContext * Namespace context to be used. May be <code>null</code>. * @return The created non-<code>null</code> {@link XPath} object */ @Nonnull public static XPath createNewXPath (@Nonnull final XPathFactory aXPathFactory, @Nullable final XPathVariableResolver aVariableResolver, @Nullable final XPathFunctionResolver aFunctionResolver, @Nullable final NamespaceContext aNamespaceContext) { ValueEnforcer.notNull (aXPathFactory, "XPathFactory"); final XPath aXPath = aXPathFactory.newXPath (); if (aVariableResolver != null) aXPath.setXPathVariableResolver (aVariableResolver); if (aFunctionResolver != null) aXPath.setXPathFunctionResolver (aFunctionResolver); if (aNamespaceContext != null) aXPath.setNamespaceContext (aNamespaceContext); return aXPath; }
/** * Create a new {@link XPath} with the passed variable resolver, function * resolver and namespace context. * * @param aXPathFactory * The XPath factory object to use. May not be <code>null</code>. * @param aVariableResolver * Variable resolver to be used. May be <code>null</code>. * @param aFunctionResolver * Function resolver to be used. May be <code>null</code>. * @param aNamespaceContext * Namespace context to be used. May be <code>null</code>. * @return The created non-<code>null</code> {@link XPath} object */ @Nonnull public static XPath createNewXPath (@Nonnull final XPathFactory aXPathFactory, @Nullable final XPathVariableResolver aVariableResolver, @Nullable final XPathFunctionResolver aFunctionResolver, @Nullable final NamespaceContext aNamespaceContext) { ValueEnforcer.notNull (aXPathFactory, "XPathFactory"); final XPath aXPath = aXPathFactory.newXPath (); if (aVariableResolver != null) aXPath.setXPathVariableResolver (aVariableResolver); if (aFunctionResolver != null) aXPath.setXPathFunctionResolver (aFunctionResolver); if (aNamespaceContext != null) aXPath.setNamespaceContext (aNamespaceContext); return aXPath; }
public Object evaluate(final ProcessContext context) throws Exception { XPathFactory factory = XPathFactory.newInstance(); XPath xpathEvaluator = factory.newXPath(); xpathEvaluator.setXPathFunctionResolver( new XPathFunctionResolver() { public XPathFunction resolveFunction(QName functionName, int arity)
/** * Compiles the expression, if it has not already been compiled. This is * called from the various <code>evaluate</code> methods, and ensures * that the caller has completely configured the wrapper prior to use. */ private void compileIfNeeded() { if (_compiled != null) return; try { XPathFactory fact = null; synchronized (XPathFactory.class) { fact = XPathFactory.newInstance(); } XPath xpath = fact.newXPath(); xpath.setNamespaceContext(_nsResolver); xpath.setXPathVariableResolver(new MyVariableResolver()); xpath.setXPathFunctionResolver(_functions); _compiled = xpath.compile(_expr); } catch (XPathExpressionException ee) { throw new XmlException("unable to compile: " + _expr, ee); } }
.setXPathFunctionResolver(new javax.xml.xpath.XPathFunctionResolver() {
xpathObj.setXPathFunctionResolver(testCase.functionResolver); xpathObj.setNamespaceContext(testCase.nsContext);
public synchronized String evaluateDOMXPath(MessageContext synCtx) throws XPathExpressionException { OMElement element = synCtx.getEnvelope().getBody().getFirstElement(); OMElement doomElement; if (element == null) { doomElement = new DOMSOAPFactory().createOMElement(new QName("")); } else { doomElement = convertToDOOM(element); } domXpath.setNamespaceContext(domNamespaceMap); domXpath.setXPathFunctionResolver(new GetPropertyFunctionResolver(synCtx)); domXpath.setXPathVariableResolver(new DOMSynapseXPathVariableResolver(this.getVariableContext(), synCtx)); /* Compile the original expression again with Saxon to be evaluated with XPath 2.0 */ XPathExpression expr = domXpath.compile(getExpression()); Object result = expr.evaluate(doomElement); if (result != null) { return result.toString(); } return null; }
JaxpVariableResolver varResolver = new JaxpVariableResolver(ctx, oxpath20, ((XPathFactoryImpl) _xpf).getConfiguration()); XPath xpe = _xpf.newXPath(); xpe.setXPathFunctionResolver(funcResolver); xpe.setXPathVariableResolver(varResolver); xpe.setNamespaceContext(oxpath20.namespaceCtx);
_compilerContext, out); XPath xpe = xpf.newXPath(); xpe.setXPathFunctionResolver(funcResolver); xpe.setXPathVariableResolver(varResolver); xpe.setNamespaceContext(source.getNamespaceContext());
private void readAttachTo(ExternalAttachment attachment, XMLStreamReader reader, ProcessorContext context) { Monitor monitor = context.getMonitor(); String attachTo = reader.getAttributeValue(null, ATTACH_TO); if ( attachTo != null ) { try { XPath path = xpathHelper.newXPath(); NamespaceContext nsContext = xpathHelper.getNamespaceContext(attachTo, reader.getNamespaceContext()); path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(nsContext)); attachTo = PolicyXPathFunction.normalize(attachTo,getSCAPrefix(nsContext)); XPathExpression expression = xpathHelper.compile(path, nsContext, attachTo); attachment.setAttachTo(attachTo); attachment.setAttachToXPathExpression(expression); } catch (XPathExpressionException e) { ContributionReadException ce = new ContributionReadException(e); error(monitor, "ContributionReadException", attachment, ce); } } }
private void readAttachTo(ExternalAttachment attachment, XMLStreamReader reader, ProcessorContext context) { Monitor monitor = context.getMonitor(); String attachTo = reader.getAttributeValue(null, ATTACH_TO); if ( attachTo != null ) { try { XPath path = xpathHelper.newXPath(); NamespaceContext nsContext = xpathHelper.getNamespaceContext(attachTo, reader.getNamespaceContext()); path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(nsContext)); attachTo = PolicyXPathFunction.normalize(attachTo,getSCAPrefix(nsContext)); XPathExpression expression = xpathHelper.compile(path, nsContext, attachTo); attachment.setAttachTo(attachTo); attachment.setAttachToXPathExpression(expression); } catch (XPathExpressionException e) { ContributionReadException ce = new ContributionReadException(e); error(monitor, "ContributionReadException", attachment, ce); } } }
XPath path = xpathHelper.newXPath(); NamespaceContext nsContext = xpathHelper.getNamespaceContext(attachTo, reader.getNamespaceContext()); path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(nsContext));
XPath path = xpathHelper.newXPath(); NamespaceContext nsContext = xpathHelper.getNamespaceContext(attachTo, reader.getNamespaceContext()); path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(nsContext));