- 浏览: 38582 次
- 性别:
- 来自: 大连
文章分类
最新评论
BirtEngine.java
BIRT Report Engine configuration.
package com.samaxes.webreport.presentation; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import java.util.logging.Level; import javax.servlet.ServletContext; import org.eclipse.birt.core.exception.BirtException; 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.EngineConfig; import org.eclipse.birt.report.engine.api.IReportEngine; import org.eclipse.birt.report.engine.api.IReportEngineFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * BIRT Report Engine configuration. * * @author Samuel Santos * @version $Revision$ */ public class BirtEngine { private static final Logger logger = LoggerFactory.getLogger(BirtEngine.class); private static IReportEngine birtEngine = null; private static Level level = Level.OFF; private static String logDirectory = null; /** * Gets the BIRT Report Engine. * * @return the BIRT Report Engine */ public static IReportEngine getBirtEngine() { return birtEngine; } /** * Initialize BIRT Report Engine configuration. * * @param servletContext the ServletContext */ public static synchronized void initBirtEngine(ServletContext servletContext) { if (birtEngine == null) { loadEngineProps(); IPlatformContext context = new PlatformServletContext(servletContext); EngineConfig config = new EngineConfig(); config.setLogConfig(logDirectory, level); config.setEngineHome(""); config.setPlatformContext(context); config.setResourcePath(BirtEngine.class.getResource("/").getPath()); try { Platform.startup(config); } catch (BirtException e) { logger.error(e.getMessage(), e); } IReportEngineFactory factory = (IReportEngineFactory) Platform .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY); birtEngine = factory.createReportEngine(config); birtEngine.changeLogLevel(Level.WARNING); } } /** * Destroys the BIRT Report Engine. */ public static synchronized void destroyBirtEngine() { if (birtEngine != null) { birtEngine.destroy(); } Platform.shutdown(); } /** * Creates and returns a copy of this object. * * @return a clone of this instance. * @exception CloneNotSupportedException if the object's class does not support the <code>Cloneable</code> * interface. Subclasses that override the <code>clone</code> method can also throw this exception * to indicate that an instance cannot be cloned. */ public Object clone() throws CloneNotSupportedException { throw new CloneNotSupportedException(); } /** * Loads the Engone properties. */ private static void loadEngineProps() { try { // Config File must be in classpath ClassLoader cl = Thread.currentThread().getContextClassLoader(); Properties configProps = new Properties(); InputStream in = null; in = cl.getResourceAsStream("BirtConfig.properties"); configProps.load(in); in.close(); String logLevel = configProps.getProperty("logLevel"); if ("SEVERE".equalsIgnoreCase(logLevel)) { level = Level.SEVERE; } else if ("WARNING".equalsIgnoreCase(logLevel)) { level = Level.WARNING; } else if ("INFO".equalsIgnoreCase(logLevel)) { level = Level.INFO; } else if ("CONFIG".equalsIgnoreCase(logLevel)) { level = Level.CONFIG; } else if ("FINE".equalsIgnoreCase(logLevel)) { level = Level.FINE; } else if ("FINER".equalsIgnoreCase(logLevel)) { level = Level.FINER; } else if ("FINEST".equalsIgnoreCase(logLevel)) { level = Level.FINEST; } else if ("ALL".equalsIgnoreCase(logLevel)) { level = Level.ALL; } logDirectory = configProps.getProperty("logDirectory"); } catch (IOException e) { logger.error(e.getMessage(), e); } }
WebReportActionBean.java
Actions related to the reports generation.
package com.samaxes.webreport.presentation.action; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import net.sourceforge.stripes.action.ActionBean; import net.sourceforge.stripes.action.ActionBeanContext; import net.sourceforge.stripes.action.DefaultHandler; import net.sourceforge.stripes.action.Resolution; import net.sourceforge.stripes.action.StreamingResolution; import org.eclipse.birt.report.engine.api.EngineConstants; import org.eclipse.birt.report.engine.api.EngineException; import org.eclipse.birt.report.engine.api.HTMLRenderOption; import org.eclipse.birt.report.engine.api.HTMLServerImageHandler; import org.eclipse.birt.report.engine.api.IHTMLRenderOption; import org.eclipse.birt.report.engine.api.IPDFRenderOption; import org.eclipse.birt.report.engine.api.IRenderOption; import org.eclipse.birt.report.engine.api.IReportEngine; import org.eclipse.birt.report.engine.api.IReportRunnable; import org.eclipse.birt.report.engine.api.IRunAndRenderTask; import org.eclipse.birt.report.engine.api.PDFRenderOption; import org.eclipse.birt.report.engine.api.RenderOption; import org.eclipse.birt.report.model.api.DesignElementHandle; import org.eclipse.birt.report.model.api.activity.SemanticException; import com.samaxes.webreport.entities.WebReportEntity; import com.samaxes.webreport.presentation.BirtEngine; /** * Actions related to the reports generation. * * @author Samuel Santos * @version $Revision$ */ public class WebReportActionBean implements ActionBean { private ActionBeanContext context; public ActionBeanContext getContext() { return context; } public void setContext(ActionBeanContext context) { this.context = context; } /** * Generates the html report. * * @return forward to the jsp page * @throws EngineException when opening report design or reunning the report * @throws SemanticException when changing properties of DesignElementHandle */ @DefaultHandler public Resolution htmlReport() throws EngineException, SemanticException { ByteArrayOutputStream reportOutput = new ByteArrayOutputStream(); // set output options IHTMLRenderOption options = new HTMLRenderOption(); options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML); options.setOutputStream(reportOutput); options.setEmbeddable(true); options.setBaseImageURL(context.getRequest().getContextPath() + "/images"); options.setImageDirectory(context.getServletContext().getRealPath("/images")); options.setImageHandler(new HTMLServerImageHandler()); options.setMasterPageContent(false); generateReport(options); return new StreamingResolution("text/html", new ByteArrayInputStream(reportOutput.toByteArray())); } /** * Generates the PDF report. * * @return PDF file with the report output * @throws EngineException when opening report design or reunning the report * @throws SemanticException when changing properties of DesignElementHandle */ public Resolution pdfReport() throws EngineException, SemanticException { ByteArrayOutputStream reportOutput = new ByteArrayOutputStream(); // set output options IPDFRenderOption options = new PDFRenderOption(); options.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF); options.setOutputStream(reportOutput); generateReport(options); return new StreamingResolution("application/pdf", new ByteArrayInputStream(reportOutput.toByteArray())) .setFilename("WebReport.pdf"); } /** * Generates the Excel report. * * @return Excel file with the report output * @throws EngineException when opening report design or reunning the report * @throws SemanticException when changing properties of DesignElementHandle */ public Resolution xlsReport() throws EngineException, SemanticException { ByteArrayOutputStream reportOutput = new ByteArrayOutputStream(); // set output options IRenderOption options = new RenderOption(); options.setOutputFormat("xls"); options.setOutputStream(reportOutput); generateReport(options); return new StreamingResolution("application/vnd.ms-excel", new ByteArrayInputStream(reportOutput.toByteArray())) .setFilename("WebReport.xls"); } /** * Generates the Word report. * * @return Excel file with the report output * @throws EngineException when opening report design or reunning the report * @throws SemanticException when changing properties of DesignElementHandle */ public Resolution docReport() throws EngineException, SemanticException { ByteArrayOutputStream reportOutput = new ByteArrayOutputStream(); // set output options IRenderOption options = new RenderOption(); options.setOutputFormat("doc"); options.setOutputStream(reportOutput); generateReport(options); return new StreamingResolution("application/vnd.ms-word", new ByteArrayInputStream(reportOutput.toByteArray())) .setFilename("WebReport.doc"); } /** * Generates the Powerpoint report. * * @return Excel file with the report output * @throws EngineException when opening report design or reunning the report * @throws SemanticException when changing properties of DesignElementHandle */ public Resolution pptReport() throws EngineException, SemanticException { ByteArrayOutputStream reportOutput = new ByteArrayOutputStream(); // set output options IRenderOption options = new RenderOption(); options.setOutputFormat("ppt"); options.setOutputStream(reportOutput); generateReport(options); return new StreamingResolution("application/vnd.ms-powerpoint", new ByteArrayInputStream(reportOutput .toByteArray())).setFilename("WebReport.ppt"); } /** * Generates the Postscript report. * * @return Excel file with the report output * @throws EngineException when opening report design or reunning the report * @throws SemanticException when changing properties of DesignElementHandle */ public Resolution psReport() throws EngineException, SemanticException { ByteArrayOutputStream reportOutput = new ByteArrayOutputStream(); // set output options IRenderOption options = new RenderOption(); options.setOutputFormat("postscript"); options.setOutputStream(reportOutput); generateReport(options); return new StreamingResolution("application/postscript", new ByteArrayInputStream(reportOutput.toByteArray())) .setFilename("WebReport.ps"); } /** * Generates the report output. * * @return the report output * @throws EngineException when opening report design or reunning the report * @throws SemanticException when changing properties of DesignElementHandle */ private void generateReport(IRenderOption options) throws EngineException, SemanticException { // this list simulates a call to the application business logic List<webReportEntity> webReportEntities = new ArrayList<webReportEntity>(); webReportEntities.add(new WebReportEntity(new Double(2), "Product1")); webReportEntities.add(new WebReportEntity(new Double(4), "Product2")); webReportEntities.add(new WebReportEntity(new Double(7), "Product3")); // get the engine IReportEngine birtReportEngine = BirtEngine.getBirtEngine(); // open the report design IReportRunnable design = birtReportEngine.openReportDesign(context.getServletContext().getRealPath("/reports") + "/webReport.rptdesign"); // create task to run and render report IRunAndRenderTask task = birtReportEngine.createRunAndRenderTask(design); @SuppressWarnings("unchecked") Map<string, Object> appContext = task.getAppContext(); DesignElementHandle reportChart = task.getReportRunnable().getDesignHandle().getModuleHandle().findElement( "reportChart"); appContext.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, WebReportActionBean.class.getClassLoader()); appContext.put("webReportEntities", webReportEntities); reportChart.setProperty("dataSet", "Scripted Data Set"); // change the chart dataset task.setLocale(context.getLocale()); task.setRenderOption(options); task.setAppContext(appContext); // run report task.run(); task.close(); } }
发表评论
-
jdbc连接各数据库及事务处理
2012-11-17 10:29 905jdbc连接各数据库及事务 ... -
Java Properties 类读取配置文件
2012-08-16 16:35 640package jp.co.test.common.utils ... -
BIRT 保存为PDF
2011-09-08 11:11 809public class PDFReportServiceAc ... -
Birt报表三大引擎的启动
2011-09-08 11:07 963// Design Engine Sample: ... -
Java 生成 XML文件
2011-06-09 11:36 976Java 生成 XML文件 package test; ... -
使用SAX解析XML文件
2011-06-07 13:43 659<?xml version="1.0" ... -
Eclipse中的一些特殊的注释技术
2011-05-12 14:04 684Eclipse中的一些特殊的注释技术包括: 1. // ... -
访问不同的URL地址
2011-04-14 14:12 921import java.io.BufferedReader; ...
相关推荐
1、 webcontent/birt/layout文件里面 具体路径为:webcontent/birt/pages/layout下 分别在这FramesetFragment.jsp 、RequesterFragment.jsp、RunFragment.jsp 3个文件的头部里面也就是<head>加上 <META ...
【Birt 4.2 学习手册】是针对新手入门的一份培训文档,主要涵盖了Birt 4.2的环境搭建、组件学习和脚本编写等基础内容。Birt是一个开源的报告生成工具,它集成在Eclipse环境中,允许开发者创建复杂的报表和数据分析。...
birt-runtime 2.5 网址:http://download.eclipse.org/birt/downloads/ 下载后解压,将birt-runtime-2_5_1\WebViewerExample\WEB-INF中的lib,platform两个文件夹copy到eclipse中的相应的两个文件夹中..能过eclipse发布...
3. 输入 BIRT 更新站点的 URL([http://download.eclipse.org/tools/birt/updates](http://download.eclipse.org/tools/birt/updates))。 4. 选择所需的 BIRT 组件进行安装。 #### 结论 BIRT 提供了一套完整的...
6. **BIRT演示**:http://download3.eclipse.org/birt/downloads/demos/MyFirstReport.html 通过以上步骤,您可以快速上手BIRT,开始设计和部署自己的报表。随着对BIRT的深入了解,您还可以探索更多高级功能,实现...
"birt-report-framework"是一个基于Java的开源报表系统,由Eclipse基金会开发并维护,主要用于创建、设计和展示复杂的业务报告。BIRT全称为Business Intelligence and Reporting Tools,它提供了丰富的图表、表格和...
1:去/WebViewerExample/WEB-INF/lib下找到名为“viewservlets.jar”的jar包,使用压缩工具打开(不用解压),进入/org/eclipse/birt/report/resource目录,这里会发现一个Messages.properties文件,这个就是birt...
**本插件,即“birt-report-framework”,是Eclipse集成开发环境(IDE)中的一个关键组件,用于帮助开发者创建、设计和实现复杂的业务报表。在Eclipse中安装此插件后,开发者可以充分利用其功能,无需离开熟悉的IDE...
在`http://download.eclipse.org/birt/downloads`上,根据你的Eclipse版本选择对应的BIRT Framework和Runtime包。例如,如果你的Eclipse是3.2版,那么BIRT的版本可能是2.1M5。下载这两个包并进行解压。 1. **框架...
- prototype.js v1.4.0 – 将prototype.js文件复制到`plugins/org.eclipse.birt.report.viewer_version/birt/ajax/lib`目录。 ##### 其他资源 - **安装演示**:BIRT提供的一个Flash格式的安装演示视频,可以参考...
"Eclipse BIRT Chart Engine Example Resource Code" 提供的是一个示例资源代码库,帮助开发者更好地理解和使用BIRT图表引擎。 **BIRT图表引擎核心概念:** 1. **图表引擎**:这是BIRT的核心组件之一,负责生成...
3. **PDF处理库**:`itext-1.4.1.jar`需放置于`%TOMCAT_HOME%/webapps/birt/plugins/org.eclipse.birt.report.engine.emitter.pdf/lib`目录下,以便在Web环境下也能支持PDF格式的报表输出。 **二、BIRT初次接触** ...
<script src="birt/ajax/utility/Calendar.js" type="text/javascript"></script> 3、修改TextBoxParameterFragment.jsp 在textbox中加入onclick事件 (encodedParameterName.indexOf("Time")>=0) {%> onclick=...
这可以通过修改/WebRoot/report-viewer/birt/pages/control/ToolbarFragment.jsp文件来实现。例如,增加中文提示,替换或调整图标,以便更好地符合用户的使用习惯。图三展示了经过修改后的直观界面。 此外,美化...
从`NLpack1-birt-runtime-2_5_0.zip`中找到`ReportEngine`文件夹下的`plugins`文件夹中的`org.eclipse.birt.report.viewer.nl1_2.5.0.v20090730-1349.jar`,然后从中提取`org/eclipse/birt/report/resource/Messages...
eclipse开发报表的插件birt 只是一个插件,安装方法和其它eclipse插件一样
<script src="birt/ajax/core/BirtSoapResponse.js" type="text/javascript"></script>, 再下面加上 <script src="<%= baseHref %>/ajax/utility/My97DatePicker/WdatePicker.js" type="text/javascript"></script>...