in src/main/java/org/apache/sling/resourcebuilder/impl/ResourceBuilderImpl.java [170:188]
protected final Resource ensureResourceExists(String path) {
if (path == null || path.length() == 0 || path.equals("/")) {
return resourceResolver.getResource("/");
}
Resource resource = resourceResolver.getResource(path);
if (resource != null) {
return resource;
}
String parentPath = ResourceUtil.getParent(path);
String name = ResourceUtil.getName(path);
Resource parentResource = ensureResourceExists(parentPath);
try {
resource = resourceResolver.create(
parentResource, name, MapArgsConverter.toMap(JCR_PRIMARYTYPE, intermediatePrimaryType));
return resource;
} catch (PersistenceException ex) {
throw new RuntimeException("Unable to create intermediate resource at " + path, ex);
}
}