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));
}
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();
}
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();
}
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);
}
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();
}
Aggregations