初始化:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
package com.pandy.birt; import com.pandy.birt.dto.AppException; import com.pandy.birt.dto.Report; import org.eclipse.birt.core.framework.IPlatformContext; import org.eclipse.birt.core.framework.Platform; import org.eclipse.birt.core.framework.PlatformServletContext; import org.eclipse.birt.report.engine.api.*; import org.springframework.beans.BeansException; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.web.context.ServletContextAware; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.util.*; public class BirtEngineFactory implements FactoryBean<IReportEngine>, ApplicationContextAware, ServletContextAware, DisposableBean { private ApplicationContext applicationContext; private static ServletContext servletContext; private IReportEngine birtEngine; private Map<String, IReportRunnable> reports = new HashMap<>(); @Override protected void finalize() throws Throwable { super.finalize(); EngineConfig config = new EngineConfig(); //注入Spring和Servlet环境 config.getAppContext().put("applicationContext", this.applicationContext); config.getAppContext().put("servletContext", this.servletContext); startupOSGI(config); IReportEngineFactory factory = (IReportEngineFactory) Platform .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY); this.birtEngine = factory.createReportEngine(config); loadReports();//载入报表 } } |
在rptdesign文件读取:
1 2 3 4 5 6 7 8 9 10 11 12 |
importPackage(Packages.org.springframework.context); importPackage(Packages.org.springframework.web.context.support ); //方式一: var sc = reportContext.getHttpServletRequest().getSession().getServletContext(); var applicationContext= WebApplicationContextUtils.getWebApplicationContext(sc); //方式二: var applicationContext = reportContext.getAppContext().get("applicationContext"); var servletContext = reportContext.getAppContext().get("servletContext"); var mypojo = applicationContext.getBean("carService"); this.text = mypojo.getAllCars().get(0).getMake(); |
在java代码读取:
1 2 3 |
//获取 ApplicationContext applicationContext =(ApplicationContext)runAndRenderTask.getAppContext().get("spring"); |
在Event Handler等监听器:好像无法做到