@DefaultKey(value="text") @ValidScope(value="request") public class MessageTool extends MessageResourcesTool
The MessageTool is used to render internationalized message strings. Source of the strings are the message resource bundles of the Struts framework. The following methods operate on these message resources.
Template example(s): #if( $text.greeting.exists ) $text.greeting #end Toolbox configuration: <tools> <toolbox scope="request"> <tool class="org.apache.velocity.tools.struts.MessageTool"/> </toolbox> </tools>
This tool should only be used in the request scope.
Modifier and Type | Class and Description |
---|---|
class |
MessageTool.TextKey
Helper class to simplify tool usage when retrieving
no-arg messages from the default bundle that have periods
in their key.
|
application, LOG, request
Constructor and Description |
---|
MessageTool() |
Modifier and Type | Method and Description |
---|---|
boolean |
exists(String key)
Checks if a message string for a specified message key exists
for the user's locale.
|
boolean |
exists(String key,
String bundle)
Checks if a message string for a specified message key exists
for the user's locale.
|
MessageTool.TextKey |
get(String key)
Looks up and returns the localized message for the specified key.
|
String |
get(String key,
List args)
Same as
get(String key, Object[] args) , but takes a
java.util.List instead of an array. |
String |
get(String key,
Object[] args)
Looks up and returns the localized message for the specified key.
|
String |
get(String key,
String bundle)
Looks up and returns the localized message for the specified key.
|
String |
get(String key,
String bundle,
List args)
Same as
get(String key, Object[] args) , but takes a
java.util.List instead of an array. |
String |
get(String key,
String bundle,
List args,
Locale locale)
Looks up and returns the localized message for the specified key.
|
String |
get(String key,
String bundle,
Object[] args)
Looks up and returns the localized message for the specified key.
|
String |
get(String key,
String bundle,
Object[] args,
Locale locale)
Looks up and returns the localized message for the specified key.
|
configure, getLocale, getResources, init
public MessageTool.TextKey get(String key)
Example use: $text.forms.profile.title
key
- message keypublic String get(String key, String bundle)
key
- message keybundle
- The bundle name to look for.null
if no such message existspublic String get(String key, Object[] args)
args
are
inserted into the message. The user's locale is consulted to
determine the language of the message.key
- message keyargs
- replacement parameters for this messagenull
if no such message existspublic String get(String key, String bundle, Object[] args)
args
are
inserted into the message. The user's locale is consulted to
determine the language of the message.key
- message keybundle
- The bundle name to look for.args
- replacement parameters for this messagenull
if no such message existspublic String get(String key, String bundle, Object[] args, Locale locale)
args
are
inserted into the message.key
- message keybundle
- The bundle name to look for.args
- replacement parameters for this messagelocale
- The locale to use for this message.null
if no such message existspublic String get(String key, List args)
get(String key, Object[] args)
, but takes a
java.util.List
instead of an array. This is more
Velocity friendly.key
- message keyargs
- replacement parameters for this messagenull
if no such message existspublic String get(String key, String bundle, List args)
get(String key, Object[] args)
, but takes a
java.util.List
instead of an array. This is more
Velocity friendly.key
- message keybundle
- The bundle name to look for.args
- replacement parameters for this messagenull
if no such message existspublic String get(String key, String bundle, List args, Locale locale)
args
are
inserted into the message.key
- message keybundle
- The bundle name to look for.args
- replacement parameters for this messagelocale
- The locale to use for this message.null
if no such message existspublic boolean exists(String key)
key
- message keytrue
if a message strings exists,
false
otherwiseCopyright © 2002–2021 Apache Software Foundation. All rights reserved.