Search in sources :

Example 31 with DynamicError

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

the class FnEndsWith method ends_with.

/**
 * Ends-with operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:ends-with operation.
 */
public static ResultSequence ends_with(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    // get args
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    String str1 = "";
    String str2 = "";
    if (!arg1.empty())
        str1 = ((XSString) arg1.first()).value();
    ResultSequence arg2 = (ResultSequence) argiter.next();
    if (!arg2.empty())
        str2 = ((XSString) arg2.first()).value();
    int str1len = str1.length();
    int str2len = str2.length();
    if (str1len == 0 && str2len != 0) {
        return XSBoolean.FALSE;
    }
    if (str2len == 0) {
        return XSBoolean.TRUE;
    }
    return XSBoolean.valueOf(str1.endsWith(str2));
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 32 with DynamicError

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

the class FnID method id.

/**
 * Insert-Before operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:insert-before operation.
 */
public static ResultSequence id(Collection args, EvaluationContext context) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultBuffer rs = new ResultBuffer();
    Iterator argIt = cargs.iterator();
    ResultSequence idrefRS = (ResultSequence) argIt.next();
    String[] idrefst = idrefRS.first().getStringValue().split(" ");
    ArrayList idrefs = createIDRefs(idrefst);
    ResultSequence nodeArg = null;
    NodeType nodeType = null;
    if (argIt.hasNext()) {
        nodeArg = (ResultSequence) argIt.next();
        nodeType = (NodeType) nodeArg.first();
    } else {
        if (context.getContextItem() == null) {
            throw DynamicError.contextUndefined();
        }
        if (!(context.getContextItem() instanceof NodeType)) {
            throw new DynamicError(TypeError.invalid_type(null));
        }
        nodeType = (NodeType) context.getContextItem();
        if (nodeType.node_value().getOwnerDocument() == null) {
            throw DynamicError.contextUndefined();
        }
    }
    Node node = nodeType.node_value();
    if (node.getOwnerDocument() == null) {
        // W3C Test suite seems to want XPDY0002
        throw DynamicError.contextUndefined();
    // throw DynamicError.noContextDoc();
    }
    if (hasIDREF(idrefs, node)) {
        ElementType element = new ElementType((Element) node, context.getStaticContext().getTypeModel());
        rs.add(element);
    }
    processAttributes(node, idrefs, rs, context);
    processChildNodes(node, idrefs, rs, context);
    return rs.getSequence();
}
Also used : ElementType(org.eclipse.wst.xml.xpath2.processor.internal.types.ElementType) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) NodeType(org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) DynamicError(org.eclipse.wst.xml.xpath2.processor.DynamicError)

Example 33 with DynamicError

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

the class FnIndexOf method index_of.

/**
 * Index-Of operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @param dynamicContext
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:index-of operation.
 */
public static ResultSequence index_of(Collection args, DynamicContext dc) {
    Function.convert_arguments(args, expected_args());
    // get args
    Iterator citer = args.iterator();
    ResultSequence arg1 = (ResultSequence) citer.next();
    ResultSequence arg2 = (ResultSequence) citer.next();
    if (arg1.empty()) {
        return ResultBuffer.EMPTY;
    }
    // sanity chex
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    String collationUri = dc.getCollationProvider().getDefaultCollation();
    if (citer.hasNext()) {
        ResultSequence arg3 = (ResultSequence) citer.next();
        if (!arg3.empty()) {
            XSString collation = (XSString) arg3.first();
            collationUri = collation.getStringValue();
        }
    }
    ResultBuffer rb = new ResultBuffer();
    AnyAtomicType at = (AnyAtomicType) arg2.first();
    get_comparable(at);
    int index = 1;
    for (Iterator i = arg1.iterator(); i.hasNext(); ) {
        AnyType cmptype = (AnyType) i.next();
        get_comparable(cmptype);
        if (!(at instanceof CmpEq))
            continue;
        if (isBoolean(cmptype, at)) {
            XSBoolean boolat = (XSBoolean) cmptype;
            if (boolat.eq(at, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (isNumeric(cmptype, at)) {
            NumericType numericat = (NumericType) at;
            if (numericat.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (isDuration(cmptype, at)) {
            XSDuration durat = (XSDuration) at;
            if (durat.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (at instanceof QName && cmptype instanceof QName) {
            QName qname = (QName) at;
            if (qname.eq(cmptype, dc)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        } else if (needsStringComparison(cmptype, at)) {
            XSString xstr1 = new XSString(cmptype.getStringValue());
            XSString itemStr = new XSString(at.getStringValue());
            if (FnCompare.compare_string(collationUri, xstr1, itemStr, dc).equals(BigInteger.ZERO)) {
                rb.add(new XSInteger(BigInteger.valueOf(index)));
            }
        }
        index++;
    }
    return rb.getSequence();
}
Also used : NumericType(org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType) XSDuration(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator) AnyAtomicType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 34 with DynamicError

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

the class FnStringJoin method string_join.

/**
 * Join the arguments.
 *
 * @param args
 *            are joined.
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of the arguments being joined together.
 */
public static ResultSequence string_join(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    Iterator argi = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argi.next();
    ResultSequence arg2 = (ResultSequence) argi.next();
    String result = "";
    String separator = ((XSString) arg2.first()).value();
    StringBuffer buf = new StringBuffer();
    for (Iterator i = arg1.iterator(); i.hasNext(); ) {
        XSString item = (XSString) i.next();
        buf.append(item.value());
        if (i.hasNext())
            buf.append(separator);
    }
    result = buf.toString();
    return new XSString(result);
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) Iterator(java.util.Iterator) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 35 with DynamicError

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

the class FnStringToCodepoints method string_to_codepoints.

/**
 * Base-Uri operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:base-uri operation.
 */
public static ResultSequence string_to_codepoints(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty())
        return ResultBuffer.EMPTY;
    XSString xstr = (XSString) arg1.first();
    CodePointIterator cpi = new StringCodePointIterator(xstr.value());
    ResultBuffer rs = new ResultBuffer();
    for (int codePoint = cpi.current(); codePoint != CodePointIterator.DONE; codePoint = cpi.next()) {
        rs.add(new XSInteger(BigInteger.valueOf(codePoint)));
    }
    return rs.getSequence();
}
Also used : ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) CodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.CodePointIterator) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) StringCodePointIterator(org.eclipse.wst.xml.xpath2.processor.internal.utils.StringCodePointIterator)

Aggregations

DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)8211 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)8203 URL (java.net.URL)8194 StaticError (org.eclipse.wst.xml.xpath2.processor.StaticError)8193 XPathParserException (org.eclipse.wst.xml.xpath2.processor.XPathParserException)8193 XSModel (org.apache.xerces.xs.XSModel)8192 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)144 Schema (javax.xml.validation.Schema)100 Collection (java.util.Collection)81 DefaultEvaluator (org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator)72 Evaluator (org.eclipse.wst.xml.xpath2.processor.Evaluator)72 XPath (org.eclipse.wst.xml.xpath2.processor.ast.XPath)72 DynamicContext (org.eclipse.wst.xml.xpath2.processor.DynamicContext)71 Iterator (java.util.Iterator)70 Item (org.eclipse.wst.xml.xpath2.api.Item)68 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)54 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)47 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)25 XSAnyURI (org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI)22 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)20