Scene7ListInfoProvider.java
5.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.ListInfoProvider
* com.day.cq.dam.api.Asset
* com.day.cq.dam.api.s7dam.set.MediaSet
* com.day.cq.dam.api.s7dam.set.SpinSet
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.json.JSONArray
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.dam.scene7.impl;
import com.day.cq.commons.ListInfoProvider;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.s7dam.set.MediaSet;
import com.day.cq.dam.api.s7dam.set.SpinSet;
import com.day.cq.dam.scene7.api.Scene7AssetMimetypeService;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0, immediate=1)
@Service
public class Scene7ListInfoProvider
implements ListInfoProvider {
private static final Logger LOG = LoggerFactory.getLogger(Scene7ListInfoProvider.class);
static final String SCENE7_FILE_STATUS_JSON_KEY = "scene7Status";
static final String SCENE7_TEMPLATE_PARAMS_JSON_KEY = "templateParams";
static final String SCENE7_WIDTH_JSON_KEY = "imageWidth";
static final String SCENE7_HEIGHT_JSON_KEY = "imageHeight";
static final String MIMETYPE_JSON_KEY = "mimeType";
@Reference
private Scene7AssetMimetypeService scene7AssetMimetypeService;
public void updateListGlobalInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
}
public void updateListItemInfo(SlingHttpServletRequest request, JSONObject info, Resource resource) throws JSONException {
Asset asset = (Asset)resource.adaptTo(Asset.class);
if (asset != null) {
ResourceResolver rr = resource.getResourceResolver();
String path = resource.getPath();
String mimeType = null;
String scene7FileStatus = null;
Object templateParams = null;
Object width = null;
Object height = null;
Resource metadataResource = null;
metadataResource = path.endsWith("jcr:content") ? rr.getResource(path + "/" + "metadata") : rr.getResource(path + "/" + "jcr:content" + "/" + "metadata");
if (metadataResource != null) {
ValueMap valueMap = (ValueMap)metadataResource.adaptTo(ValueMap.class);
scene7FileStatus = (String)valueMap.get("dam:scene7FileStatus", String.class);
templateParams = (String)valueMap.get("dam:scene7TemplateParameters", String.class);
width = (Long)valueMap.get("dam:scene7Width", Long.class);
height = (Long)valueMap.get("dam:scene7Height", Long.class);
mimeType = this.scene7AssetMimetypeService.getMimeTypeForAsset(asset);
}
LOG.debug("Resource {} has {}={}", new Object[]{path, "scene7Status", scene7FileStatus});
if (scene7FileStatus != null) {
info.put("scene7Status", (Object)scene7FileStatus);
this.addDDGroup(info, "s7media");
} else if (!this.isSet(resource)) {
this.addDDGroup(info, "s7media");
}
info.put("templateParams", templateParams == null ? JSONObject.NULL : templateParams);
info.put("imageWidth", width == null ? JSONObject.NULL : width);
info.put("imageHeight", height == null ? JSONObject.NULL : height);
if (mimeType != null) {
info.put("mimeType", (Object)mimeType);
}
}
}
private void addDDGroup(JSONObject info, String ddGroup) throws JSONException {
JSONArray ddGroups = null;
try {
ddGroups = info.getJSONArray("ddGroups");
}
catch (JSONException jse) {
// empty catch block
}
if (ddGroups == null) {
ddGroups = new JSONArray();
info.put("ddGroups", (Object)ddGroups);
}
ddGroups.put((Object)"s7media");
}
private boolean isSet(Resource res) {
boolean setResource = false;
if (res != null && (res.adaptTo(MediaSet.class) != null || res.adaptTo(SpinSet.class) != null)) {
setResource = true;
}
return setResource;
}
protected void bindScene7AssetMimetypeService(Scene7AssetMimetypeService scene7AssetMimetypeService) {
this.scene7AssetMimetypeService = scene7AssetMimetypeService;
}
protected void unbindScene7AssetMimetypeService(Scene7AssetMimetypeService scene7AssetMimetypeService) {
if (this.scene7AssetMimetypeService == scene7AssetMimetypeService) {
this.scene7AssetMimetypeService = null;
}
}
}