Package freemarker.core
Class TemplateNumberFormat
- java.lang.Object
-
- freemarker.core.TemplateValueFormat
-
- freemarker.core.TemplateNumberFormat
-
public abstract class TemplateNumberFormat extends TemplateValueFormat
Represents a number format; used in templates for formatting and parsing with that format. This is similar to Java'sNumberFormat
, but made to fit the requirements of FreeMarker. Also, it makes easier to define formats that can't be represented with Java's existingNumberFormat
implementations.Implementations need not be thread-safe if the
TemplateNumberFormatFactory
doesn't recycle them among differentEnvironment
-s. As far as FreeMarker's concerned, instances are bound to a singleEnvironment
, andEnvironment
-s are thread-local objects.- Since:
- 2.3.24
-
-
Constructor Summary
Constructors Constructor Description TemplateNumberFormat()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 throwsParsingNotSupportedException
.-
Methods inherited from class freemarker.core.TemplateValueFormat
getDescription
-
-
-
-
Method Detail
-
formatToPlainText
public abstract java.lang.String formatToPlainText(TemplateNumberModel numberModel) throws TemplateValueFormatException, TemplateModelException
- Parameters:
numberModel
- The number to format; notnull
. Most implementations will just work with the return value ofTemplateDateModel.getAsDate()
, but some may format differently depending on the properties of a customTemplateDateModel
implementation.- Returns:
- The number as text, with no escaping (like no HTML escaping); can't be
null
. - Throws:
TemplateValueFormatException
- If any problem occurs while parsing/getting the format. Notable subclass:UnformattableValueException
.TemplateModelException
- Exception thrown by thedateModel
object when calling its methods.
-
format
public java.lang.Object format(TemplateNumberModel numberModel) throws TemplateValueFormatException, TemplateModelException
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. If the markup result would be just the result offormatToPlainText(TemplateNumberModel)
escaped, it must return theString
thatformatToPlainText(TemplateNumberModel)
does.The implementation in
TemplateNumberFormat
simply callsformatToPlainText(TemplateNumberModel)
.- Returns:
- A
String
or aTemplateMarkupOutputModel
; notnull
. - Throws:
TemplateValueFormatException
TemplateModelException
-
isLocaleBound
public abstract boolean isLocaleBound()
Tells if this formatter should be re-created if the locale changes.
-
parse
public final java.lang.Object parse(java.lang.String s) throws TemplateValueFormatException
This method is reserved for future purposes; currently it always throwsParsingNotSupportedException
. We don't yet support number parsing withTemplateNumberFormat
-s, because currently FTL parses strings to number with theArithmeticEngine
(TemplateNumberFormat
were only introduced in 2.3.24). If it will be support, it will be similar toTemplateDateFormat.parse(String, int)
.- Throws:
TemplateValueFormatException
-
-