Programming using the BIRT Reporting APIs : Generating reports from an application : Setting up the report engine : How to set up a report engine as a web application
 
How to set up a report engine as a web application
1 Set up the platform context, as shown in Listing 12‑2.
Listing 12‑2 Setting up the platform context for WAR file deployment
// Example class to create the report engine
public class BirtEngine
{
private static IReportEngine birtEngine = null;
 
public static synchronized IReportEngine
getBirtEngine( ServletContext sc )
{
if (birtEngine == null) {
EngineConfig config = new EngineConfig( );
config.setBIRTHome( "" );
IPlatformContext context = new PlatformServletContext( sc );
config.setPlatformContext( context );
try
{
Platform.startup( config );
IReportEngineFactory factory = ( IReportEngineFactory )Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
birtEngine = factory.createReportEngine( config );
}
catch ( Exception e ) { e.printStackTrace( ); }
}
return birtEngine;
}
}
2 Set up further configuration options on the engine after instantiating the class, as shown in Listing 12‑3.
Listing 12‑3 Setting up HTML options for WAR file deployment
// In a different class, get the report engine
IReportEngine reportEngine = BirtEngine.getBirtEngine( request.getSession( ).getServletContext( ));
// Set up the engine
EngineConfig config = reportEngine.getConfig( );
HTMLRenderOption ho = new HTMLRenderOption( );
ho.setImageHandler( new HTMLServerImageHandler( ));
ho.setImageDirectory("output/image");
ho.setBaseImageURL("http://myhost/prependme?image=");
config.setEmitterConfiguration
( RenderOption.OUTPUT_FORMAT_HTML, ho );
In this listing, request is an HttpServletRequest object.