|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.DisplayTool
@DefaultKey(value="display") public class DisplayTool
Provides general utility methods for controlling the display of references.
Currently, this class contains methods for "pretty printing" an array or
Collection
, methods for truncating the string value of a reference
at a configured or specified length, methods for displaying an alternate
value when a specified value is null, a method for generating whitespace,
a "printf" type of method for formatting messages, and
methods for forcing values into "cells" of equal size (via truncation or
padding with whitespace).
Example Use:
tools.xml... <tools> <toolbox scope="application"> <tool class="org.apache.velocity.tools.generic.DisplayTool"/> </toolbox> </tools> template... #set( $list = [1..5] ) $display.list($list) $display.truncate(10, "This is a long string.") Not Null: $display.alt("not null", "--") Null: $display.alt($null, "--") output... 1, 2, 3, 4 and 5 This is... Not Null: not null Null: --
Nested Class Summary | |
---|---|
static class |
DisplayTool.Measurements
Measures the dimensions of the string given to its constructor. |
Field Summary | |
---|---|
static java.lang.String |
CELL_LENGTH_KEY
|
static java.lang.String |
CELL_SUFFIX_KEY
|
static java.lang.String |
DEFAULT_ALTERNATE_KEY
|
private java.lang.String |
defaultAlternate
|
private int |
defaultCellLength
|
private java.lang.String |
defaultCellSuffix
|
private java.lang.String |
defaultDelim
|
private java.lang.String |
defaultFinalDelim
|
private int |
defaultTruncateLength
|
private java.lang.String |
defaultTruncateSuffix
|
static java.lang.String |
LIST_DELIM_KEY
|
static java.lang.String |
LIST_FINAL_DELIM_KEY
|
static java.lang.String |
TRUNCATE_LENGTH_KEY
|
static java.lang.String |
TRUNCATE_SUFFIX_KEY
|
Fields inherited from class org.apache.velocity.tools.generic.LocaleConfig |
---|
DEFAULT_LOCALE |
Fields inherited from class org.apache.velocity.tools.generic.SafeConfig |
---|
LOCK_CONFIG_KEY, OLD_LOCK_CONFIG_KEY, SAFE_MODE_KEY |
Constructor Summary | |
---|---|
DisplayTool()
|
Method Summary | |
---|---|
java.lang.Object |
alt(java.lang.Object checkMe)
Returns a configured default value if specified value is null. |
java.lang.Object |
alt(java.lang.Object checkMe,
java.lang.Object alternate)
Returns the second argument if first argument specified is null. |
java.lang.String |
capitalize(java.lang.Object capitalizeMe)
Changes the first character of the string value of the specified object to upper case and returns the resulting string. |
java.lang.String |
cell(java.lang.Object obj)
Truncates or pads the string value of the specified object as necessary to ensure that the returned string's length equals the default cell size. |
java.lang.String |
cell(java.lang.Object obj,
int cellsize)
Truncates or pads the string value of the specified object as necessary to ensure that the returned string's length equals the specified cell size. |
java.lang.String |
cell(java.lang.Object obj,
int cellsize,
java.lang.String suffix)
Truncates or pads the string value of the specified object as necessary to ensure that the returned string's length equals the specified cell size. |
java.lang.String |
cell(java.lang.Object obj,
java.lang.String suffix)
Truncates or pads the string value of the specified object as necessary to ensure that the returned string's length equals the default cell size. |
protected void |
configure(ValueParser values)
Does the actual configuration. |
protected java.lang.String |
format(java.util.Collection list,
java.lang.String delim,
java.lang.String finaldelim)
Does the actual formatting of the collection. |
int |
getCellLength()
|
java.lang.String |
getCellSuffix()
|
java.lang.String |
getDefaultAlternate()
|
java.lang.String |
getListDelimiter()
|
java.lang.String |
getListFinalDelimiter()
|
int |
getTruncateLength()
|
java.lang.String |
getTruncateSuffix()
|
java.lang.String |
list(java.lang.Object list)
Formats a collection or array into the form "A, B and C". |
java.lang.String |
list(java.lang.Object list,
java.lang.String delim)
Formats a collection or array into the form "A<delim>B<delim>C". |
java.lang.String |
list(java.lang.Object list,
java.lang.String delim,
java.lang.String finaldelim)
Formats a collection or array into the form "A<delim>B<finaldelim>C". |
DisplayTool.Measurements |
measure(java.lang.Object measureMe)
Returns the DisplayTool.Measurements of the string value of the specified object. |
java.lang.String |
message(java.lang.String format,
java.util.Collection args)
Deprecated. Will be unnecessary with Velocity 1.6 |
java.lang.String |
message(java.lang.String format,
java.lang.Object... args)
Uses MessageFormat to format the specified String with
the specified arguments. |
java.lang.String |
message(java.lang.String format,
java.lang.Object arg)
Deprecated. Will be unnecessary with Velocity 1.6 |
java.lang.String |
message(java.lang.String format,
java.lang.Object arg1,
java.lang.Object arg2)
Deprecated. Will be unnecessary with Velocity 1.6 |
java.lang.String |
printf(java.lang.String format,
java.lang.Object... args)
Uses String#format(Locale,String,Object... to format the specified String
with the specified arguments. |
protected void |
setCellLength(int maxlen)
|
protected void |
setCellSuffix(java.lang.String suffix)
|
protected void |
setDefaultAlternate(java.lang.String dflt)
|
protected void |
setListDelimiter(java.lang.String delim)
|
protected void |
setListFinalDelimiter(java.lang.String finalDelim)
|
protected void |
setTruncateLength(int maxlen)
|
protected void |
setTruncateSuffix(java.lang.String suffix)
|
java.lang.String |
space(int length)
Returns a string of spaces of the specified length. |
java.lang.String |
truncate(java.lang.Object truncateMe)
Limits the string value of 'truncateMe' to the configured max length in characters (default is 30 characters). |
java.lang.String |
truncate(java.lang.Object truncateMe,
int maxLength)
Limits the string value of 'truncateMe' to 'maxLength' characters. |
java.lang.String |
truncate(java.lang.Object truncateMe,
int maxLength,
java.lang.String suffix)
Limits the string value of 'truncateMe' to the specified max length in characters. |
java.lang.String |
truncate(java.lang.Object truncateMe,
java.lang.String suffix)
Limits the string value of 'truncateMe' to the configured max length in characters (default is 30 characters). |
java.lang.String |
uncapitalize(java.lang.Object uncapitalizeMe)
Changes the first character of the string value of the specified object to lower case and returns the resulting string. |
Methods inherited from class org.apache.velocity.tools.generic.LocaleConfig |
---|
getLocale, setLocale |
Methods inherited from class org.apache.velocity.tools.generic.SafeConfig |
---|
configure, isConfigLocked, isSafeMode, setLockConfig, setSafeMode |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String LIST_DELIM_KEY
public static final java.lang.String LIST_FINAL_DELIM_KEY
public static final java.lang.String TRUNCATE_LENGTH_KEY
public static final java.lang.String TRUNCATE_SUFFIX_KEY
public static final java.lang.String CELL_LENGTH_KEY
public static final java.lang.String CELL_SUFFIX_KEY
public static final java.lang.String DEFAULT_ALTERNATE_KEY
private java.lang.String defaultDelim
private java.lang.String defaultFinalDelim
private int defaultTruncateLength
private java.lang.String defaultTruncateSuffix
private int defaultCellLength
private java.lang.String defaultCellSuffix
private java.lang.String defaultAlternate
Constructor Detail |
---|
public DisplayTool()
Method Detail |
---|
protected void configure(ValueParser values)
configure
in class LocaleConfig
public java.lang.String getListDelimiter()
protected void setListDelimiter(java.lang.String delim)
public java.lang.String getListFinalDelimiter()
protected void setListFinalDelimiter(java.lang.String finalDelim)
public int getTruncateLength()
protected void setTruncateLength(int maxlen)
public java.lang.String getTruncateSuffix()
protected void setTruncateSuffix(java.lang.String suffix)
public java.lang.String getCellSuffix()
protected void setCellSuffix(java.lang.String suffix)
public int getCellLength()
protected void setCellLength(int maxlen)
public java.lang.String getDefaultAlternate()
protected void setDefaultAlternate(java.lang.String dflt)
public java.lang.String list(java.lang.Object list)
list
- A collection or array.
public java.lang.String list(java.lang.Object list, java.lang.String delim)
list
- A collection or array.delim
- A String.
public java.lang.String list(java.lang.Object list, java.lang.String delim, java.lang.String finaldelim)
list
- A collection or array.delim
- A String.finaldelim
- A String.
protected java.lang.String format(java.util.Collection list, java.lang.String delim, java.lang.String finaldelim)
@Deprecated public java.lang.String message(java.lang.String format, java.util.Collection args)
@Deprecated public java.lang.String message(java.lang.String format, java.lang.Object arg)
@Deprecated public java.lang.String message(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)
public java.lang.String message(java.lang.String format, java.lang.Object... args)
MessageFormat
to format the specified String with
the specified arguments. If there are no arguments, then the String
is returned directly. Please note that the format
required here is quite different from that of
printf(String,Object...)
.
public java.lang.String printf(java.lang.String format, java.lang.Object... args)
String#format(Locale,String,Object...
to format the specified String
with the specified arguments. Please note that the format
required here is quite different from that of
message(String,Object...)
.
Formatter
public java.lang.String truncate(java.lang.Object truncateMe)
truncateMe
- The value to be truncated.
public java.lang.String truncate(java.lang.Object truncateMe, int maxLength)
maxLength
- An int with the maximum length.truncateMe
- The value to be truncated.
public java.lang.String truncate(java.lang.Object truncateMe, java.lang.String suffix)
truncateMe
- The value to be truncated.suffix
- A String.
public java.lang.String truncate(java.lang.Object truncateMe, int maxLength, java.lang.String suffix)
truncateMe
- The value to be truncated.maxLength
- An int with the maximum length.suffix
- A String.
public java.lang.String space(int length)
length
- the number of spaces to returnpublic java.lang.String cell(java.lang.Object obj)
obj
- the value to be put in the 'cell'public java.lang.String cell(java.lang.Object obj, int cellsize)
obj
- the value to be put in the 'cell'cellsize
- the size of the cell into which the object must be placedpublic java.lang.String cell(java.lang.Object obj, java.lang.String suffix)
obj
- the value to be put in the 'cell'suffix
- the suffix to put at the end of any values that need truncating
to indicate that they've been truncatedpublic java.lang.String cell(java.lang.Object obj, int cellsize, java.lang.String suffix)
obj
- the value to be put in the 'cell'cellsize
- the size of the cell into which the object must be placedsuffix
- the suffix to put at the end of any values that need truncating
to indicate that they've been truncatedpublic java.lang.String capitalize(java.lang.Object capitalizeMe)
capitalizeMe
- The value to be capitalized.public java.lang.String uncapitalize(java.lang.Object uncapitalizeMe)
uncapitalizeMe
- The value to be uncapitalized.public java.lang.Object alt(java.lang.Object checkMe)
checkMe
-
public java.lang.Object alt(java.lang.Object checkMe, java.lang.Object alternate)
checkMe
- alternate
-
public DisplayTool.Measurements measure(java.lang.Object measureMe)
DisplayTool.Measurements
of the string value of the specified object.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |