Package com.saperion.ngc.util
Class MimeUtil
java.lang.Object
com.saperion.ngc.util.MimeUtil
This MimiUtil can be used to get a MIME type by filenames in a convenient
way. Use it like this: MimeUtil.getMimeType("myFile.pdf").
- Author:
- sts
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The default MIME type to be used if no MIME type matches.protected static javax.activation.MimetypesFileTypeMap
The MimetypesFileTypeMap used by this util. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
decodeFilename
(jakarta.servlet.http.HttpServletRequest request, String filename) Decodes a filename decoded by theencodeFilename(HttpServletRequest, String)
method.static String
decodeFilename
(String filename) Decodes a filename encoded by theencodeFilename(String)
method.static String
encodeFilename
(jakarta.servlet.http.HttpServletRequest request, String filename) Encodes a filename so that it is save for downloading in different browsers.static String
encodeFilename
(String filename) Encodes a filename so that it is save for downloading in different browsers.static String
getMimeType
(String filename) Returns the MIME type matching the given filename.protected static void
Initializes the MimetypesFileTypeMap used by this util.
-
Field Details
-
DEFAULT_MIMETYPE
The default MIME type to be used if no MIME type matches.- See Also:
-
mimeMap
protected static javax.activation.MimetypesFileTypeMap mimeMapThe MimetypesFileTypeMap used by this util.
-
-
Method Details
-
initialize
protected static void initialize()Initializes the MimetypesFileTypeMap used by this util. -
getMimeType
Returns the MIME type matching the given filename.- Parameters:
filename
- The filename to get the MIME type of.- Returns:
- the MIME type or "application/octet-stream" if no matching MIME could be found or the util could not be initialized properly.
-
encodeFilename
Encodes a filename so that it is save for downloading in different browsers. For Internet Explorer, UTF-8 will be used. For other browsers, the filename will be encoded according to RFC 2047. This method can be called from within ZK-context only.- Parameters:
filename
- the filename to encode- Returns:
- the encoded filename
- Throws:
UnsupportedEncodingException
- if the encoding used to encode the filename is unknown
-
decodeFilename
Decodes a filename encoded by theencodeFilename(String)
method.- Parameters:
filename
- the filename to decoded- Returns:
- the decoded filename
- Throws:
UnsupportedEncodingException
- if the encoding used to decode the filename is unknown
-
encodeFilename
public static String encodeFilename(jakarta.servlet.http.HttpServletRequest request, String filename) throws UnsupportedEncodingException Encodes a filename so that it is save for downloading in different browsers. For Internet Explorer, UTF-8 will be used. For other browsers, the filename will be encoded according to RFC 2047. This method can be called from without ZK-context.- Parameters:
request
- the current requestfilename
- the filename to encode- Returns:
- the encoded filename
- Throws:
UnsupportedEncodingException
- if the encoding used to encode the filename is unknown
-
decodeFilename
public static String decodeFilename(jakarta.servlet.http.HttpServletRequest request, String filename) throws UnsupportedEncodingException Decodes a filename decoded by theencodeFilename(HttpServletRequest, String)
method.- Parameters:
request
- the current requestfilename
- the filename to decoded- Returns:
- the decoded filename
- Throws:
UnsupportedEncodingException
- if the encoding used to decode the filename is unknown
-