This renames the currencygen tool to supplementgen to denote
its new role as generating all necessary data from supplementaryData.xml.

ChangeLog:

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

        * Makefile.am: Replace currencygen with supplementgen.
        * bin/currencygen.in: Renamed to...
        * bin/supplementgen.in: ...this.
        * configure.ac: Replace currencygen with supplementgen.
        * src/gnu/currencygen/Main.java: Renamed to...
        * src/gnu/supplementgen/Main.java: ...this and
        updated version/copyright output.


-- 
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: Makefile.am
===================================================================
RCS file: /sources/classpath/cp-tools/Makefile.am,v
retrieving revision 1.15
diff -u -u -r1.15 Makefile.am
--- Makefile.am 3 Jul 2008 21:31:47 -0000       1.15
+++ Makefile.am 7 Jul 2008 00:44:00 -0000
@@ -19,7 +19,7 @@
 LTGCJCOMPILE = $(LIBGCJCOMPILE) -MF $(@:.lo=.d)
 
 if ENABLE_GCJ_BINARY
-bin_PROGRAMS = localegen currencygen
+bin_PROGRAMS = localegen supplementgen
 lib_LTLIBRARIES = libcpgenerators.la 
 if USE_GNUBYTECODE
 bin_PROGRAMS += gjavap gjavah
@@ -28,7 +28,7 @@
 nodist_libbytecode_la_SOURCES = $(BYTECODE_JAR)
 endif
 else
-bin_SCRIPTS = bin/localegen bin/currencygen
+bin_SCRIPTS = bin/localegen bin/supplementgen
 data_JARS = cpgenerators-$(VERSION).jar
 BUILT_SOURCES = $(data_JARS)
 if USE_GNUBYTECODE
@@ -60,10 +60,10 @@
 localegen_LDFLAGS = --main=gnu.localegen.Main \
        -Dgnu.gcj.runtime.VMClassLoader.library_control=never
 
-currencygen_SOURCES =
-currencygen_LINK = $(GCJLINK)
-currencygen_LDADD = libcpgenerators.la 
-currencygen_LDFLAGS = --main=gnu.currencygen.Main \
+supplementgen_SOURCES =
+supplementgen_LINK = $(GCJLINK)
+supplementgen_LDADD = libcpgenerators.la 
+supplementgen_LDFLAGS = --main=gnu.supplementgen.Main \
        -Dgnu.gcj.runtime.VMClassLoader.library_control=never
 
 else
@@ -71,7 +71,7 @@
 gjavap: $(srcdir)/bin/gjavap.in
 gjavah: $(srcdir)/bin/gjavah.in
 localegen: $(srcdir)/bin/localegen.in
-currencygen: $(srcdir)/bin/currencygen.in
+supplementgen: $(srcdir)/bin/supplementgen.in
 
 endif # if ENABLE_GCJ_BINARY
 
@@ -129,10 +129,10 @@
        src/gnu/localegen/JavaGenerator.java \
        src/gnu/localegen/Main.java
 
-currencygen_java_files = \
-       src/gnu/currencygen/Main.java
+supplementgen_java_files = \
+       src/gnu/supplementgen/Main.java
 
-cpgenerators_jar_SOURCES = $(localegen_java_files) $(currencygen_java_files)
+cpgenerators_jar_SOURCES = $(localegen_java_files) $(supplementgen_java_files)
 
 if ENABLE_GCJ_BINARY
 libcpgenerators_la_SOURCES = $(cpgenerators_jar_SOURCES)
@@ -141,7 +141,7 @@
 
 cpgenerators-$(VERSION).jar: createdirectories $(cpgenerators_jar_CLASSES)
        (cd classes; \
-       $(JAR) cf ../$@ gnu/ldml gnu/localegen gnu/currencygen; \
+       $(JAR) cf ../$@ gnu/ldml gnu/localegen gnu/supplementgen; \
        cd ..)
 
 $(cpgenerators_jar_CLASSES): classes/gnu/%.class: $(srcdir)/src/gnu/%.java
Index: configure.ac
===================================================================
RCS file: /sources/classpath/cp-tools/configure.ac,v
retrieving revision 1.8
diff -u -u -r1.8 configure.ac
--- configure.ac        29 Jun 2008 17:09:09 -0000      1.8
+++ configure.ac        7 Jul 2008 00:44:00 -0000
@@ -105,9 +105,9 @@
 
 AC_CONFIG_FILES([Makefile])
 if test "x${enable_gcj}" = xno; then
-  AC_CONFIG_FILES([bin/localegen bin/currencygen])
+  AC_CONFIG_FILES([bin/localegen bin/supplementgen])
   AC_CONFIG_COMMANDS([localegen],[chmod 755 bin/localegen])
-  AC_CONFIG_COMMANDS([currencygen],[chmod 755 bin/currencygen])
+  AC_CONFIG_COMMANDS([supplementgen],[chmod 755 bin/supplementgen])
   if test "x${with_gnubytecode}" = xyes
   then
     AC_CONFIG_FILES([bin/gjavap bin/gjavah])
Index: bin/currencygen.in
===================================================================
RCS file: bin/currencygen.in
diff -N bin/currencygen.in
--- bin/currencygen.in  29 Jun 2008 01:07:02 -0000      1.1
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,48 +0,0 @@
-#!/bin/sh
-
-## Copyright (C) 2008 Free Software Foundation, Inc.
-##
-## This file is a part of GNU Classpath.
-##
-## GNU Classpath is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 2 of the License, or (at
-## your option) any later version.
-##
-## GNU Classpath is distributed in the hope that it will be useful, but
-## WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-## General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with GNU Classpath; if not, write to the Free Software
-## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
-## USA.
-##
-## Linking this library statically or dynamically with other modules is
-## making a combined work based on this library.  Thus, the terms and
-## conditions of the GNU General Public License cover the whole
-## combination.
-##
-## As a special exception, the copyright holders of this library give you
-## permission to link this library with independent modules to produce an
-## executable, regardless of the license terms of these independent
-## modules, and to copy and distribute the resulting executable under
-## terms of your choice, provided that you also meet, for each linked
-## independent module, the terms and conditions of the license of that
-## module.  An independent module is a module which is not derived from
-## or based on this library.  If you modify this library, you may extend
-## this exception to your version of the library, but you are not
-## obligated to do so.  If you do not wish to do so, delete this
-## exception statement from your version.
-##
-##
-## A simple shell script to launch the GNU Classpath currencygen tool.
-##
-
[EMAIL PROTECTED]@
[EMAIL PROTECTED]@
[EMAIL PROTECTED]@/@PACKAGE@
-tools_cp=${tools_dir}/cpgenerators.jar
-
-exec @JAVA@ -classpath "${tools_cp}" gnu.currencygen.Main "$@"
Index: bin/supplementgen.in
===================================================================
RCS file: bin/supplementgen.in
diff -N bin/supplementgen.in
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ bin/supplementgen.in        7 Jul 2008 00:44:00 -0000
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+## Copyright (C) 2008 Free Software Foundation, Inc.
+##
+## This file is a part of GNU Classpath.
+##
+## GNU Classpath is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or (at
+## your option) any later version.
+##
+## GNU Classpath is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with GNU Classpath; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+## USA.
+##
+## Linking this library statically or dynamically with other modules is
+## making a combined work based on this library.  Thus, the terms and
+## conditions of the GNU General Public License cover the whole
+## combination.
+##
+## As a special exception, the copyright holders of this library give you
+## permission to link this library with independent modules to produce an
+## executable, regardless of the license terms of these independent
+## modules, and to copy and distribute the resulting executable under
+## terms of your choice, provided that you also meet, for each linked
+## independent module, the terms and conditions of the license of that
+## module.  An independent module is a module which is not derived from
+## or based on this library.  If you modify this library, you may extend
+## this exception to your version of the library, but you are not
+## obligated to do so.  If you do not wish to do so, delete this
+## exception statement from your version.
+##
+##
+## A simple shell script to launch the GNU Classpath currencygen tool.
+##
+
[EMAIL PROTECTED]@
[EMAIL PROTECTED]@
[EMAIL PROTECTED]@/@PACKAGE@
+tools_cp=${tools_dir}/cpgenerators.jar
+
+exec @JAVA@ -classpath "${tools_cp}" gnu.supplementgen.Main "$@"
Index: src/gnu/currencygen/Main.java
===================================================================
RCS file: src/gnu/currencygen/Main.java
diff -N src/gnu/currencygen/Main.java
--- src/gnu/currencygen/Main.java       7 Jul 2008 00:33:53 -0000       1.6
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,301 +0,0 @@
-/*
- * gnu.currencygen.Main Copyright (C) 2004 Free Software Foundation,
- * Inc.
- *
- * This file is part of GNU Classpath.
- *
- * GNU Classpath is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2, or (at your option) any later 
version.
- *
- * GNU Classpath is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * GNU Classpath; see the file COPYING. If not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-package gnu.currencygen;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.helpers.DefaultHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.InputSource;
-import org.xml.sax.helpers.XMLReaderFactory;
-import java.io.PrintWriter;
-import java.io.FileWriter;
-import java.io.BufferedWriter;
-import java.io.FileInputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Iterator;
-
-public class Main
-{
-
-  static public void main(String args[]) throws Exception
-  {
-    XMLReader reader;
-    SupplementalHandler handler;
-    InputSource source;
-    printVersion();
-    if (args.length != 1)
-      {
-        printUsage();
-        return;
-      }
-    reader = XMLReaderFactory.createXMLReader();
-    source = new InputSource(new FileInputStream(args[0]));
-    FileWriter currencyFile = new FileWriter("iso4217.properties");
-    BufferedWriter bWriter = new BufferedWriter(currencyFile);
-    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);
-    reader.setContentHandler(handler);
-    reader.parse(source);
-    bWriter.flush();
-    weekFile.flush();
-    bWriter.close();
-    weekFile.close();
-  }
-
-  static void printUsage()
-  {
-    System.out.println(" Usage: [filename]");
-    System.out.println();
-  }
-  static void printVersion()
-  {
-    System.out
-      .println(" This is the LDML to GNU Classpath converter (currency part)");
-    System.out.println("   Copyright (C) 2004 The Free Software Foundation.");
-    System.out.println();
-  }
-}
-class SupplementalHandler extends DefaultHandler
-{
-
-  static class CurrencyInfo
-  {
-    int digits;
-    int rounding;
-
-    CurrencyInfo(int digits, int rounding)
-    {
-      this.digits = digits;
-      this.rounding = rounding;
-    }
-  }
-  static final int STATE_ALTERNATE = 6;
-  static final int STATE_CURRENCY = 4;
-  static final int STATE_CURRENCYDATA = 5;
-  static final int STATE_FRACTIONS = 8;
-  static final int STATE_IGNORING = 2;
-  static final int STATE_INFO = 9;
-  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;
-  Map currencyInfo = new HashMap();
-  String currentCurrency;
-  String currentRegion;
-  int ignoreLevel;
-  int oldState;
-  PrintWriter output;
-  PrintWriter wOutput;
-  Map weekInfo = new HashMap();
-
-  int state;
-
-  /**
-   *
-   * 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
-  {
-    int i;
-    for (i = 0; i < currentStates.length; i++)
-      {
-        if (currentStates[i] == state)
-          break;
-      }
-    if (i == currentStates.length)
-      throw new SAXException("Invalid current state " + state);
-    oldState = state;
-    state = newState;
-  }
-
-  void checkState(int currentState, int newState) throws SAXException
-  {
-    if (currentState != state)
-      throw new SAXException("Invalid current state " + currentState
-                             + " (was expecting " + state + ")");
-    oldState = state;
-    state = newState;
-  }
-
-  public void endElement(String uri, String localName, String qName)
-    throws SAXException
-  {
-    if (ignoreLevel > 0)
-      {
-        ignoreLevel--;
-        return;
-      }
-    if (state == STATE_SEENCURRENCY || state == STATE_REGION)
-      {
-        output.println();
-        CurrencyInfo info = (CurrencyInfo) currencyInfo.get(currentCurrency);
-        if (info == null)
-          info = (CurrencyInfo) currencyInfo.get("DEFAULT");
-        if (info != null)
-          {
-            output.println(currentRegion + ".fractionDigits=" + info.digits);
-          }
-      }
-    if (localName.equals("supplementalData"))
-      checkState(STATE_SUPPLEMENTAL, STATE_ZERO);
-    else if (localName.equals("currencyData"))
-      checkState(STATE_CURRENCYDATA, STATE_SUPPLEMENTAL);
-    else if (localName.equals("region"))
-      checkMultiState(new int[] { STATE_SEENCURRENCY, STATE_REGION },
-                      STATE_CURRENCYDATA);
-    else if (localName.equals("currency"))
-      checkState(STATE_CURRENCY, STATE_SEENCURRENCY);
-    else if (localName.equals("alternate"))
-      checkState(STATE_ALTERNATE, STATE_CURRENCY);
-    else if (localName.equals("fractions"))
-      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()
-  {
-    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;
-  }
-
-  public void startElement(String uri, String localName, String qName,
-                           Attributes atts) throws SAXException
-  {
-    if (ignoreLevel > 0)
-      {
-        ignoreLevel++;
-        return;
-      }
-    if (localName.equals("supplementalData"))
-      checkState(STATE_ZERO, STATE_SUPPLEMENTAL);
-    else if (localName.equals("currencyData"))
-      checkState(STATE_SUPPLEMENTAL, STATE_CURRENCYDATA);
-    else if (localName.equals("region"))
-      checkState(STATE_CURRENCYDATA, STATE_REGION);
-    else if (localName.equals("currency"))
-      checkMultiState(new int[] { STATE_SEENCURRENCY, STATE_REGION },
-                      STATE_CURRENCY);
-    else if (localName.equals("alternate"))
-      checkState(STATE_CURRENCY, STATE_ALTERNATE);
-    else if (localName.equals("fractions"))
-      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++;
-        return;
-      }
-    if (state == STATE_REGION)
-      {
-        String tRegion = (String) atts.getValue("iso3166");
-        if (tRegion == null)
-          throw new SAXException("region must have a iso3166 attribute");
-        currentRegion = tRegion;
-        output.print(tRegion + ".currency=");
-      }
-    if (state == STATE_INFO)
-      {
-        String currencyCode = (String) atts.getValue("iso4217");
-        String digits = (String) atts.getValue("digits");
-        String rounding = (String) atts.getValue("rounding");
-        if (currencyCode == null || digits == null || rounding == null)
-          throw new SAXException(
-                                 "currency info must have an iso4217, a digits 
and a rounding attribute (here we get "
-                                                                  + 
currencyCode
-                                                                  + ","
-                                                                  + digits
-                                                                  + ","
-                                                                  + rounding
-                                                                  + ")");
-        currencyInfo.put(currencyCode, new CurrencyInfo(Integer
-          .parseInt(digits), Integer.parseInt(rounding)));
-      }
-    if (state == STATE_CURRENCY || state == STATE_ALTERNATE)
-      {
-        String tName = (String) atts.getValue("iso4217");
-        if (tName == null)
-          throw new SAXException("currency must have a iso 4217 attribute");
-        if (state == STATE_CURRENCY)
-          currentCurrency = tName;
-        // We only treat current currencies.
-        if (atts.getValue("before") == null)
-          {
-            if (oldState == STATE_SEENCURRENCY || state == STATE_ALTERNATE)
-              output.print(',');
-            output.print(tName);
-          }
-        else
-          {
-            System.err.println("WARNING: before not supported (value="
-                               + atts.getValue("before") + ")");
-          }
-      }
-  }
-}
Index: src/gnu/supplementgen/Main.java
===================================================================
RCS file: src/gnu/supplementgen/Main.java
diff -N src/gnu/supplementgen/Main.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/gnu/supplementgen/Main.java     7 Jul 2008 00:44:01 -0000
@@ -0,0 +1,301 @@
+/*
+ * gnu.supplementgen.Main Copyright (C) 2004 Free Software Foundation,
+ * Inc.
+ *
+ * This file is part of GNU Classpath.
+ *
+ * GNU Classpath is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2, or (at your option) any later 
version.
+ *
+ * GNU Classpath is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Classpath; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package gnu.supplementgen;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.helpers.XMLReaderFactory;
+import java.io.PrintWriter;
+import java.io.FileWriter;
+import java.io.BufferedWriter;
+import java.io.FileInputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Iterator;
+
+public class Main
+{
+
+  static public void main(String args[]) throws Exception
+  {
+    XMLReader reader;
+    SupplementalHandler handler;
+    InputSource source;
+    printVersion();
+    if (args.length != 1)
+      {
+        printUsage();
+        return;
+      }
+    reader = XMLReaderFactory.createXMLReader();
+    source = new InputSource(new FileInputStream(args[0]));
+    FileWriter currencyFile = new FileWriter("iso4217.properties");
+    BufferedWriter bWriter = new BufferedWriter(currencyFile);
+    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);
+    reader.setContentHandler(handler);
+    reader.parse(source);
+    bWriter.flush();
+    weekFile.flush();
+    bWriter.close();
+    weekFile.close();
+  }
+
+  static void printUsage()
+  {
+    System.out.println(" Usage: [filename]");
+    System.out.println();
+  }
+  static void printVersion()
+  {
+    System.out
+      .println(" This is the LDML to GNU Classpath converter (supplementary 
data part)");
+    System.out.println("   Copyright (C) 2004, 2008 The Free Software 
Foundation.");
+    System.out.println();
+  }
+}
+class SupplementalHandler extends DefaultHandler
+{
+
+  static class CurrencyInfo
+  {
+    int digits;
+    int rounding;
+
+    CurrencyInfo(int digits, int rounding)
+    {
+      this.digits = digits;
+      this.rounding = rounding;
+    }
+  }
+  static final int STATE_ALTERNATE = 6;
+  static final int STATE_CURRENCY = 4;
+  static final int STATE_CURRENCYDATA = 5;
+  static final int STATE_FRACTIONS = 8;
+  static final int STATE_IGNORING = 2;
+  static final int STATE_INFO = 9;
+  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;
+  Map currencyInfo = new HashMap();
+  String currentCurrency;
+  String currentRegion;
+  int ignoreLevel;
+  int oldState;
+  PrintWriter output;
+  PrintWriter wOutput;
+  Map weekInfo = new HashMap();
+
+  int state;
+
+  /**
+   *
+   * 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
+  {
+    int i;
+    for (i = 0; i < currentStates.length; i++)
+      {
+        if (currentStates[i] == state)
+          break;
+      }
+    if (i == currentStates.length)
+      throw new SAXException("Invalid current state " + state);
+    oldState = state;
+    state = newState;
+  }
+
+  void checkState(int currentState, int newState) throws SAXException
+  {
+    if (currentState != state)
+      throw new SAXException("Invalid current state " + currentState
+                             + " (was expecting " + state + ")");
+    oldState = state;
+    state = newState;
+  }
+
+  public void endElement(String uri, String localName, String qName)
+    throws SAXException
+  {
+    if (ignoreLevel > 0)
+      {
+        ignoreLevel--;
+        return;
+      }
+    if (state == STATE_SEENCURRENCY || state == STATE_REGION)
+      {
+        output.println();
+        CurrencyInfo info = (CurrencyInfo) currencyInfo.get(currentCurrency);
+        if (info == null)
+          info = (CurrencyInfo) currencyInfo.get("DEFAULT");
+        if (info != null)
+          {
+            output.println(currentRegion + ".fractionDigits=" + info.digits);
+          }
+      }
+    if (localName.equals("supplementalData"))
+      checkState(STATE_SUPPLEMENTAL, STATE_ZERO);
+    else if (localName.equals("currencyData"))
+      checkState(STATE_CURRENCYDATA, STATE_SUPPLEMENTAL);
+    else if (localName.equals("region"))
+      checkMultiState(new int[] { STATE_SEENCURRENCY, STATE_REGION },
+                      STATE_CURRENCYDATA);
+    else if (localName.equals("currency"))
+      checkState(STATE_CURRENCY, STATE_SEENCURRENCY);
+    else if (localName.equals("alternate"))
+      checkState(STATE_ALTERNATE, STATE_CURRENCY);
+    else if (localName.equals("fractions"))
+      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()
+  {
+    output
+      .println("# This document is automatically generated by 
gnu.supplementgen");
+    output.println();
+    wOutput
+      .println("# This document is automatically generated by 
gnu.supplementgen");
+    wOutput.println();
+    state = STATE_ZERO;
+    ignoreLevel = 0;
+  }
+
+  public void startElement(String uri, String localName, String qName,
+                           Attributes atts) throws SAXException
+  {
+    if (ignoreLevel > 0)
+      {
+        ignoreLevel++;
+        return;
+      }
+    if (localName.equals("supplementalData"))
+      checkState(STATE_ZERO, STATE_SUPPLEMENTAL);
+    else if (localName.equals("currencyData"))
+      checkState(STATE_SUPPLEMENTAL, STATE_CURRENCYDATA);
+    else if (localName.equals("region"))
+      checkState(STATE_CURRENCYDATA, STATE_REGION);
+    else if (localName.equals("currency"))
+      checkMultiState(new int[] { STATE_SEENCURRENCY, STATE_REGION },
+                      STATE_CURRENCY);
+    else if (localName.equals("alternate"))
+      checkState(STATE_CURRENCY, STATE_ALTERNATE);
+    else if (localName.equals("fractions"))
+      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++;
+        return;
+      }
+    if (state == STATE_REGION)
+      {
+        String tRegion = (String) atts.getValue("iso3166");
+        if (tRegion == null)
+          throw new SAXException("region must have a iso3166 attribute");
+        currentRegion = tRegion;
+        output.print(tRegion + ".currency=");
+      }
+    if (state == STATE_INFO)
+      {
+        String currencyCode = (String) atts.getValue("iso4217");
+        String digits = (String) atts.getValue("digits");
+        String rounding = (String) atts.getValue("rounding");
+        if (currencyCode == null || digits == null || rounding == null)
+          throw new SAXException(
+                                 "currency info must have an iso4217, a digits 
and a rounding attribute (here we get "
+                                                                  + 
currencyCode
+                                                                  + ","
+                                                                  + digits
+                                                                  + ","
+                                                                  + rounding
+                                                                  + ")");
+        currencyInfo.put(currencyCode, new CurrencyInfo(Integer
+          .parseInt(digits), Integer.parseInt(rounding)));
+      }
+    if (state == STATE_CURRENCY || state == STATE_ALTERNATE)
+      {
+        String tName = (String) atts.getValue("iso4217");
+        if (tName == null)
+          throw new SAXException("currency must have a iso 4217 attribute");
+        if (state == STATE_CURRENCY)
+          currentCurrency = tName;
+        // We only treat current currencies.
+        if (atts.getValue("before") == null)
+          {
+            if (oldState == STATE_SEENCURRENCY || state == STATE_ALTERNATE)
+              output.print(',');
+            output.print(tName);
+          }
+        else
+          {
+            System.err.println("WARNING: before not supported (value="
+                               + atts.getValue("before") + ")");
+          }
+      }
+  }
+}

Reply via email to