Title: Message
Hi all,
 
Sorry in advance if I'm not doing this right, it's my first official contribution (or attempt thereof) to FOP!
 
I ran into issues where my servlet was getting installed and run from a number of locations, making the relative paths in fop-userconfig.xml not work, so I made a couple of minor modifications to make this something the user can configure.
 
1. I added  "getBasePath" and "setBasePath" methods to configuration/Configuration.java, both in a static context
2. I updated configuration/FontInfo.java to call these methods when returning font paths
 
I also made a couple of other mods that seemed to make sense.
 
3. I changed Configuration.java to use a singleton pattern instead of static methods to make future conf migration easier (so that the same JVM could in theory have multiple Configurations by removing the singleton - now each Configuration can stand on its own). I added static helper methods to ensure backwards compatibility.
 
4. In apps/Driver.java, I changed the "ERROR - no logger set" message to "ERROR - no logger set - using System.out" just for clarity (I was confused until I saw the source code).
 
I'm attaching a cvs diff of my changes (against the fop-0_20_3 tag). I think this is the right thing to do, let me know if it's not.
 
If it's useful, I can make these changes work from the command line, or go ahead and refactor the Options to not be JVM-global - just depends if folks are interested. I guess this would make sense on the latest dev branch, not the 0.20.3 branch.
 
Brian
? bokconfdiffs.txt
Index: apps/Driver.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/apps/Driver.java,v
retrieving revision 1.36.2.1
diff -r1.36.2.1 Driver.java
226c226
<             log.error("Logger not set");
---
>             log.error("Logger not set - using System.out");
Index: configuration/Configuration.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/configuration/Configuration.java,v
retrieving revision 1.6
diff -r1.6 Configuration.java
31,37c31,39
<     /**
<      * 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);
---
>       /**
>        * base path for font paths
>        */
>       private String basePath = null ;
> 
>       /**
>        * Singleton instance
>        */
>       private static Configuration singleton = null ;
42,51c44
<     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);
<     }
---
>     private Hashtable configuration = null ;
52a46,70
>       /**
>        * HashTables for each configuration type
>        */
>       private Hashtable standardConfiguration = null ;
>       private Hashtable pdfConfiguration = null ;
>       private Hashtable awtConfiguration = null ;
> 
>       /**
>        * Constructor for singleton pattern
>        * Creates hash of hashes for different config types
>        */
>       private Configuration() {
>               standardConfiguration = new Hashtable(30) ;
>               pdfConfiguration = new Hashtable(20) ;
>               awtConfiguration = new Hashtable(20) ;
> 
>               configuration = new Hashtable(3) ;
>         configuration.put("standard", standardConfiguration) ;
>         configuration.put("pdf", pdfConfiguration) ;
>         configuration.put("awt", awtConfiguration) ;
>       }
> 
>       /**
>        * Hashtable accessor method for singleton pattern
>        */
54,55c72,115
<         return configuration;
<     }
---
>               if (singleton == null)
>                       singleton = new Configuration() ;
>               return singleton.getHashMap() ;
>     }
> 
>       /**
>        * Object accessor method for singleton pattern
>        */
>       public static Configuration getInstance() {
>               if (singleton == null)
>                       singleton = new Configuration() ;
>               return singleton ;
>       }
> 
>       /**
>        * Get base Hashtable
>        */
>       public Hashtable getHashMap() {
>               return configuration ;
>       }
> 
>       /**
>        * Set the base Path for font paths
>        */
>       public void setBasePath(String basePath) {
>               this.basePath = basePath ;
>       }
> 
>       /**
>        * Get the base Path for font paths
>        */
>       public String getBasePath() {
>               return this.basePath ;
>       }
> 
>       /**
>        * static helper for getValue
>        * when caller code is changed, remove this method for the non-static
>        * version below (change its name to just getvalue)
>        * same for other static helpers
>        */
>     public static Object getValue(String key, int role) {
>               return getInstance().lgetValue(key, role) ;
>       }
66c126
<     public static Object getValue(String key, int role) {
---
>     public Object lgetValue(String key, int role) {
254a315,321
>       /**
>        * static helper for setup
>        */
>     public static void setup(int role, Hashtable config) {
>               getInstance().lsetup(role, config) ;
>       }
>       
259c326
<     public static void setup(int role, Hashtable config) {
---
>     public void lsetup(int role, Hashtable config) {
262c329
<             standardConfiguration = config;
---
>             standardConfiguration = config ;
265c332
<             pdfConfiguration = config;
---
>                       pdfConfiguration = config ;
268c335
<             awtConfiguration = config;
---
>                       awtConfiguration = config ;
274a342,348
>       /**
>        * static helper for put
>        */
>     public static void put(String key, Object value, int role) {
>               getInstance().lput(key, value, role) ;
>       }
> 
282c356
<     public static void put(String key, Object value, int role) {
---
>     public void lput(String key, Object value, int role) {
314a389,395
>       /**
>        * static helper for backwards compatibility
>        */
>       public static void dumpConfiguration() {
>               getInstance().ldumpConfiguration() ;
>       }
> 
318c399
<     public static void dumpConfiguration() {
---
>     public void ldumpConfiguration() {
Index: configuration/FontInfo.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/configuration/FontInfo.java,v
retrieving revision 1.2
diff -r1.2 FontInfo.java
32c32
<         return metricsFile;
---
>         return Configuration.getInstance().getBasePath() + metricsFile ;
36c36
<         return embedFile;
---
>         return Configuration.getInstance().getBasePath() + embedFile ;

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to