...
The addPlaceholder
method supports two kind of placeholders:
annotations (as in example - the Language.class is an annotation) - the specified annotation must be
aa BindingAnnotation and must be used for providing a String value by some module. Each placeholder stored using this method will be resolved by replacing it by a value returned by a provider of a String annotated with the specified annotation.
In order to resolve thelanguage
placeholder in above paths, some module must provideString
annotated byLanguage
:Code Block @Provides @Language public String getLanguage() { String language; //some logic return language; }
- String - specifying a String which will replace the placeholder directly.
Post processors
Post processors are dedicated mechanism for modifying values of mapped fields. It is useful when there is a need for modification of a value already mapped from a resource, e.g. to do some low-level conversion or encoding. Currently, there's only one post processor shipped with Slice but you can implement yours in order to do some arbitrary modifications. Post processors do NOT modify resources - they only modify values mapped from a resource to a field.
EscapeValuePostProcessor
When mapping a text property to a String field all HTML entities are escaped by default. The com.cognifide.slice.mapper.impl.postprocessor.EscapeValuePostProcessor
modifies a text value to unescape HTML so that it can be properly displayed on a page. It should be used when a property represents a part of HTML markup, e.g. text saved by richtext component.
To use this post processor, a field must be annotated by com.cognifide.slice.mapper.annotation.Unescaped
annotation, e.g.
Code Block |
---|
@SliceResource
public class ExampleModel {
@JcrProperty
@Unescaped
private String text;
} |
InitializableModel
It's a common task to do some stuff after the model has been mapped and its fields hold values from underlying resource. You cannot do this in the constructor of your model because mapping is done after the object has been created, so all the fields which should be mapped are null
while executing constructor. Therefore, Slice introduces an interface called InitializableModel
which allows you to perform an arbitrary logic after the process of mapping has finished.
...