更新到最新的 FOP API

发布于 2024-11-27 09:54:49 字数 353 浏览 1 评论 0原文

我正在寻找更新应用程序以使用最新的 fop API。 该应用程序使用该库的 0.20 版本,例如仍在使用 Driver 类。

我似乎无法找到任何有关如何更新到最新 fop 版本的明智信息。我发现了一些片段,例如应该使用 FOPFactory。

所以我想知道是否有人可以向我推送有关更新到新的(最新)fop API 的资源? 或者是否真的无法更新,我是否需要重写应用程序的这一部分?

PS我找到了 fop 升级 页面(当然),但似乎没有指出两个版本的类/API 之间的相似之处。

I am looking to update an application to use the newest fop API.
The application uses version 0.20 of the library, for example the Driver class is still being used.

I do not seem to be able to find any sensible information on how to update to the newest fop version. I found some snippets, eg that the FOPFactory should be used.

So I was wondering if anyone could give me a push to resources on updating to the new(est) fop API?
Or is it not really possible to update and do I need to rewrite this part of the application?

PS I have found the fop upgrading page (of course) but it does not seem to point out the similarities between classes/APIs of both versions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑脸一如从前 2024-12-04 09:54:49

答案是,这实际上取决于您使用 FOP 的程度。

当我们从 .2* 版本更新到 .9,然后是 1.0 版本时,我们必须进行大量修改,但我们生成了各种各样的 FO(我们将 FO 转换为 PostScript),并且我们需要生成各种 PostScript看看新版本中哪些有效,哪些失败。您可能会找到一个简单的替代品来替代根据您过去所做的事情可能消失的任何东西。

幸运的是,我们将对 Driver 和 Fop 类的引用合并到自定义实用程序中,因此简单地换出使用 FopFactory 的新实用程序引用并不是那么糟糕的过渡。

您的第一步应该是编写一个抽象的 Facade,正如 @Wivani 建议的那样,整合您的旧 fop 引用调用,确保它在您的代码中有效,然后通过使用新代码的实现替换旧的 Facade 来继续前进。

Fop 唯一让我不满意的是社区需要相当长的时间来应用错误补丁并生成新版本。我们在生产中使用 v1 和 XML Graphics 1.4 没有任何问题(生成 PostScript 和 TIFF 文件的基本 FO)。

如果您需要的话,我将在周一补充这篇文章一些帮助代码。

更新
以下是我们过去用来将 FO 文件转换为 PostScript 的内容:

String foAsString = "your_fo_as_string";
File destination = new File("path_to_file"");

BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destination));
Driver driver = new Driver(new InputSource(new StringReader(foAsString)), out);
driver.setRenderer(Driver.RENDER_PS);
driver.run();

out.close();

return destination;

以下是我们现在使用的内容的摘要。

FopFactory 作为实例级代码创建

this.fopFactory = FopFactory.newInstance();

import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;

// ...

String foAsString = "your_fo_as_string";
File destination = new File("path_to_file"");

OutputStream outStream = new BufferedOutputStream(new FileOutputStream(destination));
Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, outStream);

Transformer transformer = transformerFactory.newTransformer();
Source source = new StreamSource(new StringReader(foAsString));
Result result = new SAXResult(fop.getDefaultHandler());

transformer.transform(source, result);

outStream.close();

return destination;

The answer is that it really depends on how much you use of FOP.

When we updated from a .2* version to the .9, then 1.0 version, we had to revise quite a bit, but we generated a large variety of FO (we transformed FO to PostScript) and we needed to generate a variety of PostScripts to see what worked and what failed in the newer versions. You will likely find an easy replacement for anything that might have vanished based on what you used to do.

We had, luckily, consolidated references to the Driver and Fop classes to a custom utility and therefore it wasn't so bad a transition to simply swap out a new utility reference that used the FopFactory.

Your first step should be to write an abstract Facade as @Wivani suggests to consolidate your older fop reference calls, make sure that works in your code, then move forward by replacing your older Facade with an implementation that uses the newer code.

The only thing that has displeased me about Fop is that the community takes quite a while to apply bug patches and generate new releases. We used v1 in production with XML Graphics 1.4 with no problems (basic FO to generate PostScript and TIFF files).

I will supplement this post on Monday with some helper code if you need it.

UPDATE
Here is what we used to use to convert a FO file to PostScript:

String foAsString = "your_fo_as_string";
File destination = new File("path_to_file"");

BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destination));
Driver driver = new Driver(new InputSource(new StringReader(foAsString)), out);
driver.setRenderer(Driver.RENDER_PS);
driver.run();

out.close();

return destination;

Here is an abstract of what we use now.

FopFactory is created as instance-level as

this.fopFactory = FopFactory.newInstance();

code:

import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;

// ...

String foAsString = "your_fo_as_string";
File destination = new File("path_to_file"");

OutputStream outStream = new BufferedOutputStream(new FileOutputStream(destination));
Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, outStream);

Transformer transformer = transformerFactory.newTransformer();
Source source = new StreamSource(new StringReader(foAsString));
Result result = new SAXResult(fop.getDefaultHandler());

transformer.transform(source, result);

outStream.close();

return destination;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文