use of org.apache.sling.resourcemerger.impl.MergedResource in project sling by apache.
the class MergingResourcePicker method pickResources.
@Override
public List<Resource> pickResources(final ResourceResolver resolver, final String relativePath, final Resource relatedResource) {
List<Resource> relatedMappedResources = null;
if (relatedResource instanceof MergedResource) {
relatedMappedResources = ((MergedResource) relatedResource).getMappedResources();
// Check if the path is the same
if (relatedResource.getPath().equals(mergeRootPath + '/' + relativePath)) {
return relatedMappedResources;
}
}
final List<Resource> resources = new ArrayList<Resource>();
final String[] searchPaths = resolver.getSearchPath();
for (int i = searchPaths.length - 1; i >= 0; i--) {
final String basePath = searchPaths[i];
final String fullPath = basePath + relativePath;
int baseIndex = resources.size();
Resource baseResource = null;
if (relatedMappedResources != null && relatedMappedResources.size() > baseIndex) {
baseResource = relatedMappedResources.get(baseIndex);
}
Resource resource = (baseResource != null) ? getFromBaseResource(resolver, baseResource, fullPath) : null;
if (resource == null) {
resource = resolver.getResource(fullPath);
if (resource == null) {
resource = new NonExistingResource(resolver, fullPath);
}
}
resources.add(resource);
}
return resources;
}
Aggregations