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 AbstractImageMediaMarkupBuilder
Basic implementation ofMediaMarkupBuilder
for images.If image sizes or picture sources are set on the media handler this markup builder also generates markup for responsive images using
img
withsizes
andsrcset
attributes orpicture
withsource
elements.
-
-
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 boolean
accepts(@NotNull Media media)
Checks whether this builder can generate markup for the given media.protected @Nullable io.wcm.handler.commons.dom.HtmlElement
applyImageMap(@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.HtmlElement
build(@NotNull Media media)
Build media element markupprotected @NotNull java.lang.String
buildImageMapName(@NotNull java.util.List<ImageMapArea> map, @NotNull Media media)
Builds an ID for the image map that is unique within the page.protected @Nullable MediaFormat
getFirstMediaFormat(@NotNull Media media)
Get first media format from the resolved media renditions.protected @Nullable MediaFormat
getFirstMediaFormatWithRatio(@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.HtmlElement
getImageElement(@NotNull Media media)
Create animg
element that displays the given rendition image.protected @Nullable io.wcm.handler.commons.dom.HtmlElement
getMediaElement(@NotNull Media media)
Createimg
orpicture
media element.protected @Nullable io.wcm.handler.commons.dom.HtmlElement
getPictureElement(@NotNull Media media)
Create animg
element that displays the given rendition image.protected @Nullable java.lang.String
getSrcSetRenditions(@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.String
getSrcSetRenditions(@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.boolean
isValidMedia(@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:MediaMarkupBuilder
Checks 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:MediaMarkupBuilder
Build 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)
Createimg
orpicture
media 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 animg
element that displays the given rendition image.- Parameters:
media
- Media metadata- Returns:
img
element 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 animg
element that displays the given rendition image.- Parameters:
media
- Media metadata- Returns:
img
element 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:MediaMarkupBuilder
Checks 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
-
-