...
It is especially useful for development of complex components, composed of another components - you can then easily reuse models of your simple components. Picture below presents an example:
SliceReferenceProcessor
It processes fields which are annotated with com.cognifide.slice.mapper.annotation.SliceReference
. It allows for mapping of models from a different resource (path) than a current resource
The @SliceReference
annotation takes a path as a value. The value can be either an absolute path (like /content/test/home/jcr:content/par
) or child path (like childResource/grandChildResource
) - then it will be resolved relatively to current resource. Bear in mind that parent resources (like ../../test
) are not supported.
The value of a path can contain placeholders in form of: ${placeholderName}
. This can be useful when the path is dynamic and changes depending on request, e.g. contains language. Instead of hardcoding the language in the path (like: /content/site/en/home
), you can put placeholder and have this path to be dynamically evaluated, e.g. /content/site/${language}/home
.
The placeholders are resolved using com.cognifide.slice.mapper.api.SliceReferencePathResolver
. It's an interface shipped with default implementation. Since it is intended to store a configuration of your placeholders, you must specify these placeholders. It can be done by some of your module providing the SliceReferencePathResolver object which have all placeholders added using its addReference
methods. A simple snippet of code which provides the object can look like this:
Code Block | ||
---|---|---|
| ||
@Provides
@ContextScope
public SliceReferencePathResolver getSliceReferencePathResolver(Injector injector) {
SliceReferencePathResolver resolver = SliceReferencePathResolverFactory.createResolver(injector);
resolver.addPlaceholder("language", Language.class);
return resolver;
} |
The addPlaceholder
method supports two kind of placeholders:
- annotations (as in example - the Language.class is an annotation) - the specified annotation must be a
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. - String - specifying a String which will replace the placeholder directly.
Post processors
InitializableModel
...