Home
Analytics
CSV data source and relative path
cypherdj
Hi there,
I have used CSV files as data source for some of my reports, but it seems that Birt stores the full path to those files in the rptdesign, rather than a relative path (eg, the csv files are stored within the app context).
Is there a way to specify the path as relative (to the location of the rptdesign file for example), as this is a problem at deployment time, where the full path might be different from the one stored in the rptdesign?
Thanks,
Cedric
Find more posts tagged with
Comments
Linda Chan
The common issue for these cases is where the default base path for a relative source file should be. There is always ambiguity on where a file path should be relative to. Some users may want to keep their data files outside of a BIRT installation folder. Others want to use a common folder shared by multiple products from the same vendor. Furthermore, certain sets of report designs may want to use one root path, and other sets may want to use a different root path. What may be obvious to one as a default location is not obvious to others.
So the solution available now is for a report developer to explicitly specify where a file property's base path is, by using the Property Binding feature in BIRT Data Source and Data Set Editor.
This approach also provides the flexibility for an user to define different root path for different file properties.
To do this, in BIRT "Edit Data Source" dialog, select the "Property Binding"
node, and enter a JavaScript expression in the "Home Folder" property.
The JavaScript expression can include a variable to specify the root path.
The variable will then be resolved at runtime according to the configuration
of your deployment environment. Thus no need to change the Property Binding expression in your report designs when they are deployed in different
environments.
There are multiple alternate variables that can be used to specify the root
path.
The JavaScript expression can refer to a BIRT config[] variable. For
example,
config[ "birt.viewer.working.path" ] + "../../data/myData.csv"
A JavaScript expression can also refer to BIRT reportContext global
variable.
It can specify a BIRT Viewer's BIRT_RESOURCE_PATH (whose value is defined by
user in web.xml) via the BIRT reportContext variable. For example,
reportContext.getAppContext().get("birt.viewer.resource.path") ] +
"../data/myData.csv"
Yet another option, the JavaScript expression can also refer to a BIRT
registered resource locator to look up a resource URL. For example,
reportContext.getResource( "myData.csv" )
cypherdj
Thanks for the reply ichan, one thing I should have clarified is that I'm not using the BIRT web viewer, but the report engine runtime with my own viewer.
I'm already setting app context values at runtime, so I guess I could pass the csv root path and let each report add on its own sub-path.
I'll give that a try, thanks again,
Cedric