Class MimeUtil

java.lang.Object
com.saperion.ngc.util.MimeUtil

public final class MimeUtil extends Object
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 Details

    • DEFAULT_MIMETYPE

      public static final String DEFAULT_MIMETYPE
      The default MIME type to be used if no MIME type matches.
      See Also:
    • mimeMap

      protected static javax.activation.MimetypesFileTypeMap mimeMap
      The MimetypesFileTypeMap used by this util.
  • Method Details

    • initialize

      protected static void initialize()
      Initializes the MimetypesFileTypeMap used by this util.
    • getMimeType

      public static String getMimeType(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 String encodeFilename(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 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

      public static String decodeFilename(String filename) throws UnsupportedEncodingException
      Decodes a filename encoded by the encodeFilename(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 request
      filename - 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 the encodeFilename(HttpServletRequest, String) method.
      Parameters:
      request - the current request
      filename - the filename to decoded
      Returns:
      the decoded filename
      Throws:
      UnsupportedEncodingException - if the encoding used to decode the filename is unknown