use of org.apache.xalan.templates.ElemTextLiteral in project j2objc by google.
the class TransformerImpl method executeChildTemplates.
/**
* Execute each of the children of a template element.
*
* @param elem The ElemTemplateElement that contains the children
* that should execute.
* @param shouldAddAttrs true if xsl:attributes should be executed.
*
* @throws TransformerException
* @xsl.usage advanced
*/
public void executeChildTemplates(ElemTemplateElement elem, boolean shouldAddAttrs) throws TransformerException {
// Does this element have any children?
ElemTemplateElement t = elem.getFirstChildElem();
if (null == t)
return;
if (elem.hasTextLitOnly() && m_optimizer) {
char[] chars = ((ElemTextLiteral) t).getChars();
try {
// Have to push stuff on for tooling...
this.pushElemTemplateElement(t);
m_serializationHandler.characters(chars, 0, chars.length);
} catch (SAXException se) {
throw new TransformerException(se);
} finally {
this.popElemTemplateElement();
}
return;
}
// // Check for infinite loops if we have to.
// boolean check = (m_stackGuard.m_recursionLimit > -1);
//
// if (check)
// getStackGuard().push(elem, xctxt.getCurrentNode());
XPathContext xctxt = m_xcontext;
xctxt.pushSAXLocatorNull();
int currentTemplateElementsTop = m_currentTemplateElements.size();
m_currentTemplateElements.push(null);
try {
// each of them.
for (; t != null; t = t.getNextSiblingElem()) {
if (!shouldAddAttrs && t.getXSLToken() == Constants.ELEMNAME_ATTRIBUTE)
continue;
xctxt.setSAXLocator(t);
m_currentTemplateElements.setElementAt(t, currentTemplateElementsTop);
t.execute(this);
}
} catch (RuntimeException re) {
TransformerException te = new TransformerException(re);
te.setLocator(t);
throw te;
} finally {
m_currentTemplateElements.pop();
xctxt.popSAXLocator();
}
// Check for infinite loops if we have to
// if (check)
// getStackGuard().pop();
}
use of org.apache.xalan.templates.ElemTextLiteral in project robovm by robovm.
the class TransformerImpl method executeChildTemplates.
/**
* Execute each of the children of a template element.
*
* @param elem The ElemTemplateElement that contains the children
* that should execute.
* @param shouldAddAttrs true if xsl:attributes should be executed.
*
* @throws TransformerException
* @xsl.usage advanced
*/
public void executeChildTemplates(ElemTemplateElement elem, boolean shouldAddAttrs) throws TransformerException {
// Does this element have any children?
ElemTemplateElement t = elem.getFirstChildElem();
if (null == t)
return;
if (elem.hasTextLitOnly() && m_optimizer) {
char[] chars = ((ElemTextLiteral) t).getChars();
try {
// Have to push stuff on for tooling...
this.pushElemTemplateElement(t);
m_serializationHandler.characters(chars, 0, chars.length);
} catch (SAXException se) {
throw new TransformerException(se);
} finally {
this.popElemTemplateElement();
}
return;
}
// // Check for infinite loops if we have to.
// boolean check = (m_stackGuard.m_recursionLimit > -1);
//
// if (check)
// getStackGuard().push(elem, xctxt.getCurrentNode());
XPathContext xctxt = m_xcontext;
xctxt.pushSAXLocatorNull();
int currentTemplateElementsTop = m_currentTemplateElements.size();
m_currentTemplateElements.push(null);
try {
// each of them.
for (; t != null; t = t.getNextSiblingElem()) {
if (!shouldAddAttrs && t.getXSLToken() == Constants.ELEMNAME_ATTRIBUTE)
continue;
xctxt.setSAXLocator(t);
m_currentTemplateElements.setElementAt(t, currentTemplateElementsTop);
t.execute(this);
}
} catch (RuntimeException re) {
TransformerException te = new TransformerException(re);
te.setLocator(t);
throw te;
} finally {
m_currentTemplateElements.pop();
xctxt.popSAXLocator();
}
// Check for infinite loops if we have to
// if (check)
// getStackGuard().pop();
}
use of org.apache.xalan.templates.ElemTextLiteral in project robovm by robovm.
the class TransformerImpl method transformToString.
/**
* Take the contents of a template element, process it, and
* convert it to a string.
*
* @param elem The parent element whose children will be output
* as a string.
*
* @return The stringized result of executing the elements children.
*
* @throws TransformerException
* @xsl.usage advanced
*/
public String transformToString(ElemTemplateElement elem) throws TransformerException {
ElemTemplateElement firstChild = elem.getFirstChildElem();
if (null == firstChild)
return "";
if (elem.hasTextLitOnly() && m_optimizer) {
return ((ElemTextLiteral) firstChild).getNodeValue();
}
// Save the current result tree handler.
SerializationHandler savedRTreeHandler = this.m_serializationHandler;
// Create a Serializer object that will handle the SAX events
// and build the ResultTreeFrag nodes.
StringWriter sw = (StringWriter) m_stringWriterObjectPool.getInstance();
m_serializationHandler = (ToTextStream) m_textResultHandlerObjectPool.getInstance();
if (null == m_serializationHandler) {
// if we didn't get one from the pool, go make a new one
Serializer serializer = org.apache.xml.serializer.SerializerFactory.getSerializer(m_textformat.getProperties());
m_serializationHandler = (SerializationHandler) serializer;
}
m_serializationHandler.setTransformer(this);
m_serializationHandler.setWriter(sw);
String result;
try {
/* Don't call startDocument, the SerializationHandler will
* generate its own internal startDocument call anyways
*/
// this.m_serializationHandler.startDocument();
// Do the transformation of the child elements.
executeChildTemplates(elem, true);
this.m_serializationHandler.endDocument();
result = sw.toString();
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
} finally {
sw.getBuffer().setLength(0);
try {
sw.close();
} catch (Exception ioe) {
}
m_stringWriterObjectPool.freeInstance(sw);
m_serializationHandler.reset();
m_textResultHandlerObjectPool.freeInstance(m_serializationHandler);
// Restore the previous result tree handler.
m_serializationHandler = savedRTreeHandler;
}
return result;
}
Aggregations