This is an old version of the Sling website, see the site conversion page for more info.
Apache
Apache Sling Website > Apache Sling > Documentation > The Sling Engine > Wrap or Decorate Resources

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

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 {{

Unknown macro: {decorate}

}} 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 {{

Unknown macro: {ThreadLocal}

}}) to obtain the current request if necessary.

Last modified by justinedelson on 2012-02-16 18:23:21.0
Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.