Search in sources :

Example 11 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnError method evaluate.

/**
 * Evaluate arguments.
 *
 * @param args
 *            argument expressions.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of evaluation.
 */
public ResultSequence evaluate(Collection args, org.eclipse.wst.xml.xpath2.api.EvaluationContext ec) throws DynamicError {
    // Differentiate depending on whether there is one (required) argument or whatever.
    Collection cargs = Function.convert_arguments(args, args.size() == 1 ? expected_args1() : expected_args());
    QName code = null;
    ResultSequence items = null;
    String description = null;
    // Iterate over the args
    Iterator it = cargs.iterator();
    if (it.hasNext()) {
        ResultSequence rsQName = (ResultSequence) it.next();
        // for arity 2 and 3, the code is not mandatory, as in fn:code((), "description). Handle this:
        if (!rsQName.empty())
            code = (QName) rsQName.first();
    }
    // Next arg (if present) is the description
    if (it.hasNext()) {
        ResultSequence rsDescription = (ResultSequence) it.next();
        description = ((XSString) rsDescription.first()).value();
    }
    // Final arg (if present) is the list of items
    if (it.hasNext()) {
        items = (ResultSequence) it.next();
    }
    // Handle the code if missing
    if (code == null)
        code = new QName("err", "FOER0000", "http://www.w3.org/2005/xqt-errors");
    return error(code, description, items);
}
Also used : QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) 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)

Example 12 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnError method expected_args.

/**
 * Obtain a list of expected arguments.
 *
 * @return Result of operation.
 */
public static synchronized Collection expected_args() {
    if (_expected_args == null) {
        _expected_args = new ArrayList();
        _expected_args.add(new SeqType(new QName(), SeqType.OCC_QMARK));
        _expected_args.add(new SeqType(new XSString(), SeqType.OCC_NONE));
        _expected_args.add(new SeqType(AnyType.class, SeqType.OCC_STAR));
    }
    return _expected_args;
}
Also used : SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) ArrayList(java.util.ArrayList) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)

Example 13 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnMatches method matches.

/**
 * Matches operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:matches operation.
 */
public static ResultSequence matches(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 = "";
    if (!arg1.empty()) {
        str1 = ((XSString) arg1.first()).value();
    }
    ResultSequence arg2 = (ResultSequence) argiter.next();
    String pattern = ((XSString) arg2.first()).value();
    String flags = null;
    if (argiter.hasNext()) {
        ResultSequence flagRS = null;
        flagRS = (ResultSequence) argiter.next();
        flags = flagRS.first().getStringValue();
        if (validflags.indexOf(flags) == -1 && flags.length() > 0) {
            throw DynamicError.regex_flags_error(null);
        }
    }
    try {
        boolean result = false;
        result = matches(pattern, flags, str1);
        return XSBoolean.valueOf(result);
    } catch (PatternSyntaxException pex) {
        throw DynamicError.regex_error(pex.getMessage());
    }
}
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) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 14 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString in project webtools.sourceediting by eclipse.

the class FnNormalizeSpace method expected_args.

/**
 * Calculate the expected arguments.
 *
 * @return The expected arguments.
 */
public static synchronized Collection expected_args() {
    if (_expected_args == null) {
        _expected_args = new ArrayList();
        _expected_args.add(new SeqType(new XSString(), SeqType.OCC_QMARK));
    }
    return _expected_args;
}
Also used : SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) ArrayList(java.util.ArrayList) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 15 with XSString

use of org.eclipse.wst.xml.xpath2.processor.internal.types.XSString 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)

Aggregations

XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)73 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)37 ArrayList (java.util.ArrayList)32 Collection (java.util.Collection)32 Iterator (java.util.Iterator)29 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)29 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)9 Item (org.eclipse.wst.xml.xpath2.api.Item)7 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)7 AnyType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType)6 XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)6 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)5 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)5 NumericType (org.eclipse.wst.xml.xpath2.processor.internal.types.NumericType)5 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)5 XSDouble (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDouble)5 DynamicError (org.eclipse.wst.xml.xpath2.processor.DynamicError)4 XSUntypedAtomic (org.eclipse.wst.xml.xpath2.processor.internal.types.XSUntypedAtomic)4 URL (java.net.URL)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3