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;
21
22 import java.util.Arrays;
23 import java.util.HashMap;
24 import java.util.Map;
25 import java.util.Set;
26
27 import org.apache.commons.lang3.ArrayUtils;
28 import org.apache.commons.lang3.StringUtils;
29 import org.apache.commons.lang3.builder.EqualsBuilder;
30 import org.apache.commons.lang3.builder.HashCodeBuilder;
31 import org.apache.commons.lang3.builder.ToStringBuilder;
32 import org.apache.commons.lang3.builder.ToStringStyle;
33 import org.apache.sling.api.resource.ValueMap;
34 import org.apache.sling.api.wrappers.ValueMapDecorator;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
37 import org.osgi.annotation.versioning.ProviderType;
38
39 import io.wcm.handler.media.format.MediaFormat;
40 import io.wcm.handler.media.markup.DragDropSupport;
41 import io.wcm.handler.media.markup.IPERatioCustomize;
42 import io.wcm.handler.mediasource.dam.AemRenditionType;
43 import io.wcm.handler.url.UrlMode;
44 import io.wcm.wcm.commons.contenttype.FileExtension;
45
46
47
48
49 @ProviderType
50 public final class MediaArgs implements Cloneable {
51
52 private MediaFormatOption[] mediaFormatOptions;
53 private boolean autoCrop;
54 private String[] fileExtensions;
55 private String enforceOutputFileExtension;
56 private UrlMode urlMode;
57 private long fixedWidth;
58 private long fixedHeight;
59 private boolean download;
60 private boolean contentDispositionAttachment;
61 private String altText;
62 private boolean forceAltValueFromAsset;
63 private boolean decorative;
64 private boolean dummyImage = true;
65 private String dummyImageUrl;
66 private Set<AemRenditionType> includeAssetAemRenditions;
67 private Boolean includeAssetThumbnails;
68 private Boolean includeAssetWebRenditions;
69 private ImageSizes imageSizes;
70 private PictureSource[] pictureSourceSets;
71 private Double imageQualityPercentage;
72 private DragDropSupport dragDropSupport = DragDropSupport.AUTO;
73 private IPERatioCustomize ipeRatioCustomize = IPERatioCustomize.AUTO;
74 private boolean dynamicMediaDisabled;
75 private boolean webOptimizedImageDeliveryDisabled;
76 private ValueMap properties;
77
78 private static final Set<String> ALLOWED_FORCED_FILE_EXTENSIONS = Set.of(
79 FileExtension.JPEG, FileExtension.PNG);
80
81
82
83
84 public MediaArgs() {
85
86 }
87
88
89
90
91 @SuppressWarnings("null")
92 public MediaArgs(@NotNull MediaFormat @NotNull... mediaFormats) {
93 mediaFormats(mediaFormats);
94 }
95
96
97
98
99 public MediaArgs(@NotNull String @NotNull... mediaFormatNames) {
100 mediaFormatNames(mediaFormatNames);
101 }
102
103
104
105
106
107 public MediaFormat @Nullable [] getMediaFormats() {
108 if (this.mediaFormatOptions != null) {
109 MediaFormat[] result = Arrays.stream(this.mediaFormatOptions)
110 .filter(option -> option.getMediaFormatName() == null)
111 .map(MediaFormatOption::getMediaFormat)
112 .toArray(size -> new MediaFormat[size]);
113 if (result.length > 0) {
114 return result;
115 }
116 }
117 return null;
118 }
119
120
121
122
123
124
125 public @NotNull MediaArgs mediaFormats(@Nullable MediaFormat @Nullable... values) {
126 if (values == null || values.length == 0) {
127 this.mediaFormatOptions = null;
128 }
129 else {
130 this.mediaFormatOptions = Arrays.stream(values)
131 .map(mediaFormat -> new MediaFormatOption(mediaFormat, false))
132 .toArray(size -> new MediaFormatOption[size]);
133 }
134 return this;
135 }
136
137
138
139
140
141
142 public @NotNull MediaArgs mandatoryMediaFormats(@NotNull MediaFormat @Nullable... values) {
143 if (values == null || values.length == 0) {
144 this.mediaFormatOptions = null;
145 }
146 else {
147 this.mediaFormatOptions = Arrays.stream(values)
148 .map(mediaFormat -> new MediaFormatOption(mediaFormat, true))
149 .toArray(size -> new MediaFormatOption[size]);
150 }
151 return this;
152 }
153
154
155
156
157
158
159 public @NotNull MediaArgs mediaFormat(MediaFormat value) {
160 if (value == null) {
161 this.mediaFormatOptions = null;
162 }
163 else {
164 this.mediaFormatOptions = new MediaFormatOption[] {
165 new MediaFormatOption(value, false)
166 };
167 }
168 return this;
169 }
170
171
172
173
174
175
176 public @NotNull MediaArgs mediaFormatsMandatory(boolean value) {
177 if (this.mediaFormatOptions != null) {
178 this.mediaFormatOptions = Arrays.stream(this.mediaFormatOptions)
179 .map(option -> option.withMandatory(value))
180 .toArray(size -> new MediaFormatOption[size]);
181 }
182 return this;
183 }
184
185
186
187
188
189 public String @Nullable [] getMediaFormatNames() {
190 if (this.mediaFormatOptions != null) {
191 String[] result = Arrays.stream(this.mediaFormatOptions)
192 .filter(option -> option.getMediaFormatName() != null)
193 .map(MediaFormatOption::getMediaFormatName)
194 .toArray(size -> new String[size]);
195 if (result.length > 0) {
196 return result;
197 }
198 }
199 return null;
200 }
201
202
203
204
205
206
207 public @NotNull MediaArgs mediaFormatNames(@NotNull String @Nullable... names) {
208 if (names == null || names.length == 0) {
209 this.mediaFormatOptions = null;
210 }
211 else {
212 this.mediaFormatOptions = Arrays.stream(names)
213 .map(name -> new MediaFormatOption(name, false))
214 .toArray(size -> new MediaFormatOption[size]);
215 }
216 return this;
217 }
218
219
220
221
222
223
224 public @NotNull MediaArgs mandatoryMediaFormatNames(@NotNull String @Nullable... names) {
225 if (names == null || names.length == 0) {
226 this.mediaFormatOptions = null;
227 }
228 else {
229 this.mediaFormatOptions = Arrays.stream(names)
230 .map(name -> new MediaFormatOption(name, true))
231 .toArray(size -> new MediaFormatOption[size]);
232 }
233 return this;
234 }
235
236
237
238
239
240
241 public @NotNull MediaArgs mediaFormatName(String name) {
242 if (name == null) {
243 this.mediaFormatOptions = null;
244 }
245 else {
246 this.mediaFormatOptions = new MediaFormatOption[] {
247 new MediaFormatOption(name, false)
248 };
249 }
250 return this;
251 }
252
253
254
255
256
257 public MediaFormatOption @Nullable [] getMediaFormatOptions() {
258 return this.mediaFormatOptions;
259 }
260
261
262
263
264
265
266 public @NotNull MediaArgs mediaFormatOptions(@NotNull MediaFormatOption @Nullable... values) {
267 if (values == null || values.length == 0) {
268 this.mediaFormatOptions = null;
269 }
270 else {
271 this.mediaFormatOptions = values;
272 }
273 return this;
274 }
275
276
277
278
279
280 public boolean isAutoCrop() {
281 return this.autoCrop;
282 }
283
284
285
286
287
288
289 public @NotNull MediaArgs autoCrop(boolean value) {
290 this.autoCrop = value;
291 return this;
292 }
293
294
295
296
297 public String @Nullable [] getFileExtensions() {
298 return this.fileExtensions;
299 }
300
301
302
303
304
305 public @NotNull MediaArgs fileExtensions(@NotNull String @Nullable... values) {
306 if (values == null || values.length == 0) {
307 this.fileExtensions = null;
308 }
309 else {
310 this.fileExtensions = values;
311 }
312 return this;
313 }
314
315
316
317
318
319 public @NotNull MediaArgs fileExtension(@Nullable String value) {
320 if (value == null) {
321 this.fileExtensions = null;
322 }
323 else {
324 this.fileExtensions = new String[] {
325 value
326 };
327 }
328 return this;
329 }
330
331
332
333
334
335
336
337
338
339
340
341
342
343 public @Nullable String getEnforceOutputFileExtension() {
344 return this.enforceOutputFileExtension;
345 }
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360 public @NotNull MediaArgs enforceOutputFileExtension(@Nullable String value) {
361 if (!ALLOWED_FORCED_FILE_EXTENSIONS.contains(value)) {
362 throw new IllegalArgumentException("Allowed enfourced output file extensions: "
363 + StringUtils.join(ALLOWED_FORCED_FILE_EXTENSIONS, ","));
364 }
365 this.enforceOutputFileExtension = value;
366 return this;
367 }
368
369
370
371
372 public @Nullable UrlMode getUrlMode() {
373 return this.urlMode;
374 }
375
376
377
378
379
380 public @NotNull MediaArgs urlMode(@Nullable UrlMode value) {
381 this.urlMode = value;
382 return this;
383 }
384
385
386
387
388
389 public long getFixedWidth() {
390 return this.fixedWidth;
391 }
392
393
394
395
396
397
398 public @NotNull MediaArgs fixedWidth(long value) {
399 this.fixedWidth = value;
400 return this;
401 }
402
403
404
405
406
407 public long getFixedHeight() {
408 return this.fixedHeight;
409 }
410
411
412
413
414
415
416 public @NotNull MediaArgs fixedHeight(long value) {
417 this.fixedHeight = value;
418 return this;
419 }
420
421
422
423
424
425
426
427 public @NotNull MediaArgs fixedDimension(long widthValue, long heightValue) {
428 this.fixedWidth = widthValue;
429 this.fixedHeight = heightValue;
430 return this;
431 }
432
433
434
435
436 public boolean isDownload() {
437 return this.download;
438 }
439
440
441
442
443
444 public @NotNull MediaArgs download(boolean value) {
445 this.download = value;
446 return this;
447 }
448
449
450
451
452 public boolean isContentDispositionAttachment() {
453 return this.contentDispositionAttachment;
454 }
455
456
457
458
459
460
461 public @NotNull MediaArgs contentDispositionAttachment(boolean value) {
462 this.contentDispositionAttachment = value;
463 return this;
464 }
465
466
467
468
469 public @Nullable String getAltText() {
470 return this.altText;
471 }
472
473
474
475
476
477
478
479 public @NotNull MediaArgs altText(@Nullable String value) {
480 this.altText = value;
481 return this;
482 }
483
484
485
486
487 public boolean isForceAltValueFromAsset() {
488 return this.forceAltValueFromAsset;
489 }
490
491
492
493
494
495
496 public @NotNull MediaArgs forceAltValueFromAsset(boolean value) {
497 this.forceAltValueFromAsset = value;
498 return this;
499 }
500
501
502
503
504 public boolean isDecorative() {
505 return this.decorative;
506 }
507
508
509
510
511
512 public @NotNull MediaArgs decorative(boolean value) {
513 this.decorative = value;
514 return this;
515 }
516
517
518
519
520 public boolean isDummyImage() {
521 return this.dummyImage;
522 }
523
524
525
526
527
528 public @NotNull MediaArgs dummyImage(boolean value) {
529 this.dummyImage = value;
530 return this;
531 }
532
533
534
535
536 public @Nullable String getDummyImageUrl() {
537 return this.dummyImageUrl;
538 }
539
540
541
542
543
544 public @NotNull MediaArgs dummyImageUrl(@Nullable String value) {
545 this.dummyImageUrl = value;
546 return this;
547 }
548
549
550
551
552
553 public @Nullable Set<AemRenditionType> getIncludeAssetAemRenditions() {
554 return this.includeAssetAemRenditions;
555 }
556
557
558
559
560
561
562 public @NotNull MediaArgs includeAssetAemRenditions(@Nullable Set<AemRenditionType> value) {
563 this.includeAssetAemRenditions = value;
564 return this;
565 }
566
567
568
569
570
571
572 @Deprecated(since = "2.0.0")
573 public @Nullable Boolean isIncludeAssetThumbnails() {
574 return this.includeAssetThumbnails;
575 }
576
577
578
579
580
581
582
583 @Deprecated(since = "2.0.0")
584 public @NotNull MediaArgs includeAssetThumbnails(boolean value) {
585 this.includeAssetThumbnails = value;
586 return this;
587 }
588
589
590
591
592
593
594
595 @Deprecated(since = "2.0.0")
596 public @Nullable Boolean isIncludeAssetWebRenditions() {
597 return this.includeAssetWebRenditions;
598 }
599
600
601
602
603
604
605
606 @Deprecated(since = "2.0.0")
607 public @NotNull MediaArgs includeAssetWebRenditions(boolean value) {
608 this.includeAssetWebRenditions = value;
609 return this;
610 }
611
612
613
614
615 public @Nullable ImageSizes getImageSizes() {
616 return this.imageSizes;
617 }
618
619
620
621
622
623 public @NotNull MediaArgs imageSizes(@Nullable ImageSizes value) {
624 this.imageSizes = value;
625 return this;
626 }
627
628
629
630
631 public PictureSource @Nullable [] getPictureSources() {
632 return this.pictureSourceSets;
633 }
634
635
636
637
638
639 public @NotNull MediaArgs pictureSources(@NotNull PictureSource @Nullable... value) {
640 this.pictureSourceSets = value;
641 return this;
642 }
643
644
645
646
647 public boolean isDynamicMediaDisabled() {
648 return this.dynamicMediaDisabled;
649 }
650
651
652
653
654
655 public @NotNull MediaArgs dynamicMediaDisabled(boolean value) {
656 this.dynamicMediaDisabled = value;
657 return this;
658 }
659
660
661
662
663 public boolean isWebOptimizedImageDeliveryDisabled() {
664 return this.webOptimizedImageDeliveryDisabled;
665 }
666
667
668
669
670
671 public @NotNull MediaArgs webOptimizedImageDeliveryDisabled(boolean value) {
672 this.webOptimizedImageDeliveryDisabled = value;
673 return this;
674 }
675
676
677
678
679 public @Nullable Double getImageQualityPercentage() {
680 return this.imageQualityPercentage;
681 }
682
683
684
685
686
687 public @NotNull MediaArgs imageQualityPercentage(@Nullable Double value) {
688 this.imageQualityPercentage = value;
689 return this;
690 }
691
692
693
694
695
696 public @NotNull DragDropSupport getDragDropSupport() {
697 return this.dragDropSupport;
698 }
699
700
701
702
703
704
705 public @NotNull MediaArgs dragDropSupport(@NotNull DragDropSupport value) {
706 this.dragDropSupport = value;
707 return this;
708 }
709
710
711
712
713 public IPERatioCustomize getIPERatioCustomize() {
714 return this.ipeRatioCustomize;
715 }
716
717
718
719
720
721 public @NotNull MediaArgs ipeRatioCustomize(@Nullable IPERatioCustomize value) {
722 this.ipeRatioCustomize = value;
723 return this;
724 }
725
726
727
728
729
730
731 public @NotNull MediaArgs properties(@NotNull Map<String, Object> map) {
732 getProperties().putAll(map);
733 return this;
734 }
735
736
737
738
739
740
741
742 public @NotNull MediaArgs property(@NotNull String key, @Nullable Object value) {
743 getProperties().put(key, value);
744 return this;
745 }
746
747
748
749
750
751 @NotNull
752 public ValueMap getProperties() {
753 if (this.properties == null) {
754 this.properties = new ValueMapDecorator(new HashMap<>());
755 }
756 return this.properties;
757 }
758
759 @Override
760 public int hashCode() {
761 return HashCodeBuilder.reflectionHashCode(this);
762 }
763
764 @Override
765 public boolean equals(Object obj) {
766 return EqualsBuilder.reflectionEquals(this, obj);
767 }
768
769 @Override
770 @SuppressWarnings("java:S3776")
771 public String toString() {
772 ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE);
773 if (mediaFormatOptions != null && mediaFormatOptions.length > 0) {
774 sb.append("mediaFormats", "[" + StringUtils.join(mediaFormatOptions, ", ") + "]");
775 }
776 if (autoCrop) {
777 sb.append("autoCrop", autoCrop);
778 }
779 if (fileExtensions != null && fileExtensions.length > 0) {
780 sb.append("fileExtensions", StringUtils.join(fileExtensions, ","));
781 }
782 if (enforceOutputFileExtension != null) {
783 sb.append("enforceOutputFileExtension", enforceOutputFileExtension);
784 }
785 if (urlMode != null) {
786 sb.append("urlMode", urlMode);
787 }
788 if (fixedWidth > 0) {
789 sb.append("fixedWidth", fixedWidth);
790 }
791 if (fixedHeight > 0) {
792 sb.append("fixedHeight", fixedHeight);
793 }
794 if (download) {
795 sb.append("download", download);
796 }
797 if (contentDispositionAttachment) {
798 sb.append("contentDispositionAttachment", contentDispositionAttachment);
799 }
800 if (altText != null) {
801 sb.append("altText", altText);
802 }
803 if (forceAltValueFromAsset) {
804 sb.append("forceAltValueFromAsset", forceAltValueFromAsset);
805 }
806 if (decorative) {
807 sb.append("decorative", decorative);
808 }
809 if (!dummyImage) {
810 sb.append("dummyImage ", dummyImage);
811 }
812 if (dummyImageUrl != null) {
813 sb.append("dummyImageUrl", dummyImageUrl);
814 }
815 if (includeAssetAemRenditions != null) {
816 sb.append("includeAssetAemRenditions", includeAssetAemRenditions);
817 }
818 if (includeAssetThumbnails != null) {
819 sb.append("includeAssetThumbnails", includeAssetThumbnails);
820 }
821 if (includeAssetWebRenditions != null) {
822 sb.append("includeAssetWebRenditions", includeAssetWebRenditions);
823 }
824 if (imageSizes != null) {
825 sb.append("imageSizes", imageSizes);
826 }
827 if (pictureSourceSets != null && pictureSourceSets.length > 0) {
828 sb.append("pictureSourceSets", "[" + StringUtils.join(pictureSourceSets, ",") + "]");
829 }
830 if (imageQualityPercentage != null) {
831 sb.append("imageQualityPercentage ", imageQualityPercentage);
832 }
833 if (dragDropSupport != DragDropSupport.AUTO) {
834 sb.append("dragDropSupport ", dragDropSupport);
835 }
836 if (ipeRatioCustomize != IPERatioCustomize.AUTO) {
837 sb.append("ipeRatioCustomize ", ipeRatioCustomize);
838 }
839 if (dynamicMediaDisabled) {
840 sb.append("dynamicMediaDisabled", dynamicMediaDisabled);
841 }
842 if (webOptimizedImageDeliveryDisabled) {
843 sb.append("webOptimizedImageDeliveryDisabled", webOptimizedImageDeliveryDisabled);
844 }
845 if (properties != null && !properties.isEmpty()) {
846 sb.append("properties", properties);
847 }
848 return sb.build();
849 }
850
851
852
853
854
855 @Override
856 @SuppressWarnings({ "java:S2975", "java:S1182", "checkstyle:SuperCloneCheck" })
857 public MediaArgs clone() {
858 MediaArgs clone = new MediaArgs();
859
860 clone.mediaFormatOptions = ArrayUtils.clone(this.mediaFormatOptions);
861 clone.autoCrop = this.autoCrop;
862 clone.fileExtensions = ArrayUtils.clone(this.fileExtensions);
863 clone.enforceOutputFileExtension = this.enforceOutputFileExtension;
864 clone.urlMode = this.urlMode;
865 clone.fixedWidth = this.fixedWidth;
866 clone.fixedHeight = this.fixedHeight;
867 clone.download = this.download;
868 clone.contentDispositionAttachment = this.contentDispositionAttachment;
869 clone.altText = this.altText;
870 clone.forceAltValueFromAsset = this.forceAltValueFromAsset;
871 clone.decorative = this.decorative;
872 clone.dummyImage = this.dummyImage;
873 clone.dummyImageUrl = this.dummyImageUrl;
874 clone.includeAssetAemRenditions = this.includeAssetAemRenditions;
875 clone.includeAssetThumbnails = this.includeAssetThumbnails;
876 clone.includeAssetWebRenditions = this.includeAssetWebRenditions;
877 clone.imageSizes = this.imageSizes;
878 clone.pictureSourceSets = ArrayUtils.clone(this.pictureSourceSets);
879 clone.imageQualityPercentage = this.imageQualityPercentage;
880 clone.dragDropSupport = this.dragDropSupport;
881 clone.ipeRatioCustomize = this.ipeRatioCustomize;
882 clone.dynamicMediaDisabled = this.dynamicMediaDisabled;
883 clone.webOptimizedImageDeliveryDisabled = this.webOptimizedImageDeliveryDisabled;
884 if (this.properties != null) {
885 clone.properties = new ValueMapDecorator(new HashMap<>(this.properties));
886 }
887
888 return clone;
889 }
890
891
892
893
894 @ProviderType
895 public static final class MediaFormatOption {
896
897 private final MediaFormat mediaFormat;
898 private final String mediaFormatName;
899 private final boolean mandatory;
900
901
902
903
904
905 public MediaFormatOption(@Nullable MediaFormat mediaFormat, boolean mandatory) {
906 this.mediaFormat = mediaFormat;
907 this.mediaFormatName = null;
908 this.mandatory = mandatory;
909 }
910
911
912
913
914
915 public MediaFormatOption(@NotNull String mediaFormatName, boolean mandatory) {
916 this.mediaFormat = null;
917 this.mediaFormatName = mediaFormatName;
918 this.mandatory = mandatory;
919 }
920
921 public @Nullable MediaFormat getMediaFormat() {
922 return this.mediaFormat;
923 }
924
925 public @Nullable String getMediaFormatName() {
926 return this.mediaFormatName;
927 }
928
929 public boolean isMandatory() {
930 return this.mandatory;
931 }
932
933 @Override
934 public int hashCode() {
935 return HashCodeBuilder.reflectionHashCode(this);
936 }
937
938 @Override
939 public boolean equals(Object obj) {
940 return EqualsBuilder.reflectionEquals(this, obj);
941 }
942
943 @Override
944 public String toString() {
945 return mediaFormatToString(mediaFormat, mediaFormatName, mandatory);
946 }
947
948 @NotNull
949 MediaFormatOption withMandatory(boolean newMandatory) {
950 if (this.mediaFormat != null) {
951 return new MediaFormatOption(this.mediaFormat, newMandatory);
952 }
953 else {
954 return new MediaFormatOption(this.mediaFormatName, newMandatory);
955 }
956 }
957
958 static String mediaFormatToString(MediaFormat mediaFormat, String mediaFormatName, boolean mandatory) {
959 StringBuilder sb = new StringBuilder();
960 if (mediaFormat != null) {
961 sb.append(mediaFormat.toString());
962 }
963 else if (mediaFormatName != null) {
964 sb.append(mediaFormatName);
965 }
966 if (!mandatory) {
967 sb.append("[?]");
968 }
969 return sb.toString();
970 }
971
972 }
973
974
975
976
977 @ProviderType
978 public static final class ImageSizes {
979
980 private final @NotNull String sizes;
981 private final @NotNull WidthOption @NotNull [] widthOptions;
982
983
984
985
986
987
988 public ImageSizes(@NotNull String sizes, long @NotNull... widths) {
989 this.sizes = sizes;
990 this.widthOptions = Arrays.stream(widths)
991 .mapToObj(width -> new WidthOption(width, true))
992 .toArray(size -> new WidthOption[size]);
993 }
994
995
996
997
998
999
1000 public ImageSizes(@NotNull String sizes, @NotNull WidthOption @NotNull... widthOptions) {
1001 this.sizes = sizes;
1002 this.widthOptions = widthOptions;
1003 }
1004
1005
1006
1007
1008
1009 public @NotNull String getSizes() {
1010 return this.sizes;
1011 }
1012
1013
1014
1015
1016 public @NotNull WidthOption @Nullable [] getWidthOptions() {
1017 return this.widthOptions;
1018 }
1019
1020 @Override
1021 public int hashCode() {
1022 return HashCodeBuilder.reflectionHashCode(this);
1023 }
1024
1025 @Override
1026 public boolean equals(Object obj) {
1027 return EqualsBuilder.reflectionEquals(this, obj);
1028 }
1029
1030 @Override
1031 @SuppressWarnings("null")
1032 public String toString() {
1033 ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE);
1034 sb.append("sizes", sizes);
1035 if (widthOptions != null && widthOptions.length > 0) {
1036 sb.append("widthOptions", StringUtils.join(widthOptions, ","));
1037 }
1038 return sb.build();
1039 }
1040
1041 }
1042
1043
1044
1045
1046 @ProviderType
1047 public static final class PictureSource {
1048
1049 private MediaFormat mediaFormat;
1050 private String mediaFormatName;
1051 private String media;
1052 private String sizes;
1053 private WidthOption[] widthOptions;
1054
1055
1056
1057
1058 public PictureSource(@NotNull MediaFormat mediaFormat) {
1059 this.mediaFormat = mediaFormat;
1060 }
1061
1062
1063
1064
1065 public PictureSource(@Nullable String mediaFormatName) {
1066 this.mediaFormatName = mediaFormatName;
1067 }
1068
1069 private static @NotNull WidthOption @NotNull [] toWidthOptions(long @NotNull... widths) {
1070 return Arrays.stream(widths)
1071 .mapToObj(width -> new WidthOption(width, true))
1072 .toArray(size -> new WidthOption[size]);
1073 }
1074
1075
1076
1077
1078 public @Nullable MediaFormat getMediaFormat() {
1079 return this.mediaFormat;
1080 }
1081
1082
1083
1084
1085 public @Nullable String getMediaFormatName() {
1086 return this.mediaFormatName;
1087 }
1088
1089
1090
1091
1092
1093 public PictureSource widthOptions(@NotNull WidthOption @NotNull... value) {
1094 this.widthOptions = value;
1095 return this;
1096 }
1097
1098
1099
1100
1101 public @NotNull WidthOption @Nullable [] getWidthOptions() {
1102 return this.widthOptions;
1103 }
1104
1105
1106
1107
1108
1109 public PictureSource widths(long @NotNull... value) {
1110 this.widthOptions = toWidthOptions(value);
1111 return this;
1112 }
1113
1114
1115
1116
1117
1118
1119 public PictureSource sizes(@Nullable String value) {
1120 this.sizes = value;
1121 return this;
1122 }
1123
1124
1125
1126
1127
1128 public @Nullable String getSizes() {
1129 return this.sizes;
1130 }
1131
1132
1133
1134
1135
1136
1137 public PictureSource media(@Nullable String value) {
1138 this.media = value;
1139 return this;
1140 }
1141
1142
1143
1144
1145
1146 public @Nullable String getMedia() {
1147 return this.media;
1148 }
1149
1150 @Override
1151 public int hashCode() {
1152 return HashCodeBuilder.reflectionHashCode(this);
1153 }
1154
1155 @Override
1156 public boolean equals(Object obj) {
1157 return EqualsBuilder.reflectionEquals(this, obj);
1158 }
1159
1160 @Override
1161 public String toString() {
1162 ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE);
1163 sb.append("mediaFormat", MediaFormatOption.mediaFormatToString(mediaFormat, mediaFormatName, true));
1164 if (media != null) {
1165 sb.append("media", media);
1166 }
1167 if (sizes != null) {
1168 sb.append("sizes", sizes);
1169 }
1170 if (widthOptions != null && widthOptions.length > 0) {
1171 sb.append("widthOptions", StringUtils.join(widthOptions, ","));
1172 }
1173 return sb.build();
1174 }
1175
1176 }
1177
1178
1179
1180
1181 @ProviderType
1182 public static final class WidthOption {
1183
1184 private final long width;
1185 private final boolean mandatory;
1186
1187
1188
1189
1190
1191 public WidthOption(long width, boolean mandatory) {
1192 this.width = width;
1193 this.mandatory = mandatory;
1194 }
1195
1196
1197
1198
1199 public long getWidth() {
1200 return this.width;
1201 }
1202
1203
1204
1205
1206 public boolean isMandatory() {
1207 return this.mandatory;
1208 }
1209
1210 @Override
1211 public int hashCode() {
1212 return HashCodeBuilder.reflectionHashCode(this);
1213 }
1214
1215 @Override
1216 public boolean equals(Object obj) {
1217 return EqualsBuilder.reflectionEquals(this, obj);
1218 }
1219
1220 @Override
1221 public String toString() {
1222 StringBuilder sb = new StringBuilder();
1223 sb.append(Long.toString(width));
1224 if (!mandatory) {
1225 sb.append("?");
1226 }
1227 return sb.toString();
1228 }
1229
1230 }
1231
1232 }