public class Messages extends Object
Utility wrapper around resource bundles that provides locale-specific message string lookups, as well as parameter replacement services.
If desired, this class can be used to define a managed bean wrapping
a specified resource bundle, with a declaration like this in a
faces-config.xml
configuration file:
<managed-bean> <managed-bean-name>messages</managed-bean-name> <managed-bean-class> org.apache.shale.util.Messages </managed-bean-class> <managed-bean-scope>application</managed-bean-scope> <managed-property> <property-name>name</property-name> <value>com.mycompany.mypackage.Bundle</value> </managed-property> </managed-bean>$Id: Messages.java 481403 2006-12-01 21:27:54Z rahul $
Constructor and Description |
---|
Messages()
Construct an initialized
Messages wrapper. |
Messages(String name)
Construct a new
Messages wrapper around the specified
resource bundle name, loaded by the default class loader. |
Messages(String name,
ClassLoader cl)
Construct a new
Messages wrapper around the specified
resource bundle name, loaded by the specified class loader. |
Modifier and Type | Method and Description |
---|---|
ClassLoader |
getClassLoader()
Return the
ClassLoader from which to load the
specified resource bundle, or null for the thread
context class loader. |
String |
getMessage(String key)
Retrieve the specified message string for the default locale.
|
String |
getMessage(String key,
Locale locale)
Retrieve the specified message string for the specified locale.
|
String |
getMessage(String key,
Locale locale,
Object[] params)
Retrieve the specified message string for the specified locale, and
perform parameter substitution with the specified parameters.
|
String |
getMessage(String key,
Object[] params)
Retrieve the specified message string for the default locale, and
perform parameter substitution with the specified parameters.
|
String |
getName()
Return the name of the resource bundle to be retrieved.
|
void |
setClassLoader(ClassLoader cl)
Set the
ClassLoader from which to load the
specified resource bundle. |
void |
setName(String name)
Set the name of the resource bunde to be retrieved.
|
public Messages()
Construct an initialized Messages
wrapper. At least the
name
property must be initialized before the message
retrieval public methods may be successfully utilized.
public Messages(String name)
Construct a new Messages
wrapper around the specified
resource bundle name, loaded by the default class loader.
name
- Name of the requested ResourceBundle
public Messages(String name, ClassLoader cl)
Construct a new Messages
wrapper around the specified
resource bundle name, loaded by the specified class loader.
name
- Name of the requested ResourceBundle
cl
- ClassLoader
to use for loading this
resource bundle, or null
for the default (which
selects the thread context class loader)public ClassLoader getClassLoader()
Return the ClassLoader
from which to load the
specified resource bundle, or null
for the thread
context class loader.
public void setClassLoader(ClassLoader cl)
Set the ClassLoader
from which to load the
specified resource bundle.
cl
- The new class loader, or null
for the
thread context class loaderpublic String getName()
Return the name of the resource bundle to be retrieved.
public void setName(String name)
Set the name of the resource bunde to be retrieved.
name
- New name of the resource bundle to be retrievedpublic String getMessage(String key)
Retrieve the specified message string for the default locale. If no
message can be found, return null
.
key
- Key to the message string to look uppublic String getMessage(String key, Object[] params)
Retrieve the specified message string for the default locale, and
perform parameter substitution with the specified parameters. If no
message can be found, return null
.
key
- Key to the message string to look upparams
- Parameter replacement valuespublic String getMessage(String key, Locale locale)
Retrieve the specified message string for the specified locale. If no
message can be found, return null
.
key
- Key to the message string to look uplocale
- Locale used to localize this messagepublic String getMessage(String key, Locale locale, Object[] params)
Retrieve the specified message string for the specified locale, and
perform parameter substitution with the specified parameters. If no
message can be found, return null
.
key
- Key to the message string to look uplocale
- Locale used to localize this messageparams
- Parameter replacement valuesCopyright © 2004-2013 Apache Software Foundation. All Rights Reserved.