AttachmentResource.java
1.88 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceMetadata
* 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 java.io.InputStream;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
public class AttachmentResource
extends AbstractAssetResource {
public static final String RESOURCE_TYPE = "granite/rest/assets/attachment";
private String mimeType;
public AttachmentResource(Resource resource, String path) {
super(resource, path);
Resource content = resource.getChild("jcr:content");
if (content == null) {
this.mimeType = "application/octet-stream";
} else {
if (content.getResourceMetadata() != null) {
this.resourceMetadata.setModificationTime(content.getResourceMetadata().getModificationTime());
}
ValueMap vm = (ValueMap)content.adaptTo(ValueMap.class);
this.mimeType = (String)vm.get("jcr:mimeType", String.class);
}
}
public String getMimeType() {
return this.mimeType;
}
public String getResourceType() {
return "granite/rest/assets/attachment";
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
Resource preview;
if (type == InputStream.class && (preview = this.getResourceResolver().getResource(this.resource, "preview.png")) != null) {
return (AdapterType)preview.adaptTo(InputStream.class);
}
return (AdapterType)super.adaptTo(type);
}
}