-
- All Known Subinterfaces:
VoidFormat
- All Known Implementing Classes:
CaseFormatter.Camelize
,CaseFormatter.FirstUpper
,CaseFormatter.Lower
,CaseFormatter.StringFormat
,CaseFormatter.Upper
,CropFormat
,DateFormatter.DateFormatWrapper
,DefaultFormat
,NullFormat
,NumFormatter.DecimalFormatWrapper
,NumFormatter.ToStringFormat
,PadFormat
,PropertyFormat
,SimpleFormat
,ToggleFormatter.ToggleFormat
,ValuesFormat
public interface Format
The format allows one to encapsulate and reuse portions of view logic in a simple and generic manner.Format definition in template file
Formats are activated by a single attribute, that's evaluated by aFormatFactory
, that parses this definition, found within the template file, in order to create an appropriateFormat
. However, before creating the format itself there is another step to take: The FormatFactory returns aFormatConfiguration
which takes additional parameters, called sub-attributes. Sub attributes have the form<main-attribute>.<sub-attribute>
and directly follow the main attribute. For instance:stretch="20" stretch.align="left"
FormatConfiguration
implementation:enum Alignment {left, right}; public void setAlign(Alignment value) {..
This mechanism provides support for numbers, boolean, enums, and strings. Alternatively, especially when the attributes are not known at build time, this can be done by implementingDynamicAttributes
instead. However, the separation of Format and FormatConfiguration is for advanced state handling and validation of the configuration. For most Formats extendingSimpleFormat
makes things much simpler by combining both.Binding data to formats at runtime
In order to bind data to a format at runtime you have to implementVoidFormat
and of course you've to take care for handling the state appropriately. Returning a new instance per call ofFormatConfiguration.getFormat(org.jproggy.snippetory.util.TemplateNode)
will do the job.- Author:
- B. Ebertz
- See Also:
- Official documentation on formats,
Extending the platform,
FormatFactory
,FormatConfiguration
,SimpleFormat
,VoidFormat
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clear(TemplateNode location)
Resets the state of the format to initialization value.Object
format(TemplateNode location, Object value)
Will only be called for supported values.static void
register(String name, FormatFactory value)
boolean
supports(Object value)
Many formats only apply to a special type or even specific values.
-
-
-
Method Detail
-
register
static void register(String name, FormatFactory value)
-
format
Object format(TemplateNode location, Object value)
Will only be called for supported values.- Parameters:
location
- gives some additional information to this call like the target encodingvalue
- will be turned into character data- Returns:
- value as character data. So either a String, a StringBuilder or EncodedData
-
supports
boolean supports(Object value)
Many formats only apply to a special type or even specific values. The format method will only be called for supported values
-
clear
void clear(TemplateNode location)
Resets the state of the format to initialization value. As most formats are state-less they can safely ignore this method.- Parameters:
location
- In some cases state is bound to specific nodes
-
-