You are viewing a plain text version of this content. The canonical link for it is here.
Posted to devnull@infra.apache.org by "slavb18 (GitHub)" <gi...@apache.org> on 2018/08/22 06:22:52 UTC
[GitHub] [cxf] slavb18 opened pull request #436: introduce
getStreamResult
to allow override, e.g. for pdf generation using apache fop
[ Full content available at: https://github.com/apache/cxf/pull/436 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cxf] deki closed pull request #436: introduce
getStreamResult
Posted by "deki (GitHub)" <gi...@apache.org>.
[ pull request closed by deki ]
[ Full content available at: https://github.com/apache/cxf/pull/436 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cxf] slavb18 commented on issue #436: introduce
getStreamResult
Posted by "slavb18 (GitHub)" <gi...@apache.org>.
Usage:
```java
@XSLTTransform(value = "path/to/file.xsl", mediaTypes = "application/pdf", type = XSLTTransform.TransformType.SERVER)
```
[ Full content available at: https://github.com/apache/cxf/pull/436 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org
[GitHub] [cxf] slavb18 commented on issue #436: introduce
getStreamResult
Posted by "slavb18 (GitHub)" <gi...@apache.org>.
example pdf provider based on XSLTJaxbProvider
```java
@Produces({"application/xml", "application/*+xml", "text/xml", "text/html","application/pdf" })
@Consumes({"application/xml", "application/*+xml", "text/xml", "text/html" })
@Provider
public class XSLTJaxbPDFProvider<T> extends XSLTJaxbProvider<T> {
protected FopFactory fopFactory = null;
MediaType pdfMediaType = MediaType.valueOf("application/pdf");
@Override
protected Templates createTemplates(URL urlStream) {
Templates templates = super.createTemplates(urlStream);
if (fopFactory==null) {
try {
fopFactory = FopFactory.newInstance(getClass().getResource("/fop").toURI(),getClass().getResourceAsStream("/fop/fopconf.xml"));
} catch (IOException | URISyntaxException | SAXException ex) {
throw new RuntimeException(ex);
}
}
return templates;
}
@Override
protected Result getStreamResult(OutputStream os, Annotation[] anns, MediaType mt) throws Exception {
return mt.isCompatible(pdfMediaType) ? getStreamResultPdf(os, anns, mt) : super.getStreamResult(os, anns, mt);
}
protected Result getStreamResultPdf(OutputStream os, Annotation[] anns, MediaType mt) throws FOPException {
FOUserAgent userAgent = fopFactory.newFOUserAgent();
Fop fop = fopFactory.newFop("application/pdf", userAgent, os);
return new SAXResult(fop.getDefaultHandler());
}
}
```
[ Full content available at: https://github.com/apache/cxf/pull/436 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org