diff options
author | fotis <fotis@unknown> | 2000-12-17 22:18:12 +0000 |
---|---|---|
committer | fotis <fotis@unknown> | 2000-12-17 22:18:12 +0000 |
commit | 7a8a17ca8876d9b9b76131bc34ea10bac6c9346d (patch) | |
tree | 838b07cc51c4200ca98f13621491fa5e07fb8933 | |
parent | 25173107e9a271228a956ce70af9674d5f0c72ee (diff) | |
download | xmlgraphics-fop-7a8a17ca8876d9b9b76131bc34ea10bac6c9346d.tar.gz xmlgraphics-fop-7a8a17ca8876d9b9b76131bc34ea10bac6c9346d.zip |
improvement (?): decoupling Configuration and ConfigurationParser
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193887 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 52 insertions, 61 deletions
diff --git a/src/org/apache/fop/configuration/Configuration.java b/src/org/apache/fop/configuration/Configuration.java index 1bad17965..49bf5c4a8 100644 --- a/src/org/apache/fop/configuration/Configuration.java +++ b/src/org/apache/fop/configuration/Configuration.java @@ -15,16 +15,30 @@ import org.apache.fop.messaging.MessageHandler; */ public class Configuration { - /** stores the configuration information */ - private static Hashtable standardConfiguration; - private static Hashtable pdfConfiguration; - private static Hashtable awtConfiguration; - /** defines role types */ public final static int STANDARD = 0; public final static int PDF = 1; public final static int AWT = 2; + /** stores the configuration information */ + private static Hashtable standardConfiguration = new Hashtable(30);; + private static Hashtable pdfConfiguration = new Hashtable(20); + private static Hashtable awtConfiguration = new Hashtable(20); + + /** contains a Hashtable of existing Hashtables */ + private static Hashtable configuration = new Hashtable(3); + + /** loads the configuration types into the configuration Hashtable */ + static { + configuration.put("standard",standardConfiguration); + configuration.put("pdf",pdfConfiguration); + configuration.put("awt",awtConfiguration); + } + + public static Hashtable getConfiguration() { + return configuration; + } + /** * general access method * diff --git a/src/org/apache/fop/configuration/ConfigurationParser.java b/src/org/apache/fop/configuration/ConfigurationParser.java index e6f6ffd9c..df59ca40f 100644 --- a/src/org/apache/fop/configuration/ConfigurationParser.java +++ b/src/org/apache/fop/configuration/ConfigurationParser.java @@ -60,8 +60,8 @@ import java.util.Vector; import org.apache.fop.messaging.MessageHandler; /** - * SAX2 Handler which parses the events and stores them in a Configuration. - * Normally this class must not accessed directly. + * SAX2 Handler which retrieves the configuration information and stores them in Configuration. + * Normally this class doesn't need to be accessed directly. */ public class ConfigurationParser extends DefaultHandler { @@ -82,9 +82,8 @@ public class ConfigurationParser extends DefaultHandler { private int datatype = -1; //store the result configuration - private static Hashtable standardConfiguration = new Hashtable(30); - private static Hashtable pdfConfiguration = new Hashtable(20); - private static Hashtable awtConfiguration = new Hashtable(20); + private static Hashtable configuration; + private static Hashtable activeConfiguration; //stores key for new config entry private String key = ""; @@ -105,7 +104,11 @@ public class ConfigurationParser extends DefaultHandler { private Locator locator; /** determines role / target of configuration information, default is standard */ - private int role = Configuration.STANDARD; + private String role = "standard"; + + public void startDocument() { + configuration = Configuration.getConfiguration(); + } /** get locator for position information */ public void setDocumentLocator(Locator locator) { @@ -126,22 +129,13 @@ public class ConfigurationParser extends DefaultHandler { } else if (localName.equals("subentry")) { status += IN_SUBENTRY; } else if (localName.equals("entry")) { + //role=standard as default if (attributes.getLength() == 0) { - role = Configuration.STANDARD; + role = "standard"; + //retrieve attribute value for "role" which determines configuration target } else { - //retrieve attribute value for "role" which determines configuration target - String rolen = attributes.getValue("role"); - if (rolen.equalsIgnoreCase("pdf")) { - role = Configuration.PDF; - } else if (rolen.equalsIgnoreCase("awt")) { - role = Configuration.AWT; - } else if (rolen.equalsIgnoreCase("standard")) { - role = Configuration.STANDARD; - } else { - MessageHandler.errorln("unknown role: " + rolen + ". Using standard."); - } + role = attributes.getValue("role"); } - //role=standard as default } else if (localName.equals("configuration") ) { } else { //to make sure that user knows about false tag @@ -166,7 +160,7 @@ public class ConfigurationParser extends DefaultHandler { this.store(role, key, map); } status = OUT; - role = Configuration.STANDARD; + role = "standard"; } else if (localName.equals("subentry")) { map.put(subkey, value); status -= IN_SUBENTRY; @@ -179,23 +173,6 @@ public class ConfigurationParser extends DefaultHandler { } } - private void store (int role, String key, Object value) { - switch (role) { - case Configuration.STANDARD: - standardConfiguration.put(key,value); - break; - case Configuration.PDF: - pdfConfiguration.put(key,value); - break; - case Configuration.AWT: - awtConfiguration.put(key,value); - break; - default: - MessageHandler.errorln("Unknown role for new configuration entry. " - +"Putting key:" + key + " - value:" + value +" into standard configuration."); - } - } - /** * extracts characters from text nodes and puts them into their respective * variables @@ -224,25 +201,25 @@ public class ConfigurationParser extends DefaultHandler { datatype = MAP; break; } - } //end characters + /** - * returns the parsed configuration information - * @return Hashtable containing the configuration information as key/value pairs - */ - public Hashtable getConfiguration(int role) { - switch (role) { - case Configuration.STANDARD: - return standardConfiguration; - case Configuration.PDF: - return pdfConfiguration; - case Configuration.AWT: - return awtConfiguration; - default: - MessageHandler.errorln("Can't return asked for configuration. Unknown role " ); - return null; - } + * stores configuration entry into configuration hashtable according to the role + * + * @param role a string containing the role / target for this configuration information + * @param key a string containing the key value for the configuration + * @param value a string containing the value for the configuration + */ + private void store (String role, String key, Object value) { + activeConfiguration = (Hashtable) configuration.get(role); + if (activeConfiguration != null) { + activeConfiguration.put(key,value); + } else { + MessageHandler.errorln("Unknown role >" + role + "< for new configuration entry. \n" + +"Putting configuration with key:" + key + " into standard configuration."); + } } + } diff --git a/src/org/apache/fop/configuration/ConfigurationReader.java b/src/org/apache/fop/configuration/ConfigurationReader.java index d012d3d80..ba5f7a3b4 100644 --- a/src/org/apache/fop/configuration/ConfigurationReader.java +++ b/src/org/apache/fop/configuration/ConfigurationReader.java @@ -122,9 +122,9 @@ public class ConfigurationReader { try { parser.parse(filename); - Configuration.setup(Configuration.STANDARD, configurationParser.getConfiguration(Configuration.STANDARD)); - Configuration.setup(Configuration.PDF, configurationParser.getConfiguration(Configuration.PDF)); - Configuration.setup(Configuration.AWT, configurationParser.getConfiguration(Configuration.AWT)); +// Configuration.setup(Configuration.STANDARD, configurationParser.getConfiguration(Configuration.STANDARD)); +// Configuration.setup(Configuration.PDF, configurationParser.getConfiguration(Configuration.PDF)); +// Configuration.setup(Configuration.AWT, configurationParser.getConfiguration(Configuration.AWT)); } catch (SAXException e) { if (e.getException() instanceof FOPException) { dumpError(e.getException()); |