Search in sources :

Example 16 with ResourceWrapper

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" }));
}
Also used : ResourceWrapper(org.apache.sling.api.resource.ResourceWrapper) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 17 with ResourceWrapper

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);
}
Also used : ResourceWrapper(org.apache.sling.api.resource.ResourceWrapper) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with ResourceWrapper

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;
}
Also used : ResourceWrapper(org.apache.sling.api.resource.ResourceWrapper) Resource(org.apache.sling.api.resource.Resource) ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata)

Example 19 with ResourceWrapper

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;
}
Also used : ResourceWrapper(org.apache.sling.api.resource.ResourceWrapper) Resource(org.apache.sling.api.resource.Resource) ResourceResolver(org.apache.sling.api.resource.ResourceResolver)

Aggregations

ResourceWrapper (org.apache.sling.api.resource.ResourceWrapper)19 Resource (org.apache.sling.api.resource.Resource)18 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 ResourceMetadata (org.apache.sling.api.resource.ResourceMetadata)1