|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object biz.chitec.quarterback.util.RB
Loads hierarchical ResourceBundles with respect to class hierarchy. The three static getBundle() methods try to load the resources for a class and return the appropriate resource bundle. ResourceBundles fitting into this scheme are basically named <classname>_p. Standard rules for localization apply.
To allow not only resource hierarchies along with the localization but also along with the class
hierarchy, the returned resource bundle is of the class HierarchicalResourceBundle
. That bundle
is initialized in a way so that all bundles of the classes superclass are also loaded and used
as fallbacks.
Example: Assume we have a class hierarchy JPanel > StandardPanel > ExtendedPanel . So, the first step is to have resource bundles for both new Panels. Things could look like this:
Class | Standard resource | French resource |
---|---|---|
StandardPanel | StandardPanel_p.properties | StandardPanel_p_fr.properties |
ExtendedPanel | ExtendedPanel_p.properties | ExtendedPanel_p_fr.properties |
If no resource bundle exists for ExtendedPanel , the resources for StandardPanel (and any super classes) are used.
RB makes a sharp distinction between bundles requested with an explicit locale and those without.
The bundles with explicit locale will be delivered and never changed after. The other bundles,
however, are delivered with the default locale and stored internally. If the default locales
changes afterwards AND defaultLocaleChanged()
is called afterwards, all those bundles
will reload their internal data and deliver all content with that new default locale. This can
be used to change the locale during program operation.
Field Summary | |
private static java.util.Map |
components
|
private static java.util.Locale |
fallbacklocale
Additional locale that can be set to provide an explicit fallback. |
private static java.util.Map |
locales
|
Constructor Summary | |
private |
RB()
This class is uninstanciable. |
Method Summary | |
static void |
defaultLocaleChanged()
Notifies all non-locale-specific bundles still in use about the change of the default locale. |
static java.util.ResourceBundle |
getBundle(java.lang.Class aclass)
Loads hierarchical bundle for a class and the default locale. |
static java.util.ResourceBundle |
getBundle(java.lang.Class aclass,
java.util.Locale locale)
Loads hierarchical bundle for a class and a certain locale. |
static java.util.ResourceBundle |
getBundle(java.lang.Object anobject)
Loads hierarchical bundle for an instance and the default locale |
static java.util.ResourceBundle |
getBundle(java.lang.Object anobject,
java.util.Locale locale)
Loads hierarchical bundle for an instance and a certain locale |
static java.util.ResourceBundle |
getBundle(java.lang.String aclassname)
Loads a bundle for the default locale |
static java.util.ResourceBundle |
getBundle(java.lang.String aclassname,
java.util.Locale locale)
Loads hierarchical bundle for a string-named class. |
static java.util.ResourceBundle |
getBundleWithException(java.lang.String aclassname)
Loads hierarchical bundle for given class and the default locale. |
static java.util.ResourceBundle |
getBundleWithException(java.lang.String aclassname,
java.util.Locale locale)
Loads hierarchical bundle for given class and the given locale. |
static java.util.Locale |
getLocale(java.lang.String description)
Constructs a Locale from a describing String. |
static java.util.ResourceBundle |
getStoredBundleForComponent(java.awt.Component c)
Returns the bundle created for a certain component which is not a JComponent. |
static java.lang.String |
getString(java.util.ResourceBundle rb,
java.lang.String propname)
Return a String with the guaratee that no exception is thrown |
static java.lang.String |
getStringWithModifiers(java.util.ResourceBundle rb,
java.lang.String base,
java.lang.String mod1,
java.lang.String mod2,
java.lang.String mod3)
Returns a localized property with some modifiers to the name. |
static void |
printRB(java.util.ResourceBundle rb)
Debugging helper method: Prints visible content of the given ResourceBundle. |
static void |
setFallbackLocale(java.util.Locale l)
Load explicit additional Locale. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static java.util.Map locales
private static java.util.Map components
private static java.util.Locale fallbacklocale
Constructor Detail |
private RB()
Method Detail |
public static void setFallbackLocale(java.util.Locale l)
l
- The new fallbacklocale valuepublic static java.util.ResourceBundle getBundle(java.lang.Object anobject, java.util.Locale locale)
anobject
- Object to get the ResourceBundle for.locale
- The locale to load for
public static java.util.ResourceBundle getBundle(java.lang.Object anobject)
anobject
- Object to get the ResourceBundle for.
public static void defaultLocaleChanged()
public static java.util.ResourceBundle getStoredBundleForComponent(java.awt.Component c)
TOM
to ask for the bundle of a non-JComponent element when it
comes to changing the default locale.
c
-
public static java.util.ResourceBundle getBundle(java.lang.Class aclass, java.util.Locale locale)
aclass
- Class to get the ResourceBundle for.locale
- The locale to load for
public static java.util.ResourceBundle getBundle(java.lang.Class aclass)
aclass
- Class to get the ResourceBundle for.
public static java.util.ResourceBundle getBundle(java.lang.String aclassname, java.util.Locale locale)
aclassname
- Class namelocale
- The locale for which the bundle shell be loaded
public static java.util.ResourceBundle getBundle(java.lang.String aclassname)
public static java.util.ResourceBundle getBundleWithException(java.lang.String aclassname, java.util.Locale locale)
aclassname
- Class name
public static java.util.ResourceBundle getBundleWithException(java.lang.String aclassname)
aclassname
- Class name
public static java.lang.String getString(java.util.ResourceBundle rb, java.lang.String propname)
rb
- ResourceBundle to take property frompropname
- Name of the property to read
public static java.lang.String getStringWithModifiers(java.util.ResourceBundle rb, java.lang.String base, java.lang.String mod1, java.lang.String mod2, java.lang.String mod3)
The property is searched with every combination of the three modifiers where only those modifiers are taken into respect which are not null. First combination matches where bigger number of matching modifiers precede lower index of matching modifiers. Last resort is always non-modified key (base part only). If even that cannot be found, the base itself is returned.
Modifiers are automatically surrounded with dots. For missing modifier, no dot is inserted either.
rb
- ResourceBundle to search inbase
- Base part of the keymod1
- First modifier to the key, may be nullmod2
- Second modifier to the key, may be nullmod3
- Last modifier to the key, may be null
public static java.util.Locale getLocale(java.lang.String description)
description
- Locale description of type lang_COUNTRY_variant
public static void printRB(java.util.ResourceBundle rb)
rb
- ResourceBundle to print out.
|
QJCC homepage | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |