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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations