Class ConversionTool
java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.ConversionTool
- All Implemented Interfaces:
Serializable
@DefaultKey("convert")
@SkipSetters
@Deprecated
public class ConversionTool
extends LocaleConfig
implements Serializable
Deprecated.
use NumberTool for numbers and booleans 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.
- Since:
- VelocityTools 2.0
- Version:
- $Revision$ $Date: 2007-02-26 11:24:39 -0800 (Mon, 26 Feb 2007) $
- Author:
- Nathan Bubna
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final StringDeprecated.static final booleanDeprecated.static final StringDeprecated.static final StringDeprecated.Fields inherited from class LocaleConfig
DEFAULT_LOCALEFields inherited from class SafeConfig
LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconfigure(ValueParser values) Deprecated.Does the actual configuration.final StringDeprecated.useDateToolgetDateFormat() methodsfinal StringDeprecated.useNumberToolformatfinal StringDeprecated.Gets the delimiter used for separating values in a single String value.final booleanDeprecated.protected BooleanparseBoolean(String value) Deprecated.Converts a parameter value into aBooleanSub-classes can override to allow for customized boolean parsing.Deprecated.Deprecated.Deprecated.Deprecated.Deprecated.protected LocaleparseLocale(String value) Deprecated.Converts a String value into a Locale.parseNumber(String value) Deprecated.parseNumber(String value, Object locale) Deprecated.parseNumber(String value, String format) Deprecated.parseNumber(String value, String format, Object locale) Deprecated.protected String[]parseStringList(String value) Deprecated.Converts a single String value into an array of Strings by splitting it on the tool's set stringsDelimiter.protected final voidsetDateFormat(String format) Deprecated.useDateToolsetDateFormat() methodsprotected final voidsetNumberFormat(String format) Deprecated.useNumberToolformatprotected final voidsetStringsDelimiter(String stringsDelimiter) Deprecated.protected final voidsetStringsTrim(boolean stringsTrim) Deprecated.Deprecated.Boolean[]toBooleans(Object value) Deprecated.Boolean[]toBooleans(Collection values) Deprecated.toCalendar(Object value) Deprecated.Calendar[]toCalendars(Object value) Deprecated.Calendar[]toCalendars(Collection values) Deprecated.Deprecated.Date[]Deprecated.Date[]toDates(Collection values) Deprecated.Deprecated.double[]Deprecated.Deprecated.int[]toIntegers(Object value) Deprecated.int[]Deprecated.Deprecated.Convert a singleton or an array as ListDeprecated.useDateTool.toLocale(Object)Locale[]Deprecated.Locale[]toLocales(Collection values) Deprecated.Deprecated.Number[]Deprecated.Number[]toNumbers(Collection values) Deprecated.Deprecated.Converts objects to String in a more Tools-ish way than String.valueOf(Object), especially with nulls, Arrays and Collections.String[]Deprecated.Methods inherited from class LocaleConfig
getLocale, setLocaleMethods inherited from class SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
Field Details
-
STRINGS_DELIMITER_FORMAT_KEY
-
DATE_FORMAT_KEY
-
NUMBER_FORMAT_KEY
-
DEFAULT_STRINGS_DELIMITER
-
DEFAULT_STRINGS_TRIM
public static final boolean DEFAULT_STRINGS_TRIMDeprecated.- See Also:
-
DEFAULT_NUMBER_FORMAT
-
DEFAULT_DATE_FORMAT
-
-
Constructor Details
-
ConversionTool
public ConversionTool()Deprecated.
-
-
Method Details
-
configure
Deprecated.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.- Overrides:
configurein classLocaleConfig- Parameters:
values- configuration values
-
setStringsDelimiter
Deprecated.Sets the delimiter used for separating values in a single String value. The default string delimiter is a comma.- Parameters:
stringsDelimiter- strings delimiter to use- See Also:
-
getStringsDelimiter
Deprecated.Gets the delimiter used for separating values in a single String value.- Returns:
- string delimiter
-
setStringsTrim
protected final void setStringsTrim(boolean stringsTrim) Deprecated.Sets whether strings should be trimmed when separated from a delimited string value. The default is true.- Parameters:
stringsTrim- flag value- See Also:
-
getStringsTrim
public final boolean getStringsTrim()Deprecated.- Returns:
- strings trim flag
-
setNumberFormat
-
getNumberFormat
-
setDateFormat
-
getDateFormat
-
toString
Deprecated.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.- Parameters:
value- the object to be turned into a String- Returns:
- 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
-
toInteger
-
toDouble
-
toNumber
-
toLocale
-
toDate
Deprecated.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.- Parameters:
value- the date to convert- Returns:
- the object as a
Dateornullif no conversion is possible
-
toCalendar
Deprecated.- Parameters:
value- target object- Returns:
- calendar
-
toStrings
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of String objects containing all of the values derived from the specified array, Collection, or delimited String
-
toBooleans
-
toBooleans
Deprecated.- Parameters:
values- the collection of values to be converted- Returns:
- an array of Boolean objects derived from the specified values,
or
null.
-
toNumbers
-
toNumbers
Deprecated.- Parameters:
values- the collection of values to be converted- Returns:
- an array of Number objects derived from the specified values,
or
null.
-
toInts
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of int values derived from the specified value,
or
null.
-
toIntegers
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of int values derived from the specified value,
or
null.
-
toDoubles
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of double values derived from the specified value,
or
null.
-
toLocales
-
toLocales
Deprecated.- Parameters:
values- the collection of values to be converted- Returns:
- an array of Locale objects derived from the specified values,
or
null.
-
toDates
-
toDates
Deprecated.- Parameters:
values- the collection of values to be converted- Returns:
- an array of Date objects derived from the specified values,
or
null.
-
toCalendars
-
toCalendars
Deprecated.- Parameters:
values- the collection of values to be converted- Returns:
- an array of Calendar objects derived from the specified values,
or
null.
-
toList
-
parseBoolean
-
parseStringList
Deprecated.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.- Parameters:
value- string list to parse- Returns:
- array of strings
-
parseLocale
-
parseNumber
Deprecated.Converts an object to an instance ofNumberusing the format returned bygetNumberFormat()and the defaultLocaleif the object is not already an instance of Number.- Parameters:
value- the string to parse- Returns:
- the string as a
Numberornullif no conversion is possible
-
parseNumber
Deprecated.Converts an object to an instance ofNumberusing the specified format and theLocalereturned byLocaleConfig.getLocale().- Parameters:
value- - the string to parseformat- - the format the number is in- Returns:
- the string as a
Numberornullif no conversion is possible - See Also:
-
parseNumber
-
parseNumber
Deprecated.- Parameters:
value- - the string to parseformat- - the format the number is inlocale- - the Locale to use- Returns:
- the string as a
Numberornullif no conversion is possible - See Also:
-
parseDate
-
parseDate
Deprecated.Converts a string to an instance ofDateusing the specified format,the configured defaultLocale, and the system's defaultTimeZoneto parse it.- Parameters:
value- - the date to convertformat- - the format the date is in- Returns:
- the string as a
Dateornullif no conversion is possible - See Also:
-
parseDate
-
parseDate
Deprecated.- Parameters:
value- - the date to convertformat- - the format the date is inlocale- - the Locale to use- Returns:
- the string as a
Dateornullif no conversion is possible - See Also:
-
parseDate
Deprecated.
-