Class DateTimeFormatterTool
- java.lang.Object
-
- org.apache.turbine.services.pull.util.DateTimeFormatterTool
-
- All Implemented Interfaces:
DateTimeFormatterInterface
,ApplicationTool
public class DateTimeFormatterTool extends Object implements ApplicationTool, DateTimeFormatterInterface
This pull tool is used to formatTemporalAccessor
andmap(String, DateTimeFormatter, Locale)
(different falvors) objects into strings. The methods may throwUnsupportedTemporalTypeException
orDateTimeParseException
. if the source and the target format do not match appropriately.
-
-
Constructor Summary
Constructors Constructor Description DateTimeFormatterTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends TemporalAccessor>
Stringformat(T temporalAccessor)
Formats the given datetime as a String with the #DateTimeFormatterTool#defaultFormat
.<T extends TemporalAccessor>
Stringformat(T temporalAccessor, String dateFormatString)
Formats the given date as a String.<T extends TemporalAccessor>
Stringformat(T temporalAccessor, String dateFormatString, Locale locale)
Formats the given date as a String.String
getDateTimeFormatPattern()
DateTimeFormatter
getDefaultFormat()
DateTimeFormatterService
getDtfs()
void
init(Object data)
Initialize the application tool.String
map(String src, String outgoingFormatPattern, Locale locale, String incomingFormatPattern)
Maps from an incoming format to an outgoing formatDateTimeFormatter
.String
map(String src, DateTimeFormatter outgoingFormat, Locale locale)
String
map(String src, DateTimeFormatter outgoingFormat, Locale locale, DateTimeFormatter incomingFormat)
Uses as incoming format#defaultFormat
and no locale.String
mapFrom(String src, DateTimeFormatter incomingFormat)
Uses as incomingDateTimeFormatter
#defaultFormat
.String
mapTo(String src, DateTimeFormatter outgoingFormat)
Uses as outgoingDateTimeFormatter
#defaultFormat
and no locale.void
refresh()
Refresh the application tool.
-
-
-
Constructor Detail
-
DateTimeFormatterTool
public DateTimeFormatterTool()
-
-
Method Detail
-
init
public void init(Object data)
Initialize the application tool. The data parameter holds a different type depending on how the tool is being instantiated:- For global tools data will be null
- For request tools data will be of type RunData
- For session and persistent tools data will be of type User
#defaultFormat
from#dateTimeFormatPattern
with default LocaleLocale.getDefault()
and Default zone:ZoneId.systemDefault()
- Specified by:
init
in interfaceApplicationTool
- Parameters:
data
- initialization data
-
getDtfs
public DateTimeFormatterService getDtfs()
-
refresh
public void refresh()
Refresh the application tool. This is necessary for development work where you probably want the tool to refresh itself if it is using configuration information that is typically cached after initialization- Specified by:
refresh
in interfaceApplicationTool
-
getDefaultFormat
public DateTimeFormatter getDefaultFormat()
- Specified by:
getDefaultFormat
in interfaceDateTimeFormatterInterface
-
getDateTimeFormatPattern
public String getDateTimeFormatPattern()
- Specified by:
getDateTimeFormatPattern
in interfaceDateTimeFormatterInterface
-
format
public <T extends TemporalAccessor> String format(T temporalAccessor)
Formats the given datetime as a String with the #DateTimeFormatterTool#defaultFormat
. using the default date format.- Specified by:
format
in interfaceDateTimeFormatterInterface
- Parameters:
the
-to format
- Returns:
- String value of the date
-
format
public <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString)
Description copied from interface:DateTimeFormatterInterface
Formats the given date as a String.- Specified by:
format
in interfaceDateTimeFormatterInterface
dateFormatString
- format string to use. SeeDateTimeFormatter
for details.- Returns:
- String value of the date
-
format
public <T extends TemporalAccessor> String format(T temporalAccessor, String dateFormatString, Locale locale)
Description copied from interface:DateTimeFormatterInterface
Formats the given date as a String.- Specified by:
format
in interfaceDateTimeFormatterInterface
dateFormatString
- format string to use. SeeDateTimeFormatter
for details.- Returns:
- String value of the date
-
map
public String map(String src, String outgoingFormatPattern, Locale locale, String incomingFormatPattern)
Description copied from interface:DateTimeFormatterInterface
Maps from an incoming format to an outgoing formatDateTimeFormatter
.- Specified by:
map
in interfaceDateTimeFormatterInterface
- Parameters:
src
- the formatted datetimelocale
- Locale, if needed for outgoing formatting, no default.- Returns:
- the newly mapped
-
map
public String map(String src, DateTimeFormatter outgoingFormat, Locale locale, DateTimeFormatter incomingFormat)
Description copied from interface:DateTimeFormatterInterface
Uses as incoming format#defaultFormat
and no locale.- Specified by:
map
in interfaceDateTimeFormatterInterface
- Returns:
- the formatted string
-
mapTo
public String mapTo(String src, DateTimeFormatter outgoingFormat)
Description copied from interface:DateTimeFormatterInterface
Uses as outgoingDateTimeFormatter
#defaultFormat
and no locale.- Specified by:
mapTo
in interfaceDateTimeFormatterInterface
- Parameters:
src
- the datetime formatted string- Returns:
- the date time formatted using the
#defaultFormat
.
-
mapFrom
public String mapFrom(String src, DateTimeFormatter incomingFormat)
Description copied from interface:DateTimeFormatterInterface
Uses as incomingDateTimeFormatter
#defaultFormat
.- Specified by:
mapFrom
in interfaceDateTimeFormatterInterface
- Parameters:
src
- the datetime formatted string- Returns:
- the newly formatted date time string
-
map
public String map(String src, DateTimeFormatter outgoingFormat, Locale locale)
- Specified by:
map
in interfaceDateTimeFormatterInterface
-
-