The sample BIRT viewer is optimized for use within Eclipse for the preview operation. When used outside Eclipse, it simply acts as an example of the application you might build to run and view reports. Your report viewer application must be in Java so that it has access to the BIRT engine. The viewer can also be deployed as an Eclipse plugin in an RCP application.
Because the RE API is the main API responsible for generating the reports, this article will focus on the available options for its deployment. Some of the most common deployment options are listed below:
Deploy the BIRT Viewer to a J2EE application server.
Create a servlet that wraps the RE API and deploy it to a J2EE application server.
Add the BIRT plugins to an existing Eclipse Rich Client Platform (RCP) application and use the BIRT Web Viewer plugin for generating and viewing reports.
Wrap the RE API in an existing RCP application.
Wrap the RE API in an existing Java application.
Wrapping the RE API within an existing Java application is described on the BIRT site. See Report Engine API for more details.
import java.util.HashMap;
import java.util.logging.Level;
import org.eclipse.birt.report.viewer.utilities.WebViewer;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportDocument;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.IRunTask;
import org.eclipse.birt.report.engine.ir.Report;
public class ExecuteReport {
static void executeReport() throws EngineException
{
String path = ("D:\\birt-runtime-2_2_1\\birt-runtime-2_2_1\\ReportEngine");
String path_logfile = ("d:\\birt\\logfiles");
IReportEngine engine=null;
EngineConfig config;
try{
config = new EngineConfig( );
config.setEngineHome( path );
config.setLogConfig(path_logfile, Level.ALL);
Platform.startup( config );
System.out.println("Platform.startup wurde durchgeführt");
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
engine.changeLogLevel( Level.WARNING );
System.out.println("nach Engine");
}catch( Exception ex){
System.out.println("EXCEPTION: ExecuteReport/executeReport");
ex.printStackTrace();
System.exit(0);
}
// run Reports *******************************************************************************************************
String name_rptdesign = "D:/apache-tomcat-5.5.25/apache-tomcat-5.5.25/webapps/birt-viewer/test.rptdesign";
String name_rptdocument = "D:/apache-tomcat-5.5.25/apache-tomcat-5.5.25/webapps/birt-viewer/test.rptdocument";
String name_output = "D:/apache-tomcat-5.5.25/apache-tomcat-5.5.25/webapps/birt-viewer/test.html";
// Methode die ein *.rptdocument generiert(geht)
//getIRunTask(name_rptdesign, name_rptdocument, engine);
//Open a report design - use design to modify design, retrieve embedded images etc.
IReportRunnable design = engine.openReportDesign(name_rptdesign);
//Create task to run the report and render the report
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
//Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setImageDirectory("image");
HashMap contextMap = new HashMap();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext );
task.setAppContext( contextMap );
//Set rendering options - such as file or stream output,
//output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();
//options.setOutputStream(System.out);
options.setOutputFileName(name_output);
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
task.setRenderOption(options);
task.run();
// ENDE run Reports **************************************************************************************************
// shut down engine
engine.shutdown();
Platform.shutdown();
}
private static void getIRunTask(String name_rptdesign, String name_rptdocument, IReportEngine engine) {
IReportRunnable design;
try {
design = engine.openReportDesign( name_rptdesign );
IRunTask task = engine.createRunTask(design);
task.run(name_rptdocument); //hier wird das *.rptdocument erzeugt
task.close();
} catch (EngineException e) {
System.out.println("EXCEPTION: ExecuteReport/getIRunTask");
e.printStackTrace();
System.exit(0);
}
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
System.out.println("Start <--");
executeReport( );
System.out.println("Ende <--");
System.exit(0);
}
catch ( Exception e )
{
System.out.println("EXCEPTION : ExecuteReport/Main");
e.printStackTrace();
System.exit(0);
}
}
}
Start <--
07.11.2007 11:36:43 org.eclipse.birt.report.data.oda.sampledb.SampledbPlugin start
INFO: Sampledb plugin starts up. Current startCount=0
07.11.2007 11:36:43 org.eclipse.birt.report.data.oda.sampledb.SampledbPlugin init
INFO: Creating Sampledb database at location C:\DOKUME~1\sm\LOKALE~1\Temp\/BIRTSampleDB_1194431803390_1ba94d
Platform.startup wurde durchgeführt
nach Engine
07.11.2007 11:36:46 org.eclipse.birt.report.engine.api.impl.EngineTask createContentEmitter
SCHWERWIEGEND: Report engine can not create html emitter.
EXCEPTION : ExecuteReport/Main
org.eclipse.birt.report.engine.api.EngineException: Report engine fails to initialize html emitter, please make sure required libraries for this emitter are installed.
at org.eclipse.birt.report.engine.api.impl.EngineTask.createContentEmitter(EngineTask.java:1105)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:88)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:68)
at ExecuteReport.executeReport(ExecuteReport.java:74)
at ExecuteReport.main(ExecuteReport.java:101)