C# Class NVelocity.App.Tools.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) 

Show file Open project: nats/castle-1.0.3-mono Class Usage Examples

Public Methods

Method Description
FormatArray ( Object array ) : String

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

FormatArray ( Object array, String delim ) : String

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

FormatArray ( Object array, String delim, String finaldelim ) : String

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

FormatLongDate ( System.DateTime date ) : String

Formats a date in 'long' style.

FormatLongDateTime ( System.DateTime date ) : String

Formats a date/time in 'long' style.

FormatShortDate ( System.DateTime date ) : String

Formats a date in 'short' style.

FormatShortDateTime ( System.DateTime date ) : String

Formats a date/time in 'short' style.

FormatVector ( IList list ) : String

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

FormatVector ( IList list, String delim ) : String

Formats a list into the form "A<delim>B<delim>C".

FormatVector ( IList list, String delim, String finaldelim ) : String

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

IsNull ( Object o, Object dflt ) : Object

Returns a default value if the object passed is null.

LimitLen ( int maxlen, String value ) : String

Limits 'string' to 'maxlen' characters. If the string gets curtailed, "..." is appended to it.

LimitLen ( int maxlen, String value, String suffix ) : String

Limits 'string' to 'maxlen' character. If the string gets curtailed, 'suffix' is appended to it.

MakeAlternator ( String name, String alt1, String alt2 ) : String

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 <tr><td bgcolor="$rowcolor">$item.Name</td></tr> $rowcolor.alternate() #end </table>

MakeAlternator ( String name, String alt1, String alt2, String alt3 ) : String

Makes an alternator object that alternates between three values.

MakeAlternator ( String name, String alt1, String alt2, String alt3, String alt4 ) : String

Makes an alternator object that alternates between four values.

MakeAutoAlternator ( String name, String alt1, String alt2 ) : String

Makes an alternator object that alternates between two values automatically.

VelocityFormatter ( IContext context ) : System

Constructor needs a backpointer to the context.

Method Details

FormatArray() public method

Formats an array into the form "A, B and C".
public FormatArray ( Object array ) : String
array Object An Object.
return String

FormatArray() public method

Formats an array into the form "A<delim>B<delim>C".
public FormatArray ( Object array, String delim ) : String
array Object An Object.
delim String A String.
return String

FormatArray() public method

Formats an array into the form "A<delim>B<finaldelim>C".
public FormatArray ( Object array, String delim, String finaldelim ) : String
array Object An Object.
delim String A String.
finaldelim String A String.
return String

FormatLongDate() public method

Formats a date in 'long' style.
public FormatLongDate ( System.DateTime date ) : String
date System.DateTime A Date.
return String

FormatLongDateTime() public method

Formats a date/time in 'long' style.
public FormatLongDateTime ( System.DateTime date ) : String
date System.DateTime A Date.
return String

FormatShortDate() public method

Formats a date in 'short' style.
public FormatShortDate ( System.DateTime date ) : String
date System.DateTime A Date.
return String

FormatShortDateTime() public method

Formats a date/time in 'short' style.
public FormatShortDateTime ( System.DateTime date ) : String
date System.DateTime A Date.
return String

FormatVector() public method

Formats a list into the form "A, B and C".
public FormatVector ( IList list ) : String
list IList A list.
return String

FormatVector() public method

Formats a list into the form "A<delim>B<delim>C".
public FormatVector ( IList list, String delim ) : String
list IList A list.
delim String A String.
return String

FormatVector() public method

Formats a list into the form "Adelim>B<finaldelim>C".
public FormatVector ( IList list, String delim, String finaldelim ) : String
list IList A list.
delim String A String.
finaldelim String A String.
return String

IsNull() public method

Returns a default value if the object passed is null.
public IsNull ( Object o, Object dflt ) : Object
o Object
dflt Object
return Object

LimitLen() public method

Limits 'string' to 'maxlen' characters. If the string gets curtailed, "..." is appended to it.
public LimitLen ( int maxlen, String value ) : String
maxlen int An int with the maximum length.
value String A String.
return String

LimitLen() public method

Limits 'string' to 'maxlen' character. If the string gets curtailed, 'suffix' is appended to it.
public LimitLen ( int maxlen, String value, String suffix ) : String
maxlen int An int with the maximum length.
value String A String.
suffix String A String.
return String

MakeAlternator() public method

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 <tr><td bgcolor="$rowcolor">$item.Name</td></tr> $rowcolor.alternate() #end </table>

public MakeAlternator ( String name, String alt1, String alt2 ) : String
name String The name for the alternator int the context.
alt1 String The first alternate.
alt2 String The second alternate.
return String

MakeAlternator() public method

Makes an alternator object that alternates between three values.
public MakeAlternator ( String name, String alt1, String alt2, String alt3 ) : String
name String
alt1 String
alt2 String
alt3 String
return String

MakeAlternator() public method

Makes an alternator object that alternates between four values.
public MakeAlternator ( String name, String alt1, String alt2, String alt3, String alt4 ) : String
name String
alt1 String
alt2 String
alt3 String
alt4 String
return String

MakeAutoAlternator() public method

Makes an alternator object that alternates between two values automatically.
public MakeAutoAlternator ( String name, String alt1, String alt2 ) : String
name String
alt1 String
alt2 String
return String

VelocityFormatter() public method

Constructor needs a backpointer to the context.
public VelocityFormatter ( IContext context ) : System
context IContext A Context.
return System