use of org.eclipse.wst.xml.xpath2.processor.Engine in project webservices-axiom by apache.
the class PsychoPathTest method evaluate.
private static ResultSequence evaluate(String xpath) throws Exception {
InputStream is = PsychoPathTest.class.getResourceAsStream("test.xml");
try {
OMFactory factory = OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory();
Document doc = (Document) OMXMLBuilderFactory.createOMBuilder(factory, is).getDocument();
StaticContextBuilder scb = new StaticContextBuilder();
XPath2Expression expr = new Engine().parseExpression(xpath, scb);
return expr.evaluate(new DynamicContextBuilder(scb), new Object[] { doc });
} finally {
is.close();
}
}
use of org.eclipse.wst.xml.xpath2.processor.Engine in project webtools.sourceediting by eclipse.
the class CompleteNewApiTest method evaluateSimpleXPath.
protected Object evaluateSimpleXPath(String xpath, StaticContext sc, Document doc, Class resultClass) {
XPath2Expression path = new Engine().parseExpression(xpath, sc);
DynamicContext dynamicContext = new DynamicContextBuilder(sc);
org.eclipse.wst.xml.xpath2.api.ResultSequence rs = path.evaluate(dynamicContext, doc != null ? new Object[] { doc } : new Object[0]);
assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());
Object result = rs.value(0);
assertTrue("Exected XPath result instanceof class " + resultClass.getSimpleName() + " from \'" + xpath + "\', got " + result.getClass(), resultClass.isInstance(result));
return result;
}
Aggregations