org.apache.velocity.app.tools
public class VelocityFormatter extends Object
Here's an example of some uses:
$formatter.formatShortDate($object.Date)
$formatter.formatLongDate($db.getRecord(232).getDate())
$formatter.formatArray($array)
$formatter.limitLen(30, $object.Description)
Version: $Id: VelocityFormatter.java,v 1.9 2003/05/04 17:06:11 geirm Exp $
Nested Class Summary | |
---|---|
class | VelocityFormatter.VelocityAlternator
Class that returns alternating values in a template. |
class | VelocityFormatter.VelocityAutoAlternator
As VelocityAlternator, but calls alternate()
automatically on rendering in a template. |
Field Summary | |
---|---|
Context | context |
NumberFormat | nf |
Constructor Summary | |
---|---|
VelocityFormatter(Context context)
Constructor needs a backpointer to the context.
|
Method Summary | |
---|---|
String | formatArray(Object array)
Formats an array into the form "A, B and C".
|
String | formatArray(Object array, String delim)
Formats an array into the form
"A<delim>B<delim>C".
|
String | formatArray(Object array, String delim, String finaldelim)
Formats an array into the form
"A<delim>B<finaldelim>C".
|
String | formatLongDate(Date date)
Formats a date in DateFormat.LONG style.
|
String | formatLongDateTime(Date date)
Formats a date/time in 'long' style.
|
String | formatShortDate(Date date)
Formats a date in DateFormat.SHORT style.
|
String | formatShortDateTime(Date date)
Formats a date/time in 'short' style.
|
String | formatVector(List list)
Formats a vector into the form "A, B and C".
|
String | formatVector(List list, String delim)
Formats a vector into the form "A<delim>B<delim>C".
|
String | formatVector(List list, String delim, String finaldelim)
Formats a list into the form
"Adelim>B<finaldelim>C".
|
Object | isNull(Object o, Object dflt)
Returns a default value if the object passed is null. |
String | limitLen(int maxlen, String string)
Limits 'string' to 'maxlen' characters. |
String | limitLen(int maxlen, String string, String suffix)
Limits 'string' to 'maxlen' character. |
String | makeAlternator(String name, String alt1, String alt2)
Makes an alternator object that alternates between two values.
|
String | makeAlternator(String name, String alt1, String alt2, String alt3)
Makes an alternator object that alternates between three
values.
|
String | makeAlternator(String name, String alt1, String alt2, String alt3, String alt4)
Makes an alternator object that alternates between four values.
|
String | makeAutoAlternator(String name, String alt1, String alt2)
Makes an alternator object that alternates between two values
automatically.
|
Parameters: context A Context.
Parameters: array An Object.
Returns: A String.
Parameters: array An Object. delim A String.
Returns: A String.
Parameters: array An Object. delim A String. finalDelim A String.
Returns: A String.
DateFormat.LONG
style.
Parameters: date The date to format.
Returns: The formatted date as text.
Parameters: date The date to format.
Returns: The formatted date as text.
DateFormat.SHORT
style.
Parameters: date The date to format.
Returns: The formatted date as text.
Parameters: date The date to format.
Returns: The formatted date as text.
Parameters: list The list of elements to format.
Returns: A String.
Parameters: list The list of elements to format. delim A String.
Returns: A String.
Parameters: list The list of elements to format. delim A String. finalDelim A String.
Returns: A String.
Parameters: maxlen An int with the maximum length. string A String.
Returns: A String.
Parameters: maxlen An int with the maximum length. string A String. suffix A String.
Returns: A String.
Example usage in a Velocity template:
<table>
$formatter.makeAlternator("rowcolor", "#c0c0c0", "#e0e0e0")
#foreach $item in $items
#begin
<tr><td bgcolor="$rowcolor">$item.Name</td></tr>
$rowcolor.alternate()
#end
</table>
Parameters: name The name for the alternator int the context. alt1 The first alternate. alt2 The second alternate.
Returns: The newly created instance.
See Also: VelocityFormatter
See Also: VelocityFormatter
See Also: VelocityFormatter