Package org.apache.batik.i18n
Class LocalizableSupport
- java.lang.Object
-
- org.apache.batik.i18n.LocalizableSupport
-
- All Implemented Interfaces:
Localizable
public class LocalizableSupport extends java.lang.Object implements Localizable
This class provides a default implementation of the Localizable interface. You can use it as a base class or as a member field and delegates various work to it.For example, to implement Localizable, the following code can be used:
package mypackage; ... public class MyClass implements Localizable { // This code fragment requires a file named // 'mypackage/resources/Messages.properties', or a // 'mypackage.resources.Messages' class which extends // java.util.ResourceBundle, accessible using the current // classpath. LocalizableSupport localizableSupport = new LocalizableSupport("mypackage.resources.Messages"); public void setLocale(Locale l) { localizableSupport.setLocale(l); } public Local getLocale() { return localizableSupport.getLocale(); } public String formatMessage(String key, Object[] args) { return localizableSupport.formatMessage(key, args); } }
The algorithm for the Locale lookup in a LocalizableSupport object is:- if a Locale has been set by a call to setLocale(), use this Locale, else,
- if a Locale has been set by a call to the setDefaultLocale() method of a LocalizableSupport object in the current LocaleGroup, use this Locale, else,
- use the object returned by Locale.getDefault() (and set by Locale.setDefault()).
Note: if no group is specified a LocalizableSupport object belongs to a default group common to each instance of LocalizableSupport.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
bundleName
The resource bundle classname.protected java.lang.ClassLoader
classLoader
The classloader to use to create the resource bundle.protected java.util.Locale
locale
The current locale.protected LocaleGroup
localeGroup
The locale group to which this object belongs.protected java.util.Locale
usedLocale
The locale in use.
-
Constructor Summary
Constructors Constructor Description LocalizableSupport(java.lang.String s)
Same as LocalizableSupport(s, null).LocalizableSupport(java.lang.String s, java.lang.Class cls)
Same as LocalizableSupport(cls, null).LocalizableSupport(java.lang.String s, java.lang.ClassLoader cl)
Creates a new Localizable object.LocalizableSupport(java.lang.String s, java.lang.Class cls, java.lang.ClassLoader cl)
Same as LocalizableSupport(cls, null).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
formatMessage(java.lang.String key, java.lang.Object[] args)
ImplementsLocalizable.formatMessage(String,Object[])
.int
getCharacter(java.lang.String key)
protected java.util.Locale
getCurrentLocale()
java.util.Locale
getDefaultLocale()
ImplementsExtendedLocalizable.getDefaultLocale()
.int
getInteger(java.lang.String key)
Returns the integer mapped with the given stringjava.util.Locale
getLocale()
ImplementsLocalizable.getLocale()
.LocaleGroup
getLocaleGroup()
ImplementsExtendedLocalizable.getLocaleGroup()
.java.util.ResourceBundle
getResourceBundle()
Here for backwards compatabilityprotected java.util.ResourceBundle
getResourceBundle(int i)
java.lang.String
getString(java.lang.String key)
protected boolean
hasNextResourceBundle(int i)
protected java.util.ResourceBundle
lookupResourceBundle(java.lang.String bundle, java.lang.Class theClass)
void
setDefaultLocale(java.util.Locale l)
ImplementsExtendedLocalizable.setDefaultLocale(Locale)
.void
setLocale(java.util.Locale l)
ImplementsLocalizable.setLocale(Locale)
.void
setLocaleGroup(LocaleGroup lg)
ImplementsExtendedLocalizable.setLocaleGroup(LocaleGroup)
.protected boolean
setUsedLocale()
returns true if the locale is different from the previously used locale.
-
-
-
Field Detail
-
localeGroup
protected LocaleGroup localeGroup
The locale group to which this object belongs.
-
bundleName
protected java.lang.String bundleName
The resource bundle classname.
-
classLoader
protected java.lang.ClassLoader classLoader
The classloader to use to create the resource bundle.
-
locale
protected java.util.Locale locale
The current locale.
-
usedLocale
protected java.util.Locale usedLocale
The locale in use.
-
-
Constructor Detail
-
LocalizableSupport
public LocalizableSupport(java.lang.String s, java.lang.Class cls)
Same as LocalizableSupport(cls, null).
-
LocalizableSupport
public LocalizableSupport(java.lang.String s, java.lang.Class cls, java.lang.ClassLoader cl)
Same as LocalizableSupport(cls, null).
-
LocalizableSupport
public LocalizableSupport(java.lang.String s)
Same as LocalizableSupport(s, null).
-
LocalizableSupport
public LocalizableSupport(java.lang.String s, java.lang.ClassLoader cl)
Creates a new Localizable object. The resource bundle class name is required allows the use of custom classes of resource bundles.- Parameters:
s
- must be the name of the class to use to get the appropriate resource bundle given the current locale.cl
- is the classloader used to create the resource bundle, or null.- See Also:
ResourceBundle
-
-
Method Detail
-
setLocale
public void setLocale(java.util.Locale l)
ImplementsLocalizable.setLocale(Locale)
.- Specified by:
setLocale
in interfaceLocalizable
- Parameters:
l
- The locale to set.
-
getLocale
public java.util.Locale getLocale()
ImplementsLocalizable.getLocale()
.- Specified by:
getLocale
in interfaceLocalizable
-
setLocaleGroup
public void setLocaleGroup(LocaleGroup lg)
ImplementsExtendedLocalizable.setLocaleGroup(LocaleGroup)
.
-
getLocaleGroup
public LocaleGroup getLocaleGroup()
ImplementsExtendedLocalizable.getLocaleGroup()
.
-
setDefaultLocale
public void setDefaultLocale(java.util.Locale l)
ImplementsExtendedLocalizable.setDefaultLocale(Locale)
. Later invocations of the instance methods will lead to update the resource bundle used.
-
getDefaultLocale
public java.util.Locale getDefaultLocale()
ImplementsExtendedLocalizable.getDefaultLocale()
.
-
formatMessage
public java.lang.String formatMessage(java.lang.String key, java.lang.Object[] args)
ImplementsLocalizable.formatMessage(String,Object[])
.- Specified by:
formatMessage
in interfaceLocalizable
- Parameters:
key
- The key used to retreive the message from the resource bundle.args
- The objects that compose the message.
-
getCurrentLocale
protected java.util.Locale getCurrentLocale()
-
setUsedLocale
protected boolean setUsedLocale()
returns true if the locale is different from the previously used locale. Also sets 'usedLocale' to the current locale.
-
getResourceBundle
public java.util.ResourceBundle getResourceBundle()
Here for backwards compatability
-
hasNextResourceBundle
protected boolean hasNextResourceBundle(int i)
-
lookupResourceBundle
protected java.util.ResourceBundle lookupResourceBundle(java.lang.String bundle, java.lang.Class theClass)
-
getResourceBundle
protected java.util.ResourceBundle getResourceBundle(int i)
-
getString
public java.lang.String getString(java.lang.String key) throws java.util.MissingResourceException
- Throws:
java.util.MissingResourceException
-
getInteger
public int getInteger(java.lang.String key) throws java.util.MissingResourceException
Returns the integer mapped with the given string- Parameters:
key
- a key of the resource bundle- Throws:
java.util.MissingResourceException
- if key is not the name of a resource
-
getCharacter
public int getCharacter(java.lang.String key) throws java.util.MissingResourceException
- Throws:
java.util.MissingResourceException
-
-