public List pickResources()

in src/main/java/org/apache/sling/resourcemerger/impl/picker/ResourceTypeHierarchyBasedResourcePicker.java [56:101]


    public List<Resource> pickResources(ResourceResolver resolver, String relativePath, Resource relatedResource) {
        // TODO this method can be optimised by leveraging relatedResource (similar to MergingResourcePicker)

        String absPath = "/" + relativePath;
        final List<Resource> resources = new ArrayList<Resource>();
        final Set<String> roots = new HashSet<String>();

        Resource currentTarget = resolver.getResource(absPath);

        if (currentTarget == null) {
            currentTarget = new StubResource(resolver, absPath);
        }

        resources.add(currentTarget);

        while (currentTarget != null) {
            final InheritanceRootInfo info = new InheritanceRootInfo();
            findInheritanceRoot(currentTarget, info);
            if (info.resource == null) {
                currentTarget = null;
            } else {
                final Resource inheritanceRootResource = info.resource;
                final String pathRelativeToInheritanceRoot = info.getPathRelativeToInheritanceRoot();
                final String superType = inheritanceRootResource.getResourceSuperType();

                if (superType == null
                       || roots.contains(inheritanceRootResource.getPath())) { // avoid inheritance loops
                    currentTarget = null;
                } else {
                    final String superTypeChildPath = superType + pathRelativeToInheritanceRoot;
                    final Resource superTypeResource = resolver.getResource(superTypeChildPath);
                    if (superTypeResource != null) {
                        currentTarget = superTypeResource;
                    } else {
                        currentTarget = new StubResource(resolver, superTypeChildPath);
                    }
                    resources.add(currentTarget);
                    roots.add(inheritanceRootResource.getPath());
                }
            }
        }

        Collections.reverse(resources);

        return resources;
    }