`
Ben.Sin
  • 浏览: 229666 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

[转]BIRT 2.3.1 IFilenameGenerator

阅读更多

[转]http://birtworld.blogspot.com/2008/09/naming-exported-files-from-birt.html

 

The Eclipse Business Intelligence and Reporting Tools project is an open-source project focused on the development and delivery of framework tools for reporting and business intelligence within the Eclipse platform.

Thursday, September 11, 2008

Naming Exported files from the BIRT WebViewer

A common question we get on the BIRT news group is how to change the name of an exported document. For instance, exporting to PDF, the developer may wish to have more control on what filename is used for the export. Currently the name used is just the report name followed by the emitter extension (eg MyReport.pdf).

BIRT 2.3.1 which will be released later this month now supplies a solution to this problem. The example web viewer has a setting that can be added to the web.xml that allows you to specify a Java class that will be responsible for generating the name.



<!-- Filename generator class/factory to use -->
<context-param>
<param-name>BIRT_FILENAME_GENERATOR_CLASS
<param-value>org.eclipse.birt.report.utility.filename.DefaultFilenameGenerator
</context-param>









The class specified must implement the IFilenameGenerator interface, which has one method named getFilename. This method is passed four parameters.

baseName – Contains the base filename for the report, with no extension provided.
fileExtension – The extension for the selected operation (ppt for export to PowerPoint).
outputType – The operation being executed. More on this parameter later.
options – Specific options for the operation.

The instance of the IFilenameGenerator is called in multiple locations within the example viewer. When you export the report:



When you export the report data:



And when you use the /document servlet mapping, for example:

http://localhost:8080/WebViewerExample/document?__report=OrderDetails.rptdesign





This URL will run the report and download the rptdocument.

Suppose you wish to have the date in your filename, when exporting the report. To do this, create a class with the following code:


package my.filename.generator;
import java.util.Date;
import java.util.Map;
import org.eclipse.birt.report.utility.filename.*;
public class MyFilenameGenerator implements IFilenameGenerator{
 
 public static final String DEFAULT_FILENAME = "BIRTReport"; 
 
 public String getFilename( String baseName, String extension, String outputType, Map options )
 {
  return makeFileName( baseName, extension );
 }
 public static String makeFileName( String fileName, String extensionName )
 {
  String baseName = fileName;
  if (baseName == null || baseName.trim().length() <= 0)
  {
   baseName = DEFAULT_FILENAME;
  }
  
  // check whether the file name contains non US-ASCII characters
  for (int i = 0; i < baseName.length(); i++) {
   char c = baseName.charAt(i);
 
   // char is from 0-127
   if (c < 0x00 || c >= 0x80) {
    baseName = DEFAULT_FILENAME;
    break;
   }
  }
  
  // append extension name
  if (extensionName != null && extensionName.length() > 0) {
   baseName += (new Date()).toString() + "." + extensionName; 
  }
  return baseName;
 }
}





If you check the source, you will notice this is just the default class with one modification.

   baseName += (new Date()).toString() + "." + extensionName; 



Which just inserts the date into the output.

You can also check the operation type if you wish to set the name based on the operation. Currently the available options for outputType are:

IFilenameGenerator.OUTPUT_TYPE_EXPORT – When exporting report to one of the supported formats.
IFilenameGenerator.OUTPUT_TYPE_DATA_EXTRACTION – When exporting report data.
IFilenameGenerator.OUTPUT_TYPE_REPORT_DOCUMENT – When using the document servlet mapping.

This example is located here .

Vincent Petry from the dev team has also uploaded a Birt Viewer 2.3 User Reference, which describes the settings and parameters available with the example web viewer. This document is informative and is located here .

If you wish to build your own version of the filename generator, make sure to include viewservlets.jar from the WebViewerExample\WEB_INF\lib directory in your build path.

16 comments:

Yasin Mallı said...

Hi.
I want to cancel 'ppt' exporting option and some other changing from default options.
Where can I find configuration files about that points.
Please help me.

Jason Weathersby said...

Yasin,

If you want to delete the ppt export option remove the ppt emitter plugin
org.eclipse.birt.report.engine.emitter.ppt_version.jar from the WEB-INF/platform/plugins directory.

Jason

Manish said...

Hi,

I want to use this class to construct report name based on report parameters. How could I possibly access report parameters from within the class MyFileNameGenerator.

Please clarify.

Jason Weathersby said...

Manish,

Look at the options in
public String getFilename( String baseName, String extension, String outputType, Map options )

I believe the HttpRequest is stored in the options as httpRequest which should contain your parameter values.

Manish said...

Thanks Jason. Your suggestion worked for me.

Corrado said...

Please Help to install plugin...

i Try with your bulded class and a rebuilded by me (i verify the correct reference).

When i copy the class in WebViewerExample\WEB-INF\lib\my\filename\generator\MyFilenameGenerator.class

in birt 2.3.2 runtime, and add the line you specified in the web.xml, the viewer response with an error:

HTTP Status 404 -

--------------------------------------------------------------------------------

type Status report

message

description The requested resource () is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.27

what i can do to solve this problem? excuse me but i'm nibble on plugin for birt!

CP

Jason Weathersby said...

Corrado,

If your class is not jarred try moving it to
WebViewerExample\WEB-INF\classes\my\filename\generator\MyFilenameGenerator.class

Also did you set the web.xml entry
BIRT_FILENAME_GENERATOR_CLASS to
my.filename.generator.MyFilenameGenerator

al91206 said...

Jason,

You said "BIRT 2.3.1 which will be released later this month now supplies a solution to this problem."

When I export from the interactive viewer, the filename is simply iv.extension - not even the reportname.

If this is fixed - can you let us know where the option is set - or where to configure this?

Thanks!

Al

Jason Weathersby said...

This feature should make it in the Actuate 11 version. Or at least the name that corresponds to the report name.

Suresh said...

is it possible in BIRT 2.2.1

Jason Weathersby said...

Suresh,

I believe this is only supported with 2.3.1 and above.

Jason

Bernhard said...

Hi,

I know, the original post is > 2 years old now, but I wonder if this is supposed to work with BIRT 2.6.1, Java 6 and Tomcat 6.0 ?

I'm struggling getting this to work. I've tried the following so far:

1. change web.xml entry
BIRT_FILENAME_GENERATOR_CLASS to
my.filename.generator.MyFilenameGenerator, restart Tomcat => report viewer still works, thus I assume the viewer will use the default routine if the class is not found
2. create a "classes" dir below the WEB-INF dir and copy from the example files the structure below the bin dir into classes (=> WEB-INF\classes\my\filename\generator\MyFilenameGenerator.class), restart tomcat => error 404 as in Corrado's post
3. check the Tomcat Web Application manager; report viewer is not running. Try starting the report viewer. Message: FAIL - Application at context path /birt-viewer261 could not be started
4. remove MyFilenameGenerator.class, report viewer starts => so there must be something wrong with the class?
5. create a new java project in Eclipse and import all example files. Edit the Build Path Library entry for viewservlets.jar to the file in WEB-INF\lib.
6. In MyFilenameGenerator.java, the line starting with "public String getFilename" shows 2 warnings: "- implements org.eclipse.birt.report.utility.filename.IFilenameGenerator.getFilename
- Map is a raw type. References to generic type Map should be parameterized" => not sure what this means (I am not familiar with JAVA)
7. Ignore warnings, export generated class files to MyFileNameGenerator.jar. JAR Export finished with warnings.
8. Copy MyFileNameGenerator.jar to WEB-INF\lib. Try starting the report viewer. Message: FAIL - Application at context path /birt-viewer261 could not be started

I've seen this solution in 2009 and it worked. Since my requirement is different to the example and I did not figure out how to achieve this without learning JAVA first, I've postponed it hoping this feature would make it into the report viewer. I've no idea what I could have done different those days, except that it was a different BIRT/JAVA/Tomcat environment.

So far, I could use BIRT without knowing much about JAVA - using the Report designer, some javascript, mysql and php was sufficient. My requirement is pretty simple, as in Manish's post: I want to use this class to construct report name based on report parameters. E.g. __filename=xxx just as there is a parameter __title. I could even accept __title as a default filename rather than the name of the rptdesign file. Your answer "Look at the options..." worked fine for Manish - obviously it's easy with JAVA skills.

Any help / hint / clue is highly appreciated.

Jason Weathersby said...

Can you try jarring the package and put the jar in the WEB-INF/lib directory. If you need the jar I can send it to you. I tried this with 2.6.1 and it works fine. My email address is jasonweathersby at windstream dot net. Send me an email.

Jason

Jason Weathersby said...

BTW I modified the code to use a __filename parameter. The source and jar to deploy it can be downloaded here:
http://www.birt-exchange.org/org/devshare/deploying-birt-reports/1322-filename-generator-that-uses-a-url-parameter-to-name-export/

Jason

Bernhard said...

Hi Jason,

thank you very much for the fast response. The provided .jar file works fine. The reason why my .jar file did not work was because of different Java versions in Eclipse (JVM 1.6) and my Tomcat Installation (JVM 1.5). It seems the original .class file was also compiled with 1.6 while the new one is 1.5.
At least, after changing the compiler compliance level to 1.5 in Eclipse, I was able to build the project and export "my own" .jar.

Also lots of thanks for showing how to access the report parameter - I'm sure I would have spent some more hours to figure this out by myself.

abhijit said...

I want to cancel 'ppt' exporting option.I am using "org.eclipse.birt.runtime_3.7.0.v20110615-1818.jar" file. How to do that.

分享到:
评论

相关推荐

    birt 汉化包 多国语言包 2.3.1

    解压到安装birt的eclipse对应文件夹中(plugins) 装好汉化包后 删除eclipse下的configuration目录里org.eclipse.update文件夹 再重启,选择Window-&gt;Preferences-&gt;BIRT-&gt;Preview选择你所需要的语言,再重启就可以了。

    birt报表页面显示汉化文件及过程说明

    birt报表的页面显示汉化资源文件及汉化过程说明,就是替换birt原有jar包中的英语资源文件为中文资源文件

    birt-runtime2.3.1/2.3.2汉化包

    本资源为birt官网所提供的birt运行时的汉化语言包,为方便大家使用,传到csdn上,如有需要的朋友请不要错过

    Birt报表注意Birt报表注意Birt报表注意Birt报表注意

    Birt报表注意Birt报表注意Birt报表注意Birt报表注意Birt报表注意Birt报表注意Birt报表注意Birt报表注意Birt报表注意

    转:Birt接收JSP传递的参数值

    描述jsp和birt报表的参数传递方法,还不错,转载

    BIRT 3.7 Report Design

    Eclipse Business Intelligence and Reporting Tools (BIRT) is an opensource, Eclipse-based reporting system that integrates with your Java EE application to produce compelling reports. BIRT is the only ...

    BIRT报表学习手册

    BIRT――商业智能和报表工具。 BIRT是一个Eclipse-based开放源代码的报表系统,它主要是用在基于Java和J2ee的web应用程序上。BIRT主要由两部分组成:一个是基于Eclipse的报表设计器和一个可以添加到应用服务器的运行...

    BIRT报表开发手册

    BIRT报表中文开发手册 PDF版本 BIRT Business Intelligence and Reporting Tools 是为 Web 应用程序开发的基于 Eclipse 的开源报表系统 特别之处在于它是以 Java 和 JavaEE 为基础 BIRT 有两个主要组件:基于 ...

    birt调用存储过程

    birt报表中调用存储过程的方法. 目录 1. 概述 3 2. BIRT支持的存储过程返回值类型 3 3. BIRT调用存储过程的语法 4 4. 创建存储过程数据源/集 4 5. 在BIRT中使用存储过程 5 调用返回单结果集的存储过程。 5 调用...

    BIRT报表详细示例及说明

    BIRT是一个Eclipse-based开放源代码报表系统。它主要是用在基于Java与J2EE的Web应用程序上。BIRT主要由两部分组成:一个是基于Eclipse的报表设计和一个可以加到你应用服务的运行期组件。BIRT同时也提供一个图形报表...

    birt 视频教程下载

    birt 视频教程 birt 视频教程 birt 视频教程

    eclipse3.7 birt 汉化包

    BabelLanguagePack-birt-zh_3.7.0.v20110723043401.zip eclipse 3.7 birt 汉化包

    Birt报表开发教程

    birt超详细教程,里面有各种教程和用法。制作报表视频、详解+案例,谢谢大家支持

    BIRT报表学习资料

    BIRT学习资料 BIRT学习资料 BIRT学习资料 BIRT学习资料

    Birt中文指南(Birt家园版)(chm)

    Birt中文指南(Birt家园版)(chm) 贡献给大家 2MB

    birt实例08-12-25

    birt实例 birt实例 birt实例 birt实例 birt实例 birt实例

    Eclipse Birt源码4.5.0

    Birt4.5.0 的源码,全部为JAR格式,导入Eclipse请参考文章 http://blog.csdn.net/supercooly/article/details/49357709

    Birt使用技巧集锦

    网罗了网络上大家使用Birt的一些经验技巧,这个RAR文件主要包括: 1、Birt参数使用方法 2、Birt Java 整合开发详解 3、应付大部分应用的birt的css样式 4、在团队中使用birt 5、Birt经验谈

    eclipse 4.5birt插件

    BIRT (Business Intelligence and Reporting Tools), 是为 Web 应用程序开发的基于 Eclipse 的开源报表系统,特别之处在于它是以 Java 和 JavaEE 为基础。BIRT 有两个主要组件:基于 Eclipse 的报表设计器,以及部署...

    BIRT使用经验谈。birt的初步使用方法

    BIRT使用经验谈.birt的初步使用方法

Global site tag (gtag.js) - Google Analytics