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:
java.io.Serializable
@DefaultKey("convert") @SkipSetters @Deprecated public class ConversionTool extends LocaleConfig implements java.io.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDATE_FORMAT_KEYDeprecated.static java.lang.StringDEFAULT_DATE_FORMATDeprecated.static java.lang.StringDEFAULT_NUMBER_FORMATDeprecated.static java.lang.StringDEFAULT_STRINGS_DELIMITERDeprecated.static booleanDEFAULT_STRINGS_TRIMDeprecated.static java.lang.StringNUMBER_FORMAT_KEYDeprecated.static java.lang.StringSTRINGS_DELIMITER_FORMAT_KEYDeprecated.-
Fields inherited from class org.apache.velocity.tools.generic.LocaleConfig
DEFAULT_LOCALE
-
Fields 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 Constructor Description ConversionTool()Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidconfigure(ValueParser values)Deprecated.Does the actual configuration.java.lang.StringgetDateFormat()Deprecated.useDateToolgetDateFormat() methodsjava.lang.StringgetNumberFormat()Deprecated.useNumberToolformatjava.lang.StringgetStringsDelimiter()Deprecated.Gets the delimiter used for separating values in a single String value.booleangetStringsTrim()Deprecated.protected java.lang.BooleanparseBoolean(java.lang.String value)Deprecated.Converts a parameter value into aBooleanSub-classes can override to allow for customized boolean parsing.java.util.DateparseDate(java.lang.String value)Deprecated.java.util.DateparseDate(java.lang.String value, java.lang.Object locale)Deprecated.java.util.DateparseDate(java.lang.String value, java.lang.String format)Deprecated.java.util.DateparseDate(java.lang.String value, java.lang.String format, java.lang.Object locale)Deprecated.java.util.DateparseDate(java.lang.String value, java.lang.String format, java.lang.Object locale, java.util.TimeZone timezone)Deprecated.protected java.util.LocaleparseLocale(java.lang.String value)Deprecated.Converts a String value into a Locale.java.lang.NumberparseNumber(java.lang.String value)Deprecated.java.lang.NumberparseNumber(java.lang.String value, java.lang.Object locale)Deprecated.java.lang.NumberparseNumber(java.lang.String value, java.lang.String format)Deprecated.java.lang.NumberparseNumber(java.lang.String value, java.lang.String format, java.lang.Object locale)Deprecated.protected java.lang.String[]parseStringList(java.lang.String value)Deprecated.Converts a single String value into an array of Strings by splitting it on the tool's set stringsDelimiter.protected voidsetDateFormat(java.lang.String format)Deprecated.useDateToolsetDateFormat() methodsprotected voidsetNumberFormat(java.lang.String format)Deprecated.useNumberToolformatprotected voidsetStringsDelimiter(java.lang.String stringsDelimiter)Deprecated.protected voidsetStringsTrim(boolean stringsTrim)Deprecated.java.lang.BooleantoBoolean(java.lang.Object value)Deprecated.java.lang.Boolean[]toBooleans(java.lang.Object value)Deprecated.java.lang.Boolean[]toBooleans(java.util.Collection values)Deprecated.java.util.CalendartoCalendar(java.lang.Object value)Deprecated.java.util.Calendar[]toCalendars(java.lang.Object value)Deprecated.java.util.Calendar[]toCalendars(java.util.Collection values)Deprecated.java.util.DatetoDate(java.lang.Object value)Deprecated.java.util.Date[]toDates(java.lang.Object value)Deprecated.java.util.Date[]toDates(java.util.Collection values)Deprecated.java.lang.DoubletoDouble(java.lang.Object value)Deprecated.double[]toDoubles(java.lang.Object value)Deprecated.java.lang.IntegertoInteger(java.lang.Object value)Deprecated.int[]toIntegers(java.lang.Object value)Deprecated.int[]toInts(java.lang.Object value)Deprecated.java.util.ListtoList(java.lang.Object value)Deprecated.Convert a singleton or an array as Listjava.util.LocaletoLocale(java.lang.Object value)Deprecated.useDateTool.toLocale(Object)java.util.Locale[]toLocales(java.lang.Object value)Deprecated.java.util.Locale[]toLocales(java.util.Collection values)Deprecated.java.lang.NumbertoNumber(java.lang.Object value)Deprecated.java.lang.Number[]toNumbers(java.lang.Object value)Deprecated.java.lang.Number[]toNumbers(java.util.Collection values)Deprecated.java.lang.StringtoString(java.lang.Object value)Deprecated.Converts objects to String in a more Tools-ish way than String.valueOf(Object), especially with nulls, Arrays and Collections.java.lang.String[]toStrings(java.lang.Object value)Deprecated.-
Methods inherited from class org.apache.velocity.tools.generic.LocaleConfig
getLocale, setLocale
-
Methods inherited from class org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig, setSafeMode
-
-
-
-
Field Detail
-
STRINGS_DELIMITER_FORMAT_KEY
public static final java.lang.String STRINGS_DELIMITER_FORMAT_KEY
Deprecated.- See Also:
- Constant Field Values
-
DATE_FORMAT_KEY
public static final java.lang.String DATE_FORMAT_KEY
Deprecated.- See Also:
- Constant Field Values
-
NUMBER_FORMAT_KEY
public static final java.lang.String NUMBER_FORMAT_KEY
Deprecated.- See Also:
- Constant Field Values
-
DEFAULT_STRINGS_DELIMITER
public static final java.lang.String DEFAULT_STRINGS_DELIMITER
Deprecated.- See Also:
- Constant Field Values
-
DEFAULT_STRINGS_TRIM
public static final boolean DEFAULT_STRINGS_TRIM
Deprecated.- See Also:
- Constant Field Values
-
DEFAULT_NUMBER_FORMAT
public static final java.lang.String DEFAULT_NUMBER_FORMAT
Deprecated.- See Also:
- Constant Field Values
-
DEFAULT_DATE_FORMAT
public static final java.lang.String DEFAULT_DATE_FORMAT
Deprecated.- See Also:
- Constant Field Values
-
-
Method Detail
-
configure
protected void configure(ValueParser values)
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
protected final void setStringsDelimiter(java.lang.String stringsDelimiter)
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:
parseStringList(java.lang.String)
-
getStringsDelimiter
public final java.lang.String 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:
parseStringList(java.lang.String)
-
getStringsTrim
public final boolean getStringsTrim()
Deprecated.- Returns:
- strings trim flag
-
setNumberFormat
protected final void setNumberFormat(java.lang.String format)
Deprecated.useNumberToolformatSets numbers format- Parameters:
format- numbers format
-
getNumberFormat
public final java.lang.String getNumberFormat()
Deprecated.useNumberToolformat- Returns:
- number format
-
setDateFormat
protected final void setDateFormat(java.lang.String format)
Deprecated.useDateToolsetDateFormat() methodsSets date format- Parameters:
format- date format
-
getDateFormat
public final java.lang.String getDateFormat()
Deprecated.useDateToolgetDateFormat() methods- Returns:
- date format
-
toString
public java.lang.String toString(java.lang.Object value)
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
public java.lang.Boolean toBoolean(java.lang.Object value)
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
public java.lang.Integer toInteger(java.lang.Object value)
Deprecated.- Parameters:
value- the object to be converted- Returns:
- a
Integerfor the specified value ornullif the value is null or the conversion failed
-
toDouble
public java.lang.Double toDouble(java.lang.Object value)
Deprecated.- Parameters:
value- the object to be converted- Returns:
- a
Doublefor the specified value ornullif the value is null or the conversion failed
-
toNumber
public java.lang.Number toNumber(java.lang.Object value)
Deprecated.- Parameters:
value- the object to be converted- Returns:
- a
Numberfor the specified value ornullif the value is null or the conversion failed
-
toLocale
public java.util.Locale toLocale(java.lang.Object value)
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
public java.util.Date toDate(java.lang.Object value)
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
public java.util.Calendar toCalendar(java.lang.Object value)
Deprecated.- Parameters:
value- target object- Returns:
- calendar
-
toStrings
public java.lang.String[] toStrings(java.lang.Object value)
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
public java.lang.Boolean[] toBooleans(java.lang.Object value)
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of Boolean objects derived from the specified value,
or
null.
-
toBooleans
public java.lang.Boolean[] toBooleans(java.util.Collection values)
Deprecated.- Parameters:
values- the collection of values to be converted- Returns:
- an array of Boolean objects derived from the specified values,
or
null.
-
toNumbers
public java.lang.Number[] toNumbers(java.lang.Object value)
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of Number objects derived from the specified value,
or
null.
-
toNumbers
public java.lang.Number[] toNumbers(java.util.Collection values)
Deprecated.- Parameters:
values- the collection of values to be converted- Returns:
- an array of Number objects derived from the specified values,
or
null.
-
toInts
public int[] toInts(java.lang.Object value)
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of int values derived from the specified value,
or
null.
-
toIntegers
public int[] toIntegers(java.lang.Object value)
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of int values derived from the specified value,
or
null.
-
toDoubles
public double[] toDoubles(java.lang.Object value)
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of double values derived from the specified value,
or
null.
-
toLocales
public java.util.Locale[] toLocales(java.lang.Object value)
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of Locale objects derived from the specified value,
or
null.
-
toLocales
public java.util.Locale[] toLocales(java.util.Collection values)
Deprecated.- Parameters:
values- the collection of values to be converted- Returns:
- an array of Locale objects derived from the specified values,
or
null.
-
toDates
public java.util.Date[] toDates(java.lang.Object value)
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of Date objects derived from the specified value,
or
null.
-
toDates
public java.util.Date[] toDates(java.util.Collection values)
Deprecated.- Parameters:
values- the collection of values to be converted- Returns:
- an array of Date objects derived from the specified values,
or
null.
-
toCalendars
public java.util.Calendar[] toCalendars(java.lang.Object value)
Deprecated.- Parameters:
value- the value to be converted- Returns:
- an array of Calendar objects derived from the specified value,
or
null.
-
toCalendars
public java.util.Calendar[] toCalendars(java.util.Collection values)
Deprecated.- Parameters:
values- the collection of values to be converted- Returns:
- an array of Calendar objects derived from the specified values,
or
null.
-
toList
public java.util.List toList(java.lang.Object value)
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
protected java.lang.Boolean parseBoolean(java.lang.String value)
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
protected java.lang.String[] parseStringList(java.lang.String value)
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
protected java.util.Locale parseLocale(java.lang.String value)
Deprecated.Converts a String value into a Locale.- Parameters:
value- string of locale to parse- Returns:
- parsed locale, or null
-
parseNumber
public java.lang.Number parseNumber(java.lang.String value)
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
public java.lang.Number parseNumber(java.lang.String value, java.lang.String format)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(String value, String format, Object locale)
-
parseNumber
public java.lang.Number parseNumber(java.lang.String value, java.lang.Object locale)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:
NumberFormat.parse(java.lang.String, java.text.ParsePosition)
-
parseNumber
public java.lang.Number parseNumber(java.lang.String value, java.lang.String format, java.lang.Object locale)Deprecated.Converts an object to an instance ofNumberusing the specified format andLocale.- 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:
NumberFormat.parse(java.lang.String, java.text.ParsePosition)
-
parseDate
public java.util.Date parseDate(java.lang.String value)
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
public java.util.Date parseDate(java.lang.String value, java.lang.String format)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:
ConversionUtils.toDate(String str, String format, Locale locale, TimeZone timezone)
-
parseDate
public java.util.Date parseDate(java.lang.String value, java.lang.Object locale)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:
SimpleDateFormat.parse(java.lang.String, java.text.ParsePosition)
-
parseDate
public java.util.Date parseDate(java.lang.String value, java.lang.String format, java.lang.Object locale)Deprecated.Converts a string to an instance ofDateusing the specified format andLocaleto parse it.- 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:
SimpleDateFormat.parse(java.lang.String, java.text.ParsePosition)
-
parseDate
public java.util.Date parseDate(java.lang.String value, java.lang.String format, java.lang.Object locale, java.util.TimeZone timezone)Deprecated.Converts a string to an instance ofDateusing the specified format,Locale, andTimeZone.- Parameters:
value- - the date to convertformat- - the format the date is inlocale- - the Locale to usetimezone- - theTimeZone- Returns:
- the string as a
Dateornullif no conversion is possible - See Also:
getDateFormat(),SimpleDateFormat.parse(java.lang.String, java.text.ParsePosition)
-
-