Home
Analytics
Avoiding absolute paths in rptdesign
lenburt
Hi there - i have a csv data source that i would like to use a relative path to the war when deployed....is there any way to do this?...here is an example:
<oda-data-source extensionID="org.eclipse.datatools.connectivity.oda.flatfile" name="Portal Report List" id="59"
extends="CACSDashboard.Portal Report List">
<property name="HOME">C:\Documents and Settings\leonard.burt\workspace\CACS9_Dashboard\resources/data</property>
<property name="DELIMTYPE">COMMA</property>
<property name="CHARSET">Big5</property>
<property name="INCLCOLUMNNAME">YES</property>
<property name="INCLTYPELINE">YES</property>
</oda-data-source>
Find more posts tagged with
Comments
JasonW
You should be able to do this with a beforeOpen script on the data source like:
if( reportContext.getHttpServletRequest().getAttribute("attributeBean").isDesigner() ){
//do nothing in the designer
}else{
var rp = reportContext.getHttpServletRequest().getSession().getServletContext().getRealPath("/csvfile");
if( rp == null ){
//"cant find reports";
}else{
this.setExtensionProperty("HOME", rp+"/chk.csv");
}
}
Jason
lenburt
<blockquote class='ipsBlockquote' data-author="'JasonW'" data-cid="99646" data-time="1335376024" data-date="25 April 2012 - 10:47 AM"><p>
You should be able to do this with a beforeOpen script on the data source like:<br />
<br />
if( reportContext.getHttpServletRequest().getAttribute("attributeBean").isDesigner() ){<br />
//do nothing in the designer<br />
}else{<br />
var rp = reportContext.getHttpServletRequest().getSession().getServletContext().getRealPath("/csvfile");<br />
if( rp == null ){<br />
//"cant find reports";<br />
}else{<br />
<br />
this.setExtensionProperty("HOME", rp+"/chk.csv");<br />
}<br />
}<br />
<br />
Jason<br /></p></blockquote>
lenburt
Ok, thanks Jason -- so there is no way to have environment vars available in the XML rptdesign, correct?
CBR
Hi Len,<br />
<br />
sure just replace <br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var rp = reportContext.getHttpServletRequest().getSession().getServletContext().getRealPath("/csvfile");
</pre>
<br />
with<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var rp = java.lang.System.getenv("varname");
</pre>
replace varname with the name of your env variable.<br />
<br />
This only works if you server is not running with restricting Security Manager
rushtonjj
What about if you are running a standalone application that could be placed on any laptop in the field? How do I handle the HOME relative path in the XML for my flatfile. I won't be using a servlett?
JasonW
That should still be ok to use Christian's approach for a standalone operation.
Jason
Sai Kushal R
<p>I'm using the BIRT run time to generate the report. I have kept the birt runtime inside the folder 'DataFolder'</p>
<p>At present i have configured the HOME path as an absolute path which is shown below i.e 'C:\MainDataFolder\DataFolder\_temp' and everthing works fine.</p>
<p> </p>
<p><oda-data-source extensionID="org.eclipse.datatools.connectivity.oda.flatfile" name="Data Source" id="7"><br>
<property name="HOME">C:\MainDataFolder\DataFolder\_temp</property></p>
<p> </p>
<p> </p>
<p>I would like to give the relative path to the data source something like '..\_temp\' .</p>
<p> </p>
<p>If i specify the relative path i get the below error message</p>
<p>'org.eclipse.datatools.connectivity.oda.flatfile.InvalidResourceException: Invalid table name:\_temp\'.</p>
<p> </p>
<p>Please help me out how to specify the relative path to the flat file data source.</p>
<p>Thanks in advancve</p>
JFreeman
<p>So you are wanting to set a relative path location for a flat file you are using as your data source?</p>
<p> </p>
<p>What version of BIRT are you using?</p>
Sai Kushal R
<p>Yes I need to set the relative path location for the flat file using the data source.</p>
<p>I'm using BIRT 4.3.2.</p>
<p>Thanks in advance.</p>
JFreeman
<p>If you are using the BIRT designer, in 4.3.2 you should be able to select File URI in the flat file data source dialogue and then enter the relative path within your project directory.</p>
<p> </p>
<p>If the report and CSV file are both in the root of the project, the XML will look like this:</p>
<pre class="_prettyXprint _lang-xml">
<oda-data-source extensionID="org.eclipse.datatools.connectivity.oda.flatfile" name="Data Source1" id="21">
<text-property name="displayName"></text-property>
<property name="URI">sample.csv</property>
<property name="DELIMTYPE">COMMA</property>
<property name="CHARSET">UTF-8</property>
<property name="INCLCOLUMNNAME">YES</property>
<property name="INCLTYPELINE">NO</property>
<property name="TRAILNULLCOLS">NO</property>
</oda-data-source>
</pre>
Sai Kushal R
<p>I'm using only BIRT run time in server, and passing required information to Birt run time as paramter in one of the Batch file .</p>
<p> </p>
<p>So as mentioned above , I would like to use the folder relative path as I have many file in that folder which will be an input to the Birt.</p>
<p> </p>
<p>Curent scenarion :</p>
<p>1. I have the Birt run time in the folder '<span style="color:#ff0000;"><strong>C:\D-Drive\BirtRuntime</strong></span>'</p>
<p>2. I have the input file in the foler '<strong><span style="color:#ff0000;">C:\D-Drive\Data</span>'</strong></p>
<p>3.I'm using the absolute path for the data source to BIRT like as shown in the below(as marked in red colour) and it is working fine</p>
<p> </p>
<p><oda-data-source extensionID="org.eclipse.datatools.connectivity.oda.flatfile" name="Data Source" id="7"><br>
<property name="HOME"><span style="color:#ff0000;"><strong>C:\D-Drive\Data</strong></span></property><br>
<property name="DELIMTYPE">SEMICOLON</property><br>
<property name="CHARSET">UTF-8</property><br>
<property name="INCLCOLUMNNAME">YES</property><br>
<property name="INCLTYPELINE">NO</property><br>
<property name="TRAILNULLCOLS">NO</property><br>
</oda-data-source></p>
<p> </p>
<p>Changes i'm expecting is to specify the relative path to the Birt data source which is as shown below(marked in red).</p>
<p>It would be a great help if you could let me know is this feasible if yes let me know how to specify the relative path</p>
<p>to the data source.</p>
<p> </p>
<p><oda-data-source extensionID="org.eclipse.datatools.connectivity.oda.flatfile" name="Data Source" id="7"><br>
<property name="HOME"><span style="color:#ff0000;"><strong>..\Data</strong></span></property><br>
<property name="DELIMTYPE">SEMICOLON</property><br>
<property name="CHARSET">UTF-8</property><br>
<property name="INCLCOLUMNNAME">YES</property><br>
<property name="INCLTYPELINE">NO</property><br>
<property name="TRAILNULLCOLS">NO</property><br>
</oda-data-source></p>
JFreeman
<p>Does the data directory have to be outside of the resources directory for the BIRT?</p>
<p>I do not believe you will be able to traverse up and outside of the directory using "../".</p>
<p> </p>
<p>However, if you place the data directory within the resources path for the BIRT Runtime you should be able to use a relative path to access it and traverse down into sub-directories. </p>
Sai Kushal R
<p>Thanks for your reply.</p>
<p>Yes the data directory must be outside the resource directory and wanted to traverse up the using '../'.</p>
JFreeman
<p>Unfortunately, I do not believe you will be able to traverse up and out of the root of the runtime's resources directory for security reasons.</p>
<p> </p>
<p>If the directory has to stay where it is, you can create symlink inside of the runtime's resources directory that links to your data directory. Then you should be able to hit it with a relative path inside of the resources without actually moving the directory.</p>
Sai Kushal R
<p>Thanks for your reply,I will use the symlink instead.
</p>
JFreeman
<p>You're welcome.</p>
<p> </p>
<p>Let us know if you have additional questions.</p>