Project Wiki
Views

Adding an exporter

From Wiki

Jump to: navigation, search

Adding a new exporter, step-by-step:

If we need only to view a report in a new format (let's say it XML format), one should achieve these steps first:

  1. A new exporter class should be written in the com.jaspersoft.jasperserver.war.action package. This new class has to extend the AbstractReportExporter class and implement its abstract methods. If you have to pass export parameters, see for example the ReportExcelExporter class, otherwise take a look at ReportRtfExporter.
  2. Configure the new exporter in the WEB-INF/flows/viewReportBeans.xml file.
    1. Create the associated reportXxxExporter bean (let's name it reportXmlExporter). If you have to communicate some export parameters, declare your bean as in reportExcelExporter, otherwise, declare it as in reportRtfExporter bean.
    2. Create an associated xxxExporterConfiguration bean, as in xlsExporterConfiguration (having a non empty export parameters map) or rtfExporterConfiguration (where this map is empty). In order to internationalize labels, use resource bundles when set the descriptionKey attribute. Get a new and appropriate icon image for the new exporter, and set the iconSrc attribute with the path to this icon.
      • If you have to pass some export parameters, then you have to configure them in the applicationContext.xml file first. The applicationContext.xml is chosen because the export parameters are shared between report viewing and report scheduling jobs. Take a look at xlsExportParameters bean in this xml file.
    3. In the viewReportBeans.xml file add a new entry in the exporterConfigMap bean, containing a reference to the new xxxExporterConfiguration bean you created. It's recommended to use the file type extension as key in this map (i.e for the XML exporter use key="xml").

That's all, now we can view the report in a new format. After rebuild and restart, a new icon will appear in the report detail page, and clicking on this icon will open the appropriate report viewer for this format.

In order to schedule a report, one have to continue the steps above with the next ones:

  1. In the ReportJob class you have to add a new static output format constant, let's name it OUTPUT_FORMAT_XML.
  2. In the ContentResource class add a new export type constant, e.g. TYPE_XML
  3. In the ReportJobEditAction modify the getOutputFormats() method body by adding a new element containing the desired output type
  4. Finally, in the ReportExecutionJob:
    1. Modify the getReportOutput(...) method body by introducing a new case block associated with your new output format.
    2. Create the getXxxOutput() method called by the case block you introduced above (i.e. getXmlOutput() method)

After all these steps, you'll be able to schedule the report as you wish. The option for the report format will appear in the scheduled reporting screens, and can be set in web services.

(Original contributor: Sanda Zaharia 6/24/2008)