Package io.milton.http.annotated
Class NullSafeDateTimeConverter
java.lang.Object
org.apache.commons.beanutils.converters.AbstractConverter
io.milton.http.annotated.NullSafeDateTimeConverter
- All Implemented Interfaces:
org.apache.commons.beanutils.Converter
public class NullSafeDateTimeConverter
extends org.apache.commons.beanutils.converters.AbstractConverter
Null safe and pulls the timezone from the request using DataBinder.getTimeZoneForRequest
Mostly copied from DateTimeConverter
- Author:
- brad
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a Date/Time Converter that throws aConversionExceptionif an error occurs.NullSafeDateTimeConverter(Object defaultValue) Construct a Date/Time Converter that returns a default value if an error occurs. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringconvertToString(Object value) Convert an input Date/Calendar object into a String.protected ObjectconvertToType(Class targetType, Object value) Convert the input object into a Date object of the specified type.protected Classprotected DateFormatReturn aDateFormatfor the Locale.Return the Locale for the Converter (ornullif none specified).String[]Return the date format patterns used to convert dates to/from ajava.lang.String(ornullif none specified).protected ObjecthandleMissing(Class type) voidSet the Locale for the Converter.voidsetPattern(String pattern) Set a date format pattern to use to convert dates to/from ajava.lang.String.voidsetPatterns(String[] patterns) Set the date format patterns to use to convert dates to/from ajava.lang.String.voidsetUseLocaleFormat(boolean useLocaleFormat) Indicate whether conversion should use a format/pattern or not.toString()Provide a String representation of this date/time converter.Methods inherited from class org.apache.commons.beanutils.converters.AbstractConverter
conversionException, convert, convertArray, getDefault, handleError, isUseDefault, setDefaultValue
-
Constructor Details
-
NullSafeDateTimeConverter
public NullSafeDateTimeConverter()Construct a Date/Time Converter that throws aConversionExceptionif an error occurs. -
NullSafeDateTimeConverter
Construct a Date/Time Converter that returns a default value if an error occurs.- Parameters:
defaultValue- The default value to be returned if the value to be converted is missing or an error occurs converting the value.
-
-
Method Details
-
handleMissing
- Overrides:
handleMissingin classorg.apache.commons.beanutils.converters.AbstractConverter
-
getDefaultType
- Specified by:
getDefaultTypein classorg.apache.commons.beanutils.converters.AbstractConverter
-
getTimeZone
-
setUseLocaleFormat
public void setUseLocaleFormat(boolean useLocaleFormat) Indicate whether conversion should use a format/pattern or not.- Parameters:
useLocaleFormat-trueif the format for the locale should be used, otherwisefalse
-
getLocale
Return the Locale for the Converter (ornullif none specified).- Returns:
- The locale to use for conversion
-
setLocale
Set the Locale for the Converter.- Parameters:
locale- The Locale.
-
setPattern
Set a date format pattern to use to convert dates to/from ajava.lang.String.- Parameters:
pattern- The format pattern.- See Also:
-
getPatterns
Return the date format patterns used to convert dates to/from ajava.lang.String(ornullif none specified).- Returns:
- Array of format patterns.
- See Also:
-
setPatterns
Set the date format patterns to use to convert dates to/from ajava.lang.String.- Parameters:
patterns- Array of format patterns.- See Also:
-
convertToString
Convert an input Date/Calendar object into a String.N.B.If the converter has been configured to with one or more patterns (using
setPatterns()), then the first pattern will be used to format the date into a String. Otherwise the defaultDateFormatfor the default locale (and style if configured) will be used.- Overrides:
convertToStringin classorg.apache.commons.beanutils.converters.AbstractConverter- Parameters:
value- The input value to be converted- Returns:
- the converted String value.
- Throws:
Throwable- if an error occurs converting to a String
-
convertToType
Convert the input object into a Date object of the specified type.This method handles conversions between the following types:
java.util.Datejava.util.Calendarjava.sql.Datejava.sql.Timejava.sql.Timestamp
Stringto any of the above types.For
Stringconversion, if the converter has been configured with one or more patterns (usingsetPatterns()), then the conversion is attempted with each of the specified patterns. Otherwise the defaultDateFormatfor the default locale (and style if configured) will be used.- Specified by:
convertToTypein classorg.apache.commons.beanutils.converters.AbstractConverter- Parameters:
targetType- Data type to which this value should be converted.value- The input value to be converted.- Returns:
- The converted value.
- Throws:
Exception- if conversion cannot be performed successfully
-
getFormat
Return aDateFormatfor the Locale.- Parameters:
locale- The Locale to create the Format with (may be null)timeZone- The Time Zone create the Format with (may be null)- Returns:
- A Date Format.
-
toString
Provide a String representation of this date/time converter.- Overrides:
toStringin classorg.apache.commons.beanutils.converters.AbstractConverter- Returns:
- A String representation of this date/time converter
-