Search in sources :

Example 16 with FilterExpr

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

the class FilterExprTest method test_filterexpressionhc20.

// Simple filter expression involving two complex predicates.
public void test_filterexpressionhc20() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/SeqExpr/FilterExpr/filterexpressionhc20.xq";
    String resultFile = "/ExpectedTestResults/Expressions/SeqExpr/FilterExpr/filterexpressionhc20.txt";
    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 = 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 17 with FilterExpr

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

the class DefaultEvaluator method visit.

/**
 * visit filter expression
 *
 * @param e
 *            is the filter expression.
 * @return a result sequence
 */
// XXX unify with top ?
public Object visit(FilterExpr e) {
    ResultSequence rs = (ResultSequence) e.primary().accept(this);
    // the primary expression
    if (e.predicate_count() == 0)
        return rs;
    Focus original_focus = focus();
    // go through all predicates
    for (Iterator i = e.iterator(); i.hasNext(); ) {
        if (rs.size() == 0)
            break;
        set_focus(new Focus(rs));
        rs = do_predicate((Collection) i.next());
    }
    // restore focus [context switching ;D ]
    set_focus(original_focus);
    return rs;
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Focus(org.eclipse.wst.xml.xpath2.processor.internal.Focus) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 18 with FilterExpr

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

the class DefaultEvaluator method do_predicate.

// do the predicate for all items in focus
private ResultSequence do_predicate(Collection exprs) {
    ResultBuffer rs = new ResultBuffer();
    Focus focus = focus();
    int original_cp = focus.position();
    // check if predicate is single numeric constant
    if (exprs.size() == 1) {
        Expr expr = (Expr) exprs.iterator().next();
        if (expr instanceof XPathExpr) {
            XPathExpr xpe = (XPathExpr) expr;
            if (xpe.next() == null && xpe.slashes() == 0 && xpe.expr() instanceof FilterExpr) {
                FilterExpr fex = (FilterExpr) xpe.expr();
                if (fex.primary() instanceof IntegerLiteral) {
                    int pos = (((IntegerLiteral) fex.primary()).value().int_value()).intValue();
                    if (pos <= focus.last() && pos > 0) {
                        focus.set_position(pos);
                        rs.add(focus.context_item());
                    }
                    focus.set_position(original_cp);
                    return rs.getSequence();
                }
            }
        }
    }
    // go through all elements
    while (true) {
        // do the predicate
        // XXX saxon doesn't allow for predicates to have
        // commas... but XPath 2.0 spec seems to do
        ResultSequence res = do_expr(exprs.iterator());
        // in the sequence
        if (predicate_truth(res))
            rs.add(focus().context_item());
        if (!focus.advance_cp())
            break;
    }
    // restore
    focus.set_position(original_cp);
    return rs.getSequence();
}
Also used : QuantifiedExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.QuantifiedExpr) IfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IfExpr) OrExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.OrExpr) TreatAsExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.TreatAsExpr) ForExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr) ParExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ParExpr) DivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr) SubExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.SubExpr) CastExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr) RangeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.RangeExpr) 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) AddExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr) CmpExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr) PipeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PipeExpr) BinExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr) MulExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MulExpr) 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) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) CastableExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr) PlusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PlusExpr) AndExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) CntxItemExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr) ExceptExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr) UnionExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnionExpr) ModExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ModExpr) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) Focus(org.eclipse.wst.xml.xpath2.processor.internal.Focus) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) IntegerLiteral(org.eclipse.wst.xml.xpath2.processor.internal.ast.IntegerLiteral) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Example 19 with FilterExpr

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

the class FilterExprTest method test_filterexpressionhc7.

// Simple filter expression involving the "lt" operator.
public void test_filterexpressionhc7() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/SeqExpr/FilterExpr/filterexpressionhc7.xq";
    String resultFile = "/ExpectedTestResults/Expressions/SeqExpr/FilterExpr/filterexpressionhc7.txt";
    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 = 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 20 with FilterExpr

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

the class FilterExprTest method test_filterexpressionhc3.

// Simple filter expression returning a single number.
public void test_filterexpressionhc3() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/SeqExpr/FilterExpr/filterexpressionhc3.xq";
    String resultFile = "/ExpectedTestResults/Expressions/SeqExpr/FilterExpr/filterexpressionhc3.txt";
    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 = 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)

Aggregations

URL (java.net.URL)23 XSModel (org.apache.xerces.xs.XSModel)23 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)23 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)23 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)23 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)23 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)2 Focus (org.eclipse.wst.xml.xpath2.processor.internal.Focus)2 FilterExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)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