Search in sources :

Example 16 with ForExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr in project webtools.sourceediting by eclipse.

the class ForExprWithoutTest method test_ForExpr005.

// For+Return - use sequence(security/right) as the predicate.
public void test_ForExpr005() throws Exception {
    String inputFile = "/TestSources/fsx.xml";
    String xqFile = "/Queries/XQuery/Expressions/FLWORExpr/ForExpr/ForExpr005.xq";
    String resultFile = "/ExpectedTestResults/Expressions/FLWORExpr/ForExpr/ForExpr005.xml";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        compileXPath(xpath);
        ResultSequence rs = evaluate(domDoc);
        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 : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

Example 17 with ForExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr in project webtools.sourceediting by eclipse.

the class ForExprWithoutTest method test_ForExpr014.

// Incorrect syntax for nested loop. Multiple return statements at the same level.
public void test_ForExpr014() throws Exception {
    String inputFile = "/TestSources/fsx.xml";
    String xqFile = "/Queries/XQuery/Expressions/FLWORExpr/ForExpr/ForExpr014.xq";
    String expectedResult = "XPST0003";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        compileXPath(xpath);
        ResultSequence rs = evaluate(domDoc);
        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 : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

Example 18 with ForExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr in project webtools.sourceediting by eclipse.

the class ForExprWithoutTest method test_ForExpr020.

// Multiple variable bindings followed by a trailing ,.
public void test_ForExpr020() throws Exception {
    String inputFile = "/TestSources/fsx.xml";
    String xqFile = "/Queries/XQuery/Expressions/FLWORExpr/ForExpr/ForExpr020.xq";
    String expectedResult = "XPST0003";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    String actual = null;
    try {
        compileXPath(xpath);
        ResultSequence rs = evaluate(domDoc);
        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 : XPathParserException(org.eclipse.wst.xml.xpath2.processor.XPathParserException) ResultSequence(org.eclipse.wst.xml.xpath2.processor.ResultSequence) XSModel(org.apache.xerces.xs.XSModel) StaticError(org.eclipse.wst.xml.xpath2.processor.StaticError) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) URL(java.net.URL)

Example 19 with ForExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr in project webtools.sourceediting by eclipse.

the class TestWTPDOMXPath2 method test_ForExpr005.

public void test_ForExpr005() throws Exception {
    String inputFile = "/TestSources/fsx.xml";
    String xqFile = "/Queries/XQuery/Expressions/FLWORExpr/ForExpr/ForExpr005.xq";
    String resultFile = "/ExpectedTestResults/Expressions/FLWORExpr/ForExpr/ForExpr005.xml";
    String expectedResult = getExpectedResult(resultFile);
    URL fileURL = bundle.getEntry(inputFile);
    super.domDoc = load(fileURL);
    DynamicContext dc = setupDynamicContext(null);
    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) 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 20 with ForExpr

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr in project webtools.sourceediting by eclipse.

the class Normalizer method visit.

/**
 * @param fex
 *            is the For expression.
 * @return fex expression.
 */
public Object visit(ForExpr fex) {
    ForExpr last = fex;
    Expr ret = fex.expr();
    int depth = 0;
    for (Iterator i = fex.iterator(); i.hasNext(); ) {
        VarExprPair ve = (VarExprPair) i.next();
        // ok we got nested fors...
        if (depth > 0) {
            Collection pairs = new ArrayList();
            pairs.add(ve);
            ForExpr fe = new ForExpr(pairs, ret);
            last.set_expr(fe);
            last = fe;
        }
        depth++;
    }
    // normalize return value, and set it to the last for expr
    ret.accept(this);
    // get rid of the pairs in the parent (original) for
    if (depth > 1)
        fex.truncate_pairs();
    return fex;
}
Also used : PipeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PipeExpr) BinExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr) QuantifiedExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.QuantifiedExpr) MulExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MulExpr) IfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IfExpr) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr) Expr(org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr) MinusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MinusExpr) OrExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.OrExpr) TreatAsExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.TreatAsExpr) PrimaryExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PrimaryExpr) ForExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr) ParExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ParExpr) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) DivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr) CastableExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr) SubExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.SubExpr) PlusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PlusExpr) CastExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr) AndExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr) RangeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.RangeExpr) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) InstOfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.InstOfExpr) IntersectExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IntersectExpr) IDivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IDivExpr) UnExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnExpr) CntxItemExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr) ExceptExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr) AddExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr) UnionExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnionExpr) CmpExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr) ModExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ModExpr) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ForExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Aggregations

URL (java.net.URL)18 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)18 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)18 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)18 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)18 XSModel (org.apache.xerces.xs.XSModel)17 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)1 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)1 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)1 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)1 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)1 AddExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr)1 AndExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr)1 BinExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr)1 CastExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr)1 CastableExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr)1