类 ConversionTool
java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.ConversionTool
- 所有已实现的接口:
Serializable
@DefaultKey("convert")
@SkipSetters
@Deprecated
public class ConversionTool
extends LocaleConfig
implements Serializable
已过时。
use NumberTool for numbers formatting/parsing, DateTool for date/time formatting/parsing,
or CollectionTool for toStrings().
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$ $Date: 2007-02-26 11:24:39 -0800 (Mon, 26 Feb 2007) $
- 作者:
- Nathan Bubna
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明static final String已过时。static final String已过时。static final String已过时。static final String已过时。static final boolean已过时。static final String已过时。static 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 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voidconfigure(ValueParser values) 已过时。Does the actual configuration.final String已过时。useDateToolgetDateFormat() methodsfinal String已过时。useNumberToolformatfinal String已过时。Gets the delimiter used for separating values in a single String value.final boolean已过时。protected BooleanparseBoolean(String value) 已过时。Converts a parameter value into aBooleanSub-classes can override to allow for customized boolean parsing.已过时。已过时。已过时。已过时。protected LocaleparseLocale(String value) 已过时。Converts a String value into a Locale.parseNumber(String value) 已过时。parseNumber(String value, Object locale) parseNumber(String value, String format) 已过时。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 voidsetDateFormat(String format) 已过时。useDateToolsetDateFormat() methodsprotected final voidsetNumberFormat(String format) 已过时。useNumberToolformatprotected final voidsetStringsDelimiter(String stringsDelimiter) protected final voidsetStringsTrim(boolean stringsTrim) 已过时。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[]已过时。已过时。Convert a singleton or an array as List已过时。useDateTool.toLocale(Object)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, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
字段详细资料
-
STRINGS_DELIMITER_FORMAT_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
已过时。- 另请参阅:
-
-
构造器详细资料
-
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- 参数:
values- configuration values
-
setStringsDelimiter
Sets the delimiter used for separating values in a single String value. The default string delimiter is a comma.- 参数:
stringsDelimiter- strings delimiter to use- 另请参阅:
-
getStringsDelimiter
已过时。Gets the delimiter used for separating values in a single String value.- 返回:
- string delimiter
-
setStringsTrim
protected final void setStringsTrim(boolean stringsTrim) Sets whether strings should be trimmed when separated from a delimited string value. The default is true.- 参数:
stringsTrim- flag value- 另请参阅:
-
getStringsTrim
public final boolean getStringsTrim()已过时。- 返回:
- strings trim flag
-
setNumberFormat
已过时。useNumberToolformatSets numbers format- 参数:
format- numbers format
-
getNumberFormat
已过时。useNumberToolformat- 返回:
- number format
-
setDateFormat
已过时。useDateToolsetDateFormat() methodsSets date format- 参数:
format- date format
-
getDateFormat
已过时。useDateToolgetDateFormat() methods- 返回:
- date format
-
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
Booleanobject for the specified value ornullif the value is null or the conversion failed
-
toInteger
已过时。- 参数:
value- the object to be converted- 返回:
- a
Integerfor the specified value ornullif the value is null or the conversion failed
-
toDouble
已过时。- 参数:
value- the object to be converted- 返回:
- a
Doublefor the specified value ornullif the value is null or the conversion failed
-
toNumber
已过时。- 参数:
value- the object to be converted- 返回:
- a
Numberfor the specified value ornullif the value is null or the conversion failed
-
toLocale
已过时。useDateTool.toLocale(Object)- 覆盖:
toLocale在类中LocaleConfig- 参数:
value- the object to be converted- 返回:
- a
Localefor the specified value ornullif 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 defaultTimeZoneto parse the string value of the specified object.- 参数:
value- the date to convert- 返回:
- the object as a
Dateornullif no conversion is possible
-
toCalendar
已过时。- 参数:
value- target object- 返回:
- calendar
-
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.
-
toList
已过时。Convert a singleton or an array as List- 参数:
value- Object to be converted- 返回:
- either the object itself if it's already a list, the object converted to a list if it's an array, or a new singleton list.
-
parseBoolean
已过时。Converts a parameter value into aBooleanSub-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.- 参数:
value- string list to parse- 返回:
- array of strings
-
parseLocale
已过时。Converts a String value into a Locale.- 参数:
value- string of locale to parse- 返回:
- parsed locale, or null
-
parseNumber
已过时。Converts an object to an instance ofNumberusing the format returned bygetNumberFormat()and the defaultLocaleif the object is not already an instance of Number.- 参数:
value- the string to parse- 返回:
- the string as a
Numberornullif no conversion is possible
-
parseNumber
已过时。Converts an object to an instance ofNumberusing the specified format and theLocalereturned byLocaleConfig.getLocale().- 参数:
value- - the string to parseformat- - the format the number is in- 返回:
- the string as a
Numberornullif no conversion is possible - 另请参阅:
-
parseNumber
Converts an object to an instance ofNumberusing the configured number format and the specifiedLocale.- 参数:
value- - the string to parselocale- - the Locale to use- 返回:
- the string as a
Numberornullif no conversion is possible - 另请参阅:
-
parseNumber
- 参数:
value- - the string to parseformat- - the format the number is inlocale- - the Locale to use- 返回:
- the string as a
Numberornullif 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 defaultTimeZoneto parse it.- 参数:
value- the date to convert- 返回:
- the object as a
Dateornullif no conversion is possible
-
parseDate
已过时。Converts a string to an instance ofDateusing the specified format,the configured defaultLocale, and the system's defaultTimeZoneto parse it.- 参数:
value- - the date to convertformat- - the format the date is in- 返回:
- the string as a
Dateornullif no conversion is possible - 另请参阅:
-
parseDate
已过时。Converts a string to an instance ofDateusing the configured date format and specifiedLocaleto parse it.- 参数:
value- - the date to convertlocale- - the Locale to use- 返回:
- the string as a
Dateornullif no conversion is possible - 另请参阅:
-
parseDate
已过时。- 参数:
value- - the date to convertformat- - the format the date is inlocale- - the Locale to use- 返回:
- the string as a
Dateornullif no conversion is possible - 另请参阅:
-
parseDate
-