blob: 40d36b14ef25d246da6f4779da1832b7b004a7d7 [file] [log] [blame]
<html>
<head>
<title>VelocityStruts - MessageTool</title>
<meta name="author" value="Gabriel Sidler"/>
<meta name="email" value="sidler@apache.org" />
</head>
<body bgcolor="#ffffff" text="#000000" link="#525D76"
alink="#525D76" vlink="#525D76">
<table border="0" width="100%" cellspacing="4">
<tr><td colspan="2">
<a href="http://jakarta.apache.org/">
<img src="http://jakarta.apache.org/images/jakarta-logo.gif"
align="left" alt="The Jakarta Project" border="0"/>
</a>
<a href="index.html">
<img src="../images/velocitystruts.png" align="right" alt="< Velocity Tools - Struts >" border="0"/>
</a>
</td></tr>
<tr>
<td colspan="2">
<hr noshade="" size="1"/>
</td>
</tr>
<tr>
<td width="20%" valign="top" nowrap="true">
<p><strong><a href="../">Velocity Tools</a></strong></p>
<p>
<strong>VelocityStruts</strong>
</p>
<ul>
<li><a href="index.html">Overview</a></li>
<li><a href="index.html#Benefits">Benefits</a></li>
<li><a href="../index.html#Download">Download</a></li>
<li><a href="userguide.html">User Guide</a></li>
<li><a href="userguide.html#Installation">Installation</a></li>
<li><a href="../index.html#Example Applications">Examples</a></li>
<li><a href="../javadoc/index.html">Javadoc</a></li>
</ul>
<p>
<a href="StrutsTools.html"><strong>VelocityStruts Tools</strong></a>
</p>
<ul>
<li><a href="ActionMessagesTool.html">ActionMessagesTool</a></li>
<li><a href="ErrorsTool.html">ErrorsTool</a></li>
<li><a href="FormTool.html">FormTool</a></li>
<li><a href="MessageTool.html">MessageTool</a></li>
<li><a href="StrutsLinkTool.html">StrutsLinkTool</a></li>
<li><a href="SecureLinkTool.html">SecureLinkTool</a></li>
<li><a href="TilesTool.html">TilesTool</a></li>
<li><a href="ValidatorTool.html">ValidatorTool</a></li>
</ul>
<p>
<strong>Other Subprojects</strong>
</p>
<ul>
<li><a href="../generic/">GenericTools</a></li>
<li><a href="../view/">VelocityView</a></li>
</ul>
<p>
</p>
</td>
<!-- RIGHT SIDE MAIN BODY -->
<td colspan="1" valign="top" align="left">
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr>
<td colspan="2" bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica.sanserif">
<a name="MessageTool Reference Documentation">
<strong>MessageTool Reference Documentation</strong></a></font>
</td>
</tr>
<tr>
<td NOWRAP> &nbsp; &nbsp; &nbsp; &nbsp; </td>
<td>
<p>
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.
</p>
<table cellpadding="0" cellspacing="0">
<tr><td colspan="2"><strong>Class</strong></td></tr>
<tr><td>&nbsp;</td><td>org.apache.velocity.tools.struts.MessageTool</td></tr>
<tr><td colspan="2"><strong>Name</strong></td></tr>
<tr><td>&nbsp;</td><td>$text (this is the recommended name of the tool in
the Velocity context)</td></tr>
<tr><td colspan="2"><strong>Toolbox Configuration Example</strong></td></tr>
<tr><td>&nbsp;</td><td><pre>&lt;tool&gt;
&lt;key&gt;text&lt;/key&gt;
&lt;scope&gt;request&lt;/scope&gt;
&lt;class&gt;org.apache.velocity.tools.struts.MessageTool&lt;/class&gt;
&lt;/tool&gt;</pre></td></tr>
<tr><td colspan="2"><strong>Author(s)</strong></td></tr>
<tr>
<td>&nbsp;</td>
<td><a href="mailto:sidler@teamup.com">Gabriel Sidler</a><br></td>
</tr>
</table>
<dl>
<dt><strong>Method Overview</strong></dt>
<dd>
<table cellpadding="2" cellspacing="2" border="0">
<tr>
<td bgcolor="EEEEEE" nowrap>
<a href="#get()">get()</a></td>
<td bgcolor="EEEEEE">
Looks up and returns the localized message for the specified key.
</td>
</tr>
<tr>
<td bgcolor="EEEEEE" nowrap>
<a href="#exists()">exists()</a></td>
<td bgcolor="EEEEEE">
Checks if a message string for a specified message key exists
for the user's locale.
</td>
</tr>
</table>
</dd>
</dl>
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr>
<td colspan="2" bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica.sanserif">
<a name="get()">
<strong>get()</strong></a></font>
</td>
</tr>
<tr>
<td NOWRAP> &nbsp; &nbsp; &nbsp; &nbsp; </td>
<td>
<p>
<abstract>
Looks up and returns the localized message for the specified key.
</abstract>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
TextKey get(String key)
</signature>
</code></font>
</td></tr></table>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
String get(String key, String bundle)
</signature>
</code></font>
</td></tr></table>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
String get(String key, Object args[])
</signature>
</code></font>
</td></tr></table>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
String get(String key, String bundle, Object args[])
</signature>
</code></font>
</td></tr></table>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
String get(String key, List args)
</signature>
</code></font>
</td></tr></table>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
String get(String key, String bundle, List args)
</signature>
</code></font>
</td></tr></table>
</p>
<dl>
<dt><strong>Parameters</strong></dt>
<dd>
<dl>
<dt>key</dt>
<dd>
<parameter name="key">
Message key.
</parameter>
</dd>
<dt>bundle</dt>
<dd>
<parameter name="bundle">
The (non-default) message-resources bundle that holds the message.
</parameter>
</dd>
<dt>args</dt>
<dd>
<parameter name="args">
Replacement parameters for this message. Typically
an array of Strings or a List of Strings (but any
Object with a reasonable <code>toString()</code>
method can be used).
</parameter>
</dd>
</dl>
</dd>
</dl>
<dl>
<dt><strong>Returns</strong></dt>
<dd>
<returns>
The localized message for the specified key. Returns null if no
message exists for the key passed.
</returns>
</dd>
</dl>
<dl>
<dt><strong>See Also</strong></dt>
<dd>
<see>
Struts user's guide on
<a href="http://jakarta.apache.org/struts/userGuide/building_view.html#i18n">
Internationalized Messages</a>.
</see>
</dd>
</dl>
<p>The user's locale is consulted to determine the language of the
message. The third, fourth, fifth and sixth signatures take a list
of up to five replacement parameters. The third and fourth signatures
are provided for compatibility with existing applications. The fifth and
sixth signatures are more Velocity friendly.</p>
<p>Assuming that the message resource files contain the following messages:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>title=Welcome to Velocity for Struts
test=This message has five replacement parameters: {0}, {1}, {2}, {3}, {4}
label.one=foobar
label.two=woogie!</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p>then the following Velocity script:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>$text.title
$text.get('test', ['bear', 'wolf', 'tiger'])
$text.label.one
$text.label.two</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<p>produces this output:</p>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>Welcome to Velocity for Struts
Welcome to Velocity for Struts
This message has five replacement parameters: bear, wolf, tiger, {3}, {4}
foobar
woogie!</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<br clear="all">
</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr>
<td colspan="2" bgcolor="#525D76">
<font color="#ffffff" face="arial,helvetica.sanserif">
<a name="exists()">
<strong>exists()</strong></a></font>
</td>
</tr>
<tr>
<td NOWRAP> &nbsp; &nbsp; &nbsp; &nbsp; </td>
<td>
<p>
<abstract>
Checks if a message string for a specified message key exists
for the user's locale.
</abstract>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
boolean exists(String key)
</signature>
</code></font>
</td></tr></table>
</p>
<p>
<table width="100%"><tr><td bgcolor="EEEEEE">
<font size="+1"><code>
<signature>
boolean exists(String key, String bundle)
</signature>
</code></font>
</td></tr></table>
</p>
<dl>
<dt><strong>Parameters</strong></dt>
<dd>
<dl>
<dt>key</dt>
<dd>
<parameter name="key">
Message key.
</parameter>
</dd>
<dt>bundle</dt>
<dd>
<parameter name="bundle">
The (non-default) message-resources bundle that holds the message.
</parameter>
</dd>
</dl>
</dd>
</dl>
<dl>
<dt><strong>Returns</strong></dt>
<dd>
<returns>
<code>true</code> if a message string for the specified message
key exists for the user's locale. <code>false</code> otherwise.
</returns>
</dd>
</dl>
<table width="100%" cellpadding="1" cellspacing="0" border="0"><tr><td bgcolor="#000000">
<table width="100%" cellpadding="5" cellspacing="0" border="0"><tr><td bgcolor="#FFFFFF">
<pre><sourcecode>$text.exists("title")</sourcecode></pre>
</td></tr></table>
</td></tr></table>
<br clear="all">
</td>
</tr>
</table>
</td>
</tr>
<!-- FOOTER SEPARATOR -->
<tr>
<td colspan="2">
<hr noshade="" size="1"/>
</td>
</tr>
<!-- PAGE FOOTER -->
<tr><td colspan="2">
<div align="center"><font color="#525D76" size="-1"><em>
Copyright &#169; 1999-2003, Apache Software Foundation
</em></font></div>
</td></tr>
</table>
</body>
</html>