use of org.apache.xpath.XPathContext in project robovm by robovm.
the class ElemCallTemplate method execute.
/**
* Invoke a named template.
* @see <a href="http://www.w3.org/TR/xslt#named-templates">named-templates in XSLT Specification</a>
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
if (null != m_template) {
XPathContext xctxt = transformer.getXPathContext();
VariableStack vars = xctxt.getVarStack();
int thisframe = vars.getStackFrame();
int nextFrame = vars.link(m_template.m_frameSize);
// so that the default param evaluation will work correctly.
if (m_template.m_inArgsSize > 0) {
vars.clearLocalSlots(0, m_template.m_inArgsSize);
if (null != m_paramElems) {
int currentNode = xctxt.getCurrentNode();
vars.setStackFrame(thisframe);
int size = m_paramElems.length;
for (int i = 0; i < size; i++) {
ElemWithParam ewp = m_paramElems[i];
if (ewp.m_index >= 0) {
XObject obj = ewp.getValue(transformer, currentNode);
// Note here that the index for ElemWithParam must have been
// statically made relative to the xsl:template being called,
// NOT this xsl:template.
vars.setLocalVariable(ewp.m_index, obj, nextFrame);
}
}
vars.setStackFrame(nextFrame);
}
}
SourceLocator savedLocator = xctxt.getSAXLocator();
try {
xctxt.setSAXLocator(m_template);
// template.executeChildTemplates(transformer, sourceNode, mode, true);
transformer.pushElemTemplateElement(m_template);
m_template.execute(transformer);
} finally {
transformer.popElemTemplateElement();
xctxt.setSAXLocator(savedLocator);
// When we entered this function, the current
// frame buffer (cfb) index in the variable stack may
// have been manually set. If we just call
// unlink(), however, it will restore the cfb to the
// previous link index from the link stack, rather than
// the manually set cfb. So,
// the only safe solution is to restore it back
// to the same position it was on entry, since we're
// really not working in a stack context here. (Bug4218)
vars.unlink(thisframe);
}
} else {
transformer.getMsgMgr().error(this, XSLTErrorResources.ER_TEMPLATE_NOT_FOUND, //"Could not find template named: '"+templateName+"'");
new Object[] { m_templateName });
}
}
use of org.apache.xpath.XPathContext in project robovm by robovm.
the class ElemElement method execute.
/**
* Create an element in the result tree.
* The xsl:element element allows an element to be created with a
* computed name. The expanded-name of the element to be created
* is specified by a required name attribute and an optional namespace
* attribute. The content of the xsl:element element is a template
* for the attributes and children of the created element.
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
SerializationHandler rhandler = transformer.getSerializationHandler();
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
String nodeName = m_name_avt == null ? null : m_name_avt.evaluate(xctxt, sourceNode, this);
String prefix = null;
String nodeNamespace = "";
// Only validate if an AVT was used.
if ((nodeName != null) && (!m_name_avt.isSimple()) && (!XML11Char.isXML11ValidQName(nodeName))) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_VALUE, new Object[] { Constants.ATTRNAME_NAME, nodeName });
nodeName = null;
} else if (nodeName != null) {
prefix = QName.getPrefixPart(nodeName);
if (null != m_namespace_avt) {
nodeNamespace = m_namespace_avt.evaluate(xctxt, sourceNode, this);
if (null == nodeNamespace || (prefix != null && prefix.length() > 0 && nodeNamespace.length() == 0))
transformer.getMsgMgr().error(this, XSLTErrorResources.ER_NULL_URI_NAMESPACE);
else {
// Determine the actual prefix that we will use for this nodeNamespace
prefix = resolvePrefix(rhandler, prefix, nodeNamespace);
if (null == prefix)
prefix = "";
if (prefix.length() > 0)
nodeName = (prefix + ":" + QName.getLocalPart(nodeName));
else
nodeName = QName.getLocalPart(nodeName);
}
} else // No namespace attribute was supplied. Use the namespace declarations
// currently in effect for the xsl:element element.
{
try {
// Maybe temporary, until I get this worked out. test: axes59
nodeNamespace = getNamespaceForPrefix(prefix);
if ((null == nodeNamespace) && (prefix.length() == 0))
nodeNamespace = "";
else if (null == nodeNamespace) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_COULD_NOT_RESOLVE_PREFIX, new Object[] { prefix });
nodeName = null;
}
} catch (Exception ex) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_COULD_NOT_RESOLVE_PREFIX, new Object[] { prefix });
nodeName = null;
}
}
}
constructNode(nodeName, prefix, nodeNamespace, transformer);
}
use of org.apache.xpath.XPathContext in project robovm by robovm.
the class ElemExsltFuncResult method execute.
/**
* Generate the EXSLT function return value, and assign it to the variable
* index slot assigned for it in ElemExsltFunction compose().
*
*/
public void execute(TransformerImpl transformer) throws TransformerException {
XPathContext context = transformer.getXPathContext();
// in the owner ElemExsltFunction execute().
if (transformer.currentFuncResultSeen()) {
throw new TransformerException("An EXSLT function cannot set more than one result!");
}
int sourceNode = context.getCurrentNode();
// Set the return value;
XObject var = getValue(transformer, sourceNode);
transformer.popCurrentFuncResult();
transformer.pushCurrentFuncResult(var);
}
use of org.apache.xpath.XPathContext 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.xpath.XPathContext in project robovm by robovm.
the class PredicatedNodeTest method acceptNode.
//=============== NodeFilter Implementation ===============
/**
* 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 = m_lpi.getXPathContext();
try {
xctxt.pushCurrentNode(n);
XObject score = execute(xctxt, n);
// System.out.println("\n::acceptNode - score: "+score.num()+"::");
if (score != NodeTest.SCORE_NONE) {
if (getPredicateCount() > 0) {
countProximityPosition(0);
if (!executePredicates(n, xctxt))
return DTMIterator.FILTER_SKIP;
}
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