use of org.apache.xpath.XPathContext in project robovm by robovm.
the class KeyTable method getNodeSetDTMByKey.
/**
* Given a valid element key, return the corresponding node list.
*
* @param name The name of the key, which must match the 'name' attribute on xsl:key.
* @param ref The value that must match the value found by the 'match' attribute on xsl:key.
* @return a set of nodes referenced by the key named <CODE>name</CODE> and the reference <CODE>ref</CODE>. If no node is referenced by this key, an empty node set is returned.
*/
public XNodeSet getNodeSetDTMByKey(QName name, XMLString ref) {
XNodeSet refNodes = (XNodeSet) getRefsTable().get(ref);
// clone wiht reset the node set
try {
if (refNodes != null) {
refNodes = (XNodeSet) refNodes.cloneWithReset();
}
} catch (CloneNotSupportedException e) {
refNodes = null;
}
if (refNodes == null) {
// create an empty XNodeSet
KeyIterator ki = (KeyIterator) (m_keyNodes).getContainedIter();
XPathContext xctxt = ki.getXPathContext();
refNodes = new XNodeSet(xctxt.getDTMManager()) {
public void setRoot(int nodeHandle, Object environment) {
// Root cannot be set on non-iterated node sets. Ignore it.
}
};
refNodes.reset();
}
return refNodes;
}
use of org.apache.xpath.XPathContext in project robovm by robovm.
the class AxesWalker method setRoot.
/**
* Set the root node of the TreeWalker.
* (Not part of the DOM2 TreeWalker interface).
*
* @param root The context node of this step.
*/
public void setRoot(int root) {
// %OPT% Get this directly from the lpi.
XPathContext xctxt = wi().getXPathContext();
m_dtm = xctxt.getDTM(root);
m_traverser = m_dtm.getAxisTraverser(m_axis);
m_isFresh = true;
m_foundLast = false;
m_root = root;
m_currentNode = root;
if (DTM.NULL == root) {
throw new RuntimeException(//"\n !!!! Error! Setting the root of a walker to null!!!");
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_SETTING_WALKER_ROOT_TO_NULL, null));
}
resetProximityPositions();
}
use of org.apache.xpath.XPathContext in project robovm by robovm.
the class NodeSequence method setRoot.
/**
* @see DTMIterator#setRoot(int, Object)
*/
public void setRoot(int nodeHandle, Object environment) {
if (null != m_iter) {
XPathContext xctxt = (XPathContext) environment;
m_dtmMgr = xctxt.getDTMManager();
m_iter.setRoot(nodeHandle, environment);
if (!m_iter.isDocOrdered()) {
if (!hasCache())
setShouldCacheNodes(true);
runTo(-1);
m_next = 0;
}
} else
assertion(false, "Can not setRoot on a non-iterated NodeSequence!");
}
use of org.apache.xpath.XPathContext in project robovm by robovm.
the class OneStepIterator method getProximityPosition.
/**
* Get the current sub-context position. In order to do the
* reverse axes count, for the moment this re-searches the axes
* up to the predicate. An optimization on this is to cache
* the nodes searched, but, for the moment, this case is probably
* rare enough that the added complexity isn't worth it.
*
* @param predicateIndex The predicate index of the proximity position.
*
* @return The pridicate index, or -1.
*/
protected int getProximityPosition(int predicateIndex) {
if (!isReverseAxes())
return super.getProximityPosition(predicateIndex);
// -sb
if (predicateIndex < 0)
return -1;
if (m_proximityPositions[predicateIndex] <= 0) {
XPathContext xctxt = getXPathContext();
try {
OneStepIterator clone = (OneStepIterator) this.clone();
int root = getRoot();
xctxt.pushCurrentNode(root);
clone.setRoot(root, xctxt);
// clone.setPredicateCount(predicateIndex);
clone.m_predCount = predicateIndex;
// Count 'em all
int count = 1;
int next;
while (DTM.NULL != (next = clone.nextNode())) {
count++;
}
m_proximityPositions[predicateIndex] += count;
} catch (CloneNotSupportedException cnse) {
// can't happen
} finally {
xctxt.popCurrentNode();
}
}
return m_proximityPositions[predicateIndex];
}
use of org.apache.xpath.XPathContext in project j2objc by google.
the class UnionChildIterator method acceptNode.
/**
* Test whether a specified node is visible in the logical view of a
* TreeWalker or NodeIterator. This function will be called by the
* implementation of TreeWalker and NodeIterator; it is not intended to
* be called directly from user code.
* @param n The node to check to see if it passes the filter or not.
* @return a constant to determine whether the node is accepted,
* rejected, or skipped, as defined above .
*/
public short acceptNode(int n) {
XPathContext xctxt = getXPathContext();
try {
xctxt.pushCurrentNode(n);
for (int i = 0; i < m_nodeTests.length; i++) {
PredicatedNodeTest pnt = m_nodeTests[i];
XObject score = pnt.execute(xctxt, n);
if (score != NodeTest.SCORE_NONE) {
// Note that we are assuming there are no positional predicates!
if (pnt.getPredicateCount() > 0) {
if (pnt.executePredicates(n, xctxt))
return DTMIterator.FILTER_ACCEPT;
} else
return DTMIterator.FILTER_ACCEPT;
}
}
} catch (javax.xml.transform.TransformerException se) {
// TODO: Fix this.
throw new RuntimeException(se.getMessage());
} finally {
xctxt.popCurrentNode();
}
return DTMIterator.FILTER_SKIP;
}
Aggregations