Search in sources :

Example 6 with ContextResource

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

the class ContextPathStrategyMultiplexerImplTest method registerContextPathStrategy.

private void registerContextPathStrategy(String... paths) {
    final List<Resource> resources = new ArrayList<>();
    for (String path : paths) {
        Resource resource = context.resourceResolver().getResource(path);
        if (resource != null) {
            resources.add(resource);
        }
    }
    context.registerService(ContextPathStrategy.class, new ContextPathStrategy() {

        @Override
        public Iterator<ContextResource> findContextResources(Resource resource) {
            return toContextResourceIterator(resources.iterator());
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) ContextResource(org.apache.sling.caconfig.resource.spi.ContextResource) ContextResourceTestUtil.toContextResourceIterator(org.apache.sling.caconfig.resource.impl.util.ContextResourceTestUtil.toContextResourceIterator) Iterator(java.util.Iterator) ContextResourceTestUtil.toResourceIterator(org.apache.sling.caconfig.resource.impl.util.ContextResourceTestUtil.toResourceIterator) DefaultContextPathStrategy(org.apache.sling.caconfig.resource.impl.def.DefaultContextPathStrategy) ContextPathStrategy(org.apache.sling.caconfig.resource.spi.ContextPathStrategy)

Aggregations

ContextResource (org.apache.sling.caconfig.resource.spi.ContextResource)6 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4 Resource (org.apache.sling.api.resource.Resource)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Predicate (org.apache.commons.collections.Predicate)1 ArrayIterator (org.apache.commons.collections.iterators.ArrayIterator)1 FilterIterator (org.apache.commons.collections.iterators.FilterIterator)1 ConfigurationData (org.apache.sling.caconfig.management.ConfigurationData)1 DefaultContextPathStrategy (org.apache.sling.caconfig.resource.impl.def.DefaultContextPathStrategy)1 ContextResourceTestUtil.toContextResourceIterator (org.apache.sling.caconfig.resource.impl.util.ContextResourceTestUtil.toContextResourceIterator)1 ContextResourceTestUtil.toResourceIterator (org.apache.sling.caconfig.resource.impl.util.ContextResourceTestUtil.toResourceIterator)1 PathEliminateDuplicatesIterator (org.apache.sling.caconfig.resource.impl.util.PathEliminateDuplicatesIterator)1 PathParentExpandIterator (org.apache.sling.caconfig.resource.impl.util.PathParentExpandIterator)1 ContextPathStrategy (org.apache.sling.caconfig.resource.spi.ContextPathStrategy)1