Package org.apache.xmlgraphics.util.i18n
Class LocalizableSupport
- java.lang.Object
-
- org.apache.xmlgraphics.util.i18n.LocalizableSupport
-
- All Implemented Interfaces:
Localizable
public class LocalizableSupport extends 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.
- Version:
- $Id: LocalizableSupport.java 1732018 2016-02-24 04:51:06Z gadams $ Originally authored by Stephane Hillion.
-
-
Field Summary
Fields Modifier and Type Field Description protected StringbundleNameThe resource bundle classname.protected ClassLoaderclassLoaderThe classloader to use to create the resource bundle.protected LocalelocaleThe current locale.protected LocaleGrouplocaleGroupThe locale group to which this object belongs.protected ResourceBundleresourceBundleThe resourcesprotected LocaleusedLocaleThe locale in use.
-
Constructor Summary
Constructors Constructor Description LocalizableSupport(String s)Same as LocalizableSupport(s, null).LocalizableSupport(String s, ClassLoader cl)Creates a new Localizable object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringformatMessage(String key, Object[] args)ImplementsLocalizable.formatMessage(String,Object[]).LocalegetDefaultLocale()ImplementsExtendedLocalizable.getDefaultLocale().LocalegetLocale()ImplementsLocalizable.getLocale().LocaleGroupgetLocaleGroup()ImplementsExtendedLocalizable.getLocaleGroup().ResourceBundlegetResourceBundle()ImplementsExtendedLocalizable.getResourceBundle().voidsetDefaultLocale(Locale l)ImplementsExtendedLocalizable.setDefaultLocale(Locale).voidsetLocale(Locale l)ImplementsLocalizable.setLocale(Locale).voidsetLocaleGroup(LocaleGroup lg)ImplementsExtendedLocalizable.setLocaleGroup(LocaleGroup).
-
-
-
Field Detail
-
localeGroup
protected LocaleGroup localeGroup
The locale group to which this object belongs.
-
bundleName
protected String bundleName
The resource bundle classname.
-
classLoader
protected ClassLoader classLoader
The classloader to use to create the resource bundle.
-
locale
protected Locale locale
The current locale.
-
usedLocale
protected Locale usedLocale
The locale in use.
-
resourceBundle
protected ResourceBundle resourceBundle
The resources
-
-
Constructor Detail
-
LocalizableSupport
public LocalizableSupport(String s)
Same as LocalizableSupport(s, null).
-
LocalizableSupport
public LocalizableSupport(String s, 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(Locale l)
ImplementsLocalizable.setLocale(Locale).- Specified by:
setLocalein interfaceLocalizable- Parameters:
l- The locale to set.
-
getLocale
public Locale getLocale()
ImplementsLocalizable.getLocale().- Specified by:
getLocalein interfaceLocalizable
-
setLocaleGroup
public void setLocaleGroup(LocaleGroup lg)
ImplementsExtendedLocalizable.setLocaleGroup(LocaleGroup).
-
getLocaleGroup
public LocaleGroup getLocaleGroup()
ImplementsExtendedLocalizable.getLocaleGroup().
-
setDefaultLocale
public void setDefaultLocale(Locale l)
ImplementsExtendedLocalizable.setDefaultLocale(Locale). Later invocations of the instance methods will lead to update the resource bundle used.
-
getDefaultLocale
public Locale getDefaultLocale()
ImplementsExtendedLocalizable.getDefaultLocale().
-
formatMessage
public String formatMessage(String key, Object[] args)
ImplementsLocalizable.formatMessage(String,Object[]).- Specified by:
formatMessagein interfaceLocalizable- Parameters:
key- The key used to retreive the message from the resource bundle.args- The objects that compose the message.
-
getResourceBundle
public ResourceBundle getResourceBundle()
ImplementsExtendedLocalizable.getResourceBundle().
-
-