Report Template-Based Programming

Although it is possible to create an entire report programmatically (using just the InetSoft API), the recommended approach is to use the Report Designer to create the report in its entirety.

If you need to bind the data programmatically, first create the report template layout in the Report Designer, load it as a ReportSheet object into a Java program and then use the data binding API to bind data to the report elements.

All operations such as page set-up, presentation, formatting, grouping and summarization, group ranking, etc., should be performed at the template level using the Report Designer. Extracting data from the data sources, creating the appropriate 'Lens' objects, and binding them to the report elements should be done programmatically only if required.

Note: Before calling any InetSoft API function programmatically, first specify the location of the registry directory (SREE Home). To do this from within your program, use the following syntax:

System.setProperty("sree.home", "{path to registry}"); 

To do this from the command line (for example, when running a program named “ProgramName”), use the following syntax:

java -Dsree.home="{path to registry}" ProgramName

Importing Report Templates

To use a report template in a Java program, the first step is to create a ReportSheet object from the template file. The Builder class in the inetsoft.report.io package handles this.

Builder builder = Builder.getBuilder(Builder.TEMPLATE, 
new FileInputStream(“report1.srt”)); 
ReportSheet report = builder.read(“.”); 

If the template is not stored in the correct format, an Exception will be returned and it should be properly handled.

The argument to the Builder.read() is a directory which is used to calculate the image paths if relative file paths are used in the template to specify the image file locations. If no image is used in the report, then the directory can be passed with any value.

Report templates can be loaded from a remote site through a URL. To do this, simply get an input stream object from a URL and the builder will read the template information from the remote server pointed to by the URL:

 URL url = new URL(“http://…”);
 Builder builder = Builder.getBuilder(Builder.TEMPLATE, url.openStream());
 ReportSheet report = builder.read("."); 

The directory passed into the read() call is ignored in this case, so the template cannot use any local files for image elements.

Perhaps the most flexible way to import a template file is by loading the file in as a resource file. This allows the template files to be packaged as part of the application JAR file or together in the class file directory tree. Once the CLASSPATH is properly setup, resource files can be located by the Java class loader in the same way as other class files. This enables the templates to be used independent of the location of the installation.

 InputStream input =
  getClass().getResourceAsStream("/templates/report1.srt");
 Builder builder =
  Builder.getBuilder(Builder.TEMPLATE, input);
 ReportSheet report = builder.read("."); 
Previous: Programming Reports