Logger.debug(this, "Call to fillReport with Data Source: " + report.getDs());
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, DbConnectionFactory.getConnection(report.getDs()));
Logger.debug(this, "Creating exporter");
JRHtmlExporter exporter = new JRHtmlExporter();
Logger.debug(this, "Getting pages");
int lastPageIndex = 0;
if (jasperPrint.getPages() != null) {
lastPageIndex = jasperPrint.getPages().size() - 1;
}
if (!(pageIndex >= 0)) {
pageIndex = 0;
}
if (pageIndex > lastPageIndex) {
pageIndex = lastPageIndex;
}
StringBuffer sbuffer = new StringBuffer();
request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint);
Logger.debug(this, "Setting parameters");
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, sbuffer);
if (jasperPrint.getPages() != null && jasperPrint.getPages().size()>0){
exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
}
exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");
exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "/servlets/jrimage?image=");
request.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint);
Logger.debug(this, "Exporting report");
exporter.exportReport();
request.setAttribute("reportSB", sbuffer);
request.setAttribute("pageIndex", pageIndex);
request.setAttribute("lastPageIndex", lastPageIndex);
request.setAttribute("reportId", report.getInode());
request.setAttribute("submittedPars", submittedPars);