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!





MultiQuote





