Class MimeTypeTranslationHelper


  • public class MimeTypeTranslationHelper
    extends Object
    Helper class to manage chains of converters.
    Author:
    tiry
    • Constructor Detail

      • MimeTypeTranslationHelper

        public MimeTypeTranslationHelper()
    • Method Detail

      • hasCompatibleMimeType

        public boolean hasCompatibleMimeType​(List<String> mimeTypes,
                                             String mimeType)
        Returns true if the given mimeTypes has a compatible mime type with mimeType, false otherwise.

        The mimeTypes list has a compatible mime type if:

        • it contains "*"
        • it contains exactly mimeType
        • it contains a mime type with the same primary type as mimeType and a wildcard sub type
        Since:
        10.3
      • getConverterNames

        public List<String> getConverterNames​(String sourceMimeType,
                                              String destinationMimeType,
                                              boolean allowWildcard)
        Returns the list of converter names handling the given sourceMimeType and destinationMimeType.

        Finds the converter names based on the following algorithm:

        • Find the converters exactly matching the given sourceMimeType and matching the given destinationMimeType
        • If no converter found, find the converters matching a wildcard subtype based on the sourceMimeType, such has "image/*", and matching the given destinationMimeType
        • If no converter found and allowWildcard is true, find the converters matching a wildcard source mime type "*" and matching the given destinationMimeType
        Parameters:
        allowWildcard - true to allow returning converters with '*' as source mime type.
        Since:
        11.1
      • parseMimeType

        protected String parseMimeType​(String mimeType)
        Parses the given mimeType and returns only the primary type and optionally the sub type if any.

        Some input/output samples:

        • "image/jpeg" => "image/jpeg"
        • "image/*" => "image/*"
        • "image/png; param1=foo; param2=bar" => "image/png"
        Since:
        10.3
      • computeMimeTypeWithWildcardSubType

        protected String computeMimeTypeWithWildcardSubType​(String mimeType)
        Returns a new mime type with the primary type of the given mimeType and a wildcard sub type.

        Some input/output samples:

        • "image/jpeg" => "image/*"
        • "video/*" => "video/*"
        • "application/pdf" => "application/*"
        Since:
        10.3
      • doGetConverterNames

        protected List<String> doGetConverterNames​(String sourceMimeType,
                                                   String destinationMimeType)
        Returns the list of converter names matching exactly the given sourceMimeType and destinationMimeType.
        Since:
        11.5
      • getDestinationMimeTypes

        @Deprecated
        public List<String> getDestinationMimeTypes​(String sourceMimeType)
        Deprecated.
        since 10.3. Not used.
      • getSourceMimeTypes

        @Deprecated
        public List<String> getSourceMimeTypes​(String destinationMimeType)
        Deprecated.
        since 10.3. Not used.
      • clear

        public void clear()