RenditionImpl.java
2.42 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
67
68
69
70
71
72
73
74
75
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.asset.api.AssetIOException
* com.adobe.granite.asset.api.Rendition
* javax.jcr.Binary
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ResourceWrapper
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.asset.core.impl;
import com.adobe.granite.asset.api.AssetIOException;
import com.adobe.granite.asset.api.Rendition;
import java.io.InputStream;
import javax.jcr.Binary;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ResourceWrapper;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RenditionImpl
extends ResourceWrapper
implements Rendition {
private static final Logger log = LoggerFactory.getLogger(Rendition.class);
private final ValueMap contentProperties;
public RenditionImpl(Resource resource) {
super(resource);
Resource contentResource = resource.getResourceResolver().getResource(resource, "jcr:content");
this.contentProperties = ResourceUtil.getValueMap((Resource)contentResource);
}
public String getName() {
return ResourceUtil.getName((String)this.getPath());
}
public String getMimeType() {
return (String)this.contentProperties.get("jcr:mimeType", String.class);
}
public long getSize() {
boolean size = false;
Property p = (Property)this.contentProperties.get("jcr:data", Property.class);
try {
return null != p ? p.getBinary().getSize() : 0;
}
catch (RepositoryException e) {
log.error("Failed to get the Rendition binary size in bytes [{}]: ", (Object)this.getPath(), (Object)e);
return (long)size ? 1 : 0;
}
}
public InputStream getStream() {
try {
return (InputStream)this.contentProperties.get("jcr:data", InputStream.class);
}
catch (Throwable t) {
throw new AssetIOException(t);
}
}
}