Search in sources :

Example 41 with ResultSequence

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

the class FnSecondsFromTime method seconds_from_time.

/**
 * Base-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:base-uri operation.
 */
public static ResultSequence seconds_from_time(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSTime dt = (XSTime) arg1.first();
    double res = dt.second();
    return new XSDecimal(new BigDecimal(res));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Collection(java.util.Collection) XSTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime) XSDecimal(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDecimal) BigDecimal(java.math.BigDecimal)

Example 42 with ResultSequence

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

the class FnCollection method getCollection.

private static ResultSequence getCollection(String uri, EvaluationContext ec) {
    ResultBuffer rs = new ResultBuffer();
    Map /*<String, List<Document>>*/
    collectionMap = ec.getDynamicContext().getCollections();
    List /*<Document>*/
    docList = (List) collectionMap.get(uri);
    for (int i = 0; i < docList.size(); i++) {
        Document doc = (Document) docList.get(i);
        rs.add(new DocType(doc, ec.getStaticContext().getTypeModel()));
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.w3c.dom.Document) Map(java.util.Map) DocType(org.eclipse.wst.xml.xpath2.processor.internal.types.DocType)

Example 43 with ResultSequence

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

the class FnCount method count.

/**
 * Count operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:count operation.
 */
public static ResultSequence count(Collection args) throws DynamicError {
    assert args.size() == 1;
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg = (ResultSequence) citer.next();
    return ResultSequenceFactory.create_new(new XSInteger(BigInteger.valueOf(arg.size())));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator)

Example 44 with ResultSequence

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

the class FnDayFromDate method day_from_date.

/**
 * Day-From-Date operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:day-from-date operation.
 */
public static ResultSequence day_from_date(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    XSDate dt = (XSDate) arg1.first();
    int res = dt.day();
    return new XSInteger(BigInteger.valueOf(res));
}
Also used : XSDate(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection)

Example 45 with ResultSequence

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

the class SeqExprCastableTest method test_CastableAs080.

// Try xs:untypedAtomic(http://www.example.com/~b%C3%A9b%C3%A9) castable as xs:anyURI.
public void test_CastableAs080() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/exprSeqTypes/SeqExprCastable/CastableAs080.xq";
    String resultFile = "/ExpectedTestResults/Expressions/exprSeqTypes/SeqExprCastable/CastableAs080.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

ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)8383 URL (java.net.URL)8366 XSModel (org.apache.xerces.xs.XSModel)8363 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)8279 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)8279 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)8208 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)173 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)156 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)130 Schema (javax.xml.validation.Schema)102 Iterator (java.util.Iterator)92 Collection (java.util.Collection)83 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)83 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 Item (org.eclipse.wst.xml.xpath2.api.Item)56 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)34 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)32