Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » HowTo - Scripting - Dinamically get Images...
icon5.gif  HowTo - Scripting - Dinamically get Images... [message #655837] Tue, 22 February 2011 14:07 Go to next message
Bruno Mattos is currently offline Bruno Mattos
Messages: 17
Registered: November 2010
Junior Member
I'm having difficulty using scripts to dynamically set the URI of an image in a report.

What I need to do is this:
When running a preview of the report, find the Path of the project folder, and inside that folder, look for a file that ends with jpeg. I'm trying to insert javascript in the URI field of the image. I know how to search in a directory for the file that ends with jpeg. My problem is to take the path of the project folder, or the name of the project.

Any help?

Thanks.
Re: HowTo - Scripting - Dinamically get Images... [message #655864 is a reply to message #655837] Tue, 22 February 2011 16:51 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

How are you going to deploy the report?
Have you seen this post?
http://birtworld.blogspot.com/2010/09/birt-image-report-item .html

Jason

n 2/22/2011 2:07 PM, Bruno Mattos wrote:
> I'm having difficulty using scripts to dynamically set the URI of an
> image in a report.
> What I need to do is this:
> When running a preview of the report, find the Path of the project
> folder, and inside that folder, look for a file that ends with jpeg. I'm
> trying to insert javascript in the URI field of the image. I know how to
> search in a directory for the file that ends with jpeg. My problem is to
> take the path of the project folder, or the name of the project.
>
> Any help?
>
> Thanks.
icon5.gif  Re: HowTo - Scripting - Dinamically get Images... [message #656058 is a reply to message #655837] Wed, 23 February 2011 17:37 Go to previous messageGo to next message
Bruno Mattos is currently offline Bruno Mattos
Messages: 17
Registered: November 2010
Junior Member
Hi.

I Had already looked at the link but could not find a guide to what i need to do.

The Report will be distributed through a template that I'm setting. The user must create a report from the template I'm developing.

In my situation I do not know the path of the image because I do not know the name of the project created by the user, and also do not know his workspace. Just know that there must be a jpeg file in the user's project folder.

I need a way to find the path of the project through a javascript entered in the URI field of the Image in the reportTemplate.

Thank you for listening.

Bruno.
Re: HowTo - Scripting - Dinamically get Images... [message #656228 is a reply to message #656058] Thu, 24 February 2011 10:44 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Bruno,

Most BIRT projects setup a resource folder to contain things like
images, libraries, external js files etc.
If you used this approach you could enter:
var myurl = reportContext.getResource("green.png");
As the expression. If that is not an option try something like:

var mybundle =
Packages.org.eclipse.core.runtime.Platform.getBundle("my.rcp.application ");
var furl = FileLocator.find(mybundle, new Path("/"), null);
var myimage = FileLocator.toFileURL(furl).getPath() +"myimage.png";

Jason

On 2/23/2011 5:38 PM, Bruno Mattos wrote:
> Hi.
>
> I Had already looked at the link but could not find a guide to what i
> need to do.
>
> The Report will be distributed through a template that I'm setting. The
> user must create a report from the template I'm developing.
>
> In my situation I do not know the path of the image because I do not
> know the name of the project created by the user, and also do not know
> his workspace. Just know that there must be a jpeg file in the user's
> project folder.
>
> I need a way to find the path of the project through a javascript
> entered in the URI field of the Image in the reportTemplate.
>
> Thank you for listening.
>
> Bruno.
icon5.gif  Re: HowTo - Scripting - Dinamically get Images... [message #656263 is a reply to message #655837] Thu, 24 February 2011 14:33 Go to previous messageGo to next message
Bruno Mattos is currently offline Bruno Mattos
Messages: 17
Registered: November 2010
Junior Member
I tried as suggested but could not solve the problem.

When running javascript, I get NullPointerException on the line "var furl = FileLocator.find (mybundle, new Path ("/"), null)".

I noticed that the variable mybundle is set to NULL.

I'm new in the Eclipse environment and do not know exactly which symbolicname should pass to the method Platform.getBundle.

I looked the Platform class in Eclipse API and did not find guidance on this.

Any suggestions?

Thank you very much for the help.

Bruno.
Re: HowTo - Scripting - Dinamically get Images... [message #656275 is a reply to message #656263] Thu, 24 February 2011 15:16 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Bruno

Try:

//extra code to show how to iterate projects
importPackage(Packages.org.eclipse.core.resources);
projects = ResourcesPlugin.getWorkspace( ).getRoot( ).getProjects( );
projectString = "";
for ( i = 0; i < projects.length; i++ )
{
proj = projects[i];
projectString += proj.getName( ) + File.pathSeparator;
}

var wkspcroot = ResourcesPlugin.getWorkspace().getRoot();
var myProject = wkspcroot.getProject("BIRT Reports");
var specFolder = myProject.getFolder("demo").getLocation();

Jason

On 2/24/2011 2:34 PM, Bruno Mattos wrote:
> I tried as suggested but could not solve the problem.
>
> When running javascript, I get NullPointerException on the line "var
> furl = FileLocator.find (mybundle, new Path ("/"), null)".
>
> I noticed that the variable mybundle is set to NULL.
>
> I'm new in the Eclipse environment and do not know exactly which
> symbolicname should pass to the method Platform.getBundle.
>
> I looked the Platform class in Eclipse API and did not find guidance on
> this.
>
> Any suggestions?
>
> Thank you very much for the help.
>
> Bruno.
icon14.gif  Re: HowTo - Scripting - Dinamically get Images... [message #656449 is a reply to message #655837] Fri, 25 February 2011 12:39 Go to previous messageGo to next message
Bruno Mattos is currently offline Bruno Mattos
Messages: 17
Registered: November 2010
Junior Member
I managed to solve my problem.

Using the solution suggested earlier - var myURL reportContext.getResource = ("green.png") - can get on the path to the project where my report is located, I just need to know the name of a file that is in the project.

For example, I can do:
var myurl reportContext.getResource = ("whatever.whatever");
(assuming there's a file named whatever.whatever in the project folder)
And then I just need to remove the end of the string, so i get the address to the the project folder.

I can also point to the report itself, since I know the report's name.
Any tips on how to get the report's name directly from a javascript that is running in a Image's field?

Thank you for your help.
Re: HowTo - Scripting - Dinamically get Images... [message #656460 is a reply to message #656449] Fri, 25 February 2011 13:24 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Use one of these methods:

reportContext.getRenderOption().getOptions().get("report");
or
reportContext.getReportRunnable().getReportName();

Jason

On 2/25/2011 12:39 PM, Bruno Mattos wrote:
> I managed to solve my problem.
>
> Using the solution suggested earlier - var myURL
> reportContext.getResource = ("green.png") - can get on the path to the
> project where my report is located, I just need to know the name of a
> file that is in the project.
>
> For example, I can do:
> var myurl reportContext.getResource = ("whatever.whatever");
> (assuming there's a file named whatever.whatever in the project folder)
> And then I just need to remove the end of the string, so i get the
> address to the the project folder.
>
> I can also point to the report itself, since I know the report's name.
> Any tips on how to get the report's name directly from a javascript that
> is running in a Image's field?
>
> Thank you for your help.
Previous Topic:Problems with viewing report as PDF and also in Preview
Next Topic:Font not in list
Goto Forum:
  


Current Time: Thu Aug 28 23:41:52 EDT 2014

Powered by FUDForum. Page generated in 0.02256 seconds