DefaultRenditionHandler.java
3 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
76
77
78
79
80
81
82
83
84
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.asset.api.AssetException
* com.adobe.granite.asset.api.Rendition
* com.adobe.granite.asset.api.RenditionHandler
* javax.jcr.Binary
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.ValueFactory
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
*/
package com.adobe.granite.asset.core.impl;
import com.adobe.granite.asset.api.AssetException;
import com.adobe.granite.asset.api.Rendition;
import com.adobe.granite.asset.api.RenditionHandler;
import com.adobe.granite.asset.core.impl.RenditionImpl;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Map;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.ValueFactory;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(metatype=0, immediate=1)
@Properties(value={@Property(name="service.description", value={"Default JCR RenditionHandler"}), @Property(name="rendition.handler.id", value={"jcr.default"})})
@Service
public class DefaultRenditionHandler
implements RenditionHandler {
public static final String ID = "jcr.default";
public Rendition getRendition(Resource resource) {
return new RenditionImpl(resource);
}
public Rendition setRendition(Resource resource, InputStream is, Map<String, Object> map) {
if (is == null) {
throw new AssetException("DefaultRenditionHandler cannot create rendition without binary stream");
}
String mimeType = (String)map.get("rendition.mime");
try {
Node content = ((Node)resource.adaptTo(Node.class)).getNode("jcr:content");
this.setRenditionContent(content, is, mimeType);
return this.getRendition(resource);
}
catch (RepositoryException e) {
throw new AssetException((Throwable)e);
}
}
public void deleteRendition(Resource resource) {
try {
((Node)resource.adaptTo(Node.class)).remove();
}
catch (RepositoryException e) {
throw new AssetException((Throwable)e);
}
}
private void setRenditionContent(Node content, InputStream is, String mimeType) throws RepositoryException {
content.setProperty("jcr:mimeType", mimeType);
content.setProperty("jcr:data", content.getSession().getValueFactory().createBinary(is));
content.setProperty("jcr:lastModified", Calendar.getInstance());
}
}