Search in sources :

Example 6 with Engine

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();
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StaticContextBuilder(org.eclipse.wst.xml.xpath2.processor.util.StaticContextBuilder) InputStream(java.io.InputStream) DynamicContextBuilder(org.eclipse.wst.xml.xpath2.processor.util.DynamicContextBuilder) Document(org.w3c.dom.Document) XPath2Expression(org.eclipse.wst.xml.xpath2.api.XPath2Expression) Engine(org.eclipse.wst.xml.xpath2.processor.Engine)

Example 7 with Engine

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;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) DynamicContextBuilder(org.eclipse.wst.xml.xpath2.processor.util.DynamicContextBuilder) XPath2Expression(org.eclipse.wst.xml.xpath2.api.XPath2Expression) Engine(org.eclipse.wst.xml.xpath2.processor.Engine) DynamicContext(org.eclipse.wst.xml.xpath2.api.DynamicContext)

Aggregations

Engine (org.eclipse.wst.xml.xpath2.processor.Engine)5 XPath2Expression (org.eclipse.wst.xml.xpath2.api.XPath2Expression)3 DynamicContextBuilder (org.eclipse.wst.xml.xpath2.processor.util.DynamicContextBuilder)3 DynamicContext (org.eclipse.wst.xml.xpath2.api.DynamicContext)2 StaticContext (org.eclipse.wst.xml.xpath2.api.StaticContext)2 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)2 StaticContextBuilder (org.eclipse.wst.xml.xpath2.processor.util.StaticContextBuilder)2 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 URI (java.net.URI)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Symbol (java_cup.runtime.Symbol)1 NamespaceContext (javax.xml.namespace.NamespaceContext)1 QName (javax.xml.namespace.QName)1 OMFactory (org.apache.axiom.om.OMFactory)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)1 CollationProvider (org.eclipse.wst.xml.xpath2.api.CollationProvider)1