Class PrefixRenditionPicker

  • All Implemented Interfaces:
    RenditionPicker

    public class PrefixRenditionPicker
    extends java.lang.Object
    implements RenditionPicker
    A RenditionPicker that picks the first rendition found which name starts with a given prefix.
    • Constructor Summary

      Constructors 
      Constructor Description
      PrefixRenditionPicker​(java.lang.String startsWith)
      Picks the first rendition found which name starts with the given prefix.
      PrefixRenditionPicker​(java.lang.String prefix, boolean returnOriginal)
      Picks the first rendition found which name starts with the given prefix.
    • Constructor Detail

      • PrefixRenditionPicker

        public PrefixRenditionPicker​(java.lang.String startsWith)
        Picks the first rendition found which name starts with the given prefix. If no matching rendition was found, null will be returned.
        Parameters:
        startsWith - the name prefix to match
      • PrefixRenditionPicker

        public PrefixRenditionPicker​(java.lang.String prefix,
                                     boolean returnOriginal)
        Picks the first rendition found which name starts with the given prefix. It can be defined what to return if no matching rendition was found (original rendition or null).
        Parameters:
        prefix - the name prefix to match
        returnOriginal - if true, will return the original rendition if no matching rendition was found, otherwise the picker will return null
    • Method Detail

      • getRendition

        public Rendition getRendition​(Asset asset)
        Description copied from interface: RenditionPicker
        Returns the desired rendition Rendition if existing, otherwise null.

        Implementations are free to decide which rendition is chosen when this method is called.

        The rendition shall be searched for within the given Asset.

        Example implementation:

          ...
          public Resource getRendition(Asset asset) {
              // 1. try to get a web enabled rendition
              List<Resource> renditions = asset.getRenditions();
              for (Resource rendition: renditions) {
                  if (Text.getName(rendition.getPath()).startsWith("cq5dam.web.")) {
                      return rendition;
                  }
              }
              // 2. return current rendition
              return asset.getCurrentOriginal();
          }
          ...
         
        Specified by:
        getRendition in interface RenditionPicker
        Parameters:
        asset - The Asset within which to search the rendition.
        Returns:
        the desired rendition if existing, otherwise null
      • getRendition

        public Rendition getRendition​(java.util.Iterator<Rendition> renditions)