Top Description Fields Constructors Methods
org.glassfish.grizzly.http.util

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]]
Version
$Revision: 1.2 $ $Date: 2005/12/08 01:29:37 $
See Also
java.util.ResourceBundle

Field Summary

Modifier and TypeField and Description
private ResourceBundle
bundle

The ResourceBundle for this StringManager.

private static final Map<String, StringManager>

Constructor Summary

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

Creates a new StringManager for a given package.

private
StringManager(String packageName, Locale loc, ClassLoader loader)

private

Method Summary

Modifier and TypeMethod and Description
public static synchronized StringManager
getManager(String packageName, ClassLoader loader)

Get the StringManager for a particular package.

public static synchronized StringManager
getManager(ResourceBundle bundle)

Get the StringManager for a particular package.

public static synchronized StringManager
getManager(String packageName, Locale loc, ClassLoader loader)

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
getString(String key, Object[] args)

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

public String
getString(String key, Object arg)

Get a string from the underlying resource bundle and format it with the given object argument.

public String
getString(String key, Object arg1, Object arg2)

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

public String
getString(String key, Object arg1, Object arg2, Object arg3)

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

public String
getString(String key, Object arg1, Object arg2, Object arg3, Object arg4)

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bundleback to summary
private ResourceBundle bundle

The ResourceBundle for this StringManager.

managersback to summary
private static final Map<String, StringManager> managers

Constructor Detail

StringManagerback to summary
private StringManager(String packageName, ClassLoader loader)

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.

StringManagerback to summary
private StringManager(String packageName, Locale loc, ClassLoader loader)
StringManagerback to summary
private StringManager(ResourceBundle bundle)

Method Detail

getManagerback to summary
public static synchronized StringManager getManager(String packageName, ClassLoader loader)

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.

getManagerback to summary
public static synchronized StringManager getManager(ResourceBundle bundle)

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.

getManagerback to summary
public static synchronized StringManager getManager(String packageName, Locale loc, ClassLoader loader)

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

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(String key, Object[] args)

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

getStringback to summary
public String getString(String key, Object arg)

Get a string from the underlying resource bundle and format it with the given object argument. This argument can of course be a String object.

getStringback to summary
public String getString(String key, Object arg1, Object arg2)

Get a string from the underlying resource bundle and format it with the given object arguments. These arguments can of course be String objects.

getStringback to summary
public String getString(String key, Object arg1, Object arg2, Object arg3)

Get a string from the underlying resource bundle and format it with the given object arguments. These arguments can of course be String objects.

getStringback to summary
public String getString(String key, Object arg1, Object arg2, Object arg3, Object arg4)

Get a string from the underlying resource bundle and format it with the given object arguments. These arguments can of course be String objects.