Service to wrap resources
Introduction
The Sling API provides an easy way to wrap or decorate a resource before returning. Use cases for this could for example be
- overwrite resource type/resource super type (for example based on the resource path)
- add metadata
To add a resource decorator just register one or more services which implement the interface ResourceDecorator
interface ResourceDecorator {
Resource decorate(Resource)
@Deprecated
Resource decorate(Resource, HttpServletRequest)
}
The registered decorators will be called from the resource resolver for each resource returned.
If the service decorates the resource it should return the new resource. If the service does not want to decorate the resource, it should return the original resource or null.
The two-argument {{
}} method will not be invoked, starting with version 2.1.0 of the JCR Resource bundle. Implementors of this interface targeting both newer and older versions of this bundle are advised to implement this method with:
public Resource decorate(Resource resource, HttpServletRequest request) {
return this.decorate(resource);
}
And use some other method (e.g. a {{
}}) to obtain the current request if necessary.