VideoProfile.java
5.61 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.dam.api.Asset
* com.day.cq.dam.api.Rendition
* com.day.cq.dam.api.RenditionPicker
* com.day.cq.dam.commons.util.PrefixRenditionPicker
* javax.jcr.Node
* org.apache.commons.lang.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.dam.video;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.Rendition;
import com.day.cq.dam.api.RenditionPicker;
import com.day.cq.dam.commons.util.PrefixRenditionPicker;
import java.awt.Dimension;
import javax.jcr.Node;
import org.apache.commons.lang.StringUtils;
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.ValueMap;
public class VideoProfile {
public static final String PROFILE_BASE_PATH = "/etc/dam/video";
public static final String PROFILE_TYPE_CQ = "dam/components/video/profile";
public static final String PROFILE_TYPE_S7 = "dam/components/video/s7profile";
private Resource resource;
public static VideoProfile get(ResourceResolver resolver, String name) {
String path = name.startsWith("/") ? name : "/etc/dam/video/" + name;
Resource resource = resolver.getResource(path);
if (resource != null) {
return new VideoProfile(resource);
}
return null;
}
public VideoProfile(Resource resource) {
this.resource = "jcr:content".equals(resource.getName()) ? resource.getParent() : resource;
}
public String getName() {
return this.resource.getName();
}
public String getPath() {
return this.resource.getPath();
}
public Resource getResource() {
return this.resource;
}
public Resource getContentResource() {
return this.resource.getResourceResolver().getResource(this.resource, "jcr:content");
}
public ValueMap getProperties() {
return ResourceUtil.getValueMap((Resource)this.getContentResource());
}
public Node getContentNode() {
Resource content = this.getContentResource();
return content == null ? null : (Node)content.adaptTo(Node.class);
}
public String getHtmlType() {
return (String)this.getProperties().get("htmlType", (Object)"");
}
public Rendition getRendition(Asset asset) {
if (this.isCQProfile()) {
String prefix = "cq5dam.video." + this.getName();
return asset.getRendition((RenditionPicker)new PrefixRenditionPicker(prefix));
}
if (this.isS7Profile()) {
String prefix = "cq5dam.video.s7." + this.getPresetHandle();
return asset.getRendition((RenditionPicker)new PrefixRenditionPicker(prefix));
}
return null;
}
public Dimension getOutputSize() {
ValueMap props = this.getProperties();
Integer width = (Integer)props.get("width", Integer.class);
Integer height = (Integer)props.get("height", Integer.class);
if (width != null && height != null) {
return new Dimension(width, height);
}
return null;
}
public String getHtmlSource(Rendition rendition) {
String htmlSource = "";
if (rendition != null && this.isCQProfile()) {
htmlSource = rendition.getPath();
} else if (rendition != null && this.isS7Profile()) {
htmlSource = this.getScene7Url(rendition);
}
return htmlSource;
}
public String getStrobeVideoSource(Rendition rendition) {
String source = "";
if (rendition != null && this.isCQProfile()) {
source = "../../../../.." + rendition.getPath();
} else if (rendition != null && this.isS7Profile()) {
source = this.getScene7Url(rendition);
}
return source;
}
public String getFlvVideoSource(Rendition rendition) {
String source = "";
if (rendition != null && this.isCQProfile()) {
source = rendition.getPath();
} else if (rendition != null && this.isS7Profile()) {
source = this.getScene7Url(rendition);
}
return source;
}
public String getCustomVideoSource(Rendition rendition) {
return this.getFlvVideoSource(rendition);
}
private boolean isS7Profile() {
return this.getResourceType().equals("dam/components/video/s7profile");
}
private boolean isCQProfile() {
return this.getResourceType().equals("dam/components/video/profile");
}
private String getResourceType() {
String resourcType = "";
Resource content = this.resource.getChild("jcr:content");
if (content != null) {
resourcType = content.getResourceType();
}
return resourcType;
}
private String getPresetHandle() {
String presetHandle = (String)this.getProperties().get("preset", (Object)"");
if (StringUtils.isNotBlank((String)presetHandle)) {
int lastIndex = presetHandle.lastIndexOf("/");
presetHandle = presetHandle.substring(lastIndex + 1, presetHandle.length());
presetHandle = presetHandle.replaceFirst("ps-", "");
}
return presetHandle;
}
private String getScene7Url(Rendition rendition) {
String scene7Url = "";
if (rendition != null) {
scene7Url = (String)rendition.getProperties().get("scene7.url", (Object)"");
}
return scene7Url;
}
}