FolderResource.java
2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.rest.utils.DeepModifiableValueMapDecorator
* org.apache.sling.api.resource.ModifiableValueMap
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
*/
package com.adobe.granite.rest.assets.impl;
import com.adobe.granite.rest.assets.impl.AbstractAssetResource;
import com.adobe.granite.rest.assets.impl.RenditionResource;
import com.adobe.granite.rest.utils.DeepModifiableValueMapDecorator;
import java.io.InputStream;
import java.util.Map;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
public class FolderResource
extends AbstractAssetResource {
public static final String RESOURCE_TYPE = "granite/rest/assets/folder";
private ValueMap valueMap;
public FolderResource(Resource resource, String path) {
ValueMap base;
super(resource, path);
Resource content = resource;
if (resource.getChild("jcr:content") != null) {
content = resource.getChild("jcr:content");
}
if ((base = (ValueMap)content.adaptTo(ModifiableValueMap.class)) == null) {
base = (ValueMap)content.adaptTo(ValueMap.class);
}
this.valueMap = new DeepModifiableValueMapDecorator(resource, (Map)base);
}
public String getResourceType() {
return "granite/rest/assets/folder";
}
public RenditionResource getThumbnail() {
ResourceResolver resolver = this.resource.getResourceResolver();
Resource thumbnail = resolver.getResource(this.resource, "jcr:content/folderThumbnail");
if (thumbnail != null) {
RenditionResource rendition = new RenditionResource(thumbnail, this.getPath() + "/folderThumbnail");
return rendition;
}
return null;
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
RenditionResource thumbnail;
if (type == ValueMap.class || type == ModifiableValueMap.class) {
return (AdapterType)this.valueMap;
}
if (type == InputStream.class && (thumbnail = this.getThumbnail()) != null) {
return (AdapterType)thumbnail.adaptTo(InputStream.class);
}
return (AdapterType)super.adaptTo(type);
}
}