in src/main/java/org/apache/sling/resourcemerger/impl/CRUDMergingResourceProvider.java [134:161]
public void delete(final ResolveContext<Void> ctx, final Resource resource) throws PersistenceException {
final ResourceResolver resolver = ctx.getResourceResolver();
final String path = resource.getPath();
// deleting of the root mount resource is not supported
final String relativePath = getRelativePath(path);
if ( relativePath == null || relativePath.length() == 0 ) {
throw new PersistenceException("Resource at " + path + " can't be deleted.", null, path, null);
}
final ExtendedResourceHolder holder = this.getAllResources(resolver, path, relativePath);
// we only support modifications if there is more than one location merged
if ( holder.count < 2 ) {
throw new PersistenceException("Modifying is only supported with at least two potentially merged resources.", null, path, null);
}
if ( holder.resources.size() == 1 && holder.resources.get(0).getPath().equals(holder.highestResourcePath) ) {
// delete the only resource which is the highest one
resolver.delete(holder.resources.get(0));
} else {
// create overlay resource which is hiding the other
final String createPath = holder.highestResourcePath;
final Resource parentResource = ResourceUtil.getOrCreateResource(resolver, ResourceUtil.getParent(createPath), (String)null, null, false);
final Map<String, Object> properties = new HashMap<>();
properties.put(MergedResourceConstants.PN_HIDE_RESOURCE, Boolean.TRUE);
resolver.create(parentResource, ResourceUtil.getName(createPath), properties);
}
}