*/
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
*
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 {
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 = "";
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) {
} 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
this.store(role, key, map);
}
status = OUT;
- role = Configuration.STANDARD;
+ role = "standard";
} else if (localName.equals("subentry")) {
map.put(subkey, value);
status -= IN_SUBENTRY;
}
}
- 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
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.");
+ }
}
+
}