package org.apache.fop.configuration;
-import java.util.Vector;
-import java.util.Hashtable;
-import java.util.Enumeration;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
import org.apache.fop.messaging.MessageHandler;
/**
* a configuration class for all general configuration aspects except those
- * related to specific renderers. All configuration is stored
- * in key / value pairs. The value can be a String, a list of Strings
- * or a map, containing a list of key / value pairs.
+ * related to specific renderers. All configuration is stored in
+ * key.value pairs. The value can be a String, a Boolean, an Integer,
+ * or a list of Strings or a map, containing a list of key.value pairs.
*
*/
public class Configuration {
/**
* stores the configuration information
*/
- private static Hashtable standardConfiguration = new Hashtable(30);
+ private static HashMap standardConfiguration = new HashMap(30);
;
- private static Hashtable pdfConfiguration = new Hashtable(20);
- private static Hashtable awtConfiguration = new Hashtable(20);
+ private static HashMap pdfConfiguration = new HashMap(20);
+ private static HashMap awtConfiguration = new HashMap(20);
/**
- * contains a Hashtable of existing Hashtables
+ * contains a HashMap of existing HashMaps
*/
- private static Hashtable configuration = new Hashtable(3);
+ private static HashMap configuration = new HashMap(3);
/**
- * loads the configuration types into the configuration Hashtable
+ * loads the configuration types into the configuration HashMap
*/
static {
configuration.put("standard", standardConfiguration);
configuration.put("awt", awtConfiguration);
}
- public static Hashtable getConfiguration() {
+ public static HashMap getConfiguration() {
return configuration;
}
/**
* general access method
*
- * @param key a string containing the key value for the configuration value
- * role detemines the configuration target
+ * @param key a string containing the key for the configuration value
+ * role determines the configuration target
* @return Object containing the value; normally you would use one of the
* convenience methods, which return the correct form.
* null if the key is not defined.
}
}
- ;
/**
* convenience methods to access strings values in the configuration
- * @param key a string containing the key value for the configuration value
- * role detemines the configuration target
+ * @param key a string containing the key for the configuration value
+ * role determines the configuration target
* @return String a string containing the value
* null if the key is not defined.
*/
}
}
- ;
/**
* convenience methods to access int values in the configuration
- * @param key a string containing the key value for the configuration value
- * role detemines the configuration target
+ * @param key a string containing the key for the configuration value
+ * role determines the configuration target
* @return int a int containing the value
* -1 if the key is not defined.
*/
Object obj = Configuration.getValue(key, role);
if (obj instanceof String) {
return Integer.parseInt((String)obj);
+ } else if (obj instanceof Integer) {
+ return ((Integer)obj).intValue();
} else {
return -1;
}
}
- ;
/**
* convenience methods to access boolean values in the configuration
- * @param key a string containing the key value for the configuration value
- * role detemines the configuration target
+ * @param key a string containing the key for the configuration value
+ * role determines the configuration target
* @return Boolean true or false as value
* null if the key is not defined.
*/
}
}
- ;
/**
* convenience methods to access list values in the configuration
- * @param key a string containing the key value for the configuration value
- * role detemines the configuration target
- * @return Vector a Vector containing the values
+ * @param key a string containing the key for the configuration value
+ * role determines the configuration target
+ * @return ArrayList a ArrayList containing the values
* null if the key is not defined.
*/
- public static Vector getListValue(String key, int role) {
+ public static ArrayList getListValue(String key, int role) {
Object obj = Configuration.getValue(key, role);
- if (obj instanceof Vector) {
- return (Vector)obj;
+ if (obj instanceof ArrayList) {
+ return (ArrayList)obj;
} else {
return null;
}
}
- ;
/**
* convenience methods to access map/hashtable values in the configuration
- * @param key a string containing the key value for the configuration value
- * role detemines the configuration target
- * @return Hashtable a Hashtable containing the values
+ * @param key a string containing the key for the configuration value
+ * role determines the configuration target
+ * @return HashMap a HashMap containing the values
* null if the key is not defined.
*/
- public static Hashtable getHashtableValue(String key, int role) {
+ public static HashMap getHashMapValue(String key, int role) {
Object obj = Configuration.getValue(key, role);
- if (obj instanceof Hashtable) {
- return (Hashtable)obj;
+ if (obj instanceof HashMap) {
+ return (HashMap)obj;
} else {
return null;
}
}
- ;
+
+ /**
+ * Convenience method to access values in HashMap entries in the
+ * configuration.
+ * @param map a string containing the key for the configuration value.
+ * <i>N.B.</i> this is the key of the <tt>HashMap</tt> itself.
+ * @param key an object containing the key for an entry in the
+ * <tt>HashMap</tt> indexed by <i>map</i>.
+ * @param role determines the configuration target
+ * @return an <tt>Object</tt> containing the value associated with
+ * <i>key</i>, or <tt>null</tt>
+ * if the map is not defined, the <i>key</i>entry is not defined,
+ * or the <i>key</i>entry is itself <tt>null</tt>.
+ */
+ public static Object getHashMapEntry(String map, Object key, int role) {
+ Object obj = getValue(map, role);
+ if (obj instanceof HashMap) {
+ return ((HashMap)obj).get(key);
+ } else {
+ return null;
+ }
+ }
/**
* convenience method which retrieves some configuration information
* from the standard configuration
*
- * @param key a string containing the key value for the configuration value
+ * @param key a string containing the key for the configuration value
* @return Object containing the value; normally you would use one of the
* convenience methods, which return the correct form.
* null if the key is not defined.
}
/**
- * convenience methods to access strings values in the standard configuration
+ * convenience methods to access strings values in the standard
+ * configuration
*
- * @param key a string containing the key value for the configuration value
+ * @param key a string containing the key for the configuration value
* @return String a string containing the value
* null if the key is not defined.
*/
/**
* convenience methods to access int values in the standard configuration
*
- * @param key a string containing the key value for the configuration value
+ * @param key a string containing the key for the configuration value
* @return int a int containing the value
* -1 if the key is not defined.
*/
/**
* convenience methods to access boolean values in the configuration
*
- * @param key a string containing the key value for the configuration value
+ * @param key a string containing the key for the configuration value
* @return boolean true or false as value
* null if the key is not defined.
*/
/**
* convenience methods to access list values in the standard configuration
*
- * @param key a string containing the key value for the configuration value
- * @return Vector a Vector containing the values
+ * @param key a string containing the key for the configuration value
+ * @return ArrayList a ArrayList containing the values
* null if the key is not defined.
*/
- public static Vector getListValue(String key) {
+ public static ArrayList getListValue(String key) {
return Configuration.getListValue(key, Configuration.STANDARD);
}
/**
- * convenience methods to access map/hashtable values in the standard configuration
+ * convenience methods to access map/hashtable values in the standard
+ * configuration
*
- * @param key a string containing the key value for the configuration value
- * @return Hashtable a Hashtable containing the values
+ * @param key a string containing the key for the configuration value
+ * @return HashMap a HashMap containing the values
* null if the key is not defined.
*/
- public static Hashtable getHashtableValue(String key) {
- return Configuration.getHashtableValue(key, Configuration.STANDARD);
+ public static HashMap getHashMapValue(String key) {
+ return Configuration.getHashMapValue(key, Configuration.STANDARD);
+ }
+
+
+ /**
+ * Convenience method to access values in HashMap entries in the
+ * standard configuration.
+ * @param map a string containing the key for the configuration value.
+ * <i>N.B.</i> this is the key of the <tt>HashMap</tt> itself.
+ * @param key an object containing the key for an entry in the
+ * <tt>HashMap</tt> indexed by <i>map</i>.
+ * @return an <tt>Object</tt> containing the value associated with
+ * <i>key</i>, or <tt>null</tt>
+ * if the map is not defined, the <i>key</i>entry is not defined,
+ * or the <i>key</i>entry is itself <tt>null</tt>.
+ */
+ public static Object getHashMapEntry(String map, Object key) {
+ return Configuration.getHashMapEntry(map, key, STANDARD);
}
/**
* method to access fonts values in the standard configuration
*
- * @param key a string containing the key value for the configuration value
- * @return Hashtable a Hashtable containing the values
+ * @param key a string containing the key for the configuration value
+ * @return HashMap a HashMap containing the values
* null if the key is not defined.
*/
- public static Vector getFonts() {
- return (Vector)Configuration.getValue("fonts",
+ public static ArrayList getFonts() {
+ return (ArrayList)Configuration.getValue("fonts",
Configuration.STANDARD);
}
* initializes this configuration
* @param config contains the configuration information
*/
- public static void setup(int role, Hashtable config) {
+ public static void setup(int role, HashMap config) {
switch (role) {
case Configuration.STANDARD:
standardConfiguration = config;
awtConfiguration = config;
break;
default:
- MessageHandler.errorln("Can't setup configuration. Unknown configuration role/target");
+ MessageHandler.errorln(
+ "Can't setup configuration. Unknown configuration role/target"
+ );
}
}
/**
* adds information to the configuration map/hashtable in key,value form
- * @param key a string containing the key value for the configuration value
+ * @param key a string containing the key for the configuration value
* value the configuration information
- * role detemines the configuration target
- * @param value an Object containing the value; can be a String, a Vector or a Hashtable
+ * role determines the configuration target
+ * @param value an Object containing the value;
+ * can be a String, a Boolean, and Integer, an ArrayList or a HashMap
*/
public static void put(String key, Object value, int role) {
switch (role) {
break;
default:
standardConfiguration.put(key, value);
- MessageHandler.errorln("Unknown role for new configuration entry. "
- + "Putting key:" + key + " - value:"
+ MessageHandler.errorln("Unknown role for new configuration entry."
+ + " Putting key:" + key + " - value:"
+ value + " into standard configuration.");
}
}
- ;
/**
- * adds information to the standard configuration map/hashtable in key,value form
- * @param key a string containing the key value for the configuration value
+ * adds information to the standard configuration hashmap in key.value form
+ * @param key a string containing the key for the configuration value
* value the configuration information
- * role detemines the configuration target
- * @param value an Object containing the value; can be a String, a Vector or a Hashtable
+ * role determines the configuration target
+ * @param value an Object containing the value;
+ * can be a String, a Boolean, an Integer, an ArrayList or a HashMap
*/
public static void put(String key, Object value) {
public static void dumpConfiguration() {
String key;
Object value;
- Vector list;
- Hashtable map, configuration;
- Enumeration enum;
+ ArrayList list;
+ HashMap map, configuration;
+ Iterator iterator;
String tmp;
System.out.println("Dumping configuration: ");
- Hashtable[] configs = {
+ HashMap[] configs = {
standardConfiguration, pdfConfiguration, awtConfiguration
};
for (int i = 0; i < configs.length; i++) {
MessageHandler.logln("----------------------");
configuration = configs[i];
- Enumeration enumeration = configuration.keys();
- while (enumeration.hasMoreElements()) {
- key = (String)enumeration.nextElement();
+ Iterator iter = configuration.keySet().iterator();
+ while (iter.hasNext()) {
+ key = (String)iter.next();
MessageHandler.logln("key: " + key);
value = configuration.get(key);
if (value instanceof String) {
MessageHandler.logln(" value: " + value);
- } else if (value instanceof Vector) {
- list = (Vector)value;
- enum = list.elements();
+ } else if (value instanceof Boolean) {
+ MessageHandler.logln
+ (" value: " + ((Boolean)value).booleanValue());
+ } else if (value instanceof Integer) {
+ MessageHandler.logln
+ (" value: " + ((Integer)value).intValue());
+ } else if (value instanceof ArrayList) {
+ list = (ArrayList)value;
+ iterator = list.iterator();
MessageHandler.log(" values: ");
- while (enum.hasMoreElements()) {
- MessageHandler.log(enum.nextElement() + " - ");
+ while (iterator.hasNext()) {
+ MessageHandler.log(iterator.next() + " - ");
}
MessageHandler.logln("");
- } else if (value instanceof Hashtable) {
- map = (Hashtable)value;
- enum = map.keys();
+ } else if (value instanceof HashMap) {
+ map = (HashMap)value;
+ iterator = map.keySet().iterator();
MessageHandler.log(" values: ");
- while (enum.hasMoreElements()) {
- tmp = (String)enum.nextElement();
+ while (iterator.hasNext()) {
+ tmp = (String)iterator.next();
MessageHandler.log(" " + tmp + ":" + map.get(tmp));
}
MessageHandler.logln("");
}
}
-
-
}