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 fo...@locus.apache.org on 2000/12/17 17:27:21 UTC

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

fotis       00/12/17 08:27:21

  Modified:    src/org/apache/fop/apps CommandLine.java Driver.java
                        Version.java XalanCommandLine.java
               src/org/apache/fop/configuration ConfigurationParser.java
                        ConfigurationReader.java
  Added:       src/org/apache/fop/configuration Configuration.java
  Removed:     src/org/apache/fop/configuration AWTConfiguration.java
                        PDFConfiguration.java StandardConfiguration.java
  Log:
  changed configuration design following the ideas of Kelly Campbell
  
  Revision  Changes    Path
  1.16      +41 -33    xml-fop/src/org/apache/fop/apps/CommandLine.java
  
  Index: CommandLine.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/CommandLine.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- CommandLine.java	2000/12/12 21:12:17	1.15
  +++ CommandLine.java	2000/12/17 16:27:19	1.16
  @@ -1,4 +1,4 @@
  -/*-- $Id: CommandLine.java,v 1.15 2000/12/12 21:12:17 fotis Exp $ --
  +/*-- $Id: CommandLine.java,v 1.16 2000/12/17 16:27:19 fotis Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -71,6 +71,7 @@
   
   // FOP
   import org.apache.fop.messaging.MessageHandler;
  +import org.apache.fop.configuration.Configuration;
   
   /**
    * mainline class.
  @@ -85,6 +86,7 @@
       private String pdfFile = null;
       private String userConfigFile = null;
       private String baseDir = null;
  +    private boolean dumpConfiguration = false;
   
       /** show a full dump on error */
       private static boolean errorDump = false;
  @@ -93,7 +95,10 @@
           for (int i = 0; i < args.length; i++) {
               if (args[i].equals("-d") || args[i].equals("--full-error-dump")) {
                   errorDump = true;
  -            } else if ((args[i].charAt(0) == '-') && (args[i].charAt(1) == 'c')) {
  +            } else if (args[i].equals("-x")) {
  +                dumpConfiguration = true;
  +            } else if ((args[i].charAt(0) == '-') &&
  +                    (args[i].charAt(1) == 'c')) {
                   userConfigFile = args[i].substring(2);
               } else if (args[i].charAt(0) == '-') {
                   printUsage(args[i]);
  @@ -112,29 +117,32 @@
   
       public void printUsage(String arg) {
           if (arg != null) {
  -            MessageHandler.errorln("Unkown argument: '"+arg + "'");
  -            MessageHandler.errorln("Usage: java [-d] " +
  -                                   "[-cMyConfigFile] " +
  -                                   "org.apache.fop.apps.CommandLine " + "formatting-object-file pdf-file");
  -            MessageHandler.errorln("Options:\n" + "  -d or --full-error-dump    Show stack traces upon error");
  -            MessageHandler.errorln("-cMyConfigFile use values in configuration file MyConfigFile instead of default");
  +            MessageHandler.errorln("Unknown argument: '"+arg + "'");
  +        } 
  +        MessageHandler.errorln("Usage: java [-d] [-x]" +
  +                               "[-cMyConfigFile] \n" +
  +                               "            org.apache.fop.apps.CommandLine " + "formatting-object-file pdf-file");
  +        MessageHandler.errorln("Options:\n" + "  -d or --full-error-dump      Show stack traces upon error");
  +        MessageHandler.errorln("  -x                           dump configuration information");
  +        MessageHandler.errorln("  -cMyConfigFile               use configuration file MyConfigFile");
   
  -            System.exit(1);
  -        }
  +        System.exit(1);
       }
   
       public void run() {
  -        Driver driver  = new Driver();
  -        if (errorDump)  {
  +        Driver driver = new Driver();
  +        if (errorDump) {
               driver.setErrorDump(true);
           }
  -        driver.loadStandardConfiguration("standard");
  -//        driver.loadStandardConfiguration("pdf");
  -        if (userConfigFile != null)  {
  -            driver.loadUserconfiguration(userConfigFile,"standard");
  +        if (userConfigFile != null) {
  +            driver.loadUserconfiguration(userConfigFile);
           }
           driver.setBaseDir(foFile);
   
  +        if (dumpConfiguration) {
  +            Configuration.dumpConfiguration();
  +            System.exit(0);
  +        }
   
           String version = Version.getVersion();
           MessageHandler.logln(version);
  @@ -181,11 +189,11 @@
   
   
       /**
  -      * creates a SAX parser, using the value of org.xml.sax.parser
  -      * defaulting to org.apache.xerces.parsers.SAXParser
  -      *
  -      * @return the created SAX parser
  -      */
  +       * creates a SAX parser, using the value of org.xml.sax.parser
  +       * defaulting to org.apache.xerces.parsers.SAXParser
  +       *
  +       * @return the created SAX parser
  +       */
       static XMLReader createParser() {
           String parserClassName = System.getProperty("org.xml.sax.parser");
           if (parserClassName == null) {
  @@ -229,11 +237,11 @@
       }
   
       /**
  -      * create an InputSource from a file name
  -      *
  -      * @param filename the name of the file
  -      * @return the InputSource created
  -      */
  +       * create an InputSource from a file name
  +       *
  +       * @param filename the name of the file
  +       * @return the InputSource created
  +       */
       public static InputSource fileInputSource(String filename) {
   
           /* this code adapted from James Clark's in XT */
  @@ -252,13 +260,13 @@
       }
   
       /**
  -      * mainline method
  -      *
  -      * first command line argument is input file
  -      * second command line argument is output file
  -      *
  -      * @param command line arguments
  -      */
  +       * mainline method
  +       *
  +       * first command line argument is input file
  +       * second command line argument is output file
  +       *
  +       * @param command line arguments
  +       */
       public static void main(String[] args) {
           CommandLine cmdLine = new CommandLine(args);
           cmdLine.run();
  
  
  
  1.18      +65 -73    xml-fop/src/org/apache/fop/apps/Driver.java
  
  Index: Driver.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/Driver.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Driver.java	2000/12/14 18:11:45	1.17
  +++ Driver.java	2000/12/17 16:27:20	1.18
  @@ -1,4 +1,4 @@
  -/*-- $Id: Driver.java,v 1.17 2000/12/14 18:11:45 fotis Exp $ --
  +/*-- $Id: Driver.java,v 1.18 2000/12/17 16:27:20 fotis Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -60,7 +60,7 @@
   import org.apache.fop.render.Renderer;
   import org.apache.fop.messaging.MessageHandler;
   import org.apache.fop.configuration.ConfigurationReader;
  -import org.apache.fop.configuration.StandardConfiguration;
  +import org.apache.fop.configuration.Configuration;
   
   
   // DOM
  @@ -140,11 +140,12 @@
       /** create a new Driver */
       public Driver() {
           this.treeBuilder = new FOTreeBuilder();
  +        this.loadStandardConfiguration();
       }
   
       /** Set the error dump option
  -       * @param dump if true, full stacks will be reported to the error log
  -       */
  +        * @param dump if true, full stacks will be reported to the error log
  +        */
       public void setErrorDump(boolean dump) {
           errorDump = dump;
       }
  @@ -155,18 +156,18 @@
       }
   
       /**
  -       * set the class name of the Renderer to use as well as the
  -       * producer string for those renderers that can make use of it
  -       */
  +        * set the class name of the Renderer to use as well as the
  +        * producer string for those renderers that can make use of it
  +        */
       public void setRenderer(String rendererClassName, String producer) {
           this.renderer = createRenderer(rendererClassName);
           this.renderer.setProducer(producer);
       }
   
       /**
  -       * protected method used by setRenderer(String, String) to
  -       * instantiate the Renderer class
  -       */
  +        * protected method used by setRenderer(String, String) to
  +        * instantiate the Renderer class
  +        */
       protected Renderer createRenderer(String rendererClassName) {
           MessageHandler.logln("using renderer " + rendererClassName);
   
  @@ -190,26 +191,26 @@
       }
   
       /**
  -       * add the given element mapping.
  -       *
  -       * an element mapping maps element names to Java classes
  -       */
  +        * add the given element mapping.
  +        *
  +        * an element mapping maps element names to Java classes
  +        */
       public void addElementMapping(ElementMapping mapping) {
           mapping.addToBuilder(this.treeBuilder);
       }
   
       /**
  -       * add the element mapping with the given class name
  -       */
  +        * add the element mapping with the given class name
  +        */
       public void addElementMapping(String mappingClassName) {
           createElementMapping(mappingClassName).addToBuilder(
             this.treeBuilder);
       }
   
       /**
  -       * protected method used by addElementMapping(String) to
  -       * instantiate element mapping class
  -       */
  +        * protected method used by addElementMapping(String) to
  +        * instantiate element mapping class
  +        */
       protected ElementMapping createElementMapping(
         String mappingClassName) {
           MessageHandler.logln("using element mapping " + mappingClassName);
  @@ -238,16 +239,16 @@
       }
   
       /**
  -       * add the element mapping with the given class name
  -       */
  +        * add the element mapping with the given class name
  +        */
       public void addPropertyList(String listClassName) {
           createPropertyList(listClassName).addToBuilder(this.treeBuilder);
       }
   
       /**
  -       * protected method used by addPropertyList(String) to
  -       * instantiate list mapping class
  -       */
  +        * protected method used by addPropertyList(String) to
  +        * instantiate list mapping class
  +        */
       protected PropertyListMapping createPropertyList(
         String listClassName) {
           MessageHandler.logln("using property list mapping " +
  @@ -277,20 +278,20 @@
       }
   
       /**
  -       * return the tree builder (a SAX ContentHandler).
  -       *
  -       * used in situations where SAX is used but not via a FOP-invoked
  -       * SAX parser. A good example is an XSLT engine that fires SAX
  -       * events but isn't a SAX Parser itself.
  -       */
  +        * return the tree builder (a SAX ContentHandler).
  +        *
  +        * used in situations where SAX is used but not via a FOP-invoked
  +        * SAX parser. A good example is an XSLT engine that fires SAX
  +        * events but isn't a SAX Parser itself.
  +        */
       public ContentHandler getContentHandler() {
           return this.treeBuilder;
       }
   
       /**
  -       * build the formatting object tree using the given SAX Parser and
  -       * SAX InputSource
  -       */
  +        * build the formatting object tree using the given SAX Parser and
  +        * SAX InputSource
  +        */
       public void buildFOTree(XMLReader parser,
                               InputSource source) throws FOPException {
   
  @@ -313,8 +314,8 @@
       }
   
       /**
  -       * build the formatting object tree using the given DOM Document
  -       */
  +        * build the formatting object tree using the given DOM Document
  +        */
       public void buildFOTree(Document document) throws FOPException {
   
           /* most of this code is modified from John Cowan's */
  @@ -342,7 +343,7 @@
                           int datalen = data.length();
                           if (array == null || array.length < datalen) {
                               /* if the array isn't big enough, make a new
  -                                 one */
  +                                  one */
                               array = new char[datalen];
                           }
                           data.getChars(0, datalen, array, 0);
  @@ -404,8 +405,8 @@
       }
   
       /**
  -       * Dumps an error
  -       */
  +        * Dumps an error
  +        */
       public void dumpError(Exception e) {
           if (errorDump) {
               if (e instanceof SAXException) {
  @@ -422,16 +423,16 @@
   
   
       /**
  -       * set the PrintWriter to use to output the result of the Renderer
  -       * (if applicable)
  -       */
  +        * set the PrintWriter to use to output the result of the Renderer
  +        * (if applicable)
  +        */
       public void setWriter(PrintWriter writer) {
           this.writer = writer;
       }
   
       /**
  -       * format the formatting object tree into an area tree
  -       */
  +        * format the formatting object tree into an area tree
  +        */
       public void format() throws FOPException {
           FontInfo fontInfo = new FontInfo();
           this.renderer.setupFontInfo(fontInfo);
  @@ -443,31 +444,22 @@
       }
   
       /**
  -       * render the area tree to the output form
  -       */
  +        * render the area tree to the output form
  +        */
       public void render() throws IOException, FOPException {
           this.renderer.render(areaTree, this.writer);
       }
   
       /**
  -      *  loads standard configuration file and a user file, if it has been specified
  -      */
  -    public void loadStandardConfiguration(String role) {
  -        String file;
  -        if (role.equals("standard")) {
  -            file = "config.xml";
  -        } else if (role.equals("pdf")) {
  -            file = "pdf.xml";
  -        } else  if (role.equals("awt")) {
  -            file = "awt.xml";
  -        } else {
  -            MessageHandler.errorln("Error: unknown configuration role: " + role
  -                                   + "\n using standard");
  -            file = "config.xml";
  -        }
  +       *  loads standard configuration file and a user file, if it has been specified
  +       */
  +    public void loadStandardConfiguration() {
  +        String file = "config.xml";
  +
           // the entry /conf/config.xml refers to a directory conf which is a sibling of org
           InputStream configfile =
  -          ConfigurationReader.class.getResourceAsStream("/conf/"+file);
  +          ConfigurationReader.class.getResourceAsStream("/conf/"+
  +                  file);
           if (configfile == null) {
               MessageHandler.errorln("Fatal error: can't find default configuration file");
               System.exit(1);
  @@ -476,8 +468,7 @@
               MessageHandler.logln("reading default configuration file");
           }
           ConfigurationReader reader =
  -          new ConfigurationReader (new InputSource(configfile),
  -                                   "standard");
  +          new ConfigurationReader (new InputSource(configfile));
           if (errorDump) {
               reader.setDumpError(true);
           }
  @@ -492,12 +483,12 @@
           }
       }
   
  -    public void loadUserconfiguration(String userConfigFile, String role) {
  +    public void loadUserconfiguration(String userConfigFile) {
           //read user configuration file
           if (userConfigFile != null) {
               MessageHandler.logln("reading user configuration file");
               ConfigurationReader reader = new ConfigurationReader (
  -                                           CommandLine.fileInputSource(userConfigFile), role);
  +                                           CommandLine.fileInputSource(userConfigFile));
               if (errorDump) {
                   reader.setDumpError(true);
               }
  @@ -516,14 +507,15 @@
       }
   
       public void setBaseDir(String fofile) {
  -      String baseDir = StandardConfiguration.getStringValue("baseDir");
  -      if (baseDir == null)  {
  -        baseDir = new File(new File(fofile).getAbsolutePath()).getParent();
  -        StandardConfiguration.put("baseDir",baseDir);
  -      } 
  -      if (errorDump) {
  -        MessageHandler.logln("base directory: " + baseDir);
  -      }
  +        String baseDir = Configuration.getStringValue("baseDir");
  +        if (baseDir == null) {
  +            baseDir = new File(
  +                        new File(fofile).getAbsolutePath()).getParent();
  +            Configuration.put("baseDir",baseDir);
  +        }
  +        if (errorDump) {
  +            MessageHandler.logln("base directory: " + baseDir);
  +        }
       }
   
   
  
  
  
  1.14      +3 -3      xml-fop/src/org/apache/fop/apps/Version.java
  
  Index: Version.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/Version.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Version.java	2000/12/12 19:18:30	1.13
  +++ Version.java	2000/12/17 16:27:20	1.14
  @@ -1,4 +1,4 @@
  -/*-- $Id: Version.java,v 1.13 2000/12/12 19:18:30 fotis Exp $ -- 
  +/*-- $Id: Version.java,v 1.14 2000/12/17 16:27:20 fotis Exp $ -- 
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -51,7 +51,7 @@
   
   package org.apache.fop.apps;
   
  -import org.apache.fop.configuration.StandardConfiguration;
  +import org.apache.fop.configuration.Configuration;
   /** 
    * class representing the version of FOP.
    */
  @@ -63,6 +63,6 @@
        * @return the version string
        */
       public static String getVersion() {
  -        return StandardConfiguration.getStringValue("version");
  +        return Configuration.getStringValue("version");
       }
   }
  
  
  
  1.9       +18 -10    xml-fop/src/org/apache/fop/apps/XalanCommandLine.java
  
  Index: XalanCommandLine.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/XalanCommandLine.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XalanCommandLine.java	2000/12/12 21:12:16	1.8
  +++ XalanCommandLine.java	2000/12/17 16:27:20	1.9
  @@ -82,6 +82,7 @@
   // FOP
   import org.apache.fop.messaging.MessageHandler;
   import org.apache.fop.configuration.ConfigurationReader;
  +import org.apache.fop.configuration.Configuration;
   
   /**
    * mainline class.
  @@ -97,8 +98,8 @@
       private String xsltFile = null;
       private String userConfigFile = null;
       private String baseDir = null;
  +    private boolean dumpConfiguration = false;
   
  -
       /** show a full dump on error */ //this should be implemented here too
       private static boolean errorDump = false;
   
  @@ -106,6 +107,8 @@
           for (int i = 0; i < args.length; i++) {
               if (args[i].equals("-d") || args[i].equals("--full-error-dump")) {
                   errorDump = true;
  +            } else if (args[i].equals("-x")) {
  +                dumpConfiguration = true;
               } else if ((args[i].charAt(0) == '-') &&
                       (args[i].charAt(1) == 'c')) {
                   userConfigFile = args[i].substring(2);
  @@ -133,14 +136,15 @@
       public void printUsage(String arg) {
           if (arg != null) {
               MessageHandler.errorln("Unkown argument: '"+ arg + "'");
  -            MessageHandler.errorln("Usage: java [-d] " +
  -                                   "[-cMyConfigFile] " +
  -                                   "org.apache.fop.apps.XalanCommandLine " + "xml-file xslt-file pdf-file");
  -            MessageHandler.errorln("Options:\n" + "  -d or --full-error-dump    Show stack traces upon error");
  -            MessageHandler.errorln("-cMyConfigFile use values in configuration file MyConfigFile instead of/additional to default");
  +        } 
  +        MessageHandler.errorln("Usage: java [-d] [-x]" +
  +                               "[-cMyConfigFile] " +
  +                               "org.apache.fop.apps.XalanCommandLine " + "xml-file xslt-file pdf-file");
  +        MessageHandler.errorln("Options:\n" + "  -d or --full-error-dump    Show stack traces upon error");
  +        MessageHandler.errorln("  -x                           dump configuration information");
  +        MessageHandler.errorln("-cMyConfigFile use values in configuration file MyConfigFile instead of/additional to default");
   
  -            System.exit(1);
  -        }
  +        System.exit(1);
       }
   
       /**
  @@ -217,10 +221,14 @@
           if (errorDump)  {
               driver.setErrorDump(true);
           }
  -        driver.loadStandardConfiguration("standard");
           if (userConfigFile != null) {
  -            driver.loadUserconfiguration(userConfigFile, "standard");
  +            driver.loadUserconfiguration(userConfigFile);
           }
  +        if (dumpConfiguration) {
  +            Configuration.dumpConfiguration();
  +            System.exit(0);
  +        }
  +
           driver.setBaseDir(foFile);
           String version = Version.getVersion();
           MessageHandler.logln(version);
  
  
  
  1.2       +56 -10    xml-fop/src/org/apache/fop/configuration/ConfigurationParser.java
  
  Index: ConfigurationParser.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/configuration/ConfigurationParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConfigurationParser.java	2000/12/12 19:18:36	1.1
  +++ ConfigurationParser.java	2000/12/17 16:27:20	1.2
  @@ -81,8 +81,10 @@
       private int status = OUT;
       private int datatype = -1;
   
  -    //stores the result configuration
  -    private static Hashtable configuration = new Hashtable(20);
  +    //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);
   
       //stores key for new config entry
       private String key = "";
  @@ -102,6 +104,8 @@
       /** locator for line number information */
       private Locator locator;
   
  +    /** determines role / target of configuration information, default is standard */
  +    private int role = Configuration.STANDARD;
   
       /** get locator for position information */
       public void setDocumentLocator(Locator locator) {
  @@ -121,8 +125,24 @@
               status += IN_LIST;
           } else if (localName.equals("subentry")) {
               status += IN_SUBENTRY;
  -        } else if (localName.equals("configuration") ||
  -                localName.equals("entry") || localName.equals("datatype")) {
  +        } else if (localName.equals("entry"))   {
  +            if (attributes.getLength() == 0) {
  +                role = Configuration.STANDARD;
  +            } 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=standard as default
  +        } else if (localName.equals("configuration") ) {
           } else {
               //to make sure that user knows about false tag
               MessageHandler.errorln(
  @@ -135,18 +155,18 @@
        */
       public void endElement(String uri, String localName, String qName) {
           if (localName.equals("entry")) {
  -            int tek = 0;
               switch (datatype) {
                   case STRING:
  -                    configuration.put(key, value);
  +                    this.store(role, key, value);
                       break;
                   case LIST:
  -                    configuration.put(key, list);
  +                    this.store(role, key, list);
                       break;
                   case MAP:
  -                    configuration.put(key, map);
  +                    this.store(role, key, map);
               }
               status = OUT;
  +            role = Configuration.STANDARD;
           } else if (localName.equals("subentry")) {
               map.put(subkey, value);
               status -= IN_SUBENTRY;
  @@ -157,7 +177,23 @@
           } else if (localName.equals("value")) {
               status -= IN_VALUE;
           }
  +    }
   
  +    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.");
  +        } 
       }
   
       /**
  @@ -195,8 +231,18 @@
        * returns the parsed configuration information
        * @return Hashtable containing the configuration information as key/value pairs
        */
  -    public Hashtable getConfiguration() {
  -        return configuration;
  +    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;
  +        }
       }
   
   }
  
  
  
  1.2       +6 -18     xml-fop/src/org/apache/fop/configuration/ConfigurationReader.java
  
  Index: ConfigurationReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/configuration/ConfigurationReader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConfigurationReader.java	2000/12/12 19:18:36	1.1
  +++ ConfigurationReader.java	2000/12/17 16:27:20	1.2
  @@ -61,9 +61,7 @@
   //fop
   import org.apache.fop.messaging.MessageHandler;
   import org.apache.fop.apps.FOPException;
  -import org.apache.fop.configuration.AWTConfiguration;
  -import org.apache.fop.configuration.PDFConfiguration;
  -import org.apache.fop.configuration.StandardConfiguration;
  +import org.apache.fop.configuration.Configuration;
   
   /**
    *  entry class for reading configuration from file and creating a configuration
  @@ -87,16 +85,13 @@
       /** inputsource for configuration file  */
       private InputSource filename;
   
  -    private String role ;
   
       /**
        * creates a configuration reader
        * @param filename the file which contains the configuration information
  -     * @param role three values are recognized: awt, pdf, standard
        */
  -    public ConfigurationReader (InputSource filename, String role) {
  +    public ConfigurationReader (InputSource filename) {
           this.filename = filename;
  -        this.role = role;
       }
   
   
  @@ -127,16 +122,9 @@
   
           try {
               parser.parse(filename);
  -            if (role.equalsIgnoreCase("standard")) {
  -                StandardConfiguration.setup(
  -                  configurationParser.getConfiguration());
  -            } else if (role.equalsIgnoreCase("pdf")) {
  -                PDFConfiguration.setup(
  -                  configurationParser.getConfiguration());
  -            } else if (role.equalsIgnoreCase("awt")) {
  -                AWTConfiguration.setup(
  -                  configurationParser.getConfiguration());
  -            }
  +            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());
  @@ -221,7 +209,7 @@
         *
         */
       public void setDumpError(boolean dumpError) {
  -        this.errorDump = errorDump;
  +        errorDump = dumpError;
       }
   
   }
  
  
  
  1.1                  xml-fop/src/org/apache/fop/configuration/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  
  package org.apache.fop.configuration;
  
  import java.util.Vector;
  import java.util.Hashtable;
  import java.util.Enumeration;
  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.
   *
   */
  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;
  
      /**
       * general access method
       *
       * @param key a string containing the key value for the configuration value
       *        role detemines 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.
       */
      public static Object getValue (String key, int role) {
          switch (role) {
              case Configuration.STANDARD:
                  return standardConfiguration.get(key);
              case Configuration.PDF:
                  return pdfConfiguration.get(key);
              case Configuration.AWT:
                  return awtConfiguration.get(key);
              default:
                  return standardConfiguration.get(key);
          }
      };
  
      /**
       *  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
       *  @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);
          if (obj instanceof String) {
              return (String) obj;
          } else {
              return null;
          }
      };
  
      /**
       *  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
       *  @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);
          if (obj instanceof String) {
              return Integer.parseInt((String) obj);
          } 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
       *  @return boolean true or false as value
       *          -1   if the key is not defined.
       */
      public static Boolean getBooleanValue(String key, int role) {
          Object obj = Configuration.getValue (key, role);
          if (obj instanceof String) {
              String value = (String) obj;
              if (value.equals("true")) {
                  return new Boolean(true);
              } else if (value.equals("false")) {
                  return new Boolean(false);
              } else {
                  return null;
              }
          } else {
              return null;
          }
      };
  
      /**
       *  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
       *          null   if the key is not defined.
       */
      public static Vector getListValue(String key, int role) {
          Object obj = Configuration.getValue (key, role);
          if (obj instanceof Vector) {
              return (Vector) 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
       *          null   if the key is not defined.
       */
      public static Hashtable getHashtableValue(String key, int role) {
          Object obj = Configuration.getValue (key, role);
          if (obj instanceof Hashtable) {
              return (Hashtable) obj;
          } 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
       * @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.
       */
      public static Object getValue (String key) {
          return Configuration.getValue(key, Configuration.STANDARD);
      }
  
      /**
         *  convenience methods to access strings values in the standard configuration
         *
         *  @param key a string containing the key value for the configuration value
         *  @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);
      }
  
      /**
         *  convenience methods to access int values in the standard configuration
         *
         *  @param key a string containing the key value for the configuration value
         *  @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);
      }
  
      /**
         *  convenience methods to access boolean values in the configuration
         *
         *  @param key a string containing the key value for the configuration value
         *  @return boolean true or false as value
         *          -1   if the key is not defined.
         */
      public static Boolean getBooleanValue(String key) {
          return Configuration.getBooleanValue(key, Configuration.STANDARD);
      }
  
      /**
         *  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
         *          null   if the key is not defined.
         */
      public static Vector getListValue(String key) {
          return Configuration.getListValue(key, Configuration.STANDARD);
      }
  
      /**
         *  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
         *          null   if the key is not defined.
         */
      public static Hashtable getHashtableValue(String key) {
          return Configuration.getHashtableValue(key, Configuration.STANDARD);
      }
  
  
      /**
         * initializes this configuration
         * @param config contains the configuration information
         */
      public static void setup(int role, Hashtable config) {
          switch (role) {
              case Configuration.STANDARD:
                  standardConfiguration = config;
                  break;
              case Configuration.PDF:
                  pdfConfiguration = config;
                  break;
              case Configuration.AWT:
                  awtConfiguration = config;
                  break;
              default:
                  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
         *         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
         */
      public static void put(String key, Object value, int role) {
          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:
                  standardConfiguration.put(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
       *         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
       */
  
      public static void put(String key, Object value) {
          Configuration.put(key, value, Configuration.STANDARD);
      }
  
      /**
         *  debug methods, which writes out all information in this configuration
         */
      public static void dumpConfiguration() {
          String key;
          Object value;
          Vector list;
          Hashtable map, configuration;
          Enumeration enum;
          String tmp;
          System.out.println("Dumping configuration: ");
          Hashtable [] 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();
                  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();
                      MessageHandler.log("   values: ");
                      while (enum.hasMoreElements()) {
                          MessageHandler.log(enum.nextElement() + " - ");
                      }
                      MessageHandler.logln("");
                  } else if (value instanceof Hashtable) {
                      map = (Hashtable) value;
                      enum = map.keys();
                      MessageHandler.log("   values: ");
                      while (enum.hasMoreElements()) {
                          tmp = (String) enum.nextElement();
                          MessageHandler.log(" " + tmp + ":" + map.get(tmp));
                      }
                      MessageHandler.logln("");
                  }
              }
          }
      }
  
  
  
  }