BIRT Exchange Forum: Shared Resource Location - BIRT Exchange Forum

Jump to content


 

BIRT Poll: To best make a table fill a pdf page before breaking (PL=page layout, PBI=page break interval) set:

PL: auto, PBI: 0PL: fixed, PBI: 0PL: auto, PBI: 1000000PL: fixed, PBI: 1000000
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Shared Resource Location Question about how to tell BIRT where the shared resource files are. Rate Topic: -----

#1 User is offline   pxuxp Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 24-January 12


Posted 20 April 2012 - 02:10 AM

Hopefully a straightforward question - though I've not yet found the answer in the BIRT integration book, nor here on the forums...

I'm attempting to open a report design from a simple script so I can add lots of data sources to it programmatically. I've the following method:

private ReportDesignHandle getReportDesignHandle( String reportDefLoc ) throws BirtException
{
	DesignConfig config = new DesignConfig();
	config.setResourceLocator( new CustomResourceLocator() );
	System.out.print(" Starting design engine...");
	Platform.startup( config );
	IDesignEngineFactory factory = ( IDesignEngineFactory ) Platform
			.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
	IDesignEngine designEngine = factory.createDesignEngine( config );
	System.out.println("...done");
	System.out.println( " Starting session..." );
	sesh = designEngine.newSessionHandle( null );
	sesh.setResourceLocator( new CustomResourceLocator() ); // Doesn't seem to help.
	sesh.setResourceFolder( CustomResourceLocator.RESOURCE_FOLDER_STRING ); // Ditto!
	ReportDesignHandle rdh = null;
	rdh = sesh.openDesign( reportDefLoc );
	return rdh;
}



Where CustomResourceLocator looks like this:

public class CustomResourceLocator implements IResourceLocator
{
	public static final String RESOURCE_FOLDER_STRING = "PATH TO SHARED RESOURCES";

	@Override
	public URL findResource( ModuleHandle modHandle, String path, int i )
	{
		return findResource( modHandle, path, i, null );
	}

	@Override
	public URL findResource( ModuleHandle modHandle, String path, int i, Map map )
	{
		try
		{
			URL url;
			url = new URL( "file://" + RESOURCE_FOLDER_STRING + path );
			System.out.println(" Custom Resource Locator suggests " + url );
			return url;
		}
		catch ( MalformedURLException e )
		{
			e.printStackTrace();
			return null;
		}
	}

}



The CustomResourceLocator is returning a valid URL - pasting it into Windows Explorer results in the file opening - and yet I still get a cannot find the shared resource (in this case the Library file) when I run the code...

Do I need to manipulate the ModuleHandle too? (It isn't returned so that seems unlikely...)

Your ideas would be greatly appreciated!
0

#2 User is offline   cbrell Icon

  • Member
  • Group: Members
  • Posts: 523
  • Joined: 17-March 09


Posted 20 April 2012 - 03:47 AM

You don't need to implement a ResourceLocator just to tell BIRT that your libraries are located in a special folder.

Just use:

config.setResourcePath(String dir)

to tell BIRT that your libraries are located in a special folder.

Nevertheless: Your code should work too. Can you post a URL that is generated from your code?
Interested to join BIRT User Group Mannheim (Germany)?
Have a look at: http://www.xing.com/...-group-mannheim or write me an email
0

#3 User is offline   pxuxp Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 24-January 12


Posted 20 April 2012 - 05:25 AM

Hello,

Thanks for the reply.

I initially thought of using setResourcePath() but DesignConfig (extends PlatformConfig) does not have this method so I thought I'd try the resource locator. The API doc is here.

The custom resource locator prints its output using the URLs toString method - an example when I run it:

file://D:/Workspaces/ReportDesign/reports/shared_resources/libraries/general.rptlibrary


Thanks again!

Pete
0

#4 User is offline   pxuxp Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 24-January 12


Posted 20 April 2012 - 05:28 AM

Thanks cbrell - you prompted me to look closer and I noticed the missing "/"...

file://D:/Workspaces/ReportDesign/reports/shared_resources/libraries/general.rptlibrary


should have been:

file:///D:/Workspaces/ReportDesign/reports/shared_resources/libraries/general.rptlibrary


Now,

private ReportDesignHandle getReportDesignHandle( String reportDefLoc ) throws BirtException
{
        DesignConfig config = new DesignConfig();
        System.out.print(" Starting design engine...");
        Platform.startup( config );
        IDesignEngineFactory factory = ( IDesignEngineFactory ) Platform
                        .createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
        IDesignEngine designEngine = factory.createDesignEngine( config );
        System.out.println("...done");
        System.out.println( " Starting session..." );
        sesh = designEngine.newSessionHandle( null );
        sesh.setResourceLocator( new CustomResourceLocator() );
        ReportDesignHandle rdh = null;
        rdh = sesh.openDesign( reportDefLoc );
        return rdh;
}



Works - nb. I've removed the setResourceFolder and also setResourceLocator on the config as it doesn't seem to be needed.

Also seems OK - as you suggest - to use setResourceFolder provided you give a URL String:

sesh.setResourceFolder( "file:///D:/Workspaces/ReportDesign/reports/shared_resources" );


is OK.

sesh.setResourceFolder( "D:/Workspaces/ReportDesign/reports/shared_resources" );


isn't.

This makes sense but wouldn't it be better for setResourceFolder to expect a URL? Not exactly major though... ;-)
0

#5 User is offline   cbrell Icon

  • Member
  • Group: Members
  • Posts: 523
  • Joined: 17-March 09


Posted 24 April 2012 - 10:38 PM

Hi,

it should even work without providing the file protocol, so i m wondering why it didn't work for you.

Is your d drive a local or a mapped network drive? I remember that Java could only adress network drives using the file protocol or their real name.
Interested to join BIRT User Group Mannheim (Germany)?
Have a look at: http://www.xing.com/...-group-mannheim or write me an email
0

#6 User is offline   pxuxp Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 24-January 12


Posted 30 April 2012 - 12:36 AM

Hello,

Nope - the d drive is local. I thought it'd work too and probably just did something wrong.

Not to worry - all working now.

Thanks for the help!

Pete
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users