ninja.utils
Class MimeTypes

java.lang.Object
  extended by ninja.utils.MimeTypes

public class MimeTypes
extends Object

MimeTypes utils Adapted from play 1.2.4


Constructor Summary
MimeTypes(NinjaProperties ninjaProperties)
           
 
Method Summary
 String getContentType(Context context, String filename)
          return the content-type from a file name.
 String getContentType(Context context, String filename, String defaultContentType)
          return the content-type from a file name.
 String getMimeType(String filename)
          return the mimetype from a file name
 String getMimeType(String filename, String defaultMimeType)
          return the mimetype from a file name.
 boolean isValidMimeType(String mimeType)
          check the mimetype is referenced in the mimetypes database
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeTypes

@Inject
public MimeTypes(NinjaProperties ninjaProperties)
Method Detail

getMimeType

public String getMimeType(String filename)
return the mimetype from a file name

Parameters:
filename - the file name
Returns:
the mimetype or the empty string if not found

getMimeType

public String getMimeType(String filename,
                          String defaultMimeType)
return the mimetype from a file name.

Parameters:
filename - the file name
defaultMimeType - the default mime type to return when no matching mimetype is found
Returns:
the mimetype

getContentType

public String getContentType(Context context,
                             String filename)
return the content-type from a file name. If none is found returning application/octet-stream
For a text-based content-type, also return the encoding suffix eg. "text/plain; charset=utf-8"

Parameters:
filename - the file name
Returns:
the content-type deduced from the file extension.

getContentType

public String getContentType(Context context,
                             String filename,
                             String defaultContentType)
return the content-type from a file name.
For a text-based content-type, also return the encoding suffix eg. "text/plain; charset=utf-8"

Parameters:
filename - the file name
defaultContentType - the default content-type to return when no matching content-type is found
Returns:
the content-type deduced from the file extension.

isValidMimeType

public boolean isValidMimeType(String mimeType)
check the mimetype is referenced in the mimetypes database

Parameters:
mimeType - the mimeType to verify


Copyright © 2012. All Rights Reserved.