Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Birt supports custom export Chinese names

Shulou Source: shulou.com Published: 2022-06-03 06:23:05 09月24日 Update

BIRT is an open source report system based on Eclipse developed for Web applications based on Java and JavaEE. Although it supports file export, it does not support dynamic customization of file names during export, especially in Chinese.

By default, Birt provides two ways to customize the name when exporting a file, as follows:

DefaultFilenameGenerator: the name of the report file. Suffix name TimestampFilenameGenerator: report file name + yyyyMMdd-HHmmss. Suffix name

If Birt implements the custom export file name, you need to implement the IFilenameGenerator API under the org.eclipse.birt.report.utility.filename package, as shown below:

Custom implementation of IFilenameGenerator interface public class CustomExportGenerator implements IFilenameGenerator {@ Override public String getFilename (String baseName, String fileExtension, String outputType, Map options) {return baseName + "." + fileExtension;}}

As you can see from the above code, the method in IFilenameGenerator does not provide a custom file name by default, which can only be obtained from the Map options parameter. Of course, if it is not too much trouble, you can override the getFilename interface.

Object obj = options.get ("httpRequest"); if (obj! = null & & obj instanceof RequestFacade) {RequestFacade request = (RequestFacade) obj; exportName = ParameterAccessor.getParameter (request, "_ _ filename");} configure Birt's export file generation class

Modify web.xml

BIRT_FILENAME_GENERATOR_CLASS org.eclipse.birt.report.utility.filename.CustomExportGenerator supports Chinese

File name: org.eclipse.birt.report.presentation.aggregation.layout.FramesetFragment

Method: doPreService (HttpServletRequest request, HttpServletResponse response)

Action:

String filename = ParameterAccessor.getExportFilename (new BirtContext (request, response), format, emitterId); String displayName = URLEncoder.encode (filename, "utf-8"); displayName = displayName .replace ("+", "% 20"); response.setCharacterEncoding ("utf-8"); response.setHeader ("contentType", "text/html; charset=utf-8") Response.setHeader ("Content-Disposition", / / $NON-NLS-1$ ParameterAccessor.htmlEncode (openType) + "; filename=\"+ ParameterAccessor.htmlEncode (displayName) +"\ "); modify the encoding of Tomcat

Access method:

Frameset?report=test.rptdesign&format=docx&__filename= test

Tags: File name support report interface method Chinese suffix utf-8 code function dynamic parameter foundation application file name method program system code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information OPPO Reno Xiaomi NVidia Huawei