Top Description Fields Constructors Methods
org.apache.naming

public Class StringManager

extends Object
Class Inheritance
Imports
java.text.MessageFormat, java.util.HashMap, .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 classpath.

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 final Map<String, StringManager>

Constructor Summary

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

Creates a new StringManager for a given package.

Method Summary

Modifier and TypeMethod and Description
public static final synchronized StringManager

Returns:

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

Get the StringManager for a particular package.

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

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
managersback to summary
private static final Map<String, StringManager> managers

Constructor Detail

StringManagerback to summary
private StringManager(String packageName)

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 synchronized 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

getManagerback to summary
public static final StringManager getManager(Class<?> clazz)
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.