Search in sources :

Example 66 with DefaultEvaluator

use of org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator in project webtools.sourceediting by eclipse.

the class StaticContextAdapterTest method testFunctionCall.

public void testFunctionCall() {
    XPathParser xpp = new JFlexCupParser();
    XPath xpath = xpp.parse("fn:sum((1,2,3))");
    DefaultStaticContext sc = new DefaultStaticContext(null);
    sc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
    sc.add_function_library(new FnFunctionLibrary());
    StaticChecker namecheck = new StaticNameResolver(sc);
    namecheck.check(xpath);
    DefaultDynamicContext dc = new DefaultDynamicContext(null, null);
    dc.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");
    dc.add_function_library(new FnFunctionLibrary());
    Evaluator eval = new DefaultEvaluator(dc, null);
    ResultSequence rs = eval.evaluate(xpath);
    assertEquals(1, rs.size());
    XSDecimal result = (XSDecimal) rs.first();
    String actual = result.getStringValue();
    assertEquals("6", actual);
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath) StaticChecker(org.eclipse.wst.xml.xpath2.processor.StaticChecker) XPathParser(org.eclipse.wst.xml.xpath2.processor.XPathParser) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) DefaultStaticContext(org.eclipse.wst.xml.xpath2.processor.internal.DefaultStaticContext) Evaluator(org.eclipse.wst.xml.xpath2.processor.Evaluator) DefaultEvaluator(org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator) FnFunctionLibrary(org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary) StaticNameResolver(org.eclipse.wst.xml.xpath2.processor.StaticNameResolver) DefaultDynamicContext(org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) JFlexCupParser(org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)

Example 67 with DefaultEvaluator

use of org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_Axes078_3.

// elem//name gets the 1 descendant of that name.
public void test_Axes078_3() throws Exception {
    String inputFile = "/TestSources/TreeCompass.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/Steps/Axes/Axes078.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/Steps/Axes/Axes078-3.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 = buildResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertEquals("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)

Example 68 with DefaultEvaluator

use of org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_Axes078_2.

// elem//name gets none when no elements have that name.
public void test_Axes078_2() throws Exception {
    String inputFile = "/TestSources/Tree1Child.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/Steps/Axes/Axes078.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/Steps/Axes/Axes078-2.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 = buildResultString(rs);
    } catch (XPathParserException ex) {
        actual = ex.code();
    } catch (StaticError ex) {
        actual = ex.code();
    } catch (DynamicError ex) {
        actual = ex.code();
    }
    assertEquals("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)

Example 69 with DefaultEvaluator

use of org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_unabbreviatedSyntax_21.

// Evaluates unabbreviated syntax. Evaluate
// "child::employee[fn:position() = fn:last()]". Selects the last "employee"
// child of the context node.
public void test_unabbreviatedSyntax_21() throws Exception {
    String inputFile = "/TestSources/works-mod.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-21.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-21.txt";
    String expectedResult = formatResultString(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)

Example 70 with DefaultEvaluator

use of org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_unabbreviatedSyntax_12.

// Evaluates unabbreviated syntax - descendant-or-self::employee - Selects
// all the "employee" descendant of the context node (selects employee, if
// the context node is "employee").
public void test_unabbreviatedSyntax_12() throws Exception {
    String inputFile = "/TestSources/works-mod.xml";
    String xqFile = "/Queries/XQuery/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-12.xq";
    String resultFile = "/ExpectedTestResults/Expressions/PathExpr/UnabbrAxes/unabbreviatedSyntax-12.txt";
    String expectedResult = formatResultString(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

ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)79 URL (java.net.URL)77 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)77 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)77 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)77 XSModel (org.apache.xerces.xs.XSModel)74 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)74 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)74 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)74 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)72 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)2 DefaultDynamicContext (org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext)1 JFlexCupParser (org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)1 StaticChecker (org.eclipse.wst.xml.xpath2.processor.StaticChecker)1 StaticNameResolver (org.eclipse.wst.xml.xpath2.processor.StaticNameResolver)1 XPathParser (org.eclipse.wst.xml.xpath2.processor.XPathParser)1 FnFunctionLibrary (org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary)1 DefaultStaticContext (org.eclipse.wst.xml.xpath2.processor.internal.DefaultStaticContext)1 XSDecimal (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal)1