第十五章 高级特性-开放源码:BIRT报表CVS构建

15.1 使用CVS构建BIRT报表设计器和引擎

BIRT报表提供了在设计阶段开放脚本编辑器,添加javascript和java事件机制来扩展报表的使用,另外还提供了包括数据源,数据项,聚合函数,数据展示,数据导出等等一系列的扩展接口,这对于一般的用户来实现丰富多彩的报表已经足矣。不过BIRT报表作为开源社区报表类别使用率最大的报表框架,开放源代码以及组织良好的源码和类库功不可没。这对于想深度定制报表功能的用户是个很大的福音。

使用CVS构建BIRT报表设计器和引擎在官网上有一个详细的介绍,地址如下:

http://www.eclipse.org/birt/phoenix/build/buildInstructions.php

大概的步骤如下:

首先用Eclipse连上BIRTCVS

填写地址路径用户名端口等信息:

Host

dev.eclipse.org

Repository path

/cvsroot/birt

User

anonymous

Connection type

pserver

Use Default Port

Selected

CVS文件夹下 / home / BIRT BIRT模块。BIRT有超过150个模块,其中的一些描述如下。

项目文件夹

内容

org.eclipse.birt.chart.device.extension

扩展类的设备渲染架构的图表

org.eclipse.birt.chart.engine

图表模型和工厂类

org.eclipse.birt.chart.engine.extension

扩展类的模型渲染架构的图表

org.eclipse.birt.chart.reportitem

BIRT报表设计器和运行时引擎的图表模块的类进行交互

org.eclipse.birt.chart.shared

图表模块的不同组件之间的共享的类

org.eclipse.birt.chart.ui

图表生成器UI

org.eclipse.birt.chart.ui.extension

图表生成器UI的扩展

org.eclipse.birt.chart.device.extension

图表引擎扩展插件包含设备的渲染器实现(的SwingSWTPNGGIFJPGBMP

org.eclipse.birt.chart.device.svg

图表引擎扩展插件的渲染器实现SVG装置

org.eclipse.birt.converters

包含转换器,可以转换成其他格式的报告,的BIRT报表格式的

org.eclipse.birt.core

加载插件在运行时提供了一个框架,并包含其他类,它们可用于由任何其他模块

org.eclipse.birt.data

提供的数据引擎执行情况和官方发布的工厂实现。它也包含类应用的数据转换。

org.eclipse.birt.data.oda

官方发布的公共接口:用于创建数据扩展的类和接口。

org.eclipse.birt.data.oda.adapter.dtp

适配器的数据工具项目

org.eclipse.birt.report.data.oda.flatfile

官方发布的访问平面文件数据源驱动程序

org.eclipse.birt.report.data.oda.flatfile.ui

官方发布的平面文件驱动器的用户界面

org.eclipse.birt.data.oda.jdbc

官方发布JDBC驱动程序

org.eclipse.birt.data.oda.jdbc.ui

官方发布JDBC驱动程序的用户界面

org.eclipse.birt.report.data.oda.sampledb

官方开发的示例数据库驱动程序

org.eclipse.birt.report.data.oda.sampledb.ui

官方开发的示例数据库驱动程序的用户界面

org.eclipse.birt.data.oda.xml

ODA驱动程序来访问XML数据源

org.eclipse.birt.data.oda.xml.ui

ODA驱动程序来访问XML数据源的用户界面

org.eclipse.birt.report.debug.ui

用于创建启动配置调试包含Java事件的报告时

org.eclipse.birt.report.designer.core

核心类的BIRT报表设计器,包括的BIRT模型的类互动,本地化和其他实用工具类

org.eclipse.birt.report.designer.lib

用于库操作的类

org.eclipse.birt.report.designer.lib.explorer

处理库内容的浏览和探索

org.eclipse.birt.report.designer.ui

BIRT报表设计器

org.eclipse.birt.report.designer.ui.rcp

BIRT RCP报告设计器

org.eclipse.birt.report.engine

BIRT报表引擎,生成报表的报表设计

org.eclipse.birt.report.engine.emitter.fo

发射器,用于生成报表输出FO

org.eclipse.birt.report.engine.emitter.html

HTML生成报表输出的发射器,

org.eclipse.birt.report.engine.emitter.pdf

发射器,生成报表输出PDF

org.eclipse.birt.report.model

BIRT报表模型

org.eclipse.birt.report.viewer

BIRT报表查看器(BIRT Web应用程序)

org.eclipse.birt-feature 

BIRT功能

导入iText1.3和 iTextAsiancom.lowagie.itext / lib目录中。  

从源码中复制三个插件到当前项目根目录下:

org.apache.batik.pdf_1.6.0.v20060623-1511
org.apache.batik_1.6.0.v20060623-1511
org.apache.xerces_2.8.0.v20060815-0630
重命名如下:
org.apache.batik.pdf
org.apache.batik
org.apache.xerces 

用ant编译:

这样,在源码中改变视图viewer语言,汉化视图的方法如下:

Source里有一个nl的文件夹 里面有很多国际化文件

打开org.eclipse.birt.report.viewer.nl这个包的src/org/eclipse/birt/report/resource下边可以看到几个msg文件

接着Check out Message_zh_CN.msg这个msg文件

直接打开会是乱码的 需要通过 native2ascii -encoding gbk BirtResources_zh_CN.msg BirtResources_zh_CN.properties 来编码(也可以直接使用UE等高级文本工具打开后直接复制出来)。

最后复制这个编码后的文件压到 lib/viewServlets.jar这个包的

/org/eclipse/birt/report/resource目录下

注意目录和包路径不要放错了,我几次都放错位置而且把文件名也弄错了。

接着就可以通过__locale=zh-CN的属性来访问中文的BIRT view

 

扩展报表其它格式文件的导出和显示也可以直接从源码入手,例如增加一个csv格式的render:

  1. import org.eclipse.birt.report.engine.api.IRenderOption;  
  2. import org.eclipse.birt.report.engine.api.RenderOption;  
  3. public class CSVRenderOption extends RenderOption   
  4. {  
  5. public static final String OUTPUT_FORMAT_CSV = "xls";  
  6. public CSVRenderOption()   
  7. {  
  8. super();  
  9. }  
  10. public CSVRenderOption(IRenderOption options)   
  11. {  
  12. super(options);  
  13. }  
  14. }  

在报表引擎那里这样调用的:

  1. // PDFIRenderOption pdfOptions;  
  2. pdfOptions = new PDFRenderOption();  
  3. pdfOptions.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);  
  4. pdfOptions.setOutputFileName("D:/birt/test.pdf");  
  5. task.setRenderOption(pdfOptions);  
  6. task.run();  
  7. // HTMLIRenderOption htmlOptions;  
  8. htmlOptions = new HTMLRenderOption();  
  9. ByteArrayOutputStream bos = new ByteArrayOutputStream();  
  10. htmlOptions.setOutputStream(bos);  
  11. htmlOptions.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);  
  12. task.setRenderOption(htmlOptions);  
  13. task.run();  
  14. browser.setText(bos.toString());  
  15. // CSVIRenderOption csvOptions;  
  16. csvOptions = new CSVRenderOption();  
  17. csvOptions.setOutputFileName("D:/birt/test.xls");  
  18. csvOptions.setOutputFormat(CSVRenderOption.OUTPUT_FORMAT_CSV);  
  19. task.setRenderOption(csvOptions);  
  20. task.run();  
  21. // destroy the tasktask.close();  
  22. engine.destroy();  

这样会分别导出为Excel文件,pdf文件,同时用HTML的形式显示在browser上。
同时在plugin.xmlsillycatGen.product上面都要添加上这个包:
org.eclipse.birt.report.engine.emitter.prototype.excel

改变导出文件编码的方式如下,以导出CSV数据为例

找到输出csv数据的代码找到org.eclipse.birt.report.viewer/birt/WEB-INF/classes/org/eclipse/birt/report/service/ReportEngineService.java. 找到extractData这个函数,这个函数是负责输出数据到csv文件的.这个函数里面有两个outputStream.write( buf.toString( ).getBytes( ParameterAccessor.UTF_8_ENCODE ) );把这两行语句改为outputStream.write( buf.toString( ).getBytes( "GBK" ) );

把修改了的文件进行编译,把这个class文件替换viewservlets.jar包中的ReportEngineService文件.最后在把这个包放到lib.这样问题得到解决.

当然,通过修改源代码还能进行更多复杂的功能,比如增加报表预览时的权限审核,增加数据源,数据集,数据项等等。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值