gmazza 2004/07/15 22:10:32
Modified: src/java/org/apache/fop/apps Driver.java FOUserAgent.java
src/java/org/apache/fop/fo FOTreeBuilder.java
Log:
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.)
Revision Changes Path
1.86 +4 -62 xml-fop/src/java/org/apache/fop/apps/Driver.java
Index: Driver.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Driver.java,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -r1.85 -r1.86
--- Driver.java 14 Jul 2004 23:05:44 -0000 1.85
+++ Driver.java 16 Jul 2004 05:10:32 -0000 1.86
@@ -30,7 +30,6 @@
// 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 @@
* 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 @@
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 @@
* Main constructor for the Driver class.
*/
public Driver() {
+ foUserAgent = new FOUserAgent();
stream = null;
}
@@ -113,23 +104,6 @@
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 synchronized void reset() {
stream = null;
- if (treeBuilder != null) {
- treeBuilder.reset();
- }
}
/**
@@ -148,10 +119,6 @@
* @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 @@
* @return the user agent
*/
public FOUserAgent getUserAgent() {
- if (foUserAgent == null) {
- foUserAgent = new FOUserAgent();
- }
return foUserAgent;
}
@@ -209,24 +173,6 @@
}
/**
- * 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 @@
* @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);
}
/**
1.15 +24 -1 xml-fop/src/java/org/apache/fop/apps/FOUserAgent.java
Index: FOUserAgent.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/FOUserAgent.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- FOUserAgent.java 9 Jul 2004 20:06:30 -0000 1.14
+++ FOUserAgent.java 16 Jul 2004 05:10:32 -0000 1.15
@@ -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 @@
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.)
*/
@@ -103,6 +107,25 @@
*/
public InputHandler getInputHandler() {
return inputHandler;
+ }
+
+ /**
+ * 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;
}
/**
1.37 +24 -21 xml-fop/src/java/org/apache/fop/fo/FOTreeBuilder.java
Index: FOTreeBuilder.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOTreeBuilder.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- FOTreeBuilder.java 13 Jul 2004 05:25:26 -0000 1.36
+++ FOTreeBuilder.java 16 Jul 2004 05:10:32 -0000 1.37
@@ -24,6 +24,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
@@ -88,17 +89,12 @@
private Locator locator;
/**
- * Default constructor
+ * FOTreeBuilder constructor
+ * @param render type as defined in Constants class
+ * @param foUserAgent in effect for this process
+ * @param stream OutputStream to direct results
*/
- public FOTreeBuilder() {
- setupDefaultMappings();
- }
-
- /**
- * Creates the FOInputHandler object based on passed-in render type
- * @param render type
- */
- public void initialize(int renderType, FOUserAgent foUserAgent,
+ public FOTreeBuilder(int renderType, FOUserAgent foUserAgent,
OutputStream stream) throws FOPException {
if (renderType == Constants.RENDER_MIF) {
foInputHandler = new MIFHandler(foUserAgent, stream);
@@ -113,6 +109,18 @@
foInputHandler = new AreaTreeHandler(foUserAgent, renderType,
stream);
}
+
+ // Add standard element mappings
+ setupDefaultMappings();
+
+ // add additional ElementMappings defined within FOUserAgent
+ ArrayList addlEMs = foUserAgent.getAdditionalElementMappings();
+
+ if (addlEMs != null) {
+ for (int i = 0; i < addlEMs.size(); i++) {
+ addElementMapping((String) addlEMs.get(i));
+ }
+ }
}
/**
@@ -142,23 +150,13 @@
}
/**
- * 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) {
- this.fobjTable.put(mapping.getNamespaceURI(), mapping.getTable());
- this.namespaces.add(mapping.getNamespaceURI().intern());
- }
-
- /**
* Add the element mapping with the given class name.
* @param mappingClassName the class name representing the element mapping.
* @throws IllegalArgumentException if there was not such element mapping.
*/
public void addElementMapping(String mappingClassName)
throws IllegalArgumentException {
+
try {
ElementMapping mapping =
(ElementMapping)Class.forName(mappingClassName).newInstance();
@@ -176,6 +174,11 @@
throw new IllegalArgumentException(mappingClassName
+ " is not an ElementMapping");
}
+ }
+
+ private void addElementMapping(ElementMapping mapping) {
+ this.fobjTable.put(mapping.getNamespaceURI(), mapping.getTable());
+ this.namespaces.add(mapping.getNamespaceURI().intern());
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]