Class TemplateDateFormatFactory
- Direct Known Subclasses:
AliasTemplateDateFormatFactory
TemplateDateFormat
). Usually a singleton
(one-per-VM or one-per-Configuration
), and so must be thread-safe.- Since:
- 2.3.24
- See Also:
Configurable.setCustomDateFormats(java.util.Map)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract TemplateDateFormat
get(String params, int dateType, Locale locale, TimeZone timeZone, boolean zonelessInput, Environment env)
Returns a formatter for the given parameters.
-
Constructor Details
-
TemplateDateFormatFactory
public TemplateDateFormatFactory()
-
-
Method Details
-
get
public abstract TemplateDateFormat get(String params, int dateType, Locale locale, TimeZone timeZone, boolean zonelessInput, Environment env) throws TemplateValueFormatExceptionReturns a formatter for the given parameters.The returned formatter can be a new instance or a reused (cached) instance. Note that
Environment
itself caches the returned instances, though that cache is lost with theEnvironment
(i.e., when the top-level template execution ends), also it might flushes lot of entries if the locale or time zone is changed during template execution. So caching on the factory level is still useful, unless creating the formatters is sufficiently cheap.- Parameters:
params
- The string that further describes how the format should look. For example, when thedateFormat
is"@fooBar 1, 2"
, then it will be"1, 2"
(and"@fooBar"
selects the factory). The format of this string is up to theTemplateDateFormatFactory
implementation. Notnull
, often an empty string.dateType
-TemplateDateModel.DATE
,TemplateDateModel.TIME
,TemplateDateModel.DATETIME
orTemplateDateModel.UNKNOWN
. SupportingTemplateDateModel.UNKNOWN
is not necessary, in which case the method should throw anUnknownDateTypeFormattingUnsupportedException
exception.locale
- The locale to format for. Notnull
. The resulting format should be bound to this locale forever (i.e. locale changes in theEnvironment
must not be followed).timeZone
- The time zone to format for. Notnull
. The resulting format must be bound to this time zone forever (i.e. time zone changes in theEnvironment
must not be followed).zonelessInput
- Indicates that the input JavaDate
is not from a time zone aware source. When this istrue
, the formatters shouldn't override the time zone provided to its constructor (most formatters don't do that anyway), and it shouldn't show the time zone, if it can hide it (like aSimpleDateFormat
pattern-based formatter may can't do that, as the pattern prescribes what to show).As of FreeMarker 2.3.21, this is
true
exactly when the date is an SQL "date without time of the day" (i.e., ajava.sql.Date
) or an SQL "time of the day" value (i.e., ajava.sql.Time
, although this rule can change in future, depending on configuration settings and such, so you shouldn't rely on this rule, just accept what this parameter says.env
- The runtime environment from which the formatting was called. This is mostly meant to be used forEnvironment.setCustomState(Object, Object)
/Environment.getCustomState(Object)
.- Throws:
TemplateValueFormatException
- If any problem occurs while parsing/getting the format. Notable subclasses:InvalidFormatParametersException
ifparams
is malformed;UnknownDateTypeFormattingUnsupportedException
ifdateType
isTemplateDateModel.UNKNOWN
and that's unsupported by this factory.
-