Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » how to change export file name
how to change export file name [message #893683] Thu, 05 July 2012 09:09 Go to next message
smith link is currently offline smith linkFriend
Messages: 14
Registered: May 2012
Junior Member
birt 2.3.x



<context-param>
		<param-name>BIRT_FILENAME_GENERATOR_CLASS</param-name>
		<param-value>com.link.report.FilenameGenerator</param-value>
	</context-param>



package jetsennet.jnmp.report;

import java.util.Date;
import java.util.Map;

import org.eclipse.birt.report.utility.filename.IFilenameGenerator;


public class FilenameGenerator implements IFilenameGenerator
{
	/**
	 * default report file name
	 */
	public static final String DEFAULT_FILENAME = "report";

	public String getFilename(String [b]fileName[/b], String extension,
	        String outputType, Map options)
	{
		System.out.println(baseName);
		return makeFileName(baseName, extension);
	}

	/**
	 * Makes a filename using the target extension from the options.
	 * 
	 * @param fileName
	 *            file name which extension must be replaced
	 * @return file name with replaced 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; //$NON-NLS-1$
		}
		return baseName;
	}
}





I'd like to use the follow code, but it is unusable!
<birt:viewer id="birtViewer" reportDesign="reports/alarmeventstatisticsnew.rptdesign"
pattern="frameset"
format="HTML"
isHostPage = "true">
<birt:param name="baseName" value="myexportfile"/>
</birt:viewer>


how to change baseName, or how to pass parameter to baseName?

[Updated on: Thu, 05 July 2012 10:13]

Report message to a moderator

Re: how to change export file name [message #893807 is a reply to message #893683] Thu, 05 July 2012 14:25 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

I assume you read through this post?
http://birtworld.blogspot.com/2008/09/naming-exported-files-from-birt.html

baseName is passed in and in your case should be
alarmeventstatisticsnew

I am not certain 2.3.x implemented the filename generator extension.
Did this context parameter already exist in your web.xml?
> <context-param>
> <param-name>BIRT_FILENAME_GENERATOR_CLASS</param-name>
> <param-value>com.link.report.FilenameGenerator</param-value>
> </context-param>

Or did you add it?

Jason

On 7/5/2012 5:09 AM, smith link wrote:
> birt 2.3.x
>
>
>
>
> <context-param>
> <param-name>BIRT_FILENAME_GENERATOR_CLASS</param-name>
> <param-value>com.link.report.FilenameGenerator</param-value>
> </context-param>
>
>
>
>
> package jetsennet.jnmp.report;
>
> import java.util.Date;
> import java.util.Map;
>
> import org.eclipse.birt.report.utility.filename.IFilenameGenerator;
>
>
> public class FilenameGenerator implements IFilenameGenerator
> {
> /**
> * default report file name
> */
> public static final String DEFAULT_FILENAME = "report";
>
> public String getFilename(String baseName, String extension,
> String outputType, Map options)
> {
> System.out.println(baseName);
> return makeFileName(baseName, extension);
> }
>
> /**
> * Makes a filename using the target extension from the options.
> * * @param fileName
> * file name which extension must be replaced
> * @return file name with replaced 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;
> //$NON-NLS-1$
> }
> return baseName;
> }
> }
>
>
>
>
>
> I'd like to use the follow code, but it is unusable!
> <birt:viewer id="birtViewer"
> reportDesign="reports/alarmeventstatisticsnew.rptdesign"
> pattern="frameset"
> format="HTML"
> isHostPage = "true">
> <birt:param name="baseName" value="ok"/>
> </birt:viewer>
>
>
> how to change baseName, or how to pass parameter to baseName?
Re: how to change export file name [message #894381 is a reply to message #893807] Mon, 09 July 2012 02:02 Go to previous message
smith link is currently offline smith linkFriend
Messages: 14
Registered: May 2012
Junior Member
Thanks Jason.
Previous Topic:Adhoc Reporting in Open Source BIRT
Next Topic:Error in Localization?
Goto Forum:
  


Current Time: Sat Dec 20 13:54:26 GMT 2014

Powered by FUDForum. Page generated in 0.08153 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software