fdda.utils
Class Localization

java.lang.Object
  |
  +--fdda.utils.Localization

public final class Localization
extends Object

Provides some helping methods pertaining to the output of localized Strings, either in the dialog or for messages. The locale can be specified if the default locale shall not be used.

Author:
Jörg Rüdenauer

Method Summary
static String formatMessage(String message, Object o1)
          Formats a message using MessageFormat.format, version with 1 parameter.
static String formatMessage(String message, Object[] params)
          Formats a message using MessageFormat.format.
static String formatMessage(String message, Object o1, Object o2)
          Formats a message using MessageFormat.format, version with 2 parameters.
static String formatMessage(String message, Object o1, Object o2, Object o3)
          Formats a message using MessageFormat.format, version with 3 parameter.
static Locale getLocale()
          Returns the used locale.
static String getLocalizedString(Class aClass, String key, String aDefault)
          Loads a localized version of a String out of a resource bundle.
static String getLocalizedString(ResourceBundle bundle, String key, String aDefault)
          Loads a localized version of a String out of a resource bundle.
static ResourceBundle getResourceBundleForPackage(Class aClass)
          Loads a resource bundle for a certain package.
static void setLocale(Locale aLocale)
          Sets the locale that is used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setLocale

public static void setLocale(Locale aLocale)
Sets the locale that is used. If null is given, it is ignored.

Parameters:
aLocale - the new locale

getLocale

public static Locale getLocale()
Returns the used locale.

Returns:
the locale

formatMessage

public static String formatMessage(String message,
                                   Object[] params)
Formats a message using MessageFormat.format. Catches possibly occuring exceptions.

Parameters:
message - the message
params - the parameters
Returns:
the formatted message
See Also:
MessageFormat

formatMessage

public static String formatMessage(String message,
                                   Object o1)
Formats a message using MessageFormat.format, version with 1 parameter. Catches possibly occuring exceptions.

Parameters:
message - the message
o1 - the first parameter
Returns:
the formatted message
See Also:
MessageFormat

formatMessage

public static String formatMessage(String message,
                                   Object o1,
                                   Object o2)
Formats a message using MessageFormat.format, version with 2 parameters. Catches possibly occuring exceptions.

Parameters:
message - the message
o1 - the first parameter
o2 - the second parameter
Returns:
the formatted message
See Also:
MessageFormat

formatMessage

public static String formatMessage(String message,
                                   Object o1,
                                   Object o2,
                                   Object o3)
Formats a message using MessageFormat.format, version with 3 parameter. Catches possibly occuring exceptions.

Parameters:
message - the message
o1 - the first parameter
o2 - the second parameter
o3 - the third parameter
Returns:
the formatted message
See Also:
MessageFormat

getResourceBundleForPackage

public static ResourceBundle getResourceBundleForPackage(Class aClass)
Loads a resource bundle for a certain package. The package is determined by a class in it. Packages should be roughly equivalent to components and should therefore use different resource bundles.
The resources must either be in a ResourceBundle class in the package with the name 'LocaleResources[_language etc.]' or in a resource file in the package directory with the name 'LocalResources[_language etc.].properties.

Parameters:
aClass - a class in the package, must not be null
Returns:
the resource bundle for the package
Throws:
MissingResourceException - if the resource bundle isn't found
See Also:
ResourceBundle

getLocalizedString

public static String getLocalizedString(ResourceBundle bundle,
                                        String key,
                                        String aDefault)
Loads a localized version of a String out of a resource bundle. All exceptions are caught; in case of an exception, the default String is returned.

Parameters:
bundle - the resource bundle, must not be null
key - the key for the String
aDefault - the default String
Returns:
the localized String

getLocalizedString

public static String getLocalizedString(Class aClass,
                                        String key,
                                        String aDefault)
Loads a localized version of a String out of a resource bundle. The resource bundle is determined by a class and is the resource bundle for the package of the class. Catches all exceptions; if an exception occurs, the default String is returned.

Parameters:
aClass - a class
key - the key for the String
aDefault - the default String
Returns:
the localized String
See Also:
getResourceBundleForPackage(Class)


API documentation for FDDA version 0.9. Generated on 17/02/2004 14:12.