Package freemarker.core
Class TemplateNumberFormatFactory
java.lang.Object
freemarker.core.TemplateValueFormatFactory
freemarker.core.TemplateNumberFormatFactory
- Direct Known Subclasses:
AliasTemplateNumberFormatFactory
Factory for a certain kind of number formatting (
TemplateNumberFormat
). Usually a singleton (one-per-VM or
one-per-Configuration
), and so must be thread-safe.- Since:
- 2.3.24
- See Also:
Configurable.setCustomNumberFormats(java.util.Map)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract TemplateNumberFormat
get(String params, Locale locale, Environment env)
Returns a formatter for the given parameters.
-
Constructor Details
-
TemplateNumberFormatFactory
public TemplateNumberFormatFactory()
-
-
Method Details
-
get
public abstract TemplateNumberFormat get(String params, Locale locale, 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 thenumberFormat
is"@fooBar 1, 2"
, then it will be"1, 2"
(and"@fooBar"
selects the factory). The format of this string is up to theTemplateNumberFormatFactory
implementation. Notnull
, often an empty string.locale
- The locale to format for. Notnull
. The resulting format must be bound to this locale forever (i.e. locale changes in theEnvironment
must not be followed).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
if theparams
is malformed.
-