类 DisplayTool
java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.DisplayTool
- 所有已实现的接口:
Serializable
@DefaultKey("display")
@ValidScope("application")
public class DisplayTool
extends LocaleConfig
implements Serializable
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("This is a long string.", 10)
Not Null: $display.alt("not null", "--")
Null: $display.alt($null, "--")
output...
1, 2, 3, 4 and 5
This is...
Not Null: not null
Null: --
- 从以下版本开始:
- VelocityTools 2.0
- 版本:
- $Id: DisplayTool.java 463298 2006-10-12 16:10:32Z henning $
- 作者:
- Sean Legassick, Daniel Rall, Nathan Bubna
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明static classMeasures the dimensions of the string given to its constructor. -
字段概要
字段修饰符和类型字段说明static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String从类继承的字段 org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALE从类继承的字段 org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明Returns a configured default value if specified value is null.Returns the second argument if first argument specified is null.Inserts HTML line break tag (<br />) in front of all newline characters of the string value of the specified object and returns the resulting string.capitalize(Object capitalizeMe) Changes the first character of the string value of the specified object to upper case and returns the resulting string.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.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.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.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 voidconfigure(ValueParser values) Does the actual configuration.protected Stringformat(Collection list, String delim, String finaldelim, String property) Does the actual formatting of the collection.String[]intprotected ObjectgetProperty(Object object, String property) Safely retrieves the specified property from the specified object.booleanintFormats a collection or array into the form "A, B and C".Formats a collection or array into the form "A<delim>B<delim>C".Formats a collection or array into the form "A<delim>B<finaldelim>C".Formats a specified property of collection or array of objects into the form "A<delim>B<finaldelim>C".Returns theDisplayTool.Measurementsof the string value of the specified object.UsesMessageFormatto format the specified String with the specified arguments.Builds plural form of a passed word if 'value' is plural, otherwise returns 'singular'.Returns 'plural' parameter if passed 'value' is plural, otherwise 'singular' is returned.UsesString.format(Locale,String,Object...)to format the specified String with the specified arguments.protected voidsetAllowedTags(String[] tags) protected voidsetCellLength(int maxlen) protected voidsetCellSuffix(String suffix) protected voidsetDefaultAlternate(String dflt) protected voidsetListDelimiter(String delim) protected voidsetListFinalDelimiter(String finalDelim) protected voidsetTruncateAtWord(boolean atWord) protected voidsetTruncateLength(int maxlen) protected voidsetTruncateSuffix(String suffix) space(int length) Returns a string of spaces of the specified length.Removes HTML tags from the string value of the specified object and returns the resulting string.Removes all not allowed HTML tags from the string value of the specified object and returns the resulting string.Limits the string value of 'truncateMe' to the configured max length in characters (default is 30 characters).Limits the string value of 'truncateMe' to 'maxLength' characters.Limits the string value of 'truncateMe' to the specified max length in characters.Limits the string value of 'truncateMe' to the latest complete word within the specified maxLength.Limits the string value of 'truncateMe' to the configured max length in characters (default is 30 characters).uncapitalize(Object uncapitalizeMe) Changes the first character of the string value of the specified object to lower case and returns the resulting string.从类继承的方法 org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale, toLocale从类继承的方法 org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
字段详细资料
-
构造器详细资料
-
DisplayTool
public DisplayTool()
-
-
方法详细资料
-
configure
Does the actual configuration. This is protected, so subclasses may share the same ValueParser and call configure at any time, while preventing templates from doing so when configure(Map) is locked.- 覆盖:
configure在类中LocaleConfig- 参数:
values- configuration values
-
getListDelimiter
-
setListDelimiter
-
getListFinalDelimiter
-
setListFinalDelimiter
-
getTruncateLength
public int getTruncateLength() -
setTruncateLength
protected void setTruncateLength(int maxlen) -
getTruncateSuffix
-
setTruncateSuffix
-
getTruncateAtWord
public boolean getTruncateAtWord() -
setTruncateAtWord
protected void setTruncateAtWord(boolean atWord) -
getCellSuffix
-
setCellSuffix
-
getCellLength
public int getCellLength() -
setCellLength
protected void setCellLength(int maxlen) -
getDefaultAlternate
-
setDefaultAlternate
-
getAllowedTags
-
setAllowedTags
-
list
Formats a collection or array into the form "A, B and C".- 参数:
list- A collection or array.- 返回:
- A String.
-
list
Formats a collection or array into the form "A<delim>B<delim>C".- 参数:
list- A collection or array.delim- A String.- 返回:
- A String.
-
list
Formats a collection or array into the form "A<delim>B<finaldelim>C".- 参数:
list- A collection or array.delim- A String.finaldelim- A String.- 返回:
- A String.
-
list
Formats a specified property of collection or array of objects into the form "A<delim>B<finaldelim>C".- 参数:
list- A collection or array.delim- A String.finaldelim- A String.property- An object property to format.- 返回:
- A String.
-
format
Does the actual formatting of the collection.- 参数:
list- collection of objects to formatdelim- delimiterfinaldelim- final delimiterproperty- objects property to use- 返回:
- formatted string
-
message
UsesMessageFormatto 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 ofprintf(String,Object...).- 参数:
format- format stringargs- arguments- 返回:
- formatted message
- 从以下版本开始:
- VelocityTools 2.0
-
printf
UsesString.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 ofmessage(String,Object...).- 参数:
format- format stringargs- printf arguments- 返回:
- formatted string
- 从以下版本开始:
- VelocityTools 2.0
- 另请参阅:
-
truncate
Limits the string value of 'truncateMe' to the configured max length in characters (default is 30 characters). If the string gets curtailed, the configured suffix (default is "...") is used as the ending of the truncated string.- 参数:
truncateMe- The value to be truncated.- 返回:
- A String.
-
truncate
Limits the string value of 'truncateMe' to 'maxLength' characters. If the string gets curtailed, the configured suffix (default is "...") is used as the ending of the truncated string.- 参数:
maxLength- An int with the maximum length.truncateMe- The value to be truncated.- 返回:
- A String.
-
truncate
Limits the string value of 'truncateMe' to the configured max length in characters (default is 30 characters). If the string gets curtailed, the specified suffix is used as the ending of the truncated string.- 参数:
truncateMe- The value to be truncated.suffix- A String.- 返回:
- A String.
-
truncate
Limits the string value of 'truncateMe' to the specified max length in characters. If the string gets curtailed, the specified suffix is used as the ending of the truncated string.- 参数:
truncateMe- The value to be truncated.maxLength- An int with the maximum length.suffix- A String.- 返回:
- A String.
-
truncate
public String truncate(Object truncateMe, int maxLength, String suffix, boolean defaultTruncateAtWord) Limits the string value of 'truncateMe' to the latest complete word within the specified maxLength. If the string gets curtailed, the specified suffix is used as the ending of the truncated string.- 参数:
truncateMe- The value to be truncated.maxLength- An int with the maximum length.suffix- A String.defaultTruncateAtWord- Truncate at a word boundary if true.- 返回:
- A String.
-
space
Returns a string of spaces of the specified length.- 参数:
length- the number of spaces to return- 返回:
- string of spaces
-
cell
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.- 参数:
obj- the value to be put in the 'cell'- 返回:
- truncated/padded string
-
cell
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.- 参数:
obj- the value to be put in the 'cell'cellsize- the size of the cell into which the object must be placed- 返回:
- truncated/padded string
-
cell
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. If truncation is necessary, the specified suffix will replace the end of the string value to indicate that.- 参数:
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 truncated- 返回:
- truncated/padded string
-
cell
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.- 参数:
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 truncated- 返回:
- truncated/padded string
-
capitalize
Changes the first character of the string value of the specified object to upper case and returns the resulting string.- 参数:
capitalizeMe- The value to be capitalized.- 返回:
- capitalized string
-
uncapitalize
Changes the first character of the string value of the specified object to lower case and returns the resulting string.- 参数:
uncapitalizeMe- The value to be uncapitalized.- 返回:
- uncapitalized string
-
alt
Returns a configured default value if specified value is null.- 参数:
checkMe- object to check- 返回:
- a configured default value if the specified value is null.
-
alt
Returns the second argument if first argument specified is null.- 参数:
checkMe- object to checkalternate- alternate value- 返回:
- the second argument if the first is null.
-
br
Inserts HTML line break tag (<br />) in front of all newline characters of the string value of the specified object and returns the resulting string.- 参数:
obj- source object- 返回:
- string with added br tags
-
stripTags
Removes HTML tags from the string value of the specified object and returns the resulting string.- 参数:
obj- source object- 返回:
- text stripped from HTML tags
-
stripTags
Removes all not allowed HTML tags from the string value of the specified object and returns the resulting string.- 参数:
obj- source objectallowedTags- An array of allowed tag names (i.e. "h1","br","img")- 返回:
- text stripped from given HTML tags
-
plural
Builds plural form of a passed word if 'value' is plural, otherwise returns 'singular'. Plural form is built using some basic English language rules for nouns which does not guarantee correct syntax of a result in all cases.- 参数:
value- countsingular- Singular form of a word.- 返回:
- guessed plural
-
plural
Returns 'plural' parameter if passed 'value' is plural, otherwise 'singular' is returned.- 参数:
value- countsingular- Singular form of a word.plural- Plural form of a word.- 返回:
- guessed plural
-
getProperty
Safely retrieves the specified property from the specified object. Subclasses that wish to perform more advanced, efficient, or just different property retrieval methods should override this method to do so.- 参数:
object- target objectproperty- target property- 返回:
- property value
- 抛出:
IllegalArgumentException- if it wasn't possible to get the object's property value
-
measure
Returns theDisplayTool.Measurementsof the string value of the specified object.- 参数:
measureMe- object to measure- 返回:
DisplayTool.Measurementsobject
-