initial commit of resource grafting bundle
12 files changed
tree: 923d9882745c7a111e9777bd3ec265806cc96a97
  1. src/
  2. .asf.yaml
  3. .gitignore
  4. CODE_OF_CONDUCT.md
  5. CONTRIBUTING.md
  6. Jenkinsfile
  7. LICENSE
  8. pom.xml
  9. README.md
README.md

Build Status License

Apache Sling Resource Graft

This module is part of the Apache Sling project.

Grafting

Grafting or graftage is a horticultural technique whereby tissues of plants are joined so as to continue their growth together. The upper part of the combined plant is called the scion while the lower part is called the rootstock.

Source: https://en.wikipedia.org/wiki/Grafting

Description

This bundle contains utilities for grafting resource trees (scions) onto existing resources (rootstocks). It is intended to be used with Sling's ResourecDecorator API.

Example

@Component
public class ExampleResourceDecorator implements ResourceDecorator {

    public Resource decorate(final Resource rootstock) {
        GraftedResource scion = GraftedResource.graftOnto(rootstock);
        scion.appendChild("foo") // see also appendChild() and insertBefore()
            .setProperty("bar", this is foo")
        .parent() // navigate back from "foo" to scion
        .setProperty("virtual-property", "I'm not persisted') 
        .removeProperty("existing") // hide existing property
        .removeChild("subtree"); // remove a complete subtree

        return scion;
    }
    ...    
}