use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.
the class FnDateTime method dateTime.
/**
* Evaluate the function using the arguments passed.
*
* @param args
* Result from the expressions evaluation.
* @param sc
* Result of static context operation.
* @throws DynamicError
* Dynamic error.
* @return Result of the fn:dateTime operation.
*/
public static ResultSequence dateTime(Collection args, StaticContext sc) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
// get args
Iterator argiter = cargs.iterator();
ResultSequence arg1 = (ResultSequence) argiter.next();
ResultSequence arg2 = (ResultSequence) argiter.next();
// is an empty sequence
if (arg1.empty() || arg2.empty()) {
return ResultBuffer.EMPTY;
}
XSDate param1 = (XSDate) arg1.first();
XSTime param2 = (XSTime) arg2.first();
Calendar cal = Calendar.getInstance();
cal.set(param1.year(), param1.month() - 1, param1.day());
cal.set(Calendar.HOUR_OF_DAY, param2.hour());
cal.set(Calendar.MINUTE, param2.minute());
cal.set(Calendar.SECOND, (new Double(Math.floor(param2.second())).intValue()));
cal.set(Calendar.MILLISECOND, 0);
XSDuration dateTimeZone = param1.tz();
XSDuration timeTimeZone = param2.tz();
if ((dateTimeZone != null && timeTimeZone != null) && !dateTimeZone.getStringValue().equals(timeTimeZone.getStringValue())) {
// it's an error, if the arguments have different timezones
throw DynamicError.inconsistentTimeZone();
} else if (dateTimeZone == null && timeTimeZone != null) {
return new XSDateTime(cal, timeTimeZone);
} else if (dateTimeZone != null && timeTimeZone == null) {
return new XSDateTime(cal, dateTimeZone);
} else if ((dateTimeZone != null && timeTimeZone != null) && dateTimeZone.getStringValue().equals(timeTimeZone.getStringValue())) {
return new XSDateTime(cal, dateTimeZone);
} else {
return new XSDateTime(cal, null);
}
}
use of org.eclipse.wst.xml.xpath2.api.ResultSequence 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));
}
use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.
the class FnInScopePrefixes method inScopePrefixes.
/**
* Prefix-from-QName operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:prefix-from-QName operation.
*/
public static ResultSequence inScopePrefixes(Collection args, DynamicContext dc) throws DynamicError {
// Collection cargs = Function.convert_arguments(args, expected_args());
Collection cargs = args;
ResultSequence arg1 = (ResultSequence) cargs.iterator().next();
if (arg1.empty())
return ResultBuffer.EMPTY;
ResultBuffer rs = new ResultBuffer();
Item anytype = arg1.item(0);
if (!(anytype instanceof ElementType)) {
throw new DynamicError(TypeError.invalid_type(null));
}
ElementType element = (ElementType) anytype;
List prefixList = lookupPrefixes(element);
createPrefixResultSet(rs, prefixList);
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.api.ResultSequence 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();
}
use of org.eclipse.wst.xml.xpath2.api.ResultSequence in project webtools.sourceediting by eclipse.
the class FnLang method lang.
/**
* Language operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:lang operation.
*/
public static ResultSequence lang(Collection args, EvaluationContext ec) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
// get arg
Iterator citer = cargs.iterator();
ResultSequence arg1 = (ResultSequence) citer.next();
ResultSequence arg2 = null;
if (cargs.size() == 1) {
if (ec.getContextItem() == null) {
throw DynamicError.contextUndefined();
}
arg2 = (AnyType) ec.getContextItem();
} else {
arg2 = (ResultSequence) citer.next();
}
String lang = "";
if (!arg1.empty()) {
lang = ((XSString) arg1.first()).value();
}
if (!(arg2.first() instanceof NodeType)) {
throw DynamicError.invalidType();
}
NodeType an = (NodeType) arg2.first();
return new XSBoolean(test_lang(an.node_value(), lang));
}
Aggregations