|
||||||||||
| PREV CLASS Documentation homepage NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectilog.views.util.IlvResourceUtil
public class IlvResourceUtil
Utilities for resource bundles.
Use of this class, instead of ResourceBundle.getBundle,
allows applets loaded over http to perform only a minimal
number of http requests (assuming the applet's main code
uses the setAvailableResourceSuffixes(java.lang.String...) method to specify which
locale is supported by the applet's resources).
The second idea here is not to hard code resource bundle paths. Instead, we pass the corresponding class. The advantage: if classes are moved, the resource bundle path is also up to date.
For example:
String s = IlvResourceUtil.getString(key, Myclass.class);
It is not recommended to use this utility with an implicit class reference
such as
String s = IlvResourceUtil.getString(key, getClass());
because this variant works only if all subclasses of the current class
are in the same package.
| Method Summary | |
|---|---|
static ResourceBundle |
getBundle(String baseName)
Returns a resource bundle, examining the available resource suffixes. |
static ResourceBundle |
getBundle(String name,
Class clazz)
Returns the resource bundle in the package of the input class. |
static ResourceBundle |
getBundle(String name,
Class clazz,
Locale locale)
Returns the resource bundle in the package of the input class. |
static ResourceBundle |
getBundle(String baseName,
Locale locale)
Returns a resource bundle, examining the available resource suffixes. |
static ResourceBundle |
getBundle(String baseName,
Locale locale,
ClassLoader loader)
Returns a resource bundle, examining the available resource suffixes. |
static String |
getSafeString(String key,
Class clazz)
Returns a string for the given key from the resource bundle named "messages" in the package of the input class. |
static String |
getSafeString(String key,
Class clazz,
Locale locale)
Returns a string for the given key from the resource bundle named "messages" in the package of the input class. |
static String |
getSafeString(String key,
String bundle,
Class clazz)
Returns a string for the given key from the resource bundle in the package of the input class. |
static String |
getSafeString(String key,
String bundle,
Class clazz,
Locale locale)
Returns a string for the given key from the resource bundle in the package of the input class. |
static String |
getString(String key,
Class clazz)
Returns a string for the given key from the resource bundle named "messages" in the package of the input class. |
static String |
getString(String key,
Class clazz,
Locale locale)
Returns a string for the given key from the resource bundle named "messages" in the package of the input class. |
static String |
getString(String key,
Class clazz,
Locale locale,
String defString)
Returns a string for the given key from the resource bundle named "messages" in the package of the input class. |
static String |
getString(String key,
Class clazz,
String defString)
Returns a string for the given key from the resource bundle named "messages" in the package of the input class. |
static String |
getString(String key,
String bundle,
Class clazz)
Returns a string for the given key from the resource bundle in the package of the input class. |
static String |
getString(String key,
String bundle,
Class clazz,
Locale locale)
Returns a string for the given key from the resource bundle in the package of the input class. |
static String |
getString(String key,
String bundle,
Class clazz,
Locale locale,
String defString)
Returns a string for the given key from the resource bundle in the package of the input class. |
static String |
getString(String key,
String bundle,
Class clazz,
String defString)
Returns a string for the given key from the resource bundle in the package of the input class. |
static void |
setAvailableResourceSuffixes(String... suffixes)
Sets the available resource suffixes. |
static void |
setDebug(int debug)
Sets the debugging mode. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static String getString(String key,
Class clazz)
key - The key of the resource string.clazz - The input class, to determine the package name and the
class loader.
MissingResourceException - if no string for the given key can
be found
public static String getString(String key,
Class clazz,
Locale locale)
key - The key of the resource string.clazz - The input class, to determine the package name and the
class loader.locale - The locale.
MissingResourceException - if no string for the given key can
be found
public static String getString(String key,
String bundle,
Class clazz)
key - The key of the resource string.bundle - The base name of the resource bundle excluding the
package name.clazz - The input class, to determine the package name and the
class loader.
MissingResourceException - if no string for the given key can
be found
public static String getString(String key,
String bundle,
Class clazz,
Locale locale)
key - The key of the resource string.bundle - The base name of the resource bundle excluding the
package name.clazz - The input class, to determine the package name and the
class loader.locale - The locale.
MissingResourceException - if no string for the given key can
be found
public static String getString(String key,
Class clazz,
String defString)
This variant does not throw missing resource exceptions. If the resource is missing, the default string is returned instead.
key - The key of the resource string.clazz - The input class, to determine the package name and the
class loader.defString - If the resource bundle is not found or no string for
the given key can be found, this default string is returned.
public static String getString(String key,
Class clazz,
Locale locale,
String defString)
This variant does not throw missing resource exceptions. If the resource is missing, the default string is returned instead.
key - The key of the resource string.clazz - The input class, to determine the package name and the
class loader.locale - The locale.defString - If the resource bundle is not found or no string for
the given key can be found, this default string is returned.
public static String getString(String key,
String bundle,
Class clazz,
String defString)
This variant does not throw missing resource exceptions. If the resource is missing, the default string is returned instead.
key - The key of the resource string.bundle - The base name of the resource bundle excluding the
package name.clazz - The input class, to determine the package name and the
class loader.defString - If the resource bundle is not found or no string for
the given key can be found, this default string is returned.
public static String getString(String key,
String bundle,
Class clazz,
Locale locale,
String defString)
This variant does not throw missing resource exceptions. If the resource is missing, the default string is returned instead.
key - The key of the resource string.bundle - The base name of the resource bundle excluding the
package name.clazz - The input class, to determine the package name and the
class loader.locale - The locale.defString - If the resource bundle is not found or no string for
the given key can be found, this default string is returned.
public static String getSafeString(String key,
Class clazz)
This variant does not throw missing resource exceptions. If the resource is missing, the key is returned instead.
key - The key of the resource string.clazz - The input class, to determine the package name and the
class loader.
public static String getSafeString(String key,
Class clazz,
Locale locale)
This variant does not throw missing resource exceptions. If the resource is missing, the key is returned instead.
key - The key of the resource string.clazz - The input class, to determine the package name and the
class loader.locale - The locale.
public static String getSafeString(String key,
String bundle,
Class clazz)
This variant does not throw missing resource exceptions. If the resource is missing, the key is returned instead.
key - The key of the resource string.bundle - The base name of the resource bundle excluding the
package name.clazz - The input class, to determine the package name and the
class loader.
public static String getSafeString(String key,
String bundle,
Class clazz,
Locale locale)
This variant does not throw missing resource exceptions. If the resource is missing, the key is returned instead.
key - The key of the resource string.bundle - The base name of the resource bundle excluding the
package name.clazz - The input class, to determine the package name and the
class loader.locale - The locale.
public static ResourceBundle getBundle(String name,
Class clazz)
name - The base name of the resource bundle excluding the
package name.clazz - The input class, to determine the package name and the
class loader.
public static ResourceBundle getBundle(String name,
Class clazz,
Locale locale)
name - The base name of the resource bundle excluding the
package name.clazz - The input class, to determine the package name and the
class loader.locale - The locale.public static void setAvailableResourceSuffixes(String... suffixes)
The following sample shows how to use the API:
IlvResourceUtil.setAvailableResourceSuffixes("", "_fr", "_de" );
This statement specifies that the default bundle (""), the generic
French bundle ("_fr") and the generic German bundle ("_de") are
available. If the locale is currently Canadian French, it will not try
to load the bundle "_fr_CA" but immediately use the bundle "fr" instead.
In order to set back to the default behavior, call:
IlvResourceUtil.setAvailableResourceSuffixes(null);
Suffixes have the following formats:
public static void setDebug(int debug)
ilog.views.util.IlvResourceUtil",
stderr.
public static ResourceBundle getBundle(String baseName,
Locale locale,
ClassLoader loader)
throws MissingResourceException
baseName - The base name of the resource bundle including the
package name.locale - The locale.loader - The class loader to load the bundle.
MissingResourceException
public static ResourceBundle getBundle(String baseName,
Locale locale)
throws MissingResourceException
baseName - The base name of the resource bundle including the
package name.locale - The locale.
MissingResourceExceptionpublic static ResourceBundle getBundle(String baseName)
baseName - The base name of the resource bundle including the
package name.
|
||||||||||
| PREV CLASS Documentation homepage NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||