use of org.apache.sling.api.resource.Resource in project sling by apache.
the class MockedResourceResolverImplTest method testGetResource.
/**
* Test getResource for a resource provided by a resource provider.
* @throws LoginException
*/
@Test
public void testGetResource() throws LoginException {
ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(null);
Assert.assertNotNull(resourceResolver);
Resource singleResource = buildResource("/single/test", EMPTY_RESOURCE_LIST, resourceResolver, resourceProvider);
Resource resource = resourceResolver.getResource("/single/test");
Assert.assertEquals(singleResource, resource);
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class MockedResourceResolverImplTest method testResourceResolverGetChildren.
/**
* Tests listing children via the resource resolver getChildren call.
* @throws LoginException
*/
@Test
public void testResourceResolverGetChildren() throws LoginException {
ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(null);
buildResource("/single/test/withchildren", buildChildResources("/single/test/withchildren"), resourceResolver, resourceProvider);
Resource resource = resourceResolver.getResource("/single/test/withchildren");
Assert.assertNotNull(resource);
// test via the resource list children itself, this really just tests this test case.
Iterable<Resource> resourceIterator = resourceResolver.getChildren(resource);
Assert.assertNotNull(resourceResolver);
int i = 0;
for (Resource r : resourceIterator) {
Assert.assertEquals("m" + i, r.getName());
i++;
}
Assert.assertEquals(5, i);
}
use of org.apache.sling.api.resource.Resource 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;
}
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceResolverImpl method copy.
@Override
public Resource copy(final String srcAbsPath, final String destAbsPath) throws PersistenceException {
Resource rsrc = this.control.copy(this.context, srcAbsPath, destAbsPath);
if (rsrc != null) {
rsrc.getResourceMetadata().setResolutionPath(rsrc.getPath());
rsrc = this.factory.getResourceDecoratorTracker().decorate(rsrc);
}
return rsrc;
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceResolverImpl method getAbsoluteResourceInternal.
/**
* Creates a resource with the given path if existing
*/
private Resource getAbsoluteResourceInternal(@CheckForNull final Resource parent, @CheckForNull final String path, final Map<String, String> parameters, final boolean isResolve) {
if (path == null || path.length() == 0 || path.charAt(0) != '/') {
logger.debug("getResourceInternal: Path must be absolute {}", path);
// path must be absolute
return null;
}
final Resource parentToUse;
if (parent != null && path.startsWith(parent.getPath())) {
parentToUse = parent;
} else {
parentToUse = null;
}
final Resource resource = this.control.getResource(this.context, path, parentToUse, parameters, isResolve);
if (resource != null) {
resource.getResourceMetadata().setResolutionPath(path);
resource.getResourceMetadata().setParameterMap(parameters);
return resource;
}
logger.debug("getResourceInternal: Cannot resolve path '{}' to a resource", path);
return null;
}
Aggregations