Report report = reportManager.generateReport(request, optionalFilter, null);
//FIXME: the report transformer is defined as a singleton bean in the export report
// action configured through spring. Here we are instantiating a new specific
// transformer - there was a bug in that this one did not have the droid config
// object configured. For the time being, just set up this transformer correctly.
ReportTransformerImpl transformer = new ReportTransformerImpl();
transformer.setConfig(config);
String message = String.format("Exporting report as [%s] to: [%s]", reportOutputType, destination);
log.info(message);
if (DROID_REPORT_XML.equalsIgnoreCase(reportOutputType)) {
FileWriter tempReport = new FileWriter(destination);
reportXmlWriter.writeReport(report, tempReport);
} else {
// Write the report xml to a temporary file:
File tempFile = File.createTempFile("report~", ".xml", config.getTempDir());
FileWriter tempReport = new FileWriter(tempFile);
reportXmlWriter.writeReport(report, tempReport);
FileReader reader = new FileReader(tempFile);
try {
if (PDF_FORMAT.equalsIgnoreCase(reportOutputType)) {
FileOutputStream out = new FileOutputStream(destination);
transformer.transformToPdf(reader, XHTML_TRANSFORM_LOCATION, out);
out.close();
} else {
ReportSpec spec = request.getReportSpec();
File xslFile = getXSLFile(spec.getXslTransforms());
if (xslFile != null) {
FileWriter out = new FileWriter(destination);
transformer.transformUsingXsl(reader, xslFile, out);
out.close();
}
}
} finally {
reader.close();