类 ConversionTool
java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.ConversionTool
- 直接已知子类:
ValueParser
Utility class for easy conversion of String values to richer types.
Template example(s): $convert.toNumber('12.6') -> 12.6 $convert.toInt('12.6') -> 12 $convert.toNumbers('12.6,42') -> [12.6, 42] Toolbox configuration: <tools> <toolbox scope="application"> <tool class="org.apache.velocity.tools.generic.ConversionTool" dateFormat="yyyy-MM-dd"/> </toolbox> </tools>
This comes in very handy when parsing anything.
- 从以下版本开始:
- VelocityTools 2.0
- 版本:
- $Revision: 932578 $ $Date: 2007-02-26 11:24:39 -0800 (Mon, 26 Feb 2007) $
- 作者:
- Nathan Bubna
-
字段概要
字段修饰符和类型字段说明static final String
private String
static final String
static final String
static final String
static final boolean
static final String
private String
static final String
static final String
private String
private boolean
从类继承的字段 org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALE
从类继承的字段 org.apache.velocity.tools.generic.SafeConfig
LOCK_CONFIG_KEY, OLD_LOCK_CONFIG_KEY, SAFE_MODE_KEY
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected void
configure
(ValueParser values) Does the actual configuration.final String
final String
final String
final boolean
protected Boolean
parseBoolean
(String value) Converts a parameter value into aBoolean
Sub-classes can override to allow for customized boolean parsing.protected Locale
parseLocale
(String value) Converts a String value into a Locale.parseNumber
(String value) Converts an object to an instance ofNumber
using the format returned bygetNumberFormat()
and the defaultLocale
if the object is not already an instance of Number.parseNumber
(String value, Object locale) parseNumber
(String value, String format) Converts an object to an instance ofNumber
using the specified format and theLocale
returned byLocaleConfig.getLocale()
.parseNumber
(String value, String format, Object locale) protected String[]
parseStringList
(String value) Converts a single String value into an array of Strings by splitting it on the tool's set stringsDelimiter.protected final void
setDateFormat
(String format) protected final void
setNumberFormat
(String format) protected final void
setStringsDelimiter
(String stringsDelimiter) Sets the delimiter used for separating values in a single String value.protected final void
setStringsTrim
(boolean stringsTrim) Sets whether strings should be trimmed when separated from a delimited string value.Boolean[]
toBooleans
(Object value) Boolean[]
toBooleans
(Collection values) toCalendar
(Object value) Calendar[]
toCalendars
(Object value) Calendar[]
toCalendars
(Collection values) Date[]
Date[]
toDates
(Collection values) double[]
int[]
toIntegers
(Object value) int[]
Locale[]
Locale[]
toLocales
(Collection values) Number[]
Number[]
toNumbers
(Collection values) Converts objects to String in a more Tools-ish way than String.valueOf(Object), especially with nulls, Arrays and Collections.String[]
从类继承的方法 org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale
从类继承的方法 org.apache.velocity.tools.generic.SafeConfig
configure, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
字段详细资料
-
STRINGS_DELIMITER_FORMAT_KEY
- 另请参阅:
-
STRINGS_TRIM_KEY
- 另请参阅:
-
DATE_FORMAT_KEY
- 另请参阅:
-
NUMBER_FORMAT_KEY
- 另请参阅:
-
DEFAULT_STRINGS_DELIMITER
- 另请参阅:
-
DEFAULT_STRINGS_TRIM
public static final boolean DEFAULT_STRINGS_TRIM- 另请参阅:
-
DEFAULT_NUMBER_FORMAT
- 另请参阅:
-
DEFAULT_DATE_FORMAT
- 另请参阅:
-
stringsDelimiter
-
stringsTrim
private boolean stringsTrim -
numberFormat
-
dateFormat
-
-
构造器详细资料
-
ConversionTool
public ConversionTool()
-
-
方法详细资料
-
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
-
setStringsDelimiter
Sets the delimiter used for separating values in a single String value. The default string delimiter is a comma. -
getStringsDelimiter
-
setStringsTrim
protected final void setStringsTrim(boolean stringsTrim) Sets whether strings should be trimmed when separated from a delimited string value. The default is true. -
getStringsTrim
public final boolean getStringsTrim() -
setNumberFormat
-
getNumberFormat
-
setDateFormat
-
getDateFormat
-
toString
Converts objects to String in a more Tools-ish way than String.valueOf(Object), especially with nulls, Arrays and Collections. Null returns null, Arrays and Collections return the toString(Object) of their first value, or null if they have no values.- 参数:
value
- the object to be turned into a String- 返回:
- the string value of the object or null if the value is null or it is an array or collection whose first value is null
-
toBoolean
- 参数:
value
- the object to be converted- 返回:
- a
Boolean
object for the specified value ornull
if the value is null or the conversion failed
-
toInteger
- 参数:
value
- the object to be converted- 返回:
- a
Integer
for the specified value ornull
if the value is null or the conversion failed
-
toDouble
- 参数:
value
- the object to be converted- 返回:
- a
Double
for the specified value ornull
if the value is null or the conversion failed
-
toNumber
- 参数:
value
- the object to be converted- 返回:
- a
Number
for the specified value ornull
if the value is null or the conversion failed
-
toLocale
- 参数:
value
- the object to be converted- 返回:
- a
Locale
for the specified value ornull
if the value is null or the conversion failed
-
toDate
Converts an object to an instance ofDate
, when necessary using the configured date parsing format, the configured defaultLocale
, and the system's defaultTimeZone
to parse the string value of the specified object.- 参数:
value
- the date to convert- 返回:
- the object as a
Date
ornull
if no conversion is possible
-
toCalendar
-
toStrings
- 参数:
value
- the value to be converted- 返回:
- an array of String objects containing all of the values derived from the specified array, Collection, or delimited String
-
toBooleans
- 参数:
value
- the value to be converted- 返回:
- an array of Boolean objects derived from the specified value,
or
null
.
-
toBooleans
- 参数:
values
- the collection of values to be converted- 返回:
- an array of Boolean objects derived from the specified values,
or
null
.
-
toNumbers
- 参数:
value
- the value to be converted- 返回:
- an array of Number objects derived from the specified value,
or
null
.
-
toNumbers
- 参数:
values
- the collection of values to be converted- 返回:
- an array of Number objects derived from the specified values,
or
null
.
-
toInts
- 参数:
value
- the value to be converted- 返回:
- an array of int values derived from the specified value,
or
null
.
-
toIntegers
- 参数:
value
- the value to be converted- 返回:
- an array of int values derived from the specified value,
or
null
.
-
toDoubles
- 参数:
value
- the value to be converted- 返回:
- an array of double values derived from the specified value,
or
null
.
-
toLocales
- 参数:
value
- the value to be converted- 返回:
- an array of Locale objects derived from the specified value,
or
null
.
-
toLocales
- 参数:
values
- the collection of values to be converted- 返回:
- an array of Locale objects derived from the specified values,
or
null
.
-
toDates
- 参数:
value
- the value to be converted- 返回:
- an array of Date objects derived from the specified value,
or
null
.
-
toDates
- 参数:
values
- the collection of values to be converted- 返回:
- an array of Date objects derived from the specified values,
or
null
.
-
toCalendars
- 参数:
value
- the value to be converted- 返回:
- an array of Calendar objects derived from the specified value,
or
null
.
-
toCalendars
- 参数:
values
- the collection of values to be converted- 返回:
- an array of Calendar objects derived from the specified values,
or
null
.
-
parseBoolean
Converts a parameter value into aBoolean
Sub-classes can override to allow for customized boolean parsing. (e.g. to handle "Yes/No" or "T/F")- 参数:
value
- the string to be parsed- 返回:
- the value as a
Boolean
-
parseStringList
Converts a single String value into an array of Strings by splitting it on the tool's set stringsDelimiter. The default stringsDelimiter is a comma, and by default, all strings parsed out are trimmed before returning. -
parseLocale
Converts a String value into a Locale. -
parseNumber
Converts an object to an instance ofNumber
using the format returned bygetNumberFormat()
and the defaultLocale
if the object is not already an instance of Number.- 参数:
value
- the string to parse- 返回:
- the string as a
Number
ornull
if no conversion is possible
-
parseNumber
Converts an object to an instance ofNumber
using the specified format and theLocale
returned byLocaleConfig.getLocale()
.- 参数:
value
- - the string to parseformat
- - the format the number is in- 返回:
- the string as a
Number
ornull
if no conversion is possible - 另请参阅:
-
parseNumber
Converts an object to an instance ofNumber
using the configured number format and the specifiedLocale
.- 参数:
value
- - the string to parselocale
- - the Locale to use- 返回:
- the string as a
Number
ornull
if no conversion is possible - 另请参阅:
-
parseNumber
- 参数:
value
- - the string to parseformat
- - the format the number is inlocale
- - the Locale to use- 返回:
- the string as a
Number
ornull
if no conversion is possible - 另请参阅:
-
parseDate
Converts a string to an instance ofDate
, using the configured date parsing format, the configured defaultLocale
, and the system's defaultTimeZone
to parse it.- 参数:
value
- the date to convert- 返回:
- the object as a
Date
ornull
if no conversion is possible
-
parseDate
Converts a string to an instance ofDate
using the specified format,the configured defaultLocale
, and the system's defaultTimeZone
to parse it.- 参数:
value
- - the date to convertformat
- - the format the date is in- 返回:
- the string as a
Date
ornull
if no conversion is possible - 另请参阅:
-
parseDate
Converts a string to an instance ofDate
using the configured date format and specifiedLocale
to parse it.- 参数:
value
- - the date to convertlocale
- - the Locale to use- 返回:
- the string as a
Date
ornull
if no conversion is possible - 另请参阅:
-
parseDate
- 参数:
value
- - the date to convertformat
- - the format the date is inlocale
- - the Locale to use- 返回:
- the string as a
Date
ornull
if no conversion is possible - 另请参阅:
-
parseDate
-