1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.handler.media.spi;
21
22 import java.util.Collections;
23 import java.util.EnumSet;
24 import java.util.List;
25 import java.util.Set;
26
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29 import org.osgi.annotation.versioning.ConsumerType;
30
31 import com.day.cq.wcm.api.Page;
32
33 import io.wcm.handler.media.MediaFileType;
34 import io.wcm.handler.media.MediaNameConstants;
35 import io.wcm.handler.media.markup.DummyImageMediaMarkupBuilder;
36 import io.wcm.handler.media.markup.MediaMarkupBuilderUtil;
37 import io.wcm.handler.media.markup.SimpleImageMediaMarkupBuilder;
38 import io.wcm.handler.mediasource.dam.AemRenditionType;
39 import io.wcm.handler.mediasource.dam.DamMediaSource;
40 import io.wcm.sling.commons.caservice.ContextAwareService;
41
42
43
44
45
46
47 @ConsumerType
48 public abstract class MediaHandlerConfig implements ContextAwareService {
49
50
51
52
53 public static final double DEFAULT_IMAGE_QUALITY = 0.85d;
54
55
56
57
58
59 @Deprecated(since = "2.0.0")
60 public static final double DEFAULT_JPEG_QUALITY = DEFAULT_IMAGE_QUALITY;
61
62 private static final List<Class<? extends MediaSource>> DEFAULT_MEDIA_SOURCES = List.of(
63 DamMediaSource.class);
64
65 private static final List<Class<? extends MediaMarkupBuilder>> DEFAULT_MEDIA_MARKUP_BUILDERS = List.of(
66 SimpleImageMediaMarkupBuilder.class,
67 DummyImageMediaMarkupBuilder.class);
68
69
70
71
72 public @NotNull List<Class<? extends MediaSource>> getSources() {
73 return DEFAULT_MEDIA_SOURCES;
74 }
75
76
77
78
79 public @NotNull List<Class<? extends MediaMarkupBuilder>> getMarkupBuilders() {
80 return DEFAULT_MEDIA_MARKUP_BUILDERS;
81 }
82
83
84
85
86 public @NotNull List<Class<? extends MediaProcessor>> getPreProcessors() {
87
88 return Collections.emptyList();
89 }
90
91
92
93
94 public @NotNull List<Class<? extends MediaProcessor>> getPostProcessors() {
95
96 return Collections.emptyList();
97 }
98
99
100
101
102
103
104
105
106 public double getDefaultImageQuality(@Nullable String contentType) {
107 MediaFileType mediaFileType = MediaFileType.getByContentType(contentType);
108 if (mediaFileType != null && mediaFileType.isImageQualityPercentage()) {
109 return getDefaultImageQualityPercentage();
110 }
111 else if (mediaFileType == MediaFileType.GIF) {
112 return 256d;
113 }
114
115 return 1d;
116 }
117
118
119
120
121
122
123 public double getDefaultImageQualityPercentage() {
124 return DEFAULT_IMAGE_QUALITY;
125 }
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142 public boolean useAdobeStandardNames() {
143 return false;
144 }
145
146
147
148
149 public @NotNull String getMediaRefProperty() {
150 if (useAdobeStandardNames()) {
151 return MediaNameConstants.PN_MEDIA_REF_STANDARD;
152 }
153 else {
154 return MediaNameConstants.PN_MEDIA_REF;
155 }
156 }
157
158
159
160
161 public @NotNull String getMediaCropProperty() {
162 if (useAdobeStandardNames()) {
163 return MediaNameConstants.PN_MEDIA_CROP_STANDARD;
164 }
165 else {
166 return MediaNameConstants.PN_MEDIA_CROP;
167 }
168 }
169
170
171
172
173 public @NotNull String getMediaRotationProperty() {
174 if (useAdobeStandardNames()) {
175 return MediaNameConstants.PN_MEDIA_ROTATION_STANDARD;
176 }
177 else {
178 return MediaNameConstants.PN_MEDIA_ROTATION;
179 }
180 }
181
182
183
184
185 public @NotNull String getMediaMapProperty() {
186 if (useAdobeStandardNames()) {
187 return MediaNameConstants.PN_MEDIA_MAP_STANDARD;
188 }
189 else {
190 return MediaNameConstants.PN_MEDIA_MAP;
191 }
192 }
193
194
195
196
197 public @NotNull String getMediaAltTextProperty() {
198 if (useAdobeStandardNames()) {
199 return MediaNameConstants.PN_MEDIA_ALTTEXT_STANDARD;
200 }
201 else {
202 return MediaNameConstants.PN_MEDIA_ALTTEXT;
203 }
204 }
205
206
207
208
209 public @NotNull String getMediaForceAltTextFromAssetProperty() {
210 if (useAdobeStandardNames()) {
211 return MediaNameConstants.PN_MEDIA_FORCE_ALTTEXT_FROM_ASSET_STANDARD;
212 }
213 else {
214 return MediaNameConstants.PN_MEDIA_FORCE_ALTTEXT_FROM_ASSET;
215 }
216 }
217
218
219
220
221 public @NotNull String getMediaIsDecorativeProperty() {
222 if (useAdobeStandardNames()) {
223 return MediaNameConstants.PN_MEDIA_IS_DECORATIVE_STANDARD;
224 }
225 else {
226 return MediaNameConstants.PN_MEDIA_IS_DECORATIVE;
227 }
228 }
229
230
231
232
233 public @NotNull String getMediaInlineNodeName() {
234 if (useAdobeStandardNames()) {
235 return MediaNameConstants.NN_MEDIA_INLINE_STANDARD;
236 }
237 else {
238 return MediaNameConstants.NN_MEDIA_INLINE;
239 }
240 }
241
242
243
244
245
246
247 @Deprecated(since = "2.0.0")
248 public boolean includeAssetWebRenditionsByDefault() {
249 return false;
250 }
251
252
253
254
255
256
257 @SuppressWarnings("java:S1874")
258 public @NotNull Set<AemRenditionType> getIncludeAssetAemRenditionsByDefault() {
259 if (includeAssetWebRenditionsByDefault()) {
260 return EnumSet.of(AemRenditionType.WEB_RENDITION, AemRenditionType.VIDEO_RENDITION);
261 }
262 else {
263 return EnumSet.of(AemRenditionType.VIDEO_RENDITION);
264 }
265 }
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282 public boolean enforceVirtualRenditions() {
283 return false;
284 }
285
286
287
288
289
290 public @NotNull Set<String> allowedIpeEditorTypes() {
291 return MediaMarkupBuilderUtil.DEFAULT_ALLOWED_IPE_EDITOR_TYPES;
292 }
293
294
295
296
297
298
299 public @NotNull String getDamRootPath(@NotNull Page page) {
300 return "/content/dam";
301 }
302
303 }