use of org.apache.xalan.templates.ElemTextLiteral in project robovm by robovm.
the class ProcessorCharacters method startNonText.
/**
* Receive notification of the start of the non-text event. This
* is sent to the current processor when any non-text event occurs.
*
* @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
*/
public void startNonText(StylesheetHandler handler) throws org.xml.sax.SAXException {
if (this == handler.getCurrentProcessor()) {
handler.popProcessor();
}
int nChars = m_accumulator.length();
if ((nChars > 0) && ((null != m_xslTextElement) || !XMLCharacterRecognizer.isWhiteSpace(m_accumulator)) || handler.isSpacePreserve()) {
ElemTextLiteral elem = new ElemTextLiteral();
elem.setDOMBackPointer(m_firstBackPointer);
elem.setLocaterInfo(handler.getLocator());
try {
elem.setPrefixes(handler.getNamespaceSupport());
} catch (TransformerException te) {
throw new org.xml.sax.SAXException(te);
}
boolean doe = (null != m_xslTextElement) ? m_xslTextElement.getDisableOutputEscaping() : false;
elem.setDisableOutputEscaping(doe);
elem.setPreserveSpace(true);
char[] chars = new char[nChars];
m_accumulator.getChars(0, nChars, chars, 0);
elem.setChars(chars);
ElemTemplateElement parent = handler.getElemTemplateElement();
parent.appendChild(elem);
}
m_accumulator.setLength(0);
m_firstBackPointer = null;
}
use of org.apache.xalan.templates.ElemTextLiteral in project robovm by robovm.
the class ProcessorExsltFunction method validate.
/**
* Non-recursive traversal of FunctionElement tree based on TreeWalker to verify that
* there are no literal result elements except within a func:result element and that
* the func:result element does not contain any following siblings except xsl:fallback.
*/
public void validate(ElemTemplateElement elem, StylesheetHandler handler) throws SAXException {
String msg = "";
while (elem != null) {
//System.out.println("elem " + elem);
if (elem instanceof ElemExsltFuncResult && elem.getNextSiblingElem() != null && !(elem.getNextSiblingElem() instanceof ElemFallback)) {
msg = "func:result has an illegal following sibling (only xsl:fallback allowed)";
handler.error(msg, new SAXException(msg));
}
if ((elem instanceof ElemApplyImport || elem instanceof ElemApplyTemplates || elem instanceof ElemAttribute || elem instanceof ElemCallTemplate || elem instanceof ElemComment || elem instanceof ElemCopy || elem instanceof ElemCopyOf || elem instanceof ElemElement || elem instanceof ElemLiteralResult || elem instanceof ElemNumber || elem instanceof ElemPI || elem instanceof ElemText || elem instanceof ElemTextLiteral || elem instanceof ElemValueOf) && !(ancestorIsOk(elem))) {
msg = "misplaced literal result in a func:function container.";
handler.error(msg, new SAXException(msg));
}
ElemTemplateElement nextElem = elem.getFirstChildElem();
while (nextElem == null) {
nextElem = elem.getNextSiblingElem();
if (nextElem == null)
elem = elem.getParentElem();
if (elem == null || elem instanceof ElemExsltFunction)
// ok
return;
}
elem = nextElem;
}
}
use of org.apache.xalan.templates.ElemTextLiteral in project j2objc by google.
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;
}
use of org.apache.xalan.templates.ElemTextLiteral in project j2objc by google.
the class ProcessorExsltFunction method validate.
/**
* Non-recursive traversal of FunctionElement tree based on TreeWalker to verify that
* there are no literal result elements except within a func:result element and that
* the func:result element does not contain any following siblings except xsl:fallback.
*/
public void validate(ElemTemplateElement elem, StylesheetHandler handler) throws SAXException {
String msg = "";
while (elem != null) {
// System.out.println("elem " + elem);
if (elem instanceof ElemExsltFuncResult && elem.getNextSiblingElem() != null && !(elem.getNextSiblingElem() instanceof ElemFallback)) {
msg = "func:result has an illegal following sibling (only xsl:fallback allowed)";
handler.error(msg, new SAXException(msg));
}
if ((elem instanceof ElemApplyImport || elem instanceof ElemApplyTemplates || elem instanceof ElemAttribute || elem instanceof ElemCallTemplate || elem instanceof ElemComment || elem instanceof ElemCopy || elem instanceof ElemCopyOf || elem instanceof ElemElement || elem instanceof ElemLiteralResult || elem instanceof ElemNumber || elem instanceof ElemPI || elem instanceof ElemText || elem instanceof ElemTextLiteral || elem instanceof ElemValueOf) && !(ancestorIsOk(elem))) {
msg = "misplaced literal result in a func:function container.";
handler.error(msg, new SAXException(msg));
}
ElemTemplateElement nextElem = elem.getFirstChildElem();
while (nextElem == null) {
nextElem = elem.getNextSiblingElem();
if (nextElem == null)
elem = elem.getParentElem();
if (elem == null || elem instanceof ElemExsltFunction)
// ok
return;
}
elem = nextElem;
}
}
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();
}
Aggregations