use of org.apache.xpath.XPathContext in project j2objc by google.
the class TransformerImpl method executeChildTemplates.
/**
* Execute each of the children of a template element. This method
* is only for extension use.
*
* @param elem The ElemTemplateElement that contains the children
* that should execute.
* NEEDSDOC @param context
* @param mode The current mode.
* @param handler The ContentHandler to where the result events
* should be fed.
*
* @throws TransformerException
* @xsl.usage advanced
*/
public void executeChildTemplates(ElemTemplateElement elem, org.w3c.dom.Node context, QName mode, ContentHandler handler) throws TransformerException {
XPathContext xctxt = m_xcontext;
try {
if (null != mode)
pushMode(mode);
xctxt.pushCurrentNode(xctxt.getDTMHandleFromNode(context));
executeChildTemplates(elem, handler);
} finally {
xctxt.popCurrentNode();
// error though, without a corresponding pushMode().
if (null != mode)
popMode();
}
}
use of org.apache.xpath.XPathContext in project j2objc by google.
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 j2objc by google.
the class ElemChoose method execute.
/**
* Execute the xsl:choose transformation.
*
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
boolean found = false;
for (ElemTemplateElement childElem = getFirstChildElem(); childElem != null; childElem = childElem.getNextSiblingElem()) {
int type = childElem.getXSLToken();
if (Constants.ELEMNAME_WHEN == type) {
found = true;
ElemWhen when = (ElemWhen) childElem;
// must be xsl:when
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
if (when.getTest().bool(xctxt, sourceNode, when)) {
transformer.executeChildTemplates(when, true);
return;
}
} else if (Constants.ELEMNAME_OTHERWISE == type) {
found = true;
// xsl:otherwise
transformer.executeChildTemplates(childElem, true);
return;
}
}
if (!found)
transformer.getMsgMgr().error(this, XSLTErrorResources.ER_CHOOSE_REQUIRES_WHEN);
}
use of org.apache.xpath.XPathContext in project j2objc by google.
the class ElemCopy method execute.
/**
* The xsl:copy element provides an easy way of copying the current node.
* Executing this function creates a copy of the current node into the
* result tree.
* <p>The namespace nodes of the current node are automatically
* copied as well, but the attributes and children of the node are not
* automatically copied. The content of the xsl:copy element is a
* template for the attributes and children of the created node;
* the content is instantiated only for nodes of types that can have
* attributes or children (i.e. root nodes and element nodes).</p>
* <p>The root node is treated specially because the root node of the
* result tree is created implicitly. When the current node is the
* root node, xsl:copy will not create a root node, but will just use
* the content template.</p>
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
XPathContext xctxt = transformer.getXPathContext();
try {
int sourceNode = xctxt.getCurrentNode();
xctxt.pushCurrentNode(sourceNode);
DTM dtm = xctxt.getDTM(sourceNode);
short nodeType = dtm.getNodeType(sourceNode);
if ((DTM.DOCUMENT_NODE != nodeType) && (DTM.DOCUMENT_FRAGMENT_NODE != nodeType)) {
SerializationHandler rthandler = transformer.getSerializationHandler();
// TODO: Process the use-attribute-sets stuff
ClonerToResultTree.cloneToResultTree(sourceNode, nodeType, dtm, rthandler, false);
if (DTM.ELEMENT_NODE == nodeType) {
super.execute(transformer);
SerializerUtils.processNSDecls(rthandler, sourceNode, nodeType, dtm);
transformer.executeChildTemplates(this, true);
String ns = dtm.getNamespaceURI(sourceNode);
String localName = dtm.getLocalName(sourceNode);
transformer.getResultTreeHandler().endElement(ns, localName, dtm.getNodeName(sourceNode));
}
} else {
super.execute(transformer);
transformer.executeChildTemplates(this, true);
}
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
} finally {
xctxt.popCurrentNode();
}
}
use of org.apache.xpath.XPathContext in project j2objc by google.
the class TreeWalker2Result method startNode.
/**
* Start traversal of the tree at the given node
*
*
* @param node Starting node for traversal
*
* @throws TransformerException
*/
protected void startNode(int node) throws org.xml.sax.SAXException {
XPathContext xcntxt = m_transformer.getXPathContext();
try {
if (DTM.ELEMENT_NODE == m_dtm.getNodeType(node)) {
xcntxt.pushCurrentNode(node);
if (m_startNode != node) {
super.startNode(node);
} else {
String elemName = m_dtm.getNodeName(node);
String localName = m_dtm.getLocalName(node);
String namespace = m_dtm.getNamespaceURI(node);
//xcntxt.pushCurrentNode(node);
// SAX-like call to allow adding attributes afterwards
m_handler.startElement(namespace, localName, elemName);
boolean hasNSDecls = false;
DTM dtm = m_dtm;
for (int ns = dtm.getFirstNamespaceNode(node, true); DTM.NULL != ns; ns = dtm.getNextNamespaceNode(node, ns, true)) {
SerializerUtils.ensureNamespaceDeclDeclared(m_handler, dtm, ns);
}
for (int attr = dtm.getFirstAttribute(node); DTM.NULL != attr; attr = dtm.getNextAttribute(attr)) {
SerializerUtils.addAttribute(m_handler, attr);
}
}
} else {
xcntxt.pushCurrentNode(node);
super.startNode(node);
xcntxt.popCurrentNode();
}
} catch (javax.xml.transform.TransformerException te) {
throw new org.xml.sax.SAXException(te);
}
}
Aggregations