Package io.wcm.handler.media.markup
Class SimpleImageMediaMarkupBuilder
- java.lang.Object
-
- io.wcm.handler.media.markup.AbstractImageMediaMarkupBuilder
-
- io.wcm.handler.media.markup.SimpleImageMediaMarkupBuilder
-
- All Implemented Interfaces:
MediaMarkupBuilder
@Model(adaptables={org.apache.sling.api.SlingHttpServletRequest.class,org.apache.sling.api.resource.Resource.class}) @ConsumerType public class SimpleImageMediaMarkupBuilder extends AbstractImageMediaMarkupBuilderBasic implementation ofMediaMarkupBuilderfor images.If image sizes or picture sources are set on the media handler this markup builder also generates markup for responsive images using
imgwithsizesandsrcsetattributes orpicturewithsourceelements.
-
-
Field Summary
-
Fields inherited from interface io.wcm.handler.media.spi.MediaMarkupBuilder
DUMMY_IMAGE, DUMMY_MIN_DIMENSION
-
-
Constructor Summary
Constructors Constructor Description SimpleImageMediaMarkupBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaccepts(@NotNull Media media)Checks whether this builder can generate markup for the given media.protected @Nullable io.wcm.handler.commons.dom.HtmlElementapplyImageMap(@Nullable io.wcm.handler.commons.dom.HtmlElement element, @NotNull Media media)If a image map was resolved apply map markup to given image element.io.wcm.handler.commons.dom.HtmlElementbuild(@NotNull Media media)Build media element markupprotected @NotNull java.lang.StringbuildImageMapName(@NotNull java.util.List<ImageMapArea> map, @NotNull Media media)Builds an ID for the image map that is unique within the page.protected @Nullable MediaFormatgetFirstMediaFormat(@NotNull Media media)Get first media format from the resolved media renditions.protected @Nullable MediaFormatgetFirstMediaFormatWithRatio(@NotNull Media media)Get first media format from the media formats of the media args that has a ratio set.protected @Nullable io.wcm.handler.commons.dom.HtmlElementgetImageElement(@NotNull Media media)Create animgelement that displays the given rendition image.protected @Nullable io.wcm.handler.commons.dom.HtmlElementgetMediaElement(@NotNull Media media)Createimgorpicturemedia element.protected @Nullable io.wcm.handler.commons.dom.HtmlElementgetPictureElement(@NotNull Media media)Create animgelement that displays the given rendition image.protected @Nullable java.lang.StringgetSrcSetRenditions(@NotNull Media media, @NotNull MediaFormat mediaFormat, long @NotNull ... widths)Generate srcset list from the resolved renditions for the ratio of the given media formats and the given widths.protected @Nullable java.lang.StringgetSrcSetRenditions(@NotNull Media media, @NotNull MediaFormat mediaFormat, @NotNull MediaArgs.WidthOption @Nullable ... widths)Generate srcset list from the resolved renditions for the ratio of the given media formats and the given widths.booleanisValidMedia(@NotNull io.wcm.handler.commons.dom.HtmlElement element)Checks if the given HTML element is valid.-
Methods inherited from class io.wcm.handler.media.markup.AbstractImageMediaMarkupBuilder
applyWcmMarkup, getRequest, getWcmMode, setAdditionalAttributes
-
-
-
-
Method Detail
-
accepts
public final boolean accepts(@NotNull @NotNull Media media)Description copied from interface:MediaMarkupBuilderChecks whether this builder can generate markup for the given media.- Parameters:
media- Media metadata- Returns:
- true if this markup builder can handle the given media
-
build
public final io.wcm.handler.commons.dom.HtmlElement build(@NotNull @NotNull Media media)Description copied from interface:MediaMarkupBuilderBuild media element markup- Parameters:
media- Media metadata- Returns:
- Media element or null if media is invalid
-
getMediaElement
@Nullable protected @Nullable io.wcm.handler.commons.dom.HtmlElement getMediaElement(@NotNull @NotNull Media media)Createimgorpicturemedia element.- Parameters:
media- Media metadata- Returns:
- Media element with properties or null if media metadata is invalid
-
getPictureElement
@Nullable protected @Nullable io.wcm.handler.commons.dom.HtmlElement getPictureElement(@NotNull @NotNull Media media)Create animgelement that displays the given rendition image.- Parameters:
media- Media metadata- Returns:
imgelement with properties or null if media metadata is invalid
-
getImageElement
@Nullable protected @Nullable io.wcm.handler.commons.dom.HtmlElement getImageElement(@NotNull @NotNull Media media)Create animgelement that displays the given rendition image.- Parameters:
media- Media metadata- Returns:
imgelement with properties or null if media metadata is invalid
-
getSrcSetRenditions
@Nullable protected @Nullable java.lang.String getSrcSetRenditions(@NotNull @NotNull Media media, @NotNull @NotNull MediaFormat mediaFormat, @NotNull @NotNull MediaArgs.WidthOption @Nullable ... widths)Generate srcset list from the resolved renditions for the ratio of the given media formats and the given widths. Widths that have no match are ignored.- Parameters:
media- MediamediaFormat- Media formatwidths- widths- Returns:
- srcset String or null if no matching renditions found
-
getSrcSetRenditions
@Nullable protected @Nullable java.lang.String getSrcSetRenditions(@NotNull @NotNull Media media, @NotNull @NotNull MediaFormat mediaFormat, long @NotNull ... widths)Generate srcset list from the resolved renditions for the ratio of the given media formats and the given widths. Widths that have no match are ignored.- Parameters:
media- MediamediaFormat- Media formatwidths- widths- Returns:
- srcset String or null if no matching renditions found
-
getFirstMediaFormatWithRatio
@Nullable protected final @Nullable MediaFormat getFirstMediaFormatWithRatio(@NotNull @NotNull Media media)
Get first media format from the media formats of the media args that has a ratio set.- Parameters:
media- Media- Returns:
- Media format or null if none found
-
getFirstMediaFormat
@Nullable protected final @Nullable MediaFormat getFirstMediaFormat(@NotNull @NotNull Media media)
Get first media format from the resolved media renditions.- Parameters:
media- Media- Returns:
- Media format or null if none found
-
applyImageMap
@Nullable protected final @Nullable io.wcm.handler.commons.dom.HtmlElement applyImageMap(@Nullable @Nullable io.wcm.handler.commons.dom.HtmlElement element, @NotNull @NotNull Media media)If a image map was resolved apply map markup to given image element. As a result both image and map markup are wrapped in a span element.- Parameters:
element- Image Elementmedia- Media- Returns:
- Unchanged element or wrapped element with map
-
buildImageMapName
@NotNull protected final @NotNull java.lang.String buildImageMapName(@NotNull @NotNull java.util.List<ImageMapArea> map, @NotNull @NotNull Media media)Builds an ID for the image map that is unique within the page.- Parameters:
map- Map datamedia- Media- Returns:
- Unique ID
-
isValidMedia
public final boolean isValidMedia(@NotNull @NotNull io.wcm.handler.commons.dom.HtmlElement element)Description copied from interface:MediaMarkupBuilderChecks if the given HTML element is valid. It is treated as invalid if it is null, or if it is a simple IMG element containing the dummy image.- Parameters:
element- Media markup element.- Returns:
- true if media element is invalid
-
-