Search in sources :

Example 76 with Item

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

the class SeqIDREFFuncTest method test_fn_idref_2.

// Evaluation of fn:idref with second argument ommited and no context item.
public void test_fn_idref_2() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Functions/NodeSeqFunc/SeqIDREFFunc/fn-idref-2.xq";
    String expectedResult = "XPDY0002";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = "fn:idref(\"argument1\")";
    String actual = null;
    try {
        compileXPath(xpath);
        // no context
        ResultSequence rs = evaluate(null);
        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 77 with Item

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

the class SeqExactlyOneFuncTest method test_fn_exactly_one_1.

// Evaluates the "exactly-one" function with the argument set to a sequence with more than one item.
public void test_fn_exactly_one_1() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Functions/SeqFunc/CardinalitySeqFunc/SeqExactlyOneFunc/fn-exactly-one-1.xq";
    String expectedResult = "FORG0005";
    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 78 with Item

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

the class SeqBooleanFuncTest method test_context_item_1.

// Evaluates fn:boolean that uses a context item, which is not defined.
public void test_context_item_1() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Functions/SeqFunc/GeneralSeqFunc/SeqBooleanFunc/context-item-1.xq";
    String expectedResult = "XPDY0002";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = extractXPathExpression(xqFile, inputFile);
    xpath = "fn:boolean(.)";
    String actual = null;
    try {
        compileXPath(xpath);
        // no context
        ResultSequence rs = evaluate(null);
        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 79 with Item

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

the class StringFuncTest method test_fn_string_3.

// Evaluates the "string" function with argument set to "." and context item undefined.
public void test_fn_string_3() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Functions/AccessorFunc/StringFunc/fn-string-3.xq";
    String expectedResult = "XPDY0002";
    URL fileURL = bundle.getEntry(inputFile);
    loadDOMDocument(fileURL);
    // Get XML Schema Information for the Document
    XSModel schema = getGrammar();
    setupDynamicContext(schema);
    String xpath = "fn:string(.)";
    String actual = null;
    try {
        compileXPath(xpath);
        // no context document!
        ResultSequence rs = evaluate(null);
        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 80 with Item

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

the class DefaultEvaluator method visit.

/**
 * visit XPath expression
 *
 * @param e
 *            is the XPath expression.
 * @return a new function
 */
public Object visit(XPathExpr e) {
    XPathExpr xp = e;
    ResultSequence rs = null;
    Focus original_focus = focus();
    // do all the steps
    while (xp != null) {
        StepExpr se = xp.expr();
        if (se != null) {
            // this is not the first step
            if (rs != null) {
                // results...
                if (rs.size() == 0)
                    break;
                // nodes!
                for (Iterator i = rs.iterator(); i.hasNext(); ) {
                    AnyType item = (AnyType) i.next();
                    if (!(item instanceof NodeType)) {
                        report_error(TypeError.step_conatins_atoms(null));
                        // unreach
                        return null;
                    }
                }
                // check if we got a //
                if (xp.slashes() == 2) {
                    rs = descendant_or_self_node(rs);
                    if (rs.size() == 0)
                        break;
                }
                // make result of previous step the new
                // focus
                set_focus(new Focus(rs));
                // do the step for all item in context
                rs = do_step(se);
            } else // this is first step...
            // note... we may be called from upstream...
            // like in the expression sorbo/*[2] ... we may
            // be called to evaluate the 2... the caller
            // will iterate through the whole outer focus
            // for us
            {
                // XXX ???
                if (xp.slashes() == 1) {
                    rs = root_self_node();
                    set_focus(new Focus(rs));
                    rs = do_step(se);
                } else if (xp.slashes() == 2) {
                    rs = root_self_node();
                    rs = descendant_or_self_node(rs);
                    set_focus(new Focus(rs));
                    rs = do_step(se);
                } else
                    rs = (ResultSequence) se.accept(this);
            }
        } else // the expression is "/"
        {
            assert xp.slashes() == 1;
            rs = root_self_node();
        }
        xp = xp.next();
    }
    // restore focus
    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) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)71 Item (org.eclipse.wst.xml.xpath2.api.Item)69 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)66 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)65 URL (java.net.URL)64 XSModel (org.apache.xerces.xs.XSModel)64 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)64 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)46 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)34 Iterator (java.util.Iterator)26 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)14 BigInteger (java.math.BigInteger)13 Collection (java.util.Collection)13 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)11 ListIterator (java.util.ListIterator)8 NodeType (org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)5 ArrayList (java.util.ArrayList)4 GregorianCalendar (java.util.GregorianCalendar)4