You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by pb...@apache.org on 2004/03/06 06:59:10 UTC

cvs commit: xml-fop/src/java/org/apache/fop/configuration Configuration.java ConfigurationReader.java ConfigurationParser.java

pbwest      2004/03/05 21:59:10

  Modified:    src/java/org/apache/fop/configuration Tag:
                        FOP_0-20-0_Alt-Design Configuration.java
                        ConfigurationReader.java ConfigurationParser.java
  Log:
  Made Configuration instance.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.7   +89 -62    xml-fop/src/java/org/apache/fop/configuration/Attic/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/configuration/Attic/Configuration.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- Configuration.java	19 Feb 2004 03:11:57 -0000	1.1.2.6
  +++ Configuration.java	6 Mar 2004 05:59:10 -0000	1.1.2.7
  @@ -36,7 +36,7 @@
    */
   public class Configuration {
   
  -    protected static final Logger logger = Logger.getLogger(Fop.fopPackage);
  +    protected final Logger logger = Logger.getLogger(Fop.fopPackage);
       /**
        * defines role types
        */
  @@ -47,25 +47,45 @@
       /**
        * stores the configuration information
        */
  -    private static HashMap standardConfiguration = new HashMap(30);
  -    private static HashMap pdfConfiguration = new HashMap(20);
  -    private static HashMap awtConfiguration = new HashMap(20);
  +    private HashMap standardConfiguration = new HashMap();
  +    private HashMap pdfConfiguration = new HashMap();
  +    private HashMap awtConfiguration = new HashMap();
   
       /**
        * contains a HashMap of existing HashMaps
        */
  -    private static HashMap configuration = new HashMap(3);
  -
  -    /**
  -     * loads the configuration types into the configuration HashMap
  -     */
  -    static {
  +    private HashMap configuration = new HashMap(3);
  +    
  +    public Configuration() {
           configuration.put("standard", standardConfiguration);
           configuration.put("pdf", pdfConfiguration);
           configuration.put("awt", awtConfiguration);
       }
   
  -    public static HashMap getConfiguration() {
  +    public Configuration(int role, HashMap config) {
  +        this();
  +        setRole(role, config);
  +    }
  +    
  +    public void setRole(int role, HashMap config) {
  +        switch (role) {
  +            case Configuration.STANDARD:
  +                standardConfiguration = config;
  +                break;
  +            case Configuration.PDF:
  +                pdfConfiguration = config;
  +                break;
  +            case Configuration.AWT:
  +                awtConfiguration = config;
  +                break;
  +            default:
  +                logger.warning(
  +                "Can't setup configuration. Unknown configuration role/target"
  +                );
  +            }
  +    }
  +    
  +    public HashMap getConfiguration() {
           return configuration;
       }
   
  @@ -78,7 +98,7 @@
        * convenience methods, which return the correct form.
        * null   if the key is not defined.
        */
  -    public static Object getValue(String key, int role) {
  +    public Object getValue(String key, int role) {
           switch (role) {
           case Configuration.STANDARD:
               return standardConfiguration.get(key);
  @@ -99,8 +119,8 @@
        * @return String a string containing the value
        * null   if the key is not defined.
        */
  -    public static String getStringValue(String key, int role) {
  -        Object obj = Configuration.getValue(key, role);
  +    public String getStringValue(String key, int role) {
  +        Object obj = getValue(key, role);
           if (obj instanceof String) {
               return (String)obj;
           } else {
  @@ -116,8 +136,8 @@
        * @return int a int containing the value
        * -1   if the key is not defined.
        */
  -    public static int getIntValue(String key, int role) {
  -        Object obj = Configuration.getValue(key, role);
  +    public int getIntValue(String key, int role) {
  +        Object obj = getValue(key, role);
           if (obj instanceof String) {
               return Integer.parseInt((String)obj);
           } else if (obj instanceof Integer) {
  @@ -129,14 +149,14 @@
   
   
       /**
  -     * convenience methods to access boolean values in the configuration
  +     * convenience methods to access Boolean values in the configuration
        * @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.
        */
  -    public static Boolean getBooleanValue(String key, int role) {
  -        Object obj = Configuration.getValue(key, role);
  +    public Boolean getBooleanObject(String key, int role) {
  +        Object obj = getValue(key, role);
           if (obj instanceof String) {
               return new Boolean((String)obj);
           } else if (obj instanceof Boolean) {
  @@ -146,6 +166,17 @@
           }
       }
   
  +    /**
  +     * Convenience method for accessing boolean values in the configuration
  +     * @param key the key for the configuration entry
  +     * @param role the configuration target
  +     * @return the boolean value of the key value if defined, or false
  +     */
  +    public boolean isTrue(String key, int role) {
  +        Boolean bval = getBooleanObject(key, role);
  +        if (bval == null) return false;
  +        return bval.booleanValue();
  +    }
   
       /**
        * convenience methods to access list values in the configuration
  @@ -154,8 +185,8 @@
        * @return ArrayList a ArrayList containing the values
        * null   if the key is not defined.
        */
  -    public static ArrayList getListValue(String key, int role) {
  -        Object obj = Configuration.getValue(key, role);
  +    public ArrayList getListValue(String key, int role) {
  +        Object obj = getValue(key, role);
           if (obj instanceof ArrayList) {
               return (ArrayList)obj;
           } else {
  @@ -171,8 +202,8 @@
        * @return HashMap a HashMap containing the values
        * null   if the key is not defined.
        */
  -    public static HashMap getHashMapValue(String key, int role) {
  -        Object obj = Configuration.getValue(key, role);
  +    public HashMap getHashMapValue(String key, int role) {
  +        Object obj = getValue(key, role);
           if (obj instanceof HashMap) {
               return (HashMap)obj;
           } else {
  @@ -194,7 +225,7 @@
        * 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) {
  +    public Object getHashMapEntry(String map, Object key, int role) {
           Object obj = getValue(map, role);
           if (obj instanceof HashMap) {
               return ((HashMap)obj).get(key);
  @@ -213,8 +244,8 @@
        * convenience methods, which return the correct form.
        * null   if the key is not defined.
        */
  -    public static Object getValue(String key) {
  -        return Configuration.getValue(key, Configuration.STANDARD);
  +    public Object getValue(String key) {
  +        return getValue(key, Configuration.STANDARD);
       }
   
       /**
  @@ -225,8 +256,8 @@
        * @return String a string containing the value
        * null   if the key is not defined.
        */
  -    public static String getStringValue(String key) {
  -        return Configuration.getStringValue(key, Configuration.STANDARD);
  +    public String getStringValue(String key) {
  +        return getStringValue(key, Configuration.STANDARD);
       }
   
       /**
  @@ -236,19 +267,30 @@
        * @return int a int containing the value
        * -1   if the key is not defined.
        */
  -    public static int getIntValue(String key) {
  -        return Configuration.getIntValue(key, Configuration.STANDARD);
  +    public int getIntValue(String key) {
  +        return getIntValue(key, Configuration.STANDARD);
       }
   
       /**
  -     * convenience methods to access boolean values in the configuration
  +     * convenience methods to access Boolean values in the configuration
        *
        * @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.
        */
  -    public static Boolean getBooleanValue(String key) {
  -        return Configuration.getBooleanValue(key, Configuration.STANDARD);
  +    public Boolean getBooleanObject(String key) {
  +        return getBooleanObject(key, Configuration.STANDARD);
  +    }
  +
  +    /**
  +     * Convenience method for accessing boolean values in the configuration
  +     * @param key the key for the configuration entry
  +     * @return the boolean value of the key value if defined, or false
  +     */
  +    public boolean isTrue(String key) {
  +        Boolean bval = getBooleanObject(key);
  +        if (bval == null) return false;
  +        return bval.booleanValue();
       }
   
       /**
  @@ -258,8 +300,8 @@
        * @return ArrayList a ArrayList containing the values
        * null   if the key is not defined.
        */
  -    public static ArrayList getListValue(String key) {
  -        return Configuration.getListValue(key, Configuration.STANDARD);
  +    public ArrayList getListValue(String key) {
  +        return getListValue(key, Configuration.STANDARD);
       }
   
       /**
  @@ -270,8 +312,8 @@
        * @return HashMap a HashMap containing the values
        * null   if the key is not defined.
        */
  -    public static HashMap getHashMapValue(String key) {
  -        return Configuration.getHashMapValue(key, Configuration.STANDARD);
  +    public HashMap getHashMapValue(String key) {
  +        return getHashMapValue(key, Configuration.STANDARD);
       }
   
   
  @@ -287,8 +329,8 @@
        * 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);
  +    public Object getHashMapEntry(String map, Object key) {
  +        return getHashMapEntry(map, key, STANDARD);
       }
   
   
  @@ -298,8 +340,8 @@
        * @return HashMap a HashMap containing the values
        * null   if the key is not defined.
        */
  -    public static ArrayList getFonts() {
  -        return (ArrayList)Configuration.getValue("fonts",
  +    public ArrayList getFonts() {
  +        return (ArrayList)getValue("fonts",
                                                 Configuration.STANDARD);
       }
   
  @@ -307,22 +349,7 @@
        * initializes this configuration
        * @param config contains the configuration information
        */
  -    public static void setup(int role, HashMap config) {
  -        switch (role) {
  -        case Configuration.STANDARD:
  -            standardConfiguration = config;
  -            break;
  -        case Configuration.PDF:
  -            pdfConfiguration = config;
  -            break;
  -        case Configuration.AWT:
  -            awtConfiguration = config;
  -            break;
  -        default:
  -            logger.warning(
  -            "Can't setup configuration. Unknown configuration role/target"
  -            );
  -        }
  +    public void setup(int role, HashMap config) {
       }
   
       /**
  @@ -333,7 +360,7 @@
        * @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) {
  +    public void put(String key, Object value, int role) {
           switch (role) {
           case Configuration.STANDARD:
               standardConfiguration.put(key, value);
  @@ -362,14 +389,14 @@
        * can be a String, a Boolean, an Integer, an ArrayList or a HashMap
        */
   
  -    public static void put(String key, Object value) {
  -        Configuration.put(key, value, Configuration.STANDARD);
  +    public void put(String key, Object value) {
  +        put(key, value, Configuration.STANDARD);
       }
   
       /**
        * debug methods, which writes out all information in this configuration
        */
  -    public static void dumpConfiguration() {
  +    public void dumpConfiguration() {
           String key;
           Object value;
           ArrayList list;
  
  
  
  1.1.2.5   +17 -63    xml-fop/src/java/org/apache/fop/configuration/Attic/ConfigurationReader.java
  
  Index: ConfigurationReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/configuration/Attic/ConfigurationReader.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- ConfigurationReader.java	19 Feb 2004 03:11:57 -0000	1.1.2.4
  +++ ConfigurationReader.java	6 Mar 2004 05:59:10 -0000	1.1.2.5
  @@ -26,49 +26,28 @@
   import java.io.IOException;
   import org.xml.sax.InputSource;
   
  -// fop
  -import org.apache.fop.apps.Driver;
   import org.apache.fop.apps.FOPException;
  +import org.apache.fop.apps.Fop;
   
   /**
    * entry class for reading configuration from file and creating a configuration
  - * class. Typical use looks like: <br>
  - *
  - * <code>ConfigurationReader reader = new ConfigurationReader ("config.xml","standard");
  - * try {
  - * reader.start();
  - * } catch (org.apache.fop.apps.FOPException error) {
  - * reader.dumpError(error);
  - * }
  - * </code>
  - * Once the configuration has been setup, the information can be accessed with
  - * the methods of StandardConfiguration.
  - */
  + * class. */
   public class ConfigurationReader {
   
  -    /**
  -     * show a full dump on error
  -     */
  -    private static boolean errorDump = false;
  -
  -    /**
  -     * inputsource for configuration file
  -     */
  +    /** inputsource for configuration file */
       private InputSource filename;
   
  +    private Configuration configuration;
   
       /**
  -     * creates a configuration reader
  +     * creates a configuration reader and starts parsing of config file
        * @param filename the file which contains the configuration information
        */
  -    public ConfigurationReader(InputSource filename) {
  +    public ConfigurationReader(
  +            InputSource filename, Configuration configuration)
  +    throws FOPException {
           this.filename = filename;
  -    }
  -
  -    /**
  -     * intantiates parser and starts parsing of config file
  -     */
  -    public void start() throws FOPException {
  +        this.configuration = configuration;
           XMLReader parser = createParser();
   
           // setting the parser features
  @@ -79,7 +58,8 @@
               throw new FOPException("You need a parser which supports SAX version 2",
                                      e);
           }
  -        ConfigurationParser configurationParser = new ConfigurationParser();
  +        ConfigurationParser configurationParser =
  +            new ConfigurationParser(configuration);
           parser.setContentHandler(configurationParser);
   
           try {
  @@ -101,13 +81,11 @@
        *
        * @return the created SAX parser
        */
  -    public static XMLReader createParser() throws FOPException {
  -        String parserClassName = Driver.getParserClassName();
  -        if (errorDump) {
  -            Configuration.logger.config(
  -                    "configuration reader using SAX parser "
  -                                 + parserClassName);
  -        }
  +    public XMLReader createParser() throws FOPException {
  +        String parserClassName = Fop.getParserClassName();
  +        configuration.logger.config(
  +                "configuration reader using SAX parser "
  +                + parserClassName);
   
           try {
               return (XMLReader)Class.forName(parserClassName).newInstance();
  @@ -122,30 +100,6 @@
               throw new FOPException(parserClassName + " is not a SAX driver",
                                      e);
           }
  -    }
  -
  -    /**
  -     * Dumps an error
  -     */
  -    public void dumpError(Exception e) {
  -        if (errorDump) {
  -            if (e instanceof SAXException) {
  -                e.printStackTrace();
  -                if (((SAXException)e).getException() != null) {
  -                    ((SAXException)e).getException().printStackTrace();
  -                }
  -            } else {
  -                e.printStackTrace();
  -            }
  -        }
  -    }
  -
  -    /**
  -     * long or short error messages
  -     *
  -     */
  -    public void setDumpError(boolean dumpError) {
  -        errorDump = dumpError;
       }
   
   }
  
  
  
  1.1.2.4   +22 -15    xml-fop/src/java/org/apache/fop/configuration/Attic/ConfigurationParser.java
  
  Index: ConfigurationParser.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/configuration/Attic/ConfigurationParser.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- ConfigurationParser.java	19 Feb 2004 03:11:57 -0000	1.1.2.3
  +++ ConfigurationParser.java	6 Mar 2004 05:59:10 -0000	1.1.2.4
  @@ -33,7 +33,7 @@
   
   
   /**
  - * SAX2 Handler which retrieves the configuration information and stores them in Configuration.
  + * SAX2 Handler which retrieves the configMaps information and stores them in Configuration.
    * Normally this class doesn't need to be accessed directly.
    */
   public class ConfigurationParser extends DefaultHandler {
  @@ -55,18 +55,18 @@
       private int status = OUT;
       private int datatype = -1;
   
  -    // store the result configuration
  -    private static HashMap configuration;
  +    // store the result configMaps
  +    private static HashMap configMaps;
       private static HashMap activeConfiguration;
   
  -    // stores key for new config entry
  +    // stores key for new configuration entry
       private String key = "";
       private ArrayList keyStack = new ArrayList();
   
       // stores string value
       private String value = "";
   
  -    // stores key for new config entry
  +    // stores key for new configuration entry
       private String subkey = "";
   
       // stores list value
  @@ -81,7 +81,7 @@
       private Locator locator;
   
       /**
  -     * determines role / target of configuration information, default is standard
  +     * determines role / target of configMaps information, default is standard
        */
       private String role = "standard";
   
  @@ -101,9 +101,14 @@
   
       // information on a font triplet
       private String fontTripletName, weight, style;
  +    private Configuration configuration;
  +    
  +    public ConfigurationParser(Configuration config) {
  +        this.configuration = config;
  +    }
   
       public void startDocument() {
  -        configuration = Configuration.getConfiguration();
  +        configMaps = configuration.getConfiguration();
       }
   
       /**
  @@ -130,7 +135,7 @@
               // role=standard as default
               if (attributes.getLength() == 0) {
                   role = "standard";
  -                // retrieve attribute value for "role" which determines configuration target
  +                // retrieve attribute value for "role" which determines configMaps target
               } else {
                   role = attributes.getValue("role");
               }
  @@ -156,13 +161,13 @@
               fontTriplets.add(fontTriplet);
           } else {
               // to make sure that user knows about false tag
  -            Configuration.logger.warning("Unknown tag in configuration file: "
  +            configuration.logger.warning("Unknown tag in configMaps file: "
                                      + localName);
           }
       }                                            // end startElement
   
       /**
  -     * stores subentries or entries into their hashes (map for subentries, configuration for entry)
  +     * stores subentries or entries into their hashes (map for subentries, configMaps for entry)
        */
       public void endElement(String uri, String localName, String qName) {
           if (localName.equals("entry")) {
  @@ -252,18 +257,20 @@
       }    // end characters
   
       /**
  -     * stores configuration entry into configuration hashtable according to the role
  +     * stores configuration entry into configuration hashtable
  +     * according to the role
        *
  -     * @param role a string containing the role / target for this configuration information
  +     * @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 = (HashMap)configuration.get(role);
  +        activeConfiguration = (HashMap)configMaps.get(role);
           if (activeConfiguration != null) {
               activeConfiguration.put(key, value);
           } else {
  -            Configuration.logger.warning("Unknown role >" + role
  +            configuration.logger.warning("Unknown role >" + role
                                      + "< for new configuration entry. \n"
                                      + "Putting configuration with key:" + key
                                      + " into standard configuration.");
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org