diff options
author | Glen Mazza <gmazza@apache.org> | 2004-07-16 05:10:32 +0000 |
---|---|---|
committer | Glen Mazza <gmazza@apache.org> | 2004-07-16 05:10:32 +0000 |
commit | 4cd2247565deba8992baa983ba5622620fa6bb5e (patch) | |
tree | f532f1b3f662df43ac7674d5857dbfc83f6cd194 /src/java/org/apache/fop/apps | |
parent | 03a30e10172c62743876bc3bb6546c8e0a0ca4d2 (diff) | |
download | xmlgraphics-fop-4cd2247565deba8992baa983ba5622620fa6bb5e.tar.gz xmlgraphics-fop-4cd2247565deba8992baa983ba5622620fa6bb5e.zip |
Moved user-defined ElementMapping initialization from Driver to FOUserAgent.
Moved only "string" method, the version we use internally--probably sufficient
for others' work as well. (Note: an additional unused FOUserAgent object will
be created in driver during command-line use--cp. its no-param constructor vs.
setUserAgent() call in apps.Fop; this will need to be ironed out at some time.)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197794 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/apps')
-rw-r--r-- | src/java/org/apache/fop/apps/Driver.java | 64 | ||||
-rw-r--r-- | src/java/org/apache/fop/apps/FOUserAgent.java | 23 |
2 files changed, 26 insertions, 61 deletions
diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index 8dd1a4652..41ae90469 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -30,7 +30,6 @@ import org.xml.sax.XMLReader; // FOP import org.apache.fop.fo.Constants; -import org.apache.fop.fo.ElementMapping; import org.apache.fop.fo.FOTreeBuilder; import org.apache.fop.render.awt.AWTRenderer; @@ -47,11 +46,7 @@ import org.apache.fop.render.awt.AWTRenderer; * 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 - * 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 ElementMapping(s). + * rendering (where applicable). * <P> * Once the Driver is set up, the render method * is called. The invocation of the method is @@ -68,11 +63,6 @@ import org.apache.fop.render.awt.AWTRenderer; public class Driver implements Constants { /** - * the FO tree builder - */ - private FOTreeBuilder treeBuilder; - - /** * the render type code given by setRender */ private int renderType = NOT_SET; @@ -91,6 +81,7 @@ public class Driver implements Constants { * Main constructor for the Driver class. */ public Driver() { + foUserAgent = new FOUserAgent(); stream = null; } @@ -113,23 +104,6 @@ public class Driver implements Constants { this.stream = stream; } - private boolean isInitialized() { - return (treeBuilder != null); - } - - /** - * Initializes the Driver object. - */ - private void initialize() { - if (isInitialized()) { - throw new IllegalStateException("Driver already initialized"); - } - treeBuilder = new FOTreeBuilder(); - if (foUserAgent == null) { - foUserAgent = new FOUserAgent(); - } - } - /** * Resets the Driver so it can be reused. Property and element * mappings are reset to defaults. @@ -137,9 +111,6 @@ public class Driver implements Constants { */ public synchronized void reset() { stream = null; - if (treeBuilder != null) { - treeBuilder.reset(); - } } /** @@ -148,10 +119,6 @@ public class Driver implements Constants { * @param agent FOUserAgent to use */ public void setUserAgent(FOUserAgent agent) throws FOPException { - if (foUserAgent != null) { - throw new IllegalStateException("FOUserAgent " + - "instance already set."); - } foUserAgent = agent; } @@ -160,9 +127,6 @@ public class Driver implements Constants { * @return the user agent */ public FOUserAgent getUserAgent() { - if (foUserAgent == null) { - foUserAgent = new FOUserAgent(); - } return foUserAgent; } @@ -209,24 +173,6 @@ public class Driver implements Constants { } /** - * Add the given element mapping. - * An element mapping maps element names to Java classes. - * - * @param mapping the element mappingto add - */ - public void addElementMapping(ElementMapping mapping) { - treeBuilder.addElementMapping(mapping); - } - - /** - * Add the element mapping with the given class name. - * @param mappingClassName the class name representing the element mapping. - */ - public void addElementMapping(String mappingClassName) { - treeBuilder.addElementMapping(mappingClassName); - } - - /** * Determines which SAX ContentHandler is appropriate for the renderType. * Structure renderers (e.g. MIF & RTF) each have a specialized * ContentHandler that directly place data into the output stream. Layout @@ -236,16 +182,12 @@ public class Driver implements Constants { * @throws FOPException if setting up the ContentHandler fails */ public ContentHandler getContentHandler() throws FOPException { - if (!isInitialized()) { - initialize(); - } if (renderType != RENDER_PRINT && renderType != RENDER_AWT) { validateOutputStream(); } - treeBuilder.initialize(renderType, foUserAgent, stream); - return treeBuilder; + return new FOTreeBuilder(renderType, foUserAgent, stream); } /** diff --git a/src/java/org/apache/fop/apps/FOUserAgent.java b/src/java/org/apache/fop/apps/FOUserAgent.java index e7679259e..c1ae3d3af 100644 --- a/src/java/org/apache/fop/apps/FOUserAgent.java +++ b/src/java/org/apache/fop/apps/FOUserAgent.java @@ -19,6 +19,7 @@ package org.apache.fop.apps; // Java +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -73,6 +74,9 @@ public class FOUserAgent { private Configuration userConfig = null; private Log log = LogFactory.getLog("FOP"); + /* Additional fo.ElementMapping subclasses set by user */ + private ArrayList additionalElementMappings = null; + /** Producer: Metadata element for the system/software that produces * the document. (Some renderers can store this in the document.) */ @@ -106,6 +110,25 @@ public class FOUserAgent { } /** + * Add the element mapping with the given class name. + * @param mappingClassName the class name representing the element mapping. + */ + public void addElementMapping(String mappingClassName) { + if (additionalElementMappings == null) { + additionalElementMappings = new ArrayList(); + } + additionalElementMappings.add(mappingClassName); + } + + /** + * Returns the ArrayList of user-added ElementMapping class names + * @return ArrayList of Strings holding ElementMapping names. + */ + public ArrayList getAdditionalElementMappings() { + return additionalElementMappings; + } + + /** * Sets the producer of the document. * @param producer source of document */ |