org.apache.commons.beanutils.locale.converters

Class DateLocaleConverter

Implemented Interfaces:
Converter, LocaleConverter
Known Direct Subclasses:
SqlDateLocaleConverter, SqlTimeLocaleConverter, SqlTimestampLocaleConverter

public class DateLocaleConverter
extends BaseLocaleConverter

Standard LocaleConverter implementation that converts an incoming locale-sensitive String into a java.util.Date object, optionally using a default value or throwing a ConversionException if a conversion error occurs.
Authors:
Yauheny Mikulski
Michael Szlapa

Field Summary

private static String
DEFAULT_PATTERN_CHARS
Default Pattern Characters
(package private) boolean
isLenient
Should the date conversion be lenient?
private Log
log
All logging goes through this logger

Fields inherited from class org.apache.commons.beanutils.locale.BaseLocaleConverter

defaultValue, locPattern, locale, log, pattern, useDefault

Constructor Summary

DateLocaleConverter()
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.
DateLocaleConverter(Locale locale)
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.
DateLocaleConverter(Locale locale, String pattern)
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.
DateLocaleConverter(Locale locale, String pattern, boolean locPattern)
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.
DateLocaleConverter(Locale locale, boolean locPattern)
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.
DateLocaleConverter(Object defaultValue)
Create a LocaleConverter that will return the specified default value if a conversion error occurs.
DateLocaleConverter(Object defaultValue, Locale locale)
Create a LocaleConverter that will return the specified default value if a conversion error occurs.
DateLocaleConverter(Object defaultValue, Locale locale, String pattern)
Create a LocaleConverter that will return the specified default value if a conversion error occurs.
DateLocaleConverter(Object defaultValue, Locale locale, String pattern, boolean locPattern)
Create a LocaleConverter that will return the specified default value if a conversion error occurs.
DateLocaleConverter(Object defaultValue, Locale locale, boolean locPattern)
Create a LocaleConverter that will return the specified default value if a conversion error occurs.
DateLocaleConverter(Object defaultValue, boolean locPattern)
Create a LocaleConverter that will return the specified default value if a conversion error occurs.
DateLocaleConverter(boolean locPattern)
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.

Method Summary

private String
convertLocalizedPattern(String localizedPattern, Locale locale)
Convert a pattern from a localized format to the default format.
private String
convertPattern(String pattern, String fromChars, String toChars)
Converts a Pattern from one character set to another.
private static String
initDefaultChars()
This method is called at class initialization time to define the value for constant member DEFAULT_PATTERN_CHARS.
boolean
isLenient()
Returns whether date formatting is lenient.
protected Object
parse(Object value, String pattern)
Convert the specified locale-sensitive input object into an output object of the specified type.
void
setLenient(boolean lenient)
Specify whether or not date-time parsing should be lenient.

Methods inherited from class org.apache.commons.beanutils.locale.BaseLocaleConverter

convert, convert, convert, convert, parse

Field Details

DEFAULT_PATTERN_CHARS

private static final String DEFAULT_PATTERN_CHARS
Default Pattern Characters

isLenient

(package private)  boolean isLenient
Should the date conversion be lenient?

log

private Log log
All logging goes through this logger

Constructor Details

DateLocaleConverter

public DateLocaleConverter()
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs. The locale is the default locale for this instance of the Java Virtual Machine and an unlocalized pattern is used for the convertion.

DateLocaleConverter

public DateLocaleConverter(Locale locale)
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs. An unlocalized pattern is used for the convertion.
Parameters:
locale - The locale

DateLocaleConverter

public DateLocaleConverter(Locale locale,
                           String pattern)
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs. An unlocalized pattern is used for the convertion.
Parameters:
locale - The locale
pattern - The convertion pattern

DateLocaleConverter

public DateLocaleConverter(Locale locale,
                           String pattern,
                           boolean locPattern)
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.
Parameters:
locale - The locale
pattern - The convertion pattern
locPattern - Indicate whether the pattern is localized or not

DateLocaleConverter

public DateLocaleConverter(Locale locale,
                           boolean locPattern)
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs.
Parameters:
locale - The locale
locPattern - Indicate whether the pattern is localized or not

DateLocaleConverter

public DateLocaleConverter(Object defaultValue)
Create a LocaleConverter that will return the specified default value if a conversion error occurs. The locale is the default locale for this instance of the Java Virtual Machine and an unlocalized pattern is used for the convertion.
Parameters:
defaultValue - The default value to be returned

DateLocaleConverter

public DateLocaleConverter(Object defaultValue,
                           Locale locale)
Create a LocaleConverter that will return the specified default value if a conversion error occurs. An unlocalized pattern is used for the convertion.
Parameters:
defaultValue - The default value to be returned
locale - The locale

DateLocaleConverter

public DateLocaleConverter(Object defaultValue,
                           Locale locale,
                           String pattern)
Create a LocaleConverter that will return the specified default value if a conversion error occurs. An unlocalized pattern is used for the convertion.
Parameters:
defaultValue - The default value to be returned
locale - The locale
pattern - The convertion pattern

DateLocaleConverter

public DateLocaleConverter(Object defaultValue,
                           Locale locale,
                           String pattern,
                           boolean locPattern)
Create a LocaleConverter that will return the specified default value if a conversion error occurs.
Parameters:
defaultValue - The default value to be returned
locale - The locale
pattern - The convertion pattern
locPattern - Indicate whether the pattern is localized or not

DateLocaleConverter

public DateLocaleConverter(Object defaultValue,
                           Locale locale,
                           boolean locPattern)
Create a LocaleConverter that will return the specified default value if a conversion error occurs.
Parameters:
defaultValue - The default value to be returned
locale - The locale
locPattern - Indicate whether the pattern is localized or not

DateLocaleConverter

public DateLocaleConverter(Object defaultValue,
                           boolean locPattern)
Create a LocaleConverter that will return the specified default value if a conversion error occurs. The locale is the default locale for this instance of the Java Virtual Machine.
Parameters:
defaultValue - The default value to be returned
locPattern - Indicate whether the pattern is localized or not

DateLocaleConverter

public DateLocaleConverter(boolean locPattern)
Create a LocaleConverter that will throw a ConversionException if a conversion error occurs. The locale is the default locale for this instance of the Java Virtual Machine.
Parameters:
locPattern - Indicate whether the pattern is localized or not

Method Details

convertLocalizedPattern

private String convertLocalizedPattern(String localizedPattern,
                                       Locale locale)
Convert a pattern from a localized format to the default format.
Parameters:
localizedPattern - The pattern in 'local' symbol format
locale - The locale
Returns:
pattern in 'default' symbol format

convertPattern

private String convertPattern(String pattern,
                              String fromChars,
                              String toChars)
Converts a Pattern from one character set to another.

initDefaultChars

private static String initDefaultChars()
This method is called at class initialization time to define the value for constant member DEFAULT_PATTERN_CHARS. All other methods needing this data should just read that constant.

isLenient

public boolean isLenient()
Returns whether date formatting is lenient.
Returns:
true if the DateFormat used for formatting is lenient
See Also:
java.text.DateFormat.isLenient

parse

protected Object parse(Object value,
                       String pattern)
            throws ParseException
Convert the specified locale-sensitive input object into an output object of the specified type.
Overrides:
parse in interface BaseLocaleConverter
Parameters:
value - The input object to be converted
pattern - The pattern is used for the convertion
Returns:
the converted Date value

setLenient

public void setLenient(boolean lenient)
Specify whether or not date-time parsing should be lenient.
Parameters:
lenient - true if the DateFormat used for formatting should be lenient
See Also:
java.text.DateFormat.setLenient

Copyright (c) 2001-2007 - Apache Software Foundation