use of org.apache.xpath.objects.XNodeSet in project j2objc by google.
the class LocPathIterator method asIterator.
/**
* Given an select expression and a context, evaluate the XPath
* and return the resulting iterator.
*
* @param xctxt The execution context.
* @param contextNode The node that "." expresses.
* @throws TransformerException thrown if the active ProblemListener decides
* the error condition is severe enough to halt processing.
*
* @throws javax.xml.transform.TransformerException
* @xsl.usage experimental
*/
public DTMIterator asIterator(XPathContext xctxt, int contextNode) throws javax.xml.transform.TransformerException {
XNodeSet iter = new XNodeSet((LocPathIterator) m_clones.getInstance());
iter.setRoot(contextNode, xctxt);
return iter;
}
use of org.apache.xpath.objects.XNodeSet in project j2objc by google.
the class FilterExprIteratorSimple method executeFilterExpr.
/**
* Execute the expression. Meant for reuse by other FilterExpr iterators
* that are not derived from this object.
*/
public static XNodeSet executeFilterExpr(int context, XPathContext xctxt, PrefixResolver prefixResolver, boolean isTopLevel, int stackFrame, Expression expr) throws org.apache.xml.utils.WrappedRuntimeException {
PrefixResolver savedResolver = xctxt.getNamespaceContext();
XNodeSet result = null;
try {
xctxt.pushCurrentNode(context);
xctxt.setNamespaceContext(prefixResolver);
if (isTopLevel) {
// System.out.println("calling m_expr.execute(getXPathContext())");
VariableStack vars = xctxt.getVarStack();
// These three statements need to be combined into one operation.
int savedStart = vars.getStackFrame();
vars.setStackFrame(stackFrame);
result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
result.setShouldCacheNodes(true);
// These two statements need to be combined into one operation.
vars.setStackFrame(savedStart);
} else
result = (org.apache.xpath.objects.XNodeSet) expr.execute(xctxt);
} catch (javax.xml.transform.TransformerException se) {
// TODO: Fix...
throw new org.apache.xml.utils.WrappedRuntimeException(se);
} finally {
xctxt.popCurrentNode();
xctxt.setNamespaceContext(savedResolver);
}
return result;
}
use of org.apache.xpath.objects.XNodeSet in project j2objc by google.
the class Expression method asIteratorRaw.
/**
* Given an select expression and a context, evaluate the XPath
* and return the resulting iterator, but do not clone.
*
* @param xctxt The execution context.
* @param contextNode The node that "." expresses.
*
*
* @return A valid DTMIterator.
* @throws TransformerException thrown if the active ProblemListener decides
* the error condition is severe enough to halt processing.
*
* @throws javax.xml.transform.TransformerException
* @xsl.usage experimental
*/
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode) throws javax.xml.transform.TransformerException {
try {
xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);
XNodeSet nodeset = (XNodeSet) execute(xctxt);
return nodeset.iterRaw();
} finally {
xctxt.popCurrentNodeAndExpression();
}
}
use of org.apache.xpath.objects.XNodeSet in project j2objc by google.
the class FuncKey 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 {
// TransformerImpl transformer = (TransformerImpl)xctxt;
TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
XNodeSet nodes = null;
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocumentRoot(context);
if (DTM.NULL == docContext) {
// path.error(context, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC); //"context does not have an owner document!");
}
String xkeyname = getArg0().execute(xctxt).str();
QName keyname = new QName(xkeyname, xctxt.getNamespaceContext());
XObject arg = getArg1().execute(xctxt);
boolean argIsNodeSetDTM = (XObject.CLASS_NODESET == arg.getType());
KeyManager kmgr = transformer.getKeyManager();
// Don't bother with nodeset logic if the thing is only one node.
if (argIsNodeSetDTM) {
XNodeSet ns = (XNodeSet) arg;
ns.setShouldCacheNodes(true);
int len = ns.getLength();
if (len <= 1)
argIsNodeSetDTM = false;
}
if (argIsNodeSetDTM) {
Hashtable usedrefs = null;
DTMIterator ni = arg.iter();
int pos;
UnionPathIterator upi = new UnionPathIterator();
upi.exprSetParent(this);
while (DTM.NULL != (pos = ni.nextNode())) {
dtm = xctxt.getDTM(pos);
XMLString ref = dtm.getStringValue(pos);
if (null == ref)
continue;
if (null == usedrefs)
usedrefs = new Hashtable();
if (usedrefs.get(ref) != null) {
// We already have 'em.
continue;
} else {
// ISTRUE being used as a dummy value.
usedrefs.put(ref, ISTRUE);
}
XNodeSet nl = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nl.setRoot(xctxt.getCurrentNode(), xctxt);
// try
// {
upi.addIterator(nl);
// }
// catch(CloneNotSupportedException cnse)
// {
// // will never happen.
// }
//mnodeset.addNodesInDocOrder(nl, xctxt); needed??
}
int current = xctxt.getCurrentNode();
upi.setRoot(current, xctxt);
nodes = new XNodeSet(upi);
} else {
XMLString ref = arg.xstr();
nodes = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
nodes.setRoot(xctxt.getCurrentNode(), xctxt);
}
return nodes;
}
use of org.apache.xpath.objects.XNodeSet in project j2objc by google.
the class KeyTable method addValueInRefsTable.
/**
* Add an association between a ref and a node in the m_refsTable.
* Requires that m_refsTable != null
* @param xctxt XPath context
* @param ref the value of the use clause of the current key for the given node
* @param node the node to reference
*/
private void addValueInRefsTable(XPathContext xctxt, XMLString ref, int node) {
XNodeSet nodes = (XNodeSet) m_refsTable.get(ref);
if (nodes == null) {
nodes = new XNodeSet(node, xctxt.getDTMManager());
nodes.nextNode();
m_refsTable.put(ref, nodes);
} else {
// easily compare node against the current node.
if (nodes.getCurrentNode() != node) {
nodes.mutableNodeset().addNode(node);
nodes.nextNode();
}
}
}
Aggregations