use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.
the class ElemForEach method transformSelectedNodes.
/**
* Perform a query if needed, and call transformNode for each child.
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException Thrown in a variety of circumstances.
* @xsl.usage advanced
*/
public void transformSelectedNodes(TransformerImpl transformer) throws TransformerException {
final XPathContext xctxt = transformer.getXPathContext();
final int sourceNode = xctxt.getCurrentNode();
DTMIterator sourceNodes = m_selectExpression.asIterator(xctxt, sourceNode);
try {
final Vector keys = (m_sortElems == null) ? null : transformer.processSortKeys(this, sourceNode);
// Sort if we need to.
if (null != keys)
sourceNodes = sortNodes(xctxt, keys, sourceNodes);
xctxt.pushCurrentNode(DTM.NULL);
IntStack currentNodes = xctxt.getCurrentNodeStack();
xctxt.pushCurrentExpressionNode(DTM.NULL);
IntStack currentExpressionNodes = xctxt.getCurrentExpressionNodeStack();
xctxt.pushSAXLocatorNull();
xctxt.pushContextNodeList(sourceNodes);
transformer.pushElemTemplateElement(null);
// pushParams(transformer, xctxt);
// Should be able to get this from the iterator but there must be a bug.
DTM dtm = xctxt.getDTM(sourceNode);
int docID = sourceNode & DTMManager.IDENT_DTM_DEFAULT;
int child;
while (DTM.NULL != (child = sourceNodes.nextNode())) {
currentNodes.setTop(child);
currentExpressionNodes.setTop(child);
if ((child & DTMManager.IDENT_DTM_DEFAULT) != docID) {
dtm = xctxt.getDTM(child);
docID = child & DTMManager.IDENT_DTM_DEFAULT;
}
//final int exNodeType = dtm.getExpandedTypeID(child);
final int nodeType = dtm.getNodeType(child);
// each of them.
for (ElemTemplateElement t = this.m_firstChild; t != null; t = t.m_nextSibling) {
xctxt.setSAXLocator(t);
transformer.setCurrentElement(t);
t.execute(transformer);
}
// FuncDocument and here.
if (m_doc_cache_off) {
if (DEBUG)
System.out.println("JJK***** CACHE RELEASE *****\n" + "\tdtm=" + dtm.getDocumentBaseURI());
// NOTE: This will work because this is _NOT_ a shared DTM, and thus has
// only a single Document node. If it could ever be an RTF or other
// shared DTM, this would require substantial rework.
xctxt.getSourceTreeManager().removeDocumentFromCache(dtm.getDocument());
xctxt.release(dtm, false);
}
}
} finally {
xctxt.popSAXLocator();
xctxt.popContextNodeList();
transformer.popElemTemplateElement();
xctxt.popCurrentExpressionNode();
xctxt.popCurrentNode();
sourceNodes.detach();
}
}
use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.
the class XObjectFactory method create.
/**
* Create the right XObject based on the type of the object passed.
* This function <emph>can</emph> make an XObject that exposes DOM Nodes, NodeLists, and
* NodeIterators to the XSLT stylesheet as node-sets.
*
* @param val The java object which this object will wrap.
* @param xctxt The XPath context.
*
* @return the right XObject based on the type of the object passed.
*/
public static XObject create(Object val, XPathContext xctxt) {
XObject result;
if (val instanceof XObject) {
result = (XObject) val;
} else if (val instanceof String) {
result = new XString((String) val);
} else if (val instanceof Boolean) {
result = new XBoolean((Boolean) val);
} else if (val instanceof Number) {
result = new XNumber(((Number) val));
} else if (val instanceof DTM) {
DTM dtm = (DTM) val;
try {
int dtmRoot = dtm.getDocument();
DTMAxisIterator iter = dtm.getAxisIterator(Axis.SELF);
iter.setStartNode(dtmRoot);
DTMIterator iterator = new OneStepIterator(iter, Axis.SELF);
iterator.setRoot(dtmRoot, xctxt);
result = new XNodeSet(iterator);
} catch (Exception ex) {
throw new org.apache.xml.utils.WrappedRuntimeException(ex);
}
} else if (val instanceof DTMAxisIterator) {
DTMAxisIterator iter = (DTMAxisIterator) val;
try {
DTMIterator iterator = new OneStepIterator(iter, Axis.SELF);
iterator.setRoot(iter.getStartNode(), xctxt);
result = new XNodeSet(iterator);
} catch (Exception ex) {
throw new org.apache.xml.utils.WrappedRuntimeException(ex);
}
} else if (val instanceof DTMIterator) {
result = new XNodeSet((DTMIterator) val);
} else // might also implement a Node!
if (val instanceof org.w3c.dom.Node) {
result = new XNodeSetForDOM((org.w3c.dom.Node) val, xctxt);
} else // also implement NodeList.
if (val instanceof org.w3c.dom.NodeList) {
result = new XNodeSetForDOM((org.w3c.dom.NodeList) val, xctxt);
} else if (val instanceof org.w3c.dom.traversal.NodeIterator) {
result = new XNodeSetForDOM((org.w3c.dom.traversal.NodeIterator) val, xctxt);
} else {
result = new XObject(val);
}
return result;
}
use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.
the class UnionPathIterator method setRoot.
/**
* Initialize the context values for this expression
* after it is cloned.
*
* @param context The XPath runtime context for this
* transformation.
*/
public void setRoot(int context, Object environment) {
super.setRoot(context, environment);
try {
if (null != m_exprs) {
int n = m_exprs.length;
DTMIterator[] newIters = new DTMIterator[n];
for (int i = 0; i < n; i++) {
DTMIterator iter = m_exprs[i].asIterator(m_execContext, context);
newIters[i] = iter;
iter.nextNode();
}
m_iterators = newIters;
}
} catch (Exception e) {
throw new org.apache.xml.utils.WrappedRuntimeException(e);
}
}
use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.
the class FunctionPattern method execute.
/**
* Test a node to see if it matches the given node test.
*
* @param xctxt XPath runtime context.
*
* @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt, int context, DTM dtm, int expType) throws javax.xml.transform.TransformerException {
DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
XNumber score = SCORE_NONE;
if (null != nl) {
int n;
while (DTM.NULL != (n = nl.nextNode())) {
score = (n == context) ? SCORE_OTHER : SCORE_NONE;
if (score == SCORE_OTHER) {
context = n;
break;
}
}
nl.detach();
}
return score;
}
use of org.apache.xml.dtm.DTMIterator in project robovm by robovm.
the class FunctionPattern method execute.
/**
* Test a node to see if it matches the given node test.
*
* @param xctxt XPath runtime context.
*
* @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
* {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
* {@link org.apache.xpath.patterns.NodeTest#SCORE_OTHER}.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt, int context) throws javax.xml.transform.TransformerException {
DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
XNumber score = SCORE_NONE;
if (null != nl) {
int n;
while (DTM.NULL != (n = nl.nextNode())) {
score = (n == context) ? SCORE_OTHER : SCORE_NONE;
if (score == SCORE_OTHER) {
context = n;
break;
}
}
// nl.detach();
}
nl.detach();
return score;
}
Aggregations