outputType = "html";
//outputType = ExporterFactory.getDefaultType();
}
logger.debug("Output format is [" + outputType + "]");
Monitor monitorExportReport =MonitorFactory.start("JasperReportRunner.ExportReport");
JRExporter exporter = ExporterFactory.getExporter(outputType);
String mimeType = ExporterFactory.getMIMEType(outputType);
if(exporter != null) logger.debug("Configured exporter class [" + exporter.getClass().getName() + "]");
else logger.debug("Exporter class [null]");
logger.debug("Configured MIME type [" + mimeType + "]");
// for base types use default exporter, mimeType and parameters if these
// are not specified by configuration file
if (outputType.equalsIgnoreCase("csv")) {
if(mimeType == null) mimeType = "text/plain";
servletResponse.setContentType(mimeType);
if(exporter == null) exporter = new JRCsvExporter();
} else if (outputType.equalsIgnoreCase("html")) {
if(mimeType == null) mimeType = "text/html";
servletResponse.setContentType(mimeType);
if(exporter == null) exporter = new JRHtmlExporter();
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");
// define the map structure for report images
HashMap m_imagesMap = new HashMap();
String mapName = uuid_local.toString();
servletRequest.getSession().setAttribute(mapName, m_imagesMap);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP ,m_imagesMap);
//exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image.jsp?mapname="+mapName+"&image=");
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "JRImageServlet?mapname="+mapName+"&image=");
/* commented by Davide Zerbetto on 12/10/2009: there are problems with MIF (Ext ManagedIFrame library) library
// setting HTML header: this is necessary in order to inject the document.domain directive
String head = getHTMLHeader();
exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, head);
*/
} else if (outputType.equalsIgnoreCase("xls")) {
if(mimeType == null) mimeType = "application/vnd.ms-excel";
servletResponse.setContentType(mimeType);
//if(exporter == null) exporter = new JRXlsExporter();
if(exporter == null) exporter = new JExcelApiExporter();
} else if (outputType.equalsIgnoreCase("rtf")) {
if(mimeType == null) mimeType = "application/rtf";
servletResponse.setContentType(mimeType);
if(exporter == null) exporter = new JRRtfExporter();
} else if (outputType.equalsIgnoreCase("xml")) {
if(mimeType == null) mimeType = "text/xml";
servletResponse.setContentType(mimeType);
if(exporter == null) exporter = new JRXmlExporter();
} else if (outputType.equalsIgnoreCase("txt")) {
if(mimeType == null) mimeType = "text/plain";
servletResponse.setContentType(mimeType);
if(exporter == null) exporter = new JRTextExporter();
exporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT,new Integer(100));
exporter.setParameter(JRTextExporterParameter.PAGE_WIDTH,new Integer(100));
} else if (outputType.equalsIgnoreCase("pdf")) {
if(mimeType == null) mimeType = "application/pdf";
servletResponse.setContentType(mimeType);
if(exporter == null) exporter = new JRPdfExporter();
} else if (outputType.equalsIgnoreCase("JPG")) {
byte[] bytes = getImageBytes(report, jasperPrint);
if(mimeType == null) mimeType = "application/jpeg";
out.write(bytes);
return;
} else if (outputType.equalsIgnoreCase("JPGBASE64")) {
byte[] bytes = getImagesBase64Bytes(report, jasperPrint);
if(mimeType == null) mimeType = "text/plain";
out.write(bytes);
return;
} else {
if(mimeType != null && exporter != null) servletResponse.setContentType(mimeType);
else {
logger.warn("Impossible to load exporter for type " + outputType);
logger.warn("Pdf exporter will be used");
servletResponse.setContentType("application/pdf");
exporter = new JRPdfExporter();
}
}
logger.debug("MIME type of response is [" + servletResponse.getContentType()+ "]");
logger.debug("Exporter class used is [" + exporter.getClass().getName()+ "]");
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
exporter.exportReport();
monitorExportReport.stop();
logger.debug("Report exported succesfully");
} catch(Throwable e) {