This patch removes the FIXME in DateFormatSymbols,
adding support for the TimeZone and DateFormatSymbols
SPIs.

Changelog:

2007-01-03  Andrew John Hughes  <[EMAIL PROTECTED]>

        * java/text/DateFormatSymbols.java:
        (getZoneStrings(ResourceBundle)): Changed to...
        (getZoneStrings(ResourceBundle,Locale)): Added
        use of TimeZoneNamesProvider.
        (getZoneStrings()): Return either mutated zone
        strings or initial ones.
        (getInstance(Locale)): Check DateFormatSymbolsProvider
        instances.
        * java/text/spi/DateFormatSymbolsProvider.java:
        New file.
        * java/text/spi/package.html: New file.

-- 
Andrew :-)

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: java/text/DateFormatSymbols.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/DateFormatSymbols.java,v
retrieving revision 1.21
diff -u -3 -p -u -r1.21 DateFormatSymbols.java
--- java/text/DateFormatSymbols.java    29 Dec 2006 02:17:58 -0000      1.21
+++ java/text/DateFormatSymbols.java    3 Jan 2007 00:45:57 -0000
@@ -38,9 +38,19 @@ exception statement from your version. *
 
 package java.text;
 
+import gnu.java.locale.LocaleHelper;
+
+import java.text.spi.DateFormatSymbolsProvider;
+
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
+import java.util.ServiceLoader;
+import java.util.TimeZone;
+
+import java.util.spi.TimeZoneNameProvider;
 
 /**
  * This class acts as container for locale specific date/time formatting
@@ -62,6 +72,15 @@ public class DateFormatSymbols implement
   String[] shortMonths;
   String[] shortWeekdays;
   String[] weekdays;
+
+  /**
+   * The timezone strings supplied by the runtime.
+   */
+  private String[][] runtimeZoneStrings;
+
+  /**
+   * Custom timezone strings supplied by [EMAIL PROTECTED] #setZoneStrings()}.
+   */
   private String[][] zoneStrings;
 
   private static final long serialVersionUID = -5987973545549424702L;
@@ -85,22 +104,52 @@ public class DateFormatSymbols implement
     return res.getString(name).split("\u00ae");
   }
 
-  private String[][] getZoneStrings(ResourceBundle res)
+  private String[][] getZoneStrings(ResourceBundle res, Locale locale)
   {
+    List<String[]> allZones = new ArrayList<String[]>();
     try
       {
         int index = 0;
         String data = res.getString("zoneStrings");
        String[] zones = data.split("\u00a9");
-       String[][] array = new String[zones.length][];
        for (int a = 0; a < zones.length; ++a)
-         array[a] = zones[a].split("\u00ae");
-       return array;
+         allZones.add(zones[a].split("\u00ae"));
       }
     catch (MissingResourceException e)
       {
-       return new String[0][];
+       /* This means runtime support for the locale
+        * is not available, so we just include providers. */
+      }
+    for (TimeZoneNameProvider p :
+          ServiceLoader.load(TimeZoneNameProvider.class))
+      {
+       for (Locale loc : p.getAvailableLocales())
+         {
+           if (loc.equals(locale))
+             {
+               for (String id : TimeZone.getAvailableIDs())
+                 {
+                   String[] z = new String[5];
+                   z[0] = id;
+                   z[1] = p.getDisplayName(id, false,
+                                           TimeZone.LONG,
+                                           locale);
+                   z[2] = p.getDisplayName(id, false,
+                                           TimeZone.SHORT,
+                                           locale);
+                   z[3] = p.getDisplayName(id, true,
+                                           TimeZone.LONG,
+                                           locale);
+                   z[4] = p.getDisplayName(id, true,
+                                           TimeZone.SHORT,
+                                           locale);
+                   allZones.add(z);
+                 }
+               break;
+             }
+         }
       }
+    return allZones.toArray(new String[allZones.size()][]);
   }
   
   private String[] formatsForKey(ResourceBundle res, String key) 
@@ -139,7 +188,7 @@ public class DateFormatSymbols implement
     shortMonths = getStringArray(res, "shortMonths");
     shortWeekdays = getStringArray(res, "shortWeekdays");
     weekdays = getStringArray(res, "weekdays");
-    zoneStrings = getZoneStrings(res);
+    runtimeZoneStrings = getZoneStrings(res, locale);
     dateFormats = formatsForKey(res, "DateFormat");
     timeFormats = formatsForKey(res, "TimeFormat");
   }
@@ -286,12 +335,21 @@ public class DateFormatSymbols implement
    * <li>3 - The long name of the time zone (daylight savings time).</li>
    * <li>4 - the short name of the time zone (daylight savings time).</li>
    * </ul>
+   * <p>
+   * If [EMAIL PROTECTED] #setZoneStrings(String[][])} has been called, then 
the value
+   * passed to this will be returned.  Otherwise the returned array contains
+   * zone names provided by the runtime environment and any
+   * [EMAIL PROTECTED] java.util.spi.TimeZoneProvider} instances.
+   * </p>
    *
    * @return The list of time zone display strings.
+   * @see #setZoneStrings(String[][])
    */
-  public String[] [] getZoneStrings ()
+  public String[][] getZoneStrings()
   {
-    return zoneStrings;
+    if (zoneStrings != null)
+      return zoneStrings;
+    return runtimeZoneStrings;
   }
 
   /**
@@ -590,9 +648,24 @@ public class DateFormatSymbols implement
       }
     catch (MissingResourceException e)
       {
-       /* FIXME: Check the service provider */
-       return null;
+       /* This means runtime support for the locale
+        * is not available, so we check providers. */
+      }
+    for (DateFormatSymbolsProvider p :
+          ServiceLoader.load(DateFormatSymbolsProvider.class))
+      {
+       for (Locale loc : p.getAvailableLocales())
+         {
+           if (loc.equals(locale))
+             {
+               DateFormatSymbols syms = p.getInstance(locale);
+               if (syms != null)
+                 return syms;
+               break;
+             }
+         }
       }
+    return getInstance(LocaleHelper.getFallbackLocale(locale));
   }
 
 }
Index: java/text/spi/DateFormatSymbolsProvider.java
===================================================================
RCS file: java/text/spi/DateFormatSymbolsProvider.java
diff -N java/text/spi/DateFormatSymbolsProvider.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ java/text/spi/DateFormatSymbolsProvider.java        3 Jan 2007 00:45:57 
-0000
@@ -0,0 +1,79 @@
+/* DateFormatSymbolsProvider.java -- Providers of localized currency symbols
+   Copyright (C) 2007 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., 51 Franklin Street, 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. */
+
+package java.text.spi;
+
+import java.text.DateFormatSymbols;
+
+import java.util.Locale;
+
+import java.util.spi.LocaleServiceProvider;
+
+/**
+ * A [EMAIL PROTECTED] DateFormatSymbolsProvider} provides localized
+ * instances of [EMAIL PROTECTED] java.text.DateFormatSymbols}.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.6
+ */
+public abstract class DateFormatSymbolsProvider
+  extends LocaleServiceProvider
+{
+
+  /**
+   * Constructs a new [EMAIL PROTECTED] DateFormatSymbolsProvider}.
+   * Provided for implicit invocation by subclasses.
+   */
+  protected DateFormatSymbolsProvider()
+  {
+  }
+
+  /**
+   * Returns a [EMAIL PROTECTED] java.text.DateFormatSymbols} instance
+   * for the specified [EMAIL PROTECTED] java.util.Locale}.
+   *
+   * @param locale the locale to express the symbols in.
+   * @return the localized instance.
+   * @throws NullPointerException if the locale is null.
+   * @throws IllegalArgumentException if the locale is not one
+   *                                  returned by
+   *                                  [EMAIL PROTECTED] getAvailableLocales()}
+   * @see java.text.DateFormatSymbols#getInstance(java.util.Locale)
+   */
+  public abstract DateFormatSymbols getInstance(Locale locale);
+
+}
Index: java/text/spi/package.html
===================================================================
RCS file: java/text/spi/package.html
diff -N java/text/spi/package.html
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ java/text/spi/package.html  3 Jan 2007 00:45:57 -0000
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in java.text.spi package.
+   Copyright (C) 2007 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., 51 Franklin Street, 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. -->
+
+<html>
+<head><title>GNU Classpath - java.text.spi</title></head>
+
+<body>
+
+<p>
+A series of service provider interfaces for use by the
+classes in <code>java.text</code>.
+</p>
+<p><span style="font-weight: bold;">Since</span>: 1.6</p>
+</body>
+</html>

Attachment: signature.asc
Description: Digital signature

Reply via email to