Search in sources :

Example 1 with SimpleVariableContext

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/>")));
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) SimpleVariableContext(org.jaxen.SimpleVariableContext)

Example 2 with SimpleVariableContext

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;
}
Also used : PropertyDescriptor(net.sourceforge.pmd.properties.PropertyDescriptor) BaseXPath(org.jaxen.BaseXPath) SimpleVariableContext(org.jaxen.SimpleVariableContext)

Aggregations

SimpleVariableContext (org.jaxen.SimpleVariableContext)2 PropertyDescriptor (net.sourceforge.pmd.properties.PropertyDescriptor)1 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)1 BaseXPath (org.jaxen.BaseXPath)1