1 22 23 package org.efs.openreports.providers; 24 25 import java.util.logging.Level ; 26 27 import org.apache.log4j.Logger; 28 import org.eclipse.birt.core.exception.BirtException; 29 import org.eclipse.birt.core.framework.IPlatformContext; 30 import org.eclipse.birt.core.framework.Platform; 31 import org.eclipse.birt.core.framework.PlatformConfig; 32 import org.eclipse.birt.core.framework.PlatformFileContext; 33 import org.eclipse.birt.report.engine.api.EngineConfig; 34 import org.eclipse.birt.report.engine.api.HTMLActionHandler; 35 import org.eclipse.birt.report.engine.api.HTMLEmitterConfig; 36 import org.eclipse.birt.report.engine.api.HTMLServerImageHandler; 37 import org.eclipse.birt.report.engine.api.IReportEngine; 38 import org.eclipse.birt.report.engine.api.IReportEngineFactory; 39 import org.springframework.beans.factory.DisposableBean; 40 41 47 public class BirtProvider implements DisposableBean 48 { 49 protected static Logger log = Logger.getLogger(BirtProvider.class); 50 51 private static IReportEngine birtEngine = null; 52 53 public static synchronized IReportEngine getBirtEngine(String birtHome) 54 { 55 if (birtEngine == null) 56 { 57 log.info("Starting BIRT Engine and OSGI Platform"); 58 59 PlatformConfig platformConfig = new PlatformConfig(); 60 platformConfig.getBIRTHome(birtHome); 61 62 IPlatformContext context = new PlatformFileContext(platformConfig); 63 64 HTMLServerImageHandler imageHandler = new HTMLServerImageHandler(); 65 66 HTMLEmitterConfig emitterConfig = new HTMLEmitterConfig(); 67 emitterConfig.setActionHandler(new HTMLActionHandler()); 68 emitterConfig.setImageHandler(imageHandler); 69 70 EngineConfig config = new EngineConfig(); 71 config.setEngineHome(""); 72 config.setPlatformContext(context); 73 config.setLogConfig(null, Level.ALL); 74 config.getEmitterConfigs().put("html", emitterConfig); 75 76 try 77 { 78 Platform.startup(config); 79 } 80 catch (BirtException e) 81 { 82 log.error("BirtException", e); 83 } 84 85 IReportEngineFactory factory = (IReportEngineFactory) Platform 86 .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY); 87 88 birtEngine = factory.createReportEngine(config); 89 90 log.info("BIRT Engine Started"); 91 } 92 93 birtEngine.changeLogLevel(Level.SEVERE); 94 95 return birtEngine; 96 } 97 98 public void destroy() 99 { 100 if (birtEngine == null) return; 101 102 birtEngine.destroy(); 103 birtEngine.shutdown(); 104 Platform.shutdown(); 105 birtEngine = null; 106 107 log.info("BIRT Engine and OSGI Platform Shutdown"); 108 } 109 } 110
| Popular Tags
|