Include BIRT Library into Report from InputStream (BIRT DEAPI)

478 Views Asked by At

I have an environment where I dynamically assemble BIRT ReportDesigns using components in ReportLibraries. These ReportLibraries are stored in a Database, and are not to be found anywhere on the file system.

What I am trying to do is to open a Library in a Session, 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 a ReportDesign and include the Library (by name?)

    ReportDesignHandle reportDesign = session.createDesign();

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

Later I would search for a Table Element in the Library and try to copy that to the Design:

    ElementFactory elementFactory = reportDesign.getElementFactory();

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

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

At this point I would get 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)

It seems like the Library is found and the DesignElementHandle is indeed pointing to the component that I want to copy into the Design, but the Library opened in the session cannot be found by the ReportDesign.

Is there any way to tell the ReportDesign to include the Library from a non-FileSystem resource, or to include the Library from the Session, since it has the same name?

I want to avoid having to put rptlibrary Files on my FielSystem to assemble a ReportDesign at all costs.

1

There are 1 best solutions below

0
On

I have not tested it by I think your Report needs to include the Library first, before you can try to get element Handles inside the report out of the Library.

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

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

ElementFactory elementFactory = reportDesign.getElementFactory();

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

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