Top Description Fields Constructors Methods
org.apache.tomcat.jakartaee

public Class StringManager

extends Object
Class Inheritance
Imports
java.text.MessageFormat, java.util.Hashtable, .LinkedHashMap, .Locale, .Map, .MissingResourceException, .ResourceBundle

An internationalization / localization helper class which reduces the bother of handling ResourceBundles and takes care of the common cases of message formatting which otherwise require the creation of Object arrays and such.

The StringManager operates on a package basis. One StringManager per package can be created and accessed via the getManager method call.

The StringManager will look for a ResourceBundle named by the package name given plus the suffix of "LocalStrings". In practice, this means that the localized information will be contained in a LocalStrings.properties file located in the package directory of the class path.

Please see the documentation for java.util.ResourceBundle for more information.

Authors
James Duncan Davidson [[email protected]], James Todd [[email protected]], Mel Martinez [[email protected]]
See Also
java.util.ResourceBundle

Field Summary

Modifier and TypeField and Description
private final ResourceBundle
bundle

The ResourceBundle for this StringManager.

private final Locale
private static int
private static final Map<String, Map<Locale, StringManager>>

Constructor Summary

AccessConstructor and Description
private
StringManager(String
Name of package to create StringManager for.
packageName
,
Locale locale)

Creates a new StringManager for a given package.

Method Summary

Modifier and TypeMethod and Description
public static final StringManager

Returns:

The instance associated with the package of the provide class
getManager
(Class<?>
The class for which to retrieve the StringManager
clazz
)

Get the StringManager for a given class.

public static final StringManager

Returns:

The instance associated with the given package and the default Locale
getManager
(String
The package name
packageName
)

Get the StringManager for a particular package.

public static final synchronized StringManager

Returns:

The instance associated with the given package and Locale
getManager
(String
The package name
packageName
,
Locale
The Locale
locale
)

Get the StringManager for a particular package and Locale.

public String

Returns:

resource String matching key from underlying bundle or null if not found.
getString
(String
to desired resource String
key
)

Get a string from the underlying resource bundle or return null if the String is not found.

public String

Returns:

The request string formatted with the provided arguments or the key if the key was not found.
getString
(final String
The key for the required message
key
,
final Object...
The values to insert into the message
args
)

Get a string from the underlying resource bundle and format it with the given set of arguments.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bundleback to summary
private final ResourceBundle bundle

The ResourceBundle for this StringManager.

localeback to summary
private final Locale locale
LOCALE_CACHE_SIZEback to summary
private static int LOCALE_CACHE_SIZE
managersback to summary
private static final Map<String, Map<Locale, StringManager>> managers

Constructor Detail

StringManagerback to summary
private StringManager(String packageName, Locale locale)

Creates a new StringManager for a given package. This is a private method and all access to it is arbitrated by the static getManager method call so that only one StringManager per package will be created.

Parameters
packageName:String

Name of package to create StringManager for.

Method Detail

getManagerback to summary
public static final StringManager getManager(Class<?> clazz)

Get the StringManager for a given class. The StringManager will be returned for the package in which the class is located. If a manager for that package already exists, it will be reused, else a new StringManager will be created and returned.

Parameters
clazz:Class<?>

The class for which to retrieve the StringManager

Returns:StringManager

The instance associated with the package of the provide class

getManagerback to summary
public static final StringManager getManager(String packageName)

Get the StringManager for a particular package. If a manager for a package already exists, it will be reused, else a new StringManager will be created and returned.

Parameters
packageName:String

The package name

Returns:StringManager

The instance associated with the given package and the default Locale

getManagerback to summary
public static final synchronized StringManager getManager(String packageName, Locale locale)

Get the StringManager for a particular package and Locale. If a manager for a package/Locale combination already exists, it will be reused, else a new StringManager will be created and returned.

Parameters
packageName:String

The package name

locale:Locale

The Locale

Returns:StringManager

The instance associated with the given package and Locale

getStringback to summary
public String getString(String key)

Get a string from the underlying resource bundle or return null if the String is not found.

Parameters
key:String

to desired resource String

Returns:String

resource String matching key from underlying bundle or null if not found.

Exceptions
IllegalArgumentException:
if key is null
getStringback to summary
public String getString(final String key, final Object... args)

Get a string from the underlying resource bundle and format it with the given set of arguments.

Parameters
key:String

The key for the required message

args:Object[]

The values to insert into the message

Returns:String

The request string formatted with the provided arguments or the key if the key was not found.