public static synchronized ByteArrayOutputStream export(Type type, JasperPrint print) {
if (logger == null) {
logger = LoggerProducer.create(Logger.class);
}
ResourceBundle bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-report-bundle"));
logger.debug(bundle.getString("generating-report", type.name()));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
switch (type) {
case CSV:
logger.debug(bundle.getString("exporting-report", "csv"));
JRCsvExporter exporterCSV = new JRCsvExporter();
exporterCSV.setParameter(JRCsvExporterParameter.JASPER_PRINT, print);
exporterCSV.setParameter(JRCsvExporterParameter.OUTPUT_STREAM, outputStream);
exporterCSV.exportReport();
break;
case HTML:
logger.debug(bundle.getString("exporting-report", "html"));
JRHtmlExporter exporterHTML = new JRHtmlExporter();
exporterHTML.setParameter(JRHtmlExporterParameter.JASPER_PRINT, print);
exporterHTML.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, outputStream);
exporterHTML.exportReport();
break;
case ODT:
logger.debug(bundle.getString("exporting-report", "odt"));
JROdtExporter exporterODT = new JROdtExporter();
exporterODT.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporterODT.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporterODT.exportReport();
break;
case PDF:
logger.debug(bundle.getString("exporting-report", "pdf"));
JRPdfExporter exporterPDF = new JRPdfExporter();
exporterPDF.setParameter(JRPdfExporterParameter.JASPER_PRINT, print);
exporterPDF.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, outputStream);
exporterPDF.setParameter(JRPdfExporterParameter.IS_CREATING_BATCH_MODE_BOOKMARKS, Boolean.TRUE);
exporterPDF.setParameter(JRPdfExporterParameter.IGNORE_PAGE_MARGINS, Boolean.TRUE);
exporterPDF.exportReport();
break;
case TXT:
logger.debug(bundle.getString("exporting-report", "txt"));
JRTextExporter exporterTXT = new JRTextExporter();
exporterTXT.setParameter(JRTextExporterParameter.JASPER_PRINT, print);
exporterTXT.setParameter(JRTextExporterParameter.OUTPUT_STREAM, outputStream);
exporterTXT.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, new Float(30));
exporterTXT.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, new Float(30));
exporterTXT.exportReport();
break;
case RTF:
logger.debug(bundle.getString("exporting-report", "rtf"));
JRRtfExporter exporterRTF = new JRRtfExporter();
exporterRTF.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporterRTF.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporterRTF.exportReport();
case XLS:
logger.debug(bundle.getString("exporting-report", "xls"));
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporterXLS.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterXLS.exportReport();
break;
case ODS:
logger.debug(bundle.getString("exporting-report", "ods"));
JROdsExporter exporterODS = new JROdsExporter();
exporterODS.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporterODS.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporterODS.exportReport();
break;
default:
throw new DemoiselleException(bundle.getString("exception-reportimpl-not-found", type.name()));
}
} catch (JRException jre) {
throw new DemoiselleException(bundle.getString("exception-generating-report", type.name()), jre);
}
return outputStream;
}