public String execute()
{
ReportUser user =
(ReportUser) ActionContext.getContext().getSession().get(ORStatics.REPORT_USER);
Report report = (Report) ActionContext.getContext().getSession().get(ORStatics.REPORT);
int exportTypeCode =
Integer.parseInt(
(String) ActionContext.getContext().getSession().get(ORStatics.EXPORT_TYPE));
ExportType exportType = ExportType.findByCode(exportTypeCode);
Map<String, Object> reportParameters = getReportParameterMap(user, report, exportType);
Map imagesMap = getImagesMap();
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
// set headers to disable caching
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "max-age=0");
ReportLog reportLog = new ReportLog(user, report, new Date());
reportLog.setExportType(exportType.getCode());
JRVirtualizer virtualizer = null;
try
{
if (exportType == ExportType.PDF)
{
// Handle "contype" request from Internet Explorer
if ("contype".equals(request.getHeader("User-Agent")))
{
response.setContentType("application/pdf");
response.setContentLength(0);
ServletOutputStream outputStream = response.getOutputStream();
outputStream.close();
return NONE;
}
}
log.debug("Filling report: " + report.getName());
reportLogProvider.insertReportLog(reportLog);
if (report.isVirtualizationEnabled() && exportType != ExportType.IMAGE)
{
log.debug("Virtualization Enabled");
virtualizer = new JRFileVirtualizer(2, directoryProvider.getTempDirectory());
reportParameters.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
}
ReportEngineInput reportInput = new ReportEngineInput(report, reportParameters);
reportInput.setExportType(exportType);
reportInput.setImagesMap(imagesMap);
// add any charts
if (report.getReportChart() != null)
{
log.debug("Adding chart: " + report.getReportChart().getName());
ChartReportEngine chartEngine = new ChartReportEngine(dataSourceProvider,
directoryProvider, propertiesProvider);
ChartEngineOutput chartOutput = (ChartEngineOutput) chartEngine
.generateReport(reportInput);
reportParameters.put("ChartImage", chartOutput.getContent());
}
ReportEngineOutput reportOutput = null;
JasperPrint jasperPrint = null;
if (report.isJasperReport())
{
JasperReportEngine jasperEngine = new JasperReportEngine(
dataSourceProvider, directoryProvider, propertiesProvider);
jasperPrint = jasperEngine.fillReport(reportInput);
log.debug("Report filled - " + report.getName() + " : size = "
+ jasperPrint.getPages().size());
log.debug("Exporting report: " + report.getName());
reportOutput = jasperEngine.exportReport(jasperPrint, exportType, report
.getReportExportOption(), imagesMap, false);
}
else
{
ReportEngine reportEngine = ReportEngineHelper.getReportEngine(report, dataSourceProvider, directoryProvider, propertiesProvider);
reportOutput = reportEngine.generateReport(reportInput);
}
response.setContentType(reportOutput.getContentType());
if (exportType != ExportType.HTML && exportType != ExportType.IMAGE)
{
response.setHeader("Content-disposition", "inline; filename="
+ StringUtils.deleteWhitespace(report.getName()) + reportOutput.getContentExtension());
}
if (exportType == ExportType.IMAGE)
{
if (jasperPrint != null)
{
session.put(ORStatics.JASPERPRINT, jasperPrint);
}
}
else
{
byte[] content = reportOutput.getContent();
response.setContentLength(content.length);
ServletOutputStream out = response.getOutputStream();
out.write(content, 0, content.length);
out.flush();
out.close();
}
reportLog.setEndTime(new Date());
reportLog.setStatus(ReportLog.STATUS_SUCCESS);
reportLogProvider.updateReportLog(reportLog);
log.debug("Finished report: " + report.getName());
}
catch (Exception e)
{
if (e.getMessage() != null && e.getMessage().equals(LocalStrings.ERROR_REPORT_EMPTY))
{