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"); } }
/** * 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 PSBoundSchemaCacheKey (@Nonnull final IReadableResource aResource, @Nullable final String sPhase, @Nullable final IPSErrorHandler aErrorHandler, @Nullable final XPathVariableResolver aVariableResolver, @Nullable final XPathFunctionResolver aFunctionResolver, @Nullable final EntityResolver aEntityResolver) { ValueEnforcer.notNull (aResource, "Resource"); m_aResource = aResource; m_sPhase = sPhase; m_aErrorHandler = aErrorHandler; m_aVariableResolver = aVariableResolver; m_aFunctionResolver = aFunctionResolver; m_aEntityResolver = aEntityResolver; }
/** * Look for a function in the registered XPathFunctionResolvers. * @param iri The URI of the function to find. * @return The requested XPathFunction, or <code>null</code> if not found. */ private XPathFunction findFunction(IRI iri, int argCount) { String label = iri.toString() + "/" + argCount; XPathFunction result = fnCache.get(label); if (result == null) { QName fnName = iri.getQName(); if (fnName == null) return null; for (XPathFunctionResolver resolver: FunctionResolverRegistry.getFunctionResolverRegistry()) { try { result = resolver.resolveFunction(fnName, argCount); if (result != null) { fnCache.put(label, result); break; } } catch (Exception e) { // this resolver is unable to handle the given QName result = null; } } } return result; }
public void init(Node ctx, final Map<String, Object> properties, final ReferenceResolver referenceResolver){ XPathFactory factory = XPathFactory.newInstance(); xpath = factory.newXPath(); xpath.setXPathVariableResolver(new XPathVariableResolver(){ @Override public Object resolveVariable(QName variableName) { return properties.get(variableName.getLocalPart()); } }); xpath.setXPathFunctionResolver(new XPathFunctionResolver(){ @Override public XPathFunction resolveFunction(QName name, int arity) { if (FUNC_RANDOM.equals(name.getLocalPart())){ return new XPathFunctionRandom(); } if (FUNC_EVALUATE.equals(name.getLocalPart())){ return new XPathFunctionEvaluate(referenceResolver); } return null; } }); this.ctx=ctx; }
public JAXPExtensionsProvider(XPathFunctionResolver resolver, boolean featureSecureProcessing, FeatureManager featureManager ) { this.resolver = resolver; if (featureSecureProcessing && !featureManager.isFeatureEnabled(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION)) { this.extensionInvocationDisabled = true; } }
XPathImpl( XPathVariableResolver vr, XPathFunctionResolver fr, boolean featureSecureProcessing, boolean useServiceMechanism, FeatureManager featureManager) { this.origVariableResolver = this.variableResolver = vr; this.origFunctionResolver = this.functionResolver = fr; this.featureSecureProcessing = featureSecureProcessing; this.useServiceMechanism = useServiceMechanism; this.featureManager = featureManager; }
/** * <p>Establishes a function resolver.</p> * * @param resolver XPath function resolver */ public void setXPathFunctionResolver(XPathFunctionResolver resolver) { if ( resolver == null ) { String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] {"XPathFunctionResolver"} ); throw new NullPointerException( fmsg ); } this.functionResolver = resolver; }
protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath, JAXPPrefixResolver prefixResolver, XPathFunctionResolver functionResolver, XPathVariableResolver variableResolver ) { this(xpath, prefixResolver, functionResolver, variableResolver, false, true, new FeatureManager()); }
protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath, JAXPPrefixResolver prefixResolver,XPathFunctionResolver functionResolver, XPathVariableResolver variableResolver, boolean featureSecureProcessing, boolean useServicesMechanism, FeatureManager featureManager ) { this.xpath = xpath; this.prefixResolver = prefixResolver; this.functionResolver = functionResolver; this.variableResolver = variableResolver; this.featureSecureProcessing = featureSecureProcessing; this.useServicesMechanism = useServicesMechanism; this.featureManager = featureManager; }
public JAXPExtensionsProvider(XPathFunctionResolver resolver, boolean featureSecureProcessing, JdkXmlFeatures featureManager ) { this.resolver = resolver; if (featureSecureProcessing && !featureManager.getFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION)) { this.extensionInvocationDisabled = true; } }
XPathImpl(XPathVariableResolver vr, XPathFunctionResolver fr, boolean featureSecureProcessing, boolean useServiceMechanism, JdkXmlFeatures featureManager) { this.origVariableResolver = this.variableResolver = vr; this.origFunctionResolver = this.functionResolver = fr; this.featureSecureProcessing = featureSecureProcessing; this.useServiceMechanism = useServiceMechanism; this.featureManager = featureManager; }
protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath, JAXPPrefixResolver prefixResolver, XPathFunctionResolver functionResolver, XPathVariableResolver variableResolver) { this(xpath, prefixResolver, functionResolver, variableResolver, false, true, new JdkXmlFeatures(false)); }
protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath, JAXPPrefixResolver prefixResolver,XPathFunctionResolver functionResolver, XPathVariableResolver variableResolver, boolean featureSecureProcessing, boolean useServiceMechanism, JdkXmlFeatures featureManager) { this.xpath = xpath; this.prefixResolver = prefixResolver; this.functionResolver = functionResolver; this.variableResolver = variableResolver; this.featureSecureProcessing = featureSecureProcessing; this.useServiceMechanism = useServiceMechanism; this.featureManager = featureManager; }
XPathImpl(XPathVariableResolver vr, XPathFunctionResolver fr, boolean featureSecureProcessing, boolean useServiceMechanism, FeatureManager featureManager) { this.origVariableResolver = this.variableResolver = vr; this.origFunctionResolver = this.functionResolver = fr; this.featureSecureProcessing = featureSecureProcessing; this.useServiceMechanism = useServiceMechanism; this.featureManager = featureManager; }
protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath, JAXPPrefixResolver prefixResolver, XPathFunctionResolver functionResolver, XPathVariableResolver variableResolver) { this(xpath, prefixResolver, functionResolver, variableResolver, false, true, new FeatureManager()); }
protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath, JAXPPrefixResolver prefixResolver,XPathFunctionResolver functionResolver, XPathVariableResolver variableResolver, boolean featureSecureProcessing, boolean useServiceMechanism, FeatureManager featureManager) { this.xpath = xpath; this.prefixResolver = prefixResolver; this.functionResolver = functionResolver; this.variableResolver = variableResolver; this.featureSecureProcessing = featureSecureProcessing; this.useServiceMechanism = useServiceMechanism; this.featureManager = featureManager; }
XPathImpl(NamespaceContext namespaceContext, XPathVariableResolver variableResolver, XPathFunctionResolver functionResolver) { parser = new XPathParser(); this.namespaceContext = namespaceContext; this.variableResolver = variableResolver; this.functionResolver = functionResolver; reset(); }
public FunctionCall(XPathFunctionResolver resolver, String name, List<Expr> args) { this.resolver = resolver; this.name = name; if (args == null) this.args = Collections.emptyList(); else this.args = args; }
/** * 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); }
/** * A utility to extract the WorkflowFunctionResolver from the given XPath instances. If the XPath instance * does not contain a WorkflowFunctionResolver, then this method will throw a WorkflowRuntimeException. * * @throws WorkflowRuntimeException if the given XPath instance does not contain a WorklflowFunctionResolver */ public static WorkflowFunctionResolver extractFunctionResolver(XPath xPath) { XPathFunctionResolver resolver = xPath.getXPathFunctionResolver(); if (!hasWorkflowFunctionResolver(xPath)) { throw new WorkflowRuntimeException("The XPathFunctionResolver on the given XPath instance is not an instance of WorkflowFunctionResolver, was: " + resolver); } return (WorkflowFunctionResolver)resolver; }
protected XPathExpressionImpl(org.apache.xpath.XPath xpath, JAXPPrefixResolver prefixResolver, XPathFunctionResolver functionResolver, XPathVariableResolver variableResolver ) { this.xpath = xpath; this.prefixResolver = prefixResolver; this.functionResolver = functionResolver; this.variableResolver = variableResolver; this.featureSecureProcessing = false; }
protected XPathExpressionImpl(org.apache.xpath.XPath xpath, JAXPPrefixResolver prefixResolver, XPathFunctionResolver functionResolver, XPathVariableResolver variableResolver, boolean featureSecureProcessing ) { this.xpath = xpath; this.prefixResolver = prefixResolver; this.functionResolver = functionResolver; this.variableResolver = variableResolver; this.featureSecureProcessing = featureSecureProcessing; }
/** * Create a new {@link XPath} without any special settings using the default * {@link XPathFactory}. * * @return The created non-<code>null</code> {@link XPath} object */ @Nonnull public static XPath createNewXPath () { return createNewXPath (s_aXPathFactory, (XPathVariableResolver) null, (XPathFunctionResolver) null, (NamespaceContext) null); }
/** * Create a new {@link XPath} without any special settings. * * @param aXPathFactory * The XPath factory object to use. May not be <code>null</code>. * @return The created non-<code>null</code> {@link XPath} object */ @Nonnull public static XPath createNewXPath (@Nonnull final XPathFactory aXPathFactory) { return createNewXPath (aXPathFactory, (XPathVariableResolver) null, (XPathFunctionResolver) null, (NamespaceContext) null); }
/** * Create a new {@link XPath} with the passed namespace context using the * default {@link XPathFactory}. * * @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 (@Nullable final NamespaceContext aNamespaceContext) { return createNewXPath (s_aXPathFactory, (XPathVariableResolver) null, (XPathFunctionResolver) null, aNamespaceContext); }