// Return the content handler for this Result object
try {
// Result object could be SAXResult, DOMResult, or StreamResult
if (result instanceof SAXResult) {
final SAXResult target = (SAXResult)result;
final ContentHandler handler = target.getHandler();
_tohFactory.setHandler(handler);
/**
* Fix for bug 24414
* If the lexicalHandler is set then we need to get that
* for obtaining the lexical information
*/
LexicalHandler lexicalHandler = target.getLexicalHandler();
if (lexicalHandler != null ) {
_tohFactory.setLexicalHandler(lexicalHandler);
}
_tohFactory.setOutputType(TransletOutputHandlerFactory.SAX);
return _tohFactory.getSerializationHandler();
}
else if (result instanceof DOMResult) {
_tohFactory.setNode(((DOMResult) result).getNode());
_tohFactory.setNextSibling(((DOMResult) result).getNextSibling());
_tohFactory.setOutputType(TransletOutputHandlerFactory.DOM);
return _tohFactory.getSerializationHandler();
}
else if (result instanceof StreamResult) {
// Get StreamResult
final StreamResult target = (StreamResult) result;
// StreamResult may have been created with a java.io.File,
// java.io.Writer, java.io.OutputStream or just a String
// systemId.
_tohFactory.setOutputType(TransletOutputHandlerFactory.STREAM);
// try to get a Writer from Result object
final Writer writer = target.getWriter();
if (writer != null) {
_tohFactory.setWriter(writer);
return _tohFactory.getSerializationHandler();
}
// or try to get an OutputStream from Result object
final OutputStream ostream = target.getOutputStream();
if (ostream != null) {
_tohFactory.setOutputStream(ostream);
return _tohFactory.getSerializationHandler();
}