Search in sources :

Example 1 with MergedResource

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;
}
Also used : NonExistingResource(org.apache.sling.api.resource.NonExistingResource) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) MergedResource(org.apache.sling.resourcemerger.impl.MergedResource) ArrayList(java.util.ArrayList) MergedResource(org.apache.sling.resourcemerger.impl.MergedResource)

Aggregations

ArrayList (java.util.ArrayList)1 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)1 Resource (org.apache.sling.api.resource.Resource)1 MergedResource (org.apache.sling.resourcemerger.impl.MergedResource)1