use of org.apache.xml.serializer.SerializationHandler in project robovm by robovm.
the class ElemTextLiteral method execute.
/**
* Copy the text literal to the result tree.
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
try {
SerializationHandler rth = transformer.getResultTreeHandler();
if (m_disableOutputEscaping) {
rth.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
}
rth.characters(m_ch, 0, m_ch.length);
if (m_disableOutputEscaping) {
rth.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
}
} catch (SAXException se) {
throw new TransformerException(se);
}
}
use of org.apache.xml.serializer.SerializationHandler in project robovm by robovm.
the class TransformerHandlerImpl method setResult.
////////////////////////////////////////////////////////////////////
// Implementation of javax.xml.transform.sax.TransformerHandler.
////////////////////////////////////////////////////////////////////
/**
* Enables the user of the TransformerHandler to set the
* to set the Result for the transformation.
*
* @param result A Result instance, should not be null.
*
* @throws IllegalArgumentException if result is invalid for some reason.
*/
public void setResult(Result result) throws IllegalArgumentException {
if (null == result)
//"result should not be null");
throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_RESULT_NULL, null));
try {
// ContentHandler handler =
// m_transformer.createResultContentHandler(result);
// m_transformer.setContentHandler(handler);
SerializationHandler xoh = m_transformer.createSerializationHandler(result);
m_transformer.setSerializationHandler(xoh);
} catch (javax.xml.transform.TransformerException te) {
//"result could not be set");
throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_RESULT_COULD_NOT_BE_SET, null));
}
m_result = result;
}
use of org.apache.xml.serializer.SerializationHandler in project robovm by robovm.
the class TransformerImpl method transformToRTF.
/**
* Given a stylesheet element, create a result tree fragment from it's
* contents.
* @param templateParent The template element that holds the fragment.
* @param dtmFrag The DTM to write the RTF into
* @return the NodeHandle for the root node of the resulting RTF.
*
* @throws TransformerException
* @xsl.usage advanced
*/
private int transformToRTF(ElemTemplateElement templateParent, DTM dtmFrag) throws TransformerException {
XPathContext xctxt = m_xcontext;
ContentHandler rtfHandler = dtmFrag.getContentHandler();
// Obtain the ResultTreeFrag's root node.
// NOTE: In SAX2RTFDTM, this value isn't available until after
// the startDocument has been issued, so assignment has been moved
// down a bit in the code.
// not yet reliably = dtmFrag.getDocument();
int resultFragment;
// Save the current result tree handler.
SerializationHandler savedRTreeHandler = this.m_serializationHandler;
// And make a new handler for the RTF.
ToSAXHandler h = new ToXMLSAXHandler();
h.setContentHandler(rtfHandler);
h.setTransformer(this);
// Replace the old handler (which was already saved)
m_serializationHandler = h;
// use local variable for the current handler
SerializationHandler rth = m_serializationHandler;
try {
rth.startDocument();
// startDocument is "bottlenecked" in RTH. We need it acted upon immediately,
// to set the DTM's state as in-progress, so that if the xsl:variable's body causes
// further RTF activity we can keep that from bashing this DTM.
rth.flushPending();
try {
// Do the transformation of the child elements.
executeChildTemplates(templateParent, true);
// Make sure everything is flushed!
rth.flushPending();
// Get the document ID. May not exist until the RTH has not only
// received, but flushed, the startDocument, and may be invalid
// again after the document has been closed (still debating that)
// ... so waiting until just before the end seems simplest/safest.
resultFragment = dtmFrag.getDocument();
} finally {
rth.endDocument();
}
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
} finally {
// Restore the previous result tree handler.
this.m_serializationHandler = savedRTreeHandler;
}
return resultFragment;
}
use of org.apache.xml.serializer.SerializationHandler in project robovm by robovm.
the class TransformerImpl method transformNode.
/**
* Process the source node to the output result, if the
* processor supports the "http://xml.org/trax/features/dom/input"
* feature.
* %REVIEW% Do we need a Node version of this?
* @param node The input source node, which can be any valid DTM node.
* @param outputTarget The output source target.
*
* @throws TransformerException
*/
public void transformNode(int node, Result outputTarget) throws TransformerException {
SerializationHandler xoh = createSerializationHandler(outputTarget);
this.setSerializationHandler(xoh);
m_outputTarget = outputTarget;
transformNode(node);
}
use of org.apache.xml.serializer.SerializationHandler in project j2objc by google.
the class ElemAttribute method constructNode.
/**
* Construct a node in the result tree. This method is overloaded by
* xsl:attribute. At this class level, this method creates an element.
*
* @param nodeName The name of the node, which may be null.
* @param prefix The prefix for the namespace, which may be null.
* @param nodeNamespace The namespace of the node, which may be null.
* @param transformer non-null reference to the the current transform-time state.
* @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
* @param mode reference, which may be null, to the <a href="http://www.w3.org/TR/xslt#modes">current mode</a>.
*
* @throws TransformerException
*/
void constructNode(String nodeName, String prefix, String nodeNamespace, TransformerImpl transformer) throws TransformerException {
if (null != nodeName && nodeName.length() > 0) {
SerializationHandler rhandler = transformer.getSerializationHandler();
// Evaluate the value of this attribute
String val = transformer.transformToString(this);
try {
// Let the result tree handler add the attribute and its String value.
String localName = QName.getLocalPart(nodeName);
if (prefix != null && prefix.length() > 0) {
rhandler.addAttribute(nodeNamespace, localName, nodeName, "CDATA", val, true);
} else {
rhandler.addAttribute("", localName, nodeName, "CDATA", val, true);
}
} catch (SAXException e) {
}
}
}
Aggregations