Search in sources :

Example 16 with ResourceMetadata

use of org.apache.sling.api.resource.ResourceMetadata 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 17 with ResourceMetadata

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

the class SuperimposingResourceProviderImplTest method prepareOriginalResource.

private void prepareOriginalResource(Resource mockResource, String path) {
    // prepare resource
    when(mockResource.getPath()).thenReturn(path);
    when(mockResource.getResourceType()).thenReturn(RESOURCE_TYPE);
    when(mockResource.getResourceSuperType()).thenReturn(null);
    ResourceMetadata resourceMetadata = new ResourceMetadata();
    resourceMetadata.setResolutionPath(path);
    when(mockResource.getResourceMetadata()).thenReturn(resourceMetadata);
    when(mockResource.getResourceResolver()).thenReturn(resourceResolver);
    // mount in resource tree
    when(resourceResolver.getResource(path)).thenReturn(mockResource);
}
Also used : ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata)

Example 18 with ResourceMetadata

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

the class ContentFileResource method getResourceMetadata.

public ResourceMetadata getResourceMetadata() {
    if (metaData == null) {
        metaData = new ResourceMetadata();
        metaData.setModificationTime(contentFile.getFile().lastModified());
        metaData.setResolutionPath(resourcePath);
    }
    return metaData;
}
Also used : ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata)

Example 19 with ResourceMetadata

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

the class FileResource method getResourceMetadata.

/**
     * Returns the resource meta data for this resource containing the file
     * length, last modification time and the resource path (same as
     * {@link #getPath()}).
     */
public ResourceMetadata getResourceMetadata() {
    if (metaData == null) {
        metaData = new ResourceMetadata();
        metaData.setContentLength(file.length());
        metaData.setModificationTime(file.lastModified());
        metaData.setResolutionPath(resourcePath);
        if (this.file.isDirectory()) {
            metaData.put(FsResourceProvider.RESOURCE_METADATA_FILE_DIRECTORY, Boolean.TRUE);
        }
    }
    return metaData;
}
Also used : ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata)

Example 20 with ResourceMetadata

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

the class MockedResourceResolverImplTest method buildResource.

/**
     * Build a resource with path, children and resource resolver.
     * @param fullpath
     * @param children
     * @param resourceResolver
     * @return
     */
@SuppressWarnings("unchecked")
private Resource buildResource(String fullpath, Iterable<Resource> children, ResourceResolver resourceResolver, ResourceProvider<?> provider, String... properties) {
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(resource.getName()).thenReturn(getName(fullpath));
    Mockito.when(resource.getPath()).thenReturn(fullpath);
    ResourceMetadata resourceMetadata = new ResourceMetadata();
    Mockito.when(resource.getResourceMetadata()).thenReturn(resourceMetadata);
    Mockito.when(resource.listChildren()).thenReturn(children.iterator());
    Mockito.when(resource.getResourceResolver()).thenReturn(resourceResolver);
    // register the resource with the provider
    if (provider != null) {
        Mockito.when(provider.listChildren(Mockito.any(ResolveContext.class), Mockito.eq(resource))).thenReturn(children.iterator());
        Mockito.when(provider.getResource(Mockito.any(ResolveContext.class), Mockito.eq(fullpath), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(resource);
    }
    if (properties != null) {
        ValueMap vm = new SimpleValueMapImpl();
        for (int i = 0; i < properties.length; i += 2) {
            resourceMetadata.put(properties[i], properties[i + 1]);
            vm.put(properties[i], properties[i + 1]);
        }
        Mockito.when(resource.getValueMap()).thenReturn(vm);
        Mockito.when(resource.adaptTo(Mockito.eq(ValueMap.class))).thenReturn(vm);
    } else {
        Mockito.when(resource.getValueMap()).thenReturn(ValueMapDecorator.EMPTY);
        Mockito.when(resource.adaptTo(Mockito.eq(ValueMap.class))).thenReturn(ValueMapDecorator.EMPTY);
    }
    return resource;
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) ResourceContext(org.apache.sling.spi.resource.provider.ResourceContext) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata)

Aggregations

ResourceMetadata (org.apache.sling.api.resource.ResourceMetadata)31 Resource (org.apache.sling.api.resource.Resource)15 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)7 Test (org.junit.Test)6 AbstractResourceImpl (com.adobe.acs.commons.mcp.impl.AbstractResourceImpl)5 ValueMap (org.apache.sling.api.resource.ValueMap)5 InputStream (java.io.InputStream)4 ValueMapResource (com.adobe.granite.ui.components.ds.ValueMapResource)3 HashMap (java.util.HashMap)3 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)3 BufferedInputStream (java.io.BufferedInputStream)2 ArrayList (java.util.ArrayList)2 Session (javax.jcr.Session)2 AccessControlManager (javax.jcr.security.AccessControlManager)2 Privilege (javax.jcr.security.Privilege)2 SlingException (org.apache.sling.api.SlingException)2 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)2 ScriptingResourceResolverProvider (org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider)2 SourceIdentifier (org.apache.sling.scripting.sightly.impl.engine.compiled.SourceIdentifier)2 ResolveContext (org.apache.sling.spi.resource.provider.ResolveContext)2