VelocityFormatter (Velocity 1.4 API)
Keywords: org.apache.velocity.app.tools.VelocityFormatter class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.velocity.app.tools
Class VelocityFormatter

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

public class VelocityFormatter
extends java.lang.Object

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,v 1.9 2003/05/04 17:06:11 geirm Exp $
Author:
  Sean Legassick, Daniel Rall

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
`(package private) Context` | `context`
`(package private) java.text.NumberFormat` | `nf`

Constructor Summary
`VelocityFormatter(Context context)` Constructor needs a backpointer to the context.

Method Summary
`java.lang.String` | `formatArray(java.lang.Object array)` Formats an array into the form "A, B and C".
`java.lang.String` | `formatArray(java.lang.Object array, java.lang.String delim)` Formats an array into the form "A<delim>B<delim>C".
`java.lang.String` | `formatArray(java.lang.Object array, java.lang.String delim, java.lang.String finaldelim)` Formats an array into the form "A<delim>B<finaldelim>C".
`java.lang.String` | `formatLongDate(java.util.Date date)` Formats a date in `DateFormat.LONG` style.
`java.lang.String` | `formatLongDateTime(java.util.Date date)` Formats a date/time in 'long' style.
`java.lang.String` | `formatShortDate(java.util.Date date)` Formats a date in `DateFormat.SHORT` style.
`java.lang.String` | `formatShortDateTime(java.util.Date date)` Formats a date/time in 'short' style.
`java.lang.String` | `formatVector(java.util.List list)` Formats a vector into the form "A, B and C".
`java.lang.String` | `formatVector(java.util.List list, java.lang.String delim)` Formats a vector into the form "A<delim>B<delim>C".
`java.lang.String` | `formatVector(java.util.List list, java.lang.String delim, java.lang.String finaldelim)` Formats a list into the form "Adelim>B<finaldelim>C".
`java.lang.Object` | `isNull(java.lang.Object o, java.lang.Object dflt)` Returns a default value if the object passed is null.
`java.lang.String` | `limitLen(int maxlen, java.lang.String string)` Limits 'string' to 'maxlen' characters.
`java.lang.String` | `limitLen(int maxlen, java.lang.String string, java.lang.String suffix)` Limits 'string' to 'maxlen' character.
`java.lang.String` | `makeAlternator(java.lang.String name, java.lang.String alt1, java.lang.String alt2)` Makes an alternator object that alternates between two values.
`java.lang.String` | `makeAlternator(java.lang.String name, java.lang.String alt1, java.lang.String alt2, java.lang.String alt3)` Makes an alternator object that alternates between three values.
`java.lang.String` | `makeAlternator(java.lang.String name, java.lang.String alt1, java.lang.String alt2, java.lang.String alt3, java.lang.String alt4)` Makes an alternator object that alternates between four values.
`java.lang.String` | `makeAutoAlternator(java.lang.String name, java.lang.String alt1, java.lang.String alt2)` 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`

Field Detail

### context

    Context context

### nf

    java.text.NumberFormat nf

Constructor Detail

### VelocityFormatter

    public VelocityFormatter(Context context)

  Constructor needs a backpointer to the context.

Parameters:
  `context` - A Context.

Method Detail

### formatShortDate

    public java.lang.String formatShortDate(java.util.Date date)

  Formats a date in `DateFormat.SHORT` style.

  Parameters:
    `date` - The date to format.
  Returns:
    The formatted date as text.

### formatLongDate

    public java.lang.String formatLongDate(java.util.Date date)

  Formats a date in `DateFormat.LONG` style.

  Parameters:
    `date` - The date to format.
  Returns:
    The formatted date as text.

### formatShortDateTime

    public java.lang.String formatShortDateTime(java.util.Date date)

  Formats a date/time in 'short' style.

  Parameters:
    `date` - The date to format.
  Returns:
    The formatted date as text.

### formatLongDateTime

    public java.lang.String formatLongDateTime(java.util.Date date)

  Formats a date/time in 'long' style.

  Parameters:
    `date` - The date to format.
  Returns:
    The formatted date as text.

### formatArray

    public java.lang.String formatArray(java.lang.Object array)

  Formats an array into the form "A, B and C".

  Parameters:
    `array` - An Object.
  Returns:
    A String.

### formatArray

    public java.lang.String formatArray(java.lang.Object array,
                                        java.lang.String delim)

  Formats an array into the form "A<delim>B<delim>C".

  Parameters:
    `array` - An Object.
    `delim` - A String.
  Returns:
    A String.

### formatArray

    public java.lang.String formatArray(java.lang.Object array,
                                        java.lang.String delim,
                                        java.lang.String finaldelim)

  Formats an array into the form "A<delim>B<finaldelim>C".

  Parameters:
    `array` - An Object.
    `delim` - A String.
  Returns:
    A String.

### formatVector

    public java.lang.String formatVector(java.util.List list)

  Formats a vector into the form "A, B and C".

  Parameters:
    `list` - The list of elements to format.
  Returns:
    A String.

### formatVector

    public java.lang.String formatVector(java.util.List list,
                                         java.lang.String delim)

  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 java.lang.String formatVector(java.util.List list,
                                         java.lang.String delim,
                                         java.lang.String finaldelim)

  Formats a list into the form "Adelim>B<finaldelim>C".

  Parameters:
    `list` - The list of elements to format.
    `delim` - A String.
  Returns:
    A String.

### limitLen

    public java.lang.String limitLen(int maxlen,
                                     java.lang.String string)

  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 java.lang.String limitLen(int maxlen,
                                     java.lang.String string,
                                     java.lang.String suffix)

  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 java.lang.String makeAlternator(java.lang.String name,
                                           java.lang.String alt1,
                                           java.lang.String alt2)

  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 java.lang.String makeAlternator(java.lang.String name,
                                           java.lang.String alt1,
                                           java.lang.String alt2,
                                           java.lang.String alt3)

  Makes an alternator object that alternates between three values.

  See Also:
    `makeAlternator(String name, String alt1, String alt2)`

### makeAlternator

    public java.lang.String makeAlternator(java.lang.String name,
                                           java.lang.String alt1,
                                           java.lang.String alt2,
                                           java.lang.String alt3,
                                           java.lang.String alt4)

  Makes an alternator object that alternates between four values.

  See Also:
    `makeAlternator(String name, String alt1, String alt2)`

### makeAutoAlternator

    public java.lang.String makeAutoAlternator(java.lang.String name,
                                               java.lang.String alt1,
                                               java.lang.String alt2)

  Makes an alternator object that alternates between two values automatically.

  See Also:
    `makeAlternator(String name, String alt1, String alt2)`

### isNull

    public java.lang.Object isNull(java.lang.Object o,
                                   java.lang.Object dflt)

  Returns a default value if the object passed is null.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002 Apache Software Foundation. All Rights Reserved.