Run the FO to PDF/AWT conversion. This automatically closes any provided OutputStream for this FopTask.
()
| 179 | * this FopTask. |
| 180 | */ |
| 181 | @Override |
| 182 | public void run() |
| 183 | { |
| 184 | try (OutputStream out = outputStream) |
| 185 | { |
| 186 | userAgent.setProducer("PC Gen Character Generator"); |
| 187 | userAgent.setAuthor(System.getProperty("user.name")); |
| 188 | userAgent.setCreationDate(Date.from(LocalDateTime.now().toInstant(ZoneOffset.ofHours(0)))); |
| 189 | |
| 190 | userAgent.getEventBroadcaster().addEventListener(new FOPEventListener()); |
| 191 | |
| 192 | String mimeType; |
| 193 | if (renderer != null) |
| 194 | { |
| 195 | userAgent.setKeywords("PCGEN FOP PREVIEW"); |
| 196 | mimeType = MimeConstants.MIME_FOP_AWT_PREVIEW; |
| 197 | } |
| 198 | else |
| 199 | { |
| 200 | userAgent.setKeywords("PCGEN FOP PDF"); |
| 201 | mimeType = org.apache.xmlgraphics.util.MimeConstants.MIME_PDF; |
| 202 | } |
| 203 | Fop fop; |
| 204 | if (out != null) |
| 205 | { |
| 206 | fop = FOP_FACTORY.newFop(mimeType, userAgent, out); |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | fop = FOP_FACTORY.newFop(mimeType, userAgent); |
| 211 | } |
| 212 | |
| 213 | Transformer transformer; |
| 214 | if (xsltSource != null) |
| 215 | { |
| 216 | transformer = TRANS_FACTORY.newTransformer(xsltSource); |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | transformer = TRANS_FACTORY.newTransformer(); // identity transformer |
| 221 | } |
| 222 | transformer.setErrorListener(new FOPErrorListener()); |
| 223 | transformer.transform(inputSource, new SAXResult(fop.getDefaultHandler())); |
| 224 | } |
| 225 | catch (TransformerException | FOPException | IOException e) |
| 226 | { |
| 227 | errorBuilder.append(e.getMessage()).append(Constants.LINE_SEPARATOR); |
| 228 | Logging.errorPrint("Exception in FopTask:run", e); |
| 229 | } |
| 230 | catch (RuntimeException ex) |
| 231 | { |
| 232 | errorBuilder.append(ex.getMessage()).append(Constants.LINE_SEPARATOR); |
| 233 | Logging.errorPrint("Unexpected exception in FopTask:run: ", ex); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * The Class {@code FOPErrorListener} listens for notifications of issues when generating |