/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2004, 2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.w3c.dom.Text;
// FOP
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
*/
public class ExampleDOM2PDF {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
/** xsl-fo namespace URI */
protected static String foNS = "http://www.w3.org/1999/XSL/Format";
*/
public void convertDOM2PDF(Document xslfoDoc, File pdf) {
try {
- // Construct fop with desired output format
- Fop fop = new Fop(MimeConstants.MIME_PDF);
-
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+ // configure foUserAgent as desired
+
// Setup output
OutputStream out = new java.io.FileOutputStream(pdf);
out = new java.io.BufferedOutputStream(out);
try {
- fop.setOutputStream(out);
+ // Construct fop with desired output format and output stream
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup Identity Transformer
TransformerFactory factory = TransformerFactory.newInstance();
/*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
try {
FopFactory fopFactory = FopFactory.newInstance();
// configure fopFactory as desired
+
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired
- // Construct fop with desired output format
- Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent);
// Setup output stream. Note: Using BufferedOutputStream
// for performance reasons (helpful with FileOutputStreams).
out = new FileOutputStream(pdf);
out = new BufferedOutputStream(out);
- fop.setOutputStream(out);
+
+ // Construct fop with desired output format
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup JAXP using identity transformer
TransformerFactory factory = TransformerFactory.newInstance();
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2004,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.xml.sax.SAXException;
// FOP
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
/**
*/
public class ExampleFO2PDFUsingSAXParser {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
/**
* Converts an FO file to a PDF file using FOP
* @param fo the FO file
ParserConfigurationException,
FOPException, SAXException, IOException {
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+ // configure foUserAgent as desired
+
OutputStream out = null;
try {
- // Construct fop and setup output format
- Fop fop = new Fop(MimeConstants.MIME_PDF);
-
// Setup output stream. Note: Using BufferedOutputStream
// for performance reasons (helpful with FileOutputStreams).
out = new FileOutputStream(pdf);
out = new BufferedOutputStream(out);
- fop.setOutputStream(out);
+ // Construct fop and setup output format
+ Fop fop = new Fop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup SAX parser
// throws FactoryConfigurationError
/*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import javax.xml.transform.sax.SAXResult;
// FOP
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
/**
*/
public class ExampleFO2RTF {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
/**
* Converts an FO file to a RTF file using FOP
* @param fo the FO file
*/
public void convertFO2RTF(File fo, File rtf) throws IOException, FOPException {
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+ // configure foUserAgent as desired
+
OutputStream out = null;
try {
- // Construct fop with desired output format
- Fop fop = new Fop(MimeConstants.MIME_RTF);
-
// Setup output stream. Note: Using BufferedOutputStream
// for performance reasons (helpful with FileOutputStreams).
out = new FileOutputStream(rtf);
out = new BufferedOutputStream(out);
- fop.setOutputStream(out);
+ // Construct fop with desired output format
+ Fop fop = new Fop(MimeConstants.MIME_RTF, foUserAgent, out);
+
// Setup JAXP using identity transformer
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); // identity transformer
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2004,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import javax.xml.transform.sax.SAXResult;
// FOP
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import embedding.model.ProjectTeam;
*/
public class ExampleObj2PDF {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
/**
* Converts a ProjectTeam object to a PDF file.
* @param team the ProjectTeam object
public void convertProjectTeam2PDF(ProjectTeam team, File xslt, File pdf)
throws IOException, FOPException, TransformerException {
- // Construct fop with desired output format
- Fop fop = new Fop(MimeConstants.MIME_PDF);
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+ // configure foUserAgent as desired
// Setup output
OutputStream out = new java.io.FileOutputStream(pdf);
out = new java.io.BufferedOutputStream(out);
try {
- fop.setOutputStream(out);
+ // Construct fop with desired output format
+ Fop fop = new Fop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
/*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import javax.xml.transform.sax.SAXResult;
//FOP
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
/**
System.out.println();
System.out.println("Transforming...");
- // Construct fop with desired output format
- Fop fop = new Fop(MimeConstants.MIME_PDF);
-
+ // configure fopFactory as desired
+ FopFactory fopFactory = FopFactory.newInstance();
+
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+ // configure foUserAgent as desired
+
// Setup output
OutputStream out = new java.io.FileOutputStream(pdffile);
out = new java.io.BufferedOutputStream(out);
try {
- fop.setOutputStream(out);
+ // Construct fop with desired output format
+ Fop fop = new Fop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.AreaTreeModel;
import org.apache.fop.area.AreaTreeParser;
*/
public class ExampleConcat {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
/**
* Creates a sample ProjectTeam instance for this demo.
* @return ProjectTeam the newly created ProjectTeam instance
throws IOException, FOPException, TransformerException {
//Create a user agent
- FOUserAgent userAgent = new FOUserAgent();
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
//Create an instance of the target renderer so the XMLRenderer can use its font setup
Renderer targetRenderer = userAgent.getRendererFactory().createRenderer(
//Make sure the prepared XMLRenderer is used
userAgent.setRendererOverride(xmlRenderer);
- // Construct fop (the MIME type here is unimportant due to the override on the user agent)
- Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, userAgent);
-
// Setup output
OutputStream out = new java.io.FileOutputStream(intermediate);
out = new java.io.BufferedOutputStream(out);
try {
- fop.setOutputStream(out);
+ // Construct fop (the MIME type here is unimportant due to the override on the user agent)
+ Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, userAgent, out);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
* Set the OutputStream to use to output the result of the Render
* (if applicable)
* @param stream the stream to output the result of rendering to
+ * @deprecated Set the output stream in the constructor
*/
public void setOutputStream(OutputStream stream) {
this.stream = stream;
/*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.apache.commons.logging.impl.SimpleLog;
//FOP
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
/**
protected byte[] render(Source src, Transformer transformer)
throws FOPException, TransformerException {
- //Setup FOP
- Fop fop = new Fop(MimeConstants.MIME_PDF);
+ // configure fopFactory as desired
+ FopFactory fopFactory = FopFactory.newInstance();
+
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+ // configure foUserAgent as desired
//Setup output
ByteArrayOutputStream out = new ByteArrayOutputStream();
- fop.setOutputStream(out);
+
+ //Setup FOP
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
//Make sure the XSL transformation's result is piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
/*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.cli.InputHandler;
*/
public class BasicDriverTestCase extends AbstractFOPTestCase {
+ private FopFactory fopFactory = FopFactory.newInstance();
+
/**
* @see junit.framework.TestCase#TestCase(String)
*/
* @throws Exception if anything fails
*/
public void testFO2PDFWithJAXP() throws Exception {
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
- Fop fop = new Fop(MimeConstants.MIME_PDF);
- fop.setOutputStream(baout);
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, baout);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); //Identity transf.
* @throws Exception if anything fails
*/
public void testFO2PSWithJAXP() throws Exception {
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
- Fop fop = new Fop(MimeConstants.MIME_POSTSCRIPT);
- fop.setOutputStream(baout);
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, foUserAgent, baout);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); //Identity transf.
* @throws Exception if anything fails
*/
public void testFO2RTFWithJAXP() throws Exception {
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
- Fop fop = new Fop(MimeConstants.MIME_RTF);
- fop.setOutputStream(baout);
+ Fop fop = new Fop(MimeConstants.MIME_RTF, foUserAgent, baout);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); //Identity transf.
* @throws Exception if anything fails
*/
public void testFO2PDFWithXSLTInputHandler() throws Exception {
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
File xmlFile = new File(getBaseDir(), "test/xml/1.xml");
File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl");
ByteArrayOutputStream baout = new ByteArrayOutputStream();
InputHandler handler = new InputHandler(xmlFile, xsltFile, null);
- handler.renderTo(null, MimeConstants.MIME_PDF, baout);
+ handler.renderTo(foUserAgent, MimeConstants.MIME_PDF, baout);
assertTrue("Generated PDF has zero length", baout.size() > 0);
}
/*
- * Copyright 1999-2005 The Apache Software Foundation.
+ * Copyright 1999-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
MessageDigest outDigest = MessageDigest.getInstance("MD5");
DigestOutputStream out =
new DigestOutputStream(new ByteArrayOutputStream(), outDigest);
- Fop fop = new Fop(MimeConstants.MIME_PDF, foUserAgent);
- fop.setOutputStream(out);
+ Fop fop = new Fop(MimeConstants.MIME_PDF, foUserAgent, out);
InputSource source = new InputSource(new StringReader(fo));
DigestFilter filter = new DigestFilter("MD5");
filter.setParent(parserFactory.newSAXParser().getXMLReader());
/*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
ua.setURIResolver(resolver);
ua.setBaseURL(foFile.getParentFile().toURL().toString());
- Fop fop = new Fop(MimeConstants.MIME_PDF, ua);
-
ByteArrayOutputStream baout = new ByteArrayOutputStream();
- fop.setOutputStream(baout);
+
+ Fop fop = new Fop(MimeConstants.MIME_PDF, ua, baout);
Transformer transformer = tfactory.newTransformer(); //Identity transf.
Source src = new StreamSource(foFile);
/*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.avalon.framework.activity.Initializable;
public void process(InputStream in, Templates templates, OutputStream out)
throws org.apache.fop.apps.FOPException, java.io.IOException {
- Fop fop = new Fop(MimeConstants.MIME_PDF);
- fop.setOutputStream(out);
+ FopFactory fopFactory = FopFactory.newInstance();
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+ Fop fop = new Fop(MimeConstants.MIME_PDF, foUserAgent, out);
try {
Transformer transformer;
/*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
OutputStream out = new FileOutputStream(tempOut);
out = new BufferedOutputStream(out);
try {
- Fop fop = new Fop(getTargetFormat(), userAgent);
- fop.setOutputStream(out);
+ Fop fop = new Fop(getTargetFormat(), userAgent, out);
SAXResult res = new SAXResult(fop.getDefaultHandler());
Transformer transformer = getTransformer(context);
/*
- * Copyright 2005 The Apache Software Foundation.
+ * Copyright 2005-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
OutputStream out = new FileOutputStream(outputFile);
out = new BufferedOutputStream(out);
try {
- Fop fop = new Fop(MimeConstants.MIME_PNG, userAgent);
- fop.setOutputStream(out);
+ Fop fop = new Fop(MimeConstants.MIME_PNG, userAgent, out);
SAXResult res = new SAXResult(fop.getDefaultHandler());
Transformer transformer = getTransformer(context);