Class VelocityFormatter

java.lang.Object
org.apache.velocity.app.tools.VelocityFormatter

public class VelocityFormatter extends Object
Deprecated.
This class has been replaced by NumberTool, DateTool, DisplayTool, and AlternatorTool available from the Velocity-Tools sub-project. VelocityFormatter will be removed in a future version of Velocity.
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)
 
Version:
$Id: VelocityFormatter.java 544641 2007-06-05 21:30:22Z nbubna $
  • Field Details

    • context

      Context context
      Deprecated.
  • Constructor Details

    • VelocityFormatter

      public VelocityFormatter(Context context)
      Deprecated.
      Constructor needs a backpointer to the context.
      Parameters:
      context - A Context.
  • Method Details

    • formatShortDate

      public String formatShortDate(Date date)
      Deprecated.
      Formats a date in DateFormat.SHORT style.
      Parameters:
      date - The date to format.
      Returns:
      The formatted date as text.
    • formatLongDate

      public String formatLongDate(Date date)
      Deprecated.
      Formats a date in DateFormat.LONG style.
      Parameters:
      date - The date to format.
      Returns:
      The formatted date as text.
    • formatShortDateTime

      public String formatShortDateTime(Date date)
      Deprecated.
      Formats a date/time in 'short' style.
      Parameters:
      date - The date to format.
      Returns:
      The formatted date as text.
    • formatLongDateTime

      public String formatLongDateTime(Date date)
      Deprecated.
      Formats a date/time in 'long' style.
      Parameters:
      date - The date to format.
      Returns:
      The formatted date as text.
    • formatArray

      public String formatArray(Object array)
      Deprecated.
      Formats an array into the form "A, B and C".
      Parameters:
      array - An Object.
      Returns:
      A String.
    • formatArray

      public String formatArray(Object array, String delim)
      Deprecated.
      Formats an array into the form "A<delim>B<delim>C".
      Parameters:
      array - An Object.
      delim - A String.
      Returns:
      A String.
    • formatArray

      public String formatArray(Object array, String delim, String finaldelim)
      Deprecated.
      Formats an array into the form "A<delim>B<finaldelim>C".
      Parameters:
      array - An Object.
      delim - A String.
      finaldelim - A String.
      Returns:
      A String.
    • formatVector

      public String formatVector(List list)
      Deprecated.
      Formats a vector into the form "A, B and C".
      Parameters:
      list - The list of elements to format.
      Returns:
      A String.
    • formatVector

      public String formatVector(List list, String delim)
      Deprecated.
      Formats a vector into the form "A<delim>B<delim>C".
      Parameters:
      list - The list of elements to format.
      delim - A String.
      Returns:
      A String.
    • formatVector

      public String formatVector(List list, String delim, String finaldelim)
      Deprecated.
      Formats a list into the form "Adelim>B<finaldelim>C".
      Parameters:
      list - The list of elements to format.
      delim - A String.
      finaldelim - A String.
      Returns:
      A String.
    • limitLen

      public String limitLen(int maxlen, String string)
      Deprecated.
      Limits 'string' to 'maxlen' characters. If the string gets curtailed, "..." is appended to it.
      Parameters:
      maxlen - An int with the maximum length.
      string - A String.
      Returns:
      A String.
    • limitLen

      public String limitLen(int maxlen, String string, String suffix)
      Deprecated.
      Limits 'string' to 'maxlen' character. If the string gets curtailed, 'suffix' is appended to it.
      Parameters:
      maxlen - An int with the maximum length.
      string - A String.
      suffix - A String.
      Returns:
      A String.
    • makeAlternator

      public String makeAlternator(String name, String alt1, String alt2)
      Deprecated.
      Makes an alternator object that alternates between two values.

      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.
    • makeAlternator

      public String makeAlternator(String name, String alt1, String alt2, String alt3)
      Deprecated.
      Makes an alternator object that alternates between three values.
      Parameters:
      name -
      alt1 -
      alt2 -
      alt3 -
      Returns:
      alternated object.
      See Also:
    • makeAlternator

      public String makeAlternator(String name, String alt1, String alt2, String alt3, String alt4)
      Deprecated.
      Makes an alternator object that alternates between four values.
      Parameters:
      name -
      alt1 -
      alt2 -
      alt3 -
      alt4 -
      Returns:
      Alternated object.
      See Also:
    • makeAutoAlternator

      public String makeAutoAlternator(String name, String alt1, String alt2)
      Deprecated.
      Makes an alternator object that alternates between two values automatically.
      Parameters:
      name -
      alt1 -
      alt2 -
      Returns:
      Alternated object.
      See Also:
    • isNull

      public Object isNull(Object o, Object dflt)
      Deprecated.
      Returns a default value if the object passed is null.
      Parameters:
      o -
      dflt -
      Returns:
      Object or default value when object is null.