001: /*
002: * Copyright (C) 2006 by Open Source Software Solutions, LLC and Contributors
003: *
004: * This program is free software; you can redistribute it and/or modify it
005: * under the terms of the GNU General Public License as published by the Free
006: * Software Foundation; either version 2 of the License, or (at your option)
007: * any later version.
008: *
009: * This program is distributed in the hope that it will be useful, but WITHOUT
010: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
012: * more details.
013: *
014: * You should have received a copy of the GNU General Public License along with
015: * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
016: * Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: * Original Author : Roberto Nibali - rnibali@pyx.ch
019: * Contributor(s) : Erik Swenson - erik@oreports.com
020: *
021: */
022:
023: package org.efs.openreports.providers;
024:
025: import java.util.logging.Level;
026:
027: import org.apache.log4j.Logger;
028: import org.eclipse.birt.core.exception.BirtException;
029: import org.eclipse.birt.core.framework.IPlatformContext;
030: import org.eclipse.birt.core.framework.Platform;
031: import org.eclipse.birt.core.framework.PlatformConfig;
032: import org.eclipse.birt.core.framework.PlatformFileContext;
033: import org.eclipse.birt.report.engine.api.EngineConfig;
034: import org.eclipse.birt.report.engine.api.HTMLActionHandler;
035: import org.eclipse.birt.report.engine.api.HTMLRenderOption;
036: import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
037: import org.eclipse.birt.report.engine.api.IReportEngine;
038: import org.eclipse.birt.report.engine.api.IReportEngineFactory;
039: import org.springframework.beans.factory.DisposableBean;
040:
041: /**
042: * Provides the init and startup of the birt engine and config.
043: *
044: * @author Roberto Nibali
045: * @author Erik Swenson
046: *
047: */
048: public class BirtProvider implements DisposableBean {
049: protected static Logger log = Logger.getLogger(BirtProvider.class);
050:
051: private static IReportEngine birtEngine = null;
052:
053: @SuppressWarnings("unchecked")
054: public static synchronized IReportEngine getBirtEngine(
055: String birtHome) {
056: if (birtEngine == null) {
057: log.info("Starting BIRT Engine and OSGI Platform");
058:
059: PlatformConfig platformConfig = new PlatformConfig();
060: platformConfig.setBIRTHome(birtHome);
061:
062: IPlatformContext context = new PlatformFileContext(
063: platformConfig);
064:
065: HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();
066:
067: HTMLRenderOption emitterConfig = new HTMLRenderOption();
068: emitterConfig.setActionHandler(new HTMLActionHandler());
069: emitterConfig.setImageHandler(imageHandler);
070:
071: EngineConfig config = new EngineConfig();
072: config.setEngineHome("");
073: config.setPlatformContext(context);
074: config.setLogConfig(null, Level.ALL);
075: config.getEmitterConfigs().put("html", emitterConfig);
076:
077: try {
078: Platform.startup(config);
079: } catch (BirtException e) {
080: log.error("BirtException", e);
081: }
082:
083: IReportEngineFactory factory = (IReportEngineFactory) Platform
084: .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
085:
086: birtEngine = factory.createReportEngine(config);
087:
088: log.info("BIRT Engine Started");
089: }
090:
091: birtEngine.changeLogLevel(Level.SEVERE);
092:
093: return birtEngine;
094: }
095:
096: public void destroy() {
097: if (birtEngine == null)
098: return;
099:
100: birtEngine.destroy();
101: Platform.shutdown();
102: birtEngine = null;
103:
104: log.info("BIRT Engine and OSGI Platform Shutdown");
105: }
106: }
|