aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorGlen Mazza <gmazza@apache.org>2004-06-27 13:29:32 +0000
committerGlen Mazza <gmazza@apache.org>2004-06-27 13:29:32 +0000
commitdc2bf18ece928114fab1c159c1265042a4798f36 (patch)
treec3f8a39bb96e2780c445298131db9bfd2d12312f /src/java/org/apache
parentb0449877f620ca620d7061e17fff267b27af87e8 (diff)
downloadxmlgraphics-fop-dc2bf18ece928114fab1c159c1265042a4798f36.tar.gz
xmlgraphics-fop-dc2bf18ece928114fab1c159c1265042a4798f36.zip
1.) Moved Renderer instantiation from Driver to FOTreeHandler, as it is the only
FOInputHandler subclass concerned with Renderer creation. (MIFHandler and RTFHandler are hardcoded to a particular renderer-type). 2.) Added a RendererOverride member variable in FOUserAgent, for use by AWTRenderer as well as external (i.e. user-defined) renderers. FOTreeHandler coded to reference it. 3.) Flow validity checking which was added yesterday temporarily commented-out; I misread the content model from the spec (I will have to account for fo:markers as initial children.) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197746 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/apps/Driver.java157
-rw-r--r--src/java/org/apache/fop/apps/FOUserAgent.java19
-rw-r--r--src/java/org/apache/fop/fo/Constants.java3
-rw-r--r--src/java/org/apache/fop/fo/FOInputHandler.java2
-rw-r--r--src/java/org/apache/fop/fo/FOTreeHandler.java42
-rw-r--r--src/java/org/apache/fop/fo/pagination/Flow.java6
-rw-r--r--src/java/org/apache/fop/render/awt/AWTRenderer.java4
7 files changed, 127 insertions, 106 deletions
diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java
index e1287740e..ed4f3b50e 100644
--- a/src/java/org/apache/fop/apps/Driver.java
+++ b/src/java/org/apache/fop/apps/Driver.java
@@ -35,7 +35,6 @@ import org.apache.fop.fo.ElementMapping;
import org.apache.fop.fo.FOTreeBuilder;
import org.apache.fop.fo.FOInputHandler;
import org.apache.fop.fo.FOTreeHandler;
-import org.apache.fop.render.Renderer;
import org.apache.fop.render.awt.AWTRenderer;
import org.apache.fop.render.mif.MIFHandler;
import org.apache.fop.render.rtf.RTFHandler;
@@ -57,16 +56,16 @@ import org.apache.fop.tools.DocumentReader;
* driver.setRenderer(RENDER_PDF);
* driver.run();
* </PRE>
- * If neccessary, calling classes can call into the lower level
+ * If necessary, calling classes can call into the lower level
* methods to setup and
- * render. Methods can be called to set the
+ * render. Methods within FOUserAgent can be called to set the
* Renderer to use, the (possibly multiple) ElementMapping(s) to
* use and the OutputStream to use to output the results of the
- * rendering (where applicable). In the case of the Renderer and
+ * rendering (where applicable). In the case of
* ElementMapping(s), the Driver may be supplied either with the
* object itself, or the name of the class, in which case Driver will
* instantiate the class itself. The advantage of the latter is it
- * enables runtime determination of Renderer and ElementMapping(s).
+ * enables runtime determination of ElementMapping(s).
* <P>
* Once the Driver is set up, the render method
* is called. Depending on whether DOM or SAX is being used, the
@@ -83,7 +82,7 @@ import org.apache.fop.tools.DocumentReader;
*
* <PRE>
* Driver driver = new Driver();
- * driver.setRenderer(new org.apache.fop.render.awt.AWTRenderer(translator));
+ * driver.setRenderer(RENDER_AWT);
* driver.render(parser, fileInputSource(args[0]));
* </PRE>
*/
@@ -100,11 +99,6 @@ public class Driver implements Constants {
private int rendererType = NOT_SET;
/**
- * the renderer to use to output the area tree
- */
- private Renderer renderer;
-
- /**
* the SAX ContentHandler
*/
private FOInputHandler foInputHandler;
@@ -127,7 +121,7 @@ public class Driver implements Constants {
/**
* The system resources that FOP will use
*/
- private FOUserAgent userAgent = null;
+ private FOUserAgent foUserAgent = null;
/**
* Main constructor for the Driver class.
@@ -142,7 +136,8 @@ public class Driver implements Constants {
*/
public Driver(AWTRenderer renderer) {
this();
- setRenderer(renderer);
+ rendererType = RENDER_AWT;
+ foUserAgent = renderer.getUserAgent();
}
/**
@@ -171,15 +166,30 @@ public class Driver implements Constants {
}
/**
+ * Resets the Driver so it can be reused. Property and element
+ * mappings are reset to defaults.
+ * The output stream is cleared. The renderer is cleared.
+ */
+ public synchronized void reset() {
+ source = null;
+ stream = null;
+ reader = null;
+ if (treeBuilder != null) {
+ treeBuilder.reset();
+ }
+ }
+
+ /**
* Optionally sets the FOUserAgent instance for FOP to use. The Driver
* class sets up its own FOUserAgent if none is set through this method.
* @param agent FOUserAgent to use
*/
- public void setUserAgent(FOUserAgent agent) {
- userAgent = agent;
- if (renderer != null) {
- renderer.setUserAgent(userAgent);
+ public void setUserAgent(FOUserAgent agent) throws FOPException {
+ if (foUserAgent != null) {
+ throw new IllegalStateException("FOUserAgent " +
+ "instance already set.");
}
+ foUserAgent = agent;
}
/**
@@ -187,24 +197,10 @@ public class Driver implements Constants {
* @return the user agent
*/
public FOUserAgent getUserAgent() {
- if (userAgent == null) {
- userAgent = new FOUserAgent();
- }
- return userAgent;
- }
-
- /**
- * Resets the Driver so it can be reused. Property and element
- * mappings are reset to defaults.
- * The output stream is cleared. The renderer is cleared.
- */
- public synchronized void reset() {
- source = null;
- stream = null;
- reader = null;
- if (treeBuilder != null) {
- treeBuilder.reset();
+ if (foUserAgent == null) {
+ foUserAgent = new FOUserAgent();
}
+ return foUserAgent;
}
/**
@@ -241,68 +237,30 @@ public class Driver implements Constants {
}
/**
- * Method to set the rendering type to use. Must be one of
+ * Method to set the rendering type desired. Must be one of
* <ul>
- * <li>RENDER_PDF</li>
- * <li>RENDER_AWT</li>
- * <li>RENDER_PRINT</li>
- * <li>RENDER_MIF</li>
- * <li>RENDER_XML</li>
- * <li>RENDER_PCL</li>
- * <li>RENDER_PS</li>
- * <li>RENDER_TXT</li>
- * <li>RENDER_SVG</li>
- * <li>RENDER_RTF</li>
+ * <li>Driver.RENDER_PDF</li>
+ * <li>Driver.RENDER_AWT</li>
+ * <li>Driver.RENDER_PRINT</li>
+ * <li>Driver.RENDER_MIF</li>
+ * <li>Driver.RENDER_XML</li>
+ * <li>Driver.RENDER_PCL</li>
+ * <li>Driver.RENDER_PS</li>
+ * <li>Driver.RENDER_TXT</li>
+ * <li>Driver.RENDER_SVG</li>
+ * <li>Driver.RENDER_RTF</li>
* </ul>
- * @param renderer the type of renderer to use
- * @throws IllegalArgumentException if an unsupported renderer type was required.
+ * @param renderType the type of renderer to use
+ * @throws IllegalArgumentException if an unsupported renderer type was requested.
*/
- public void setRenderer(int renderer) throws IllegalArgumentException {
- rendererType = renderer;
- switch (renderer) {
- case RENDER_PDF:
- setRenderer(new org.apache.fop.render.pdf.PDFRenderer());
- break;
- case RENDER_AWT:
- setRenderer(new org.apache.fop.render.awt.AWTRenderer());
- break;
- case RENDER_PRINT:
- setRenderer(new org.apache.fop.render.awt.AWTPrintRenderer());
- break;
- case RENDER_PCL:
- setRenderer(new org.apache.fop.render.pcl.PCLRenderer());
- break;
- case RENDER_PS:
- setRenderer(new org.apache.fop.render.ps.PSRenderer());
- break;
- case RENDER_TXT:
- setRenderer(new org.apache.fop.render.txt.TXTRenderer());
- break;
- case RENDER_MIF:
- //foInputHandler will be set later
- break;
- case RENDER_XML:
- setRenderer(new org.apache.fop.render.xml.XMLRenderer());
- break;
- case RENDER_SVG:
- setRenderer(new org.apache.fop.render.svg.SVGRenderer());
- break;
- case RENDER_RTF:
- //foInputHandler will be set later
- break;
- default:
+ public void setRenderer(int renderType) throws IllegalArgumentException {
+ if (renderType < RENDER_MIN_CONST || renderType > RENDER_MAX_CONST) {
rendererType = NOT_SET;
- throw new IllegalArgumentException("Unknown renderer type " + renderer);
+ throw new IllegalArgumentException(
+ "Invalid renderer ID#" + renderType);
}
- }
- /**
- * Set the Renderer to use.
- * @param renderer the renderer instance to use
- */
- private void setRenderer(Renderer renderer) {
- renderer.setUserAgent(getUserAgent());
- this.renderer = renderer;
+ this.rendererType = renderType;
}
/**
@@ -344,16 +302,17 @@ public class Driver implements Constants {
// TODO: - do this stuff in a better way
// PIJ: I guess the structure handler should be created by the renderer.
if (rendererType == RENDER_MIF) {
- foInputHandler = new MIFHandler(userAgent, stream);
+ foInputHandler = new MIFHandler(foUserAgent, stream);
} else if (rendererType == RENDER_RTF) {
- foInputHandler = new RTFHandler(userAgent, stream);
+ foInputHandler = new RTFHandler(foUserAgent, stream);
} else {
- if (renderer == null) {
+ if (rendererType == NOT_SET) {
throw new IllegalStateException(
- "Renderer not set when using standard foInputHandler");
+ "Renderer must be set using setRenderer(int renderType)");
}
- foInputHandler = new FOTreeHandler(userAgent, renderer, stream, true);
+ foInputHandler = new FOTreeHandler(foUserAgent, rendererType,
+ stream, true);
}
treeBuilder.setFOInputHandler(foInputHandler);
@@ -369,7 +328,7 @@ public class Driver implements Constants {
public synchronized void render(InputHandler inputHandler)
throws FOPException {
XMLReader parser = inputHandler.getParser();
- userAgent.setBaseURL(inputHandler.getBaseURL());
+ foUserAgent.setBaseURL(inputHandler.getBaseURL());
render(parser, inputHandler.getInputSource());
}
@@ -431,7 +390,6 @@ public class Driver implements Constants {
/**
* Runs the formatting and renderering process using the previously set
* parser, input source, renderer and output stream.
- * If the renderer was not set, default to PDF.
* If no parser was set, and the input source is not a dom document,
* get a default SAX parser.
* @throws IOException in case of IO errors.
@@ -442,9 +400,8 @@ public class Driver implements Constants {
initialize();
}
- if (renderer == null && rendererType != RENDER_RTF
- && rendererType != RENDER_MIF) {
- setRenderer(RENDER_PDF);
+ if (rendererType == NOT_SET) {
+ rendererType = RENDER_PDF;
}
if (source == null) {
diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java
index 45ca4f77f..f135c5219 100644
--- a/src/java/org/apache/fop/apps/FOUserAgent.java
+++ b/src/java/org/apache/fop/apps/FOUserAgent.java
@@ -27,6 +27,7 @@ import java.io.InputStream;
// FOP
import org.apache.fop.pdf.PDFEncryptionParams;
+import org.apache.fop.render.Renderer;
/**
* The User Agent for fo.
@@ -59,7 +60,7 @@ public class FOUserAgent {
private float px2mm = 0.35277777777777777778f; //72dpi (=25.4/dpi)
private HashMap rendererOptions = new java.util.HashMap();
private InputHandler inputHandler = null;
-
+ private Renderer rendererOverride = null;
/** Producer: Metadata element for the system/software that produces
* the document. (Some renderers can store this in the document.)
@@ -97,6 +98,22 @@ public class FOUserAgent {
* Sets the producer of the document.
* @param producer source of document
*/
+ public void setRendererOverride(Renderer renderer) {
+ this.rendererOverride = renderer;
+ }
+
+ /**
+ * Returns the producer of the document
+ * @return producer name
+ */
+ public Renderer getRendererOverride() {
+ return rendererOverride;
+ }
+
+ /**
+ * Sets the producer of the document.
+ * @param producer source of document
+ */
public void setProducer(String producer) {
this.producer = producer;
}
diff --git a/src/java/org/apache/fop/fo/Constants.java b/src/java/org/apache/fop/fo/Constants.java
index 3e9bd22ef..e8915b4eb 100644
--- a/src/java/org/apache/fop/fo/Constants.java
+++ b/src/java/org/apache/fop/fo/Constants.java
@@ -25,6 +25,9 @@ public interface Constants {
apps.Driver to describe the input (either .FO or .XML/.XSL)
and desired output (PDF, PS, AWT, etc.) of the document */
+ /** render constants for bounds checking */
+ int RENDER_MIN_CONST = 1;
+ int RENDER_MAX_CONST = 10;
/** input / output not set */
int NOT_SET = 0;
/** input: fo file */
diff --git a/src/java/org/apache/fop/fo/FOInputHandler.java b/src/java/org/apache/fop/fo/FOInputHandler.java
index 270b9a327..1f3e81b34 100644
--- a/src/java/org/apache/fop/fo/FOInputHandler.java
+++ b/src/java/org/apache/fop/fo/FOInputHandler.java
@@ -66,7 +66,7 @@ public abstract class FOInputHandler {
/**
* The FOUserAgent for this process
*/
- private FOUserAgent foUserAgent;
+ protected FOUserAgent foUserAgent;
/**
* The Font information relevant for this document
diff --git a/src/java/org/apache/fop/fo/FOTreeHandler.java b/src/java/org/apache/fop/fo/FOTreeHandler.java
index bc1deccd9..8de48be23 100644
--- a/src/java/org/apache/fop/fo/FOTreeHandler.java
+++ b/src/java/org/apache/fop/fo/FOTreeHandler.java
@@ -115,10 +115,17 @@ public class FOTreeHandler extends FOInputHandler {
* @param store if true then use the store pages model and keep the
* area tree in memory
*/
- public FOTreeHandler(FOUserAgent userAgent, Renderer renderer,
+ public FOTreeHandler(FOUserAgent userAgent, int renderType,
OutputStream stream, boolean store) throws FOPException {
super(userAgent);
- this.renderer = renderer;
+
+ if (foUserAgent.getRendererOverride() != null) {
+ renderer = foUserAgent.getRendererOverride();
+ } else {
+ renderer = createRenderer(renderType);
+ renderer.setUserAgent(foUserAgent);
+ }
+
areaTree = new AreaTree(renderer);
try {
@@ -139,6 +146,37 @@ public class FOTreeHandler extends FOInputHandler {
}
/**
+ * Creates a Renderer object based on render-type desired
+ * @param renderType the type of renderer to use
+ * @return Renderer the new Renderer instance
+ * @throws IllegalArgumentException if an unsupported renderer type was requested
+ */
+ private Renderer createRenderer(int renderType) throws IllegalArgumentException {
+
+ switch (renderType) {
+ case Constants.RENDER_PDF:
+ return new org.apache.fop.render.pdf.PDFRenderer();
+ case Constants.RENDER_AWT:
+ return new org.apache.fop.render.awt.AWTRenderer();
+ case Constants.RENDER_PRINT:
+ return new org.apache.fop.render.awt.AWTPrintRenderer();
+ case Constants.RENDER_PCL:
+ return new org.apache.fop.render.pcl.PCLRenderer();
+ case Constants.RENDER_PS:
+ return new org.apache.fop.render.ps.PSRenderer();
+ case Constants.RENDER_TXT:
+ return new org.apache.fop.render.txt.TXTRenderer();
+ case Constants.RENDER_XML:
+ return new org.apache.fop.render.xml.XMLRenderer();
+ case Constants.RENDER_SVG:
+ return new org.apache.fop.render.svg.SVGRenderer();
+ default:
+ throw new IllegalArgumentException("Invalid renderer type "
+ + renderType);
+ }
+ }
+
+ /**
* Start the document.
* This starts the document in the renderer.
*
diff --git a/src/java/org/apache/fop/fo/pagination/Flow.java b/src/java/org/apache/fop/fo/pagination/Flow.java
index d7cc88cf3..00b5ff7c9 100644
--- a/src/java/org/apache/fop/fo/pagination/Flow.java
+++ b/src/java/org/apache/fop/fo/pagination/Flow.java
@@ -65,13 +65,15 @@ public class Flow extends FObj {
/**
* @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
- * XSL/FOP Content Model: (%block;)+
+ * XSL/FOP Content Model: markers* (%block;)+
*/
- protected void validateChildNode(Locator loc, String nsURI, String localName) {
+/* temporarily disabled: need to account for fo-markers which may be initial children
+ protected void validateChildNode(Locator loc, String nsURI, String localName) {
if (!isBlockItem(nsURI, localName)) {
invalidChildError(loc, nsURI, localName);
}
}
+*/
/**
* Make sure content model satisfied, if so then tell the
diff --git a/src/java/org/apache/fop/render/awt/AWTRenderer.java b/src/java/org/apache/fop/render/awt/AWTRenderer.java
index 5b174646c..57b94ea0a 100644
--- a/src/java/org/apache/fop/render/awt/AWTRenderer.java
+++ b/src/java/org/apache/fop/render/awt/AWTRenderer.java
@@ -106,6 +106,10 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable
createPreviewDialog(foUserAgent.getInputHandler());
}
+ public FOUserAgent getUserAgent() {
+ return userAgent;
+ }
+
/**
* @see org.apache.fop.render.Renderer
*/