Search in sources :

Example 1 with CollectionInheritanceDecider

use of org.apache.sling.caconfig.resource.spi.CollectionInheritanceDecider in project sling by apache.

the class DefaultConfigurationResourceResolvingStrategy method getResourceCollectionInternal.

private Collection<Resource> getResourceCollectionInternal(final Collection<String> bucketNames, final String configName, Iterator<String> paths, ResourceResolver resourceResolver) {
    final Map<String, Resource> result = new LinkedHashMap<>();
    final List<CollectionInheritanceDecider> deciders = this.collectionInheritanceDeciders;
    final Set<String> blockedItems = new HashSet<>();
    boolean inherit = false;
    while (paths.hasNext()) {
        final String path = paths.next();
        Resource item = null;
        String bucketNameUsed = null;
        for (String bucketName : bucketNames) {
            String name = bucketName + "/" + configName;
            String configPath = buildResourcePath(path, name);
            item = resourceResolver.getResource(configPath);
            if (item != null) {
                bucketNameUsed = bucketName;
                break;
            } else {
                log.trace("- No collection parent resource found: {}", configPath);
            }
        }
        if (item != null) {
            log.trace("o Check children of collection parent resource: {}", item.getPath());
            if (item.hasChildren()) {
                for (Resource child : item.getChildren()) {
                    if (isValidResourceCollectionItem(child) && !result.containsKey(child.getName()) && include(deciders, bucketNameUsed, child, blockedItems)) {
                        log.trace("+ Found collection resource item {}", child.getPath());
                        result.put(child.getName(), child);
                    }
                }
            }
            // check collection inheritance mode on current level - should we check on next-highest level as well?
            final ValueMap valueMap = item.getValueMap();
            inherit = PropertyUtil.getBooleanValueAdditionalKeys(valueMap, PROPERTY_CONFIG_COLLECTION_INHERIT, config.configCollectionInheritancePropertyNames());
            if (!inherit) {
                break;
            }
        }
    }
    return result.values();
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) ContextResource(org.apache.sling.caconfig.resource.spi.ContextResource) LinkedHashMap(java.util.LinkedHashMap) CollectionInheritanceDecider(org.apache.sling.caconfig.resource.spi.CollectionInheritanceDecider) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Resource (org.apache.sling.api.resource.Resource)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 CollectionInheritanceDecider (org.apache.sling.caconfig.resource.spi.CollectionInheritanceDecider)1 ContextResource (org.apache.sling.caconfig.resource.spi.ContextResource)1