Search in sources :

Example 6 with ResourceProvider

use of org.apache.sling.spi.resource.provider.ResourceProvider in project sling by apache.

the class ResourceResolverImplTest method setup.

@Before
public void setup() throws LoginException {
    ResourceProvider<?> rp = new ResourceProvider<Object>() {

        @Override
        public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext rCtx, Resource parent) {
            return null;
        }

        @Override
        public Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent) {
            return null;
        }
    };
    List<ResourceProviderHandler> handlers = asList(createRPHandler(rp, "rp1", 0, "/"));
    resourceProviderTracker = mock(ResourceProviderTracker.class);
    ResourceProviderStorage storage = new ResourceProviderStorage(handlers);
    when(resourceProviderTracker.getResourceProviderStorage()).thenReturn(storage);
    ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
    activator.resourceProviderTracker = resourceProviderTracker;
    activator.resourceAccessSecurityTracker = new ResourceAccessSecurityTracker();
    commonFactory = new CommonResourceResolverFactoryImpl(activator);
    final Bundle usingBundle = mock(Bundle.class);
    resFac = new ResourceResolverFactoryImpl(commonFactory, usingBundle, null);
    resResolver = resFac.getAdministrativeResourceResolver(null);
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) ResourceContext(org.apache.sling.spi.resource.provider.ResourceContext) ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) Bundle(org.osgi.framework.Bundle) ResourceProviderTracker(org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) ResourceProviderStorage(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage) ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) Before(org.junit.Before)

Example 7 with ResourceProvider

use of org.apache.sling.spi.resource.provider.ResourceProvider in project sling by apache.

the class ResourceDecoratorTestBase method setup.

@Before
public void setup() throws LoginException {
    final ResourceDecorator d = new ResourceDecorator() {

        @Override
        public Resource decorate(Resource resource) {
            return ResourceDecoratorTestBase.this.wrapResourceForTest(resource);
        }

        @Override
        public Resource decorate(Resource resource, HttpServletRequest request) {
            throw new UnsupportedOperationException("Not supposed to be used in these tests");
        }
    };
    final ResourceDecoratorTracker t = new ResourceDecoratorTracker();
    t.bindResourceDecorator(d, null);
    final ResourceProvider<?> provider = new ResourceProvider<Object>() {

        @Override
        public QueryLanguageProvider<Object> getQueryLanguageProvider() {
            return new QueryLanguageProvider<Object>() {

                @Override
                public String[] getSupportedLanguages(ResolveContext<Object> ctx) {
                    return new String[] { QUERY_LANGUAGE };
                }

                @Override
                public Iterator<Resource> findResources(ResolveContext<Object> ctx, String query, String language) {
                    final List<Resource> found = new ArrayList<Resource>();
                    found.add(mockResource("/tmp/C"));
                    found.add(mockResource("/tmp/D"));
                    found.add(mockResource("/var/one"));
                    found.add(mockResource("/var/two"));
                    return found.iterator();
                }

                @Override
                public Iterator<ValueMap> queryResources(ResolveContext<Object> ctx, String query, String language) {
                    return null;
                }
            };
        }

        @Override
        public Resource getResource(ResolveContext<Object> ctx, String path, final ResourceContext rCtx, Resource parent) {
            if (path.equals("/") || path.startsWith("/tmp") || path.startsWith("/var")) {
                return mockResource(path);
            }
            return null;
        }

        @Override
        public Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent) {
            final List<Resource> children = new ArrayList<Resource>();
            if ("/".equals(parent.getPath())) {
                children.add(mockResource("/tmp"));
                children.add(mockResource("/var"));
            } else if ("/var".equals(parent.getPath())) {
                children.add(mockResource("/var/one"));
                children.add(mockResource("/var/two"));
                children.add(mockResource("/var/three"));
            } else if ("/tmp".equals(parent.getPath())) {
                children.add(mockResource("/tmp/A"));
                children.add(mockResource("/tmp/B"));
                children.add(mockResource("/tmp/C"));
                children.add(mockResource("/tmp/D"));
            }
            return children.iterator();
        }
    };
    ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
    final CommonResourceResolverFactoryImpl crf = new CommonResourceResolverFactoryImpl(activator) {

        @Override
        public ResourceDecoratorTracker getResourceDecoratorTracker() {
            return t;
        }

        @Override
        public ResourceAccessSecurityTracker getResourceAccessSecurityTracker() {
            return new ResourceAccessSecurityTracker();
        }
    };
    final List<ResourceProviderHandler> list = Arrays.asList(MockedResourceResolverImplTest.createRPHandler(provider, "A-provider", 0L, "/"));
    resolver = new ResourceResolverImpl(crf, false, null, new ResourceProviderStorageProvider() {

        @Override
        public ResourceProviderStorage getResourceProviderStorage() {
            return new ResourceProviderStorage(list);
        }
    });
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) ResourceContext(org.apache.sling.spi.resource.provider.ResourceContext) ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) ValueMap(org.apache.sling.api.resource.ValueMap) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) ResourceProviderStorageProvider(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider) ResourceDecorator(org.apache.sling.api.resource.ResourceDecorator) HttpServletRequest(javax.servlet.http.HttpServletRequest) ResourceProviderStorage(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage) ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) ResourceDecoratorTracker(org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker) QueryLanguageProvider(org.apache.sling.spi.resource.provider.QueryLanguageProvider) Before(org.junit.Before)

Example 8 with ResourceProvider

use of org.apache.sling.spi.resource.provider.ResourceProvider in project sling by apache.

the class FsResourceProvider method getResource.

/**
     * Returns a resource wrapping a file system file or folder for the given
     * path. If the <code>path</code> is equal to the configured resource tree
     * location of this provider, the configured file system file or folder is
     * used for the resource. Otherwise the configured resource tree location
     * prefix is removed from the path and the remaining relative path is used
     * to access the file or folder. If no such file or folder exists, this
     * method returns <code>null</code>.
     */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Resource getResource(final ResolveContext<Object> ctx, final String path, final ResourceContext resourceContext, final Resource parent) {
    ResourceResolver resolver = ctx.getResourceResolver();
    boolean askParentResourceProvider;
    Resource rsrc = null;
    if (fsMode == FsMode.FILEVAULT_XML) {
        // filevault: check if path matches, if not fallback to parent resource provider
        if (fileVaultMapper.pathMatches(path)) {
            askParentResourceProvider = false;
            rsrc = fileVaultMapper.getResource(resolver, path);
        } else {
            askParentResourceProvider = true;
        }
    } else {
        // Sling-Initial-Content: mount folder/files an content files
        askParentResourceProvider = this.overlayParentResourceProvider;
        rsrc = fileMapper.getResource(resolver, path);
        if (rsrc == null) {
            rsrc = contentFileMapper.getResource(resolver, path);
        }
    }
    if (askParentResourceProvider) {
        // this allows properties like sling:resourceSuperType to take effect
        if (rsrc == null || rsrc.getResourceMetadata().containsKey(RESOURCE_METADATA_FILE_DIRECTORY)) {
            // get resource from shadowed provider
            final ResourceProvider rp = ctx.getParentResourceProvider();
            if (rp != null) {
                Resource resourceFromParentResourceProvider = rp.getResource((ResolveContext) ctx.getParentResolveContext(), path, resourceContext, parent);
                if (resourceFromParentResourceProvider != null) {
                    rsrc = resourceFromParentResourceProvider;
                }
            }
        }
    }
    return rsrc;
}
Also used : ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource)

Aggregations

ResourceProvider (org.apache.sling.spi.resource.provider.ResourceProvider)8 Resource (org.apache.sling.api.resource.Resource)4 ArrayList (java.util.ArrayList)3 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 ResourceProviderDTO (org.apache.sling.api.resource.runtime.dto.ResourceProviderDTO)2 ResourceProviderFailureDTO (org.apache.sling.api.resource.runtime.dto.ResourceProviderFailureDTO)2 RuntimeDTO (org.apache.sling.api.resource.runtime.dto.RuntimeDTO)2 ResourceProviderHandler (org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler)2 ResourceProviderStorage (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage)2 ResolveContext (org.apache.sling.spi.resource.provider.ResolveContext)2 ResourceContext (org.apache.sling.spi.resource.provider.ResourceContext)2 Before (org.junit.Before)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1