This adds the generation of a new properties file from the supplementary
CLDR data, metazones.properties.  This allows the metazones in the zone
strings to be translated into zones of the form Continent/City e.g.
Europe/London.

ChangeLog:

2008-07-07  Andrew John Hughes  <[EMAIL PROTECTED]>

        * src/gnu/supplementgen/Main.java:
        Add support for generating metazones.properties.
        (CurrencyInfo.equals(Object)): Implemented.
        (CurrencyInfo.hashCode()): Likewise.
        (ZoneInfo): New class to act as a key for zone info.
        
(SupplementalHandler.SupplementalHandler(PrintWriter,PrintWriter,PrintWriter)):
        Add new print writer for metazones.properties.
        (SupplementalHandler.endElement(String,String,String)):
        Output zone data.
        (SupplementalHandler.startDocument()): Add header for 
metazones.properties.
        (SupplementalHandler.startElement(String,String,String,Attributes)):
        Collect zone data.

-- 
Andrew :)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint = F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8
Index: src/gnu/supplementgen/Main.java
===================================================================
RCS file: /sources/classpath/cp-tools/src/gnu/supplementgen/Main.java,v
retrieving revision 1.1
diff -u -u -r1.1 Main.java
--- src/gnu/supplementgen/Main.java     7 Jul 2008 00:46:25 -0000       1.1
+++ src/gnu/supplementgen/Main.java     7 Jul 2008 01:46:54 -0000
@@ -32,6 +32,7 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Iterator;
+import java.util.TreeMap;
 
 public class Main
 {
@@ -54,13 +55,17 @@
     PrintWriter output = new PrintWriter(bWriter, true);
     BufferedWriter weekFile = new BufferedWriter(new 
FileWriter("weeks.properties"));
     PrintWriter wOutput = new PrintWriter(weekFile, true);
-    handler = new SupplementalHandler(output, wOutput);
+    BufferedWriter zoneFile = new BufferedWriter(new 
FileWriter("metazones.properties"));
+    PrintWriter zOutput = new PrintWriter(zoneFile, true);
+    handler = new SupplementalHandler(output, wOutput, zOutput);
     reader.setContentHandler(handler);
     reader.parse(source);
     bWriter.flush();
     weekFile.flush();
+    zoneFile.flush();
     bWriter.close();
     weekFile.close();
+    zoneFile.close();
   }
 
   static void printUsage()
@@ -89,6 +94,73 @@
       this.digits = digits;
       this.rounding = rounding;
     }
+
+    public boolean equals(Object o)
+    {
+      if (o == this)
+       return true;
+      if (o == null)
+       return false;
+      if (o instanceof CurrencyInfo)
+       {
+         CurrencyInfo oInfo = (CurrencyInfo) o;
+         return oInfo.digits == digits &&
+           oInfo.rounding == rounding;
+       }
+      return false;
+    }
+
+    public int hashCode()
+    {
+      return digits * 11 + rounding * 13;
+    }
+
+  }
+
+  static class ZoneInfo
+    implements Comparable
+  {
+    String other;
+    String territory;
+
+    ZoneInfo(String other, String territory)
+    {
+      this.other = other;
+      this.territory = territory;
+    }
+
+    public boolean equals(Object o)
+    {
+      if (o == this)
+       return true;
+      if (o == null)
+       return false;
+      if (o instanceof ZoneInfo)
+       {
+         ZoneInfo oInfo = (ZoneInfo) o;
+         return (oInfo.other == null ?
+                 other == null : oInfo.other.equals(other)) &&
+           (oInfo.territory == null ?
+            territory == null : oInfo.territory.equals(territory));
+       }
+      return false;
+    }
+
+    public int hashCode()
+    {
+      return other.hashCode() * 11 +
+       territory.hashCode() * 13;
+    }
+
+    public int compareTo(Object o)
+    {
+      ZoneInfo info = (ZoneInfo) o;
+      int compared = other.compareTo(info.other);
+      if (compared == 0)
+       return territory.compareTo(info.territory);
+      return compared;
+    }
+
   }
   static final int STATE_ALTERNATE = 6;
   static final int STATE_CURRENCY = 4;
@@ -96,9 +168,11 @@
   static final int STATE_FRACTIONS = 8;
   static final int STATE_IGNORING = 2;
   static final int STATE_INFO = 9;
+  static final int STATE_MAPTIMEZONES = 12;
   static final int STATE_REGION = 3;
   static final int STATE_SEENCURRENCY = 7;
   static final int STATE_SUPPLEMENTAL = 1;
+  static final int STATE_TIMEZONEDATA = 11;
   static final int STATE_WEEKDATA = 10;
   static final int STATE_ZERO = 0;
   Map currencyInfo = new HashMap();
@@ -108,7 +182,9 @@
   int oldState;
   PrintWriter output;
   PrintWriter wOutput;
+  PrintWriter zOutput;
   Map weekInfo = new HashMap();
+  Map zoneInfo = new TreeMap();
 
   int state;
 
@@ -118,11 +194,14 @@
    *
    * @param output the output file for the currency data.
    * @param wOutput the output file for the week data.
+   * @param zOutput the output file for the zone data.
    */
-  public SupplementalHandler(PrintWriter output, PrintWriter wOutput)
+  public SupplementalHandler(PrintWriter output, PrintWriter wOutput,
+                            PrintWriter zOutput)
   {
     this.output = output;
     this.wOutput = wOutput;
+    this.zOutput = zOutput;
   }
 
   void checkMultiState(int[] currentStates, int newState) throws SAXException
@@ -192,6 +271,20 @@
            wOutput.println(entry.getKey() + "=" + entry.getValue());
          }
       }
+    else if (localName.equals("timezoneData"))
+      checkState(STATE_TIMEZONEDATA, STATE_SUPPLEMENTAL);
+    else if (localName.equals("mapTimezones") && state == STATE_MAPTIMEZONES)
+      {
+       checkState(STATE_MAPTIMEZONES, STATE_TIMEZONEDATA);
+       Iterator iter = zoneInfo.entrySet().iterator();
+       while (iter.hasNext())
+         {
+           Map.Entry entry = (Map.Entry) iter.next();
+           ZoneInfo zInfo = (ZoneInfo) entry.getKey();
+           zOutput.println(zInfo.other + "." + zInfo.territory 
+                           + "=" + entry.getValue());
+         }
+      }
   }
 
   public void startDocument()
@@ -202,7 +295,10 @@
     wOutput
       .println("# This document is automatically generated by 
gnu.supplementgen");
     wOutput.println();
-    state = STATE_ZERO;
+    zOutput
+      .println("# This document is automatically generated by 
gnu.supplementgen");
+    zOutput.println();
+   state = STATE_ZERO;
     ignoreLevel = 0;
   }
 
@@ -247,6 +343,22 @@
              }
          }
       }
+    else if (localName.equals("timezoneData"))
+      checkState(STATE_SUPPLEMENTAL, STATE_TIMEZONEDATA);
+    else if (localName.equals("mapTimezones"))
+      {
+       String type = atts.getValue("type");
+       if (type != null && type.equals("metazones"))
+         checkState(STATE_TIMEZONEDATA, STATE_MAPTIMEZONES);
+      }
+    else if (localName.equals("mapZone") && state == STATE_MAPTIMEZONES)
+      {
+       String territory = atts.getValue("territory");
+       if (territory.equals("001"))
+         territory = "DEFAULT";
+       zoneInfo.put(new ZoneInfo(atts.getValue("other"), territory),
+                    atts.getValue("type"));
+      }
     else
       {
         ignoreLevel++;

Reply via email to