2002-05-10 01:41:42 +02:00
|
|
|
/* ResourceBundle -- aids in loading resource bundles
|
2004-11-24 14:26:27 +01:00
|
|
|
Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004
|
|
|
|
Free Software Foundation, Inc.
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
This file is part of GNU Classpath.
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
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.
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
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.
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
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.
|
1999-10-17 05:11:50 +02:00
|
|
|
|
2002-01-22 23:40:42 +01:00
|
|
|
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. */
|
1999-04-07 16:42:40 +02:00
|
|
|
|
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
package java.util;
|
2002-05-10 01:41:42 +02:00
|
|
|
|
2004-10-18 14:22:51 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2001-08-31 23:31:20 +02:00
|
|
|
import java.lang.ref.Reference;
|
|
|
|
import java.lang.ref.SoftReference;
|
|
|
|
|
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* A resource bundle contains locale-specific data. If you need localized
|
|
|
|
* data, you can load a resource bundle that matches the locale with
|
|
|
|
* <code>getBundle</code>. Now you can get your object by calling
|
|
|
|
* <code>getObject</code> or <code>getString</code> on that bundle.
|
|
|
|
*
|
|
|
|
* <p>When a bundle is demanded for a specific locale, the ResourceBundle
|
MarshalledObject.java, [...]: Fixed javadoc, coding style and argument names all over.
2004-04-20 Michael Koch <konqueror@gmx.de>
* java/rmi/MarshalledObject.java,
java/rmi/Naming.java,
java/rmi/RemoteException.java,
java/rmi/activation/ActivationException.java,
java/rmi/server/ServerCloneException.java,
java/security/AccessController.java,
java/security/AlgorithmParameterGenerator.java,
java/security/AlgorithmParameters.java,
java/security/CodeSource.java,
java/security/Identity.java,
java/security/IdentityScope.java,
java/security/KeyPairGenerator.java,
java/security/KeyStore.java,
java/security/Security.java,
java/security/Signature.java,
java/security/SignatureSpi.java,
java/security/SignedObject.java,
java/security/spec/DSAParameterSpec.java,
java/security/spec/DSAPrivateKeySpec.java,
java/security/spec/DSAPublicKeySpec.java,
java/sql/Array.java,
java/sql/DatabaseMetaData.java,
java/sql/ResultSet.java,
java/text/ChoiceFormat.java,
java/text/CollationElementIterator.java,
java/text/CollationKey.java,
java/text/Collator.java,
java/text/DateFormat.java,
java/text/DateFormatSymbols.java,
java/text/DecimalFormatSymbols.java,
java/text/Format.java,
java/text/ParsePosition.java,
java/text/RuleBasedCollator.java,
java/text/SimpleDateFormat.java,
java/text/StringCharacterIterator.java,
java/util/Collections.java,
java/util/PropertyResourceBundle.java,
java/util/ResourceBundle.java,
java/util/StringTokenizer.java,
java/util/jar/Attributes.java,
java/util/logging/ConsoleHandler.java,
java/util/logging/LogManager.java,
java/util/logging/MemoryHandler.java,
java/util/logging/SocketHandler.java,
javax/naming/NamingException.java:
Fixed javadoc, coding style and argument names all over.
From-SVN: r80906
2004-04-20 16:45:10 +02:00
|
|
|
* is searched in following order (<i>def. language</i> stands for the
|
2002-05-10 01:41:42 +02:00
|
|
|
* two letter ISO language code of the default locale (see
|
2001-08-31 23:31:20 +02:00
|
|
|
* <code>Locale.getDefault()</code>).
|
|
|
|
*
|
2002-05-10 01:41:42 +02:00
|
|
|
<pre>baseName_<i>language code</i>_<i>country code</i>_<i>variant</i>
|
|
|
|
baseName_<i>language code</i>_<i>country code</i>
|
|
|
|
baseName_<i>language code</i>
|
|
|
|
baseName_<i>def. language</i>_<i>def. country</i>_<i>def. variant</i>
|
|
|
|
baseName_<i>def. language</i>_<i>def. country</i>
|
|
|
|
baseName_<i>def. language</i>
|
|
|
|
baseName</pre>
|
|
|
|
*
|
2002-09-23 19:56:33 +02:00
|
|
|
* <p>A bundle is backed up by less specific bundles (omitting variant, country
|
2002-05-10 01:41:42 +02:00
|
|
|
* or language). But it is not backed up by the default language locale.
|
|
|
|
*
|
|
|
|
* <p>If you provide a bundle for a given locale, say
|
2001-08-31 23:31:20 +02:00
|
|
|
* <code>Bundle_en_UK_POSIX</code>, you must also provide a bundle for
|
|
|
|
* all sub locales, ie. <code>Bundle_en_UK</code>, <code>Bundle_en</code>, and
|
|
|
|
* <code>Bundle</code>.
|
|
|
|
*
|
2002-05-10 01:41:42 +02:00
|
|
|
* <p>When a bundle is searched, we look first for a class with the given
|
|
|
|
* name, then for a file with <code>.properties</code> extension in the
|
|
|
|
* classpath. The name must be a fully qualified classname (with dots as
|
|
|
|
* path separators).
|
|
|
|
*
|
|
|
|
* <p>(Note: This implementation always backs up the class with a properties
|
|
|
|
* file if that is existing, but you shouldn't rely on this, if you want to
|
|
|
|
* be compatible to the standard JDK.)
|
|
|
|
*
|
|
|
|
* @author Jochen Hoenicke
|
|
|
|
* @author Eric Blake (ebb9@email.byu.edu)
|
2001-08-31 23:31:20 +02:00
|
|
|
* @see Locale
|
2002-05-10 01:41:42 +02:00
|
|
|
* @see ListResourceBundle
|
2001-08-31 23:31:20 +02:00
|
|
|
* @see PropertyResourceBundle
|
2002-05-10 01:41:42 +02:00
|
|
|
* @since 1.1
|
|
|
|
* @status updated to 1.4
|
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
public abstract class ResourceBundle
|
|
|
|
{
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* The parent bundle. This is consulted when you call getObject and there
|
|
|
|
* is no such resource in the current bundle. This field may be null.
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
1999-04-07 16:42:40 +02:00
|
|
|
protected ResourceBundle parent;
|
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* The locale of this resource bundle. You can read this with
|
2001-08-31 23:31:20 +02:00
|
|
|
* <code>getLocale</code> and it is automatically set in
|
2002-05-10 01:41:42 +02:00
|
|
|
* <code>getBundle</code>.
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
|
|
|
private Locale locale;
|
|
|
|
|
2002-12-05 01:49:30 +01:00
|
|
|
private static native ClassLoader getCallingClassLoader();
|
2001-11-04 05:15:09 +01:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2004-07-10 04:14:30 +02:00
|
|
|
* The resource bundle cache.
|
2002-05-10 01:41:42 +02:00
|
|
|
*/
|
2004-07-10 04:14:30 +02:00
|
|
|
private static Map bundleCache;
|
2002-12-09 00:38:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The last default Locale we saw. If this ever changes then we have to
|
|
|
|
* reset our caches.
|
|
|
|
*/
|
|
|
|
private static Locale lastDefaultLocale;
|
2002-05-10 01:41:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The `empty' locale is created once in order to optimize
|
|
|
|
* tryBundle().
|
|
|
|
*/
|
|
|
|
private static final Locale emptyLocale = new Locale("");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The constructor. It does nothing special.
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
|
|
|
public ResourceBundle()
|
2000-07-12 05:32:07 +02:00
|
|
|
{
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Get a String from this resource bundle. Since most localized Objects
|
|
|
|
* are Strings, this method provides a convenient way to get them without
|
|
|
|
* casting.
|
|
|
|
*
|
|
|
|
* @param key the name of the resource
|
|
|
|
* @throws MissingResourceException if the resource can't be found
|
|
|
|
* @throws NullPointerException if key is null
|
|
|
|
* @throws ClassCastException if resource is not a string
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
2002-05-10 01:41:42 +02:00
|
|
|
public final String getString(String key)
|
2001-08-31 23:31:20 +02:00
|
|
|
{
|
|
|
|
return (String) getObject(key);
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Get an array of Strings from this resource bundle. This method
|
2001-08-31 23:31:20 +02:00
|
|
|
* provides a convenient way to get it without casting.
|
2002-05-10 01:41:42 +02:00
|
|
|
*
|
|
|
|
* @param key the name of the resource
|
|
|
|
* @throws MissingResourceException if the resource can't be found
|
|
|
|
* @throws NullPointerException if key is null
|
|
|
|
* @throws ClassCastException if resource is not a string
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
|
|
|
public final String[] getStringArray(String key)
|
|
|
|
{
|
|
|
|
return (String[]) getObject(key);
|
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Get an object from this resource bundle. This will call
|
|
|
|
* <code>handleGetObject</code> for this resource and all of its parents,
|
|
|
|
* until it finds a non-null resource.
|
|
|
|
*
|
|
|
|
* @param key the name of the resource
|
|
|
|
* @throws MissingResourceException if the resource can't be found
|
|
|
|
* @throws NullPointerException if key is null
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
2002-05-10 01:41:42 +02:00
|
|
|
public final Object getObject(String key)
|
2001-08-31 23:31:20 +02:00
|
|
|
{
|
|
|
|
for (ResourceBundle bundle = this; bundle != null; bundle = bundle.parent)
|
2004-07-10 04:14:30 +02:00
|
|
|
{
|
|
|
|
Object o = bundle.handleGetObject(key);
|
|
|
|
if (o != null)
|
|
|
|
return o;
|
|
|
|
}
|
2003-04-29 13:36:34 +02:00
|
|
|
|
|
|
|
throw new MissingResourceException("Key not found", getClass().getName(),
|
|
|
|
key);
|
2001-08-31 23:31:20 +02:00
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Return the actual locale of this bundle. You can use it after calling
|
|
|
|
* getBundle, to know if the bundle for the desired locale was loaded or
|
|
|
|
* if the fall back was used.
|
|
|
|
*
|
|
|
|
* @return the bundle's locale
|
2001-11-04 05:15:09 +01:00
|
|
|
*/
|
2002-05-10 01:41:42 +02:00
|
|
|
public Locale getLocale()
|
2001-08-31 23:31:20 +02:00
|
|
|
{
|
2002-05-10 01:41:42 +02:00
|
|
|
return locale;
|
2001-08-31 23:31:20 +02:00
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Set the parent of this bundle. The parent is consulted when you call
|
|
|
|
* getObject and there is no such resource in the current bundle.
|
|
|
|
*
|
|
|
|
* @param parent the parent of this bundle
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
2002-05-10 01:41:42 +02:00
|
|
|
protected void setParent(ResourceBundle parent)
|
2001-08-31 23:31:20 +02:00
|
|
|
{
|
2002-05-10 01:41:42 +02:00
|
|
|
this.parent = parent;
|
2001-08-31 23:31:20 +02:00
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Get the appropriate ResourceBundle for the default locale. This is like
|
|
|
|
* calling <code>getBundle(baseName, Locale.getDefault(),
|
|
|
|
* getClass().getClassLoader()</code>, except that any security check of
|
|
|
|
* getClassLoader won't fail.
|
|
|
|
*
|
|
|
|
* @param baseName the name of the ResourceBundle
|
|
|
|
* @return the desired resource bundle
|
|
|
|
* @throws MissingResourceException if the resource bundle can't be found
|
|
|
|
* @throws NullPointerException if baseName is null
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
2004-07-10 04:14:30 +02:00
|
|
|
public static ResourceBundle getBundle(String baseName)
|
2001-08-31 23:31:20 +02:00
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
ClassLoader cl = getCallingClassLoader();
|
|
|
|
if (cl == null)
|
|
|
|
cl = ClassLoader.getSystemClassLoader();
|
|
|
|
return getBundle(baseName, Locale.getDefault(), cl);
|
2001-08-31 23:31:20 +02:00
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Get the appropriate ResourceBundle for the given locale. This is like
|
|
|
|
* calling <code>getBundle(baseName, locale,
|
|
|
|
* getClass().getClassLoader()</code>, except that any security check of
|
|
|
|
* getClassLoader won't fail.
|
2001-08-31 23:31:20 +02:00
|
|
|
*
|
2002-05-10 01:41:42 +02:00
|
|
|
* @param baseName the name of the ResourceBundle
|
|
|
|
* @param locale A locale
|
|
|
|
* @return the desired resource bundle
|
|
|
|
* @throws MissingResourceException if the resource bundle can't be found
|
|
|
|
* @throws NullPointerException if baseName or locale is null
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
2004-07-10 04:14:30 +02:00
|
|
|
public static ResourceBundle getBundle(String baseName, Locale locale)
|
2000-12-15 07:51:07 +01:00
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
ClassLoader cl = getCallingClassLoader();
|
|
|
|
if (cl == null)
|
|
|
|
cl = ClassLoader.getSystemClassLoader();
|
|
|
|
return getBundle(baseName, locale, cl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Cache key for the ResourceBundle cache. Resource bundles are keyed
|
|
|
|
by the combination of bundle name, locale, and class loader. */
|
2004-11-25 20:20:17 +01:00
|
|
|
private static class BundleKey
|
2004-07-10 04:14:30 +02:00
|
|
|
{
|
|
|
|
String baseName;
|
|
|
|
Locale locale;
|
|
|
|
ClassLoader classLoader;
|
|
|
|
int hashcode;
|
|
|
|
|
|
|
|
BundleKey() {}
|
|
|
|
|
|
|
|
BundleKey(String s, Locale l, ClassLoader cl)
|
|
|
|
{
|
|
|
|
set(s, l, cl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set(String s, Locale l, ClassLoader cl)
|
|
|
|
{
|
|
|
|
baseName = s;
|
|
|
|
locale = l;
|
|
|
|
classLoader = cl;
|
|
|
|
hashcode = baseName.hashCode() ^ locale.hashCode() ^
|
|
|
|
classLoader.hashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int hashCode()
|
|
|
|
{
|
|
|
|
return hashcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean equals(Object o)
|
|
|
|
{
|
|
|
|
if (! (o instanceof BundleKey))
|
|
|
|
return false;
|
|
|
|
BundleKey key = (BundleKey) o;
|
|
|
|
return hashcode == key.hashcode &&
|
|
|
|
baseName.equals(key.baseName) &&
|
|
|
|
locale.equals(key.locale) &&
|
|
|
|
classLoader.equals(key.classLoader);
|
2004-11-24 14:26:27 +01:00
|
|
|
}
|
2000-12-15 07:51:07 +01:00
|
|
|
}
|
2004-07-10 04:14:30 +02:00
|
|
|
|
|
|
|
/** A cache lookup key. This avoids having to a new one for every
|
|
|
|
* getBundle() call. */
|
|
|
|
private static BundleKey lookupKey = new BundleKey();
|
|
|
|
|
|
|
|
/** Singleton cache entry to represent previous failed lookups. */
|
|
|
|
private static Object nullEntry = new Object();
|
2000-12-15 07:51:07 +01:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Get the appropriate ResourceBundle for the given locale. The following
|
|
|
|
* strategy is used:
|
|
|
|
*
|
|
|
|
* <p>A sequence of candidate bundle names are generated, and tested in
|
|
|
|
* this order, where the suffix 1 means the string from the specified
|
MarshalledObject.java, [...]: Fixed javadoc, coding style and argument names all over.
2004-04-20 Michael Koch <konqueror@gmx.de>
* java/rmi/MarshalledObject.java,
java/rmi/Naming.java,
java/rmi/RemoteException.java,
java/rmi/activation/ActivationException.java,
java/rmi/server/ServerCloneException.java,
java/security/AccessController.java,
java/security/AlgorithmParameterGenerator.java,
java/security/AlgorithmParameters.java,
java/security/CodeSource.java,
java/security/Identity.java,
java/security/IdentityScope.java,
java/security/KeyPairGenerator.java,
java/security/KeyStore.java,
java/security/Security.java,
java/security/Signature.java,
java/security/SignatureSpi.java,
java/security/SignedObject.java,
java/security/spec/DSAParameterSpec.java,
java/security/spec/DSAPrivateKeySpec.java,
java/security/spec/DSAPublicKeySpec.java,
java/sql/Array.java,
java/sql/DatabaseMetaData.java,
java/sql/ResultSet.java,
java/text/ChoiceFormat.java,
java/text/CollationElementIterator.java,
java/text/CollationKey.java,
java/text/Collator.java,
java/text/DateFormat.java,
java/text/DateFormatSymbols.java,
java/text/DecimalFormatSymbols.java,
java/text/Format.java,
java/text/ParsePosition.java,
java/text/RuleBasedCollator.java,
java/text/SimpleDateFormat.java,
java/text/StringCharacterIterator.java,
java/util/Collections.java,
java/util/PropertyResourceBundle.java,
java/util/ResourceBundle.java,
java/util/StringTokenizer.java,
java/util/jar/Attributes.java,
java/util/logging/ConsoleHandler.java,
java/util/logging/LogManager.java,
java/util/logging/MemoryHandler.java,
java/util/logging/SocketHandler.java,
javax/naming/NamingException.java:
Fixed javadoc, coding style and argument names all over.
From-SVN: r80906
2004-04-20 16:45:10 +02:00
|
|
|
* locale, and the suffix 2 means the string from the default locale:</p>
|
|
|
|
*
|
|
|
|
* <ul>
|
2002-05-10 01:41:42 +02:00
|
|
|
* <li>baseName + "_" + language1 + "_" + country1 + "_" + variant1</li>
|
|
|
|
* <li>baseName + "_" + language1 + "_" + country1</li>
|
|
|
|
* <li>baseName + "_" + language1</li>
|
|
|
|
* <li>baseName + "_" + language2 + "_" + country2 + "_" + variant2</li>
|
|
|
|
* <li>baseName + "_" + language2 + "_" + country2</li>
|
MarshalledObject.java, [...]: Fixed javadoc, coding style and argument names all over.
2004-04-20 Michael Koch <konqueror@gmx.de>
* java/rmi/MarshalledObject.java,
java/rmi/Naming.java,
java/rmi/RemoteException.java,
java/rmi/activation/ActivationException.java,
java/rmi/server/ServerCloneException.java,
java/security/AccessController.java,
java/security/AlgorithmParameterGenerator.java,
java/security/AlgorithmParameters.java,
java/security/CodeSource.java,
java/security/Identity.java,
java/security/IdentityScope.java,
java/security/KeyPairGenerator.java,
java/security/KeyStore.java,
java/security/Security.java,
java/security/Signature.java,
java/security/SignatureSpi.java,
java/security/SignedObject.java,
java/security/spec/DSAParameterSpec.java,
java/security/spec/DSAPrivateKeySpec.java,
java/security/spec/DSAPublicKeySpec.java,
java/sql/Array.java,
java/sql/DatabaseMetaData.java,
java/sql/ResultSet.java,
java/text/ChoiceFormat.java,
java/text/CollationElementIterator.java,
java/text/CollationKey.java,
java/text/Collator.java,
java/text/DateFormat.java,
java/text/DateFormatSymbols.java,
java/text/DecimalFormatSymbols.java,
java/text/Format.java,
java/text/ParsePosition.java,
java/text/RuleBasedCollator.java,
java/text/SimpleDateFormat.java,
java/text/StringCharacterIterator.java,
java/util/Collections.java,
java/util/PropertyResourceBundle.java,
java/util/ResourceBundle.java,
java/util/StringTokenizer.java,
java/util/jar/Attributes.java,
java/util/logging/ConsoleHandler.java,
java/util/logging/LogManager.java,
java/util/logging/MemoryHandler.java,
java/util/logging/SocketHandler.java,
javax/naming/NamingException.java:
Fixed javadoc, coding style and argument names all over.
From-SVN: r80906
2004-04-20 16:45:10 +02:00
|
|
|
* <li>baseName + "_" + language2</li>
|
2002-05-10 01:41:42 +02:00
|
|
|
* <li>baseName</li>
|
|
|
|
* </ul>
|
|
|
|
*
|
|
|
|
* <p>In the sequence, entries with an empty string are ignored. Next,
|
MarshalledObject.java, [...]: Fixed javadoc, coding style and argument names all over.
2004-04-20 Michael Koch <konqueror@gmx.de>
* java/rmi/MarshalledObject.java,
java/rmi/Naming.java,
java/rmi/RemoteException.java,
java/rmi/activation/ActivationException.java,
java/rmi/server/ServerCloneException.java,
java/security/AccessController.java,
java/security/AlgorithmParameterGenerator.java,
java/security/AlgorithmParameters.java,
java/security/CodeSource.java,
java/security/Identity.java,
java/security/IdentityScope.java,
java/security/KeyPairGenerator.java,
java/security/KeyStore.java,
java/security/Security.java,
java/security/Signature.java,
java/security/SignatureSpi.java,
java/security/SignedObject.java,
java/security/spec/DSAParameterSpec.java,
java/security/spec/DSAPrivateKeySpec.java,
java/security/spec/DSAPublicKeySpec.java,
java/sql/Array.java,
java/sql/DatabaseMetaData.java,
java/sql/ResultSet.java,
java/text/ChoiceFormat.java,
java/text/CollationElementIterator.java,
java/text/CollationKey.java,
java/text/Collator.java,
java/text/DateFormat.java,
java/text/DateFormatSymbols.java,
java/text/DecimalFormatSymbols.java,
java/text/Format.java,
java/text/ParsePosition.java,
java/text/RuleBasedCollator.java,
java/text/SimpleDateFormat.java,
java/text/StringCharacterIterator.java,
java/util/Collections.java,
java/util/PropertyResourceBundle.java,
java/util/ResourceBundle.java,
java/util/StringTokenizer.java,
java/util/jar/Attributes.java,
java/util/logging/ConsoleHandler.java,
java/util/logging/LogManager.java,
java/util/logging/MemoryHandler.java,
java/util/logging/SocketHandler.java,
javax/naming/NamingException.java:
Fixed javadoc, coding style and argument names all over.
From-SVN: r80906
2004-04-20 16:45:10 +02:00
|
|
|
* <code>getBundle</code> tries to instantiate the resource bundle:</p>
|
|
|
|
*
|
|
|
|
* <ul>
|
2002-05-10 01:41:42 +02:00
|
|
|
* <li>First, an attempt is made to load a class in the specified classloader
|
|
|
|
* which is a subclass of ResourceBundle, and which has a public constructor
|
|
|
|
* with no arguments, via reflection.</li>
|
|
|
|
* <li>Next, a search is made for a property resource file, by replacing
|
|
|
|
* '.' with '/' and appending ".properties", and using
|
|
|
|
* ClassLoader.getResource(). If a file is found, then a
|
|
|
|
* PropertyResourceBundle is created from the file's contents.</li>
|
|
|
|
* </ul>
|
|
|
|
* If no resource bundle was found, a MissingResourceException is thrown.
|
|
|
|
*
|
|
|
|
* <p>Next, the parent chain is implemented. The remaining candidate names
|
|
|
|
* in the above sequence are tested in a similar manner, and if any results
|
|
|
|
* in a resource bundle, it is assigned as the parent of the first bundle
|
|
|
|
* using the <code>setParent</code> method (unless the first bundle already
|
MarshalledObject.java, [...]: Fixed javadoc, coding style and argument names all over.
2004-04-20 Michael Koch <konqueror@gmx.de>
* java/rmi/MarshalledObject.java,
java/rmi/Naming.java,
java/rmi/RemoteException.java,
java/rmi/activation/ActivationException.java,
java/rmi/server/ServerCloneException.java,
java/security/AccessController.java,
java/security/AlgorithmParameterGenerator.java,
java/security/AlgorithmParameters.java,
java/security/CodeSource.java,
java/security/Identity.java,
java/security/IdentityScope.java,
java/security/KeyPairGenerator.java,
java/security/KeyStore.java,
java/security/Security.java,
java/security/Signature.java,
java/security/SignatureSpi.java,
java/security/SignedObject.java,
java/security/spec/DSAParameterSpec.java,
java/security/spec/DSAPrivateKeySpec.java,
java/security/spec/DSAPublicKeySpec.java,
java/sql/Array.java,
java/sql/DatabaseMetaData.java,
java/sql/ResultSet.java,
java/text/ChoiceFormat.java,
java/text/CollationElementIterator.java,
java/text/CollationKey.java,
java/text/Collator.java,
java/text/DateFormat.java,
java/text/DateFormatSymbols.java,
java/text/DecimalFormatSymbols.java,
java/text/Format.java,
java/text/ParsePosition.java,
java/text/RuleBasedCollator.java,
java/text/SimpleDateFormat.java,
java/text/StringCharacterIterator.java,
java/util/Collections.java,
java/util/PropertyResourceBundle.java,
java/util/ResourceBundle.java,
java/util/StringTokenizer.java,
java/util/jar/Attributes.java,
java/util/logging/ConsoleHandler.java,
java/util/logging/LogManager.java,
java/util/logging/MemoryHandler.java,
java/util/logging/SocketHandler.java,
javax/naming/NamingException.java:
Fixed javadoc, coding style and argument names all over.
From-SVN: r80906
2004-04-20 16:45:10 +02:00
|
|
|
* has a parent).</p>
|
2002-05-10 01:41:42 +02:00
|
|
|
*
|
|
|
|
* <p>For example, suppose the following class and property files are
|
|
|
|
* provided: MyResources.class, MyResources_fr_CH.properties,
|
|
|
|
* MyResources_fr_CH.class, MyResources_fr.properties,
|
|
|
|
* MyResources_en.properties, and MyResources_es_ES.class. The contents of
|
|
|
|
* all files are valid (that is, public non-abstract subclasses of
|
|
|
|
* ResourceBundle with public nullary constructors for the ".class" files,
|
|
|
|
* syntactically correct ".properties" files). The default locale is
|
MarshalledObject.java, [...]: Fixed javadoc, coding style and argument names all over.
2004-04-20 Michael Koch <konqueror@gmx.de>
* java/rmi/MarshalledObject.java,
java/rmi/Naming.java,
java/rmi/RemoteException.java,
java/rmi/activation/ActivationException.java,
java/rmi/server/ServerCloneException.java,
java/security/AccessController.java,
java/security/AlgorithmParameterGenerator.java,
java/security/AlgorithmParameters.java,
java/security/CodeSource.java,
java/security/Identity.java,
java/security/IdentityScope.java,
java/security/KeyPairGenerator.java,
java/security/KeyStore.java,
java/security/Security.java,
java/security/Signature.java,
java/security/SignatureSpi.java,
java/security/SignedObject.java,
java/security/spec/DSAParameterSpec.java,
java/security/spec/DSAPrivateKeySpec.java,
java/security/spec/DSAPublicKeySpec.java,
java/sql/Array.java,
java/sql/DatabaseMetaData.java,
java/sql/ResultSet.java,
java/text/ChoiceFormat.java,
java/text/CollationElementIterator.java,
java/text/CollationKey.java,
java/text/Collator.java,
java/text/DateFormat.java,
java/text/DateFormatSymbols.java,
java/text/DecimalFormatSymbols.java,
java/text/Format.java,
java/text/ParsePosition.java,
java/text/RuleBasedCollator.java,
java/text/SimpleDateFormat.java,
java/text/StringCharacterIterator.java,
java/util/Collections.java,
java/util/PropertyResourceBundle.java,
java/util/ResourceBundle.java,
java/util/StringTokenizer.java,
java/util/jar/Attributes.java,
java/util/logging/ConsoleHandler.java,
java/util/logging/LogManager.java,
java/util/logging/MemoryHandler.java,
java/util/logging/SocketHandler.java,
javax/naming/NamingException.java:
Fixed javadoc, coding style and argument names all over.
From-SVN: r80906
2004-04-20 16:45:10 +02:00
|
|
|
* Locale("en", "UK").</p>
|
2002-05-10 01:41:42 +02:00
|
|
|
*
|
|
|
|
* <p>Calling getBundle with the shown locale argument values instantiates
|
MarshalledObject.java, [...]: Fixed javadoc, coding style and argument names all over.
2004-04-20 Michael Koch <konqueror@gmx.de>
* java/rmi/MarshalledObject.java,
java/rmi/Naming.java,
java/rmi/RemoteException.java,
java/rmi/activation/ActivationException.java,
java/rmi/server/ServerCloneException.java,
java/security/AccessController.java,
java/security/AlgorithmParameterGenerator.java,
java/security/AlgorithmParameters.java,
java/security/CodeSource.java,
java/security/Identity.java,
java/security/IdentityScope.java,
java/security/KeyPairGenerator.java,
java/security/KeyStore.java,
java/security/Security.java,
java/security/Signature.java,
java/security/SignatureSpi.java,
java/security/SignedObject.java,
java/security/spec/DSAParameterSpec.java,
java/security/spec/DSAPrivateKeySpec.java,
java/security/spec/DSAPublicKeySpec.java,
java/sql/Array.java,
java/sql/DatabaseMetaData.java,
java/sql/ResultSet.java,
java/text/ChoiceFormat.java,
java/text/CollationElementIterator.java,
java/text/CollationKey.java,
java/text/Collator.java,
java/text/DateFormat.java,
java/text/DateFormatSymbols.java,
java/text/DecimalFormatSymbols.java,
java/text/Format.java,
java/text/ParsePosition.java,
java/text/RuleBasedCollator.java,
java/text/SimpleDateFormat.java,
java/text/StringCharacterIterator.java,
java/util/Collections.java,
java/util/PropertyResourceBundle.java,
java/util/ResourceBundle.java,
java/util/StringTokenizer.java,
java/util/jar/Attributes.java,
java/util/logging/ConsoleHandler.java,
java/util/logging/LogManager.java,
java/util/logging/MemoryHandler.java,
java/util/logging/SocketHandler.java,
javax/naming/NamingException.java:
Fixed javadoc, coding style and argument names all over.
From-SVN: r80906
2004-04-20 16:45:10 +02:00
|
|
|
* resource bundles from the following sources:</p>
|
|
|
|
*
|
|
|
|
* <ul>
|
2002-05-10 01:41:42 +02:00
|
|
|
* <li>Locale("fr", "CH"): result MyResources_fr_CH.class, parent
|
|
|
|
* MyResources_fr.properties, parent MyResources.class</li>
|
|
|
|
* <li>Locale("fr", "FR"): result MyResources_fr.properties, parent
|
|
|
|
* MyResources.class</li>
|
|
|
|
* <li>Locale("de", "DE"): result MyResources_en.properties, parent
|
|
|
|
* MyResources.class</li>
|
|
|
|
* <li>Locale("en", "US"): result MyResources_en.properties, parent
|
|
|
|
* MyResources.class</li>
|
|
|
|
* <li>Locale("es", "ES"): result MyResources_es_ES.class, parent
|
|
|
|
* MyResources.class</li>
|
|
|
|
* </ul>
|
MarshalledObject.java, [...]: Fixed javadoc, coding style and argument names all over.
2004-04-20 Michael Koch <konqueror@gmx.de>
* java/rmi/MarshalledObject.java,
java/rmi/Naming.java,
java/rmi/RemoteException.java,
java/rmi/activation/ActivationException.java,
java/rmi/server/ServerCloneException.java,
java/security/AccessController.java,
java/security/AlgorithmParameterGenerator.java,
java/security/AlgorithmParameters.java,
java/security/CodeSource.java,
java/security/Identity.java,
java/security/IdentityScope.java,
java/security/KeyPairGenerator.java,
java/security/KeyStore.java,
java/security/Security.java,
java/security/Signature.java,
java/security/SignatureSpi.java,
java/security/SignedObject.java,
java/security/spec/DSAParameterSpec.java,
java/security/spec/DSAPrivateKeySpec.java,
java/security/spec/DSAPublicKeySpec.java,
java/sql/Array.java,
java/sql/DatabaseMetaData.java,
java/sql/ResultSet.java,
java/text/ChoiceFormat.java,
java/text/CollationElementIterator.java,
java/text/CollationKey.java,
java/text/Collator.java,
java/text/DateFormat.java,
java/text/DateFormatSymbols.java,
java/text/DecimalFormatSymbols.java,
java/text/Format.java,
java/text/ParsePosition.java,
java/text/RuleBasedCollator.java,
java/text/SimpleDateFormat.java,
java/text/StringCharacterIterator.java,
java/util/Collections.java,
java/util/PropertyResourceBundle.java,
java/util/ResourceBundle.java,
java/util/StringTokenizer.java,
java/util/jar/Attributes.java,
java/util/logging/ConsoleHandler.java,
java/util/logging/LogManager.java,
java/util/logging/MemoryHandler.java,
java/util/logging/SocketHandler.java,
javax/naming/NamingException.java:
Fixed javadoc, coding style and argument names all over.
From-SVN: r80906
2004-04-20 16:45:10 +02:00
|
|
|
*
|
|
|
|
* <p>The file MyResources_fr_CH.properties is never used because it is hidden
|
|
|
|
* by MyResources_fr_CH.class.</p>
|
2002-05-10 01:41:42 +02:00
|
|
|
*
|
|
|
|
* @param baseName the name of the ResourceBundle
|
|
|
|
* @param locale A locale
|
|
|
|
* @param classloader a ClassLoader
|
2001-08-31 23:31:20 +02:00
|
|
|
* @return the desired resource bundle
|
2002-05-10 01:41:42 +02:00
|
|
|
* @throws MissingResourceException if the resource bundle can't be found
|
|
|
|
* @throws NullPointerException if any argument is null
|
|
|
|
* @since 1.2
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
|
|
|
// This method is synchronized so that the cache is properly
|
|
|
|
// handled.
|
2004-07-10 04:14:30 +02:00
|
|
|
public static synchronized ResourceBundle getBundle
|
2002-05-10 01:41:42 +02:00
|
|
|
(String baseName, Locale locale, ClassLoader classLoader)
|
2001-08-31 23:31:20 +02:00
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
// If the default locale changed since the last time we were called,
|
|
|
|
// all cache entries are invalidated.
|
2002-12-09 00:38:02 +01:00
|
|
|
Locale defaultLocale = Locale.getDefault();
|
|
|
|
if (defaultLocale != lastDefaultLocale)
|
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
bundleCache = new HashMap();
|
2002-12-09 00:38:02 +01:00
|
|
|
lastDefaultLocale = defaultLocale;
|
|
|
|
}
|
2002-05-10 01:41:42 +02:00
|
|
|
|
2004-07-10 04:14:30 +02:00
|
|
|
// This will throw NullPointerException if any arguments are null.
|
|
|
|
lookupKey.set(baseName, locale, classLoader);
|
|
|
|
|
|
|
|
Object obj = bundleCache.get(lookupKey);
|
|
|
|
ResourceBundle rb = null;
|
2004-11-24 14:26:27 +01:00
|
|
|
|
2004-07-10 04:14:30 +02:00
|
|
|
if (obj instanceof ResourceBundle)
|
2001-08-31 23:31:20 +02:00
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
return (ResourceBundle) obj;
|
2001-08-31 23:31:20 +02:00
|
|
|
}
|
2004-07-10 04:14:30 +02:00
|
|
|
else if (obj == nullEntry)
|
2001-08-31 23:31:20 +02:00
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
// Lookup has failed previously. Fall through.
|
2001-08-31 23:31:20 +02:00
|
|
|
}
|
2004-07-10 04:14:30 +02:00
|
|
|
else
|
2002-09-23 19:56:33 +02:00
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
// First, look for a bundle for the specified locale. We don't want
|
|
|
|
// the base bundle this time.
|
|
|
|
boolean wantBase = locale.equals(defaultLocale);
|
|
|
|
ResourceBundle bundle = tryBundle(baseName, locale, classLoader,
|
|
|
|
wantBase);
|
|
|
|
|
|
|
|
// Try the default locale if neccessary.
|
|
|
|
if (bundle == null && !locale.equals(defaultLocale))
|
|
|
|
bundle = tryBundle(baseName, defaultLocale, classLoader, true);
|
|
|
|
|
2004-11-25 20:20:17 +01:00
|
|
|
BundleKey key = new BundleKey(baseName, locale, classLoader);
|
2004-07-10 04:14:30 +02:00
|
|
|
if (bundle == null)
|
|
|
|
{
|
|
|
|
// Cache the fact that this lookup has previously failed.
|
|
|
|
bundleCache.put(key, nullEntry);
|
|
|
|
}
|
2002-09-23 19:56:33 +02:00
|
|
|
else
|
2004-07-10 04:14:30 +02:00
|
|
|
{
|
|
|
|
// Cache the result and return it.
|
|
|
|
bundleCache.put(key, bundle);
|
|
|
|
return bundle;
|
|
|
|
}
|
2002-09-23 19:56:33 +02:00
|
|
|
}
|
2002-05-10 01:41:42 +02:00
|
|
|
|
2004-07-10 04:14:30 +02:00
|
|
|
throw new MissingResourceException("Bundle " + baseName + " not found",
|
|
|
|
baseName, "");
|
2001-08-31 23:31:20 +02:00
|
|
|
}
|
1999-05-24 17:00:02 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Override this method to provide the resource for a keys. This gets
|
|
|
|
* called by <code>getObject</code>. If you don't have a resource
|
|
|
|
* for the given key, you should return null instead throwing a
|
|
|
|
* MissingResourceException. You don't have to ask the parent, getObject()
|
|
|
|
* already does this; nor should you throw a MissingResourceException.
|
|
|
|
*
|
|
|
|
* @param key the key of the resource
|
|
|
|
* @return the resource for the key, or null if not in bundle
|
|
|
|
* @throws NullPointerException if key is null
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
2002-05-10 01:41:42 +02:00
|
|
|
protected abstract Object handleGetObject(String key);
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* This method should return all keys for which a resource exists; you
|
|
|
|
* should include the enumeration of any parent's keys, after filtering out
|
|
|
|
* duplicates.
|
|
|
|
*
|
|
|
|
* @return an enumeration of the keys
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
2002-05-10 01:41:42 +02:00
|
|
|
public abstract Enumeration getKeys();
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Tries to load a class or a property file with the specified name.
|
2001-08-31 23:31:20 +02:00
|
|
|
*
|
2002-05-10 01:41:42 +02:00
|
|
|
* @param localizedName the name
|
|
|
|
* @param classloader the classloader
|
|
|
|
* @return the resource bundle if it was loaded, otherwise the backup
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
2004-07-10 04:14:30 +02:00
|
|
|
private static ResourceBundle tryBundle(String localizedName,
|
|
|
|
ClassLoader classloader)
|
2002-05-10 01:41:42 +02:00
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
ResourceBundle bundle = null;
|
2002-05-10 01:41:42 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Class rbClass;
|
|
|
|
if (classloader == null)
|
|
|
|
rbClass = Class.forName(localizedName);
|
|
|
|
else
|
|
|
|
rbClass = classloader.loadClass(localizedName);
|
2004-10-25 19:09:46 +02:00
|
|
|
// Note that we do the check up front instead of catching
|
|
|
|
// ClassCastException. The reason for this is that some crazy
|
|
|
|
// programs (Eclipse) have classes that do not extend
|
|
|
|
// ResourceBundle but that have the same name as a property
|
|
|
|
// bundle; in fact Eclipse relies on ResourceBundle not
|
|
|
|
// instantiating these classes.
|
|
|
|
if (ResourceBundle.class.isAssignableFrom(rbClass))
|
|
|
|
bundle = (ResourceBundle) rbClass.newInstance();
|
2002-05-10 01:41:42 +02:00
|
|
|
}
|
2004-07-10 04:14:30 +02:00
|
|
|
catch (IllegalAccessException ex) {}
|
|
|
|
catch (InstantiationException ex) {}
|
|
|
|
catch (ClassNotFoundException ex) {}
|
|
|
|
|
|
|
|
if (bundle == null)
|
2002-09-23 19:56:33 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
InputStream is;
|
2004-07-10 04:14:30 +02:00
|
|
|
String resourceName
|
2002-09-23 19:56:33 +02:00
|
|
|
= localizedName.replace('.', '/') + ".properties";
|
|
|
|
if (classloader == null)
|
|
|
|
is = ClassLoader.getSystemResourceAsStream(resourceName);
|
|
|
|
else
|
|
|
|
is = classloader.getResourceAsStream(resourceName);
|
|
|
|
if (is != null)
|
2004-07-10 04:14:30 +02:00
|
|
|
bundle = new PropertyResourceBundle(is);
|
2002-09-23 19:56:33 +02:00
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
MissingResourceException mre = new MissingResourceException
|
|
|
|
("Failed to load bundle", localizedName, "");
|
|
|
|
mre.initCause(ex);
|
|
|
|
throw mre;
|
2002-09-23 19:56:33 +02:00
|
|
|
}
|
|
|
|
}
|
2002-05-10 01:41:42 +02:00
|
|
|
|
2004-07-10 04:14:30 +02:00
|
|
|
return bundle;
|
2002-05-10 01:41:42 +02:00
|
|
|
}
|
1999-04-07 16:42:40 +02:00
|
|
|
|
2001-08-31 23:31:20 +02:00
|
|
|
/**
|
2002-05-10 01:41:42 +02:00
|
|
|
* Tries to load a the bundle for a given locale, also loads the backup
|
|
|
|
* locales with the same language.
|
|
|
|
*
|
2004-11-24 14:26:27 +01:00
|
|
|
* @param baseName the raw bundle name, without locale qualifiers
|
2002-09-23 19:56:33 +02:00
|
|
|
* @param locale the locale
|
2002-05-10 01:41:42 +02:00
|
|
|
* @param classloader the classloader
|
|
|
|
* @param bundle the backup (parent) bundle
|
2004-07-10 04:14:30 +02:00
|
|
|
* @param wantBase whether a resource bundle made only from the base name
|
|
|
|
* (with no locale information attached) should be returned.
|
2002-05-10 01:41:42 +02:00
|
|
|
* @return the resource bundle if it was loaded, otherwise the backup
|
2001-08-31 23:31:20 +02:00
|
|
|
*/
|
2004-07-10 04:14:30 +02:00
|
|
|
private static ResourceBundle tryBundle(String baseName, Locale locale,
|
|
|
|
ClassLoader classLoader,
|
|
|
|
boolean wantBase)
|
2002-05-10 01:41:42 +02:00
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
String language = locale.getLanguage();
|
|
|
|
String country = locale.getCountry();
|
|
|
|
String variant = locale.getVariant();
|
|
|
|
|
|
|
|
int baseLen = baseName.length();
|
2002-09-23 19:56:33 +02:00
|
|
|
|
2004-07-10 04:14:30 +02:00
|
|
|
// Build up a StringBuffer containing the complete bundle name, fully
|
|
|
|
// qualified by locale.
|
|
|
|
StringBuffer sb = new StringBuffer(baseLen + variant.length() + 7);
|
2002-05-10 01:41:42 +02:00
|
|
|
|
2004-07-10 04:14:30 +02:00
|
|
|
sb.append(baseName);
|
|
|
|
|
2002-05-10 01:41:42 +02:00
|
|
|
if (language.length() > 0)
|
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
sb.append('_');
|
2002-09-23 19:56:33 +02:00
|
|
|
sb.append(language);
|
2004-07-10 04:14:30 +02:00
|
|
|
|
|
|
|
if (country.length() > 0)
|
|
|
|
{
|
|
|
|
sb.append('_');
|
|
|
|
sb.append(country);
|
|
|
|
|
|
|
|
if (variant.length() > 0)
|
|
|
|
{
|
|
|
|
sb.append('_');
|
|
|
|
sb.append(variant);
|
|
|
|
}
|
|
|
|
}
|
2002-09-23 19:56:33 +02:00
|
|
|
}
|
|
|
|
|
2004-07-10 04:14:30 +02:00
|
|
|
// Now try to load bundles, starting with the most specialized name.
|
|
|
|
// Build up the parent chain as we go.
|
|
|
|
String bundleName = sb.toString();
|
|
|
|
ResourceBundle first = null; // The most specialized bundle.
|
|
|
|
ResourceBundle last = null; // The least specialized bundle.
|
|
|
|
|
|
|
|
while (true)
|
2002-09-23 19:56:33 +02:00
|
|
|
{
|
2004-07-10 04:14:30 +02:00
|
|
|
ResourceBundle foundBundle = tryBundle(bundleName, classLoader);
|
|
|
|
if (foundBundle != null)
|
|
|
|
{
|
|
|
|
if (first == null)
|
|
|
|
first = foundBundle;
|
|
|
|
if (last != null)
|
|
|
|
last.parent = foundBundle;
|
|
|
|
foundBundle.locale = locale;
|
|
|
|
last = foundBundle;
|
|
|
|
}
|
|
|
|
int idx = bundleName.lastIndexOf('_');
|
|
|
|
// Try the non-localized base name only if we already have a
|
|
|
|
// localized child bundle, or wantBase is true.
|
|
|
|
if (idx > baseLen || (idx == baseLen && (first != null || wantBase)))
|
|
|
|
bundleName = bundleName.substring(0, idx);
|
|
|
|
else
|
|
|
|
break;
|
2002-05-10 01:41:42 +02:00
|
|
|
}
|
2004-07-10 04:14:30 +02:00
|
|
|
|
|
|
|
return first;
|
2002-05-10 01:41:42 +02:00
|
|
|
}
|
2002-09-23 19:56:33 +02:00
|
|
|
}
|