use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnDistinctValues method distinct_values.
/**
* Distinct-values operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:distinct-values operation.
*/
public static ResultSequence distinct_values(Collection args, DynamicContext context) throws DynamicError {
ResultBuffer rs = new ResultBuffer();
// get args
Iterator citer = args.iterator();
ResultSequence arg1 = (ResultSequence) citer.next();
ResultSequence arg2 = ResultBuffer.EMPTY;
if (citer.hasNext()) {
arg2 = (ResultSequence) citer.next();
}
String collationURI = context.getCollationProvider().getDefaultCollation();
if (!arg2.empty()) {
XSString collation = (XSString) arg2.item(0);
collationURI = collation.getStringValue();
}
for (Iterator iter = arg1.iterator(); iter.hasNext(); ) {
AnyAtomicType atomizedItem = (AnyAtomicType) FnData.atomize((Item) iter.next());
if (!contains(rs, atomizedItem, context, collationURI))
rs.add(atomizedItem);
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnID method processChildNodes.
private static void processChildNodes(Node node, List idrefs, ResultBuffer rs, EvaluationContext context) {
if (!node.hasChildNodes()) {
return;
}
NodeList nodeList = node.getChildNodes();
for (int nodecnt = 0; nodecnt < nodeList.getLength(); nodecnt++) {
Node childNode = nodeList.item(nodecnt);
if (childNode.getNodeType() == Node.ELEMENT_NODE && !isDuplicate(childNode, rs)) {
ElementType element = new ElementType((Element) childNode, context.getStaticContext().getTypeModel());
if (element.isID()) {
if (hasIDREF(idrefs, childNode)) {
rs.add(element);
}
}
processAttributes(childNode, idrefs, rs, context);
processChildNodes(childNode, idrefs, rs, context);
}
}
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer 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.api.ResultBuffer 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.api.ResultBuffer 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