use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class AttributeAxis method iterate.
/**
* Retrieves the context node's attributes.
*
* @param node
* is the type of node.
*/
public void iterate(NodeType node, ResultBuffer copyInto, Node limitNode) {
// only elements have attributes
if (!(node instanceof ElementType))
return;
// get attributes
ElementType elem = (ElementType) node;
NamedNodeMap attrs = elem.value().getAttributes();
// add attributes
for (int i = 0; i < attrs.getLength(); i++) {
Attr attr = (Attr) attrs.item(i);
copyInto.add(NodeType.dom_to_xpath(attr, node.getTypeModel()));
}
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class ChildAxis method addChildren.
protected void addChildren(NodeType node, ResultBuffer copyInto, boolean recurse) {
NodeList nl = null;
// only document and element nodes have children
if (node instanceof DocType) {
nl = ((DocType) node).value().getChildNodes();
}
if (node instanceof ElementType)
nl = ((ElementType) node).value().getChildNodes();
// add the children to the result
if (nl != null) {
for (int i = 0; i < nl.getLength(); i++) {
Node dnode = nl.item(i);
NodeType n = NodeType.dom_to_xpath(dnode, node.getTypeModel());
if (n != null) {
copyInto.add(n);
if (recurse)
addChildren(n, copyInto, recurse);
}
}
}
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FollowingAxis method iterate.
/**
* Return the result of FollowingAxis expression
*
* @param node
* is the type of node.
*/
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);
// get the following siblings of this node, and add them
FollowingSiblingAxis fsa = new FollowingSiblingAxis();
ResultBuffer siblingBuffer = new ResultBuffer();
fsa.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);
}
// and add the results
if (parent != null) {
iterate(parent, result, limitNode);
}
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class ParentAxis method iterate.
/**
* returns parent accessors 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) {
Node n = node.node_value();
if (limitNode != null && limitNode.isSameNode(n)) {
// no further, we have reached the limit node
return;
}
Node parent = findParent(n);
// if a parent exists... add it
if (parent != null) {
NodeType nodeType = NodeType.dom_to_xpath(parent, node.getTypeModel());
if (nodeType != null) {
copyInto.add(nodeType);
}
}
}
use of org.eclipse.wst.xml.xpath2.api.ResultBuffer in project webtools.sourceediting by eclipse.
the class FnSubsequence method subsequence.
/**
* Subsequence operation.
*
* @param args
* Result from the expressions evaluation.
* @throws DynamicError
* Dynamic error.
* @return Result of fn:subsequence operation.
*/
public static ResultSequence subsequence(Collection args) throws DynamicError {
ResultBuffer rs = new ResultBuffer();
// get args
Iterator citer = args.iterator();
ResultSequence seq = (ResultSequence) citer.next();
if (seq.empty())
return ResultBuffer.EMPTY;
ResultSequence startLoc = (ResultSequence) citer.next();
ResultSequence length = null;
if (citer.hasNext()) {
length = (ResultSequence) citer.next();
}
Item at = startLoc.first();
if (!(at instanceof NumericType)) {
DynamicError.throw_type_error();
}
at = new XSDouble(at.getStringValue());
int start = (int) ((XSDouble) at).double_value();
// no of items beyond index >= 1 that are added to the result
int effectiveNoItems = 0;
if (length != null) {
// the 3rd argument is present
if (length.size() != 1)
DynamicError.throw_type_error();
at = length.first();
if (!(at instanceof NumericType)) {
DynamicError.throw_type_error();
}
at = new XSDouble(at.getStringValue());
int len = (int) ((XSDouble) at).double_value();
if (len < 0) {
DynamicError.throw_type_error();
}
if (start <= 0) {
effectiveNoItems = start + len - 1;
start = 1;
} else {
effectiveNoItems = len;
}
} else {
// 3rd argument is absent
if (start <= 0) {
start = 1;
effectiveNoItems = seq.size();
} else {
effectiveNoItems = seq.size() - start + 1;
}
}
// index running parallel to the iterator
int pos = 1;
int addedItems = 0;
if (effectiveNoItems > 0) {
for (Iterator seqIter = seq.iterator(); seqIter.hasNext(); ) {
at = (AnyType) seqIter.next();
if (start <= pos && addedItems < effectiveNoItems) {
rs.add(at);
addedItems++;
}
pos++;
}
}
return rs.getSequence();
}
Aggregations