use of org.apache.sling.api.resource.ResourceWrapper in project sling by apache.
the class ProcessorConfigurationImplTest method testMatchAtLeastOneResourceTypeWithResourceWrapper_UnwrapDisabled.
@Test
public void testMatchAtLeastOneResourceTypeWithResourceWrapper_UnwrapDisabled() {
Resource resource = context.create().resource("/content/test", ImmutableMap.<String, Object>of("sling:resourceType", "type/1"));
// overwrite resource type via ResourceWrapper
Resource resourceWrapper = new ResourceWrapper(resource) {
@Override
public String getResourceType() {
return "/type/override/1";
}
};
context.currentResource(resourceWrapper);
assertNoMatch(ImmutableMap.<String, Object>of(PROPERTY_RESOURCE_TYPES, new String[] { "type/1", "type/2" }));
}
use of org.apache.sling.api.resource.ResourceWrapper in project sling by apache.
the class ResourceResolverWrapperTest method testGetChildren.
@Test
public void testGetChildren() throws Exception {
final Resource parent = mock(Resource.class);
final List<Resource> children = new ArrayList<>(1);
final Resource child = mock(Resource.class);
when(child.getPath()).thenReturn(PATH);
children.add(child);
when(wrappedResolver.getChildren(parent)).thenReturn(children);
int index = 0;
Iterable<Resource> iterable = underTest.getChildren(parent);
for (Resource result : iterable) {
assertTrue(result instanceof ResourceWrapper);
assertEquals(PATH, result.getPath());
index++;
}
assertEquals(1, index);
verify(wrappedResolver).getChildren(parent);
}
use of org.apache.sling.api.resource.ResourceWrapper in project sling by apache.
the class ResourceProviderBasedResourceDecorator method getResourceEditorResourceWrapper.
private Resource getResourceEditorResourceWrapper(Resource resource, String resolutionPathInfo) {
Resource result = null;
ResourceMetadata resourceMetadata = resource.getResourceMetadata();
boolean isResourceEditorProviderResource = resourceMetadata != null ? resourceMetadata.containsKey(ResEditorResourceProvider.RESOURCE_EDITOR_PROVIDER_RESOURCE) : false;
boolean isHTMLResource = resolutionPathInfo != null && resolutionPathInfo.endsWith("html");
boolean isJSONResource = resolutionPathInfo != null && resolutionPathInfo.endsWith("json");
if ((isHTMLResource || isJSONResource) && isResourceEditorProviderResource) {
result = new ResourceWrapper(resource) {
@Override
public String getResourceType() {
return ResEditorResourceProvider.RESEDITOR_RESOURCE_TYPE;
}
};
}
return result;
}
use of org.apache.sling.api.resource.ResourceWrapper in project sling by apache.
the class SuperimposingResourceProviderImpl method listChildren.
/**
* {@inheritDoc}
*/
public Iterator<Resource> listChildren(Resource resource) {
// unwrap resource if it is a wrapped resource
final Resource currentResource;
if (resource instanceof ResourceWrapper) {
currentResource = ((ResourceWrapper) resource).getResource();
} else {
currentResource = resource;
}
// delegate resource listing to resource resolver
if (currentResource instanceof SuperimposingResource) {
final SuperimposingResource res = (SuperimposingResource) currentResource;
final ResourceResolver resolver = res.getResource().getResourceResolver();
final Iterator<Resource> children = resolver.listChildren(res.getResource());
return new SuperimposingResourceIterator(this, children);
}
return null;
}
Aggregations