第十三章 BIRT报表引擎API及报表API

来源:互联网 发布:php薪资待遇 编辑:程序博客网 时间:2024/05/20 09:26

13.1报表引擎详解,API结构

BIRT包含几个引擎。一个引擎是一个提供一个特定领域的功能的一套Java API。例如,数据引擎包含管理数据的API,图表引擎包含生成一个图表的API。一般而言,BIRT包含四个引擎,报表设计引擎(design Engine),报表引擎(report engine),图表引擎(chat engine),数据引擎(data engine)。

a) 关于报表设计引擎

报表设计引擎包含验证一个报表设计文件的有效性和生成一个报表设计文件的API。报表设计引擎被BIRT Report Designer和任何定制的生成一个BIRT报表设计的Java应用程序所使用。生成引擎在创建一个报表文档时也使用报表设计引擎。报表设计引擎包含使用ROM技术规范来验证设计文件的元素和结构的有效性的API。

b) 关于报表引擎

报表引擎包含两部分:生成引擎和展示引擎。BIRT Report Viewer和定制的Java应用程序使用报表引擎来处理一个报表设计并按照设计中指定的格式生成报表。生成引擎包含读取和解释一个报表设计的API。生成引擎使用数据引擎来读取和转换来自由报表设计标识的数据源。生成引擎的输出是一个报表文档,这是一个报表产品中的一个中间文档。展示引擎处理由生成引擎创建的报表文档并按设计中指定的格式产生报表。和生成引擎一样,展示引擎也使用数据引擎。但是,在展示阶段,数据引擎从报表文件而不是数据源中获取数据。展示引擎它需要的任何一个报表发射器按照设计中指定的格式生成一个报表。BIRT有两个标准的发射器,HTML和PDF。BIRT也支持不是HTML和PDF格式的定制的发射器。图表报表项和定制的报表项扩展展示引擎来提供这些报表项的展示功能。

c) 关于图表引擎

图标引擎包含生成图表及将图表与来自数据源的数据关联起来的API。图表引擎的使用不仅限于BIRT应用程序。任何Java程序都可以使用图表引擎来创建和现实一个图表。BIRT Report Viewer 解释报表设计中的图标设计信息并使用图表引擎来生成图表。

d) 关于数据引擎

数据引擎包含获取和转换数据的API。当被生成引擎使用时,数据引擎直接从数据源中获取数据。当被展示引擎使用时,数据引擎从报表文档中获取数据。

1) 关于数据引擎组件

数据引擎包含两个主要组件:数据访问组件和数据转换组件。数据访问组件与ODA框架通信来获取数据。数据引擎的数据转换组件执行像排序、分组、累计和过滤来自数据访问组件的数据的操作。

2) 关于ODA框架

ODA框架管理ODA和本地驱动、装载驱动、打开连接并管理数据请求。ODA框架使用Eclipse Data Tools Platform项目来管理连接。ODA框架包含扩展点,籍此可以添加一个定制的ODA驱动。数据引擎扩展用于数据源的连接方法和驱动。如果有一个BIRT不支持的数据源就需要一个定制的ODA驱动。创建一个定制的ODA驱动时可能不仅需要扩展数据引擎而且还需要扩展BIRT Report Designer。如果数据源需要一个GUI组件来制定数据集,那么还需要一个BIRT Report Designer扩展。

 

应用开发者只需要了解公用的API,这些API包含在以下的几个包内:

a) org.eclipse.birt.report.model.api:这个包内包含了93个class,两个接口和一个exception,这个包是为那些想要定制report designer的开发者使用的,报表设计引擎包含这个包

b) org.eclipse.birt.report.engine.api:这个包包含了一个类,17个接口和四个exception,是给那些想要定制一个report generator的开发者使用的,报表引擎包含这个包

c) org.eclipse.birt.charthierarchy:这个包是给想定制一个chartgenerator的开发者使用的,图表引擎包含这个包


BIRT报表引擎(BIRT report engine)在几个环境提供了报表生成和翻译服务,包含在以下组件中:

a) Stand-alone engine:这个engine可以让开发者使用一个命令行程序来从一个report design文件(.rptdesign)中得到Html或PDF格式的report

b) BIRT report viewer:BIRT Report Designer使用它来预览report。这个程序是一个web程序,它运行在一个Eclipse内嵌的Tomcat中,这个Tomcat中有一个内嵌的report engine

c) Custom report designer with an embedded engine:一个定制的桌面报表应用集成BIRT report engine来预览报表

d) Web application that embeds the engine:一个类似于BIRT report viewer的Web程序,可以产生基于web的报表。

 

如下图所示:


另外,用户还能定制报表引擎,除了通常是集成到一个Web应用或者一个独立的Java应用程序外,定制的Java报表生成器质性和BIRT报表生成器相同的功能。和BIRT 报表浏览器Web应用一样,定制的Java报表生成器使用报表引擎的API来读取报表设计文件并生成一个报表。一个定制的业务逻辑来管理安全事宜、控制目录和确定输出的格式。

 

Report engine的核心engine运行并实施报表,而将其他的环境相关的任务留给运行该引擎的应用程序,比如:URLconstruction, image storage, and design file caching

BIRT report engine的API可以做以下几件事情:

a) 发现一组为报表定义的参数(包括动态参数和级联参数)

b) 获得参数的默认值

c) 产生任务(task)实施操作的应用

d)包含1到2个操作阶段((RunTask 然后 Render Task 或者RunAndRenderTask)

d) 为报表产生图片或chart

e) 产生报表文档

f) 运行报表产生HTML或PDF格式的输出



EngineConfig –设置报表引擎可选的参数.

ReportEngine – 用于运行一到多个报表任务

IReportRunnable –用于打开报表设计文档,并把句柄传给报表任务

IReportDocument – 用于打开报表文档,并把句柄传给报表任务,同时包含很多方法用于获TOC,数据等等

HTMLRenderContext – 定义展示HTML的环境,例如设置HTML图片地址,事件处理

PDFRenderContext – 定义展示PDF的环境,例如设置字体的地址,事件处理

HTMLRenderOption – 用于设置html的可选选项,比如导出时的路径



报表设计引擎(Design Engine)需要完成的事情:

1、用于产生或者修改报表设计文档,报表模板文档,报表库文档

2、有时候报表引擎需要修改报表设计文档,这个时候就需要调用报表设计引擎

3、如果报表引擎在运行时,事件机制和脚本机制中本身就包含修改报表设计的代码,这个时候也要调用报表设计引擎

4、用于获取和设置报表参数

5、可以用于获取报表设计的种种属性和参数


用户还能定制报表设计器,一个定制的报表设计器是一个由Java开发人员创建的用来基于特定的需求生成一个格式良好的报表设计文件Java应用程序。定制的报表设计器不需要包含用户界面。定制的报表设计起的一个典型的例子是一个动态确定一个报表的目录、结构或者数据元的Java应用程序。定制的报表设计器使用和BIRTReport Designer相同的设计引擎API。

图表引擎用于产生图表,展示图表,修改图表,是一个比较独立的引擎。通常包含两个API包:

org.eclipse.birt.chart.model.*,org.eclipse.birt.chart.*


一般报表设计器在产生一份包含图表的设计文档的时候,都要调用图表的设计和展示引擎,但图表引擎不仅仅包含在报表设计器的类库中,报表在展示阶段如果包含图表,或者需要修改图表的时候,也会调用图表的引擎。


事实上,birt提供的开源产品Report Designer,Example Viewer都包含这三个引擎(报表设计引擎,报表引擎,图表引擎),所以用户在自定义设计器,自定义web展示器,自定义独立运行的展示器的时候,最好也要包含这三类引擎。

构建一个报表的必须工作:

创建和配置报表引擎

单个报表引擎可以通过创建多个设计器来生成多个报表。通过Platform.createFactoryObject()方法创建一个ReportEngine对象。设置BIRT目录,指向需要的plug-in和库。

打开报表文档(*.rptdesign 或 *.rptdocument)
通过ReportEngine对象的openReportDesign( )打开一个报表设计模版,参数是文件路径名或InputStream,返回一个IReportRunnable对象。
通过ReportEngine对象的openReportDocument( )打开一个报表文档,参数是文件路径名,返回一个IReportDocument对象。

连接数据源
通过创建数据连接或使用应用程序提供的连接为数据集提供数据源。

报表生成的准备工作
用一个IRenderOption对象设置输出格式,输出文件名,输出流或输出位置,和一些特定格式设置。HTMLRenderOption支持HTML格式的输出,输出PDF格式使用RenderOption

生成报表
使用IRunAndRenderTask对象生成IReportRunnable类型的报表,使用IRenderTask对象创建IReportDocument类型的报表。
也可以访问部署在应用程序服务器上的report viewer servlet来生成报表。

销毁引擎
当我们不再需要使用报表引擎时将它销毁。

可选的任务:

获取参数

如果报表中设置了参数,引擎要使用传入的参数生成报表,如果没有传入参数则使用默认值。

创建报表文档文件(*.rptdocument)
报表文档文件已二进制的形式存储的,如果应用程序使用报表设计文件,要通过IRunTask对象生成一个IReportDocument对象的报表文档。

从报表文档导出数据。
使用IDataExtractionTask对象在报表文档中导出一项或多项的值。


开发环境要求
把需要的类库都引入classpath或开发工具中。配置BIRT目录,目录中包含了从报表设计文件生成报表所需要的plug-in和类库。 BIRT的报表引擎包在他的ReportEngine子目录里提供了完整的BIRT home。如果你想动手修改BIRT源码的话,一定要保证源码的版本与BIRT home中的plug-in和类库的版本是一致的。

类库和plug-in
BIRT home的ReportEngine\lib子目录和ReportEngine\plugins中包含了报表应用程序需要的用到的类库和plug-in,你可以根据自己项目的情况删除掉不用的包。

jdbc驱动
BIRT home的plugins/org.eclipse.birt.report.data.oda.jdbc_...文件夹用于存放连接数据库所需要的驱动程序,你可以把需要的驱动程序包放到该目录下(引入classpath中好像是不起作用的…)

通过api修改报表设计模版
报表应用程序在生成报表前可以修改报表设计模版。如:添加删除数据项,更深入的定制报表等。DesignEngine API提供了修改设计模版(包括修改脚本)DesignEngine的主要接口在org.eclipse.birt.model.api包中。

下面给出一个简单的例子:

该报表的设计如下:


数据集上有事件处理绑定:


需要在报表的资源中导入事件处理包:


预览如下:


报表引擎的源码如下:

[java] view plaincopy
  1. package REAPI;  
  2. import java.util.logging.Level;  
  3. import org.eclipse.birt.core.framework.Platform;  
  4. import org.eclipse.birt.report.engine.api.EXCELRenderOption;  
  5. import org.eclipse.birt.report.engine.api.EngineConfig;  
  6. import org.eclipse.birt.report.engine.api.EngineConstants;  
  7. import org.eclipse.birt.report.engine.api.EngineException;  
  8. import org.eclipse.birt.report.engine.api.HTMLRenderOption;  
  9. import org.eclipse.birt.report.engine.api.IReportEngine;  
  10. import org.eclipse.birt.report.engine.api.IReportEngineFactory;  
  11. import org.eclipse.birt.report.engine.api.IReportRunnable;  
  12. import org.eclipse.birt.report.engine.api.IRunAndRenderTask;  
  13. import org.eclipse.birt.report.engine.api.PDFRenderOption;  
  14.   
  15.   
  16. public class RunAndRenderTask {  
  17.   
  18.     public void runReport() throws EngineException  
  19.     {  
  20.   
  21.         IRunAndRenderTask task=null;  
  22.         IReportEngine engine=null;  
  23.         EngineConfig config = null;  
  24.   
  25.         try{  
  26.             //System.setProperty("java.io.tmpdir", "c:/temp/test/testsampledb");      
  27.             config = new EngineConfig( );             
  28.             config.setLogConfig("d:\\dwn.txt", Level.INFO);  
  29.             config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, this.getClass().getClassLoader());  
  30.             config.getAppContext().put(EngineConstants.WEBAPP_CLASSPATH_KEY, "d:\\eventjar.jar");             
  31.             config.setBIRTHome("E:\\birt汉化包\\birt-runtime-3_7_2\\ReportEngine");  
  32.             //config.setLogConfig(null, Level.FINEST);  
  33.             Platform.startup( config );  
  34.               
  35.             IReportEngineFactory factory = (IReportEngineFactory) Platform  
  36.             .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );  
  37.             engine = factory.createReportEngine( config );  
  38.           
  39.   
  40.         IReportRunnable design = null;  
  41.         //Open the report design  
  42.           
  43.         design = engine.openReportDesign("d:\\dataseteventhandler.rptdesign");   
  44.         task = engine.createRunAndRenderTask(design);         
  45.         //task.setParameterValue("Top Count", (new Integer(5)));  
  46.         task.validateParameters();  
  47.               
  48.           
  49.         HTMLRenderOption options = new HTMLRenderOption();        
  50.         options.setImageDirectory("d:\\");  
  51.         options.setOutputFileName("d:\\eventhandlerjar.html");  
  52.         options.setOutputFormat("html");  
  53.           
  54.         //PDFRenderOption options = new PDFRenderOption();  
  55.         //options.setOutputFileName("d:\\topn.pdf");  
  56.         //options.setSupportedImageFormats("PNG;GIF;JPG;BMP;SWF;SVG");  
  57.         //options.setOutputFormat("pdf");  
  58.           
  59.         //EXCELRenderOption options = new EXCELRenderOption();    
  60.         //options.setOutputFormat("xls");  
  61.         //options.setOutputFileName("d:\\customers.xls");  
  62.         //options.setWrappingText(true);  
  63.           
  64.         task.setRenderOption(options);  
  65.         task.run();  
  66.         task.close();  
  67.         engine.destroy();  
  68.         }catch( Exception ex){  
  69.             ex.printStackTrace();  
  70.         }                 
  71.         finally  
  72.         {  
  73.             if ( !task.getErrors( ).isEmpty( ) )  
  74.   
  75.             {  
  76.   
  77.                 for ( Object e : task.getErrors( ) )  
  78.   
  79.                 {  
  80.   
  81.                     ( (Exception) e ).printStackTrace( );  
  82.   
  83.                 }  
  84.   
  85.             }             
  86.             Platform.shutdown( );  
  87.             System.out.println("Finished");  
  88.         }  
  89.           
  90.     }     
  91.   
  92.   
  93.     /** 
  94.      * @param args 
  95.      */  
  96.     public static void main(String[] args) {  
  97.         try  
  98.         {  
  99.   
  100.             RunAndRenderTask ex = new RunAndRenderTask( );  
  101.             ex.runReport();  
  102.   
  103.         }  
  104.         catch ( Exception e )  
  105.         {  
  106.             e.printStackTrace();  
  107.         }  
  108.     }  
  109. }  

运行,会看到D盘产生eventhandlerjar.html文档,查看如下:


下面详细介绍如何构建一个报表应用程序

org.eclipse.birt.report.engine.api包含了用来生成报表的类和接口,其中主要的类和接口有 ReportEngine, EngineConfig, IReportRunnable, IRenderOption以及它的子类,IEngineTask以及它的子类。
Eclipse提供的Birt集成开发工具的帮助文档里有详细的api参考,不过有点简略。

一、创建报表引擎

报表引擎是ReportEngine类的一个实例,是任何报表应用程序的关键部分。首先用EngineConfig对象来为ReportEngine准备参数,然后用BIRT报表引擎工厂来创建引擎。创建一个配置对象:
EngineConfig config = new EngineConfig();

设置BIRT home
BIRT home就是BIRT plug-ins和类库的路径,它是报表引擎的关键参数。
你可以用下面的方式进行BIRT home设置:
对于独立的应用程序可以吐过下面的方式设置:
config.setBIRTHome ( "C:/birt-runtime-<version>/ReportEngine" );
也可以再你自己的环境变量中设置:
set BIRT_HOME="C:\birt-runtime-<version>\ReportEngine"
SET CLASSPATH=%BIRT_HOME%\<required library 1>;
■ Web应用程序里要首先取得绝对路径让后设置到config
config.setBIRTHome( servletContext.getRealPath( "/WEB-INF" ) );
WAR 文件的Web应用程序中可以使用PlatformServletContext.
config.setBIRTHome( "" );
■ Eclipse,通过VM运行参数设置
-DBIRT_HOME="C:\birt-runtime-<version>\ReportEngine"

设置引擎的其他参数
通过配置对象进行配置的参数还有日志,OSGI(Open Services Gateway Initiative),平台上下文,资源文件,临时资源文件,脚本等,这些都是可选的参数,详细信息可以参考EngineConfigAPI

不同运行环境的差异
应用程序是独立运行的还是以web形式运行的决定了平台上下文和HTML发射器(emitter,不知道是不是生成器更合适一点)的配置的不同。 平台上下文提供了报表引擎连接plug-in的机制,默认使用独立运行的方式。HTML发射器提供了处理图片和处理超链接和标签事件的功能。

设置上下文
BIRT是一个基于Eclipse的应用程序,因此它使用OSGI平台来启动插件来产生报表和设计引擎。BIRT需要的plug-in存储在 BIRT主目录下,通过platform context进行配置,它实现了接口org.eclipse.birt.core.framework.IPlatformContext。 context作为EngineConfig的一个参数通过setEngineContext( )进行设置。
BIRT中提供了两个IPlatformContext的实现:
PlatformFileContext通过文件系统目录配置context,用于独立运行的应用程序和web应用程序中部署的基于系统文件目录的BIRT应用程序。
IPlatformContext context = new PlatformFileContext( );
config.setEngineContext( context );
对于web应用上部署的BIRT应用程序,使用PlatformServletContext。它使用基于资源连接的J2EE ServletContext来定位BIRT plug-in。它默认使用“/WEB-INF/platform/”
IPlatformContext context =
new PlatformServletContext(request.getSession().getServletContext());
config.setPlatformContext(context);
如果默认的BIRT提供的实现不能满足你的要求,可以定义自己的实现。

设置HTML emitter
当使用HTML格式生成一个报表,引擎通过一个HTMLRenderOption对象来定义如何处理HTML emitter使用的资源(图像滤镜,图像元素,图表,书签等)。桌面应用程序和web应用程序用来处理图像的方法是不同的。使用HTML emitter首先要创建HTMLRenderOption,使用方法:
HTMLRenderOption ho = new HTMLRenderOption( );
ho.setImageHandler( new HTMLCompleteImageHandler( ));
config.setEmitterConfiguration( RenderOptionBase.OUTPUT_FORMAT_HTML, ho );
创建引擎时可以不必设置HTML emitter,你可以需要生成HTML报表时再去进行配置。
IHTMLImageHandler是用来处理图像的接口,BIRT提供了两个IHTMLImageHandler的实现:
HTMLCompleteImageHander可以将图像保存到文件目录。它首先使用HTMLRenderOption设置的图像目录,如果没 有则使用EngineConfig.setTempDir( )设置的临时文件目录,如果还没有则使用java.io.tmpdir定义的系统临时文件目录。生成的HTML中引用的图像也是引擎创建的。
HTMLServerImageHandler应用在web应用程序中,它将图像文件保存在HTMLRenderOption设置的图像文目录 中。HTML的图像的src指向生成的图像文件的路径也是在HTMLRenderOption中配置的。这样报表引擎就可以在本地文件中创建图像文件,并 且通过URL共享。
ho.setImageDirectory("output/image");
ho.setBaseImageURL("http://myhost/prependme?image=");
如果IHTMLImageHandler得实现不能满足你的要求,你可以开发自己的实现。或者继承并重写已有的image handlerHTMLCompleteImageHander已经提供了足够的图像文件接口因此一般情况下不需要我们进行扩展。

启动平台
设置完成平台上下文环境,你可以通过org.eclipse.birt.core.framework.Platform类启动一个平台。 Platform是一个Eclipse OSGI平台的包装类,提供一个同步的静态方法startup( )用来启动平台,该操作的开销比较大,因此你的应用程序最好只调用一次。平台使用结束后调用Platform.shutdown( )关闭。如果你是在Web应用程序里使用报表引擎,请在servletinit方法中调用startup方法或者在第一次处理用到平台的请求时。最好启 动平台的代码封装为一个单例。如果你使用Birt提供的Web Viewer或使用基于Eclipse的富客户端程序(RCP),你就不需要启动平台,因为应用程序已经自己启动了OSGi


Platform Class的作用

用于启动所需要的插件

使用 OSGi.

DE API, CE API and the RE API都需要启动平台

使用 PlatformConfig 类去配置startup.

DesignConfig and EngineConfig 是扩展自 PlatformConfig.

PlatformContext 类决定了插件(Plugins)的地址

创建Factory用于产生DesignEngine或者ReportEngine


创建报表引擎
BIRT提供一个工厂服务用于创建ReportEngine对象。Platform.createFactoryObject( )创建一个实现了org.eclipse.birt.report.engine.api.IReportEngineFactory接口的工厂对象。该 方法需要一个PlatformConfig对象。因为EngineConfig是继承自PlatformConfig,你可以使用 EngineConfig来创建一个工厂。最后通过IReportEngineFactory.createReportEngine( )方法和刚才使用的EngineConfig对象创建报表引擎。

实例
在独立运行的应用程序中创建一个报表引擎,如下:

[java] view plaincopy
  1. // Create an EngineConfig object.  
  2. EngineConfig config = new EngineConfig( );  
  3. // Set up the path to your BIRT home directory.  
  4. config.setBIRTHome("E:\\birt汉化包\\birt-runtime-3_7_2\\ReportEngine");  
  5. // Explicitly set up the stand-alone application  
  6. IPlatformContext context = new PlatformFileContext( );  
  7. config.setEngineContext( context );  
  8. // Start the platform for a non-RCP application.  
  9. Platform.startup( config );  
  10. IReportEngineFactory factory = ( IReportEngineFactory ) Platform.createFactoryObject  
  11. ( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );  
  12. // Set up writing images or charts embedded in HTML output.  
  13. HTMLRenderOption ho = new HTMLRenderOption( );  
  14. ho.setImageHandler( new HTMLCompleteImageHandler( ));  
  15. config.setEmitterConfiguration( RenderOptionBase.OUTPUT_FORMAT_HTML, ho );  
  16. // Create the engine.  
  17. IReportEngine engine = factory.createReportEngine( config );  

说明:上面一个在windows系统上的独立运行的应用程序,它使用BIRT run-time提供的BIRT home,报表输出格式是HTML

[java] view plaincopy
  1. 在<span style="font-family:Calibri;">Web</span><span style="font-family:宋体;">应用程序上创建一个报表引擎,如下:</span>  
[java] view plaincopy
  1. // Example class to create the report engine  
  2. public class BirtEngine {  
  3. private static IReportEngine birtEngine = null;  
  4. public static synchronized IReportEngine getBirtEngine( ServletContext sc ) {  
  5. if (birtEngine == null) {  
  6. EngineConfig config = new EngineConfig( );  
  7. config.setBIRTHome( "" );  
  8. IPlatformContext context = new PlatformServletContext( sc );  
  9. config.setPlatformContext( context );  
  10. try{  
  11. Platform.startup( config );  
  12. IReportEngineFactory factory = ( IReportEngineFactory )  
  13. Platform.createFactoryObject(   
  14. IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );  
  15. birtEngine = factory.createReportEngine( config );  
  16. }catch ( Exception e ) { e.printStackTrace( ); }  
  17. }  
  18. return birtEngine;  
  19. }  
  20. }  

说明:上面的代码是一个用单例模式实现的报表引擎的创建的类,EngineConfig配置了两个参数 BIRTHomePlatformContext

在上面例子的基础上进行更多的配置

[java] view plaincopy
  1. // In a different class, get the report engine  
  2. reportEngine = BirtEngine.getBirtEngine( request.getSession( ).getServletContext( ));  
  3. // Set up the engine  
  4. EngineConfig config = reportEngine.getConfig( );  
  5. HTMLRenderOption ho = new HTMLRenderOption( );  
  6. ho.setImageHandler( new HTMLServerImageHandler( ));  
  7. ho.setImageDirectory("output/image");  
  8. ho.setBaseImageURL("http://myhost/prependme?image=");  
  9. config.setEmitterConfiguration( RenderOptionBase.OUTPUT_FORMAT_HTML, ho );  

使用日志环境调试应用程序
BIRT报表引擎使用java.util.loggingLoggerLevel类来处理引擎平台的日志信息。你在Eclipse中运行一个 应用程序运行信息默认的是显示在控制台上的。在非Eclipse环境中运行信息的输出就要有运行环境决定了。默认的日志级别是Level.INFO,你可 以通过改变日志级别来减少系统内部的日志信息。
使用EngineConfig.setLogConfig( )可以让日志输出到磁盘文件中。该方法需要两个参数,第一个参数是日志输出的目录,BIRT 引擎会在指定目录中创建一个名称格式为ReportEngine
_YYYY_MM_DD_hh_mm_ss.log的日志文件。第二个参数是日志信息的最低级别,级别越高输出的日志信息越少。ReportEngine.changeLogLevel( )方法可以让你修改日志级别。

如何使用BIRT日志 如下:

[java] view plaincopy
  1. // Set up the location and level of the logging output.  
  2. config.setLogConfig( "C:/Temp", Level.ERROR );  
  3. engine.changeLogLevel( Level.INFO );  

二、打开报表资源文件

BIRT引擎可以通过报表设计文件和报表文档两种方式生成报表,引擎还可以从报表设计文件生成报表文档。
你可以通过openReportDesign( )方法打开一个报表设计文件文件,他实例化一个IReportRunnable对象,支持文件路径或一个输入流。
你可以通过openReportDocument( )方法打开一个报表设计文件文件,他实例化一个IReportDocument对象,也支持文件路径或一个输入流。
使用这些方法要处理EngineException

理解IReportRunnable对象
IReportRunnable对象提供到报表设计的基本属性的直接接口。报表设计属性的属性名是静态字符串变量,如:IReportRunnable.AUTHOR。可以通过getProperty( )方法去访问这些属性。下面的代码展示了如何连接到报表设计文件:

[java] view plaincopy
  1. String designName = "./SimpleReport.rptdesign";  
  2. IReportRunnable runnable = null;  
  3. try {  
  4. runnable = engine.openReportDesign( designName );  
  5. }catch ( EngineException e ) {  
  6. System.err.println( "Design " + designName + " not found!" );  
  7. engine.destroy( );  
  8. System.exit( -1 );  
  9. }  
  10. // Get the value of a simple property.  
  11. String author = ( String ) runnable.getProperty( IReportRunnable.AUTHOR );  

理解IReportDocument对象
IReportDocument对象提供了访问报表数据和报表结构的接口,它提供了方法来访问表格内容,书签,页面信息等。
使用findTOC( )访问表格内容,该方法使用TOCNode参数返回一个TOCNode对象。使用null参数就可以访问根表格。
调用getTOCTree( )返回一个ITOCTree对象获取更详细的Table信息。调用TOCNode.getChildren( )方法获取table的子节点,返回值是一个TOCNode对象列表。
通过TOCNode对象你可以得到表格中的内容和书签。你可以使用书签对象作为参数调用getPageNumber( )方法获取书签连接的页面的页数。通过这些信息你可以在以格式化的报表中显示特定的页面。
下面的代码展示了如何打开一个报表文档,并在页面上查找元素:

[java] view plaincopy
  1. String dName = "./SimpleReport.rptdocument";  
  2. IReportDocument doc = null;  
  3. try {  
  4. doc = engine.openReportDocument( dName );  
  5. catch ( EngineException e ) {  
  6. System.err.println( "Document " + dName + " not found!" );  
  7. engine.destroy( );  
  8. System.exit( -1 );  
  9. }  
  10. // Get the root of the table of contents.  
  11. TOCNode td = doc.findTOC( null );  
  12. java.util.List children = td.getChildren( );  
  13. long pNumber;  
  14. // Loop through the top level table of contents entries.  
  15. if ( children != null && children.size( ) > 0 ) {  
  16. for ( int i = 0; i < children.size( ); i++ ) {  
  17. // Find the required table of contents entry.  
  18. TOCNode child = ( TOCNode ) children.get( i );  
  19. if ( child.getDisplayString( ).equals( "103" ) ) {  
  20. // Get the number of the page that contains the data.  
  21. pNumber = doc.getPageNumber( child.getBookmark( ) );  
  22. System.out.println( "Page to print is " + pNumber );  
  23. }  
  24. }  
  25. }  

三、用程序处理报表参数

参数是报表生成之前想报表设计文件输入的报表元素。报表的应用程序可以访问报表的参数的属性,最常用的属性是namevalue,你可以使用参数名或通用编码来获取参数。

为报表设计创建一个参数定义任务
一个IGetParameterDefinitionTask对象提供链接到报表设计所有参数的接口。通过调用 ReportEngine.createGetParameterDefinitionTask( )创建一个参数定义对象,使用结束后调用他的close方法关闭。

测试报表设计是否有参数
IGetParameterDefinitionTask.getParameterDefns( )可以测试报表设计是否有参数,它返回一个参数集合,调用集合的isEmpty( )方法可以测试集合中是否有元素。

获取报表设计的参数
通过IGetParameterDefinitionTask.getParameterDefn( )方法获取一个已知名字的参数,它返回一个IParameterDefnBase类型对象,也可以调用getParameterDefns( )方法返回一个参数集合。
getParameterDefns( )需要一个boolean参数,如果为false返回一个未分组的参数集合,如果为true返回报表设计中定义的参数组。
调用IParameterDefnBase.getParameterType( )可以检验参数是否是一个组。如果是一个组则返回IParameterDefnBase.PARAMETER_GROUP,如果是一个级联参数组则返回 IParameterDefnBase.CASCADING_PARAMETER_GROUP。为获取一组报表参数,使用方法 IParameterGroupDefn.getContents( ),它返回一个数据类型是IScalarParameterDefnArrayList对象。

获取报表参数的默认值
这个任务是可选的。调用IGetParameterDefinitionTask.getDefaultValue( )获取一个已知参数的默认值,它返回的是一个Object。可以通过调用IScalarParameterDefn.getDataType( )来获取Object的有效类型,它返回一个IScalarParameterDefn定义的int类型的静态变量。调用 IGetParameterDefinitionTask.getDefaultValues( )来获取报表设计的所有参数的默认值,它返回一个HashMap对象存储了从参数名到默认值的映射。

使用常量列表提供的效值
许多报表参数只接受常量列表的值,这些值可能是静态常量,也可能是数据库里查出来的数据list。使用 IGetParameterDefinitionTask.getSelectionList( )可以返回参数所能接受的参数(IParameterSelectionChoice)的集合,如果集合为null,则可以接受任何值。 IParameterSelectionChoicegetLabel( )方法返回现实的文本,getValue( )返回值。

获取每个报表参数的属性
这个任务是可选的。使用IScalarParameterDefn的方法可以获取表参数的属性。应用程序使用属性生成用户自定义接口。例如,获取参数的数据类型使用getDataType( )方法。

为参数设置值
调用IGetParameterDefinitionTask.setParameterValue( )为参数设置值。如果你是通过应用程为日期数值等参数返回一个字符串,要把他们转化成和本地无关的格式。调用方法 ReportParameterConverter.parse( )方法可以完成这项工作。getParameterValues( )方法返回一个HashMap包含了已经设置的所有参数。

实例
下面的代码展示了如何设置一个已知参数名的参数值:

[java] view plaincopy
  1. // Create a parameter definition task.  
  2. IGetParameterDefinitionTask task = engine.createGetParameterDefinitionTask( runnable );  
  3. // Instantiate a scalar parameter.  
  4. IScalarParameterDefn param = (IScalarParameterDefn)  
  5. task.getParameterDefn( "customerID" );  
  6. // Get the default value of the parameter. In this case,  
  7. // the data type of the parameter, customerID, is Double.  
  8. int customerID = ((Double) task.getDefaultValue( param )).intValue( );  
  9. // Get a value for the parameter. This example assumes that  
  10. // this step creates a correctly typed object, inputValue.  
  11. // Set the value of the parameter.  
  12. task.setParameterValue( "customerID", inputValue );  
  13. // Get the values set by the application for all parameters.  
  14. HashMap parameterValues = task.getParameterValues( );  
  15. // Close the parameter definition task.  
  16. task.close( );  

下面的代码展示了如何使用报表参数集合,例子中使用ReportParameterConverter将字符串转化成用户接口接受的参数格式。

[java] view plaincopy
  1. // Create a parameter definition task.  
  2. IGetParameterDefinitionTask task = engine.createGetParameterDefinitionTask( runnable );  
  3. // Create a collection of the parameters in the report design.  
  4. Collection params = task.getParameterDefns( false );  
  5. // Get the default values of the parameters.  
  6. HashMap parameterValues = task.getDefaultValues( );  
  7. // Get values for the parameters. Later code in this example  
  8. // assumes that this step creates a HashMap object,  
  9. // inputValues. The keys in the HashMap are the parameter  
  10. // names and the values are those that the user provided.  
  11. // Iterate through the report parameters, setting the values  
  12. // in standard locale-independent format.  
  13. Iterator iterOuter = params.iterator( );  
  14. ReportParameterConverter cfgConverter =  
  15. new ReportParameterConverter( "", Locale.getDefault() );  
  16. while ( iterOuter.hasNext( ) ) {  
  17. IParameterDefnBase param = (IParameterDefnBase) iterOuter.next( );  
  18. String value = (String) inputValues.get( param.getName( ));  
  19. if ( value != null ) {  
  20. parameterValues.put( param.getName( ),  
  21. cfgConverter.parse( value, param.getDataType( ) ) );  
  22. }  
  23. }  
  24. // Close the parameter definition task.  
  25. task.close( );  

使用级联参数
级联参数参数是一组可供用户选择的参数值的集合。第一个参数的选择会影响到第二个参数中的值。参数使用一个或多个查询来从数据集把数据展示给用户。参数定义任务根据前面的选择以行为单位过滤参数组中的数据。
使用报表引擎实现级联参数,要进行如下工作:
使用IGetParameterDefinitionTask.evaluateQuery( )方法为级联参数准备数据,它需要参数group的名字作为参数。
调用IGetParameterDefinitionTask.getSelectionListForCascadingGroup( )获取参数组的第一个参数的值,它需要两个参数,参数名和对象数组,对第一个参数来说这个数组是空的。该方法返回一个 IParameterSelectionChoice集合。
■ 再次调用getSelectionListForCascadingGroup( )方法获取后面的参数,这次Object[ ]中放的是前面获取的参数值。

下面的代码展示了如何通过查询实现级联参数:

[java] view plaincopy
  1. // Create a grouped collection of the design’s parameters.  
  2. Collection params = task.getParameterDefns( true );  
  3. // Iterate through the parameters to find the cascading group.  
  4. Iterator iter = params.iterator( );  
  5. while ( iter.hasNext( ) ) {  
  6. IParameterDefnBase param = (IParameterDefnBase) iter.next();  
  7. if ( param.getParameterType() ==  
  8. IParameterDefnBase.CASCADING_PARAMETER_GROUP ) {  
  9. ICascadingParameterGroup group = (ICascadingParameterGroup) param;  
  10. Iterator i2 = group.getContents( ).iterator( );  
  11. // Run the query for the cascading parameters.  
  12. task.evaluateQuery( group.getName() );  
  13. Object[ ] userValues = new Object[group.getContents( ).size( )];  
  14. // Get the report parameters in the cascading group.  
  15. int i = 0;  
  16. while ( i2.hasNext( ) ) {  
  17. IScalarParameterDefn member = (IScalarParameterDefn) i2.next( );  
  18. // Get the values for the parameter.  
  19. Object[ ] setValues = new Object[i];  
  20. if ( i > 0 ) System.arraycopy( userValues, 0, setValues, 0, i );  
  21. Collection c = task.getSelectionListForCascadingGroup(  
  22. group.getName(),setValues );  
  23. // Iterate through the values for the parameter.  
  24. Iterator i3 = c.iterator();  
  25. while ( i3.hasNext( ) ) {  
  26. IParameterSelectionChoice s =  
  27. ( IParameterSelectionChoice ) i3.next( );  
  28. String choiceValue = s.getValue( );  
  29. String choiceLabel = s.getLabel( );  
  30. }  
  31. // Get the value for the parameter from the list of  
  32. // choices. This example does not provide the code for  
  33. // this task.  
  34. userValues[i] = inputChoiceValue;  
  35. i++;  
  36. }  
  37. }  
  38. }  

四、报表生成的准备工作

BIRT支持HTML, Adobe PDF, Adobe PostScript (PS), Microsoft Excel (XLS), Microsoft PowerPoint (PPT)和 Microsoft Word (DOC) 格式的报表生成器。你也可以通过扩展支持自定义的格式。

有三个task类用来支持从源文件生成报表,就是:

■ IRunAndRenderTask. 通过运行报表设计文件直接生成目标格式的报表。调用方法ReportEngine.createRunAndRenderTask( )可以创建这个对象。

■ IRunTask. 通过报表设计文件生成报表文档,ReportEngine.createRunTask( )方法可以创建这个对象。

■ IRenderTask. 通过对报表文档中的内容进行格式化生成一个完整的报表或一个页面集。ReportEngine. createRenderTask( )方法返回该对象的一个实例。
每一个任务都可以使用多个报表文件,任务结束后都要调用close方法关闭。

为运行报表设计文件准备参数
IRunAndRenderTask 和 IRunTask对象允许设置报表参数。调用setParameterValues( )方法,通过传入一个参数的HashMap设置所有的参数,设置单个参数可以使用setParameterValue( )方法。

添加到报表引擎的类路径
一些报表设计需要扩展的java类,BIRT报表引擎通过使用环境变量信息定位类。通过动态设置应用程序上下文信息或引擎配置对象也可以配置java类的位置。使用EngineConstants中的常量来配置这些参数。

使用EngineTask对象和EngineConfig对象可以设置应用程序上下文,如下:

configOrTask.getAppContext( ).put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY,MyClass.class.getClassLoader( ));


使用EngineConfig对象设置CLASSPATH,如下:
Java代码 

config.setProperty( EngineConstants.WEBAPP_CLASSPATH_KEY, "c:/myjars/jar1.jar;c:/myclasses" );

使用Java System类设置CLASSPATH,如下:

System.setProperty(EngineConstants.WEBAPP_CLASSPATH_KEY, "c:/myjars/jar1.jar;c:/myclasses" );

BIRT按下面的顺序来查找扩展类:
■ 报表引擎plug-inCLASSPATH
■ 上下文环境中定义的EngineConstants.APPCONTEXT_CLASSLOADER_KEY
■Java System 类或EngineConfig 中定义的EngineConstants.WEBAPP_CLASSPATH_KEY.
■Java System 类或EngineConfig 中定义的EngineConstants. PROJECT _CLASSPATH_KEY.
■Java System 类或EngineConfig 中定义的
EngineConstants. WORKSPACE _CLASSPATH_KEY.
■ 报表设计中引入的JAR文件

为报表设计提供外部对象
BIRT支持把以前实例化的对象拿过来重用。调用报表引擎前你要在应用程序中持有这个已经在内存中存在的对象。如果在脚本环境中使用,你传递对象给引擎后,脚本可以通过对象名在必要的是后获取对象。
可以通过EngineConfigtask得上下文环境为引擎提供对象。如下:

[java] view plaincopy
  1. MyObject mo = new MyObject( );  
  2. config = new EngineConfig( );  
  3. // Get the application context from the config or the task  
  4. HashMap hm = config.getAppContext( );  
  5. //HashMap hm = task.getAppContext( );  
  6. hm.put( "MyCreatedObject", mo );  
  7. config.setAppContext( hm );  
  8. // To refer to this object in a BIRT script  
  9. // or expression, use MyCreatedObject.myMethod()  

设置rendering选项
按指定格式输出报表前要先设置报表输出选项。必须设置一个文件名或输出流用来输出报表,其他的设置都是可选的如是否创建一个可嵌入的HTML。 BIRT支持可嵌入和非可嵌入两种HTML,可嵌入HTML可以被嵌入其他的web页面,不包含头信息<body> <html>表签。

应用程序通过rendering options对象设置输出选项,指定格式的rendering options类实现了IRenderOption接口,并且继承了RenderOption类。HTMLRenderOption用来设置HTML输出 选项,PDFRenderOption用来设置PDF格式输出选项。其他的格式都使用RenderOption

常用的设置有超连接的URL,事件处理器,图像处理器,输出格式,支持的图片输出格式,还可以设置输出到数据流还是文件。

设置HTML rendering选项
生成一个使用了图片的HTML报表,必须进行更多的配置。HTMLRenderOption提供了许多方式去自定义HTML的生产。下面是一些常用的选项:
■ 图像路径,生成HTML需要的图像(图片,动态生成的图表等)的路径通过调用方法HTMLRenderOption.setImageDirectory( )进行设置。
■ 基本图像URL,在Web应用程序开发时,浏览器要引用到图像所要使用的URL路径前缀。通过HTMLRenderOption.setBaseImageURL( )进行设置。
■ 图像处理器,使用HTMLRenderOption.setImageHandler( ) 进行设置
■ 可嵌入的HTML,调用HTMLRenderOption.setEmbeddable( )
■ 从左到右的生成方式,调用HTMLRenderOption.setHtmlRtLFlag( )设置。
■ 标题标签,调用HTMLRenderOption.setHtmlTitle( )设置,该标签将显示在浏览器的标签页上。
■ 主页面内容,通过主页面可以设置页面大小、页眉、页脚等。如果不想让主页面的设置影响HTML的生成,可以调用HTMLRenderOption.setMasterPageContent( )设置。
■ 浮动的页脚,主页面的页脚默认直接显示在内容的下方。传一个booleanfalse给方法 HTMLRenderOption.setPageFooterFloatFlag( ),强制页脚在页面底部的固定位置显示。这个设置将在生成的HTML中添加一个固定高度的DIV
■主页的页边距,HTMLRenderOption.setOutputMasterPageMargins( )设置主页的页边距是否影响到HTML页面。
■ HTML分页,生成HTML时也支持分页。设置HTMLRenderOption.setHtmlPagination( )可以让HTML页面支持分页。
下面的实例展示了在IRunAndRenderTask对象上使用rendering选项:

[java] view plaincopy
  1. // Create a run and render task object.  
  2. IRunAndRenderTask task = engine.createRunAndRenderTask( runnable );  
  3. // Set values for all parameters in a HashMap, parameterValues  
  4. task.setParameterValues( parameterValues );  
  5. // Validate parameter values.  
  6. boolean parametersAreGood = task.validateParameters( );  
  7. // Set the name of an output file.  
  8. HTMLRenderOption options = new HTMLRenderOption( );  
  9. String output = name.replaceFirst( ".rptdesign"".html" );  
  10. options.setOutputFileName( output );  
  11. options.setImageDirectory( "image" );  
  12. options.setHtmlRtLFlag( true );  
  13. options.setEmbeddable( false );  
  14. // Apply the rendering options to the task.  
  15. task.setRenderOption( options );  
  16. // Run and close the task  
  17. task.run();  
  18. task.close();  

设置PDF rendering选项
生成PDF格式的报表需要在报表中嵌入字体,或者使用非标准路径的字体,应用程序支持PDF rendering以下设置:
■ 字体路径,如果使用自定义路径下的字体,使用setFontDirectory( )进行设置。
■ 嵌入的字体,调用PDFRenderOption.setEmbededFont( )可以使用嵌入字体。

五、生成报表

IRunAndRenderTaskIRunTask对象的run方法可以生成报表,同时要处理run方法抛出的EngineException异常。
下面的代码展示了如何生成一个报表:

[java] view plaincopy
  1. try {  
  2. task.run( );  
  3. System.out.println( "Created Report " + output + "." );  
  4. }catch ( EngineException e1 ) {  
  5. System.err.println( "Report " + name + " run failed." );  
  6. System.err.println( e1.toString( ) );  
  7. }  
  8. engine.destroy( );  

六、取消报表运行任务

BIRT报表引擎支持检查引擎任务的状态,并取消这个任务。通常使用不同的进程来执行这些操作。
使用EngineTask.getStatus( )方法可以检查报表的运行状态,返回值有下面这些:
■ IEngineTask.STATUS_NOT_STARTED. 任务没有启动
■ IEngineTask.STATUS_RUNNING. 任务正在运行中
■ IEngineTask.STATUS_SUCCEEDED. 任务正常结束
■ IEngineTask.STATUS_FAILED. 任务没有正常执行
■ IEngineTask.STATUS_CANCELLED. 任务被取消
调用IEngineTask.cancel( )方法可以取消任务。如果一个正在运行的任务被取消了,它将停止生成报表,如果任务正在查询数据库,则数据库要继续执行完查询任务。
下面就是一个取消任务的例子:

[java] view plaincopy
  1. private class CancelReport extends Thread  
  2. {  
  3. private IEngineTask eTask;  
  4. public CancelReport( String myName, IEngineTask task ) {  
  5. super( myName );  
  6. eTask = task;  
  7. }  
  8. public void cancel( ) {  
  9. try {  
  10. Thread.currentThread( ).sleep( 100 );  
  11. eTask.cancel( );  
  12. System.out.println( "#### Report cancelled #####" );  
  13. }catch( Exception e )  
  14. {  
  15. e.printStackTrace();  
  16. }  
  17. }  
  18. }  
  19. CancelReport cancelThread = new CancelReport( "cancelReport", task);  
  20. cancelThread.cancel( );  
下面我给出几个比较完整的例子来讲解报表引擎的工作。

下面是一个运行并导出部分列数据的代码:

[java] view plaincopy
  1. package REAPI;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.Iterator;  
  5. import java.util.logging.Level;  
  6.   
  7. import org.eclipse.birt.core.framework.Platform;  
  8. import org.eclipse.birt.data.engine.api.IConditionalExpression;  
  9. import org.eclipse.birt.data.engine.api.IFilterDefinition;  
  10. import org.eclipse.birt.data.engine.api.querydefn.ConditionalExpression;  
  11. import org.eclipse.birt.data.engine.api.querydefn.FilterDefinition;  
  12. import org.eclipse.birt.data.engine.core.DataException;  
  13. import org.eclipse.birt.report.engine.api.EngineConfig;  
  14. import org.eclipse.birt.report.engine.api.EngineException;  
  15. import org.eclipse.birt.report.engine.api.IDataExtractionTask;  
  16. import org.eclipse.birt.report.engine.api.IDataIterator;  
  17. import org.eclipse.birt.report.engine.api.IExtractionResults;  
  18. import org.eclipse.birt.report.engine.api.IReportDocument;  
  19. import org.eclipse.birt.report.engine.api.IReportEngine;  
  20. import org.eclipse.birt.report.engine.api.IReportEngineFactory;  
  21. import org.eclipse.birt.report.engine.api.IResultMetaData;  
  22. import org.eclipse.birt.report.engine.api.IResultSetItem;  
  23.   
  24. public class DataExtract {  
  25.   
  26.     static void readReport() throws EngineException  
  27.     {  
  28.         IReportEngine engine=null;  
  29.         EngineConfig config = null;  
  30.   
  31.         try{  
  32.       
  33.             config = new EngineConfig( );             
  34.             config.setBIRTHome("E:\\birt汉化包\\birt-runtime-3_7_2\\ReportEngine");  
  35.             config.setLogConfig(null, Level.OFF);  
  36.             Platform.startup( config );  
  37.             IReportEngineFactory factory = (IReportEngineFactory) Platform  
  38.             .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );  
  39.             engine = factory.createReportEngine( config );  
  40.         }catch( Exception ex){  
  41.             ex.printStackTrace();  
  42.         }  
  43.           
  44.         IReportDocument iReportDocument = engine.openReportDocument("d:\\customers.rptdocument");  
  45.           
  46.         //Setup data extraction task  
  47.         IDataExtractionTask task = engine.createDataExtractionTask(iReportDocument);          
  48.       
  49.         /** 
  50.          * returns the metadata corresponding to the data stored in the report 
  51.          * document.  Could specify a component. 
  52.          */  
  53.           
  54.         ArrayList resultSetList = (ArrayList)task.getResultSetList( );  
  55.   
  56.         IResultSetItem resultItem = null;         
  57.         Iterator it = resultSetList.iterator();  
  58.         while (it.hasNext()) {  
  59.             resultItem = (IResultSetItem)it.next();  
  60.             System.out.println("ResultSetName ====> " + resultItem.getResultSetName( ));  
  61.         }         
  62.           
  63.         resultItem = (IResultSetItem)resultSetList.get( 0 );  
  64.         String dispName = resultItem.getResultSetName( );  
  65.         //Name Tables for ease  
  66.         task.selectResultSet( dispName );  
  67.           
  68.         //Return Only customers between 201-300  
  69.         IFilterDefinition[] FilterExpression = new IFilterDefinition[2];  
  70.         FilterExpression[0] = new FilterDefinition( new ConditionalExpression( "row[\"CUSTOMERNUMBER\"]",  
  71.         IConditionalExpression.OP_GE, "201"null ) );  
  72.         FilterExpression[1] = new FilterDefinition( new ConditionalExpression( "row[\"CUSTOMERNUMBER\"]",  
  73.         IConditionalExpression.OP_LT, "300"null ) );  
  74.         task.setFilters( FilterExpression );      
  75.           
  76.         IExtractionResults iExtractResults = task.extract();  
  77.   
  78.         IDataIterator iData = null;  
  79.         try{  
  80.             if ( iExtractResults != null )  
  81.             {  
  82.   
  83.                 iData = iExtractResults.nextResultIterator( );  
  84.                 //Get metadata on retrieved results  
  85.                 IResultMetaData irmd = iData.getResultMetaData();  
  86.                 if ( iData != null  ){  
  87.                     int colCount = irmd.getColumnCount();  
  88.                     System.out.println("Cloumn Count =" + colCount );  
  89.                     forint j=0; j< colCount; j++){  
  90.                         System.out.println("Cloumn Name =" + irmd.getColumnName(j) );  
  91.                         System.out.println("Cloumn Type =" + irmd.getColumnTypeName(j) );  
  92.                           
  93.                     }  
  94.                   
  95.                     while ( iData.next( ) )  
  96.                     {     
  97.                         //Just disply the first two columns  
  98.                         Object objColumn1;  
  99.                         Object objColumn2;  
  100.                         try{  
  101.                             objColumn1 = iData.getValue(4);  
  102.                         }catch(DataException e){  
  103.                             objColumn1 = new String("");  
  104.                         }  
  105.                         try{  
  106.                             objColumn2 = iData.getValue(12);  
  107.                         }catch(DataException e){  
  108.                             objColumn2 = new String("");  
  109.                         }  
  110.                             System.out.println( objColumn1 + " , " + objColumn2 );  
  111.                     }  
  112.                     iData.close();  
  113.                 }  
  114.             }  
  115.         }  
  116.         catch( Exception e){  
  117.             e.printStackTrace();  
  118.         }  
  119.   
  120.         task.close();  
  121.         engine.destroy();  
  122.         Platform.shutdown();  
  123.         System.out.println("Finished");  
  124.         System.exit(0);  
  125.     }     
  126.     /** 
  127.      * @param args 
  128.      */  
  129.     public static void main(String[] args) {  
  130.         try  
  131.         {  
  132.             readReport( );  
  133.         }  
  134.         catch ( Exception e )  
  135.         {  
  136.             e.printStackTrace();  
  137.         }  
  138.     }  
  139.   
  140. }  

其中customers.rptdesign的设计如下:


预览如下:


该源码打印了结果集中的所有表名,从第一个表中获取了结果集列属性信息,导出了客户号在201300之间客户第4列和第12列信息

运行结果如下:

[plain] view plaincopy
  1. ResultSetName ====> MyCustomerTable  
  2. ResultSetName ====> innertable  
  3. ResultSetName ====> innertable_1  
  4. ResultSetName ====> innertable_2  
  5. ResultSetName ====> innertable_3  
  6. ResultSetName ====> innertable_4  
  7. ResultSetName ====> innertable_5  
  8. ResultSetName ====> innertable_6  
  9. ResultSetName ====> innertable_7  
  10. ResultSetName ====> innertable_8  
  11. ResultSetName ====> innertable_9  
  12. ResultSetName ====> innertable_10  
  13. ResultSetName ====> innertable_11  
  14. ResultSetName ====> innertable_12  
  15. ResultSetName ====> innertable_13  
  16. ResultSetName ====> innertable_14  
  17. ResultSetName ====> innertable_15  
  18. ResultSetName ====> innertable_16  
  19. ResultSetName ====> innertable_17  
  20. ResultSetName ====> innertable_18  
  21. ResultSetName ====> innertable_19  
  22. ResultSetName ====> innertable_20  
  23. ResultSetName ====> innertable_21  
  24. ResultSetName ====> innertable_22  
  25. ResultSetName ====> innertable_23  
  26. ResultSetName ====> innertable_24  
  27. ResultSetName ====> innertable_25  
  28. ResultSetName ====> innertable_26  
  29. ResultSetName ====> innertable_27  
  30. ResultSetName ====> innertable_28  
  31. ResultSetName ====> innertable_29  
  32. ResultSetName ====> innertable_30  
  33. ResultSetName ====> innertable_31  
  34. ResultSetName ====> innertable_32  
  35. ResultSetName ====> innertable_33  
  36. ResultSetName ====> innertable_34  
  37. ResultSetName ====> innertable_35  
  38. ResultSetName ====> innertable_36  
  39. ResultSetName ====> innertable_37  
  40. ResultSetName ====> innertable_38  
  41. ResultSetName ====> innertable_39  
  42. ResultSetName ====> innertable_40  
  43. ResultSetName ====> innertable_41  
  44. ResultSetName ====> innertable_42  
  45. ResultSetName ====> innertable_43  
  46. ResultSetName ====> innertable_44  
  47. ResultSetName ====> innertable_45  
  48. ResultSetName ====> innertable_46  
  49. ResultSetName ====> innertable_47  
  50. ResultSetName ====> innertable_48  
  51. ResultSetName ====> innertable_49  
  52. ResultSetName ====> innertable_50  
  53. ResultSetName ====> innertable_51  
  54. ResultSetName ====> innertable_52  
  55. ResultSetName ====> innertable_53  
  56. ResultSetName ====> innertable_54  
  57. ResultSetName ====> innertable_55  
  58. ResultSetName ====> innertable_56  
  59. ResultSetName ====> innertable_57  
  60. ResultSetName ====> innertable_58  
  61. ResultSetName ====> innertable_59  
  62. ResultSetName ====> innertable_60  
  63. ResultSetName ====> innertable_61  
  64. ResultSetName ====> innertable_62  
  65. ResultSetName ====> innertable_63  
  66. ResultSetName ====> innertable_64  
  67. ResultSetName ====> innertable_65  
  68. ResultSetName ====> innertable_66  
  69. ResultSetName ====> innertable_67  
  70. ResultSetName ====> innertable_68  
  71. ResultSetName ====> innertable_69  
  72. ResultSetName ====> innertable_70  
  73. ResultSetName ====> innertable_71  
  74. ResultSetName ====> innertable_72  
  75. ResultSetName ====> innertable_73  
  76. ResultSetName ====> innertable_74  
  77. ResultSetName ====> innertable_75  
  78. ResultSetName ====> innertable_76  
  79. ResultSetName ====> innertable_77  
  80. ResultSetName ====> innertable_78  
  81. ResultSetName ====> innertable_79  
  82. ResultSetName ====> innertable_80  
  83. ResultSetName ====> innertable_81  
  84. ResultSetName ====> innertable_82  
  85. ResultSetName ====> innertable_83  
  86. ResultSetName ====> innertable_84  
  87. ResultSetName ====> innertable_85  
  88. ResultSetName ====> innertable_86  
  89. ResultSetName ====> innertable_87  
  90. ResultSetName ====> innertable_88  
  91. ResultSetName ====> innertable_89  
  92. ResultSetName ====> innertable_90  
  93. ResultSetName ====> innertable_91  
  94. ResultSetName ====> innertable_92  
  95. ResultSetName ====> innertable_93  
  96. ResultSetName ====> innertable_94  
  97. ResultSetName ====> innertable_95  
  98. ResultSetName ====> innertable_96  
  99. ResultSetName ====> innertable_97  
  100. ResultSetName ====> innertable_98  
  101. ResultSetName ====> innertable_99  
  102. ResultSetName ====> innertable_100  
  103. ResultSetName ====> innertable_101  
  104. ResultSetName ====> innertable_102  
  105. ResultSetName ====> innertable_103  
  106. ResultSetName ====> innertable_104  
  107. ResultSetName ====> innertable_105  
  108. ResultSetName ====> innertable_106  
  109. ResultSetName ====> innertable_107  
  110. ResultSetName ====> innertable_108  
  111. ResultSetName ====> innertable_109  
  112. ResultSetName ====> innertable_110  
  113. ResultSetName ====> innertable_111  
  114. ResultSetName ====> innertable_112  
  115. ResultSetName ====> innertable_113  
  116. ResultSetName ====> innertable_114  
  117. ResultSetName ====> innertable_115  
  118. ResultSetName ====> innertable_116  
  119. ResultSetName ====> innertable_117  
  120. ResultSetName ====> innertable_118  
  121. ResultSetName ====> innertable_119  
  122. ResultSetName ====> innertable_120  
  123. ResultSetName ====> innertable_121  
  124. Cloumn Count =13  
  125. Cloumn Name =CUSTOMERNUMBER  
  126. Cloumn Type =Integer  
  127. Cloumn Name =CUSTOMERNAME  
  128. Cloumn Type =String  
  129. Cloumn Name =CONTACTLASTNAME  
  130. Cloumn Type =String  
  131. Cloumn Name =CONTACTFIRSTNAME  
  132. Cloumn Type =String  
  133. Cloumn Name =PHONE  
  134. Cloumn Type =String  
  135. Cloumn Name =ADDRESSLINE1  
  136. Cloumn Type =String  
  137. Cloumn Name =ADDRESSLINE2  
  138. Cloumn Type =String  
  139. Cloumn Name =CITY  
  140. Cloumn Type =String  
  141. Cloumn Name =STATE  
  142. Cloumn Type =String  
  143. Cloumn Name =POSTALCODE  
  144. Cloumn Type =String  
  145. Cloumn Name =COUNTRY  
  146. Cloumn Type =String  
  147. Cloumn Name =SALESREPEMPLOYEENUMBER  
  148. Cloumn Type =Integer  
  149. Cloumn Name =CREDITLIMIT  
  150. Cloumn Type =Float  
  151. 02 9936 8555 , 107800.0  
  152. +61 2 9495 8555 , 93300.0  
  153. (604) 555-3392 , 90300.0  
  154. (514) 555-8054 , 48700.0  
  155. (604) 555-4555 , 89600.0  
  156. 86 21 3555 , 120800.0  
  157. 88.60.1555 , 53800.0  
  158. 61.77.6555 , 61100.0  
  159. +33 1 46 62 7555 , 68100.0  
  160. 30.59.8555 , 77900.0  
  161. 0372-555188 , 0.0  
  162. 069-0555984 , 0.0  
  163. 0221-5554327 , 120400.0  
  164. 089-0877555 , 0.0  
  165. +852 2251 1555 , 58600.0  
  166. 011-4988555 , 113000.0  
  167. 035-640555 , 119600.0  
  168. +47 2212 1555 , 95100.0  
  169. +612 9411 1555 , 0.0  
  170. (93) 203 4555 , 60300.0  
  171. (91) 745 6555 , 0.0  
  172. +41 26 425 50 01 , 0.0  
  173. 0897-034555 , 141300.0  
  174. (171) 555-2282 , 92700.0  
  175. (198) 555-8888 , 93900.0  
  176. 6175557555 , 68700.0  
  177. 6265557265 , 90700.0  
  178. 3105552373 , 11000.0  
  179. 7605558146 , 105000.0  
  180. 6175558555 , 123700.0  
  181. Finished  

下面这个案例运行报表,并导出html文件:

[java] view plaincopy
  1. package REAPI;  
  2.   
  3. import java.util.logging.Level;  
  4. import org.eclipse.birt.core.framework.Platform;  
  5. import org.eclipse.birt.report.engine.api.EXCELRenderOption;  
  6. import org.eclipse.birt.report.engine.api.EngineConfig;  
  7. import org.eclipse.birt.report.engine.api.EngineException;  
  8. import org.eclipse.birt.report.engine.api.HTMLRenderOption;  
  9. import org.eclipse.birt.report.engine.api.IPDFRenderOption;  
  10. import org.eclipse.birt.report.engine.api.IRenderOption;  
  11. import org.eclipse.birt.report.engine.api.IRenderTask;  
  12. import org.eclipse.birt.report.engine.api.IReportDocument;  
  13. import org.eclipse.birt.report.engine.api.IReportEngine;  
  14. import org.eclipse.birt.report.engine.api.IReportEngineFactory;  
  15. import org.eclipse.birt.report.engine.api.PDFRenderOption;  
  16. import org.eclipse.birt.report.engine.api.RenderOption;  
  17.   
  18.   
  19. public class RenderTask {  
  20.   
  21.     public void runReport() throws EngineException  
  22.     {  
  23.   
  24.         IReportEngine engine=null;  
  25.         EngineConfig config = null;  
  26.   
  27.         try{  
  28.       
  29.             config = new EngineConfig( );             
  30.             config.setBIRTHome("E:\\birt汉化包\\birt-runtime-3_7_2\\ReportEngine");  
  31.             config.setLogConfig(null, Level.FINE);  
  32.             Platform.startup( config );  
  33.             IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );  
  34.             engine = factory.createReportEngine( config );  
  35.         }catch( Exception ex){  
  36.             ex.printStackTrace();  
  37.         }  
  38.   
  39.         IReportDocument document = null;  
  40.         //Open the report design  
  41.         document = engine.openReportDocument("d:\\ps.rptdocument");   
  42.         IRenderOption options = new RenderOption();       
  43.         options.setOutputFormat("html");  
  44.         options.setOutputFileName("d:\\ps.html");  
  45.         options.setOption( IRenderOption.HTML_PAGINATION,  
  46.                 Boolean.TRUE );       
  47. //            
  48. //      if( options.getOutputFormat().equalsIgnoreCase("html")){  
  49. //          HTMLRenderOption htmlOptions = new HTMLRenderOption( options);  
  50. //          htmlOptions.setImageDirectory("output/image");  
  51. //          //set this if you want your image source url to be altered  
  52. //          //htmlOptions.setBaseImageURL("http://myhos/prependme?image=");  
  53. //          htmlOptions.setHtmlRtLFlag(false);  
  54. //          htmlOptions.setEmbeddable(false);  
  55. //      }else if( options.getOutputFormat().equalsIgnoreCase("pdf") ){  
  56. //            
  57. //          PDFRenderOption pdfOptions = new PDFRenderOption( options );  
  58. //          /*  CLIP_CONTENT:             clip the content  
  59. //           *  FIT_TO_PAGE_SIZE:         scale the content to fit into the page  
  60. //           *  OUTPUT_TO_MULTIPLE_PAGES: divided the content into multiple pages  
  61. //           *  ENLARGE_PAGE_SIZE:        enlarge the page size to contain all the content.  
  62. //           */  
  63. //          pdfOptions.setOption( IPDFRenderOption.PAGE_OVERFLOW, Integer.valueOf( PDFRenderOption.FIT_TO_PAGE_SIZE ) );  
  64. //  
  65. //      }  
  66.           
  67.         IRenderTask task = engine.createRenderTask(document);         
  68.         task.setRenderOption(options);  
  69.         //task.setPageRange("1-3");  
  70.         //task.setPageNumber(0);  
  71.         //task.setReportlet("chart3");  
  72.         task.render();  
  73.         task.close();  
  74.         document.close();  
  75.         engine.destroy();  
  76.         Platform.shutdown();  
  77.         System.out.println("Finished");  
  78.     }     
  79.   
  80.   
  81.     /** 
  82.      * @param args 
  83.      */  
  84.     public static void main(String[] args) {  
  85.         try  
  86.         {  
  87.   
  88.             RenderTask ex = new RenderTask( );  
  89.             ex.runReport();  
  90.   
  91.         }  
  92.         catch ( Exception e )  
  93.         {  
  94.             e.printStackTrace();  
  95.         }  
  96.         System.exit(0);  
  97.     }  
  98.       
  99. }  

报表的设计如下:


运行源码,可以看到D盘导出的文件:


而下面的这段源码,打印了报表的所有参数:

[java] view plaincopy
  1. package REAPI;  
  2.   
  3. import java.util.Collection;  
  4. import java.util.Collections;  
  5. import java.util.HashMap;  
  6. import java.util.Iterator;  
  7. import java.util.logging.Level;  
  8.   
  9. import org.eclipse.birt.core.framework.Platform;  
  10. import org.eclipse.birt.report.engine.api.EngineConfig;  
  11. import org.eclipse.birt.report.engine.api.EngineException;  
  12. import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;  
  13. import org.eclipse.birt.report.engine.api.IParameterDefnBase;  
  14. import org.eclipse.birt.report.engine.api.IParameterGroupDefn;  
  15. import org.eclipse.birt.report.engine.api.IParameterSelectionChoice;  
  16. import org.eclipse.birt.report.engine.api.IReportEngine;  
  17. import org.eclipse.birt.report.engine.api.IReportEngineFactory;  
  18. import org.eclipse.birt.report.engine.api.IReportRunnable;  
  19. import org.eclipse.birt.report.engine.api.IScalarParameterDefn;  
  20. import org.eclipse.birt.report.model.api.CascadingParameterGroupHandle;  
  21. import org.eclipse.birt.report.model.api.ScalarParameterHandle;  
  22.   
  23. public class ReportParameters {  
  24.   
  25.     @SuppressWarnings("unchecked")  
  26.     static void executeReport() throws EngineException  
  27.     {  
  28.         HashMap parmDetails = new HashMap();  
  29.         IReportEngine engine=null;  
  30.         EngineConfig config = null;  
  31.         try{  
  32.   
  33.             config = new EngineConfig( );             
  34.             config.setBIRTHome("E:\\birt汉化包\\birt-runtime-3_7_2\\ReportEngine");  
  35.             config.setLogConfig(null, Level.OFF);  
  36.             Platform.startup( config );  
  37.             IReportEngineFactory factory = (IReportEngineFactory) Platform  
  38.             .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );  
  39.             engine = factory.createReportEngine( config );  
  40.         }catch( Exception ex){  
  41.             ex.printStackTrace();  
  42.         }  
  43.   
  44.   
  45.         //Open a report design   
  46.         IReportRunnable design = engine.openReportDesign("d:\\parameters.rptdesign");   
  47.   
  48.         IGetParameterDefinitionTask task = engine.createGetParameterDefinitionTask( design );  
  49.         Collection params = task.getParameterDefns( true );  
  50.   
  51.   
  52.         //task.getSelectionListForCascadingGroup();  
  53.         Iterator iter = params.iterator( );  
  54.         while ( iter.hasNext( ) )  
  55.         {  
  56.             IParameterDefnBase param = (IParameterDefnBase) iter.next( );  
  57.   
  58.             if ( param instanceof IParameterGroupDefn )  
  59.             {  
  60.                 IParameterGroupDefn group = (IParameterGroupDefn) param;  
  61.                 System.out.println( "Parameter Group: " + group.getName( ) );  
  62.   
  63.   
  64.                 // Do something with the parameter group.  
  65.                 // Iterate over group contents.  
  66.   
  67.                 Iterator i2 = group.getContents( ).iterator( );  
  68.                 while ( i2.hasNext( ) )  
  69.                 {  
  70.                     IScalarParameterDefn scalar = (IScalarParameterDefn) i2.next( );  
  71.                     //System.out.println("\t" + scalar.getName());  
  72.                     parmDetails.put( scalar.getName(), loadParameterDetails( task, scalar, design, group));  
  73.                 }  
  74.   
  75.             }  
  76.             else  
  77.             {  
  78.   
  79.                 IScalarParameterDefn scalar = (IScalarParameterDefn) param;  
  80.                 //System.out.println(param.getName());  
  81.                 parmDetails.put( scalar.getName(),loadParameterDetails( task, scalar, design, null));                             
  82.   
  83.   
  84.             }  
  85.         }  
  86.   
  87.         task.close();  
  88.         engine.destroy();  
  89.         Platform.shutdown();  
  90.         System.out.println("Finished");  
  91.     }  
  92.   
  93.     private static HashMap loadParameterDetails(IGetParameterDefinitionTask task, IScalarParameterDefn scalar, IReportRunnable report, IParameterGroupDefn group){  
  94.   
  95.   
  96.   
  97.         HashMap parameter = new HashMap();  
  98.   
  99.         if( group == null){  
  100.             parameter.put("Parameter Group""Default");  
  101.         }else{  
  102.             parameter.put("Parameter Group", group.getName());            
  103.         }  
  104.         parameter.put("Name", scalar.getName());  
  105.         parameter.put("Help Text", scalar.getHelpText());  
  106.         parameter.put("Display Name", scalar.getDisplayName());  
  107.         //this is a format code such as  > for UPPERCASE  
  108.         parameter.put("Display Format", scalar.getDisplayFormat());  
  109.   
  110.         if( scalar.isHidden() ){  
  111.             parameter.put("Hidden""Yes");  
  112.         }else{  
  113.             parameter.put("Hidden""No");  
  114.         }  
  115.         if( scalar.isHidden() ){  
  116.             parameter.put("Hidden""Yes");  
  117.         }else{  
  118.             parameter.put("Hidded""No");  
  119.         }  
  120.         if( scalar.isRequired() ){  
  121.             parameter.put("Is Required""Yes");              
  122.         }else{  
  123.             parameter.put("Is Required""No");  
  124.         }  
  125.         if( scalar.isValueConcealed() ){  
  126.             parameter.put("Conceal Entry""Yes");  //ie passwords etc  
  127.         }else{  
  128.             parameter.put("Conceal Entry""No");  
  129.         }  
  130.   
  131.   
  132.         switch (scalar.getControlType()) {  
  133.         case IScalarParameterDefn.TEXT_BOX:  parameter.put("Type""Text Box"); break;  
  134.         case IScalarParameterDefn.LIST_BOX:  parameter.put("Type""List Box"); break;  
  135.         case IScalarParameterDefn.RADIO_BUTTON:  parameter.put("Type""List Box"); break;  
  136.         case IScalarParameterDefn.CHECK_BOX:  parameter.put("Type""List Box"); break;  
  137.         default: parameter.put("Type""Text Box");break;  
  138.         }  
  139.   
  140.   
  141.         switch (scalar.getDataType()) {  
  142.         case IScalarParameterDefn.TYPE_STRING:  parameter.put("Data Type""String"); break;  
  143.         case IScalarParameterDefn.TYPE_FLOAT:  parameter.put("Data Type""Float"); break;  
  144.         case IScalarParameterDefn.TYPE_DECIMAL:  parameter.put("Data Type""Decimal"); break;  
  145.         case IScalarParameterDefn.TYPE_DATE_TIME:  parameter.put("Data Type""Date Time"); break;  
  146.         case IScalarParameterDefn.TYPE_BOOLEAN:  parameter.put("Data Type""Boolean"); break;  
  147.         default:  parameter.put("Data Type""Any"); break;  
  148.         }  
  149.   
  150.   
  151.         ScalarParameterHandle parameterHandle = ( ScalarParameterHandle ) scalar.getHandle();     
  152.   
  153.         parameter.put("Default Value", scalar.getDefaultValue());  
  154.         parameter.put("Prompt Text", scalar.getPromptText());  
  155.         parameter.put("Data Set Expression", parameterHandle.getValueExpr());  
  156.   
  157.         if(scalar.getControlType() !=  IScalarParameterDefn.TEXT_BOX)  
  158.         {  
  159.             //System.out.println("dynamic parameter");  
  160.   
  161.             if ( parameterHandle.getContainer( ) instanceof CascadingParameterGroupHandle ){  
  162.                 Collection sList = Collections.EMPTY_LIST;  
  163.                 if ( parameterHandle.getContainer( ) instanceof CascadingParameterGroupHandle )  
  164.                 {  
  165.   
  166.                     String groupName = parameterHandle.getContainer( ).getName( );  
  167.                     //used for Cascading parms see IGetParameterDefinitionTask.java code for comments  
  168.                     //task.evaluateQuery( groupName );  
  169.   
  170.                     //Need to load this for calls to get next level.  
  171.                     //This just gets the first level  
  172.                     Object [] keyValueTmp = new Object[1];  
  173.                     sList = task.getSelectionListForCascadingGroup( groupName, keyValueTmp );  
  174.       
  175.   
  176.                     for ( Iterator sl = sList.iterator( ); sl.hasNext( ); )  
  177.                     {  
  178.                         IParameterSelectionChoice sI = (IParameterSelectionChoice) sl.next( );  
  179.   
  180.   
  181.                         Object value = sI.getValue( );  
  182.                         Object label = sI.getLabel( );  
  183.                         System.out.println( label + "--" + value);  
  184.   
  185.                     }                         
  186.   
  187.                 }                 
  188.             }else{  
  189.                 Collection selectionList = task.getSelectionList( scalar.getName() );  
  190.   
  191.                 if ( selectionList != null )  
  192.                 {  
  193.                     HashMap dynamicList = new HashMap();         
  194.   
  195.                     for ( Iterator sliter = selectionList.iterator( ); sliter.hasNext( ); )  
  196.                     {  
  197.                         IParameterSelectionChoice selectionItem = (IParameterSelectionChoice) sliter.next( );  
  198.   
  199.                         Object value = selectionItem.getValue( );  
  200.                         String label = selectionItem.getLabel( );  
  201.   
  202.                         //System.out.println( label + "--" + value);  
  203.                         //Display label unless null then display value.  Value is the what should get passed to the report.  
  204.                         dynamicList.put(value,label);  
  205.   
  206.                     }  
  207.                     parameter.put("Selection List", dynamicList);  
  208.                 }  
  209.             }  
  210.   
  211.         }  
  212.   
  213.   
  214.         Iterator iter = parameter.keySet().iterator();  
  215.         System.out.println("======================Parameter =" + scalar.getName());  
  216.         while (iter.hasNext()) {  
  217.             String name = (String) iter.next();   
  218.             if( name.equals("Selection List")){  
  219.                 HashMap selList = (HashMap)parameter.get(name);  
  220.                 Iterator selIter = selList.keySet().iterator();  
  221.                 while (selIter.hasNext()) {  
  222.                     Object lbl = selIter.next();  
  223.                     System.out.println( "Selection List Entry ===== Key = " + lbl + " Value = " + selList.get(lbl));  
  224.                 }  
  225.   
  226.             }else{  
  227.                 System.out.println( name + " = " + parameter.get(name));                  
  228.             }  
  229.         }  
  230.         return parameter;  
  231.   
  232.     }     
  233.   
  234.     /** 
  235.      * @param args 
  236.      */  
  237.     public static void main(String[] args) {  
  238.         try  
  239.         {  
  240.             executeReport( );  
  241.         }  
  242.         catch ( Exception e )  
  243.         {  
  244.             e.printStackTrace();  
  245.         }  
  246.     }  
  247.   
  248. }  

运行结果如下:

[plain] view plaincopy
  1. ======================Parameter =parameter1  
  2. Hidded = No  
  3. Default Value = 1  
  4. Type = Text Box  
  5. Conceal Entry = No  
  6. Hidden = No  
  7. Data Set Expression = null  
  8. Name = parameter1  
  9. Is Required = Yes  
  10. Help Text = null  
  11. Parameter Group = Default  
  12. Display Name = null  
  13. Display Format = #,##0.00%  
  14. Data Type = Decimal  
  15. Prompt Text = "This i prompt text"  
  16. Parameter Group: ParmGroup1  
  17. ======================Parameter =Parameter2  
  18. Hidded = No  
  19. Default Value = parm2  
  20. Type = Text Box  
  21. Conceal Entry = No  
  22. Hidden = No  
  23. Data Set Expression = null  
  24. Name = Parameter2  
  25. Is Required = No  
  26. Help Text = null  
  27. Parameter Group = ParmGroup1  
  28. Display Name = null  
  29. Display Format = Unformatted  
  30. Data Type = String  
  31. Prompt Text = null  
  32. ======================Parameter =Parameter3  
  33. Hidded = No  
  34. Default Value = 10101  
  35. Type = List Box  
  36. Conceal Entry = No  
  37. Hidden = No  
  38. Selection List Entry ===== Key = 10346 Value = 10346  
  39. Selection List Entry ===== Key = 10207 Value = 10207  
  40. Selection List Entry ===== Key = 10347 Value = 10347  
  41. Selection List Entry ===== Key = 10208 Value = 10208  
  42. Selection List Entry ===== Key = 10344 Value = 10344  
  43. Selection List Entry ===== Key = 10205 Value = 10205  
  44. Selection List Entry ===== Key = 10345 Value = 10345  
  45. Selection List Entry ===== Key = 10206 Value = 10206  
  46. Selection List Entry ===== Key = 10342 Value = 10342  
  47. Selection List Entry ===== Key = 10343 Value = 10343  
  48. Selection List Entry ===== Key = 10340 Value = 10340  
  49. Selection List Entry ===== Key = 10209 Value = 10209  
  50. Selection List Entry ===== Key = 10341 Value = 10341  
  51. Selection List Entry ===== Key = 10200 Value = 10200  
  52. Selection List Entry ===== Key = 10203 Value = 10203  
  53. Selection List Entry ===== Key = 10204 Value = 10204  
  54. Selection List Entry ===== Key = 10348 Value = 10348  
  55. Selection List Entry ===== Key = 10201 Value = 10201  
  56. Selection List Entry ===== Key = 10349 Value = 10349  
  57. Selection List Entry ===== Key = 10202 Value = 10202  
  58. Selection List Entry ===== Key = 10333 Value = 10333  
  59. Selection List Entry ===== Key = 10334 Value = 10334  
  60. Selection List Entry ===== Key = 10335 Value = 10335  
  61. Selection List Entry ===== Key = 10336 Value = 10336  
  62. Selection List Entry ===== Key = 10330 Value = 10330  
  63. Selection List Entry ===== Key = 10331 Value = 10331  
  64. Selection List Entry ===== Key = 10332 Value = 10332  
  65. Selection List Entry ===== Key = 10337 Value = 10337  
  66. Selection List Entry ===== Key = 10338 Value = 10338  
  67. Selection List Entry ===== Key = 10339 Value = 10339  
  68. Selection List Entry ===== Key = 10320 Value = 10320  
  69. Selection List Entry ===== Key = 10321 Value = 10321  
  70. Selection List Entry ===== Key = 10324 Value = 10324  
  71. Selection List Entry ===== Key = 10229 Value = 10229  
  72. Selection List Entry ===== Key = 10325 Value = 10325  
  73. Selection List Entry ===== Key = 10322 Value = 10322  
  74. Selection List Entry ===== Key = 10227 Value = 10227  
  75. Selection List Entry ===== Key = 10323 Value = 10323  
  76. Selection List Entry ===== Key = 10228 Value = 10228  
  77. Selection List Entry ===== Key = 10328 Value = 10328  
  78. Selection List Entry ===== Key = 10225 Value = 10225  
  79. Selection List Entry ===== Key = 10329 Value = 10329  
  80. Selection List Entry ===== Key = 10226 Value = 10226  
  81. Selection List Entry ===== Key = 10326 Value = 10326  
  82. Selection List Entry ===== Key = 10223 Value = 10223  
  83. Selection List Entry ===== Key = 10327 Value = 10327  
  84. Selection List Entry ===== Key = 10224 Value = 10224  
  85. Selection List Entry ===== Key = 10221 Value = 10221  
  86. Selection List Entry ===== Key = 10222 Value = 10222  
  87. Selection List Entry ===== Key = 10220 Value = 10220  
  88. Selection List Entry ===== Key = 10310 Value = 10310  
  89. Selection List Entry ===== Key = 10311 Value = 10311  
  90. Selection List Entry ===== Key = 10216 Value = 10216  
  91. Selection List Entry ===== Key = 10312 Value = 10312  
  92. Selection List Entry ===== Key = 10217 Value = 10217  
  93. Selection List Entry ===== Key = 10313 Value = 10313  
  94. Selection List Entry ===== Key = 10218 Value = 10218  
  95. Selection List Entry ===== Key = 10314 Value = 10314  
  96. Selection List Entry ===== Key = 10219 Value = 10219  
  97. Selection List Entry ===== Key = 10315 Value = 10315  
  98. Selection List Entry ===== Key = 10212 Value = 10212  
  99. Selection List Entry ===== Key = 10316 Value = 10316  
  100. Selection List Entry ===== Key = 10213 Value = 10213  
  101. Selection List Entry ===== Key = 10317 Value = 10317  
  102. Selection List Entry ===== Key = 10214 Value = 10214  
  103. Selection List Entry ===== Key = 10318 Value = 10318  
  104. Selection List Entry ===== Key = 10215 Value = 10215  
  105. Selection List Entry ===== Key = 10319 Value = 10319  
  106. Selection List Entry ===== Key = 10210 Value = 10210  
  107. Selection List Entry ===== Key = 10211 Value = 10211  
  108. Selection List Entry ===== Key = 10244 Value = 10244  
  109. Selection List Entry ===== Key = 10243 Value = 10243  
  110. Selection List Entry ===== Key = 10242 Value = 10242  
  111. Selection List Entry ===== Key = 10241 Value = 10241  
  112. Selection List Entry ===== Key = 10248 Value = 10248  
  113. Selection List Entry ===== Key = 10247 Value = 10247  
  114. Selection List Entry ===== Key = 10246 Value = 10246  
  115. Selection List Entry ===== Key = 10245 Value = 10245  
  116. Selection List Entry ===== Key = 10389 Value = 10389  
  117. Selection List Entry ===== Key = 10388 Value = 10388  
  118. Selection List Entry ===== Key = 10249 Value = 10249  
  119. Selection List Entry ===== Key = 10387 Value = 10387  
  120. Selection List Entry ===== Key = 10386 Value = 10386  
  121. Selection List Entry ===== Key = 10385 Value = 10385  
  122. Selection List Entry ===== Key = 10384 Value = 10384  
  123. Selection List Entry ===== Key = 10382 Value = 10382  
  124. Selection List Entry ===== Key = 10383 Value = 10383  
  125. Selection List Entry ===== Key = 10380 Value = 10380  
  126. Selection List Entry ===== Key = 10381 Value = 10381  
  127. Selection List Entry ===== Key = 10240 Value = 10240  
  128. Selection List Entry ===== Key = 10231 Value = 10231  
  129. Selection List Entry ===== Key = 10230 Value = 10230  
  130. Selection List Entry ===== Key = 10233 Value = 10233  
  131. Selection List Entry ===== Key = 10232 Value = 10232  
  132. Selection List Entry ===== Key = 10235 Value = 10235  
  133. Selection List Entry ===== Key = 10234 Value = 10234  
  134. Selection List Entry ===== Key = 10237 Value = 10237  
  135. Selection List Entry ===== Key = 10236 Value = 10236  
  136. Selection List Entry ===== Key = 10378 Value = 10378  
  137. Selection List Entry ===== Key = 10239 Value = 10239  
  138. Selection List Entry ===== Key = 10377 Value = 10377  
  139. Selection List Entry ===== Key = 10238 Value = 10238  
  140. Selection List Entry ===== Key = 10379 Value = 10379  
  141. Selection List Entry ===== Key = 10374 Value = 10374  
  142. Selection List Entry ===== Key = 10373 Value = 10373  
  143. Selection List Entry ===== Key = 10376 Value = 10376  
  144. Selection List Entry ===== Key = 10375 Value = 10375  
  145. Selection List Entry ===== Key = 10370 Value = 10370  
  146. Selection List Entry ===== Key = 10371 Value = 10371  
  147. Selection List Entry ===== Key = 10372 Value = 10372  
  148. Selection List Entry ===== Key = 10269 Value = 10269  
  149. Selection List Entry ===== Key = 10268 Value = 10268  
  150. Selection List Entry ===== Key = 10267 Value = 10267  
  151. Selection List Entry ===== Key = 10266 Value = 10266  
  152. Selection List Entry ===== Key = 10265 Value = 10265  
  153. Selection List Entry ===== Key = 10264 Value = 10264  
  154. Selection List Entry ===== Key = 10263 Value = 10263  
  155. Selection List Entry ===== Key = 10365 Value = 10365  
  156. Selection List Entry ===== Key = 10364 Value = 10364  
  157. Selection List Entry ===== Key = 10363 Value = 10363  
  158. Selection List Entry ===== Key = 10362 Value = 10362  
  159. Selection List Entry ===== Key = 10369 Value = 10369  
  160. Selection List Entry ===== Key = 10368 Value = 10368  
  161. Selection List Entry ===== Key = 10367 Value = 10367  
  162. Selection List Entry ===== Key = 10366 Value = 10366  
  163. Selection List Entry ===== Key = 10360 Value = 10360  
  164. Selection List Entry ===== Key = 10361 Value = 10361  
  165. Selection List Entry ===== Key = 10261 Value = 10261  
  166. Selection List Entry ===== Key = 10262 Value = 10262  
  167. Selection List Entry ===== Key = 10260 Value = 10260  
  168. Selection List Entry ===== Key = 10257 Value = 10257  
  169. Selection List Entry ===== Key = 10359 Value = 10359  
  170. Selection List Entry ===== Key = 10256 Value = 10256  
  171. Selection List Entry ===== Key = 10259 Value = 10259  
  172. Selection List Entry ===== Key = 10258 Value = 10258  
  173. Selection List Entry ===== Key = 10253 Value = 10253  
  174. Selection List Entry ===== Key = 10252 Value = 10252  
  175. Selection List Entry ===== Key = 10255 Value = 10255  
  176. Selection List Entry ===== Key = 10254 Value = 10254  
  177. Selection List Entry ===== Key = 10352 Value = 10352  
  178. Selection List Entry ===== Key = 10351 Value = 10351  
  179. Selection List Entry ===== Key = 10354 Value = 10354  
  180. Selection List Entry ===== Key = 10353 Value = 10353  
  181. Selection List Entry ===== Key = 10356 Value = 10356  
  182. Selection List Entry ===== Key = 10355 Value = 10355  
  183. Selection List Entry ===== Key = 10358 Value = 10358  
  184. Selection List Entry ===== Key = 10357 Value = 10357  
  185. Selection List Entry ===== Key = 10350 Value = 10350  
  186. Selection List Entry ===== Key = 10250 Value = 10250  
  187. Selection List Entry ===== Key = 10251 Value = 10251  
  188. Selection List Entry ===== Key = 10152 Value = 10152  
  189. Selection List Entry ===== Key = 10151 Value = 10151  
  190. Selection List Entry ===== Key = 10150 Value = 10150  
  191. Selection List Entry ===== Key = 10130 Value = 10130  
  192. Selection List Entry ===== Key = 10400 Value = 10400  
  193. Selection List Entry ===== Key = 10402 Value = 10402  
  194. Selection List Entry ===== Key = 10401 Value = 10401  
  195. Selection List Entry ===== Key = 10404 Value = 10404  
  196. Selection List Entry ===== Key = 10291 Value = 10291  
  197. Selection List Entry ===== Key = 10403 Value = 10403  
  198. Selection List Entry ===== Key = 10290 Value = 10290  
  199. Selection List Entry ===== Key = 10406 Value = 10406  
  200. Selection List Entry ===== Key = 10405 Value = 10405  
  201. Selection List Entry ===== Key = 10408 Value = 10408  
  202. Selection List Entry ===== Key = 10295 Value = 10295  
  203. Selection List Entry ===== Key = 10407 Value = 10407  
  204. Selection List Entry ===== Key = 10294 Value = 10294  
  205. Selection List Entry ===== Key = 10293 Value = 10293  
  206. Selection List Entry ===== Key = 10409 Value = 10409  
  207. Selection List Entry ===== Key = 10292 Value = 10292  
  208. Selection List Entry ===== Key = 10298 Value = 10298  
  209. Selection List Entry ===== Key = 10299 Value = 10299  
  210. Selection List Entry ===== Key = 10296 Value = 10296  
  211. Selection List Entry ===== Key = 10297 Value = 10297  
  212. Selection List Entry ===== Key = 10139 Value = 10139  
  213. Selection List Entry ===== Key = 10159 Value = 10159  
  214. Selection List Entry ===== Key = 10135 Value = 10135  
  215. Selection List Entry ===== Key = 10136 Value = 10136  
  216. Selection List Entry ===== Key = 10157 Value = 10157  
  217. Selection List Entry ===== Key = 10137 Value = 10137  
  218. Selection List Entry ===== Key = 10158 Value = 10158  
  219. Selection List Entry ===== Key = 10138 Value = 10138  
  220. Selection List Entry ===== Key = 10155 Value = 10155  
  221. Selection List Entry ===== Key = 10131 Value = 10131  
  222. Selection List Entry ===== Key = 10156 Value = 10156  
  223. Selection List Entry ===== Key = 10132 Value = 10132  
  224. Selection List Entry ===== Key = 10153 Value = 10153  
  225. Selection List Entry ===== Key = 10133 Value = 10133  
  226. Selection List Entry ===== Key = 10154 Value = 10154  
  227. Selection List Entry ===== Key = 10134 Value = 10134  
  228. Selection List Entry ===== Key = 10161 Value = 10161  
  229. Selection List Entry ===== Key = 10141 Value = 10141  
  230. Selection List Entry ===== Key = 10160 Value = 10160  
  231. Selection List Entry ===== Key = 10140 Value = 10140  
  232. Selection List Entry ===== Key = 10163 Value = 10163  
  233. Selection List Entry ===== Key = 10162 Value = 10162  
  234. Selection List Entry ===== Key = 10168 Value = 10168  
  235. Selection List Entry ===== Key = 10148 Value = 10148  
  236. Selection List Entry ===== Key = 10169 Value = 10169  
  237. Selection List Entry ===== Key = 10149 Value = 10149  
  238. Selection List Entry ===== Key = 10146 Value = 10146  
  239. Selection List Entry ===== Key = 10147 Value = 10147  
  240. Selection List Entry ===== Key = 10164 Value = 10164  
  241. Selection List Entry ===== Key = 10144 Value = 10144  
  242. Selection List Entry ===== Key = 10165 Value = 10165  
  243. Selection List Entry ===== Key = 10145 Value = 10145  
  244. Selection List Entry ===== Key = 10166 Value = 10166  
  245. Selection List Entry ===== Key = 10142 Value = 10142  
  246. Selection List Entry ===== Key = 10167 Value = 10167  
  247. Selection List Entry ===== Key = 10143 Value = 10143  
  248. Selection List Entry ===== Key = 10422 Value = 10422  
  249. Selection List Entry ===== Key = 10170 Value = 10170  
  250. Selection List Entry ===== Key = 10421 Value = 10421  
  251. Selection List Entry ===== Key = 10424 Value = 10424  
  252. Selection List Entry ===== Key = 10423 Value = 10423  
  253. Selection List Entry ===== Key = 10174 Value = 10174  
  254. Selection List Entry ===== Key = 10173 Value = 10173  
  255. Selection List Entry ===== Key = 10420 Value = 10420  
  256. Selection List Entry ===== Key = 10172 Value = 10172  
  257. Selection List Entry ===== Key = 10171 Value = 10171  
  258. Selection List Entry ===== Key = 10273 Value = 10273  
  259. Selection List Entry ===== Key = 10272 Value = 10272  
  260. Selection List Entry ===== Key = 10271 Value = 10271  
  261. Selection List Entry ===== Key = 10270 Value = 10270  
  262. Selection List Entry ===== Key = 10425 Value = 10425  
  263. Selection List Entry ===== Key = 10117 Value = 10117  
  264. Selection List Entry ===== Key = 10118 Value = 10118  
  265. Selection List Entry ===== Key = 10119 Value = 10119  
  266. Selection List Entry ===== Key = 10278 Value = 10278  
  267. Selection List Entry ===== Key = 10279 Value = 10279  
  268. Selection List Entry ===== Key = 10276 Value = 10276  
  269. Selection List Entry ===== Key = 10277 Value = 10277  
  270. Selection List Entry ===== Key = 10274 Value = 10274  
  271. Selection List Entry ===== Key = 10275 Value = 10275  
  272. Selection List Entry ===== Key = 10177 Value = 10177  
  273. Selection List Entry ===== Key = 10178 Value = 10178  
  274. Selection List Entry ===== Key = 10110 Value = 10110  
  275. Selection List Entry ===== Key = 10175 Value = 10175  
  276. Selection List Entry ===== Key = 10111 Value = 10111  
  277. Selection List Entry ===== Key = 10176 Value = 10176  
  278. Selection List Entry ===== Key = 10112 Value = 10112  
  279. Selection List Entry ===== Key = 10113 Value = 10113  
  280. Selection List Entry ===== Key = 10114 Value = 10114  
  281. Selection List Entry ===== Key = 10179 Value = 10179  
  282. Selection List Entry ===== Key = 10115 Value = 10115  
  283. Selection List Entry ===== Key = 10116 Value = 10116  
  284. Selection List Entry ===== Key = 10413 Value = 10413  
  285. Selection List Entry ===== Key = 10412 Value = 10412  
  286. Selection List Entry ===== Key = 10411 Value = 10411  
  287. Selection List Entry ===== Key = 10181 Value = 10181  
  288. Selection List Entry ===== Key = 10410 Value = 10410  
  289. Selection List Entry ===== Key = 10180 Value = 10180  
  290. Selection List Entry ===== Key = 10183 Value = 10183  
  291. Selection List Entry ===== Key = 10182 Value = 10182  
  292. Selection List Entry ===== Key = 10185 Value = 10185  
  293. Selection List Entry ===== Key = 10184 Value = 10184  
  294. Selection List Entry ===== Key = 10282 Value = 10282  
  295. Selection List Entry ===== Key = 10281 Value = 10281  
  296. Selection List Entry ===== Key = 10419 Value = 10419  
  297. Selection List Entry ===== Key = 10284 Value = 10284  
  298. Selection List Entry ===== Key = 10418 Value = 10418  
  299. Selection List Entry ===== Key = 10283 Value = 10283  
  300. Selection List Entry ===== Key = 10417 Value = 10417  
  301. Selection List Entry ===== Key = 10416 Value = 10416  
  302. Selection List Entry ===== Key = 10415 Value = 10415  
  303. Selection List Entry ===== Key = 10280 Value = 10280  
  304. Selection List Entry ===== Key = 10414 Value = 10414  
  305. Selection List Entry ===== Key = 10289 Value = 10289  
  306. Selection List Entry ===== Key = 10128 Value = 10128  
  307. Selection List Entry ===== Key = 10129 Value = 10129  
  308. Selection List Entry ===== Key = 10285 Value = 10285  
  309. Selection List Entry ===== Key = 10286 Value = 10286  
  310. Selection List Entry ===== Key = 10287 Value = 10287  
  311. Selection List Entry ===== Key = 10288 Value = 10288  
  312. Selection List Entry ===== Key = 10186 Value = 10186  
  313. Selection List Entry ===== Key = 10122 Value = 10122  
  314. Selection List Entry ===== Key = 10187 Value = 10187  
  315. Selection List Entry ===== Key = 10123 Value = 10123  
  316. Selection List Entry ===== Key = 10188 Value = 10188  
  317. Selection List Entry ===== Key = 10120 Value = 10120  
  318. Selection List Entry ===== Key = 10189 Value = 10189  
  319. Selection List Entry ===== Key = 10121 Value = 10121  
  320. Selection List Entry ===== Key = 10126 Value = 10126  
  321. Selection List Entry ===== Key = 10127 Value = 10127  
  322. Selection List Entry ===== Key = 10124 Value = 10124  
  323. Selection List Entry ===== Key = 10125 Value = 10125  
  324. Selection List Entry ===== Key = 10195 Value = 10195  
  325. Selection List Entry ===== Key = 10196 Value = 10196  
  326. Selection List Entry ===== Key = 10399 Value = 10399  
  327. Selection List Entry ===== Key = 10193 Value = 10193  
  328. Selection List Entry ===== Key = 10194 Value = 10194  
  329. Selection List Entry ===== Key = 10397 Value = 10397  
  330. Selection List Entry ===== Key = 10191 Value = 10191  
  331. Selection List Entry ===== Key = 10398 Value = 10398  
  332. Selection List Entry ===== Key = 10192 Value = 10192  
  333. Selection List Entry ===== Key = 10395 Value = 10395  
  334. Selection List Entry ===== Key = 10396 Value = 10396  
  335. Selection List Entry ===== Key = 10190 Value = 10190  
  336. Selection List Entry ===== Key = 10394 Value = 10394  
  337. Selection List Entry ===== Key = 10309 Value = 10309  
  338. Selection List Entry ===== Key = 10393 Value = 10393  
  339. Selection List Entry ===== Key = 10308 Value = 10308  
  340. Selection List Entry ===== Key = 10392 Value = 10392  
  341. Selection List Entry ===== Key = 10391 Value = 10391  
  342. Selection List Entry ===== Key = 10390 Value = 10390  
  343. Selection List Entry ===== Key = 10305 Value = 10305  
  344. Selection List Entry ===== Key = 10304 Value = 10304  
  345. Selection List Entry ===== Key = 10199 Value = 10199  
  346. Selection List Entry ===== Key = 10307 Value = 10307  
  347. Selection List Entry ===== Key = 10198 Value = 10198  
  348. Selection List Entry ===== Key = 10306 Value = 10306  
  349. Selection List Entry ===== Key = 10197 Value = 10197  
  350. Selection List Entry ===== Key = 10301 Value = 10301  
  351. Selection List Entry ===== Key = 10300 Value = 10300  
  352. Selection List Entry ===== Key = 10303 Value = 10303  
  353. Selection List Entry ===== Key = 10302 Value = 10302  
  354. Selection List Entry ===== Key = 10105 Value = 10105  
  355. Selection List Entry ===== Key = 10104 Value = 10104  
  356. Selection List Entry ===== Key = 10103 Value = 10103  
  357. Selection List Entry ===== Key = 10102 Value = 10102  
  358. Selection List Entry ===== Key = 10101 Value = 10101  
  359. Selection List Entry ===== Key = 10100 Value = 10100  
  360. Selection List Entry ===== Key = 10109 Value = 10109  
  361. Selection List Entry ===== Key = 10108 Value = 10108  
  362. Selection List Entry ===== Key = 10107 Value = 10107  
  363. Selection List Entry ===== Key = 10106 Value = 10106  
  364. Data Set Expression = row["ORDERNUMBER"]  
  365. Name = Parameter3  
  366. Is Required = Yes  
  367. Help Text = null  
  368. Parameter Group = Default  
  369. Display Name = null  
  370. Display Format = >  
  371. Data Type = String  
  372. Prompt Text = null  
  373. ======================Parameter =comboparm  
  374. Hidded = No  
  375. Default Value = val2  
  376. Type = List Box  
  377. Conceal Entry = No  
  378. Hidden = No  
  379. Selection List Entry ===== Key = val1 Value = displaytext1  
  380. Selection List Entry ===== Key = val2 Value = displaytestval2  
  381. Data Set Expression = null  
  382. Name = comboparm  
  383. Is Required = No  
  384. Help Text = null  
  385. Parameter Group = Default  
  386. Display Name = null  
  387. Display Format = Unformatted  
  388. Data Type = String  
  389. Prompt Text = null  
  390. ======================Parameter =radioparm  
  391. Hidded = No  
  392. Default Value = radio1  
  393. Type = List Box  
  394. Conceal Entry = No  
  395. Hidden = No  
  396. Selection List Entry ===== Key = radio1 Value = radio1  
  397. Selection List Entry ===== Key = radio2 Value = displaytextcombo2  
  398. Data Set Expression = null  
  399. Name = radioparm  
  400. Is Required = No  
  401. Help Text = radiohelp  
  402. Parameter Group = Default  
  403. Display Name = null  
  404. Display Format = Unformatted  
  405. Data Type = String  
  406. Prompt Text = null  
  407. ======================Parameter =staticlistbox  
  408. Hidded = No  
  409. Default Value = null  
  410. Type = List Box  
  411. Conceal Entry = No  
  412. Hidden = No  
  413. Selection List Entry ===== Key = listboxstatic1 Value = listboxstatic1  
  414. Selection List Entry ===== Key = listboxstatic2 Value = displaytextlistbox2  
  415. Data Set Expression = null  
  416. Name = staticlistbox  
  417. Is Required = No  
  418. Help Text = null  
  419. Parameter Group = Default  
  420. Display Name = null  
  421. Display Format = Unformatted  
  422. Data Type = String  
  423. Prompt Text = null  
  424. Parameter Group: iii  
  425. ======================Parameter =customernumber  
  426. Hidded = No  
  427. Default Value = defaultvalue  
  428. Type = List Box  
  429. Conceal Entry = No  
  430. Hidden = No  
  431. Data Set Expression = row["CUSTOMERNUMBER"]  
  432. Name = customernumber  
  433. Is Required = No  
  434. Help Text = helptext  
  435. Parameter Group = iii  
  436. Display Name = null  
  437. Display Format = Unformatted  
  438. Data Type = String  
  439. Prompt Text = enter customer number  
  440. ======================Parameter =OrderNumber  
  441. Hidded = No  
  442. Default Value = null  
  443. Type = List Box  
  444. Conceal Entry = No  
  445. Hidden = No  
  446. Data Set Expression = row["ORDERNUMBER"]  
  447. Name = OrderNumber  
  448. Is Required = No  
  449. Help Text = null  
  450. Parameter Group = iii  
  451. Display Name = null  
  452. Display Format = Unformatted  
  453. Data Type = String  
  454. Prompt Text = null  
  455. ======================Parameter =parameter6  
  456. Hidded = No  
  457. Default Value = test  
  458. Type = Text Box  
  459. Conceal Entry = No  
  460. Hidden = No  
  461. Data Set Expression = null  
  462. Name = parameter6  
  463. Is Required = No  
  464. Help Text = null  
  465. Parameter Group = Default  
  466. Display Name = null  
  467. Display Format = <  
  468. Data Type = String  
  469. Prompt Text = null  
  470. ======================Parameter =parameter7  
  471. Hidded = No  
  472. Default Value = 2  
  473. Type = List Box  
  474. Conceal Entry = No  
  475. Hidden = No  
  476. Selection List Entry ===== Key = 3 Value = 3  
  477. Selection List Entry ===== Key = 2 Value = 2  
  478. Selection List Entry ===== Key = 1 Value = 1  
  479. Data Set Expression = null  
  480. Name = parameter7  
  481. Is Required = Yes  
  482. Help Text = null  
  483. Parameter Group = Default  
  484. Display Name = null  
  485. Display Format = Unformatted  
  486. Data Type = Decimal  
  487. Prompt Text = null  
  488. ======================Parameter =DateParameter  
  489. Hidded = No  
  490. Default Value = 12/12/2006  
  491. Type = Text Box  
  492. Conceal Entry = No  
  493. Hidden = No  
  494. Data Set Expression = null  
  495. Name = DateParameter  
  496. Is Required = Yes  
  497. Help Text = null  
  498. Parameter Group = Default  
  499. Display Name = null  
  500. Display Format = Unformatted  
  501. Data Type = Date Time  
  502. Prompt Text = null  
  503. Finished  

下面的例子在控制台打印了TOC信息:

[java] view plaincopy
  1. package REAPI;  
  2.   
  3. import java.util.logging.Level;  
  4.   
  5. import org.eclipse.birt.core.framework.Platform;  
  6. import org.eclipse.birt.report.engine.api.EngineConfig;  
  7. import org.eclipse.birt.report.engine.api.EngineException;  
  8. import org.eclipse.birt.report.engine.api.IReportDocument;  
  9. import org.eclipse.birt.report.engine.api.IReportEngine;  
  10. import org.eclipse.birt.report.engine.api.IReportEngineFactory;  
  11. import org.eclipse.birt.report.engine.api.TOCNode;  
  12.   
  13.   
  14. public class Toc {  
  15.   
  16.     public void runReport() throws EngineException  
  17.     {  
  18.   
  19.         IReportEngine engine=null;  
  20.         EngineConfig config = null;  
  21.   
  22.         try{  
  23.   
  24.             config = new EngineConfig( );             
  25.             config.setBIRTHome("E:\\birt汉化包\\birt-runtime-3_7_2\\ReportEngine");  
  26.             config.setLogConfig(null, Level.FINE);  
  27.             Platform.startup( config );  
  28.             IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );  
  29.             engine = factory.createReportEngine( config );  
  30.         }catch( Exception ex){  
  31.             ex.printStackTrace();  
  32.         }  
  33.   
  34.         IReportDocument document = null;  
  35.         //Open the report design  
  36.         document = engine.openReportDocument("d:\\customers.rptdocument");   
  37.   
  38.   
  39.         // Get the root of the table of contents.  
  40.         TOCNode td = document.findTOC( null );  
  41.         java.util.List children = td.getChildren( );  
  42.         long pNumber;  
  43.         // Loop through the top level table of contents entries.  
  44.         if ( children != null && children.size( ) > 0 ) {  
  45.             for ( int i = 0; i < children.size( ); i++ )     {  
  46.                 // Find the required table of contents entry.  
  47.                 TOCNode child = ( TOCNode ) children.get( i );  
  48.                 //if ( child.getDisplayString( ).equals( "103" ) )      {  
  49.                 // Get the number of the page that contains the data.  
  50.                 pNumber = document.getPageNumber( child.getBookmark( ) );  
  51.                 System.out.println( child.getDisplayString( ) + " Page to print is " + pNumber );  
  52.                 //}  
  53.             }  
  54.         }         
  55.   
  56.         document.close();  
  57.         engine.destroy();  
  58.         Platform.shutdown();  
  59.         System.out.println("Finished");  
  60.     }     
  61.   
  62.   
  63.     /** 
  64.      * @param args 
  65.      */  
  66.     public static void main(String[] args) {  
  67.         try  
  68.         {  
  69.   
  70.             Toc ex = new Toc( );  
  71.             ex.runReport();  
  72.   
  73.         }  
  74.         catch ( Exception e )  
  75.         {  
  76.             e.printStackTrace();  
  77.         }  
  78.     }  
  79.   
  80.   
  81. }  

报表的预览如下:


运行结果如下:

Australia Page to print is 1

Austria Page to print is 2

Belgium Page to print is 3

Canada Page to print is 4

Denmark Page to print is 5

Finland Page to print is 6

France Page to print is 7

Germany Page to print is 8

Hong Kong Page to print is 9

Ireland Page to print is 10

Israel Page to print is 11

Italy Page to print is 12

Japan Page to print is 13

Netherlands Page to print is 14

New Zealand Page to print is 15

Norway Page to print is 16

Philippines Page to print is 17

Poland Page to print is 18

Portugal Page to print is 19

Russia Page to print is 20

Singapore Page to print is 21

South Africa Page to print is 22

Spain Page to print is 23

Sweden Page to print is 24

Switzerland Page to print is 25

UK Page to print is 26

USA Page to print is 27

Finished

关于报表设计引擎API的结构和使用方法,以及如何在报表引擎中调用报表设计引擎来修改报表,将在下一节详细讲解。

0 0
原创粉丝点击