java.io.FileNotFoundException,
java.io.IOException,
javax.xml.transform.TransformerException
{
File file = new File(fileName);
TransformerImpl transformer = context.getTransformer();
String base; // Base URI to use for relative paths
if(!file.isAbsolute())
{
// This code is attributed to Jon Grov <jon@linpro.no>. A relative file name
// is relative to the Result used to kick off the transform. If no such
// Result was supplied, the filename is relative to the source document.
// When transforming with a SAXResult or DOMResult, call
// TransformerImpl.setOutputTarget() to set the desired Result base.
// String base = urlToFileName(elem.getStylesheet().getSystemId());
Result outputTarget = transformer.getOutputTarget();
if ( (null != outputTarget) && ((base = outputTarget.getSystemId()) != null) ) {
base = urlToFileName(base);
}
else
{
base = urlToFileName(transformer.getBaseURLOfSource());
}
if(null != base)
{
File baseFile = new File(base);
file = new File(baseFile.getParent(), fileName);
}
// System.out.println("file is: "+file.toString());
}
if(mkdirs)
{
String dirStr = file.getParent();
if((null != dirStr) && (dirStr.length() > 0))
{
File dir = new File(dirStr);
dir.mkdirs();
}
}
// This should be worked on so that the output format can be
// defined by a first child of the redirect element.
OutputProperties format = transformer.getOutputFormat();
// FileOutputStream ostream = new FileOutputStream(file);
// Patch from above line to below by <jpvdm@iafrica.com>
// Note that in JDK 1.2.2 at least, FileOutputStream(File)
// is implemented as a call to
// FileOutputStream(File.getPath, append), thus this should be
// the equivalent instead of getAbsolutePath()
FileOutputStream ostream = new FileOutputStream(file.getPath(), append);
try
{
ContentHandler flistener
= transformer.createResultContentHandler(new StreamResult(ostream), format);
try
{
flistener.startDocument();
}
catch(org.xml.sax.SAXException se)