Search in sources :

Example 1 with ParametrizableResourceProvider

use of org.apache.sling.api.resource.ParametrizableResourceProvider in project sling by apache.

the class LegacyResourceProviderAdapter method getResource.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) {
    Resource resourceCandidate;
    if (rp instanceof ParametrizableResourceProvider) {
        resourceCandidate = ((ParametrizableResourceProvider) rp).getResource(ctx.getResourceResolver(), path, resourceContext.getResolveParameters());
    } else {
        resourceCandidate = rp.getResource(ctx.getResourceResolver(), path);
    }
    ResourceProvider<?> parentProvider = ctx.getParentResourceProvider();
    ResolveContext parentCtx = ctx.getParentResolveContext();
    // Ask the parent provider
    if (resourceCandidate == null && !ownsRoot && parentProvider != null) {
        return parentProvider.getResource(parentCtx, path, resourceContext, parent);
    }
    // Support the INTERNAL_CONTINUE_RESOLVING flag
    Resource fallbackResource = resourceCandidate;
    if (resourceCandidate != null && parentProvider != null && isContinueResolving(resourceCandidate)) {
        resourceCandidate = ctx.getParentResourceProvider().getResource(parentCtx, path, resourceContext, parent);
    }
    if (resourceCandidate != null) {
        return resourceCandidate;
    } else {
        return fallbackResource;
    }
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) Resource(org.apache.sling.api.resource.Resource) ParametrizableResourceProvider(org.apache.sling.api.resource.ParametrizableResourceProvider)

Aggregations

ParametrizableResourceProvider (org.apache.sling.api.resource.ParametrizableResourceProvider)1 Resource (org.apache.sling.api.resource.Resource)1 ResolveContext (org.apache.sling.spi.resource.provider.ResolveContext)1