问题描述
我们的一个软件实用程序使用一个实现 net.sf.jasperreports.engine.util.FileResolver
的类来加载驻留在的报表元素(例如图像)相对于报告的路径或将通过专有文件服务器协议加载的路径。从最新版本6.6.0开始,我看到该计划是完全删除FileResolver类。但是,在Javadocs中,它只会注意到该类将被删除。没有指定有关替换的详细信息。
One of our software utilities uses a class that implements net.sf.jasperreports.engine.util.FileResolver
to load report elements (like images for example) that reside at a path relative to the report or that are to be loaded via a proprietary file server protocol. As of the latest version, 6.6.0, I see that the plan is to remove the FileResolver class entirely. However, in the Javadocs, it only notes that the class will be removed. No details about a replacement are specified.
我不希望能够将FileResolver换成另一个1:1替换的类,但是我真的想知道报告填充程序现在使用的是什么找到外部报告元素。
I am not expecting to be able to trade out the FileResolver with another class with a 1:1 substitution, but would really like to know what the report filler is now using to locate external report elements.
推荐答案
FileResolver
已被弃用,转而支持 net.sf.jasperreports.repo.RepositoryService
implements。
FileResolver
was deprecated in favor of net.sf.jasperreports.repo.RepositoryService
implementations.
有一个名为 net.sf.jasperreports的内置实现。 repo.FileRepositoryService
大致相当于弃用的 net.sf.jasperreports.engine.util.SimpleFileResolver
。
There's a builtin implementation named net.sf.jasperreports.repo.FileRepositoryService
which is roughly the equivalent of the deprecated net.sf.jasperreports.engine.util.SimpleFileResolver
.
存储库服务注册为 JasperReportsContext
扩展。
Repository services are registered as JasperReportsContext
extensions.
这可以在像这样的jasperreports_extension.properties文件:
That can be done either in a jasperreports_extension.properties file like this:
net.sf.jasperreports.extension.registry.factory.file.repository=net.sf.jasperreports.repo.FileRepositoryServiceExtensionsRegistryFactory
net.sf.jasperreports.extension.file.repository.root=/path/to/repository
net.sf.jasperreports.extension.registry.factory.persistence=net.sf.jasperreports.repo.FileRepositoryExtensionsRegistryFactory
注册扩展也可以通过编程创建 JasperReportsContext
对象然后用它来填充报告:
Registering the extensions can also be done by programmatically creating a JasperReportsContext
object and then using it to fill the reports:
SimpleJasperReportsContext context = new SimpleJasperReportsContext();
FileRepositoryService fileRepository = new FileRepositoryService(context, "/path/to/repository", false);
context.setExtensions(RepositoryService.class, Collections.singletonList(fileRepository));
context.setExtensions(PersistenceServiceFactory.class, Collections.singletonList(FileRepositoryPersistenceServiceFactory.getInstance()));
JasperPrint jasperPrint = JasperFillManager.getInstance(context).fill(jasperReport, params);
如果需要实现自定义存储库服务,可以使用 FileRepositoryService
作为参考。您可能希望实现 StreamRepositoryService
并注册 PersistenceService
s(如)。
If you need to implement a custom repository service, you can take FileRepositoryService
as a reference. You'll probably want to implement StreamRepositoryService
and register PersistenceService
s (as in FileRepositoryPersistenceServiceFactory).
如果您需要做的是关于相对于报告的资源路径,您还可以查看。传递此类对象意味着相对于报表自动解析报表资源引用(前提是存储库服务基于 RepositoryContext
实现资源查找)。
If what you need to do is about resource paths relative to the report, you can also take a look at the JRFiller methods that take a JasperReportSource
argument. Passing such an object is meant to automatically resolve report resource references as relative to the report (provided that the repository service implements resource lookup based on RepositoryContext
).
这篇关于什么取代了JasperReports API中的FileResolver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!