Class ResourceMedia

java.lang.Object
io.wcm.handler.media.ui.ResourceMedia

@Model(adaptables=org.apache.sling.api.SlingHttpServletRequest.class) public class ResourceMedia extends Object
Generic resource-based media model.

Optional use parameters when referencing model from Sightly template:

  • mediaFormat: Media format name to restrict the allowed media items
  • refProperty: Name of the property from which the media reference path is read, or node name for inline media.
  • cropProperty: Name of the property which contains the cropping parameters
  • rotationProperty: Name of the property which contains the rotation parameter
  • cssClass: CSS classes to be applied on the generated media element (most cases img element)
  • autoCrop: Sets the auto cropping behavior of the media handler. This will override the component property "wcmio:mediaCropAuto".
  • imageWidths: Responsive rendition widths for image. Example: "2560?,1920,?1280,640,320".
    Appending the suffix "?" makes the width optional, e.g. "1440?"
    Pixel density descriptors can be added with a colon separator, e.g. "1440:2x?". Default density is 1x.
    Use always 'imageWidths' together with 'imageSizes' property unless you add pixel density descriptors.
    Cannot be used together with the picture source parameters.
  • imageSizes: "Sizes" string for img element. Example: "(min-width: 400px) 400px, 100vw".
    Cannot be used together with the picture source parameters.
  • pictureSourceMediaFormat: List of media formats for the picture source elements. Example: "['mf_16_9','mf_4_3']"
    You have to define the same number of array items in all pictureSource* properties.
    Cannot be used together with image sizes.
  • pictureSourceMedia: List of media expressions for the picture source elements. Example: "['(max-width: 799px)', '(min-width: 800px)']"
    You have to define the same number of array items in all pictureSource* properties.
    Cannot be used together with image sizes.
  • pictureSourceWidths: List of widths for the picture source elements. Example: "['479,719,959,1279,1439?,1440?','640,1200:2x?']".
    Appending the suffix "?" makes the width optional, e.g. "1440?"
    Pixel density descriptors can be added with a colon separator, e.g. "1440:2x?". Default density is 1x.
    You have to define the same number of array items in all pictureSource* properties.
    Cannot be used together with image sizes.
  • property:<propertyname>: Custom properties for MediaArgs can be added with the name prefix "property:", e.g. "property:myprop1"="value1" which adds property "myprop1" to the MediaArgs. Custom properties with null value will be ignored.
  • Constructor Details

    • ResourceMedia

      public ResourceMedia()
  • Method Details

    • getMetadata

      @NotNull public @NotNull Media getMetadata()
      Returns a Media object with the metadata of the resolved media. Result is never null, check for validness with the Media.isValid() method.
      Returns:
      Media
    • isValid

      public boolean isValid()
      Returns true if the media was resolved successful.
      Returns:
      Media is valid
    • getMarkup

      @Nullable public @Nullable String getMarkup()
      Returns the XHTML markup for the resolved media object (if valid). This is in most cases an img element, but may also contain other arbitrary markup.
      Returns:
      Media markup