/** * Creates a new XPath with a given namespace context. * * @param namespaceContext The namespace context to be used or null * if none should be used. * @param resolver The name space resolver. * @return The new XPath */ public static final XPath newXPath( NamespaceContext namespaceContext, XPathVariableResolver resolver ) { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); if (namespaceContext != null) { xpath.setNamespaceContext(namespaceContext); } if (resolver != null) { xpath.setXPathVariableResolver(resolver); } return xpath; }
public Object load(Property property, final RouteContext context) { XPath xpath = XPathHelper.newXPath(); final BranchService branchService = KEWServiceLocator.getBranchService(); xpath.setXPathVariableResolver(new XPathVariableResolver() { public Object resolveVariable(QName name) { LOG.debug("Resolving XPath variable: " + name); String value = branchService.getScopedVariableValue(context.getNodeInstance().getBranch(), BranchState.VARIABLE_PREFIX + name.getLocalPart()); LOG.debug("Resolved XPath variable " + name + " to " + value); return value; } }); try { String docContent = context.getDocument().getDocContent(); LOG.debug("Executing xpath expression '" + property.locator + "' in doc '" + docContent + "'"); return xpath.evaluate(property.locator, new InputSource(new StringReader(docContent)), XPathConstants.STRING); } catch (XPathExpressionException xpee) { throw new RuntimeException("Error evaluating xpath expression '" + property.locator + "'", xpee); } }
/** * 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; }
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; }
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 variable resolver.</p> * * @param resolver Variable Resolver */ public void setXPathVariableResolver(XPathVariableResolver resolver) { if ( resolver == null ) { String fmsg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] {"XPathVariableResolver"} ); throw new NullPointerException( fmsg ); } this.variableResolver = 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; }
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(); }
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); }
/** * Create a new {@link XPath} with the passed namespace context. * * @param aXPathFactory * The XPath factory object to use. May not 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 NamespaceContext aNamespaceContext) { return createNewXPath (aXPathFactory, (XPathVariableResolver) null, (XPathFunctionResolver) null, aNamespaceContext); }
@Nonnull @Deprecated @DevelopersNote ("Typo in name") public static XPathExpression createNewXPathExpresion (@Nullable final XPathVariableResolver aVariableResolver, @Nullable final XPathFunctionResolver aFunctionResolver, @Nullable final NamespaceContext aNamespaceContext, @Nonnull @Nonempty final String sXPath) { return createNewXPathExpression (aVariableResolver, aFunctionResolver, aNamespaceContext, sXPath); }
@Nonnull @Deprecated @DevelopersNote ("Typo in name") public static XPathExpression createNewXPathExpresion (@Nullable final XPathVariableResolver aVariableResolver, @Nonnull @Nonempty final String sXPath) { return createNewXPathExpression (aVariableResolver, sXPath); }
@Nullable public static Object evalXPath (@Nullable final XPathVariableResolver aVariableResolver, @Nullable final XPathFunctionResolver aFunctionResolver, @Nullable final NamespaceContext aNamespaceContext, @Nonnull final String sXPath, @Nonnull final Document aDoc, @Nonnull final QName aReturnType) { return evalXPath (XPathHelper.createNewXPath (aVariableResolver, aFunctionResolver, aNamespaceContext), sXPath, aDoc, aReturnType); }
@Nullable public static Double evalXPathToNumber (@Nullable final XPathVariableResolver aVariableResolver, @Nullable final XPathFunctionResolver aFunctionResolver, @Nullable final NamespaceContext aNamespaceContext, @Nonnull final String sXPath, @Nonnull final Document aDoc) { return evalXPathToNumber (XPathHelper.createNewXPath (aVariableResolver, aFunctionResolver, aNamespaceContext), sXPath, aDoc); }
@Nullable public static String evalXPathToString (@Nullable final XPathVariableResolver aVariableResolver, @Nullable final XPathFunctionResolver aFunctionResolver, @Nullable final NamespaceContext aNamespaceContext, @Nonnull final String sXPath, @Nonnull final Document aDoc) { return evalXPathToString (XPathHelper.createNewXPath (aVariableResolver, aFunctionResolver, aNamespaceContext), sXPath, aDoc); }
@Nullable public static Boolean evalXPathToBoolean (@Nullable final XPathVariableResolver aVariableResolver, @Nullable final XPathFunctionResolver aFunctionResolver, @Nullable final NamespaceContext aNamespaceContext, @Nonnull final String sXPath, @Nonnull final Document aDoc) { return evalXPathToBoolean (XPathHelper.createNewXPath (aVariableResolver, aFunctionResolver, aNamespaceContext), sXPath, aDoc); }