类 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
另请参阅:
  • 字段详细资料

    • STRINGS_DELIMITER_FORMAT_KEY

      public static final String STRINGS_DELIMITER_FORMAT_KEY
      已过时。
      另请参阅:
    • DATE_FORMAT_KEY

      public static final String DATE_FORMAT_KEY
      已过时。
      另请参阅:
    • NUMBER_FORMAT_KEY

      public static final String NUMBER_FORMAT_KEY
      已过时。
      另请参阅:
    • DEFAULT_STRINGS_DELIMITER

      public static final String DEFAULT_STRINGS_DELIMITER
      已过时。
      另请参阅:
    • DEFAULT_STRINGS_TRIM

      public static final boolean DEFAULT_STRINGS_TRIM
      已过时。
      另请参阅:
    • DEFAULT_NUMBER_FORMAT

      public static final String DEFAULT_NUMBER_FORMAT
      已过时。
      另请参阅:
    • DEFAULT_DATE_FORMAT

      public static final String DEFAULT_DATE_FORMAT
      已过时。
      另请参阅:
  • 构造器详细资料

    • ConversionTool

      public ConversionTool()
      已过时。
  • 方法详细资料

    • configure

      protected void configure(ValueParser values)
      已过时。
      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

      protected final void setStringsDelimiter(String stringsDelimiter)
      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

      public final String 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

      protected final void setNumberFormat(String format)
      已过时。
      use NumberTool format
      Sets numbers format
      参数:
      format - numbers format
    • getNumberFormat

      public final String getNumberFormat()
      已过时。
      use NumberTool format
      返回:
      number format
    • setDateFormat

      protected final void setDateFormat(String format)
      已过时。
      use DateTool setDateFormat() methods
      Sets date format
      参数:
      format - date format
    • getDateFormat

      public final String getDateFormat()
      已过时。
      use DateTool getDateFormat() methods
      返回:
      date format
    • toString

      public String toString(Object value)
      已过时。
      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

      public Boolean toBoolean(Object value)
      已过时。
      参数:
      value - the object to be converted
      返回:
      a Boolean object for the specified value or null if the value is null or the conversion failed
    • toInteger

      public Integer toInteger(Object value)
      已过时。
      参数:
      value - the object to be converted
      返回:
      a Integer for the specified value or null if the value is null or the conversion failed
    • toDouble

      public Double toDouble(Object value)
      已过时。
      参数:
      value - the object to be converted
      返回:
      a Double for the specified value or null if the value is null or the conversion failed
    • toNumber

      public Number toNumber(Object value)
      已过时。
      参数:
      value - the object to be converted
      返回:
      a Number for the specified value or null if the value is null or the conversion failed
    • toLocale

      public Locale toLocale(Object value)
      已过时。
      use DateTool.toLocale(Object)
      覆盖:
      toLocale 在类中 LocaleConfig
      参数:
      value - the object to be converted
      返回:
      a Locale for the specified value or null if the value is null or the conversion failed
    • toDate

      public Date toDate(Object value)
      已过时。
      Converts an object to an instance of Date, when necessary using the configured date parsing format, the configured default Locale, and the system's default TimeZone to parse the string value of the specified object.
      参数:
      value - the date to convert
      返回:
      the object as a Date or null if no conversion is possible
    • toCalendar

      public Calendar toCalendar(Object value)
      已过时。
      参数:
      value - target object
      返回:
      calendar
    • toStrings

      public String[] toStrings(Object value)
      参数:
      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

      public Boolean[] toBooleans(Object value)
      已过时。
      参数:
      value - the value to be converted
      返回:
      an array of Boolean objects derived from the specified value, or null.
    • toBooleans

      public Boolean[] toBooleans(Collection values)
      已过时。
      参数:
      values - the collection of values to be converted
      返回:
      an array of Boolean objects derived from the specified values, or null.
    • toNumbers

      public Number[] toNumbers(Object value)
      已过时。
      参数:
      value - the value to be converted
      返回:
      an array of Number objects derived from the specified value, or null.
    • toNumbers

      public Number[] toNumbers(Collection values)
      已过时。
      参数:
      values - the collection of values to be converted
      返回:
      an array of Number objects derived from the specified values, or null.
    • toInts

      public int[] toInts(Object value)
      已过时。
      参数:
      value - the value to be converted
      返回:
      an array of int values derived from the specified value, or null.
    • toIntegers

      public int[] toIntegers(Object value)
      已过时。
      参数:
      value - the value to be converted
      返回:
      an array of int values derived from the specified value, or null.
    • toDoubles

      public double[] toDoubles(Object value)
      已过时。
      参数:
      value - the value to be converted
      返回:
      an array of double values derived from the specified value, or null.
    • toLocales

      public Locale[] toLocales(Object value)
      已过时。
      参数:
      value - the value to be converted
      返回:
      an array of Locale objects derived from the specified value, or null.
    • toLocales

      public Locale[] toLocales(Collection values)
      已过时。
      参数:
      values - the collection of values to be converted
      返回:
      an array of Locale objects derived from the specified values, or null.
    • toDates

      public Date[] toDates(Object value)
      已过时。
      参数:
      value - the value to be converted
      返回:
      an array of Date objects derived from the specified value, or null.
    • toDates

      public Date[] toDates(Collection values)
      已过时。
      参数:
      values - the collection of values to be converted
      返回:
      an array of Date objects derived from the specified values, or null.
    • toCalendars

      public Calendar[] toCalendars(Object value)
      已过时。
      参数:
      value - the value to be converted
      返回:
      an array of Calendar objects derived from the specified value, or null.
    • toCalendars

      public Calendar[] toCalendars(Collection values)
      已过时。
      参数:
      values - the collection of values to be converted
      返回:
      an array of Calendar objects derived from the specified values, or null.
    • toList

      public List toList(Object value)
      已过时。
      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

      protected Boolean parseBoolean(String value)
      已过时。
      Converts a parameter value into a Boolean 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

      protected String[] parseStringList(String value)
      已过时。
      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

      protected Locale parseLocale(String value)
      已过时。
      Converts a String value into a Locale.
      参数:
      value - string of locale to parse
      返回:
      parsed locale, or null
    • parseNumber

      public Number parseNumber(String value)
      已过时。
      Converts an object to an instance of Number using the format returned by getNumberFormat() and the default Locale if the object is not already an instance of Number.
      参数:
      value - the string to parse
      返回:
      the string as a Number or null if no conversion is possible
    • parseNumber

      public Number parseNumber(String value, String format)
      Converts an object to an instance of Number using the specified format and the Locale returned by LocaleConfig.getLocale().
      参数:
      value - - the string to parse
      format - - the format the number is in
      返回:
      the string as a Number or null if no conversion is possible
      另请参阅:
    • parseNumber

      public Number parseNumber(String value, Object locale)
      Converts an object to an instance of Number using the configured number format and the specified Locale.
      参数:
      value - - the string to parse
      locale - - the Locale to use
      返回:
      the string as a Number or null if no conversion is possible
      另请参阅:
    • parseNumber

      public Number parseNumber(String value, String format, Object locale)
      Converts an object to an instance of Number using the specified format and Locale.
      参数:
      value - - the string to parse
      format - - the format the number is in
      locale - - the Locale to use
      返回:
      the string as a Number or null if no conversion is possible
      另请参阅:
    • parseDate

      public Date parseDate(String value)
      已过时。
      Converts a string to an instance of Date, using the configured date parsing format, the configured default Locale, and the system's default TimeZone to parse it.
      参数:
      value - the date to convert
      返回:
      the object as a Date or null if no conversion is possible
    • parseDate

      public Date parseDate(String value, String format)
      Converts a string to an instance of Date using the specified format,the configured default Locale, and the system's default TimeZone to parse it.
      参数:
      value - - the date to convert
      format - - the format the date is in
      返回:
      the string as a Date or null if no conversion is possible
      另请参阅:
    • parseDate

      public Date parseDate(String value, Object locale)
      Converts a string to an instance of Date using the configured date format and specified Locale to parse it.
      参数:
      value - - the date to convert
      locale - - the Locale to use
      返回:
      the string as a Date or null if no conversion is possible
      另请参阅:
    • parseDate

      public Date parseDate(String value, String format, Object locale)
      Converts a string to an instance of Date using the specified format and Locale to parse it.
      参数:
      value - - the date to convert
      format - - the format the date is in
      locale - - the Locale to use
      返回:
      the string as a Date or null if no conversion is possible
      另请参阅:
    • parseDate

      public Date parseDate(String value, String format, Object locale, TimeZone timezone)
      Converts a string to an instance of Date using the specified format, Locale, and TimeZone.
      参数:
      value - - the date to convert
      format - - the format the date is in
      locale - - the Locale to use
      timezone - - the TimeZone
      返回:
      the string as a Date or null if no conversion is possible
      另请参阅: