use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnRemove method remove.
/**
* Remove operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:remove operation.
*/
public static ResultSequence remove(Collection args) throws DynamicError {
assert args.size() == 2;
ResultBuffer rs = new ResultBuffer();
// get args
Iterator citer = args.iterator();
ResultSequence target = (ResultSequence) citer.next();
ResultSequence arg2 = (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();
int position = ((XSInteger) at).int_value().intValue();
if (position < 1)
return target;
if (position > target.size())
return target;
if (target.empty())
return rs.getSequence();
int curpos = 1;
for (Iterator i = target.iterator(); i.hasNext(); ) {
at = (AnyType) i.next();
if (curpos != position)
rs.add(at);
curpos++;
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnCollection method getCollection.
private static ResultSequence getCollection(String uri, EvaluationContext ec) {
ResultBuffer rs = new ResultBuffer();
Map /*<String, List<Document>>*/
collectionMap = ec.getDynamicContext().getCollections();
List /*<Document>*/
docList = (List) collectionMap.get(uri);
for (int i = 0; i < docList.size(); i++) {
Document doc = (Document) docList.get(i);
rs.add(new DocType(doc, ec.getStaticContext().getTypeModel()));
}
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class PrecedingAxis method iterate.
// XXX DOCUMENT ORDER.... dunno
/**
* returns preceding nodes of the context node
*
* @param node
* is the node type.
* @throws dc
* is the Dynamic context.
*/
public void iterate(NodeType node, ResultBuffer result, Node limitNode) {
if (limitNode != null && limitNode.isSameNode(node.node_value())) {
// no further, we have reached the limit node
return;
}
// get the parent
NodeType parent = null;
ResultBuffer parentBuffer = new ResultBuffer();
new ParentAxis().iterate(node, parentBuffer, limitNode);
if (parentBuffer.size() == 1) {
parent = (NodeType) parentBuffer.item(0);
// if we got a parent, we gotta repeat the story for the parent
// and add the results
iterate(parent, result, limitNode);
}
// get the following siblings of this node, and add them
PrecedingSiblingAxis psa = new PrecedingSiblingAxis();
ResultBuffer siblingBuffer = new ResultBuffer();
psa.iterate(node, siblingBuffer, limitNode);
// for each sibling, get all its descendants
DescendantAxis da = new DescendantAxis();
for (Iterator i = siblingBuffer.iterator(); i.hasNext(); ) {
result.add((NodeType) i);
da.iterate((NodeType) i.next(), result, null);
}
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class PrecedingSiblingAxis method iterate.
// XXX again, unify with following
/**
* returns preceding nodes of the context node
*
* @param node
* is the node type.
* @throws dc
* is the Dynamic context.
*/
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
// XXX check for attribute / namespace node... if so return
// empty sequence
int pos = copyInto.size();
Node iterNode = node.node_value();
// get the children of the parent [siblings]
do {
iterNode = iterNode.getPreviousSibling();
if (iterNode != null) {
NodeType nodeType = NodeType.dom_to_xpath(iterNode, node.getTypeModel());
if (nodeType != null) {
copyInto.addAt(pos, nodeType);
}
}
} while (iterNode != null);
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnString method string.
/**
* String operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:string operation.
*/
public static ResultSequence string(Collection args, EvaluationContext ec) throws DynamicError {
assert (args.size() == 0 || args.size() == 1);
ResultSequence arg1 = null;
if (args.isEmpty()) {
// support for arity = 0
return getResultSetForArityZero(ec);
} else {
arg1 = (ResultSequence) args.iterator().next();
}
// sanity check args
if (arg1.size() > 1)
throw new DynamicError(TypeError.invalid_type(null));
ResultBuffer rs = new ResultBuffer();
if (arg1.empty()) {
rs.add(new XSString(""));
} else {
Item at = arg1.first();
rs.add(new XSString(at.getStringValue()));
}
return rs.getSequence();
}
Aggregations