0

我需要将几个 XSL 转换的输出通过管道传输到 FopFactory 对象,但我不知道如何编写代码。我有管道工作,但最后一步是个谜。

DOMResult xmlRequest = new DOMResult();
marshaller.marshal(req,xmlRequest);

FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);

XdmNode source = processor.newDocumentBuilder()
   .build(new DOMSource(xmlRequest.getNode()));

XsltTransformer step1 = templateCache.get("foo1.xsl").load();
XsltTransformer step2 = templateCache.get("foo2.xsl").load();
XsltTransformer step3 = templateCache.get("foo3_fo.xsl").load();

step1.setInitialContextNode(source);
step1.setDestination(step2);
step2.setDestination(step3);

// Here's what I really need to do -- pipe the output of step3 into the FO processor.
// Of course, the following statement doesn't work, but I don't know what I need
// to do to make the output of step3 piped into the fop, so the 
step3.setDestination(fop.getDefaultHandler());

step1.transform();

// at this point, the results of the FOP processor would be in the
// ByteArrayOutputStream "out".

我怎样才能使这项工作?

4

1 回答 1

0

当然,在发布问题并进行更多搜索后,我找到了答案。这是我想出的(省略了上面的大部分代码):

Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
SAXDestination fopDest = new SAXDestination(fop.getDefaultHandler());
.
step2.setDestination(step3);
step3.setDestination(fopDest);

step1.transform();
.
// Output is now in ByteArrayOutputStream out;
于 2013-03-08T17:33:58.320 回答