gpt4 book ai didi

birt - 将 BIRT 库包含到来自 InputStream 的报告中 (BIRT DEAPI)

转载 作者:行者123 更新时间:2023-12-01 05:06:38 26 4
gpt4 key购买 nike

我有一个使用 ReportLibraries 中的组件动态组装 BIRT ReportDesigns 的环境。这些 ReportLibraries 存储在数据库中,在文件系统的任何位置都找不到。

我想要做的是在 session 中打开一个库,给库一个名称和一个 InputStream(来自测试资源的 FileInputStream)

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

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

然后我创建一个 ReportDesign 并包含库(按名称?)
    ReportDesignHandle reportDesign = session.createDesign();

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

后来我会在库中搜索一个表元素并尝试将其复制到设计中:
    ElementFactory elementFactory = reportDesign.getElementFactory();

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

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

此时我会得到以下异常:
 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)

似乎找到了库,并且 DesignElementHandle 确实指向我要复制到设计中的组件,但是 ReportDesign 找不到在 session 中打开的库。

有没有办法告诉 ReportDesign 包含来自非文件系统资源的库,或者包含来自 session 的库,因为它具有相同的名称?

我想避免不惜一切代价将 rptlibrary 文件放在我的 FielSystem 上来组装 ReportDesign。

最佳答案

我还没有测试过,我认为您的报告需要首先包含库,然后才能尝试从库中获取报告中的元素句柄。

includeLibrary(filename, namespace)该函数只能用于从文件系统加载库。所以我认为您必须从数据库的内容创建一个临时文件,但您可以在创建报告后将其删除。

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

ElementFactory elementFactory = reportDesign.getElementFactory();

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

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

关于birt - 将 BIRT 库包含到来自 InputStream 的报告中 (BIRT DEAPI),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27900223/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com