use of org.jaxen.SimpleVariableContext in project wso2-synapse by wso2.
the class SynapseXPathTest method testCustomVariables.
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/>")));
}
use of org.jaxen.SimpleVariableContext in project pmd by pmd.
the class JaxenXPathRuleQuery method createXPath.
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;
}
Aggregations