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
143
144 public boolean useAdobeStandardNames() {
145 return false;
146 }
147
148
149
150
151 public @NotNull String getMediaRefProperty() {
152 if (useAdobeStandardNames()) {
153 return MediaNameConstants.PN_MEDIA_REF_STANDARD;
154 }
155 else {
156 return MediaNameConstants.PN_MEDIA_REF;
157 }
158 }
159
160
161
162
163 public @NotNull String getMediaCropProperty() {
164 if (useAdobeStandardNames()) {
165 return MediaNameConstants.PN_MEDIA_CROP_STANDARD;
166 }
167 else {
168 return MediaNameConstants.PN_MEDIA_CROP;
169 }
170 }
171
172
173
174
175 public @NotNull String getMediaRotationProperty() {
176 if (useAdobeStandardNames()) {
177 return MediaNameConstants.PN_MEDIA_ROTATION_STANDARD;
178 }
179 else {
180 return MediaNameConstants.PN_MEDIA_ROTATION;
181 }
182 }
183
184
185
186
187 public @NotNull String getMediaMapProperty() {
188 if (useAdobeStandardNames()) {
189 return MediaNameConstants.PN_MEDIA_MAP_STANDARD;
190 }
191 else {
192 return MediaNameConstants.PN_MEDIA_MAP;
193 }
194 }
195
196
197
198
199 public @NotNull String getMediaAltTextProperty() {
200 if (useAdobeStandardNames()) {
201 return MediaNameConstants.PN_MEDIA_ALTTEXT_STANDARD;
202 }
203 else {
204 return MediaNameConstants.PN_MEDIA_ALTTEXT;
205 }
206 }
207
208
209
210
211 public @NotNull String getMediaForceAltTextFromAssetProperty() {
212 if (useAdobeStandardNames()) {
213 return MediaNameConstants.PN_MEDIA_FORCE_ALTTEXT_FROM_ASSET_STANDARD;
214 }
215 else {
216 return MediaNameConstants.PN_MEDIA_FORCE_ALTTEXT_FROM_ASSET;
217 }
218 }
219
220
221
222
223 public @NotNull String getMediaIsDecorativeProperty() {
224 if (useAdobeStandardNames()) {
225 return MediaNameConstants.PN_MEDIA_IS_DECORATIVE_STANDARD;
226 }
227 else {
228 return MediaNameConstants.PN_MEDIA_IS_DECORATIVE;
229 }
230 }
231
232
233
234
235 public @NotNull String getMediaInlineNodeName() {
236 if (useAdobeStandardNames()) {
237 return MediaNameConstants.NN_MEDIA_INLINE_STANDARD;
238 }
239 else {
240 return MediaNameConstants.NN_MEDIA_INLINE;
241 }
242 }
243
244
245
246
247
248
249 @Deprecated(since = "2.0.0")
250 public boolean includeAssetWebRenditionsByDefault() {
251 return false;
252 }
253
254
255
256
257
258
259 @SuppressWarnings("java:S1874")
260 public @NotNull Set<AemRenditionType> getIncludeAssetAemRenditionsByDefault() {
261 if (includeAssetWebRenditionsByDefault()) {
262 return EnumSet.of(AemRenditionType.WEB_RENDITION, AemRenditionType.VIDEO_RENDITION);
263 }
264 else {
265 return EnumSet.of(AemRenditionType.VIDEO_RENDITION);
266 }
267 }
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286 public boolean enforceVirtualRenditions() {
287 return false;
288 }
289
290
291
292
293
294 public @NotNull Set<String> allowedIpeEditorTypes() {
295 return MediaMarkupBuilderUtil.DEFAULT_ALLOWED_IPE_EDITOR_TYPES;
296 }
297
298
299
300
301
302
303 public @NotNull String getDamRootPath(@NotNull Page page) {
304 return "/content/dam";
305 }
306
307 }