use of org.apache.fop.apps.FopFactoryBuilder in project pcgen by PCGen.
the class FopTask method createFopFactory.
private static FopFactory createFopFactory() {
// Allow optional customization with configuration file
String configPath = ConfigurationSettings.getOutputSheetsDir() + File.separator + "fop.xconf";
Logging.log(Logging.INFO, "FoPTask checking for config file at " + configPath);
File userConfigFile = new File(configPath);
FopFactoryBuilder builder;
if (userConfigFile.exists()) {
Logging.log(Logging.INFO, "FoPTask using config file " + configPath);
FopConfParser parser;
try {
parser = new FopConfParser(userConfigFile);
} catch (Exception e) {
Logging.errorPrint("FoPTask encountered a problem with FOP configuration " + configPath + ": ", e);
return null;
}
builder = parser.getFopFactoryBuilder();
} else {
Logging.log(Logging.INFO, "FoPTask using default config");
builder = new FopFactoryBuilder(new File(".").toURI());
builder.setStrictFOValidation(false);
}
return builder.build();
}
use of org.apache.fop.apps.FopFactoryBuilder in project series-rest-api by 52North.
the class PDFReportGenerator method encodeAndWriteTo.
@Override
public void encodeAndWriteTo(DataCollection<QuantityData> data, OutputStream stream) throws IoParseException {
try {
generateOutput(data);
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.build(document.newInputStream());
FopFactory fopFactory = new FopFactoryBuilder(baseURI).setConfiguration(cfg).build();
final String mimeType = MimeType.APPLICATION_PDF.getMimeType();
Fop fop = fopFactory.newFop(mimeType, stream);
//FopFactory fopFactory = FopFactory.newInstance(cfg);
//Fop fop = fopFactory.newFop(APPLICATION_PDF.getMimeType(), stream);
//FopFactory fopFactory = fopFactoryBuilder.build();
//Fop fop = fopFactory.newFop(APPLICATION_PDF.getMimeType(), stream);
// Create PDF via XSLT transformation
TransformerFactory transFact = TransformerFactory.newInstance();
StreamSource transformationRule = getTransforamtionRule();
Transformer transformer = transFact.newTransformer(transformationRule);
Source source = new StreamSource(document.newInputStream());
Result result = new SAXResult(fop.getDefaultHandler());
if (LOGGER.isDebugEnabled()) {
try {
File tempFile = File.createTempFile(TEMP_FILE_PREFIX, ".xml");
StreamResult debugResult = new StreamResult(tempFile);
transformer.transform(source, debugResult);
String xslResult = XmlObject.Factory.parse(tempFile).xmlText();
LOGGER.debug("xsl-fo input (locale '{}'): {}", i18n.getTwoDigitsLanguageCode(), xslResult);
} catch (IOException | TransformerException | XmlException e) {
LOGGER.error("Could not debug XSL result output!", e);
}
}
// XXX debug, diagram is not embedded
transformer.transform(source, result);
} catch (FOPException e) {
throw new IoParseException("Failed to create Formatting Object Processor (FOP)", e);
} catch (SAXException | ConfigurationException | IOException e) {
throw new IoParseException("Failed to read config for Formatting Object Processor (FOP)", e);
} catch (TransformerConfigurationException e) {
throw new IoParseException("Invalid transform configuration. Inspect xslt!", e);
} catch (TransformerException e) {
throw new IoParseException("Could not generate PDF report!", e);
}
}
use of org.apache.fop.apps.FopFactoryBuilder in project xwiki-platform by xwiki.
the class FOPXSLFORenderer method initialize.
@Override
public void initialize() throws InitializationException {
EnvironmentProfile environmentProfile = EnvironmentalProfileFactory.createDefault(new File(".").toURI(), this.resourceResolver);
FopFactoryBuilder builder = new FopFactoryBuilder(environmentProfile);
Configuration configuration = loadConfiguration();
if (configuration != null) {
builder.setConfiguration(configuration);
}
this.fopFactory = builder.build();
}
use of org.apache.fop.apps.FopFactoryBuilder in project xwiki-platform by xwiki.
the class XHTML2FOTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
EnvironmentProfile environmentProfile = EnvironmentalProfileFactory.createDefault(new File(".").toURI(), ResourceResolverFactory.createDefaultResourceResolver());
FopFactoryBuilder builder = new FopFactoryBuilder(environmentProfile);
fopFactory = builder.build();
foUserAgent = fopFactory.newFOUserAgent();
transformerFactory = TransformerFactory.newInstance();
}
use of org.apache.fop.apps.FopFactoryBuilder in project series-rest-api by 52North.
the class PDFReportGenerator method encodeAndWriteTo.
@Override
public void encodeAndWriteTo(DataCollection<Data<QuantityValue>> data, OutputStream stream) throws IoHandlerException {
try {
generateOutput(data);
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.build(document.newInputStream());
URI baseURI = new File(".").toURI();
FopFactory fopFactory = new FopFactoryBuilder(baseURI).setConfiguration(cfg).build();
final String mimeType = Constants.APPLICATION_PDF;
Fop fop = fopFactory.newFop(mimeType, stream);
// FopFactory fopFactory = FopFactory.newInstance(cfg);
// Fop fop = fopFactory.newFop(APPLICATION_PDF.getMimeType(), stream);
// FopFactory fopFactory = fopFactoryBuilder.build();
// Fop fop = fopFactory.newFop(APPLICATION_PDF.getMimeType(), stream);
// Create PDF via XSLT transformation
TransformerFactory transFact = TransformerFactory.newInstance();
StreamSource transformationRule = getTransforamtionRule();
Transformer transformer = transFact.newTransformer(transformationRule);
Source source = new StreamSource(document.newInputStream());
Result result = new SAXResult(fop.getDefaultHandler());
if (LOGGER.isDebugEnabled()) {
try {
File tempFile = File.createTempFile(TEMP_FILE_PREFIX, ".xml");
StreamResult debugResult = new StreamResult(tempFile);
transformer.transform(source, debugResult);
String xslResult = XmlObject.Factory.parse(tempFile).xmlText();
LOGGER.debug("xsl-fo input (locale '{}'): {}", i18n.getTwoDigitsLanguageCode(), xslResult);
} catch (IOException | TransformerException | XmlException e) {
LOGGER.error("Could not debug XSL result output!", e);
}
}
// XXX debug, diagram is not embedded
transformer.transform(source, result);
} catch (FOPException e) {
throw new IoParseException("Failed to create Formatting Object Processor (FOP)", e);
} catch (ConfigurationException e) {
throw new IoParseException("Failed to read config for Formatting Object Processor (FOP)", e);
} catch (TransformerConfigurationException e) {
throw new IoParseException("Invalid transform configuration. Inspect xslt!", e);
} catch (TransformerException e) {
throw new IoParseException("Could not generate PDF report!", e);
}
}
Aggregations