You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2006/03/27 11:51:21 UTC
svn commit: r389086 [2/2] - in /xmlgraphics/fop/trunk: ./
examples/embedding/java/embedding/
examples/embedding/java/embedding/intermediate/
src/java/org/apache/fop/apps/ src/java/org/apache/fop/area/
src/java/org/apache/fop/cli/ src/java/org/apache/fo...
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -37,7 +37,6 @@
import java.util.LinkedList;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.layoutmgr.inline.AlignmentContext;
-import org.apache.fop.layoutmgr.inline.LeafNodeLayoutManager.AreaInfo;
/**
* LayoutManager for the fo:character formatting object
@@ -146,7 +145,7 @@
/** @see InlineLevelLayoutManager#getWordChars(StringBuffer, Position) */
public void getWordChars(StringBuffer sbChars, Position bp) {
sbChars.append
- (((org.apache.fop.area.inline.Character) curArea).getChar());
+ (((org.apache.fop.area.inline.TextArea) curArea).getText());
}
/** @see InlineLevelLayoutManager#hyphenate(Position, HyphContext) */
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java Mon Mar 27 01:51:14 2006
@@ -1520,11 +1520,11 @@
// on an inline or wrapper below the block level.
Hyphenation hyph
= Hyphenator.hyphenate(hyphenationProperties.language,
- hyphenationProperties.country,
- getFObj().getUserAgent().getHyphenationTreeResolver(),
- sbChars.toString(),
- hyphenationProperties.hyphenationRemainCharacterCount,
- hyphenationProperties.hyphenationPushCharacterCount);
+ hyphenationProperties.country,
+ getFObj().getUserAgent().getFactory().getHyphenationTreeResolver(),
+ sbChars.toString(),
+ hyphenationProperties.hyphenationRemainCharacterCount,
+ hyphenationProperties.hyphenationPushCharacterCount);
// They hyph structure contains the information we need
// Now start from prev: reset to that position, ask that LM to get
// a Position for the first hyphenation offset. If the offset isn't in
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/PrintRenderer.java Mon Mar 27 01:51:14 2006
@@ -48,7 +48,8 @@
public void setupFontInfo(FontInfo inFontInfo) {
this.fontInfo = inFontInfo;
FontResolver resolver = new DefaultFontResolver(userAgent);
- FontSetup.setup(fontInfo, fontList, resolver, userAgent.isBase14KerningEnabled());
+ FontSetup.setup(fontInfo, fontList, resolver,
+ userAgent.getFactory().isBase14KerningEnabled());
}
/**
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/RendererFactory.java Mon Mar 27 01:51:14 2006
@@ -229,7 +229,7 @@
if (out == null
&& userAgent.getRendererOverride() == null
&& rendMaker.needsOutputStream()) {
- throw new IllegalStateException(
+ throw new FOPException(
"OutputStream has not been set");
}
//Found a Renderer so we need to construct an AreaTreeHandler.
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DRenderer.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/java2d/Java2DRenderer.java Mon Mar 27 01:51:14 2006
@@ -1030,7 +1030,7 @@
int y = currentBPPosition;
String url = ImageFactory.getURL(pUrl);
- ImageFactory fact = ImageFactory.getInstance();
+ ImageFactory fact = userAgent.getFactory().getImageFactory();
FopImage fopimage = fact.getImage(url, userAgent);
if (fopimage == null) {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFRenderer.java Mon Mar 27 01:51:14 2006
@@ -67,6 +67,7 @@
import org.apache.fop.pdf.PDFColor;
import org.apache.fop.pdf.PDFDocument;
import org.apache.fop.pdf.PDFEncryptionManager;
+import org.apache.fop.pdf.PDFEncryptionParams;
import org.apache.fop.pdf.PDFFilterList;
import org.apache.fop.pdf.PDFInfo;
import org.apache.fop.pdf.PDFLink;
@@ -111,6 +112,20 @@
*/
public static final String MIME_TYPE = MimeConstants.MIME_PDF;
+ /** PDF encryption parameter: all parameters as object, datatype: PDFEncryptionParams */
+ public static final String ENCRYPTION_PARAMS = "encryption-params";
+ /** PDF encryption parameter: user password, datatype: String */
+ public static final String USER_PASSWORD = "user-password";
+ /** PDF encryption parameter: owner password, datatype: String */
+ public static final String OWNER_PASSWORD = "owner-password";
+ /** PDF encryption parameter: Forbids printing, datatype: Boolean or "true"/"false" */
+ public static final String NO_PRINT = "noprint";
+ /** PDF encryption parameter: Forbids copying content, datatype: Boolean or "true"/"false" */
+ public static final String NO_COPY_CONTENT = "nocopy";
+ /** PDF encryption parameter: Forbids editing content, datatype: Boolean or "true"/"false" */
+ public static final String NO_EDIT_CONTENT = "noedit";
+ /** PDF encryption parameter: Forbids annotations, datatype: Boolean or "true"/"false" */
+ public static final String NO_ANNOTATIONS = "noannotations";
/** Rendering Options key for the PDF/A mode. */
public static final String PDF_A_MODE = "pdf-a-mode";
@@ -167,6 +182,9 @@
*/
protected PDFPage currentPage;
+ /** the (optional) encryption parameters */
+ protected PDFEncryptionParams encryptionParams;
+
/** The current Transform */
protected AffineTransform currentBasicTransform;
@@ -245,11 +263,70 @@
}
}
+ private boolean booleanValueOf(Object obj) {
+ if (obj instanceof Boolean) {
+ return ((Boolean)obj).booleanValue();
+ } else if (obj instanceof String) {
+ return Boolean.valueOf((String)obj).booleanValue();
+ } else {
+ throw new IllegalArgumentException("Boolean or \"true\" or \"false\" expected.");
+ }
+ }
+
/**
* @see org.apache.fop.render.Renderer#setUserAgent(FOUserAgent)
*/
public void setUserAgent(FOUserAgent agent) {
super.setUserAgent(agent);
+ PDFEncryptionParams params
+ = (PDFEncryptionParams)agent.getRendererOptions().get(ENCRYPTION_PARAMS);
+ if (params != null) {
+ this.encryptionParams = params; //overwrite if available
+ }
+ String pwd;
+ pwd = (String)agent.getRendererOptions().get(USER_PASSWORD);
+ if (pwd != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setUserPassword(pwd);
+ }
+ pwd = (String)agent.getRendererOptions().get(OWNER_PASSWORD);
+ if (pwd != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setOwnerPassword(pwd);
+ }
+ Object setting;
+ setting = agent.getRendererOptions().get(NO_PRINT);
+ if (setting != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setAllowPrint(!booleanValueOf(setting));
+ }
+ setting = agent.getRendererOptions().get(NO_COPY_CONTENT);
+ if (setting != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setAllowCopyContent(!booleanValueOf(setting));
+ }
+ setting = agent.getRendererOptions().get(NO_EDIT_CONTENT);
+ if (setting != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setAllowEditContent(!booleanValueOf(setting));
+ }
+ setting = agent.getRendererOptions().get(NO_ANNOTATIONS);
+ if (setting != null) {
+ if (encryptionParams == null) {
+ this.encryptionParams = new PDFEncryptionParams();
+ }
+ this.encryptionParams.setAllowEditAnnotations(!booleanValueOf(setting));
+ }
String s = (String)agent.getRendererOptions().get(PDF_A_MODE);
if (s != null) {
this.pdfAMode = PDFAMode.valueOf(s);
@@ -276,8 +353,7 @@
this.pdfDoc.outputHeader(stream);
//Setup encryption if necessary
- PDFEncryptionManager.setupPDFEncryption(
- userAgent.getPDFEncryptionParams(), this.pdfDoc);
+ PDFEncryptionManager.setupPDFEncryption(encryptionParams, this.pdfDoc);
}
/**
@@ -1213,7 +1289,7 @@
}
url = ImageFactory.getURL(url);
- ImageFactory fact = ImageFactory.getInstance();
+ ImageFactory fact = userAgent.getFactory().getImageFactory();
FopImage fopimage = fact.getImage(url, userAgent);
if (fopimage == null) {
return;
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/ps/PSRenderer.java Mon Mar 27 01:51:14 2006
@@ -279,7 +279,7 @@
protected void drawImage(String url, Rectangle2D pos) {
endTextObject();
url = ImageFactory.getURL(url);
- ImageFactory fact = ImageFactory.getInstance();
+ ImageFactory fact = userAgent.getFactory().getImageFactory();
FopImage fopimage = fact.getImage(url, userAgent);
if (fopimage == null) {
return;
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/rtf/RTFHandler.java Mon Mar 27 01:51:14 2006
@@ -1121,8 +1121,9 @@
String url = eg.getURL();
//set image data
- ImageFactory fact = ImageFactory.getInstance();
- FopImage fopimage = fact.getImage(url, eg.getUserAgent());
+ FOUserAgent userAgent = eg.getUserAgent();
+ ImageFactory fact = userAgent.getFactory().getImageFactory();
+ FopImage fopimage = fact.getImage(url, userAgent);
if (fopimage == null) {
log.error("Image could not be found: " + url);
return;
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/servlet/FopPrintServlet.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/servlet/FopPrintServlet.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/servlet/FopPrintServlet.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/servlet/FopPrintServlet.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -18,25 +18,18 @@
package org.apache.fop.servlet;
-import java.io.File;
-import java.io.InputStream;
+import java.io.IOException;
import java.io.PrintWriter;
-// JAXP
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
-import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.stream.StreamSource;
-// XML
-import org.apache.commons.logging.impl.SimpleLog;
+import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.MimeConstants;
@@ -58,164 +51,49 @@
* Example URL: http://servername/fop/servlet/FopPrintServlet?fo=readme.fo
* <br/>
* Example URL: http://servername/fop/servlet/FopPrintServlet?xml=data.xml&xsl=format.xsl
- *
- * @author <a href="mailto:fop-dev@xml.apache.org">Apache XML FOP Development Team</a>
+ * <br/>
+ * <b>Note:</b> This servlet is derived from FopServlet. Most methods are inherited from the
+ * superclass. Only the differences to the base class are necessary.
+ *
+ * @author <a href="mailto:fop-dev@xmlgraphics.apache.org">Apache FOP Development Team</a>
* @version $Id$
- * (todo) Doesn't work since there's no AWTRenderer at the moment. Revisit when
- * available.
- * (todo) Ev. add caching mechanism for Templates objects
*/
-public class FopPrintServlet extends HttpServlet {
-
- /** Name of the parameter used for the XSL-FO file */
- protected static final String FO_REQUEST_PARAM = "fo";
- /** Name of the parameter used for the XML file */
- protected static final String XML_REQUEST_PARAM = "xml";
- /** Name of the parameter used for the XSLT file */
- protected static final String XSLT_REQUEST_PARAM = "xslt";
-
- /** Logger to give to FOP */
- protected SimpleLog log = null;
-
- /** The TransformerFactory to use to create Transformer instances */
- protected TransformerFactory transFactory = null;
- /** URIResolver for use by this servlet */
- protected URIResolver uriResolver;
-
- /**
- * @see javax.servlet.GenericServlet#init()
- */
- public void init() throws ServletException {
- this.log = new SimpleLog("FOP/Print Servlet");
- log.setLevel(SimpleLog.LOG_LEVEL_WARN);
- this.uriResolver = new ServletContextURIResolver(getServletContext());
- this.transFactory = TransformerFactory.newInstance();
- this.transFactory.setURIResolver(this.uriResolver);
- }
-
- /**
- * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest, HttpServletResponse)
- */
- public void doGet(HttpServletRequest request,
- HttpServletResponse response) throws ServletException {
- if (log == null) {
- log = new SimpleLog("FOP/Print Servlet");
- log.setLevel(SimpleLog.LOG_LEVEL_WARN);
- }
-
- try {
- String foParam = request.getParameter(FO_REQUEST_PARAM);
- String xmlParam = request.getParameter(XML_REQUEST_PARAM);
- String xsltParam = request.getParameter(XSLT_REQUEST_PARAM);
-
- if (foParam != null) {
- InputStream file = new java.io.FileInputStream(foParam);
- renderFO(file, response);
- } else if ((xmlParam != null) && (xsltParam != null)) {
- renderXML(new File(xmlParam), new File(xsltParam), response);
- } else {
- response.setContentType("text/html");
-
- PrintWriter out = response.getWriter();
- out.println("<html><title>Error</title>\n"
- + "<body><h1>FopServlet Error</h1>\n"
- + "<h3>No 'fo' or 'xml/xsl' "
- + "request param given.</h3></body>\n</html>");
- }
- } catch (ServletException ex) {
- throw ex;
- } catch (Exception ex) {
- throw new ServletException(ex);
- }
- }
+public class FopPrintServlet extends FopServlet {
/**
- * Renders an FO inputsource to the default printer.
- * @param foFile The XSL-FO file
- * @param response Response to write to
- * @throws ServletException In case of a problem
+ * @see org.apache.fop.servlet.FopServlet#render(javax.xml.transform.Source,
+ * javax.xml.transform.Transformer, javax.servlet.http.HttpServletResponse)
*/
- public void renderFO(InputStream foFile,
- HttpServletResponse response) throws ServletException {
- try {
- Fop fop = new Fop(MimeConstants.MIME_FOP_PRINT, getFOUserAgent());
-
- // Setup JAXP
- TransformerFactory factory = TransformerFactory.newInstance();
- Transformer transformer = factory.newTransformer(); //identity transformer
- transformer.setURIResolver(this.uriResolver);
-
- // Setup input for XSLT transformation
- Source src = new StreamSource(foFile);
-
- // Resulting SAX events (the generated FO) must be piped through to FOP
- Result res = new SAXResult(fop.getDefaultHandler());
-
- // Start XSLT transformation and FOP processing
- transformer.transform(src, res);
-
- reportOK (response);
- } catch (Exception ex) {
- throw new ServletException(ex);
- }
- }
+ protected void render(Source src, Transformer transformer, HttpServletResponse response)
+ throws FOPException, TransformerException, IOException {
- /**
- * Renders an FO generated using an XML and a stylesheet to the default printer.
- * @param xmlfile XML file object
- * @param xsltfile XSLT stylesheet
- * @param response HTTP response object
- * @throws ServletException In case of a problem
- */
- public void renderXML(File xmlfile, File xsltfile,
- HttpServletResponse response) throws ServletException {
- try {
- Fop fop = new Fop(MimeConstants.MIME_FOP_PRINT, getFOUserAgent());
-
- // Setup XSLT
- TransformerFactory factory = TransformerFactory.newInstance();
- Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
- transformer.setURIResolver(this.uriResolver);
-
- // Setup input for XSLT transformation
- Source src = new StreamSource(xmlfile);
+ FOUserAgent foUserAgent = getFOUserAgent();
- // Resulting SAX events (the generated FO) must be piped through to FOP
- Result res = new SAXResult(fop.getDefaultHandler());
-
- // Start XSLT transformation and FOP processing
- transformer.transform(src, res);
-
- reportOK (response);
- } catch (Exception ex) {
- throw new ServletException(ex);
- }
+ //Setup FOP
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_PRINT, foUserAgent);
+
+ //Make sure the XSL transformation's result is piped through to FOP
+ Result res = new SAXResult(fop.getDefaultHandler());
+
+ //Start the transformation and rendering process
+ transformer.transform(src, res);
+
+ //Return the result
+ reportOK(response);
}
// private helper, tell (browser) user that file printed
- private void reportOK(HttpServletResponse response)
- throws ServletException {
+ private void reportOK(HttpServletResponse response) throws IOException {
String sMsg = "<html><title>Success</title>\n"
+ "<body><h1>FopPrintServlet: </h1>"
- + "<h3>The requested data was printed</h3></body></html>";
+ + "<h3>The requested data was printed to the default printer.</h3></body></html>";
response.setContentType("text/html");
response.setContentLength(sMsg.length());
- try {
- PrintWriter out = response.getWriter();
- out.println(sMsg);
- out.flush();
- } catch (Exception ex) {
- throw new ServletException(ex);
- }
- }
-
- /** @return a new FOUserAgent for FOP */
- protected FOUserAgent getFOUserAgent() {
- FOUserAgent userAgent = new FOUserAgent();
- userAgent.setURIResolver(this.uriResolver);
- return userAgent;
+ PrintWriter out = response.getWriter();
+ out.println(sMsg);
+ out.flush();
}
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/servlet/FopServlet.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/servlet/FopServlet.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/servlet/FopServlet.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/servlet/FopServlet.java Mon Mar 27 01:51:14 2006
@@ -19,6 +19,7 @@
package org.apache.fop.servlet;
import java.io.File;
+import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
@@ -37,10 +38,10 @@
import org.apache.commons.io.output.ByteArrayOutputStream;
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;
/**
@@ -63,7 +64,7 @@
* For this to work with Internet Explorer, you might need to append "&ext=.pdf"
* to the URL.
*
- * @author <a href="mailto:fop-dev@xml.apache.org">Apache XML FOP Development Team</a>
+ * @author <a href="mailto:fop-dev@xmlgraphics.apache.org">Apache FOP Development Team</a>
* @version $Id$
* (todo) Ev. add caching mechanism for Templates objects
*/
@@ -78,8 +79,10 @@
/** Logger to give to FOP */
protected SimpleLog log = null;
- /** The TransformerFactory to use to create Transformer instances */
+ /** The TransformerFactory used to create Transformer instances */
protected TransformerFactory transFactory = null;
+ /** The FopFactory used to create Fop instances */
+ protected FopFactory fopFactory = null;
/** URIResolver for use by this servlet */
protected URIResolver uriResolver;
@@ -92,6 +95,18 @@
this.uriResolver = new ServletContextURIResolver(getServletContext());
this.transFactory = TransformerFactory.newInstance();
this.transFactory.setURIResolver(this.uriResolver);
+ //Configure FopFactory as desired
+ this.fopFactory = FopFactory.newInstance();
+ this.fopFactory.setURIResolver(this.uriResolver);
+ configureFopFactory();
+ }
+
+ /**
+ * This method is called right after the FopFactory is instantiated and can be overridden
+ * by subclasses to perform additional configuration.
+ */
+ protected void configureFopFactory() {
+ //Subclass and override this method to perform additional configuration
}
/**
@@ -106,26 +121,17 @@
String xsltParam = request.getParameter(XSLT_REQUEST_PARAM);
//Analyze parameters and decide with method to use
- byte[] content = null;
if (foParam != null) {
- content = renderFO(foParam);
+ renderFO(foParam, response);
} else if ((xmlParam != null) && (xsltParam != null)) {
- content = renderXML(xmlParam, xsltParam);
+ renderXML(xmlParam, xsltParam, response);
} else {
+ response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><title>Error</title></head>\n"
+ "<body><h1>FopServlet Error</h1><h3>No 'fo' "
+ "request param given.</body></html>");
}
-
- if (content != null) {
- //Send the result back to the client
- response.setContentType("application/pdf");
- response.setContentLength(content.length);
- response.getOutputStream().write(content);
- response.getOutputStream().flush();
- }
-
} catch (Exception ex) {
throw new ServletException(ex);
}
@@ -140,18 +146,27 @@
return new StreamSource(new File(param));
}
+ private void sendPDF(byte[] content, HttpServletResponse response) throws IOException {
+ //Send the result back to the client
+ response.setContentType("application/pdf");
+ response.setContentLength(content.length);
+ response.getOutputStream().write(content);
+ response.getOutputStream().flush();
+ }
+
/**
* Renders an XSL-FO file into a PDF file. The PDF is written to a byte
* array that is returned as the method's result.
* @param fo the XSL-FO file
- * @return byte[] the rendered PDF file
+ * @param response HTTP response object
* @throws FOPException If an error occurs during the rendering of the
* XSL-FO
* @throws TransformerException If an error occurs while parsing the input
* file
+ * @throws IOException In case of an I/O problem
*/
- protected byte[] renderFO(String fo)
- throws FOPException, TransformerException {
+ protected void renderFO(String fo, HttpServletResponse response)
+ throws FOPException, TransformerException, IOException {
//Setup source
Source foSrc = convertString2Source(fo);
@@ -161,7 +176,7 @@
transformer.setURIResolver(this.uriResolver);
//Start transformation and rendering process
- return render(foSrc, transformer);
+ render(foSrc, transformer, response);
}
/**
@@ -170,14 +185,15 @@
* that is returned as the method's result.
* @param xml the XML file
* @param xslt the XSLT file
- * @return byte[] the rendered PDF file
+ * @param response HTTP response object
* @throws FOPException If an error occurs during the rendering of the
* XSL-FO
* @throws TransformerException If an error occurs during XSL
* transformation
+ * @throws IOException In case of an I/O problem
*/
- protected byte[] renderXML(String xml, String xslt)
- throws FOPException, TransformerException {
+ protected void renderXML(String xml, String xslt, HttpServletResponse response)
+ throws FOPException, TransformerException, IOException {
//Setup sources
Source xmlSrc = convertString2Source(xml);
@@ -188,7 +204,7 @@
transformer.setURIResolver(this.uriResolver);
//Start transformation and rendering process
- return render(xmlSrc, transformer);
+ render(xmlSrc, transformer, response);
}
/**
@@ -199,21 +215,23 @@
* returned as the method's result.
* @param src Input XML or XSL-FO
* @param transformer Transformer to use for optional transformation
- * @return byte[] the rendered PDF file
+ * @param response HTTP response object
* @throws FOPException If an error occurs during the rendering of the
* XSL-FO
* @throws TransformerException If an error occurs during XSL
* transformation
+ * @throws IOException In case of an I/O problem
*/
- protected byte[] render(Source src, Transformer transformer)
- throws FOPException, TransformerException {
+ protected void render(Source src, Transformer transformer, HttpServletResponse response)
+ throws FOPException, TransformerException, IOException {
- //Setup FOP
- Fop fop = new Fop(MimeConstants.MIME_PDF, getFOUserAgent());
+ FOUserAgent foUserAgent = getFOUserAgent();
//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());
@@ -222,13 +240,13 @@
transformer.transform(src, res);
//Return the result
- return out.toByteArray();
+ sendPDF(out.toByteArray(), response);
}
/** @return a new FOUserAgent for FOP */
protected FOUserAgent getFOUserAgent() {
- FOUserAgent userAgent = new FOUserAgent();
- userAgent.setURIResolver(this.uriResolver);
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
+ //Configure foUserAgent as desired
return userAgent;
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/tools/TestConverter.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/tools/TestConverter.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/tools/TestConverter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/tools/TestConverter.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -25,7 +25,7 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.cli.InputHandler;
@@ -48,6 +48,9 @@
*/
public class TestConverter {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
private boolean failOnly = false;
private String outputFormat = MimeConstants.MIME_FOP_AREA_TREE;
private File destdir;
@@ -284,7 +287,7 @@
+ xsl), null);
}
- FOUserAgent userAgent = new FOUserAgent();
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
userAgent.setBaseURL(baseURL);
userAgent.getRendererOptions().put("fineDetail", new Boolean(false));
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/tools/anttasks/Fop.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/tools/anttasks/Fop.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/tools/anttasks/Fop.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/tools/anttasks/Fop.java Mon Mar 27 01:51:14 2006
@@ -37,6 +37,7 @@
// FOP
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.cli.InputHandler;
@@ -306,6 +307,9 @@
class FOPTaskStarter {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
private Fop task;
private String baseURL = null;
@@ -555,11 +559,8 @@
boolean success = false;
try {
- FOUserAgent userAgent = new FOUserAgent();
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
userAgent.setBaseURL(this.baseURL);
- if (userConfig != null) {
- userAgent.setUserConfig(userConfig);
- }
inputHandler.renderTo(userAgent, outputFormat, out);
success = true;
} catch (Exception ex) {
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ContentHandlerFactoryRegistry.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ContentHandlerFactoryRegistry.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ContentHandlerFactoryRegistry.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/util/ContentHandlerFactoryRegistry.java Mon Mar 27 01:51:14 2006
@@ -36,20 +36,8 @@
/** the logger */
private static Log log = LogFactory.getLog(ContentHandlerFactoryRegistry.class);
- private static ContentHandlerFactoryRegistry instance;
-
/** Map from namespace URIs to ContentHandlerFactories */
private Map factories = new java.util.HashMap();
-
- /**
- * @return a singleton instance of the ContentHandlerFactoryRegistry.
- */
- public static ContentHandlerFactoryRegistry getInstance() {
- if (instance == null) {
- instance = new ContentHandlerFactoryRegistry();
- }
- return instance;
- }
/**
* Default constructor.
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/BasicDriverTestCase.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/BasicDriverTestCase.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/BasicDriverTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/BasicDriverTestCase.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -28,7 +28,9 @@
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;
@@ -38,6 +40,8 @@
*/
public class BasicDriverTestCase extends AbstractFOPTestCase {
+ private FopFactory fopFactory = FopFactory.newInstance();
+
/**
* @see junit.framework.TestCase#TestCase(String)
*/
@@ -50,10 +54,10 @@
* @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.
@@ -69,10 +73,10 @@
* @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.
@@ -88,10 +92,10 @@
* @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 = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, baout);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); //Identity transf.
@@ -107,12 +111,13 @@
* @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);
}
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/GenericFOPTestCase.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/GenericFOPTestCase.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/GenericFOPTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/GenericFOPTestCase.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -32,6 +32,7 @@
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FOUserAgent;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.util.DigestFilter;
import org.xml.sax.InputSource;
@@ -46,6 +47,9 @@
*/
public final class GenericFOPTestCase extends TestCase {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
protected SAXParserFactory parserFactory;
public static Test suite() {
@@ -110,13 +114,12 @@
private void renderPDF(String fo, String digestIn, String digestOut)
throws Exception {
- FOUserAgent foUserAgent = new FOUserAgent();
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
foUserAgent.setCreationDate(new Date(10000));
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 = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
InputSource source = new InputSource(new StringReader(fo));
DigestFilter filter = new DigestFilter("MD5");
filter.setParent(parserFactory.newSAXParser().getXMLReader());
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/URIResolutionTestCase.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/URIResolutionTestCase.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/URIResolutionTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/URIResolutionTestCase.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -40,8 +40,8 @@
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.image.ImageFactory;
import org.apache.fop.render.xml.XMLRenderer;
import org.apache.xpath.XPathAPI;
import org.apache.xpath.objects.XObject;
@@ -52,6 +52,9 @@
*/
public class URIResolutionTestCase extends AbstractFOPTestCase {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
private SAXTransformerFactory tfactory
= (SAXTransformerFactory)SAXTransformerFactory.newInstance();
@@ -79,12 +82,13 @@
}
private void innerTestFO1(boolean withStream) throws Exception {
+ FOUserAgent ua = fopFactory.newFOUserAgent();
+
//Reset the image caches to force URI resolution!
- ImageFactory.getInstance().clearCaches();
+ ua.getFactory().getImageFactory().clearCaches();
File foFile = new File(getBaseDir(), "test/xml/uri-resolution1.fo");
- FOUserAgent ua = new FOUserAgent();
MyURIResolver resolver = new MyURIResolver(withStream);
ua.setURIResolver(resolver);
ua.setBaseURL(foFile.getParentFile().toURL().toString());
@@ -111,15 +115,14 @@
//TODO This will only work when we can do URI resolution inside Batik!
File foFile = new File(getBaseDir(), "test/xml/uri-resolution2.fo");
- FOUserAgent ua = new FOUserAgent();
+ FOUserAgent ua = fopFactory.newFOUserAgent();
MyURIResolver resolver = new MyURIResolver(false);
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 = fopFactory.newFop(MimeConstants.MIME_PDF, ua, baout);
Transformer transformer = tfactory.newTransformer(); //Identity transf.
Source src = new StreamSource(foFile);
@@ -156,7 +159,7 @@
atrenderer.setContentHandler(athandler);
ua.setRendererOverride(atrenderer);
- Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, ua);
+ Fop fop = fopFactory.newFop(ua);
Transformer transformer = tfactory.newTransformer(); //Identity transf.
Source src = new StreamSource(fo);
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTester.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTester.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTester.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/fotreetest/FOTreeTester.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -23,18 +23,12 @@
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.sax.SAXResult;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.stream.StreamSource;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
-import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.fotreetest.ext.TestElementMapping;
-import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLFilterImpl;
@@ -44,9 +38,6 @@
*/
public class FOTreeTester {
- private SAXTransformerFactory tfactory
- = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
-
/**
* Runs a test.
* @param testFile the test file.
@@ -63,15 +54,17 @@
XMLReader reader = parser.getXMLReader();
//Setup FOP for area tree rendering
- FOUserAgent ua = new FOUserAgent();
+ FopFactory fopFactory = FopFactory.newInstance();
+ fopFactory.addElementMapping(new TestElementMapping());
+
+ FOUserAgent ua = fopFactory.newFOUserAgent();
ua.setBaseURL(testFile.getParentFile().toURL().toString());
ua.setFOEventHandlerOverride(new DummyFOEventHandler(ua));
- ua.addElementMapping(new TestElementMapping());
//Used to set values in the user agent through processing instructions
reader = new PIListener(reader, ua);
- Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, ua);
+ Fop fop = fopFactory.newFop(ua);
reader.setContentHandler(fop.getDefaultHandler());
reader.setDTDHandler(fop.getDefaultHandler());
@@ -100,7 +93,7 @@
/** @see org.xml.sax.helpers.XMLFilterImpl */
public void processingInstruction(String target, String data) throws SAXException {
if ("fop-useragent-break-indent-inheritance".equals(target)) {
- userAgent.setBreakIndentInheritanceOnReferenceAreaBoundary(
+ userAgent.getFactory().setBreakIndentInheritanceOnReferenceAreaBoundary(
Boolean.valueOf(data).booleanValue());
}
super.processingInstruction(target, data);
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/intermediate/AreaTreeParserTestCase.java Mon Mar 27 01:51:14 2006
@@ -41,6 +41,7 @@
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.area.AreaTreeModel;
import org.apache.fop.area.AreaTreeParser;
@@ -58,6 +59,9 @@
*/
public class AreaTreeParserTestCase extends XMLTestCase {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
private static SAXTransformerFactory tFactory
= (SAXTransformerFactory)SAXTransformerFactory.newInstance();
private static Templates stylesheet = null;
@@ -162,7 +166,7 @@
}
private FOUserAgent createUserAgent() {
- FOUserAgent userAgent = new FOUserAgent();
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
try {
userAgent.setBaseURL(testDir.toURL().toExternalForm());
} catch (MalformedURLException e) {
@@ -197,7 +201,7 @@
userAgent.setRendererOverride(renderer);
- Fop fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, userAgent);
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AREA_TREE, userAgent);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/layoutengine/LayoutEngineTester.java Mon Mar 27 01:51:14 2006
@@ -21,7 +21,6 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
-import java.net.MalformedURLException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -43,11 +42,10 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-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.FormattingResults;
-import org.apache.fop.apps.MimeConstants;
import org.apache.fop.layoutmgr.ElementListObserver;
import org.apache.fop.render.xml.XMLRenderer;
import org.apache.xpath.XPathAPI;
@@ -56,7 +54,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
@@ -67,6 +64,10 @@
private static final Map CHECK_CLASSES = new java.util.HashMap();
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+ private FopFactory fopFactoryWithBase14Kerning = FopFactory.newInstance();
+
private SAXTransformerFactory tfactory
= (SAXTransformerFactory)SAXTransformerFactory.newInstance();
@@ -89,6 +90,8 @@
*/
public LayoutEngineTester(File areaTreeBackupDir) {
this.areaTreeBackupDir = areaTreeBackupDir;
+ fopFactory.setBase14KerningEnabled(false);
+ fopFactoryWithBase14Kerning.setBase14KerningEnabled(true);
}
private Templates getTestcase2FOStylesheet() throws TransformerConfigurationException {
@@ -137,6 +140,7 @@
XObject xo = XPathAPI.eval(testDoc, "/testcase/cfg/base14kerning");
String s = xo.str();
boolean base14kerning = ("true".equalsIgnoreCase(s));
+ FopFactory effFactory = (base14kerning ? fopFactoryWithBase14Kerning : fopFactory);
//Setup Transformer to convert the testcase XML to XSL-FO
Transformer transformer = getTestcase2FOStylesheet().newTransformer();
@@ -147,14 +151,13 @@
athandler.setResult(domres);
//Setup FOP for area tree rendering
- FOUserAgent ua = new FOUserAgent();
+ FOUserAgent ua = effFactory.newFOUserAgent();
ua.setBaseURL(testFile.getParentFile().toURL().toString());
- ua.setBase14KerningEnabled(base14kerning);
XMLRenderer atrenderer = new XMLRenderer();
atrenderer.setUserAgent(ua);
atrenderer.setContentHandler(athandler);
ua.setRendererOverride(atrenderer);
- fop = new Fop(MimeConstants.MIME_FOP_AREA_TREE, ua);
+ fop = effFactory.newFop(ua);
SAXResult fores = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, fores);
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/threading/FOProcessorImpl.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/threading/FOProcessorImpl.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/threading/FOProcessorImpl.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/threading/FOProcessorImpl.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -35,14 +35,18 @@
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 class FOProcessorImpl extends AbstractLogEnabled
implements FOProcessor, Configurable, Initializable {
+ private FopFactory fopFactory = FopFactory.newInstance();
+ private TransformerFactory factory = TransformerFactory.newInstance();
private String baseDir;
private String fontBaseDir;
private String userconfig;
@@ -84,13 +88,12 @@
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);
+ FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
try {
Transformer transformer;
if (templates == null) {
- TransformerFactory factory = TransformerFactory.newInstance();
transformer = factory.newTransformer();
} else {
transformer = templates.newTransformer();
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/AbstractPSPDFBitmapProducer.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -36,6 +36,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
/**
* BitmapProducer implementation that uses the PS or PDF renderer and an external converter
@@ -63,6 +64,9 @@
public abstract class AbstractPSPDFBitmapProducer extends AbstractBitmapProducer
implements Configurable {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
private String converter;
private boolean deleteTempFiles;
@@ -106,7 +110,7 @@
/** @see org.apache.fop.visual.BitmapProducer */
public BufferedImage produce(File src, ProducerContext context) {
try {
- FOUserAgent userAgent = new FOUserAgent();
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
userAgent.setTargetResolution(context.getTargetResolution());
userAgent.setBaseURL(src.getParentFile().toURL().toString());
@@ -118,8 +122,7 @@
OutputStream out = new FileOutputStream(tempOut);
out = new BufferedOutputStream(out);
try {
- Fop fop = new Fop(getTargetFormat(), userAgent);
- fop.setOutputStream(out);
+ Fop fop = fopFactory.newFop(getTargetFormat(), userAgent, out);
SAXResult res = new SAXResult(fop.getDefaultHandler());
Transformer transformer = getTransformer(context);
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BitmapProducerJava2D.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BitmapProducerJava2D.java?rev=389086&r1=389085&r2=389086&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BitmapProducerJava2D.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/visual/BitmapProducerJava2D.java Mon Mar 27 01:51:14 2006
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -34,6 +34,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
/**
@@ -51,6 +52,9 @@
*/
public class BitmapProducerJava2D extends AbstractBitmapProducer implements Configurable {
+ // configure fopFactory as desired
+ private FopFactory fopFactory = FopFactory.newInstance();
+
private boolean deleteTempFiles;
/** @see org.apache.avalon.framework.configuration.Configurable */
@@ -61,7 +65,7 @@
/** @see org.apache.fop.visual.BitmapProducer */
public BufferedImage produce(File src, ProducerContext context) {
try {
- FOUserAgent userAgent = new FOUserAgent();
+ FOUserAgent userAgent = fopFactory.newFOUserAgent();
userAgent.setTargetResolution(context.getTargetResolution());
userAgent.setBaseURL(src.getParentFile().toURL().toString());
@@ -69,8 +73,7 @@
OutputStream out = new FileOutputStream(outputFile);
out = new BufferedOutputStream(out);
try {
- Fop fop = new Fop(MimeConstants.MIME_PNG, userAgent);
- fop.setOutputStream(out);
+ Fop fop = fopFactory.newFop(MimeConstants.MIME_PNG, userAgent, out);
SAXResult res = new SAXResult(fop.getDefaultHandler());
Transformer transformer = getTransformer(context);
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org