org.apache.batik.i18n

Class LocalizableSupport

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: This offers the possibility to have a different Locale for each object, a Locale for a group of object and/or a Locale for the JVM instance.

Note: if no group is specified a LocalizableSupport object belongs to a default group common to each instance of LocalizableSupport.

Field Summary
protected StringbundleName
The resource bundle classname.
protected ClassLoaderclassLoader
The classloader to use to create the resource bundle.
protected Localelocale
The current locale.
protected LocaleGrouplocaleGroup
The locale group to which this object belongs.
protected LocaleusedLocale
The locale in use.
Constructor Summary
LocalizableSupport(String s, Class cls)
Same as LocalizableSupport(cls, null).
LocalizableSupport(String s, Class cls, ClassLoader cl)
Same as LocalizableSupport(cls, null).
LocalizableSupport(String s)
Same as LocalizableSupport(s, null).
LocalizableSupport(String s, ClassLoader cl)
Creates a new Localizable object.
Method Summary
StringformatMessage(String key, Object[] args)
Implements {@link org.apache.batik.i18n.Localizable#formatMessage(String,Object[])}.
intgetCharacter(String key)
protected LocalegetCurrentLocale()
LocalegetDefaultLocale()
Implements {@link org.apache.batik.i18n.ExtendedLocalizable#getDefaultLocale()}.
intgetInteger(String key)
Returns the integer mapped with the given string
LocalegetLocale()
Implements {@link org.apache.batik.i18n.Localizable#getLocale()}.
LocaleGroupgetLocaleGroup()
Implements {@link org.apache.batik.i18n.ExtendedLocalizable#getLocaleGroup()}.
ResourceBundlegetResourceBundle()
Here for backwards compatability
protected ResourceBundlegetResourceBundle(int i)
StringgetString(String key)
protected booleanhasNextResourceBundle(int i)
protected ResourceBundlelookupResourceBundle(String bundle, Class theClass)
voidsetDefaultLocale(Locale l)
Implements {@link org.apache.batik.i18n.ExtendedLocalizable#setDefaultLocale(Locale)}.
voidsetLocale(Locale l)
Implements {@link org.apache.batik.i18n.Localizable#setLocale(Locale)}.
voidsetLocaleGroup(LocaleGroup lg)
Implements {@link org.apache.batik.i18n.ExtendedLocalizable#setLocaleGroup(LocaleGroup)}.
protected booleansetUsedLocale()
returns true if the locale is different from the previously used locale.

Field Detail

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.

localeGroup

protected LocaleGroup localeGroup
The locale group to which this object belongs.

usedLocale

protected Locale usedLocale
The locale in use.

Constructor Detail

LocalizableSupport

public LocalizableSupport(String s, Class cls)
Same as LocalizableSupport(cls, null).

LocalizableSupport

public LocalizableSupport(String s, Class cls, ClassLoader cl)
Same as LocalizableSupport(cls, null).

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: java.util.ResourceBundle

Method Detail

formatMessage

public String formatMessage(String key, Object[] args)
Implements {@link org.apache.batik.i18n.Localizable#formatMessage(String,Object[])}.

getCharacter

public int getCharacter(String key)

getCurrentLocale

protected Locale getCurrentLocale()

getDefaultLocale

public Locale getDefaultLocale()
Implements {@link org.apache.batik.i18n.ExtendedLocalizable#getDefaultLocale()}.

getInteger

public int getInteger(String key)
Returns the integer mapped with the given string

Parameters: key a key of the resource bundle

Throws: MissingResourceException if key is not the name of a resource

getLocale

public Locale getLocale()
Implements {@link org.apache.batik.i18n.Localizable#getLocale()}.

getLocaleGroup

public LocaleGroup getLocaleGroup()
Implements {@link org.apache.batik.i18n.ExtendedLocalizable#getLocaleGroup()}.

getResourceBundle

public ResourceBundle getResourceBundle()
Here for backwards compatability

getResourceBundle

protected ResourceBundle getResourceBundle(int i)

getString

public String getString(String key)

hasNextResourceBundle

protected boolean hasNextResourceBundle(int i)

lookupResourceBundle

protected ResourceBundle lookupResourceBundle(String bundle, Class theClass)

setDefaultLocale

public void setDefaultLocale(Locale l)
Implements {@link org.apache.batik.i18n.ExtendedLocalizable#setDefaultLocale(Locale)}. Later invocations of the instance methods will lead to update the resource bundle used.

setLocale

public void setLocale(Locale l)
Implements {@link org.apache.batik.i18n.Localizable#setLocale(Locale)}.

setLocaleGroup

public void setLocaleGroup(LocaleGroup lg)
Implements {@link org.apache.batik.i18n.ExtendedLocalizable#setLocaleGroup(LocaleGroup)}.

setUsedLocale

protected boolean setUsedLocale()
returns true if the locale is different from the previously used locale. Also sets 'usedLocale' to the current locale.
Copyright B) 2007 Apache Software Foundation. All Rights Reserved.