Search in sources :

Example 1 with XSInteger

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

the class FnCodepointsToString method codepoints_to_string.

/**
 * Codepoints to string operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:codepoints-to-string operation.
 */
public static ResultSequence codepoints_to_string(Collection args) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
    if (arg1.empty()) {
        return new XSString("");
    }
    int[] codePointArray = new int[arg1.size()];
    int codePointIndex = 0;
    for (Iterator i = arg1.iterator(); i.hasNext(); ) {
        XSInteger code = (XSInteger) i.next();
        int codepoint = code.int_value().intValue();
        if (codepoint < MIN_LEGAL_CODEPOINT || codepoint > MAX_LEGAL_CODEPOINT) {
            throw DynamicError.unsupported_codepoint("U+" + Integer.toString(codepoint, 16).toUpperCase());
        }
        codePointArray[codePointIndex] = codepoint;
        codePointIndex++;
    }
    try {
        String str = UTF16.newString(codePointArray, 0, codePointArray.length);
        return new XSString(str);
    } catch (IllegalArgumentException iae) {
        // This should be duoble checked above, but rather safe than sorry
        throw DynamicError.unsupported_codepoint(iae.getMessage());
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) 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 2 with XSInteger

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

the class FnCodepointsToString 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 XSInteger(), SeqType.OCC_STAR));
    }
    return _expected_args;
}
Also used : SeqType(org.eclipse.wst.xml.xpath2.processor.internal.SeqType) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) ArrayList(java.util.ArrayList)

Example 3 with XSInteger

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

the class FnCompare method compare.

/**
 * Compare the arguments.
 *
 * @param args
 *            are compared (optional 3rd argument is the collation)
 * @param dynamicContext
 * 	       Current dynamic context
 * @throws DynamicError
 *             Dynamic error.
 * @return The result of the comparison of the arguments.
 */
public static ResultSequence compare(Collection args, DynamicContext context) throws DynamicError {
    Collection cargs = Function.convert_arguments(args, expected_args());
    Iterator argiter = cargs.iterator();
    ResultSequence arg1 = (ResultSequence) argiter.next();
    ResultSequence arg2 = (ResultSequence) argiter.next();
    String collationUri = context.getCollationProvider().getDefaultCollation();
    if (argiter.hasNext()) {
        ResultSequence collArg = (ResultSequence) argiter.next();
        collationUri = collArg.first().getStringValue();
    }
    XSString xstr1 = arg1.empty() ? null : (XSString) arg1.first();
    XSString xstr2 = arg2.empty() ? null : (XSString) arg2.first();
    BigInteger result = compare_string(collationUri, xstr1, xstr2, context);
    if (result != null) {
        return ResultSequenceFactory.create_new(new XSInteger(result));
    } else {
        return ResultSequenceFactory.create_new();
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator) Collection(java.util.Collection) BigInteger(java.math.BigInteger) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString) XSString(org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)

Example 4 with XSInteger

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

the class FnDayFromDateTime method day_from_date_time.

/**
 * Day-From-DateTime operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:day-from-datetime operation.
 */
public static ResultSequence day_from_date_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;
    }
    XSDateTime dt = (XSDateTime) arg1.first();
    int res = dt.day();
    return new XSInteger(BigInteger.valueOf(res));
}
Also used : XSDateTime(org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Collection(java.util.Collection)

Example 5 with XSInteger

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

the class FnInsertBefore method insert_before.

/**
 * Insert-Before operation.
 *
 * @param args
 *            Result from the expressions evaluation.
 * @throws DynamicError
 *             Dynamic error.
 * @return Result of fn:insert-before operation.
 */
public static ResultSequence insert_before(Collection args) throws DynamicError {
    assert args.size() == 3;
    ResultBuffer rs = new ResultBuffer();
    // get args
    Iterator citer = args.iterator();
    ResultSequence target = (ResultSequence) citer.next();
    ResultSequence arg2 = (ResultSequence) citer.next();
    ResultSequence inserts = (ResultSequence) citer.next();
    // sanity chex
    if (arg2.size() != 1)
        DynamicError.throw_type_error();
    Item at = arg2.first();
    if (!(at instanceof XSInteger))
        DynamicError.throw_type_error();
    // XXX cloning!
    if (target.empty())
        return inserts;
    if (inserts.empty())
        return target;
    int position = ((XSInteger) at).int_value().intValue();
    if (position < 1)
        position = 1;
    int target_size = target.size();
    if (position > target_size)
        position = target_size + 1;
    int curpos = 1;
    for (Iterator i = target.iterator(); i.hasNext(); ) {
        at = (AnyType) i.next();
        if (curpos == position)
            rs.concat(inserts);
        rs.add(at);
        curpos++;
    }
    if (curpos == position)
        rs.concat(inserts);
    return rs.getSequence();
}
Also used : Item(org.eclipse.wst.xml.xpath2.api.Item) ResultBuffer(org.eclipse.wst.xml.xpath2.api.ResultBuffer) ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) XSInteger(org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger) Iterator(java.util.Iterator)

Aggregations

XSInteger (org.eclipse.wst.xml.xpath2.processor.internal.types.XSInteger)34 ResultSequence (org.eclipse.wst.xml.xpath2.api.ResultSequence)32 Collection (java.util.Collection)20 XSString (org.eclipse.wst.xml.xpath2.processor.internal.types.XSString)12 Iterator (java.util.Iterator)8 ResultSequence (org.eclipse.wst.xml.xpath2.processor.ResultSequence)8 XSDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration)6 URL (java.net.URL)5 XSModel (org.apache.xerces.xs.XSModel)5 Item (org.eclipse.wst.xml.xpath2.api.Item)5 XSDateTime (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDateTime)5 ResultBuffer (org.eclipse.wst.xml.xpath2.api.ResultBuffer)4 BigInteger (java.math.BigInteger)3 XSBoolean (org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean)3 XSDate (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDate)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 SeqType (org.eclipse.wst.xml.xpath2.processor.internal.SeqType)2 AnyAtomicType (org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType)2 XSTime (org.eclipse.wst.xml.xpath2.processor.internal.types.XSTime)2