Scene7RenditionHandler.java
4.13 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* 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.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.commons.lang.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
*/
package com.day.cq.dam.scene7.impl.rendition;
import com.adobe.granite.asset.api.AssetException;
import com.adobe.granite.asset.api.Rendition;
import com.adobe.granite.asset.api.RenditionHandler;
import com.day.cq.dam.scene7.api.S7ConfigResolver;
import com.day.cq.dam.scene7.api.Scene7APIClient;
import com.day.cq.dam.scene7.impl.rendition.Scene7Rendition;
import java.io.InputStream;
import java.util.Map;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import org.apache.commons.lang.StringUtils;
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.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
@Component(immediate=1)
@Properties(value={@Property(name="service.description", value={"Scene7 Proxy RenditionHandler"}), @Property(name="rendition.handler.id", value={"scene7"})})
@Service
public class Scene7RenditionHandler
implements RenditionHandler {
public static final String ID = "scene7";
@Reference
private Scene7APIClient client;
@Reference
private S7ConfigResolver s7ConfigResolver;
public Rendition getRendition(Resource resource) {
return new Scene7Rendition(resource, this.client, this.s7ConfigResolver);
}
public Rendition setRendition(Resource resource, InputStream inputStream, Map<String, Object> renditionConfig) {
String handlerId = this.getRenditionHandlerId(renditionConfig);
if (StringUtils.isBlank((String)handlerId) || !handlerId.equals("scene7")) {
throw new IllegalArgumentException("Unsupported rendition handler id set in configuration for this handler");
}
try {
Node renditionNode = (Node)resource.adaptTo(Node.class);
if (renditionNode != null) {
Node content = renditionNode.getNode("jcr:content");
this.setProxyRenditionContent(content, renditionConfig);
}
return this.getRendition(resource);
}
catch (RepositoryException e) {
throw new AssetException((Throwable)e);
}
}
public void deleteRendition(Resource resource) {
throw new UnsupportedOperationException("deletion of S7 proxy renditions is not supported yet");
}
private void setProxyRenditionContent(Node content, Map<String, Object> renditionConfig) throws RepositoryException {
if (renditionConfig != null) {
for (String key : renditionConfig.keySet()) {
String value = (String)renditionConfig.get(key);
content.setProperty(key, value);
}
}
}
private String getRenditionHandlerId(Map<String, Object> renditionConfig) {
if (renditionConfig != null) {
return (String)renditionConfig.get("rendition.handler.id");
}
return null;
}
protected void bindClient(Scene7APIClient scene7APIClient) {
this.client = scene7APIClient;
}
protected void unbindClient(Scene7APIClient scene7APIClient) {
if (this.client == scene7APIClient) {
this.client = null;
}
}
protected void bindS7ConfigResolver(S7ConfigResolver s7ConfigResolver) {
this.s7ConfigResolver = s7ConfigResolver;
}
protected void unbindS7ConfigResolver(S7ConfigResolver s7ConfigResolver) {
if (this.s7ConfigResolver == s7ConfigResolver) {
this.s7ConfigResolver = null;
}
}
}