Connection conn = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
CloseableTableModel model = null;
try
{
Report report = input.getReport();
Map parameters = input.getParameters();
ReportDataSource dataSource = report.getDataSource();
conn = dataSourceProvider.getConnection(dataSource.getId());
if (parameters == null || parameters.isEmpty())
{
pStmt = conn.prepareStatement(report.getQuery());
}
else
{
// Use JasperReports Query logic to parse parameters in chart
// queries
JRDesignQuery query = new JRDesignQuery();
query.setText(report.getQuery());
// convert parameters to JRDesignParameters so they can be
// parsed
Map jrParameters = ORUtil.buildJRDesignParameters(parameters);
pStmt = JRQueryExecuter.getStatement(query, jrParameters, parameters, conn);
}
ORProperty maxRows = propertiesProvider.getProperty(ORProperty.QUERYREPORT_MAXROWS);
if (maxRows != null && maxRows.getValue() != null)
{
pStmt.setMaxRows(Integer.parseInt(maxRows.getValue()));
}
rs = pStmt.executeQuery();
model = ResultSetTableModelFactory.getInstance().createTableModel(rs);
ReportGenerator generator = ReportGenerator.getInstance();
JFreeReport jfreeReport = generator.parseReport(directoryProvider
.getReportDirectory()
+ report.getFile());
jfreeReport.setData(model);
ReportEngineOutput output = new ReportEngineOutput();
if (input.getExportType() == ExportType.PDF)
{
output.setContentType(ReportEngineOutput.CONTENT_TYPE_PDF);
PDFReportUtil.createPDF(jfreeReport, out);
}
else if (input.getExportType() == ExportType.XLS)
{
output.setContentType(ReportEngineOutput.CONTENT_TYPE_XLS);
ExcelProcessor pr = new ExcelProcessor(jfreeReport);
pr.setStrictLayout(false);
pr.setDefineDataFormats(true);
pr.setOutputStream(out);
pr.processReport();
}
else if (input.getExportType() == ExportType.RTF)
{
output.setContentType(ReportEngineOutput.CONTENT_TYPE_RTF);
RTFProcessor pr = new RTFProcessor(jfreeReport);
pr.setStrictLayout(false);
pr.setOutputStream(out);
pr.processReport();
}
else //default to HTML
{
output.setContentType(ReportEngineOutput.CONTENT_TYPE_HTML);
HtmlProcessor pr = new HtmlProcessor(jfreeReport);
pr.setStrictLayout(false);
pr.setGenerateXHTML(true);
pr.setFilesystem(new StreamHtmlFilesystem(out));
pr.processReport();
}
output.setContent(out.toByteArray());
return output;
}
catch (Exception e)
{
throw new ProviderException(e);
}
finally
{
try
{
if (model != null) model.close();
if (out != null) out.close();
}
catch (Exception e)
{
log.warn(e.toString());