Package org.apache.velocity.tools.struts
Class MessageTool
- java.lang.Object
-
- org.apache.velocity.tools.struts.MessageResourcesTool
-
- org.apache.velocity.tools.struts.MessageTool
-
@DefaultKey("text") @ValidScope("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.
- Since:
- VelocityTools 1.0
- Version:
- $Id$
- Author:
- Gabe Sidler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMessageTool.TextKeyHelper class to simplify tool usage when retrieving no-arg messages from the default bundle that have periods in their key.
-
Field Summary
-
Fields inherited from class org.apache.velocity.tools.struts.MessageResourcesTool
application, LOG, request
-
-
Constructor Summary
Constructors Constructor Description MessageTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanexists(String key)Checks if a message string for a specified message key exists for the user's locale.booleanexists(String key, String bundle)Checks if a message string for a specified message key exists for the user's locale.MessageTool.TextKeyget(String key)Looks up and returns the localized message for the specified key.Stringget(String key, Object[] args)Looks up and returns the localized message for the specified key.Stringget(String key, String bundle)Looks up and returns the localized message for the specified key.Stringget(String key, String bundle, Object[] args)Looks up and returns the localized message for the specified key.Stringget(String key, String bundle, Object[] args, Locale locale)Looks up and returns the localized message for the specified key.Stringget(String key, String bundle, List args)Same asget(String key, Object[] args), but takes ajava.util.Listinstead of an array.Stringget(String key, String bundle, List args, Locale locale)Looks up and returns the localized message for the specified key.Stringget(String key, List args)Same asget(String key, Object[] args), but takes ajava.util.Listinstead of an array.-
Methods inherited from class org.apache.velocity.tools.struts.MessageResourcesTool
configure, getLocale, getResources, init
-
-
-
-
Method Detail
-
get
public MessageTool.TextKey get(String key)
Looks up and returns the localized message for the specified key. The user's locale is consulted to determine the language of the message.Example use: $text.forms.profile.title
- Parameters:
key- message key
-
get
public String get(String key, String bundle)
Looks up and returns the localized message for the specified key. The user's locale is consulted to determine the language of the message.- Parameters:
key- message keybundle- The bundle name to look for.- Returns:
- the localized message for the specified key or
nullif no such message exists - Since:
- VelocityTools 1.1
-
get
public String get(String key, Object[] args)
Looks up and returns the localized message for the specified key. Replacement parameters passed withargsare inserted into the message. The user's locale is consulted to determine the language of the message.- Parameters:
key- message keyargs- replacement parameters for this message- Returns:
- the localized message for the specified key or
nullif no such message exists
-
get
public String get(String key, String bundle, Object[] args)
Looks up and returns the localized message for the specified key. Replacement parameters passed withargsare inserted into the message. The user's locale is consulted to determine the language of the message.- Parameters:
key- message keybundle- The bundle name to look for.args- replacement parameters for this message- Returns:
- the localized message for the specified key or
nullif no such message exists - Since:
- VelocityTools 1.1
-
get
public String get(String key, String bundle, Object[] args, Locale locale)
Looks up and returns the localized message for the specified key. Replacement parameters passed withargsare inserted into the message.- Parameters:
key- message keybundle- The bundle name to look for.args- replacement parameters for this messagelocale- The locale to use for this message.- Returns:
- the localized message for the specified key or
nullif no such message exists - Since:
- VelocityTools 1.4
-
get
public String get(String key, List args)
Same asget(String key, Object[] args), but takes ajava.util.Listinstead of an array. This is more Velocity friendly.- Parameters:
key- message keyargs- replacement parameters for this message- Returns:
- the localized message for the specified key or
nullif no such message exists
-
get
public String get(String key, String bundle, List args)
Same asget(String key, Object[] args), but takes ajava.util.Listinstead of an array. This is more Velocity friendly.- Parameters:
key- message keybundle- The bundle name to look for.args- replacement parameters for this message- Returns:
- the localized message for the specified key or
nullif no such message exists - Since:
- VelocityTools 1.1
-
get
public String get(String key, String bundle, List args, Locale locale)
Looks up and returns the localized message for the specified key. Replacement parameters passed withargsare inserted into the message.- Parameters:
key- message keybundle- The bundle name to look for.args- replacement parameters for this messagelocale- The locale to use for this message.- Returns:
- the localized message for the specified key or
nullif no such message exists - Since:
- VelocityTools 1.4
-
exists
public boolean exists(String key)
Checks if a message string for a specified message key exists for the user's locale.- Parameters:
key- message key- Returns:
trueif a message strings exists,falseotherwise
-
-