Search in sources :

Example 36 with Item

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

the class XSInteger method plus.

/**
 * Mathematical addition operator between this XSInteger and the supplied
 * ResultSequence.
 *
 * @param arg
 *            The ResultSequence to perform an addition with
 * @return A XSInteger consisting of the result of the mathematical
 *         addition.
 */
public ResultSequence plus(ResultSequence arg) throws DynamicError {
    ResultSequence carg = convertResultSequence(arg);
    Item at = get_single_arg(carg);
    if (!(at instanceof XSInteger))
        DynamicError.throw_type_error();
    XSInteger val = (XSInteger) at;
    return ResultSequenceFactory.create_new(new XSInteger(int_value().add(val.int_value())));
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence)

Example 37 with Item

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

the class FnResolveURI method resolveURI.

/**
 * Resolve-URI operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param d_context
 *            Dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:resolve-uri operation.
 */
public static ResultSequence resolveURI(Collection args, EvaluationContext ec) throws DynamicError {
    if (ec.getStaticContext().getBaseUri() == null) {
        throw DynamicError.noBaseURI();
    }
    Collection cargs = args;
    Iterator argit = cargs.iterator();
    ResultSequence relativeRS = (ResultSequence) argit.next();
    ResultSequence baseUriRS = null;
    if (argit.hasNext()) {
        baseUriRS = (ResultSequence) argit.next();
    }
    if (relativeRS.empty()) {
        return ResultBuffer.EMPTY;
    }
    Item relativeURI = relativeRS.first();
    String resolvedURI = null;
    if (baseUriRS == null) {
        resolvedURI = resolveURI(ec.getStaticContext().getBaseUri().toString(), relativeURI.getStringValue());
    } else {
        Item baseURI = baseUriRS.first();
        resolvedURI = resolveURI(baseURI.getStringValue(), relativeURI.getStringValue());
    }
    return new XSAnyURI(resolvedURI);
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) XSAnyURI(org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 38 with Item

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

the class FnRoot method fn_root.

/**
 * Root operation.
 *
 * @param arg
 *            Result from the expressions evaluation.
 * @param dc
 *            Result of dynamic context operation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:root operation.
 */
public static ResultSequence fn_root(Collection args, EvaluationContext ec) {
    Collection cargs = Function.convert_arguments(args, expected_args());
    if (cargs.size() > 1)
        throw new DynamicError(TypeError.invalid_type(null));
    ResultSequence arg = null;
    if (cargs.isEmpty()) {
        if (ec.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        arg = ResultBuffer.wrap(ec.getContextItem());
    } else {
        arg = (ResultSequence) cargs.iterator().next();
    }
    if (arg.empty()) {
        return ResultBuffer.EMPTY;
    }
    Item aa = arg.item(0);
    if (!(aa instanceof NodeType))
        throw new DynamicError(TypeError.invalid_type(null));
    NodeType nt = (NodeType) aa;
    // ok we got a sane argument... own it.
    Node root = nt.node_value();
    while (root != null && !(root instanceof Document)) {
        Node newroot = root.getParentNode();
        if (newroot == null && root instanceof Attr) {
            newroot = ((Attr) root).getOwnerElement();
        }
        // found it
        if (newroot == null)
            break;
        root = newroot;
    }
    return NodeType.dom_to_xpath(root, ec.getStaticContext().getTypeModel());
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) Collection(java.util.Collection) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 39 with Item

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

the class InternalContextExprTest method test_internalcontextitem_12.

// Evaluation of Internal context item expression where context item used as part of a multiplication operation.
public void test_internalcontextitem_12() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/ContextExpr/InternalContextExpr/internalcontextitem-12.xq";
    String resultFile = "/ExpectedTestResults/Expressions/ContextExpr/InternalContextExpr/internalcontextitem-12.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 40 with Item

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

the class InternalContextExprTest method test_internalcontextitem_16.

// Evaluation of Internal context item expression where context item used as part of a boolean expression (and operator).
public void test_internalcontextitem_16() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Expressions/ContextExpr/InternalContextExpr/internalcontextitem-16.xq";
    String resultFile = "/ExpectedTestResults/Expressions/ContextExpr/InternalContextExpr/internalcontextitem-16.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

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