Search in sources :

Example 6 with JFlexCupParser

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

the class TestXPath20 method testParseValidXPathExpression.

public void testParseValidXPathExpression() throws Exception {
    XPathParser xpp = new JFlexCupParser();
    String xpath = "some $x in /students/student/name satisfies $x = \"Fred\"";
    xpp.parse(xpath);
}
Also used : XPathParser(org.eclipse.wst.xml.xpath2.processor.XPathParser) JFlexCupParser(org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)

Example 7 with JFlexCupParser

use of org.eclipse.wst.xml.xpath2.processor.JFlexCupParser 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 8 with JFlexCupParser

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

the class TestXPath20 method testParseInvalidXPathExpression.

public void testParseInvalidXPathExpression() throws Exception {
    try {
        XPathParser xpp = new JFlexCupParser();
        String xpath = "for  in /order/item return $x/price * $x/quantity";
        xpp.parse(xpath);
        fail("XPath parsing suceeded when it should have failed.");
    } catch (XPathParserException ex) {
    }
}
Also used : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) XPathParser(org.eclipse.wst.xml.xpath2.processor.XPathParser) JFlexCupParser(org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)

Example 9 with JFlexCupParser

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

the class Engine method parseExpression.

public XPath2Expression parseExpression(String expression, StaticContext context) {
    XPath xPath = new JFlexCupParser().parse(expression);
    xPath.setStaticContext(context);
    StaticNameResolver name_check = new StaticNameResolver(context);
    name_check.check(xPath);
    xPath.setAxes(name_check.getAxes());
    xPath.setFreeVariables(name_check.getFreeVariables());
    xPath.setResolvedFunctions(name_check.getResolvedFunctions());
    xPath.setRootUsed(name_check.isRootUsed());
    return xPath;
}
Also used : XPath(org.eclipse.wst.xml.xpath2.processor.ast.XPath)

Aggregations

JFlexCupParser (org.eclipse.wst.xml.xpath2.processor.JFlexCupParser)8 XPathParser (org.eclipse.wst.xml.xpath2.processor.XPathParser)8 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)6 StaticChecker (org.eclipse.wst.xml.xpath2.processor.StaticChecker)5 StaticNameResolver (org.eclipse.wst.xml.xpath2.processor.StaticNameResolver)5 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 DefaultDynamicContext (org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext)1 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)1 Engine (org.eclipse.wst.xml.xpath2.processor.Engine)1 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)1 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)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