aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java20
-rw-r--r--examples/plan/src/org/apache/fop/plan/PlanElementMapping.java20
-rw-r--r--src/java/org/apache/fop/extensions/ExtensionElementMapping.java26
-rw-r--r--src/java/org/apache/fop/fo/ElementMapping.java40
-rw-r--r--src/java/org/apache/fop/fo/FOElementMapping.java18
-rw-r--r--src/java/org/apache/fop/fo/FOTreeBuilder.java14
-rw-r--r--src/java/org/apache/fop/svg/SVGElementMapping.java38
7 files changed, 73 insertions, 103 deletions
diff --git a/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java b/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java
index c80a0c33c..9c48520eb 100644
--- a/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java
+++ b/examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java
@@ -50,7 +50,6 @@
*/
package org.apache.fop.mathml;
-import org.apache.fop.fo.FOTreeBuilder;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.image.analyser.XMLReader;
@@ -65,14 +64,13 @@ import net.sourceforge.jeuclid.DOMMathBuilder;
/**
* This class provides the element mapping for FOP.
*/
-public class MathMLElementMapping implements ElementMapping {
+public class MathMLElementMapping extends ElementMapping {
- /** MathML namespace */
- public static final String URI = "http://www.w3.org/1998/Math/MathML";
-
- private static HashMap foObjs = null;
+ public MathMLElementMapping() {
+ URI = "http://www.w3.org/1998/Math/MathML";
+ }
- private static synchronized void setupMathML() {
+ protected void initialize() {
if (foObjs == null) {
foObjs = new HashMap();
foObjs.put("math", new ME());
@@ -82,14 +80,6 @@ public class MathMLElementMapping implements ElementMapping {
}
}
- /**
- * @see org.apache.fop.fo.ElementMapping#addToBuilder(FOTreeBuilder)
- */
- public void addToBuilder(FOTreeBuilder builder) {
- setupMathML();
- builder.addMapping(URI, foObjs);
- }
-
static class MathMLMaker extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new MathMLObj(parent);
diff --git a/examples/plan/src/org/apache/fop/plan/PlanElementMapping.java b/examples/plan/src/org/apache/fop/plan/PlanElementMapping.java
index 7a1fecb19..724871edd 100644
--- a/examples/plan/src/org/apache/fop/plan/PlanElementMapping.java
+++ b/examples/plan/src/org/apache/fop/plan/PlanElementMapping.java
@@ -50,7 +50,6 @@
*/
package org.apache.fop.plan;
-import org.apache.fop.fo.FOTreeBuilder;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.image.analyser.XMLReader;
@@ -62,14 +61,13 @@ import java.util.HashMap;
/**
* This class provides the element mapping for FOP.
*/
-public class PlanElementMapping implements ElementMapping {
+public class PlanElementMapping extends ElementMapping {
- /** The namespace for the plan extension */
- public static final String URI = "http://xml.apache.org/fop/plan";
-
- private static HashMap foObjs = null;
+ public PlanElementMapping() {
+ URI = "http://xml.apache.org/fop/plan";
+ }
- private static synchronized void setupPlan() {
+ protected void initialize() {
if (foObjs == null) {
foObjs = new java.util.HashMap();
foObjs.put("plan", new PE());
@@ -79,14 +77,6 @@ public class PlanElementMapping implements ElementMapping {
}
}
- /**
- * @see org.apache.fop.fo.ElementMapping#addToBuilder(FOTreeBuilder)
- */
- public void addToBuilder(FOTreeBuilder builder) {
- setupPlan();
- builder.addMapping(URI, foObjs);
- }
-
static class PlanMaker extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new PlanObj(parent);
diff --git a/src/java/org/apache/fop/extensions/ExtensionElementMapping.java b/src/java/org/apache/fop/extensions/ExtensionElementMapping.java
index 283bc6e68..b95a54ba7 100644
--- a/src/java/org/apache/fop/extensions/ExtensionElementMapping.java
+++ b/src/java/org/apache/fop/extensions/ExtensionElementMapping.java
@@ -52,7 +52,6 @@ package org.apache.fop.extensions;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.ElementMapping;
-import org.apache.fop.fo.FOTreeBuilder;
import java.util.HashMap;
@@ -61,16 +60,13 @@ import java.util.HashMap;
* This sets up the mapping for the classes that handle the
* pdf bookmark extension.
*/
-public class ExtensionElementMapping implements ElementMapping {
- /**
- * The pdf bookmark extension uri
- */
- public static final String URI = "http://xml.apache.org/fop/extensions";
+public class ExtensionElementMapping extends ElementMapping {
- // the mappings are only setup once and resued after that
- private static HashMap foObjs = null;
+ public ExtensionElementMapping() {
+ URI = "http://xml.apache.org/fop/extensions";
+ }
- private static synchronized void setupExt() {
+ protected void initialize() {
if (foObjs == null) {
foObjs = new HashMap();
foObjs.put("bookmarks", new B());
@@ -79,18 +75,6 @@ public class ExtensionElementMapping implements ElementMapping {
}
}
- /**
- * Add the mappings to the fo tree builder.
- *
- * @param builder the fo tree builder to add the mappings
- */
- public void addToBuilder(FOTreeBuilder builder) {
- if (foObjs == null) {
- setupExt();
- }
- builder.addMapping(URI, foObjs);
- }
-
static class B extends ElementMapping.Maker {
public FONode make(FONode parent) {
return new Bookmarks(parent);
diff --git a/src/java/org/apache/fop/fo/ElementMapping.java b/src/java/org/apache/fop/fo/ElementMapping.java
index 331ca2a85..c81187719 100644
--- a/src/java/org/apache/fop/fo/ElementMapping.java
+++ b/src/java/org/apache/fop/fo/ElementMapping.java
@@ -50,14 +50,48 @@
*/
package org.apache.fop.fo;
+import java.util.HashMap;
+
/**
* Interface for adding supported element and property mappings to
* the given builder.
*/
-public interface ElementMapping {
- final String DEFAULT = "<default>";
+/** Abstract base class of FO Element Mappings. */
+public abstract class ElementMapping {
+ public static final String DEFAULT = "<default>";
+
+ /** The HashMap table of formatting objects defined by the ElementMapping */
+ protected HashMap foObjs = null;
+
+ /** The namespace for the ElementMapping */
+ protected String URI = null;
+
+ /**
+ * Returns a HashMap of maker objects for this element mapping
+ *
+ * @return Table of Maker objects for this ElementMapping
+ */
+ public HashMap getTable() {
+ if (foObjs == null) {
+ initialize();
+ }
+ return foObjs;
+ }
+
+ /**
+ * Returns the namespace URI for this element mapping
+ *
+ * @return Namespace URI for this element mapping
+ */
+ public String getNamespaceURI() {
+ return URI;
+ }
- void addToBuilder(FOTreeBuilder builder);
+ /**
+ * Initializes the set of maker objects associated with this ElementMapping
+ *
+ */
+ protected abstract void initialize();
public static class Maker {
public FONode make(FONode parent) {
diff --git a/src/java/org/apache/fop/fo/FOElementMapping.java b/src/java/org/apache/fop/fo/FOElementMapping.java
index f9db7f51c..4dce2889a 100644
--- a/src/java/org/apache/fop/fo/FOElementMapping.java
+++ b/src/java/org/apache/fop/fo/FOElementMapping.java
@@ -56,11 +56,13 @@ import java.util.HashMap;
/**
* Element mapping class for all XSL-FO elements.
*/
-public class FOElementMapping implements ElementMapping {
+public class FOElementMapping extends ElementMapping {
- private static HashMap foObjs = null;
+ public FOElementMapping() {
+ URI = "http://www.w3.org/1999/XSL/Format";
+ }
- private static synchronized void setupFO() {
+ protected void initialize() {
if (foObjs == null) {
foObjs = new HashMap();
@@ -148,16 +150,6 @@ public class FOElementMapping implements ElementMapping {
foObjs.put("marker", new M());
foObjs.put("retrieve-marker", new RM());
}
-
- }
-
- /**
- * @see org.apache.fop.fo.ElementMapping#addToBuilder(FOTreeBuilder)
- */
- public void addToBuilder(FOTreeBuilder builder) {
- setupFO();
- String uri = "http://www.w3.org/1999/XSL/Format";
- builder.addMapping(uri, foObjs);
}
static class R extends ElementMapping.Maker {
diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java
index 78a5a9973..546efe0ad 100644
--- a/src/java/org/apache/fop/fo/FOTreeBuilder.java
+++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java
@@ -172,24 +172,14 @@ public class FOTreeBuilder extends DefaultHandler {
}
/**
- * Adds a mapping from a namespace to a table of makers.
- *
- * @param namespaceURI namespace URI of formatting object elements
- * @param table table of makers
- */
- public void addMapping(String namespaceURI, HashMap table) {
- this.fobjTable.put(namespaceURI, table);
- this.namespaces.add(namespaceURI.intern());
- }
-
- /**
* 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) {
- mapping.addToBuilder(this);
+ this.fobjTable.put(mapping.getNamespaceURI(), mapping.getTable());
+ this.namespaces.add(mapping.getNamespaceURI().intern());
}
/**
diff --git a/src/java/org/apache/fop/svg/SVGElementMapping.java b/src/java/org/apache/fop/svg/SVGElementMapping.java
index dd6296cd5..36135c17d 100644
--- a/src/java/org/apache/fop/svg/SVGElementMapping.java
+++ b/src/java/org/apache/fop/svg/SVGElementMapping.java
@@ -53,7 +53,6 @@ package org.apache.fop.svg;
import java.util.HashMap;
import org.apache.fop.fo.FONode;
-import org.apache.fop.fo.FOTreeBuilder;
import org.apache.fop.fo.ElementMapping;
import org.apache.fop.apps.Driver;
@@ -65,34 +64,25 @@ import org.apache.batik.dom.svg.SVGDOMImplementation;
* This adds the svg element mappings used to create the objects
* that create the SVG Document.
*/
-public class SVGElementMapping implements ElementMapping {
- private static HashMap foObjs = null;
- private static boolean batik = true;
+public class SVGElementMapping extends ElementMapping {
+ private boolean batik = true;
- private static synchronized void setupSVG() {
- if (foObjs == null) {
+ public SVGElementMapping() {
+ URI = SVGDOMImplementation.SVG_NAMESPACE_URI;
+ }
+
+ protected void initialize() {
+ if (foObjs == null && batik == true) {
// this sets the parser that will be used
// by default (SVGBrokenLinkProvider)
// normally the user agent value is used
- XMLResourceDescriptor.setXMLParserClassName(
- Driver.getParserClassName());
-
- foObjs = new HashMap();
- foObjs.put("svg", new SE());
- foObjs.put(DEFAULT, new SVGMaker());
- }
- }
-
- /**
- * Add the SVG element mappings to the tree builder.
- * @param builder the FOTreeBuilder to add the mappings to
- */
- public void addToBuilder(FOTreeBuilder builder) {
- if (batik) {
try {
- setupSVG();
- String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
- builder.addMapping(svgNS, foObjs);
+ XMLResourceDescriptor.setXMLParserClassName(
+ Driver.getParserClassName());
+
+ foObjs = new HashMap();
+ foObjs.put("svg", new SE());
+ foObjs.put(DEFAULT, new SVGMaker());
} catch (Throwable t) {
// if the classes are not available
// the DISPLAY is not checked