ReportExportOption exportOptions, Map<?,?> imagesMap, boolean inlineImages) throws ProviderException
{
JasperReportEngineOutput engineOutput = new JasperReportEngineOutput();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JRAbstractExporter exporter = null;
try
{
if (exportType == ExportType.PDF)
{
engineOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_PDF);
exporter = new JRPdfExporter();
}
else if (exportType == ExportType.XLS
|| exportType == ExportType.EXCEL)
{
engineOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_XLS);
if (exportType == ExportType.XLS)
{
exporter = new JRXlsExporter();
}
else if (exportType == ExportType.EXCEL)
{
exporter = new JExcelApiExporter();
}
exporter.setParameter(
JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
new Boolean(exportOptions.isXlsRemoveEmptySpaceBetweenRows()));
exporter.setParameter(JRXlsAbstractExporterParameter.IS_ONE_PAGE_PER_SHEET,
new Boolean(exportOptions.isXlsOnePagePerSheet()));
exporter.setParameter(JRXlsAbstractExporterParameter.IS_DETECT_CELL_TYPE,
new Boolean(exportOptions.isXlsAutoDetectCellType()));
exporter.setParameter(JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND,
new Boolean(exportOptions.isXlsWhitePageBackground()));
}
else if (exportType == ExportType.CSV)
{
engineOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_CSV);
exporter = new JRCsvExporter();
}
else if (exportType == ExportType.TEXT)
{
engineOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_TEXT);
exporter = new JRTextExporter();
exporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH,
new Integer(10));
exporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT,
new Integer(10));
}
else if (exportType == ExportType.RTF)
{
engineOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_RTF);
exporter = new JRRtfExporter();
}
else
{
engineOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_HTML);
exporter = new JRHtmlExporter();
exporter.setParameter(
JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
new Boolean(exportOptions.isHtmlRemoveEmptySpaceBetweenRows()));
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,
new Boolean(exportOptions.isHtmlUsingImagesToAlign()));
exporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND,
new Boolean(exportOptions.isHtmlWhitePageBackground()));
exporter.setParameter(JRHtmlExporterParameter.IS_WRAP_BREAK_WORD,
new Boolean(exportOptions.isHtmlWrapBreakWord()));
if (imagesMap == null) imagesMap = new HashMap<Object,Object>();
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
if (inlineImages)
{
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "cid:");
}
else
{
//see ImageLoaderAction for more information
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,
"imageLoader.action?imageName=");
}
//if embedded html, just include <div> tags instead of <html>,<header>, <body>, etc.
if (exportType == ExportType.HTML_EMBEDDED)
{
exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "<div>");
exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "</div>");
}
}
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporter.exportReport();
}
catch (Exception e)
{
throw new ProviderException(e.toString());
}