With new releases of CLDR, the minimum days per week data
is now in supplementalData.xml.  This adds functionality to
the currencygen program to parse this and store it in weeks.properties.

ChangeLog:

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

        * src/gnu/currencygen/Main.java:
        Output week data to weeks.properties.
        (SupplementalHandler.SupplementalHandler(PrintWriter,PrintWriter)):
        Add new print writer for weeks.properties.
        (SupplementalHandler.endElement(String,String,String)):
        Output week data.
        (SupplementalHandler.startDocument()): Add header for weeks.properties.
        (SupplementalHandler.startElement(String,String,String,Attributes)):
        Collect week 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/currencygen/Main.java
===================================================================
RCS file: /sources/classpath/cp-tools/src/gnu/currencygen/Main.java,v
retrieving revision 1.5
diff -u -u -r1.5 Main.java
--- src/gnu/currencygen/Main.java       30 Jan 2005 02:33:09 -0000      1.5
+++ src/gnu/currencygen/Main.java       7 Jul 2008 00:29:27 -0000
@@ -30,6 +30,8 @@
 import java.io.BufferedWriter;
 import java.io.FileInputStream;
 import java.util.HashMap;
+import java.util.Map;
+import java.util.Iterator;
 
 public class Main
 {
@@ -50,10 +52,15 @@
     FileWriter currencyFile = new FileWriter("iso4217.properties");
     BufferedWriter bWriter = new BufferedWriter(currencyFile);
     PrintWriter output = new PrintWriter(bWriter, true);
-    handler = new SupplementalHandler(output);
+    BufferedWriter weekFile = new BufferedWriter(new 
FileWriter("weeks.properties"));
+    PrintWriter wOutput = new PrintWriter(weekFile, true);
+    handler = new SupplementalHandler(output, wOutput);
     reader.setContentHandler(handler);
     reader.parse(source);
     bWriter.flush();
+    weekFile.flush();
+    bWriter.close();
+    weekFile.close();
   }
 
   static void printUsage()
@@ -92,19 +99,30 @@
   static final int STATE_REGION = 3;
   static final int STATE_SEENCURRENCY = 7;
   static final int STATE_SUPPLEMENTAL = 1;
+  static final int STATE_WEEKDATA = 10;
   static final int STATE_ZERO = 0;
-  HashMap currencyInfo = new HashMap();
+  Map currencyInfo = new HashMap();
   String currentCurrency;
   String currentRegion;
   int ignoreLevel;
   int oldState;
   PrintWriter output;
+  PrintWriter wOutput;
+  Map weekInfo = new HashMap();
 
   int state;
 
-  public SupplementalHandler(PrintWriter output)
+  /**
+   *
+   * Constructs a new handler for supplemental data.
+   *
+   * @param output the output file for the currency data.
+   * @param wOutput the output file for the week data.
+   */
+  public SupplementalHandler(PrintWriter output, PrintWriter wOutput)
   {
     this.output = output;
+    this.wOutput = wOutput;
   }
 
   void checkMultiState(int[] currentStates, int newState) throws SAXException
@@ -164,6 +182,16 @@
       checkState(STATE_FRACTIONS, STATE_CURRENCYDATA);
     else if (localName.equals("info"))
       checkState(STATE_INFO, STATE_FRACTIONS);
+    else if (localName.equals("weekData"))
+      {
+       checkState(STATE_WEEKDATA, STATE_SUPPLEMENTAL);
+       Iterator iter = weekInfo.entrySet().iterator();
+       while (iter.hasNext())
+         {
+           Map.Entry entry = (Map.Entry) iter.next();
+           wOutput.println(entry.getKey() + "=" + entry.getValue());
+         }
+      }
   }
 
   public void startDocument()
@@ -171,6 +199,9 @@
     output
       .println("# This document is automatically generated by 
gnu.currencygen");
     output.println();
+    wOutput
+      .println("# This document is automatically generated by 
gnu.currencygen");
+    wOutput.println();
     state = STATE_ZERO;
     ignoreLevel = 0;
   }
@@ -198,6 +229,24 @@
       checkState(STATE_CURRENCYDATA, STATE_FRACTIONS);
     else if (localName.equals("info"))
       checkState(STATE_FRACTIONS, STATE_INFO);
+    else if (localName.equals("weekData"))
+      checkState(STATE_SUPPLEMENTAL, STATE_WEEKDATA);
+    else if (localName.equals("minDays") && state == STATE_WEEKDATA)
+      {
+       String status = atts.getValue("draft");
+       if (status == null || status.equals("false") || 
status.equals("approved"))
+         {
+           int minDays = Integer.parseInt(atts.getValue("count"));
+           String[] territories = atts.getValue("territories").split(" ");
+           for (int a = 0; a < territories.length; ++a)
+             {
+               if (territories[a].equals("001"))
+                 wOutput.println("DEFAULT=" + minDays);
+               else
+                 weekInfo.put(territories[a], minDays);
+             }
+         }
+      }
     else
       {
         ignoreLevel++;

Reply via email to