OutputStream tmpOut = outputStream;
if (xsl != null) {
String filename = rootNode.getName().replace(" ", "_");
File tempFile = File.createTempFile("exportTemplates-" + filename, "xml");
tmpOut = new DeferredFileOutputStream(1024 * 1024 * 10, tempFile);
}
DataWriter dw = new DataWriter(new OutputStreamWriter(tmpOut, "UTF-8"));
if (Boolean.TRUE.equals(params.get(SYSTEM_VIEW))) {
SystemViewExporter exporter = new SystemViewExporter(rootNode.getSession(), dw, !noRecurse, !skipBinary);
exporter.export(rootNode);
} else {
DocumentViewExporter exporter = new DocumentViewExporter(rootNode.getSession(), dw, skipBinary, noRecurse);
typesToIgnore.add("rep:system");
exporter.setTypesToIgnore(typesToIgnore);
exporter.export(rootNode, sortedNodes);
}
dw.flush();
if (xsl != null) {
DeferredFileOutputStream stream = (DeferredFileOutputStream) tmpOut;
InputStream inputStream = new BufferedInputStream(new FileInputStream(stream.getFile()));
fileCleaningTracker.track(stream.getFile(), inputStream);
if (stream.isInMemory()) {
inputStream.close();
inputStream = new ByteArrayInputStream(stream.getData());
}
XSLTransformer xslTransformer = new XSLTransformer(xsl);
SAXBuilder saxBuilder = new SAXBuilder(false);
Document document = saxBuilder.build(inputStream);
Document document1 = xslTransformer.transform(document);