use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnUnordered method unordered.
/**
* Unordered operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:unordered operation.
*/
public static ResultSequence unordered(Collection args) throws DynamicError {
assert args.size() == 1;
// get args
Iterator citer = args.iterator();
ResultSequence arg = (ResultSequence) citer.next();
if (arg.empty())
return ResultBuffer.EMPTY;
// XXX lame
ArrayList tmp = new ArrayList();
for (Iterator i = arg.iterator(); i.hasNext(); ) tmp.add(i.next());
Collections.shuffle(tmp);
ResultBuffer rb = new ResultBuffer();
for (Iterator i = tmp.iterator(); i.hasNext(); ) rb.add((AnyType) i.next());
return rb.getSequence();
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnInScopePrefixes method createPrefixResultSet.
private static void createPrefixResultSet(ResultBuffer rs, List prefixList) {
for (int i = 0; i < prefixList.size(); i++) {
String prefix = (String) prefixList.get(i);
rs.add(new XSString(prefix));
}
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnIDREF method idref.
/**
* Insert-Before operation.
*
* @param args
* Result from the expressions evaluation.
* @param dc
* @throws DynamicError
* Dynamic error.
* @return Result of fn:insert-before operation.
*/
public static ResultSequence idref(Collection args, EvaluationContext ec) throws DynamicError {
Collection cargs = Function.convert_arguments(args, expected_args());
ResultBuffer rs = new ResultBuffer();
Iterator argIt = cargs.iterator();
ResultSequence idrefRS = (ResultSequence) argIt.next();
String[] idst = idrefRS.first().getStringValue().split(" ");
ArrayList ids = createIDs(idst);
ResultSequence nodeArg = null;
NodeType nodeType = null;
if (argIt.hasNext()) {
nodeArg = (ResultSequence) argIt.next();
nodeType = (NodeType) nodeArg.first();
} else {
if (ec.getContextItem() == null) {
throw DynamicError.contextUndefined();
}
if (!(ec.getContextItem() instanceof NodeType)) {
throw new DynamicError(TypeError.invalid_type(null));
}
nodeType = (NodeType) ec.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 here
throw DynamicError.contextUndefined();
// throw DynamicError.noContextDoc();
}
if (hasID(ids, node)) {
ElementType element = new ElementType((Element) node, ec.getStaticContext().getTypeModel());
rs.add(element);
}
rs = processAttributes(node, ids, rs, ec);
rs = processChildNodes(node, ids, rs, ec);
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnIDREF method processAttributes.
private static ResultBuffer processAttributes(Node node, List idrefs, ResultBuffer rs, EvaluationContext ec) {
if (!node.hasAttributes()) {
return rs;
}
NamedNodeMap attributeList = node.getAttributes();
for (int atsub = 0; atsub < attributeList.getLength(); atsub++) {
Attr atNode = (Attr) attributeList.item(atsub);
NodeType atType = new AttrType(atNode, ec.getStaticContext().getTypeModel());
if (atType.isID()) {
if (hasID(idrefs, atNode)) {
if (!isDuplicate(node, rs)) {
ElementType element = new ElementType((Element) node, ec.getStaticContext().getTypeModel());
rs.add(element);
}
}
}
}
return rs;
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnReverse method reverse.
/**
* Reverse the arguments.
*
* @param args
* are reversed.
* @throws DynamicError
* Dynamic error.
* @return The result of the reversal of the arguments.
*/
public static ResultSequence reverse(Collection args) throws DynamicError {
assert args.size() == 1;
// get args
Iterator citer = args.iterator();
ResultSequence arg = (ResultSequence) citer.next();
if (arg.size() <= 1)
return arg;
ResultBuffer rs = new ResultBuffer();
for (int i = arg.size() - 1; i >= 0; --i) rs.add(arg.item(i));
return rs.getSequence();
}
Aggregations