use of org.apache.xpath.NodeSetDTM in project j2objc by google.
the class NotEqualComparator method mutableNodeset.
/**
* Cast result object to a mutableNodeset.
*
* @return The nodeset as a mutableNodeset
*/
public NodeSetDTM mutableNodeset() {
NodeSetDTM mnl;
if (m_obj instanceof NodeSetDTM) {
mnl = (NodeSetDTM) m_obj;
} else {
mnl = new NodeSetDTM(iter());
setObject(mnl);
setCurrentPos(0);
}
return mnl;
}
use of org.apache.xpath.NodeSetDTM in project j2objc by google.
the class FuncId method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocument();
if (DTM.NULL == docContext)
error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
XObject arg = m_arg0.execute(xctxt);
int argType = arg.getType();
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
NodeSetDTM nodeSet = nodes.mutableNodeset();
if (XObject.CLASS_NODESET == argType) {
DTMIterator ni = arg.iter();
StringVector usedrefs = null;
int pos = ni.nextNode();
while (DTM.NULL != pos) {
DTM ndtm = ni.getDTM(pos);
String refval = ndtm.getStringValue(pos).toString();
pos = ni.nextNode();
usedrefs = getNodesByID(xctxt, docContext, refval, usedrefs, nodeSet, DTM.NULL != pos);
}
// ni.detach();
} else if (XObject.CLASS_NULL == argType) {
return nodes;
} else {
String refval = arg.str();
getNodesByID(xctxt, docContext, refval, null, nodeSet, false);
}
return nodes;
}
use of org.apache.xpath.NodeSetDTM in project j2objc by google.
the class NodeSequence method getLength.
/**
* @see DTMIterator#getLength()
*/
public int getLength() {
IteratorCache cache = getCache();
if (cache != null) {
// Nodes from the iterator are cached
if (cache.isComplete()) {
// All of the nodes from the iterator are cached
// so just return the number of nodes in the cache
NodeVector nv = cache.getVector();
return nv.size();
}
// it has been mutated...
if (m_iter instanceof NodeSetDTM) {
return m_iter.getLength();
}
if (-1 == m_last) {
int pos = m_next;
runTo(-1);
m_next = pos;
}
return m_last;
} else {
return (-1 == m_last) ? (m_last = m_iter.getLength()) : m_last;
}
}
use of org.apache.xpath.NodeSetDTM in project robovm by robovm.
the class NodeSequence method addNodeInDocOrder.
/**
* Add the node into a vector of nodes where it should occur in
* document order.
* @param node The node to be added.
* @return insertIndex.
* @throws RuntimeException thrown if this NodeSetDTM is not of
* a mutable type.
*/
protected int addNodeInDocOrder(int node) {
assertion(hasCache(), "addNodeInDocOrder must be done on a mutable sequence!");
int insertIndex = -1;
NodeVector vec = getVector();
// This needs to do a binary search, but a binary search
// is somewhat tough because the sequence test involves
// two nodes.
int size = vec.size(), i;
for (i = size - 1; i >= 0; i--) {
int child = vec.elementAt(i);
if (child == node) {
// Duplicate, suppress insert
i = -2;
break;
}
DTM dtm = m_dtmMgr.getDTM(node);
if (!dtm.isNodeAfter(node, child)) {
break;
}
}
if (i != -2) {
insertIndex = i + 1;
vec.insertElementAt(node, insertIndex);
}
// checkDups();
return insertIndex;
}
use of org.apache.xpath.NodeSetDTM in project robovm by robovm.
the class CountersTable method countNode.
/**
* Count forward until the given node is found, or until
* we have looked to the given amount.
*
* @param support The XPath context to use
* @param numberElem The given xsl:number element.
* @param node The node to count.
*
* @return The node count, or 0 if not found.
*
* @throws TransformerException
*/
public int countNode(XPathContext support, ElemNumber numberElem, int node) throws TransformerException {
int count = 0;
Vector counters = getCounters(numberElem);
int nCounters = counters.size();
// XPath countMatchPattern = numberElem.getCountMatchPattern(support, node);
// XPath fromMatchPattern = numberElem.m_fromMatchPattern;
int target = numberElem.getTargetNode(support, node);
if (DTM.NULL != target) {
for (int i = 0; i < nCounters; i++) {
Counter counter = (Counter) counters.elementAt(i);
count = counter.getPreviouslyCounted(support, target);
if (count > 0)
return count;
}
// In the loop below, we collect the nodes in backwards doc order, so
// we don't have to do inserts, but then we store the nodes in forwards
// document order, so we don't have to insert nodes into that list,
// so that's what the appendBtoFList stuff is all about. In cases
// of forward counting by one, this will mean a single node copy from
// the backwards list (m_newFound) to the forwards list (counter.m_countNodes).
count = 0;
if (m_newFound == null)
m_newFound = new NodeSetDTM(support.getDTMManager());
for (; DTM.NULL != target; target = numberElem.getPreviousNode(support, target)) {
// block above.
if (0 != count) {
for (int i = 0; i < nCounters; i++) {
Counter counter = (Counter) counters.elementAt(i);
int cacheLen = counter.m_countNodes.size();
if ((cacheLen > 0) && (counter.m_countNodes.elementAt(cacheLen - 1) == target)) {
count += (cacheLen + counter.m_countNodesStartCount);
if (cacheLen > 0)
appendBtoFList(counter.m_countNodes, m_newFound);
m_newFound.removeAllElements();
return count;
}
}
}
m_newFound.addElement(target);
count++;
}
// If we got to this point, then we didn't find a counter, so make
// one and add it to the list.
Counter counter = new Counter(numberElem, new NodeSetDTM(support.getDTMManager()));
// for diagnostics
m_countersMade++;
appendBtoFList(counter.m_countNodes, m_newFound);
m_newFound.removeAllElements();
counters.addElement(counter);
}
return count;
}
Aggregations