Class MimeTypeTranslationHelper
- java.lang.Object
-
- org.nuxeo.ecm.core.convert.service.MimeTypeTranslationHelper
-
public class MimeTypeTranslationHelper extends Object
Helper class to manage chains of converters.- Author:
- tiry
-
-
Field Summary
Fields Modifier and Type Field Description static String
ANY_MIME_TYPE
protected Map<String,List<ConvertOption>>
dstMappings
static Pattern
MIME_TYPE_PATTERN
protected Map<String,List<ConvertOption>>
srcMappings
-
Constructor Summary
Constructors Constructor Description MimeTypeTranslationHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addConverter(ConverterDescriptor desc)
void
clear()
protected String
computeMimeTypeWithWildcardSubType(String mimeType)
Returns a new mime type with the primary type of the givenmimeType
and a wildcard sub type.protected List<String>
doGetConverterNames(String sourceMimeType, String destinationMimeType)
Returns the list of converter names matching exactly the givensourceMimeType
anddestinationMimeType
.String
getConverterName(String sourceMimeType, String destinationMimeType)
Returns the last registered converter name for the givensourceMimeType
anddestinationMimeType
.String
getConverterName(String sourceMimeType, String destinationMimeType, boolean allowWildcard)
Returns the last registered converter name for the givensourceMimeType
anddestinationMimeType
.List<String>
getConverterNames(String sourceMimeType, String destinationMimeType)
Returns the list of converter names handling the givensourceMimeType
anddestinationMimeType
.List<String>
getConverterNames(String sourceMimeType, String destinationMimeType, boolean allowWildcard)
Returns the list of converter names handling the givensourceMimeType
anddestinationMimeType
.List<String>
getDestinationMimeTypes(String sourceMimeType)
Deprecated.since 10.3.List<String>
getSourceMimeTypes(String destinationMimeType)
Deprecated.since 10.3.boolean
hasCompatibleMimeType(List<String> mimeTypes, String mimeType)
Returnstrue
if the givenmimeTypes
has a compatible mime type withmimeType
,false
otherwise.protected String
parseMimeType(String mimeType)
Parses the givenmimeType
and returns only the primary type and optionally the sub type if any.
-
-
-
Field Detail
-
ANY_MIME_TYPE
public static final String ANY_MIME_TYPE
- Since:
- 10.3
- See Also:
- Constant Field Values
-
MIME_TYPE_PATTERN
public static final Pattern MIME_TYPE_PATTERN
- Since:
- 10.3
-
srcMappings
protected final Map<String,List<ConvertOption>> srcMappings
-
dstMappings
protected final Map<String,List<ConvertOption>> dstMappings
-
-
Method Detail
-
addConverter
public void addConverter(ConverterDescriptor desc)
-
getConverterName
public String getConverterName(String sourceMimeType, String destinationMimeType)
Returns the last registered converter name for the givensourceMimeType
anddestinationMimeType
.Follows the algorithm of
getConverterNames(String, String)
.
-
getConverterName
public String getConverterName(String sourceMimeType, String destinationMimeType, boolean allowWildcard)
Returns the last registered converter name for the givensourceMimeType
anddestinationMimeType
.Follows the algorithm of
getConverterNames(String, String, boolean)
.- Since:
- 11.1
- See Also:
getConverterNames(String, String, boolean)
-
hasCompatibleMimeType
public boolean hasCompatibleMimeType(List<String> mimeTypes, String mimeType)
Returnstrue
if the givenmimeTypes
has a compatible mime type withmimeType
,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)
Returns the list of converter names handling the givensourceMimeType
anddestinationMimeType
.
-
getConverterNames
public List<String> getConverterNames(String sourceMimeType, String destinationMimeType, boolean allowWildcard)
Returns the list of converter names handling the givensourceMimeType
anddestinationMimeType
.Finds the converter names based on the following algorithm:
- Find the converters exactly matching the given
sourceMimeType
and matching the givendestinationMimeType
- If no converter found, find the converters matching a wildcard subtype based on the
sourceMimeType
, such has "image/*", and matching the givendestinationMimeType
- If no converter found and
allowWildcard
istrue
, find the converters matching a wildcard source mime type "*" and matching the givendestinationMimeType
- Parameters:
allowWildcard
-true
to allow returning converters with '*' as source mime type.- Since:
- 11.1
- Find the converters exactly matching the given
-
parseMimeType
protected String parseMimeType(String mimeType)
Parses the givenmimeType
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 givenmimeType
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 givensourceMimeType
anddestinationMimeType
.- 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()
-
-