in src/main/java/org/apache/sling/resourcemerger/impl/CRUDMergingResourceProvider.java [94:131]
public Resource create(final ResolveContext<Void> ctx, final String path, final Map<String, Object> properties) throws PersistenceException {
final ResourceResolver resolver = ctx.getResourceResolver();
// check if the resource exists
final Resource mountResource = this.getResource(ctx, path, ResourceContext.EMPTY_CONTEXT, null);
if ( mountResource != null ) {
throw new PersistenceException("Resource at " + path + " already exists.", null, path, null);
}
// creation 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 created.", 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() == 0
|| (holder.resources.size() < holder.count && !holder.resources.get(holder.resources.size() - 1).getPath().equals(holder.highestResourcePath) )) {
final String createPath = holder.highestResourcePath;
final Resource parentResource = ResourceUtil.getOrCreateResource(resolver, ResourceUtil.getParent(createPath), (String)null, null, false);
resolver.create(parentResource, ResourceUtil.getName(createPath), properties);
} else {
final Resource hidingResource = resolver.getResource(holder.highestResourcePath);
if ( hidingResource != null ) {
final ModifiableValueMap mvm = hidingResource.adaptTo(ModifiableValueMap.class);
if (mvm == null) {
throw new IllegalStateException("Could not get modifiable value map from resource " + hidingResource.getPath());
}
mvm.remove(MergedResourceConstants.PN_HIDE_RESOURCE);
mvm.putAll(properties);
}
// TODO check parent hiding
}
return this.getResource(ctx, path, ResourceContext.EMPTY_CONTEXT, null);
}