Package com.saperion.ngc.util
Class MimeUtil
- java.lang.Object
-
- com.saperion.ngc.util.MimeUtil
-
public final class MimeUtil extends java.lang.ObjectThis 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
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_MIMETYPEThe default MIME type to be used if no MIME type matches.protected static javax.activation.MimetypesFileTypeMapmimeMapThe MimetypesFileTypeMap used by this util.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringdecodeFilename(java.lang.String filename)Decodes a filename encoded by theencodeFilename(String)method.static java.lang.StringdecodeFilename(javax.servlet.http.HttpServletRequest request, java.lang.String filename)Decodes a filename decoded by theencodeFilename(HttpServletRequest, String)method.static java.lang.StringencodeFilename(java.lang.String filename)Encodes a filename so that it is save for downloading in different browsers.static java.lang.StringencodeFilename(javax.servlet.http.HttpServletRequest request, java.lang.String filename)Encodes a filename so that it is save for downloading in different browsers.static java.lang.StringgetMimeType(java.lang.String filename)Returns the MIME type matching the given filename.protected static voidinitialize()Initializes the MimetypesFileTypeMap used by this util.
-
-
-
Field Detail
-
DEFAULT_MIMETYPE
public static final java.lang.String DEFAULT_MIMETYPE
The default MIME type to be used if no MIME type matches.- See Also:
- Constant Field Values
-
mimeMap
protected static javax.activation.MimetypesFileTypeMap mimeMap
The MimetypesFileTypeMap used by this util.
-
-
Method Detail
-
initialize
protected static void initialize()
Initializes the MimetypesFileTypeMap used by this util.
-
getMimeType
public static java.lang.String getMimeType(java.lang.String filename)
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
public static java.lang.String encodeFilename(java.lang.String filename) throws java.io.UnsupportedEncodingExceptionEncodes 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:
java.io.UnsupportedEncodingException- if the encoding used to encode the filename is unknown
-
decodeFilename
public static java.lang.String decodeFilename(java.lang.String filename) throws java.io.UnsupportedEncodingExceptionDecodes a filename encoded by theencodeFilename(String)method.- Parameters:
filename- the filename to decoded- Returns:
- the decoded filename
- Throws:
java.io.UnsupportedEncodingException- if the encoding used to decode the filename is unknown
-
encodeFilename
public static java.lang.String encodeFilename(javax.servlet.http.HttpServletRequest request, java.lang.String filename) throws java.io.UnsupportedEncodingExceptionEncodes 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:
java.io.UnsupportedEncodingException- if the encoding used to encode the filename is unknown
-
decodeFilename
public static java.lang.String decodeFilename(javax.servlet.http.HttpServletRequest request, java.lang.String filename) throws java.io.UnsupportedEncodingExceptionDecodes a filename decoded by theencodeFilename(HttpServletRequest, String)method.- Parameters:
request- the current requestfilename- the filename to decoded- Returns:
- the decoded filename
- Throws:
java.io.UnsupportedEncodingException- if the encoding used to decode the filename is unknown
-
-