*/
public ModelResponse execute(ModelRequest req) throws ModelException
{
ModelResponse res = req.createResponse();
Output outReport = res.createOutput("report");
res.add(outReport);
String backModel = req.getParameterAsString("backModel");
if (! StringTools.isEmpty(backModel))
{
Command cmd = res.createCommand(backModel);
cmd.setName("back");
cmd.setLabel("back");
res.add(cmd);
}
try
{
JasperPrint reportPrint = null;
if (req.getParameter("page") != null)
{
reportPrint = (JasperPrint) UserTools.getUserEnvObject(req, "currentReport");
}
String reportFormat = req.getParameterAsString("format");
if (reportPrint == null)
{
String reportName = req.getParameterAsString("report");
reportPrint = ReportTools.createReport("keel-dbpool", reportName, reportFormat, req, getClass());
UserTools.setUserEnvObject(req, "currentReport", reportPrint);
}
int page = NumberTools.toInt(req.getParameter("page"), 1);
if ("pdf".equals(reportFormat))
{
res.addOutput("contentType", "application/pdf");
res.addOutput("fileName", "Report.pdf");
ByteArrayOutputStream buf = new ByteArrayOutputStream();
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
exporter.exportReport();
outReport.setContent(buf.toByteArray());
}
else if ("csv".equals(reportFormat))
{
res.addOutput("contentType", "text/plain");
res.addOutput("fileName", "Report.csv");
ByteArrayOutputStream buf = new ByteArrayOutputStream();
JRExporter exporter = new JRCsvExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
exporter.exportReport();
outReport.setContent(buf.toByteArray());
}
else if ("csv".equals(reportFormat))
{
res.addOutput("contentType", "text/xml");
res.addOutput("fileName", "Report.xml");
ByteArrayOutputStream buf = new ByteArrayOutputStream();
JRExporter exporter = new JRXmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
exporter.exportReport();
outReport.setContent(buf.toByteArray());
}
else if ("xls".equals(reportFormat))
{
res.addOutput("contentType", "application/xls");
res.addOutput("fileName", "Report.xls");
ByteArrayOutputStream buf = new ByteArrayOutputStream();
JRExporter exporter = new JRXlsExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, buf);
exporter.exportReport();
outReport.setContent(buf.toByteArray());
}
else
{
StringBuffer buf = new StringBuffer();
JRExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, reportPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, buf);
exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, new Boolean(true));
exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(page - 1));
exporter.exportReport();
outReport.setContent(buf.toString());
createPageNavigationControls(req, res, page, reportPrint.getPages().size(), backModel);
}
}
catch (JRException x)