keiron      01/07/02 03:45:38

  Modified:    src/org/apache/fop/configuration ConfigurationParser.java
  Log:
  handles key values a bit better
  
  Revision  Changes    Path
  1.8       +97 -83    
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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ConfigurationParser.java  2001/02/27 12:28:14     1.7
  +++ ConfigurationParser.java  2001/07/02 10:45:35     1.8
  @@ -1,7 +1,7 @@
  -/* 
  +/*
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  - * For details on use and redistribution please refer to the 
  - * LICENSE file included with these sources."
  + * For details on use and redistribution please refer to the
  + * LICENSE file included with these sources.
    */
   
   
  @@ -24,7 +24,6 @@
    * 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 final int OUT = 0;
       private final int IN_ENTRY = 1;
  @@ -33,8 +32,8 @@
       private final int IN_LIST = 8;
       private final int IN_SUBENTRY = 16;
       private final int IN_SUBKEY = 32;
  -     private final int IN_FONTS = 64;
  -     private final int IN_FONT = 128;
  +    private final int IN_FONTS = 64;
  +    private final int IN_FONT = 128;
   
       private final int STRING = 0;
       private final int LIST = 1;
  @@ -50,6 +49,7 @@
   
       //stores key for new config entry
       private String key = "";
  +    private Vector keyStack = new Vector();
   
       //stores string value
       private String value = "";
  @@ -71,21 +71,21 @@
   
       //stores fonts
       private Vector fontList = null;
  -     
  +
       //stores information on one font
       private FontInfo fontInfo = null;
  +
  +    //stores information on a font triplet
  +    private FontTriplet fontTriplet = null;
   
  -     //stores information on a font triplet
  -     private FontTriplet fontTriplet = null;
  -     
  -     //information on a font
  -     private String fontName, metricsFile, embedFile, kerningAsString;
  -     private boolean kerning;
  -     private Vector fontTriplets;
  -     
  -     //information on a font triplet
  -     private String fontTripletName, weight, style;
  -     
  +    //information on a font
  +    private String fontName, metricsFile, embedFile, kerningAsString;
  +    private boolean kerning;
  +    private Vector fontTriplets;
  +
  +    //information on a font triplet
  +    private String fontTripletName, weight, style;
  +
       public void startDocument() {
           configuration = Configuration.getConfiguration();
       }
  @@ -96,8 +96,8 @@
       }
   
       /**
  -      * extracts the element and attribute name and sets the fitting status and 
datatype values
  -      * */
  +     * extracts the element and attribute name and sets the fitting status and 
datatype values
  +     */
       public void startElement(String uri, String localName,
                                String qName, Attributes attributes) {
           if (localName.equals("key")) {
  @@ -108,34 +108,34 @@
               status += IN_LIST;
           } else if (localName.equals("subentry")) {
               status += IN_SUBENTRY;
  -        } else if (localName.equals("entry"))   {
  +        } else if (localName.equals("entry")) {
               //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 
configuration target
               } else {
                   role = attributes.getValue("role");
               }
  -        } else if (localName.equals("configuration") ) {
  -             } else if (localName.equals("fonts") ) {  //list of fonts starts
  -                     fontList = new Vector (10);
  -             } else if (localName.equals("font") ) {
  -                     kerningAsString = attributes.getValue("kerning");
  -                     if (kerningAsString.equalsIgnoreCase("yes")) {
  -                             kerning = true;
  -                     } else {
  -                             kerning = false;
  -                     }
  -                     metricsFile = attributes.getValue("metrics-file");
  -                     embedFile = attributes.getValue("embed-file");
  -                     fontName = attributes.getValue("name");
  -                     fontTriplets = new Vector(5);
  -             } else if (localName.equals("font-triplet") ) {                 
  -                     fontTripletName = attributes.getValue("name");
  -                     weight = attributes.getValue("weight"); 
  -                     style = attributes.getValue("style");
  -                     fontTriplet = new FontTriplet(fontTripletName,weight,style);
  -                     fontTriplets.addElement(fontTriplet);
  +        } else if (localName.equals("configuration")) {
  +        } else if (localName.equals("fonts")) { //list of fonts starts
  +            fontList = new Vector (10);
  +        } else if (localName.equals("font")) {
  +            kerningAsString = attributes.getValue("kerning");
  +            if (kerningAsString.equalsIgnoreCase("yes")) {
  +                kerning = true;
  +            } else {
  +                kerning = false;
  +            }
  +            metricsFile = attributes.getValue("metrics-file");
  +            embedFile = attributes.getValue("embed-file");
  +            fontName = attributes.getValue("name");
  +            fontTriplets = new Vector(5);
  +        } else if (localName.equals("font-triplet")) {
  +            fontTripletName = attributes.getValue("name");
  +            weight = attributes.getValue("weight");
  +            style = attributes.getValue("style");
  +            fontTriplet = new FontTriplet(fontTripletName, weight, style);
  +            fontTriplets.addElement(fontTriplet);
           } else {
               //to make sure that user knows about false tag
               MessageHandler.errorln(
  @@ -160,38 +160,54 @@
               }
               status = OUT;
               role = "standard";
  -                 key = "";
  -                 value = "";
  -             } else if (localName.equals("subentry")) {
  -                 map.put(subkey, value);
  -                 status -= IN_SUBENTRY;
  -                 key = "";
  -                 value = "";
  -             } else if (localName.equals("key")) {
  -                 status -= IN_KEY;
  -             } else if (localName.equals("list")) {
  -                 status -= IN_LIST;
  -                 value = "";
  -             } else if (localName.equals("value")) {
  -                 status -= IN_VALUE;
  -             } else if (localName.equals("fonts") ) {
  -                     this.store("standard", "fonts", fontList);
  -             } else if (localName.equals("font") ) {                 
  -                     fontInfo = new 
FontInfo(fontName,metricsFile,kerning,fontTriplets,embedFile);
  -                     fontList.addElement(fontInfo);
  -                     fontTriplets = null;
  -                     metricsFile = null;
  -                     embedFile = null;
  -                     fontName = null;
  -                     kerningAsString = "";                   
  -             } else if (localName.equals("font-triplet") ) {                 
  +            if (keyStack.size() > 0) {
  +                keyStack.removeElementAt(keyStack.size() - 1);
  +            }
  +            if (keyStack.size() > 0) {
  +                key = (String) keyStack.elementAt(keyStack.size() - 1);
  +            } else {
  +                key = "";
  +            }
  +            value = "";
  +        } else if (localName.equals("subentry")) {
  +            map.put(subkey, value);
  +            status -= IN_SUBENTRY;
  +            if (keyStack.size() > 0) {
  +                keyStack.removeElementAt(keyStack.size() - 1);
  +            }
  +            if (keyStack.size() > 0) {
  +                key = (String) keyStack.elementAt(keyStack.size() - 1);
  +            } else {
  +                key = "";
  +            }
  +            value = "";
  +        } else if (localName.equals("key")) {
  +            status -= IN_KEY;
  +            keyStack.addElement(key);
  +        } else if (localName.equals("list")) {
  +            status -= IN_LIST;
  +            value = "";
  +        } else if (localName.equals("value")) {
  +            status -= IN_VALUE;
  +        } else if (localName.equals("fonts")) {
  +            this.store("standard", "fonts", fontList);
  +        } else if (localName.equals("font")) {
  +            fontInfo = new FontInfo(fontName, metricsFile, kerning,
  +                                    fontTriplets, embedFile);
  +            fontList.addElement(fontInfo);
  +            fontTriplets = null;
  +            metricsFile = null;
  +            embedFile = null;
  +            fontName = null;
  +            kerningAsString = "";
  +        } else if (localName.equals("font-triplet")) {
           }
       }
   
       /**
  -      * extracts characters from text nodes and puts them into their respective
  -      * variables
  -      */
  +     * extracts characters from text nodes and puts them into their respective
  +     * variables
  +     */
       public void characters(char[] ch, int start, int length) {
           char characters [] = new char [length];
           System.arraycopy(ch, start, characters, 0, length);
  @@ -218,23 +234,21 @@
           }
       } //end characters
   
  -
       /**
  -      * 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 
  -      */
  +     * 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);
  +            activeConfiguration.put(key, value);
           } else {
  -            MessageHandler.errorln("Unknown role >" + role + "< for new 
configuration entry. \n" 
  -              +"Putting configuration with key:" + key + " into standard 
configuration.");
  -        } 
  +            MessageHandler.errorln("Unknown role >" + role +
  +                                   "< for new configuration entry. \n" +
  +                                   "Putting configuration with key:" + key + " into 
standard configuration.");
  +        }
       }
  -
  -
   }
  
  
  

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

Reply via email to