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; } }
/** * Defines an XPath variable and sets its value. * * @param name * the variable name. * @param value * the variable value. * @throws IllegalArgumentException * if <code>name</code> is not a valid XPath variable name or if the * value type is not supported by the underlying implementation */ @Override public void setVariable(String name, Object value) throws IllegalArgumentException { Object o = xPath.getVariableContext(); if (o instanceof SimpleVariableContext) { ((SimpleVariableContext) o).setVariableValue(null, name, value); } }
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; }
/** * Defines an XPath variable and sets its value. * * @param name the variable name. * @param value the variable value. * * @throws IllegalArgumentException if <code>name</code> is not * a valid XPath variable name * or if the value type is not * supported by the underlying * implementation */ public void setVariable(String name, Object value) throws IllegalArgumentException { Object o = xPath.getVariableContext(); if (o instanceof SimpleVariableContext) { ((SimpleVariableContext)o).setVariableValue(null, name, value); } }
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; } }
@BeforeClass public void setUp() throws Exception { super.setUp(); rootNode = document.selectSingleNode("/root"); authorNode = document.selectSingleNode("/root/author[1]"); variableContext.setVariableValue("root", rootNode); variableContext.setVariableValue("author", authorNode); } }
svc.setVariableValue(paramDefs[i].getQName().getNamespaceURI(), paramDefs[i].getQName().getLocalName(), value);
svc.setVariableValue(paramDefs[i].getQName().getNamespaceURI(), paramDefs[i].getQName().getLocalName(), value);
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/>"))); }