Inlcude BIRT Library to report from InputStream (BIRT DEAPI)

I have an environment where I am dynamically building BIRT ReportDesigns using components in ReportLibraries. These ReportLibraries are stored in the database and cannot be found anywhere in the file system.

I am trying to open a library in session by giving the library a name and an InputStream (FileInputStream from a test resource).

    SessionHandle session = de.newSessionHandle(ULocale.ENGLISH);

    LibraryHandle library = session.openLibrary("lib01.rptlibrary", is);

      

Then I create ReportDesign and include the library (by name?)

    ReportDesignHandle reportDesign = session.createDesign();

    reportDesign.includeLibrary("lib01.rptlibrary", "lib01");

      

Later I would look for the table element in the library and try to copy it to Design:

    ElementFactory elementFactory = reportDesign.getElementFactory();

    DesignElementHandle deh1 = library.findElement("NewTable");

    DesignElementHandle ldeh1 = elementFactory.newElementFrom(deh1, "newTable");

      

At this point, I am getting the following exception:

 org.eclipse.birt.report.model.api.command.InvalidParentException: The library for the parent element "Table("NewTable")" is not included.
at org.eclipse.birt.report.model.api.ElementFactoryImpl.newElementFrom(ElementFactoryImpl.java:968)
at org.eclipse.birt.report.model.api.ElementFactory.newElementFrom(ElementFactory.java:1)

      

The library seems to be found and the DesignElementHandle does indeed point to the component I want to copy to Design, but the library opened in session cannot be found in ReportDesign.

Is there a way to tell ReportDesign to include the library from a resource other than FileSystem, or to include the library from session, since it has the same name?

I want to avoid having to bring rptlibrary files into my FielSystem to build ReportDesign at any cost.

+3


source to share


1 answer


I haven't tested it, I think your report must first include the library before you can try to get the controls inside the report from the library.

includeLibrary (filename, namespace) This function can only be used to load a library from the file system. So I think you need to create a temporary file from the contents of your database, but you can delete it after generating the report.



//add this
reportDesign.includeLibrary(filename, namespace);

ElementFactory elementFactory = reportDesign.getElementFactory();

DesignElementHandle deh1 = library.findElement("NewTable");

DesignElementHandle ldeh1 = elementFactory.newElementFrom(deh1, "newTable");

      

+1


source







All Articles