public class MessageTool extends MessageResourcesTool
View tool that provides methods to render Struts application resources for internationalized text.
Template example(s):
#if( $text.greeting.exists )
$text.greeting
#end
Toolbox configuration:
<tool>
<key>text</key>
<scope>request</scope>
<class>org.apache.velocity.tools.struts.MessageTool</class>
</tool>
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, locale, LOG, request, resources| Constructor and Description |
|---|
MessageTool()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
exists(java.lang.String key)
Checks if a message string for a specified message key exists
for the user's locale.
|
boolean |
exists(java.lang.String key,
java.lang.String bundle)
Checks if a message string for a specified message key exists
for the user's locale.
|
MessageTool.TextKey |
get(java.lang.String key)
Looks up and returns the localized message for the specified key.
|
java.lang.String |
get(java.lang.String key,
java.util.List args)
Same as
get(String key, Object[] args), but takes a
java.util.List instead of an array. |
java.lang.String |
get(java.lang.String key,
java.lang.Object[] args)
Looks up and returns the localized message for the specified key.
|
java.lang.String |
get(java.lang.String key,
java.lang.String bundle)
Looks up and returns the localized message for the specified key.
|
java.lang.String |
get(java.lang.String key,
java.lang.String bundle,
java.util.List args)
Same as
get(String key, Object[] args), but takes a
java.util.List instead of an array. |
java.lang.String |
get(java.lang.String key,
java.lang.String bundle,
java.util.List args,
java.util.Locale locale)
Looks up and returns the localized message for the specified key.
|
java.lang.String |
get(java.lang.String key,
java.lang.String bundle,
java.lang.Object[] args)
Looks up and returns the localized message for the specified key.
|
java.lang.String |
get(java.lang.String key,
java.lang.String bundle,
java.lang.Object[] args,
java.util.Locale locale)
Looks up and returns the localized message for the specified key.
|
getResources, initpublic MessageTool()
public MessageTool.TextKey get(java.lang.String key)
Example use: $text.forms.profile.title
key - message keypublic java.lang.String get(java.lang.String key,
java.lang.String bundle)
key - message keybundle - The bundle name to look for.null if no such message existspublic java.lang.String get(java.lang.String key,
java.lang.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 java.lang.String get(java.lang.String key,
java.lang.String bundle,
java.lang.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 java.lang.String get(java.lang.String key,
java.lang.String bundle,
java.lang.Object[] args,
java.util.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 java.lang.String get(java.lang.String key,
java.util.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 java.lang.String get(java.lang.String key,
java.lang.String bundle,
java.util.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 java.lang.String get(java.lang.String key,
java.lang.String bundle,
java.util.List args,
java.util.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(java.lang.String key)
key - message keytrue if a message strings exists,
false otherwisepublic boolean exists(java.lang.String key,
java.lang.String bundle)
key - message keybundle - The bundle name to look for.true if a message strings exists,
false otherwiseCopyright (c) 2003-2007 Apache Software Foundation