| 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.velocity.app.tools.VelocityFormatter
public class VelocityFormatter
Formatting tool for inserting into the Velocity WebContext. Can format dates or lists of objects.
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)
 
| Nested Class Summary | |
|---|---|
 class | 
VelocityFormatter.VelocityAlternator
Deprecated. Class that returns alternating values in a template.  | 
 class | 
VelocityFormatter.VelocityAutoAlternator
Deprecated. As VelocityAlternator, but calls alternate()
 automatically on rendering in a template. | 
| Constructor Summary | |
|---|---|
VelocityFormatter(Context context)
Deprecated. Constructor needs a backpointer to the context.  | 
|
| Method Summary | |
|---|---|
 String | 
formatArray(Object array)
Deprecated. Formats an array into the form "A, B and C".  | 
 String | 
formatArray(Object array,
            String delim)
Deprecated. Formats an array into the form "A<delim>B<delim>C".  | 
 String | 
formatArray(Object array,
            String delim,
            String finaldelim)
Deprecated. Formats an array into the form "A<delim>B<finaldelim>C".  | 
 String | 
formatLongDate(Date date)
Deprecated. Formats a date in DateFormat.LONG style. | 
 String | 
formatLongDateTime(Date date)
Deprecated. Formats a date/time in 'long' style.  | 
 String | 
formatShortDate(Date date)
Deprecated. Formats a date in DateFormat.SHORT style. | 
 String | 
formatShortDateTime(Date date)
Deprecated. Formats a date/time in 'short' style.  | 
 String | 
formatVector(List list)
Deprecated. Formats a vector into the form "A, B and C".  | 
 String | 
formatVector(List list,
             String delim)
Deprecated. Formats a vector into the form "A<delim>B<delim>C".  | 
 String | 
formatVector(List list,
             String delim,
             String finaldelim)
Deprecated. Formats a list into the form "Adelim>B<finaldelim>C".  | 
 Object | 
isNull(Object o,
       Object dflt)
Deprecated. Returns a default value if the object passed is null.  | 
 String | 
limitLen(int maxlen,
         String string)
Deprecated. Limits 'string' to 'maxlen' characters.  | 
 String | 
limitLen(int maxlen,
         String string,
         String suffix)
Deprecated. Limits 'string' to 'maxlen' character.  | 
 String | 
makeAlternator(String name,
               String alt1,
               String alt2)
Deprecated. Makes an alternator object that alternates between two values.  | 
 String | 
makeAlternator(String name,
               String alt1,
               String alt2,
               String alt3)
Deprecated. Makes an alternator object that alternates between three values.  | 
 String | 
makeAlternator(String name,
               String alt1,
               String alt2,
               String alt3,
               String alt4)
Deprecated. Makes an alternator object that alternates between four values.  | 
 String | 
makeAutoAlternator(String name,
                   String alt1,
                   String alt2)
Deprecated. Makes an alternator object that alternates between two values automatically.  | 
| Methods inherited from class java.lang.Object | 
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public VelocityFormatter(Context context)
context - A Context.| Method Detail | 
|---|
public String formatShortDate(Date date)
DateFormat.SHORT style.
date - The date to format.
public String formatLongDate(Date date)
DateFormat.LONG style.
date - The date to format.
public String formatShortDateTime(Date date)
date - The date to format.
public String formatLongDateTime(Date date)
date - The date to format.
public String formatArray(Object array)
array - An Object.
public String formatArray(Object array,
                          String delim)
array - An Object.delim - A String.
public String formatArray(Object array,
                          String delim,
                          String finaldelim)
array - An Object.delim - A String.finaldelim - A String.
public String formatVector(List list)
list - The list of elements to format.
public String formatVector(List list,
                           String delim)
list - The list of elements to format.delim - A String.
public String formatVector(List list,
                           String delim,
                           String finaldelim)
list - The list of elements to format.delim - A String.finaldelim - A String.
public String limitLen(int maxlen,
                       String string)
maxlen - An int with the maximum length.string - A String.
public String limitLen(int maxlen,
                       String string,
                       String suffix)
maxlen - An int with the maximum length.string - A String.suffix - A String.
public String makeAlternator(String name,
                             String alt1,
                             String alt2)
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>
 
name - The name for the alternator int the context.alt1 - The first alternate.alt2 - The second alternate.
public String makeAlternator(String name,
                             String alt1,
                             String alt2,
                             String alt3)
name - alt1 - alt2 - alt3 - 
makeAlternator(String name, String alt1, String alt2)
public String makeAlternator(String name,
                             String alt1,
                             String alt2,
                             String alt3,
                             String alt4)
name - alt1 - alt2 - alt3 - alt4 - 
makeAlternator(String name, String alt1, String alt2)
public String makeAutoAlternator(String name,
                                 String alt1,
                                 String alt2)
name - alt1 - alt2 - 
makeAlternator(String name, String alt1, String alt2)
public Object isNull(Object o,
                     Object dflt)
o - dflt - 
  | 
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||