Welcome!

Open Source Authors: Matt Hester, Pat Romanski, Liz McMillan, Elizabeth White, Jnan Dash

Related Topics: Open Source, Linux, Eclipse

Open Source: Article

Developing an Application Using the Eclipse BIRT Report Engine API

Provide report generation and rendering services

The Eclipse platform is an open source, integrated system of application development tools that you implement and extend using a plug-in interface. The Eclipse Business Intelligence Reporting Tool (BIRT) is a set of plug-in extensions that enable a developer to add reporting functionality to an application. BIRT provides a Report Engine API that a developer can use to create a customized report generator application. The org.eclipse.birt.report.engine.api package contains a set of interfaces and implementation classes that supports integrating the runtime part of BIRT into an application.

The BIRT Report Engine can provide report generation and rendering services in the following environments:

  • Stand-alone engine: A Java developer uses a stand-alone engine to render a BIRT report from a report design (.rptdesign) file. In this environment, the Java developer creates a command-line application that writes a report to disk, either in HTML or PDF format.
  • BIRT report viewer: BIRT Report Designer uses the BIRT report viewer to view a report as paginated HTML. The BIRT report viewer is a Web application that runs in the Tomcat Application Server embedded in Eclipse. This viewer contains an embedded BIRT report engine.
  • Customized report designer: A customized report design environment uses an embedded BIRT report engine to preview a report.
  • Web application: A Web application similar to the BIRT report viewer uses an embedded BIRT report engine to generate a Web-based report.
This article describes how to develop a customized report generation application that performs the following tasks:
  • Creates and configures a report engine
  • Opens a report design or report document
  • Accesses data from a data source
  • Generates a report in a supported output format
  • Shuts down the engine
Creating and Configuring a Report Engine
The main interfaces and classes in the org.eclipse.birt.report.engine.api package are:
  • ReportEngine
  • EngineConfig
  • IReportRunnable
  • IRenderOption and its descendants
  • IEngineTask and its descendants
A report engine is an instantiation of the ReportEngine class. This object is the key component in any reporting application. It provides access to runnable report designs, parameters, the structure of a report design, and the task for generating a report from a report design. You can use the ReportEngine object to perform the following tasks:
  • Get a configuration object.
  • Open a report design or a report document.
  • Create an engine task to get parameter definitions and set parameter values.
  • Create an engine task to access data from a data set.
  • Get supported report formats and MIME types.
  • Create an engine task to run a report or render a report to an output format.
  • Create an engine task to extract data from a report document.
  • Clean up and shut down the engine.
A single report engine object can generate multiple reports from multiple report designs. Each application, whether it's stand-alone or Web-based, only needs to create one ReportEngine instance. The BIRT report engine is thread-safe, so this single-instance recommendation is not a restriction. At termination, the application should call shutdown( ) to unload extensions and delete temporary files.

The EngineConfig class contains the configuration settings for the report engine. Use the EngineConfig object to specify the settings for the following properties:

  • HTML emitter configuration for custom handling of images or actions for HTML output
  • Logging to set the logging file location and level
  • Platform context to indicate whether the application and engine home are in a stand-alone environment or packaged as a WAR file
  • Resource files to set the location where the reporting application can access libraries and properties files
  • Scripting configuration to provide external values and Java resources to scripting methods
The engine home is the key property that the report engine requires. The report engine cannot parse the report design or run the report without a defined engine home. For a stand-alone application, the engine home is an absolute path to a file system location. For an application running from a WAR file on an application server, the engine home is a relative path in the WAR file.

Two engine configuration properties depend on whether the environment in which the application runs is stand-alone or in a WAR file on an application server. These properties are the platform context and the HTML emitter configuration. The platform context provides the report engine with the mechanism to access files. The HTML emitter configuration provides the functionality for processing images and handling hyperlinking and bookmark actions.

A ReportEngine constructor takes the EngineConfig object as its argument. If the configuration object is null, the report engine uses the default configuration. If the configuration object is null, the environment must provide a BIRT_HOME variable that specifies the directory containing the engine plug-ins and JAR files.

Listing 1 shows how to set up a report engine in a stand-alone application. The application uses the engine home located in the BIRT runtime directory. The report output format is HTML. The application configures the HTML emitter and creates the report engine using the settings contained in the EngineConfig object.

Opening a Report Design or Report Document
BIRT Report Engine can generate a report from either a report design or an existing report document. To open a report design, call one of the openReportDesign( ) methods on ReportEngine. These methods instantiate an IReportRunnable object using a String object that specifies the path to a report design or an input stream.

To open a report document, call the ReportEngine.openReportDocument( ) method. This method instantiates an IReportDocument object using a String object that specifies the path to a report document (.rptdocument) file. This method returns the IReportDocument object. You must handle the EngineException that these methods throw.

The IReportRunnable object provides direct access to basic properties of the report design. The names of report design properties are static String fields, such as IReportRunnable.AUTHOR. To access a report design property, use the getProperty( ) method with a string argument that contains one of these fields.

To access and set the values of parameters, use methods on a parameter definition task object, described later in this article. Listing 2 shows how to open a report design and find a property value. If the engine cannot open the specified report design, the code shuts down the engine. The variable, engine, is a ReportEngine object.

The IReportDocument object provides access to the data in a report and the report's structure. IReportDocument provides methods to retrieve table of content entries, bookmarks, and page information.

To access table of content entries, use the findTOC( ) method. This method takes a TOCNode argument and returns a TOCNode object. To find the root table of contents entry, use a null argument. To find the subentries of a table of contents entry, use the getChildren( ) method. This method returns a list of TOCNode objects. From a TOCNode object, you can retrieve the display value of the entry and a Bookmark object.


More Stories By Jason Weathersby

Jason Weathersby is a member of the extended BIRT development team at Actuate Corporation and has backgrounds in both computer science and technical writing. He has many years experience in technical consulting, training, writing, and publishing about reporting, business intelligence tools, and database technologies.

More Stories By Tom Bondur

Tom Bondur is a member of the extended BIRT development team at Actuate Corporation and has backgrounds in both computer science and technical writing. He has many years experience in technical consulting, training, writing, and publishing about reporting, business intelligence tools, and database technologies.

More Stories By Jane Tatchell

Jane Tatchell is a content development manager in the Developer Communications group of Actuate Engineering.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.