in src/main/java/org/apache/sling/bundleresource/impl/BundleResourceProvider.java [100:161]
public Resource getResource(
final ResolveContext<Object> ctx,
final String resourcePath,
final ResourceContext resourceContext,
final Resource parent) {
final PathMapping mappedPath = getMappedPath(resourcePath);
if (mappedPath != null) {
final String entryPath = mappedPath.getEntryPath(resourcePath);
// first try, whether the bundle has an entry with a trailing slash
// which would be a folder. In this case we check whether the
// repository contains an item with the same path. If so, we
// don't create a BundleResource but instead return null to be
// able to return an item-based resource
URL entry = cache.getEntry(entryPath.concat("/"));
final boolean isFolder = entry != null;
// if there is no entry with a trailing slash, try plain name
// which would then of course be a file
if (entry == null) {
entry = cache.getEntry(entryPath);
if (entry == null && this.root.getJSONPropertiesExtension() != null) {
entry = cache.getEntry(entryPath + this.root.getJSONPropertiesExtension());
}
}
// here we either have a folder for which no same-named item exists
// or a bundle file
if (entry != null) {
// check if a JSON props file is directly requested
// if so, we deny the access
if (this.root.getJSONPropertiesExtension() == null
|| !entryPath.endsWith(this.root.getJSONPropertiesExtension())) {
return new BundleResource(
ctx.getResourceResolver(), cache, mappedPath, resourcePath, null, isFolder);
}
}
// the bundle does not contain the path
// if JSON is enabled check for any parent
if (this.root.getJSONPropertiesExtension() != null) {
String parentPath = ResourceUtil.getParent(resourcePath);
while (parentPath != null) {
final Resource rsrc = getResource(ctx, parentPath, resourceContext, null);
if (rsrc != null) {
final Resource childResource = ((BundleResource) rsrc)
.getChildResource(resourcePath.substring(parentPath.length() + 1));
if (childResource != null) {
return childResource;
}
}
parentPath = ResourceUtil.getParent(parentPath);
if (parentPath != null && this.getMappedPath(parentPath) == null) {
parentPath = null;
}
}
}
}
return null;
}