Search in sources :

Example 66 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class TestXPath20 method testAddLibraries.

public void testAddLibraries() throws Exception {
    DynamicContext dc = new DefaultDynamicContext(null, domDoc);
    dc.add_namespace("xsd", "http://www.w3.org/2001/XMLSchema");
    dc.add_function_library(new FnFunctionLibrary());
    dc.add_function_library(new XSCtrLibrary());
}
Also used : FnFunctionLibrary(org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary) DefaultDynamicContext(org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext) XSCtrLibrary(org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext) DefaultDynamicContext(org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext)

Example 67 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class AbstractPsychoPathWTPTest method assertXPathTrue.

protected void assertXPathTrue(String xpath, DynamicContext dc, Document domDoc) {
    XSBoolean result = evaluateBoolXPath(xpath, dc, domDoc);
    assertEquals(true, result.value());
}
Also used : XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)

Example 68 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class AbstractPsychoPathWTPTest method setupDynamicContext2.

protected DefaultDynamicContext setupDynamicContext2(TypeModel model) {
    DefaultDynamicContext dc = new DefaultDynamicContext(model);
    dynamicContext = dc;
    dc.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");
    dc.add_namespace("xsd", "http://www.w3.org/2001/XMLSchema");
    dc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
    dc.add_namespace("xml", "http://www.w3.org/XML/1998/namespace");
    dc.add_function_library(new FnFunctionLibrary());
    dc.add_function_library(new XSCtrLibrary());
    setupVariables(dc);
    return dc;
}
Also used : FnFunctionLibrary(org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary) DefaultDynamicContext(org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext) XSCtrLibrary(org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary)

Example 69 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class AbstractPsychoPathWTPTest method evaluateSimpleXPath.

protected AnyType evaluateSimpleXPath(String xpath, DynamicContext dc, Document doc, Class resultClass) {
    XPath path;
    try {
        path = compileXPath(dc, xpath);
    } catch (XPathParserException e) {
        throw new RuntimeException("XPath parse: " + e.getMessage(), e);
    } catch (StaticError e) {
        throw new RuntimeException("Static error: " + e.getMessage(), e);
    }
    Evaluator eval = new DefaultEvaluator(dc, doc);
    ResultSequence rs;
    try {
        rs = eval.evaluate(path);
    } catch (DynamicError e) {
        throw new RuntimeException("Evaluation error: " + e.getMessage(), e);
    }
    assertEquals("Expected single result from \'" + xpath + "\'", 1, rs.size());
    AnyType result = rs.first();
    assertTrue("Exected XPath result instanceof class " + resultClass.getSimpleName() + " from \'" + xpath + "\', got " + result.getClass(), resultClass.isInstance(result));
    return result;
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 70 with DynamicContext

use of org.eclipse.wst.xml.xpath2.api.DynamicContext in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_unabbreviatedSyntax_33.

// Evaluates unabbreviated syntax. Evaluate
// "child::*[self::empnum or self::pnum][fn:position() = fn:last()]".
// Selects the last empnum or pnum child of the context node.
public void test_unabbreviatedSyntax_33() throws Exception {
    String inputFile = "/TestSources/works-mod.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-33.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-33.txt";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    domDoc = load(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = null;
    DynamicContext dc = setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        XPath path = compileXPath(dc, xpath);
        Evaluator eval = new DefaultEvaluator(dc, domDoc);
        ResultSequence rs = eval.evaluate(path);
        actual = buildXMLResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertXMLEqual("XPath Result Error " + xqFile + ":", expectedResult, actual);
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL) DynamicContext(org.eclipse.wst.xml.xpath2.processor.DynamicContext)

Aggregations

XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)77 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)75 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)75 URL (java.net.URL)73 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)73 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)73 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)73 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)72 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)72 XSModel (org.apache.xerces.xs.XSModel)69 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)20 Item (org.eclipse.wst.xml.xpath2.api.Item)17 Iterator (java.util.Iterator)13 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)11 Collection (java.util.Collection)10 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)8 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)6 Duration (javax.xml.datatype.Duration)5