Copyright© 2008-2025 Sitevision AB, all rights reserved.
@Requireable(value="MimeTypeUtil") public interface MimeTypeUtil extends VelocityAccess.MimeTypeUtilConstants
An instance of the Sitevision class implementing this interface can be obtained via Utils.getMimeTypeUtil().
See Utils for how to obtain an instance of the Utils interface.
| Modifier and Type | Field and Description |
|---|---|
static String |
GENERIC_MIME_TYPE
The generic
application/octet-stream MIME type. |
| Modifier and Type | Method and Description |
|---|---|
String |
getExtension(String aMimeType)
Returns the file extension for a specified MIME type.
|
String |
getExtension(String aMimeType,
String aFallbackExtension)
Returns the file extension (or a fallback extension) for a specified MIME type.
|
String |
getMimeType(String aFileExtensionExpression)
Returns the MIME type appropriate for a specified file extension.
|
String |
getMimeType(String aFileExtensionExpression,
String aFallbackMimeType)
Returns the MIME type (or a fallback MIME type) appropriate for a specified file extension.
|
boolean |
isAudioType(String aFileExtensionExpression)
Checks if a specified file extension is an audio type (according to its mapped MIME type).
|
boolean |
isCompressedType(String aFileExtensionExpression)
Checks if a specified file extension is a compressed/archive type (according to its mapped MIME type).
|
boolean |
isFontType(String aFileExtensionExpression)
Checks if a specified file extension is a font type (according to its mapped MIME type).
|
boolean |
isImageType(String aFileExtensionExpression)
Checks if a specified file extension is an image type (according to its mapped MIME type).
|
boolean |
isJsonMime(String aMimeType)
Checks if a specified MIME type depicts the JSON format.
|
boolean |
isJsonType(String aFileExtensionExpression)
Checks if a specified file extension is a JSON type (according to its mapped MIME type).
|
boolean |
isMSExcelType(String aFileExtensionExpression)
Checks if a specified file extension is a MS Excel type (according to its mapped MIME type).
|
boolean |
isMSOfficeType(String aFileExtensionExpression)
Checks if a specified file extension is a MS Office type (according to its mapped MIME type).
|
boolean |
isMSPowerpointType(String aFileExtensionExpression)
Checks if a specified file extension is a MS Powerpoint type (according to its mapped MIME type).
|
boolean |
isMSWordType(String aFileExtensionExpression)
Checks if a specified file extension is a MS Word type (according to its mapped MIME type).
|
boolean |
isTextType(String aFileExtensionExpression)
Checks if a specified file extension is a text type (according to its mapped MIME type).
|
boolean |
isVideoType(String aFileExtensionExpression)
Checks if a specified file extension is a video type (according to its mapped MIME type).
|
boolean |
isXmlType(String aFileExtensionExpression)
Checks if a specified file extension is a text type (according to its mapped MIME type).
|
getGENERIC_MIME_TYPEstatic final String GENERIC_MIME_TYPE
application/octet-stream MIME type.
Would typically be appropriate to use as value for the fallback MIME type when using the
getMimeType(String, String) whenever you require an acceptable, non-null MIME type to be returned.
String mime = aMimeTypeUtil.getMimeType(anExtension, MimeTypeUtil.GENERIC_MIME_TYPE);String getMimeType(String aFileExtensionExpression)
aFileExtensionExpression - a file extension (e.g pdf) or an expression that ends with a period and a file extension
(e.g myfile.pdf or http://www.xyz.com/files/myfile.pdf). Case insensitive.aFileExtensionExpression, or null if
extension is unknowngetMimeType(String, String)String getMimeType(String aFileExtensionExpression, String aFallbackMimeType)
aFileExtensionExpression - a file extension (e.g pdf) or an expression that ends with a period and a file extension
(e.g myfile.pdf or http://www.xyz.com/files/myfile.pdf). Case insensitive.aFallbackMimeType - the fallback MIME type to return if no MIME type can be found for aFileExtensionExpressionaFileExtensionExpression, or aFallbackMimeType if
extension is unknownString getExtension(String aMimeType)
aMimeType - a MIME type. Case insensitive.aMimeType, or null if
aMimeType is unknown or has no single well-known extension (e.g. application/octet-stream or text/plain)getExtension(String, String)String getExtension(String aMimeType, String aFallbackExtension)
aMimeType - a MIME type. Case insensitive.aFallbackExtension - the fallback extension to return if no extension can be found for aMimeTypeaMimeType, or aFallbackExtension if
aMimeType is unknown or has no single well-known extension (e.g. application/octet-stream or text/plain)boolean isImageType(String aFileExtensionExpression)
An image type has a MIME that starts with image/.
aFileExtensionExpression - a file extension (e.g png) or an expression that ends with a period and a file extension
(e.g myresource.png or http://www.xyz.com/files/myresource.png). Case insensitive.aFileExtensionExpression is mapped to a image/* MIME type, false otherwiseboolean isTextType(String aFileExtensionExpression)
A text type has a MIME that starts with "text/".
aFileExtensionExpression - a file extension (e.g txt) or an expression that ends with a period and a file extension
(e.g myresource.txt or http://www.xyz.com/files/myresource.txt). Case insensitive.aFileExtensionExpression is mapped to a text/* MIME type, false otherwiseboolean isXmlType(String aFileExtensionExpression)
A XML type typically has a MIME that starts with "application/" and ends with "xml".
This method will not include xml-based files covered by other categories (e.g. "office" types or the "svg" image type).
aFileExtensionExpression - a file extension (e.g xml) or an expression that ends with a period and a file extension
(e.g myresource.xml or http://www.xyz.com/files/myresource.xml). Case insensitive.aFileExtensionExpression is mapped to a application/*xml MIME type, false otherwiseboolean isVideoType(String aFileExtensionExpression)
A video type has a MIME that starts with "video/".
aFileExtensionExpression - a file extension (e.g mov) or an expression that ends with a period and a file extension
(e.g myresource.mov or http://www.xyz.com/files/myresource.mov). Case insensitive.aFileExtensionExpression is mapped to a video/* MIME type, false otherwiseboolean isCompressedType(String aFileExtensionExpression)
Example of compressed MIME types:
aFileExtensionExpression - a file extension (e.g zip) or an expression that ends with a period and a file extension
(e.g myresource.zip or http://www.xyz.com/files/myresource.zip). Case insensitive.aFileExtensionExpression is mapped to a MIME type that is registered as compressed, false otherwiseboolean isMSWordType(String aFileExtensionExpression)
Example of typical MS Word MIME types:
aFileExtensionExpression - a file extension (e.g doc) or an expression that ends with a period and a file extension
(e.g myresource.doc or http://www.xyz.com/files/myresource.doc). Case insensitive.aFileExtensionExpression is mapped to a MS Word MIME type, false otherwiseboolean isMSExcelType(String aFileExtensionExpression)
Example of typical MS Excel MIME types:
aFileExtensionExpression - a file extension (e.g xls) or an expression that ends with a period and a file extension
(e.g myresource.xls or http://www.xyz.com/files/myresource.xls). Case insensitive.aFileExtensionExpression is mapped to a MS Excel MIME type, false otherwiseboolean isMSPowerpointType(String aFileExtensionExpression)
Example of typical MS Powerpoint MIME types:
aFileExtensionExpression - a file extension (e.g ppt) or an expression that ends with a period and a file extension
(e.g myresource.ppt or http://www.xyz.com/files/myresource.ppt). Case insensitive.aFileExtensionExpression is mapped to a MS Powerpoint MIME type, false otherwiseboolean isMSOfficeType(String aFileExtensionExpression)
This is a convenience method that checks if aFileExtensionExpression is mapped to a MS Word/Excel/Powerpoint MIME type.
(i.e. a combination of isMSWordType(String), isMSExcelType(String) and isMSPowerpointType(String))
aFileExtensionExpression - a file extension (e.g doc) or an expression that ends with a period and a file extension
(e.g myresource.xls or http://www.xyz.com/files/myresource.ppt). Case insensitive.aFileExtensionExpression is mapped to a MS Word/Excel/Powerpoint MIME type, false otherwiseboolean isFontType(String aFileExtensionExpression)
Example of typical font MIME types:
aFileExtensionExpression - a file extension (e.g woff2) or an expression that ends with a period and a file extension
(e.g myresource.woff2 or http://www.xyz.com/files/myresource.woff2). Case insensitive.boolean isAudioType(String aFileExtensionExpression)
An audio type has a MIME that starts with "audio/".
aFileExtensionExpression - a file extension (e.g wav) or an expression that ends with a period and a file extension
(e.g myresource.wav or http://www.xyz.com/files/myresource.wav). Case insensitive.aFileExtensionExpression is mapped to a audio/* MIME type, false otherwiseboolean isJsonType(String aFileExtensionExpression)
aFileExtensionExpression - a file extension (e.g "json") or an expression that ends with a period and a file extension
(e.g "myfile.json" or "https://www.xyz.com/files/myfile.json"). Case insensitive.isJsonMime(String)boolean isJsonMime(String aMimeType)
The primary JSON format MIME is "application/json" and should always be handled as UTF-8 text. Other MIME:s that uses the JSON
format typically has a "+json" suffix (see RFC 6839)
or a "+json-seq" suffix (see RFC 8091). But there
are also some legacy/unofficial MIME:s that also depicts the JSON format (e.g. "text/json", "application/jsonrequest").
Example of typical MIME types that depicts the JSON format:
A Content-Type header value for a JSON response is typically "application/json; charset=utf-8".
This method handles such values, only the leading MIME part will be checked (any semicolon suffix part will be completely ignored).
aMimeType - a MIME value or Content-Type header valueSitevision - Content Management Made Easy
Sitevision is an advanced Java enterprise portal product that implements Java Content Repository (JSR 283).
Copyright© 2008-2025 Sitevision AB, all rights reserved.