final Translet translet = (Translet)this;
String encoding = translet.getOutputEncoding();
if (encoding == null) encoding = "UTF-8";
// create a DefaultSAXOutputHandler
DefaultSAXOutputHandler saxHandler = null;
StreamResult target = (StreamResult)outputTarget;
java.io.Writer writer = target.getWriter();
java.io.OutputStream os = target.getOutputStream();
String systemid = target.getSystemId();
if (writer != null) {
// no constructor that takes encoding yet...
try {
saxHandler = new DefaultSAXOutputHandler(writer);
} catch (java.io.IOException e) {
throw new TransformerException(
"IOException creating DefaultSAXOutputHandler");
}
} else if (os != null) {
try {
saxHandler = new DefaultSAXOutputHandler(os, encoding);
} catch (java.io.IOException e) {
throw new TransformerException(
"IOException creating DefaultSAXOutputHandler");
}
} else if (systemid != null) {
String filePrefix = new String("file:///");
if (systemid.startsWith(filePrefix)) {
systemid = systemid.substring(filePrefix.length());
}
try {
saxHandler = new DefaultSAXOutputHandler(
((OutputStream)new FileOutputStream(systemid)),
encoding);
} catch (java.io.FileNotFoundException e) {
throw new TransformerException(
"Transform output target could not be opened.");