eu.beesoft.gaia.util
Class Language

java.lang.Object
  extended by eu.beesoft.gaia.util.Language

public class Language
extends java.lang.Object

Encapsulates the work with resource bundles and language dependent texts.


Constructor Summary
protected Language()
          Creates a new instance of the Language.
 
Method Summary
 void addLanguageListener(LanguageListener listener)
          Adds LanguageListener to the listeners list.
static Language getInstance()
          Returns the last created instance of Language.
 java.util.Locale getLocale()
          Returns a Locale for this object.
 java.text.DateFormat getLongDateFormat()
          Returns a long date format for current locale.
 java.text.DateFormat getLongTimeFormat()
          Returns a long time format for current locale.
 java.text.DateFormat getMediumDateFormat()
          Returns a medium date format for current locale.
 java.text.DateFormat getMediumTimeFormat()
          Returns a medium time format for current locale.
 java.util.ResourceBundle getResourceBundle(java.lang.String name)
          Returns a resource bundle with given name and for current object's locale.
 java.text.DateFormat getShortDateFormat()
          Returns a short date format for current locale.
 java.text.DateFormat getShortTimeFormat()
          Returns a short time format for current locale.
 java.lang.String getText(java.lang.Object resourceBundleOwner, java.lang.String textKey)
          Returns a text from resource bundle related to the given resourceBundleOwner for the textKey.
 java.lang.String getText(java.lang.Object resourceBundleOwner, java.lang.String textKey, java.lang.String defaultValue)
          Returns a text from resource bundle related to the given resourceBundleOwner for the textKey.
 java.lang.String getText(java.lang.String resourceBundleName, java.lang.String textKey)
          Returns a text from resource bundle for given textKey.
 java.lang.String getText(java.lang.String resourceBundleName, java.lang.String textKey, java.lang.String defaultValue)
          Returns a text from resource bundle for given textKey.
 void removeLanguageListener(LanguageListener listener)
          Removes LanguageListener from the listeners list.
 void setLocale(java.util.Locale locale)
          Sets Locale for this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Language

protected Language()
Creates a new instance of the Language.

Method Detail

getInstance

public static Language getInstance()
Returns the last created instance of Language.

Returns:
last created instance of Language

addLanguageListener

public void addLanguageListener(LanguageListener listener)
Adds LanguageListener to the listeners list.

Parameters:
listener - - a listener to add

removeLanguageListener

public void removeLanguageListener(LanguageListener listener)
Removes LanguageListener from the listeners list.

Parameters:
listener - - a listener to remove

setLocale

public void setLocale(java.util.Locale locale)
Sets Locale for this object. All registered LanguageListener instances are notified.

Parameters:
locale - - a locale to set

getLocale

public java.util.Locale getLocale()
Returns a Locale for this object.

Returns:
current object's locale

getLongDateFormat

public java.text.DateFormat getLongDateFormat()
Returns a long date format for current locale.

Returns:
long date format

getMediumDateFormat

public java.text.DateFormat getMediumDateFormat()
Returns a medium date format for current locale.

Returns:
medium date format

getShortDateFormat

public java.text.DateFormat getShortDateFormat()
Returns a short date format for current locale.

Returns:
short date format

getLongTimeFormat

public java.text.DateFormat getLongTimeFormat()
Returns a long time format for current locale.

Returns:
long time format

getMediumTimeFormat

public java.text.DateFormat getMediumTimeFormat()
Returns a medium time format for current locale.

Returns:
medium time format

getShortTimeFormat

public java.text.DateFormat getShortTimeFormat()
Returns a short time format for current locale.

Returns:
short time format

getResourceBundle

public java.util.ResourceBundle getResourceBundle(java.lang.String name)
Returns a resource bundle with given name and for current object's locale. Returns null, if no resource bundle is found, no exception is thrown.

Parameters:
name - - the base name of the resource bundle, a fully qualified class name
Returns:
a resource bundle for the given base name and the current locale or null if not found

getText

public java.lang.String getText(java.lang.Object resourceBundleOwner,
                                java.lang.String textKey)
Returns a text from resource bundle related to the given resourceBundleOwner for the textKey. If key is not found, returns textKey.

This method obtains the qualified class name of the resourceBundleOwner and uses it to get ResourceBundle and text for the textKey from it. If text not found, it takes a superclass of resourceBundleOwner and repeats these steps.

Parameters:
resourceBundleOwner - - the base name of the resource bundle, a fully qualified class name
textKey - - the key for the desired text
Returns:
a text associated with textKey or the textKey if no association found

getText

public java.lang.String getText(java.lang.Object resourceBundleOwner,
                                java.lang.String textKey,
                                java.lang.String defaultValue)
Returns a text from resource bundle related to the given resourceBundleOwner for the textKey. If key is not found, returns defaultValue.

This method obtains the qualified class name of the resourceBundleOwner and uses it to get ResourceBundle and text for the textKey from it. If text not found, it takes a superclass of resourceBundleOwner and repeats these steps.

Parameters:
resourceBundleOwner - - the base name of the resource bundle, a fully qualified class name
textKey - - the key for the desired text
defaultValue - - value is used when no value for textKey is found
Returns:
a text associated with textKey or the textKey if no association found

getText

public java.lang.String getText(java.lang.String resourceBundleName,
                                java.lang.String textKey)
Returns a text from resource bundle for given textKey. If key is not found, returns textKey.

Parameters:
resourceBundleName - - the base name of the resource bundle, a fully qualified class name
textKey - - the key for the desired text
Returns:
a text associated with textKey or the textKey if no association found

getText

public java.lang.String getText(java.lang.String resourceBundleName,
                                java.lang.String textKey,
                                java.lang.String defaultValue)
Returns a text from resource bundle for given textKey. If key is not found, returns defaultValue.

Parameters:
resourceBundleName - - the base name of the resource bundle, a fully qualified class name
textKey - - the key for the desired text
defaultValue - - value is used when no value for textKey is found
Returns:
a text associated with textKey or defaultValue if no association found