S7SetHelper.java
5.11 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.asset.api.Asset
* com.adobe.granite.asset.api.AssetManager
* com.day.cq.dam.api.s7dam.set.ImageSet
* com.day.cq.dam.api.s7dam.set.MediaSet
* com.day.cq.dam.api.s7dam.set.SpinSet
* com.day.cq.dam.api.s7dam.set.SwatchSet
* org.apache.sling.api.resource.ModifiableValueMap
* org.apache.sling.api.resource.PersistenceException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.dam.commons.util;
import com.adobe.granite.asset.api.Asset;
import com.adobe.granite.asset.api.AssetManager;
import com.day.cq.dam.api.s7dam.set.ImageSet;
import com.day.cq.dam.api.s7dam.set.MediaSet;
import com.day.cq.dam.api.s7dam.set.SpinSet;
import com.day.cq.dam.api.s7dam.set.SwatchSet;
import java.util.Map;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
public class S7SetHelper {
private static String MIME_TYPE = "Multipart/Related; type=application/x-";
public static ImageSet createS7ImageSet(Resource parent, String name, Map<String, Object> props) throws PersistenceException {
Resource resource = S7SetHelper.createS7Set(parent, name, props, "ImageSet");
return (ImageSet)resource.adaptTo(ImageSet.class);
}
private static Resource createS7Set(Resource parent, String name, Map<String, Object> props, String type) throws PersistenceException {
return S7SetHelper.createS7Set(parent, name, props, type, null);
}
private static Resource createS7Set(Resource parent, String name, Map<String, Object> props, String type, Map<String, Object> metadata) throws PersistenceException {
if (parent != null && name != null) {
ResourceResolver resolver = parent.getResourceResolver();
String path = parent.getPath() + "/" + name;
AssetManager am = (AssetManager)resolver.adaptTo(AssetManager.class);
Asset asset = am.createAsset(path);
ValueMap vm = (ValueMap)asset.adaptTo(ValueMap.class);
vm.put((Object)"dam:s7damType", (Object)type);
if (props != null) {
vm.putAll(props);
}
Resource metadataResource = resolver.getResource((Resource)asset, "jcr:content/metadata");
ModifiableValueMap metadataVm = (ModifiableValueMap)metadataResource.adaptTo(ModifiableValueMap.class);
metadataVm.put((Object)"dc:format", (Object)(MIME_TYPE + type));
if (metadata != null) {
metadataVm.putAll(metadata);
}
resolver.commit();
return resolver.getResource(path);
}
throw new IllegalArgumentException("parent resource or name can not be null");
}
public static SwatchSet createS7SwatchSet(Resource parent, String name, Map<String, Object> props) throws PersistenceException {
Resource resource = S7SetHelper.createS7Set(parent, name, props, "SwatchSet");
return (SwatchSet)resource.adaptTo(SwatchSet.class);
}
public static MediaSet createS7VideoSet(Resource parent, String name, Map<String, Object> props) throws PersistenceException {
Resource resource = S7SetHelper.createS7Set(parent, name, props, "VideoSet");
return (MediaSet)resource.adaptTo(MediaSet.class);
}
public static MediaSet createS7MixedMediaSet(Resource parent, String name, Map<String, Object> props) throws PersistenceException {
Resource resource = S7SetHelper.createS7Set(parent, name, props, "MixedMediaSet");
return (MediaSet)resource.adaptTo(MediaSet.class);
}
public static SpinSet createS7SpinSet(Resource parent, String name, Map<String, Object> props) throws PersistenceException {
Resource resource = S7SetHelper.createS7Set(parent, name, props, "SpinSet");
return (SpinSet)resource.adaptTo(SpinSet.class);
}
public static boolean isS7Set(Resource resource) {
String s7Type;
ValueMap vm;
Resource contentResource = resource.getChild("jcr:content");
if (contentResource != null && ("ImageSet".equals(s7Type = (String)(vm = (ValueMap)contentResource.adaptTo(ValueMap.class)).get("dam:s7damType", (Object)"")) || "SwatchSet".equals(s7Type) || "VideoSet".equals(s7Type) || "MixedMediaSet".equals(s7Type) || "SpinSet".equals(s7Type) || "CarouselSet".equals(s7Type) || "ECatalog".equals(s7Type))) {
return true;
}
return false;
}
public static boolean isS7Video(Resource resource) {
Resource contentResource = resource.getChild("jcr:content");
if (contentResource != null) {
ValueMap vm = (ValueMap)contentResource.adaptTo(ValueMap.class);
String s7Type = (String)vm.get("dam:s7damType", (Object)"");
boolean isVideo = "Video".equals(s7Type) || "VideoAVS".equals(s7Type);
return isVideo;
}
return false;
}
}