Interface MediaFormatHandler


  • @ProviderType
    public interface MediaFormatHandler
    Media format handling.

    The interface is implemented by a Sling Model. You can adapt from SlingHttpServletRequest or Resource to get a context-specific handler instance.

    • Field Detail

      • RATIO_TOLERANCE

        static final double RATIO_TOLERANCE
        When comparing the ratio's of different media formats for automatic rendition generation, use this value as tolerance barrier when comparing ratios of different media formats.
        See Also:
        Constant Field Values
    • Method Detail

      • getMediaFormat

        @Nullable
        @Nullable MediaFormat getMediaFormat​(@NotNull
                                             @NotNull String mediaFormatName)
        Resolves media format name to media format object.
        Parameters:
        mediaFormatName - Media format name
        Returns:
        Media format or null if no match found
      • getMediaFormats

        @NotNull
        @NotNull SortedSet<MediaFormat> getMediaFormats()
        Get media formats defined by a CMS application that is responsible for the given media library path.
        Returns:
        Media formats sorted by combined title
      • getMediaFormats

        @NotNull
        @NotNull SortedSet<MediaFormat> getMediaFormats​(@NotNull
                                                        @NotNull Comparator<MediaFormat> comparator)
        Get media formats defined by a CMS application that is responsible for the given media library path.
        Parameters:
        comparator - Comparator for set
        Returns:
        Media formats
      • getSameBiggerMediaFormats

        @NotNull
        @NotNull SortedSet<MediaFormat> getSameBiggerMediaFormats​(@NotNull
                                                                  @NotNull MediaFormat mediaFormatRequested,
                                                                  boolean filterRenditionGroup)
        Get list of media formats that have the same (or bigger) resolution as the requested media format and (nearly) the same aspect ratio.
        Parameters:
        mediaFormatRequested - Requested media format
        filterRenditionGroup - Only check media formats of the same rendition group.
        Returns:
        Matching media formats, sorted by size (biggest first), ranking, name
      • getSameSmallerMediaFormats

        @NotNull
        @NotNull SortedSet<MediaFormat> getSameSmallerMediaFormats​(@NotNull
                                                                   @NotNull MediaFormat mediaFormatRequested,
                                                                   boolean filterRenditionGroup)
        Get list of possible media formats that can be rendered from the given media format, i.e. same size or smaller and (nearly) the same aspect ratio.
        Parameters:
        mediaFormatRequested - Available media format
        filterRenditionGroup - Only check media formats of the same rendition group.
        Returns:
        Matching media formats, sorted by size (biggest first), ranking, name
      • detectMediaFormat

        @Nullable
        @Nullable MediaFormat detectMediaFormat​(@Nullable
                                                @Nullable String extension,
                                                long fileSize,
                                                long width,
                                                long height)
        Detect matching media format.
        Parameters:
        extension - File extension
        fileSize - File size
        width - Image width (or 0 if not image)
        height - Image height (or 0 if not image)
        Returns:
        Media format or null if no matching media format found
      • detectMediaFormats

        @NotNull
        @NotNull SortedSet<MediaFormat> detectMediaFormats​(@Nullable
                                                           @Nullable String extension,
                                                           long fileSize,
                                                           long width,
                                                           long height)
        Detect all matching media formats.
        Parameters:
        extension - File extension
        fileSize - File size
        width - Image width (or 0 if not image)
        height - Image height (or 0 if not image)
        Returns:
        Matching media formats sorted by their ranking or an empty list if no matching format was found