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 org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALEFields inherited from class org.apache.velocity.tools.generic.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 org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocaleMethods inherited from class org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
Field Details
-
STRINGS_DELIMITER_FORMAT_KEY
Deprecated.- See Also:
-
DATE_FORMAT_KEY
Deprecated.- See Also:
-
NUMBER_FORMAT_KEY
Deprecated.- See Also:
-
DEFAULT_STRINGS_DELIMITER
Deprecated.- See Also:
-
DEFAULT_STRINGS_TRIM
public static final boolean DEFAULT_STRINGS_TRIMDeprecated.- See Also:
-
DEFAULT_NUMBER_FORMAT
Deprecated.- See Also:
-
DEFAULT_DATE_FORMAT
Deprecated.- See Also:
-
-
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
Deprecated.useNumberToolformatSets numbers format- Parameters:
format- numbers format
-
getNumberFormat
Deprecated.useNumberToolformat- Returns:
- number format
-
setDateFormat
Deprecated.useDateToolsetDateFormat() methodsSets date format- Parameters:
format- date format
-
getDateFormat
Deprecated.useDateToolgetDateFormat() methods- Returns:
- date format
-
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
Deprecated.- Parameters:
value- the object to be converted- Returns:
- a
Booleanobject for the specified value ornullif the value is null or the conversion failed
-
toInteger
Deprecated.- Parameters:
value- the object to be converted- Returns:
- a
Integerfor the specified value ornullif the value is null or the conversion failed
-
toDouble
Deprecated.- Parameters:
value- the object to be converted- Returns:
- a
Doublefor the specified value ornullif the value is null or the conversion failed
-
toNumber
Deprecated.- Parameters:
value- the object to be converted- Returns:
- a
Numberfor the specified value ornullif the value is null or the conversion failed
-
toLocale
Deprecated.useDateTool.toLocale(Object)- Overrides:
toLocalein classLocaleConfig- Parameters:
value- the object to be converted- Returns:
- a
Localefor the specified value ornullif the value is null or the conversion failed
-
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
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of Boolean objects derived from the specified value,
or
null.
-
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
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of Number objects derived from the specified value,
or
null.
-
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
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of Locale objects derived from the specified value,
or
null.
-
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
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of Date objects derived from the specified value,
or
null.
-
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
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of Calendar objects derived from the specified value,
or
null.
-
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
Deprecated.Convert a singleton or an array as List- Parameters:
value- Object to be converted- Returns:
- 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
Deprecated.Converts a parameter value into aBooleanSub-classes can override to allow for customized boolean parsing. (e.g. to handle "Yes/No" or "T/F")- Parameters:
value- the string to be parsed- Returns:
- the value as a
Boolean
-
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
Deprecated.Converts a String value into a Locale.- Parameters:
value- string of locale to parse- Returns:
- parsed locale, or null
-
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
Deprecated.Converts an object to an instance ofNumberusing the configured number format and the specifiedLocale.- Parameters:
value- - the string to parselocale- - the Locale to use- Returns:
- the string as a
Numberornullif no conversion is possible - See Also:
-
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
Deprecated.Converts a string to an instance ofDate, using the configured date parsing format, the configured defaultLocale, and the system's defaultTimeZoneto parse it.- Parameters:
value- the date to convert- Returns:
- the object as a
Dateornullif no conversion is possible
-
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
Deprecated.Converts a string to an instance ofDateusing the configured date format and specifiedLocaleto parse it.- Parameters:
value- - the date to convertlocale- - the Locale to use- Returns:
- the string as a
Dateornullif no conversion is possible - See Also:
-
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.
-