diff --git a/src/main/java/io/wcm/handler/media/Media.java b/src/main/java/io/wcm/handler/media/Media.java index 7fe640a5..8980e079 100644 --- a/src/main/java/io/wcm/handler/media/Media.java +++ b/src/main/java/io/wcm/handler/media/Media.java @@ -97,7 +97,7 @@ public void setMediaRequest(@NotNull MediaRequest mediaRequest) { * @return Html element */ @JsonIgnore - public HtmlElement getElement() { + public @Nullable HtmlElement getElement() { if (this.element == null && this.elementBuilder != null) { this.element = this.elementBuilder.apply(this); this.elementBuilder = null; @@ -109,7 +109,7 @@ public HtmlElement getElement() { * @return Media HTML element serialized to string. Returns null if media element is null. */ @JsonIgnore - public String getMarkup() { + public @Nullable String getMarkup() { HtmlElement el = getElement(); if (markup == null && el != null) { if (el instanceof Span) { @@ -130,7 +130,7 @@ public String getMarkup() { /** * @param value Function that builds the HTML element representation on demand */ - public void setElementBuilder(Function> value) { + public void setElementBuilder(@NotNull Function> value) { this.elementBuilder = value; this.markup = null; } @@ -138,14 +138,14 @@ public void setElementBuilder(Function> value) { /** * @return Media URL */ - public String getUrl() { + public @Nullable String getUrl() { return this.url; } /** * @param value Media URL */ - public void setUrl(String value) { + public void setUrl(@Nullable String value) { this.url = value; } @@ -153,7 +153,7 @@ public void setUrl(String value) { * Get media item info that was resolved during media handler processing * @return Media item */ - public Asset getAsset() { + public @Nullable Asset getAsset() { return this.asset; } @@ -161,7 +161,7 @@ public Asset getAsset() { * Set media item that was resolved during media handler processing * @param asset Media item */ - public void setAsset(Asset asset) { + public void setAsset(@Nullable Asset asset) { this.asset = asset; } @@ -170,7 +170,7 @@ public void setAsset(Asset asset) { * @return Rendition */ @JsonIgnore - public Rendition getRendition() { + public @Nullable Rendition getRendition() { if (this.renditions == null || this.renditions.isEmpty()) { return null; } @@ -181,7 +181,7 @@ public Rendition getRendition() { * Get all renditions that were resolved during media handler processing * @return Renditions */ - public Collection getRenditions() { + public @NotNull Collection getRenditions() { if (this.renditions == null) { return Collections.emptyList(); } @@ -194,7 +194,7 @@ public Collection getRenditions() { * Set all renditions that was resolved during media handler processing * @param renditions Renditions */ - public void setRenditions(Collection renditions) { + public void setRenditions(@Nullable Collection renditions) { this.renditions = renditions; } @@ -254,14 +254,14 @@ public boolean isValid() { * @return Reason why the requested media could not be resolved and is invalid */ @JsonIgnore - public MediaInvalidReason getMediaInvalidReason() { + public @Nullable MediaInvalidReason getMediaInvalidReason() { return this.mediaInvalidReason; } /** * @param mediaInvalidReason Reason why the requested media could not be resolved and is invalid */ - public void setMediaInvalidReason(MediaInvalidReason mediaInvalidReason) { + public void setMediaInvalidReason(@Nullable MediaInvalidReason mediaInvalidReason) { this.mediaInvalidReason = mediaInvalidReason; } @@ -269,7 +269,7 @@ public void setMediaInvalidReason(MediaInvalidReason mediaInvalidReason) { * @return Custom message when {@link #getMediaInvalidReason()} is set to {@link MediaInvalidReason#CUSTOM}. * Message is interpreted as i18n key. */ - public String getMediaInvalidReasonCustomMessage() { + public @Nullable String getMediaInvalidReasonCustomMessage() { return this.mediaInvalidReasonCustomMessage; } @@ -277,7 +277,7 @@ public String getMediaInvalidReasonCustomMessage() { * @param mediaInvalidReasonCustomMessage Custom message when {@link #getMediaInvalidReason()} is set to * {@link MediaInvalidReason#CUSTOM}. Message is interpreted as i18n key. */ - public void setMediaInvalidReasonCustomMessage(String mediaInvalidReasonCustomMessage) { + public void setMediaInvalidReasonCustomMessage(@Nullable String mediaInvalidReasonCustomMessage) { this.mediaInvalidReasonCustomMessage = mediaInvalidReasonCustomMessage; } diff --git a/src/main/java/io/wcm/handler/media/MediaComponentPropertyResolver.java b/src/main/java/io/wcm/handler/media/MediaComponentPropertyResolver.java index 9690430c..fbd95198 100644 --- a/src/main/java/io/wcm/handler/media/MediaComponentPropertyResolver.java +++ b/src/main/java/io/wcm/handler/media/MediaComponentPropertyResolver.java @@ -193,7 +193,6 @@ else if (mediaFormatsMandatory.length > i) { /** * @return Image sizes */ - @SuppressWarnings("null") public @Nullable ImageSizes getImageSizes() { String responsiveType = getResponsiveType(); if (responsiveType != null && !StringUtils.equals(responsiveType, RESPONSIVE_TYPE_IMAGE_SIZES)) { diff --git a/src/main/java/io/wcm/handler/media/MediaHandler.java b/src/main/java/io/wcm/handler/media/MediaHandler.java index 0f53848b..0b7feb76 100644 --- a/src/main/java/io/wcm/handler/media/MediaHandler.java +++ b/src/main/java/io/wcm/handler/media/MediaHandler.java @@ -46,7 +46,7 @@ public interface MediaHandler { * @return Media builder */ @NotNull - MediaBuilder get(Resource resource); + MediaBuilder get(@Nullable Resource resource); /** * Build media which is referenced in the resource (as property or inline binary data). @@ -57,7 +57,7 @@ public interface MediaHandler { * @return Media builder */ @NotNull - MediaBuilder get(Resource resource, MediaArgs mediaArgs); + MediaBuilder get(@Nullable Resource resource, @NotNull MediaArgs mediaArgs); /** * Build media which is referenced in the resource (as property or inline binary data). @@ -68,7 +68,7 @@ public interface MediaHandler { * @return Media builder */ @NotNull - MediaBuilder get(Resource resource, MediaFormat... mediaFormats); + MediaBuilder get(@Nullable Resource resource, MediaFormat @NotNull... mediaFormats); /** * Build media which is referenced via its string address. @@ -78,7 +78,7 @@ public interface MediaHandler { * @see #get(String, Resource) */ @NotNull - MediaBuilder get(String mediaRef); + MediaBuilder get(@Nullable String mediaRef); /** * Build media which is referenced via its string address. @@ -88,7 +88,7 @@ public interface MediaHandler { * @return Media builder */ @NotNull - MediaBuilder get(String mediaRef, @Nullable Resource contextResource); + MediaBuilder get(@Nullable String mediaRef, @Nullable Resource contextResource); /** * Build media which is referenced via its string address. @@ -97,7 +97,7 @@ public interface MediaHandler { * @return Media builder */ @NotNull - MediaBuilder get(String mediaRef, MediaArgs mediaArgs); + MediaBuilder get(@Nullable String mediaRef, @NotNull MediaArgs mediaArgs); /** * Build media which is referenced via its string address. @@ -106,7 +106,7 @@ public interface MediaHandler { * @return Media builder */ @NotNull - MediaBuilder get(String mediaRef, MediaFormat... mediaFormats); + MediaBuilder get(@Nullable String mediaRef, MediaFormat @NotNull... mediaFormats); /** * Build media for the given request holding all further request properties. @@ -122,7 +122,7 @@ public interface MediaHandler { * @param element Media markup element. * @return true if media element is invalid */ - boolean isValidElement(HtmlElement element); + boolean isValidElement(@Nullable HtmlElement element); /** * Returns an empty media that is marked as invalid. diff --git a/src/main/java/io/wcm/handler/media/MediaNameConstants.java b/src/main/java/io/wcm/handler/media/MediaNameConstants.java index 4ff421b7..a364cca1 100644 --- a/src/main/java/io/wcm/handler/media/MediaNameConstants.java +++ b/src/main/java/io/wcm/handler/media/MediaNameConstants.java @@ -19,7 +19,6 @@ */ package io.wcm.handler.media; -import org.jetbrains.annotations.NotNull; import org.osgi.annotation.versioning.ProviderType; /** @@ -46,117 +45,117 @@ private MediaNameConstants() { /** * Media format node type */ - public static final @NotNull String NT_MEDIAFORMAT = "wcmio:MediaFormat"; + public static final String NT_MEDIAFORMAT = "wcmio:MediaFormat"; /** * Media source */ - public static final @NotNull String PN_MEDIA_SOURCE = "mediaSource"; + public static final String PN_MEDIA_SOURCE = "mediaSource"; /** * Default property name for reference to media library item (Legacy wcm.io Handler Standard) */ - public static final @NotNull String PN_MEDIA_REF = "mediaRef"; + public static final String PN_MEDIA_REF = "mediaRef"; /** * Default property name for reference to media library item (Adobe/Core Component standard) */ - public static final @NotNull String PN_MEDIA_REF_STANDARD = "fileReference"; + public static final String PN_MEDIA_REF_STANDARD = "fileReference"; /** * Default property name for cropping parameters (Legacy wcm.io Handler Standard) */ - public static final @NotNull String PN_MEDIA_CROP = "mediaCrop"; + public static final String PN_MEDIA_CROP = "mediaCrop"; /** * Default property name for cropping parameters (Adobe/Core Component standard) */ - public static final @NotNull String PN_MEDIA_CROP_STANDARD = "imageCrop"; + public static final String PN_MEDIA_CROP_STANDARD = "imageCrop"; /** * Default property name for rotate parameter (Legacy wcm.io Handler Standard) */ - public static final @NotNull String PN_MEDIA_ROTATION = "mediaRotate"; + public static final String PN_MEDIA_ROTATION = "mediaRotate"; /** * Default property name for rotate parameter (Adobe/Core Component standard) */ - public static final @NotNull String PN_MEDIA_ROTATION_STANDARD = "imageRotate"; + public static final String PN_MEDIA_ROTATION_STANDARD = "imageRotate"; /** * Default property name for map parameter (Legacy wcm.io Handler Standard) */ - public static final @NotNull String PN_MEDIA_MAP = "mediaMap"; + public static final String PN_MEDIA_MAP = "mediaMap"; /** * Default property name for map parameter (Adobe/Core Component standard) */ - public static final @NotNull String PN_MEDIA_MAP_STANDARD = "imageMap"; + public static final String PN_MEDIA_MAP_STANDARD = "imageMap"; /** * Default property name for media alt. text (Legacy wcm.io Handler Standard) */ - public static final @NotNull String PN_MEDIA_ALTTEXT = "mediaAltText"; + public static final String PN_MEDIA_ALTTEXT = "mediaAltText"; /** * Default property name for media alt. text (Adobe/Core Component standard) */ - public static final @NotNull String PN_MEDIA_ALTTEXT_STANDARD = "alt"; + public static final String PN_MEDIA_ALTTEXT_STANDARD = "alt"; /** * Default property name for forcing reading alt. text from DAM asset description (Legacy wcm.io Handler Standard) */ - public static final @NotNull String PN_MEDIA_FORCE_ALTTEXT_FROM_ASSET = "mediaForceAltValueFromAsset"; + public static final String PN_MEDIA_FORCE_ALTTEXT_FROM_ASSET = "mediaForceAltValueFromAsset"; /** * Default property name for forcing reading alt. text from DAM asset description (Adobe/Core Component standard) */ - public static final @NotNull String PN_MEDIA_FORCE_ALTTEXT_FROM_ASSET_STANDARD = "altValueFromDAM"; + public static final String PN_MEDIA_FORCE_ALTTEXT_FROM_ASSET_STANDARD = "altValueFromDAM"; /** * Default property name for marking image as "decorative" - requiring no alt. text (Legacy wcm.io Handler Standard) */ - public static final @NotNull String PN_MEDIA_IS_DECORATIVE = "mediaIsDecorative"; + public static final String PN_MEDIA_IS_DECORATIVE = "mediaIsDecorative"; /** * Default property name for marking image as "decorative" - requiring no alt. text (Adobe/Core Component standard) */ - public static final @NotNull String PN_MEDIA_IS_DECORATIVE_STANDARD = "isDecorative"; + public static final String PN_MEDIA_IS_DECORATIVE_STANDARD = "isDecorative"; /** * Default node name for inline media item stored in node within the content page (Legacy wcm.io Handler Standard) */ - public static final @NotNull String NN_MEDIA_INLINE = "mediaInline"; + public static final String NN_MEDIA_INLINE = "mediaInline"; /** * Default node name for inline media item stored in node within the content page (Adobe/Core Component standard) */ - public static final @NotNull String NN_MEDIA_INLINE_STANDARD = "file"; + public static final String NN_MEDIA_INLINE_STANDARD = "file"; /** * CSS class for dummy image */ - public static final @NotNull String CSS_DUMMYIMAGE = "wcmio_mediahandler_wcm_dummy"; + public static final String CSS_DUMMYIMAGE = "wcmio_mediahandler_wcm_dummy"; /** * CSS class for "Added in Diff Mode" */ - public static final @NotNull String CSS_DIFF_ADDED = "wcmio_mediahandler_wcm_diff_added"; + public static final String CSS_DIFF_ADDED = "wcmio_mediahandler_wcm_diff_added"; /** * CSS class for "Updated in Diff Mode" */ - public static final @NotNull String CSS_DIFF_UPDATED = "wcmio_mediahandler_wcm_diff_updated"; + public static final String CSS_DIFF_UPDATED = "wcmio_mediahandler_wcm_diff_updated"; /** * CSS class for "Removed in Diff Mode" */ - public static final @NotNull String CSS_DIFF_REMOVED = "wcmio_mediahandler_wcm_diff_removed"; + public static final String CSS_DIFF_REMOVED = "wcmio_mediahandler_wcm_diff_removed"; /** * Property name for setting additional CSS classes */ - public static final @NotNull String PROP_CSS_CLASS = "cssClass"; + public static final String PROP_CSS_CLASS = "cssClass"; /** * Enable "auto-cropping" mode for this component by setting to true. @@ -164,7 +163,7 @@ private MediaNameConstants() { * Property is to be set on component or in policy. *

*/ - public static final @NotNull String PN_COMPONENT_MEDIA_AUTOCROP = "wcmio:mediaCropAuto"; + public static final String PN_COMPONENT_MEDIA_AUTOCROP = "wcmio:mediaCropAuto"; /** * List of media format names accepted by this component. @@ -172,7 +171,7 @@ private MediaNameConstants() { * Property is to be set on component or in policy. *

*/ - public static final @NotNull String PN_COMPONENT_MEDIA_FORMATS = "wcmio:mediaFormats"; + public static final String PN_COMPONENT_MEDIA_FORMATS = "wcmio:mediaFormats"; /** * Resolving of all media formats is mandatory. This can be a single boolean, or a boolean array @@ -181,7 +180,7 @@ private MediaNameConstants() { * Property is to be set on component or in policy. *

*/ - public static final @NotNull String PN_COMPONENT_MEDIA_FORMATS_MANDATORY = "wcmio:mediaFormatsMandatory"; + public static final String PN_COMPONENT_MEDIA_FORMATS_MANDATORY = "wcmio:mediaFormatsMandatory"; /** * List of media format names that are mandatory. The list of names is merged with the list @@ -191,7 +190,7 @@ private MediaNameConstants() { * Property is to be set on component or in policy. *

*/ - public static final @NotNull String PN_COMPONENT_MEDIA_FORMATS_MANDATORY_NAMES = "wcmio:mediaFormatsMandatoryNames"; + public static final String PN_COMPONENT_MEDIA_FORMATS_MANDATORY_NAMES = "wcmio:mediaFormatsMandatoryNames"; /** * If multiple responsive image settings are defined, this property defines which gets active. @@ -200,7 +199,7 @@ private MediaNameConstants() { * Property is to be set on component or in policy. *

*/ - public static final @NotNull String PN_COMPONENT_MEDIA_RESPONSIVE_TYPE = "wcmio:mediaResponsiveType"; + public static final String PN_COMPONENT_MEDIA_RESPONSIVE_TYPE = "wcmio:mediaResponsiveType"; /** * Defines "image sizes" responsive image setting. @@ -209,7 +208,7 @@ private MediaNameConstants() { * Child node is to be defined on component or in policy. *

*/ - public static final @NotNull String NN_COMPONENT_MEDIA_RESPONSIVEIMAGE_SIZES = "wcmio:mediaResponsiveImageSizes"; + public static final String NN_COMPONENT_MEDIA_RESPONSIVEIMAGE_SIZES = "wcmio:mediaResponsiveImageSizes"; /** * Defines "picture sources" responsive image setting. @@ -219,7 +218,7 @@ private MediaNameConstants() { * Child node is to be defined on component or in policy. *

*/ - public static final @NotNull String NN_COMPONENT_MEDIA_RESPONSIVEPICTURE_SOURCES = "wcmio:mediaResponsivePictureSources"; + public static final String NN_COMPONENT_MEDIA_RESPONSIVEPICTURE_SOURCES = "wcmio:mediaResponsivePictureSources"; /** * Media format property name for the parent media format. Parent media format is the original media format that diff --git a/src/main/java/io/wcm/handler/media/UriTemplate.java b/src/main/java/io/wcm/handler/media/UriTemplate.java index de774a97..60227511 100644 --- a/src/main/java/io/wcm/handler/media/UriTemplate.java +++ b/src/main/java/io/wcm/handler/media/UriTemplate.java @@ -19,6 +19,7 @@ */ package io.wcm.handler.media; +import org.jetbrains.annotations.NotNull; import org.osgi.annotation.versioning.ProviderType; /** @@ -30,11 +31,13 @@ public interface UriTemplate { /** * @return URI template string containing placeholders like {width} or {height}. */ + @NotNull String getUriTemplate(); /** * @return URI template type */ + @NotNull UriTemplateType getType(); /** diff --git a/src/main/java/io/wcm/handler/media/impl/MediaFormatValidateServlet.java b/src/main/java/io/wcm/handler/media/impl/MediaFormatValidateServlet.java index 340e698b..50106c9a 100644 --- a/src/main/java/io/wcm/handler/media/impl/MediaFormatValidateServlet.java +++ b/src/main/java/io/wcm/handler/media/impl/MediaFormatValidateServlet.java @@ -126,11 +126,15 @@ protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHtt } private String getMediaInvalidReasonI18nKeyOrMessage(@NotNull Media media) { - if (media.getMediaInvalidReason() == MediaInvalidReason.CUSTOM) { + MediaInvalidReason reason = media.getMediaInvalidReason(); + if (reason == MediaInvalidReason.CUSTOM) { return media.getMediaInvalidReasonCustomMessage(); } + else if (reason != null) { + return MEDIA_INVALID_REASON_I18N_PREFIX + reason.name(); + } else { - return MEDIA_INVALID_REASON_I18N_PREFIX + media.getMediaInvalidReason().name(); + return ""; } } diff --git a/src/main/java/io/wcm/handler/media/impl/MediaHandlerImpl.java b/src/main/java/io/wcm/handler/media/impl/MediaHandlerImpl.java index 4ad4e523..20d81d38 100644 --- a/src/main/java/io/wcm/handler/media/impl/MediaHandlerImpl.java +++ b/src/main/java/io/wcm/handler/media/impl/MediaHandlerImpl.java @@ -70,37 +70,37 @@ public final class MediaHandlerImpl implements MediaHandler { private static final Logger log = LoggerFactory.getLogger(MediaHandlerImpl.class); @Override - public @NotNull MediaBuilder get(Resource resource) { + public @NotNull MediaBuilder get(@Nullable Resource resource) { return new MediaBuilderImpl(resource, this, componentPropertyResolverFactory); } @Override - public @NotNull MediaBuilder get(Resource resource, MediaArgs mediaArgs) { + public @NotNull MediaBuilder get(@Nullable Resource resource, @NotNull MediaArgs mediaArgs) { return get(resource).args(mediaArgs); } @Override - public @NotNull MediaBuilder get(Resource resource, MediaFormat... mediaFormats) { + public @NotNull MediaBuilder get(@Nullable Resource resource, MediaFormat @NotNull... mediaFormats) { return get(resource).mediaFormats(mediaFormats); } @Override - public @NotNull MediaBuilder get(String mediaRef) { + public @NotNull MediaBuilder get(@Nullable String mediaRef) { return new MediaBuilderImpl(mediaRef, null, this, componentPropertyResolverFactory); } @Override - public @NotNull MediaBuilder get(String mediaRef, @Nullable Resource contextResource) { + public @NotNull MediaBuilder get(@Nullable String mediaRef, @Nullable Resource contextResource) { return new MediaBuilderImpl(mediaRef, contextResource, this, componentPropertyResolverFactory); } @Override - public @NotNull MediaBuilder get(String mediaRef, MediaArgs mediaArgs) { + public @NotNull MediaBuilder get(@Nullable String mediaRef, @NotNull MediaArgs mediaArgs) { return get(mediaRef).args(mediaArgs); } @Override - public @NotNull MediaBuilder get(String mediaRef, MediaFormat... mediaFormats) { + public @NotNull MediaBuilder get(@Nullable String mediaRef, MediaFormat @NotNull... mediaFormats) { return get(mediaRef).mediaFormats(mediaFormats); } diff --git a/src/main/java/io/wcm/handler/media/impl/WidthUtils.java b/src/main/java/io/wcm/handler/media/impl/WidthUtils.java index bede57f9..7071656f 100644 --- a/src/main/java/io/wcm/handler/media/impl/WidthUtils.java +++ b/src/main/java/io/wcm/handler/media/impl/WidthUtils.java @@ -27,7 +27,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.handler.media.MediaArgs.WidthOption; /** @@ -49,8 +48,7 @@ private WidthUtils() { * @param widths Width string * @return Width options */ - @SuppressFBWarnings("NP_NONNULL_RETURN_VIOLATION") - public static @NotNull WidthOption @Nullable [] parseWidths(@Nullable String widths) { + public static @Nullable WidthOption @Nullable [] parseWidths(@Nullable String widths) { if (StringUtils.isBlank(widths)) { return null; } diff --git a/src/main/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilder.java b/src/main/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilder.java index ad24bb55..96fe7e3c 100644 --- a/src/main/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilder.java +++ b/src/main/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilder.java @@ -70,9 +70,10 @@ public class SimpleImageMediaMarkupBuilder extends AbstractImageMediaMarkupBuild @Override public final boolean accepts(@NotNull Media media) { // accept if rendition is an image rendition, and resolving was successful + Rendition rendition = media.getRendition(); return media.isValid() - && media.getRendition() != null - && media.getRendition().isBrowserImage(); + && rendition != null + && rendition.isBrowserImage(); } @Override diff --git a/src/main/java/io/wcm/handler/media/spi/MediaFormatProvider.java b/src/main/java/io/wcm/handler/media/spi/MediaFormatProvider.java index c3b0c8a3..223c2642 100644 --- a/src/main/java/io/wcm/handler/media/spi/MediaFormatProvider.java +++ b/src/main/java/io/wcm/handler/media/spi/MediaFormatProvider.java @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.Set; +import org.jetbrains.annotations.NotNull; import org.osgi.annotation.versioning.ConsumerType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,7 +61,7 @@ protected MediaFormatProvider(Class type) { /** * @return Media formats that the application defines */ - public Set getMediaFormats() { + public @NotNull Set getMediaFormats() { return mediaFormats; } diff --git a/src/main/java/io/wcm/handler/media/ui/ImageUtils.java b/src/main/java/io/wcm/handler/media/ui/ImageUtils.java index 53807c38..0281a917 100644 --- a/src/main/java/io/wcm/handler/media/ui/ImageUtils.java +++ b/src/main/java/io/wcm/handler/media/ui/ImageUtils.java @@ -24,6 +24,7 @@ import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,8 +51,8 @@ private ImageUtils() { * @param medias media expressions for the picture source elements * @param widths widths for the picture source elements */ - public static void applyPictureSources(MediaFormatHandler mediaFormatHandler, MediaBuilder builder, - String[] mediaFormatNames, String[] medias, String[] widths) { + public static void applyPictureSources(@NotNull MediaFormatHandler mediaFormatHandler, @NotNull MediaBuilder builder, + String @NotNull [] mediaFormatNames, String @NotNull [] medias, String @NotNull [] widths) { for (int i = 0; i < mediaFormatNames.length && i < medias.length && i < widths.length; i++) { MediaFormat mediaFormat = mediaFormatHandler.getMediaFormat(mediaFormatNames[i]); if (mediaFormat != null) { @@ -79,7 +80,7 @@ public static void applyPictureSources(MediaFormatHandler mediaFormatHandler, Me * @param widths Widths string * @return Widths array */ - public static long[] toWidthsArray(String widths) { + public static long[] toWidthsArray(@NotNull String widths) { if (StringUtils.isBlank(widths)) { return new long[0]; } @@ -97,7 +98,7 @@ public static long[] toWidthsArray(String widths) { * @param widthOptions Width options string * @return Widths array which is empty in case given widthOptions is blank */ - public static MediaArgs.WidthOption[] toWidthOptionArray(String widthOptions) { + public static MediaArgs.WidthOption[] toWidthOptionArray(@NotNull String widthOptions) { if (StringUtils.isBlank(widthOptions)) { return new MediaArgs.WidthOption[0]; } diff --git a/src/main/java/io/wcm/handler/media/ui/MediaPlaceholder.java b/src/main/java/io/wcm/handler/media/ui/MediaPlaceholder.java index f40ba524..6c21834f 100644 --- a/src/main/java/io/wcm/handler/media/ui/MediaPlaceholder.java +++ b/src/main/java/io/wcm/handler/media/ui/MediaPlaceholder.java @@ -99,10 +99,10 @@ private String getMediaDropCssClass(Media mediaMetadata) { } private String getMediaInvalidReasonText(Media mediaMetadata) { - if (mediaMetadata.getMediaInvalidReason() != null - && mediaMetadata.getMediaInvalidReason() != MediaInvalidReason.MEDIA_REFERENCE_MISSING) { + MediaInvalidReason reason = mediaMetadata.getMediaInvalidReason(); + if (reason != null && reason != MediaInvalidReason.MEDIA_REFERENCE_MISSING) { // build i18n key - return MEDIA_INVALID_REASON_I18N_PREFIX + mediaMetadata.getMediaInvalidReason().name(); + return MEDIA_INVALID_REASON_I18N_PREFIX + reason.name(); } else { return null; diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/DamUriTemplate.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/DamUriTemplate.java index 00bee5a0..5be2e84c 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/DamUriTemplate.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/DamUriTemplate.java @@ -204,12 +204,12 @@ private static NamedDimension getDynamicMediaSmartCropDef(@Nullable CropDimensio } @Override - public UriTemplateType getType() { + public @NotNull UriTemplateType getType() { return type; } @Override - public String getUriTemplate() { + public @NotNull String getUriTemplate() { return uriTemplate; } diff --git a/src/main/java/io/wcm/handler/mediasource/dam/markup/DamVideoMediaMarkupBuilder.java b/src/main/java/io/wcm/handler/mediasource/dam/markup/DamVideoMediaMarkupBuilder.java index 4227df35..24ef6d2f 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/markup/DamVideoMediaMarkupBuilder.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/markup/DamVideoMediaMarkupBuilder.java @@ -33,6 +33,7 @@ import org.apache.sling.models.annotations.injectorspecific.Self; import org.apache.sling.models.annotations.injectorspecific.SlingObject; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.osgi.annotation.versioning.ConsumerType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -123,8 +124,12 @@ private VideoProfile getVideoProfile(String profileName) { * @param media Media metadata * @return DAM asset or null */ - protected Asset getDamAsset(Media media) { - return media.getAsset().adaptTo(Asset.class); + protected @Nullable Asset getDamAsset(Media media) { + io.wcm.handler.media.Asset asset = media.getAsset(); + if (asset != null) { + return asset.adaptTo(Asset.class); + } + return null; } @Override diff --git a/src/main/java/io/wcm/handler/mediasource/inline/InlineUriTemplate.java b/src/main/java/io/wcm/handler/mediasource/inline/InlineUriTemplate.java index 807f2517..f2e47935 100644 --- a/src/main/java/io/wcm/handler/mediasource/inline/InlineUriTemplate.java +++ b/src/main/java/io/wcm/handler/mediasource/inline/InlineUriTemplate.java @@ -99,12 +99,12 @@ private static String buildUriTemplate(@NotNull UriTemplateType type, @NotNull R } @Override - public UriTemplateType getType() { + public @NotNull UriTemplateType getType() { return type; } @Override - public String getUriTemplate() { + public @NotNull String getUriTemplate() { return uriTemplate; } diff --git a/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndTest.java b/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndTest.java index e69a861a..1cf41435 100644 --- a/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndTest.java +++ b/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndTest.java @@ -445,6 +445,7 @@ void buildAssertInvalidMedia_AutoCrop(Asset asset) { assertFalse(media.isValid(), "media valid"); } + @SuppressWarnings("null") void assertMedia(Resource resource, Media media, int width, int height, String mediaUrl, String contentType) { assertTrue(media.isValid(), "media valid"); assertEquals(mediaUrl, media.getUrl(), "mediaUrl"); diff --git a/src/test/java/io/wcm/handler/media/testcontext/UriTemplateAssert.java b/src/test/java/io/wcm/handler/media/testcontext/UriTemplateAssert.java index 797ebbf7..392ef33d 100644 --- a/src/test/java/io/wcm/handler/media/testcontext/UriTemplateAssert.java +++ b/src/test/java/io/wcm/handler/media/testcontext/UriTemplateAssert.java @@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import io.wcm.handler.media.Asset; import io.wcm.handler.media.Media; import io.wcm.handler.media.Rendition; import io.wcm.handler.media.UriTemplate; @@ -40,7 +41,9 @@ private UriTemplateAssert() { public static void assertUriTemplate(Media media, UriTemplateType type, long expectedMaxWith, long expectedMaxHeight, String expectedTemplate) { assertTrue(media.isValid(), "media valid"); - UriTemplate uriTemplate = media.getAsset().getUriTemplate(type); + Asset asset = media.getAsset(); + assertNotNull(asset); + UriTemplate uriTemplate = asset.getUriTemplate(type); assertEquals(type, uriTemplate.getType(), "uriTemplateType"); assertEquals(expectedMaxWith, uriTemplate.getMaxWidth(), "maxWidth(" + type + ")"); assertEquals(expectedMaxHeight, uriTemplate.getMaxHeight(), "maxHeight(" + type + ")"); diff --git a/src/test/java/io/wcm/handler/mediasource/dam/DamUriTemplateRenditionTest.java b/src/test/java/io/wcm/handler/mediasource/dam/DamUriTemplateRenditionTest.java index 809d8709..9bd85da9 100644 --- a/src/test/java/io/wcm/handler/mediasource/dam/DamUriTemplateRenditionTest.java +++ b/src/test/java/io/wcm/handler/mediasource/dam/DamUriTemplateRenditionTest.java @@ -88,6 +88,7 @@ void setUp() { } @Test + @SuppressWarnings("null") void testOriginal_CropCenter() { Asset asset = createSampleAsset(); Media media = mediaHandler.get(asset.getPath()) diff --git a/src/test/java/io/wcm/handler/mediasource/dam/impl/AssertThumbnailWebRenditionMediaHandlerTest.java b/src/test/java/io/wcm/handler/mediasource/dam/impl/AssertThumbnailWebRenditionMediaHandlerTest.java index 1f7265d7..f52d8deb 100644 --- a/src/test/java/io/wcm/handler/mediasource/dam/impl/AssertThumbnailWebRenditionMediaHandlerTest.java +++ b/src/test/java/io/wcm/handler/mediasource/dam/impl/AssertThumbnailWebRenditionMediaHandlerTest.java @@ -72,7 +72,7 @@ void setUp() { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings({ "deprecation", "null" }) void testWithAllowWebRenditions() { mediaHandler = AdaptTo.notNull(context.request(), MediaHandler.class); @@ -89,7 +89,7 @@ void testWithAllowWebRenditions() { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings({ "deprecation", "null" }) void testWithDisallowWebRenditions() { mediaHandler = AdaptTo.notNull(context.request(), MediaHandler.class); @@ -106,7 +106,7 @@ void testWithDisallowWebRenditions() { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings({ "deprecation", "null" }) void testWithAllowThumbnailRenditions() { mediaHandler = AdaptTo.notNull(context.request(), MediaHandler.class); @@ -123,6 +123,7 @@ void testWithAllowThumbnailRenditions() { } @Test + @SuppressWarnings("null") void testWithAllowSpecificRenditions() { mediaHandler = AdaptTo.notNull(context.request(), MediaHandler.class); @@ -139,6 +140,7 @@ void testWithAllowSpecificRenditions() { } @Test + @SuppressWarnings("null") void testWithDisallowWebRenditionsViaMediaHandlerConfig() { context.registerService(MediaHandlerConfig.class, new MediaHandlerConfig() { @Override diff --git a/src/test/java/io/wcm/handler/mediasource/dam/impl/AutoCroppingMediaHandlerTest.java b/src/test/java/io/wcm/handler/mediasource/dam/impl/AutoCroppingMediaHandlerTest.java index 1cf0da6a..bff652ba 100644 --- a/src/test/java/io/wcm/handler/mediasource/dam/impl/AutoCroppingMediaHandlerTest.java +++ b/src/test/java/io/wcm/handler/mediasource/dam/impl/AutoCroppingMediaHandlerTest.java @@ -80,6 +80,7 @@ void setUp() { } @Test + @SuppressWarnings("null") void testMediaFormatWithRatio() { Media media = mediaHandler.get(resource) .mediaFormat(RATIO_16_10) @@ -92,6 +93,7 @@ void testMediaFormatWithRatio() { } @Test + @SuppressWarnings("null") void testMediaFormatFixedDimension() { Media media = mediaHandler.get(resource) .mediaFormat(EDITORIAL_1COL) @@ -104,6 +106,7 @@ void testMediaFormatFixedDimension() { } @Test + @SuppressWarnings("null") void testMultipleMediaFormatsFixedDimension() { Media media = mediaHandler.get(resource) .mediaFormats(EDITORIAL_2COL, EDITORIAL_1COL) @@ -124,8 +127,8 @@ void testMediaFormatFixedDimension_NoMatch() { } @Test + @SuppressWarnings("null") void testManualCroppingParametersHaveHigherPrecedence() { - // prepare resource with asset reference and manual cropping parameters // this manual cropping results in a 16:10 image and should have higher precedence than auto-cropping Resource resource2 = context.create().resource("/content/test2", @@ -144,8 +147,8 @@ void testManualCroppingParametersHaveHigherPrecedence() { } @Test + @SuppressWarnings("null") void testInvalidManualCroppingParametersFallbackToAutoCropping() { - // prepare resource with asset reference and manual cropping parameters // this manual cropping results in a 1:1 image not matching the media format Resource resource2 = context.create().resource("/content/test2", @@ -165,7 +168,7 @@ void testInvalidManualCroppingParametersFallbackToAutoCropping() { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings({ "deprecation", "null" }) void testMediaFormatWithRatio_WebRenditionsExcludedFromMediaHandling() { Media media = mediaHandler.get(resource) .mediaFormat(RATIO_16_10) diff --git a/src/test/java/io/wcm/handler/mediasource/inline/InlineUriTemplateRenditionTest.java b/src/test/java/io/wcm/handler/mediasource/inline/InlineUriTemplateRenditionTest.java index 44249da9..942749e6 100644 --- a/src/test/java/io/wcm/handler/mediasource/inline/InlineUriTemplateRenditionTest.java +++ b/src/test/java/io/wcm/handler/mediasource/inline/InlineUriTemplateRenditionTest.java @@ -73,6 +73,7 @@ void setUp() { } @Test + @SuppressWarnings("null") void testOriginal_CropCenter() { Media media = mediaHandler.get(inlineImage) .mediaFormat(RATIO_16_10)