use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class StylesheetRoot method shouldStripWhiteSpace.
/**
* Get information about whether or not an element should strip whitespace.
* @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
*
* @param support The XPath runtime state.
* @param targetElement Element to check
*
* @return true if the whitespace should be stripped.
*
* @throws TransformerException
*/
public boolean shouldStripWhiteSpace(XPathContext support, int targetElement) throws TransformerException {
if (null != m_whiteSpaceInfoList) {
while (DTM.NULL != targetElement) {
DTM dtm = support.getDTM(targetElement);
WhiteSpaceInfo info = (WhiteSpaceInfo) m_whiteSpaceInfoList.getTemplate(support, targetElement, null, false, dtm);
if (null != info)
return info.getShouldStripSpace();
int parent = dtm.getParent(targetElement);
if (DTM.NULL != parent && DTM.ELEMENT_NODE == dtm.getNodeType(parent))
targetElement = parent;
else
targetElement = DTM.NULL;
}
}
return false;
}
use of org.apache.xml.dtm.DTM in project robovm by robovm.
the class Counter method getPreviouslyCounted.
/**
* Construct a counter object.
*
* @param numberElem The owning xsl:number element.
*
* @throws TransformerException
*
Counter(ElemNumber numberElem) throws TransformerException
{
m_numberElem = numberElem;
}*/
/**
* Try and find a node that was previously counted. If found,
* return a positive integer that corresponds to the count.
*
* @param support The XPath context to use
* @param node The node to be counted.
*
* @return The count of the node, or -1 if not found.
*/
int getPreviouslyCounted(XPathContext support, int node) {
int n = m_countNodes.size();
m_countResult = 0;
for (int i = n - 1; i >= 0; i--) {
int countedNode = m_countNodes.elementAt(i);
if (node == countedNode) {
// Since the list is in backwards order, the count is
// how many are in the rest of the list.
m_countResult = i + 1 + m_countNodesStartCount;
break;
}
DTM dtm = support.getDTM(countedNode);
// if it does, don't keep searching backwards.
if (dtm.isNodeAfter(countedNode, node))
break;
}
return m_countResult;
}
use of org.apache.xml.dtm.DTM in project robovm by robovm.
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.xml.dtm.DTM 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.DTM in project robovm by robovm.
the class SerializerUtils method addAttribute.
/**
* Copy an DOM attribute to the created output element, executing
* attribute templates as need be, and processing the xsl:use
* attribute.
*
* @param handler SerializationHandler to which the attributes are added.
* @param attr Attribute node to add to SerializationHandler.
*
* @throws TransformerException
*/
public static void addAttribute(SerializationHandler handler, int attr) throws TransformerException {
TransformerImpl transformer = (TransformerImpl) handler.getTransformer();
DTM dtm = transformer.getXPathContext().getDTM(attr);
if (SerializerUtils.isDefinedNSDecl(handler, attr, dtm))
return;
String ns = dtm.getNamespaceURI(attr);
if (ns == null)
ns = "";
// %OPT% ...can I just store the node handle?
try {
handler.addAttribute(ns, dtm.getLocalName(attr), dtm.getNodeName(attr), "CDATA", dtm.getNodeValue(attr), false);
} catch (SAXException e) {
// do something?
}
}
Aggregations