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:24:28 UTC
[GitHub] [cxf] slavb18 commented on issue #436: introduce
getStreamResult
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