/******************************************************************************* * Copyright (c) 2004 Actuate Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * Contributors: * Actuate Corporation - initial API and implementation *******************************************************************************/ import java.util.logging.Level; import org.eclipse.birt.core.framework.Platform; import org.eclipse.birt.report.engine.api.EmitterInfo; import org.eclipse.birt.report.engine.api.EngineConfig; import org.eclipse.birt.report.engine.api.IRenderOption; 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.RenderOption; public class ExecuteCvsReport { static void executeReport() throws Exception { IReportEngine engine=null; EngineConfig config = null; //Configure the Engine and start the Platform config = new EngineConfig( ); config.setEngineHome( "C:/java/birt-runtime-2_2_0/ReportEngine" ); //set log config using ( null, Level ) if you do not want a log file config.setLogConfig("c:/birt/logs", Level.FINE); //start the Platform to load the appropriate plug-ins Platform.startup( config ); //get the factory from the platform IReportEngineFactory factory = (IReportEngineFactory) Platform .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY ); //create the engine engine = factory.createReportEngine( config ); engine.changeLogLevel( Level.WARNING ); //Open a report design - use design to modify design, retrieve embedded images etc. IReportRunnable design = engine.openReportDesign("reports/csvTest.rptdesign"); //Create task to run the report - use the task to execute and run the report, IRunAndRenderTask task = engine.createRunAndRenderTask(design); //INFO: to see if your emitter is available. // the emitter needs to be in a jar file in the following location // $BIRT_RUNTIME_HOME/ReportEngine/plugins // I have found that the name of the jar is not important. System.out.println("EMITTERS"); EmitterInfo[] emitters = engine.getEmitterInfo(); String emitterId = ""; for (int i = 0; i < emitters.length; i++) { System.out.println(emitters[i].getFormat()); if ("CVS".equalsIgnoreCase(emitters[i].getFormat())){ emitterId = emitters[i].getID(); System.out.println("ID = " + emitterId); } } System.out.println("FORMATS"); String[] formats = engine.getSupportedFormats(); for (int i = 0; i < formats.length; i++) { System.out.println(formats[i]); } // Create a render option and setup appropriately IRenderOption cvsOption = new RenderOption(); cvsOption.setOutputFormat("CVS"); cvsOption.setOutputFileName("test_cvs.cvs"); task.setRenderOption(cvsOption); //task.setRenderOption(cvsOption); task.setEmitterID(emitterId); //run the report and destroy the engine task.run(); task.close(); // Shut down the engine. engine.shutdown(); Platform.shutdown(); System.out.println("We are done!!!"); } /** * @param args */ public static void main(String[] args) { try { executeReport( ); } catch ( Exception e ) { e.printStackTrace(); } } }