public abstract class TemplateNumberFormat extends TemplateValueFormat
NumberFormat
, but made to fit the requirements of FreeMarker. Also, it makes easier to define formats that
can't be represented with Java's existing NumberFormat
implementations.
Implementations need not be thread-safe if the TemplateNumberFormatFactory
doesn't recycle them among
different Environment
-s. As far as FreeMarker's concerned, instances are bound to a single
Environment
, and Environment
-s are thread-local objects.
Constructor and Description |
---|
TemplateNumberFormat() |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
format(TemplateNumberModel numberModel)
Formats the model to markup instead of to plain text if the result markup will be more than just plain text
escaped, otherwise falls back to formatting to plain text.
|
abstract java.lang.String |
formatToPlainText(TemplateNumberModel numberModel) |
abstract boolean |
isLocaleBound()
Tells if this formatter should be re-created if the locale changes.
|
java.lang.Object |
parse(java.lang.String s)
This method is reserved for future purposes; currently it always throws
ParsingNotSupportedException . |
getDescription
public abstract java.lang.String formatToPlainText(TemplateNumberModel numberModel) throws TemplateValueFormatException, TemplateModelException
numberModel
- The number to format; not null
. Most implementations will just work with the return value of
TemplateDateModel.getAsDate()
, but some may format differently depending on the properties of
a custom TemplateDateModel
implementation.null
.TemplateValueFormatException
- If any problem occurs while parsing/getting the format. Notable subclass:
UnformattableValueException
.TemplateModelException
- Exception thrown by the dateModel
object when calling its methods.public java.lang.Object format(TemplateNumberModel numberModel) throws TemplateValueFormatException, TemplateModelException
formatToPlainText(TemplateNumberModel)
escaped, it must return the String
that
formatToPlainText(TemplateNumberModel)
does.
The implementation in TemplateNumberFormat
simply calls formatToPlainText(TemplateNumberModel)
.
String
or a TemplateMarkupOutputModel
; not null
.TemplateValueFormatException
TemplateModelException
public abstract boolean isLocaleBound()
public final java.lang.Object parse(java.lang.String s) throws TemplateValueFormatException
ParsingNotSupportedException
. We
don't yet support number parsing with TemplateNumberFormat
-s, because currently FTL parses strings to
number with the ArithmeticEngine
(TemplateNumberFormat
were only introduced in 2.3.24). If it
will be support, it will be similar to TemplateDateFormat.parse(String, int)
.TemplateValueFormatException