/** Create a default <code>VariableContext</code>. * * @return a default <code>VariableContext</code> instance */ protected VariableContext createVariableContext() { return new SimpleVariableContext(); }
private BaseXPath createXPath(final String xpathQueryString, final Navigator navigator) throws JaxenException { final BaseXPath xpath = new BaseXPath(xpathQueryString, navigator); if (properties.size() > 1) { final SimpleVariableContext vc = new SimpleVariableContext(); for (Entry<PropertyDescriptor<?>, Object> e : properties.entrySet()) { final String propName = e.getKey().name(); if (!"xpath".equals(propName)) { final Object value = e.getValue(); vc.setVariableValue(propName, value != null ? value.toString() : null); } } xpath.setVariableContext(vc); } return xpath; } }
protected ContextSupport getContextSupport() { return new ContextSupport(new SimpleNamespaceContext(), XPathFunctionContext.getInstance(), new SimpleVariableContext(), DocumentNavigator.getInstance()); }
import org.jaxen.SimpleVariableContext; import org.dom4j.XPath; XPath xpath = oDocument.createXPath("//page[@name=$targetName]/Body/contents"); SimpleVariableContext ctx = new SimpleVariableContext(); xpath.setVariableContext(ctx); ctx.setVariableValue("targetName", current.Name); Element n = (Element)xpath.selectSingleNode(oDocument);
private static VariableContext getVariableContext(Map<QName, Object> variables, SimpleVariableContext context) { if (context == null) context = new SimpleVariableContext(); for (QName qname : variables.keySet()) { Object value = variables.get(qname); context.setVariableValue(qname.getNamespaceURI(), qname.getLocalPart(), value); } return context; }
private NormalizedNodeContextSupport(final ConverterNamespaceContext context, final NormalizedNodeNavigator navigator) { super(context, YangFunctionContext.getInstance(), new SimpleVariableContext(), navigator); this.root = NormalizedNodeContext.forRoot(this); }
private NormalizedNodeContextSupport(final ConverterNamespaceContext context, final NormalizedNodeNavigator navigator) { super(context, YangFunctionContext.getInstance(), new SimpleVariableContext(), navigator); this.root = NormalizedNodeContext.forRoot(this); }
private BaseXPath createXPath(final String xpathQueryString, final Navigator navigator) throws JaxenException { final BaseXPath xpath = new BaseXPath(xpathQueryString, navigator); if (properties.size() > 1) { final SimpleVariableContext vc = new SimpleVariableContext(); for (Entry<PropertyDescriptor<?>, Object> e : properties.entrySet()) { final String propName = e.getKey().name(); if (!"xpath".equals(propName)) { final Object value = e.getValue(); vc.setVariableValue(propName, value != null ? value.toString() : null); } } xpath.setVariableContext(vc); } return xpath; } }
protected ContextSupport getContextSupport() { return new ContextSupport(new SimpleNamespaceContext(), XPathFunctionContext.getInstance(), new SimpleVariableContext(), DocumentNavigator.getInstance()); }
protected ContextSupport getContextSupport() { return new ContextSupport(new SimpleNamespaceContext(), XPathFunctionContext.getInstance(), new SimpleVariableContext(), DocumentNavigator.getInstance()); }
protected ContextSupport getContextSupport() { return new ContextSupport(new SimpleNamespaceContext(), XPathFunctionContext.getInstance(), new SimpleVariableContext(), DocumentNavigator.getInstance()); }
protected ContextSupport getContextSupport() { return new ContextSupport(new SimpleNamespaceContext(), XPathFunctionContext.getInstance(), new SimpleVariableContext(), DocumentNavigator.getInstance()); }
protected ContextSupport getContextSupport() { return new ContextSupport(new SimpleNamespaceContext(), XPathFunctionContext.getInstance(), new SimpleVariableContext(), DocumentNavigator.getInstance()); }
protected ContextSupport getContextSupport() { return new ContextSupport(new SimpleNamespaceContext(), XPathFunctionContext.getInstance(), new SimpleVariableContext(), DocumentNavigator.getInstance()); }
protected ContextSupport getContextSupport() { return new ContextSupport(new SimpleNamespaceContext(), XPathFunctionContext.getInstance(), new SimpleVariableContext(), DocumentNavigator.getInstance()); }
protected ContextSupport getContextSupport() { return new ContextSupport(new SimpleNamespaceContext(), XPathFunctionContext.getInstance(), new SimpleVariableContext(), DocumentNavigator.getInstance()); }
public static boolean matches(SpecificationNode test, String xpathExpr, Namespace namespace) { if (StringUtil.isEmpty(xpathExpr)) { throw new IllegalArgumentException(); } NamespaceContext nsContext; if (namespace == null) { nsContext = new SimpleNamespaceContext(); } else { nsContext = new NamespaceContextImpl(namespace); } ContextSupport support = new ContextSupport( nsContext, XPathFunctionContext.getInstance(), new SimpleVariableContext(), SpecificationNavigator.getInstance()); Context context = new Context(support); try { Pattern pattern = PatternParser.parse(xpathExpr); return pattern.matches(test, context); } catch (JaxenException e) { throw new RuntimeException(e); } catch (SAXPathException e) { throw new RuntimeException(e); } }
public void testCustomVariables() throws Exception { SynapseXPath xpath = new SynapseXPath("$myvar"); SimpleVariableContext variableContext = new SimpleVariableContext(); variableContext.setVariableValue("myvar", "myvalue"); xpath.setVariableContext(variableContext); assertEquals("myvalue", xpath.evaluate(TestUtils.getTestContext("<test/>"))); }