SHOW Signed
 

net.rim.device.api.io
Class MIMETypeAssociations

java.lang.Object
  |
  +--net.rim.device.api.io.MIMETypeAssociations

public final class MIMETypeAssociations
extends Object

This class provides an association between file extensions, MIME types and media types. Authors are allowed to associate with a media type with an extension and query what type is associated with a filename.

Sample code

String contentType = MIMETypeAssociations.getMIMEType(fileName);
// Normalize and strip off parameters.
String normalizedContentType = MIMETypeAssociations.getNormalizedType(contentType);

// Method to check if your application supports a particular MIME type.
public boolean supported(String mimeType)
{
    return (mimeType != null && (MIMETypeAssociations.getMediaTypeFromMIMEType( mimeType ) == MIMETypeAssociations.MEDIA_ parameter));
}

// Register the default extension for the MMS MIME type.
MIMETypeAssociations.registerType("mms", "application/vnd.wap.mms-message", MIMETypeAssociations.MEDIA_TYPE_UNKNOWN);
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

Since:
JDE 4.2.0

Field Summary
 Category: Signed static int MEDIA_TYPE_APPLICATION
          Media Type Application.
 Category: Signed static int MEDIA_TYPE_ARCHIVE
          Media Type Archive.
 Category: Signed static int MEDIA_TYPE_AUDIO
          Media Type Audio.
 Category: Signed static int MEDIA_TYPE_IMAGE
          Media Type Image.
 Category: Signed static int MEDIA_TYPE_PLAY_LIST
          Media Type Audio play list.
 Category: Signed static int MEDIA_TYPE_TEXT
          Media Type Text.
 Category: Signed static int MEDIA_TYPE_UNKNOWN
          Media Type Unknown.
 Category: Signed static int MEDIA_TYPE_VIDEO
          Media Type Video.
 
Method Summary
 Category: Signed static String getExtensionFromMIMEType(String mimeType)
          Return the file extension associated with the MIME type.
 Category: Signed static int getMediaType(String filename)
          Return the media type associated with a filename.
 Category: Signed static int getMediaTypeFromMIMEType(String mimeType)
          Return the media type associated with the MIME type.
 Category: Signed static String getMIMEType(String filename)
          Return the MIME type associated with a filename.
 Category: Signed static String getNormalizedType(String mimeType)
          Return a normalized MIME type for the provided type.
 Category: Signed static void registerMIMETypeMapping(String typeFrom, String typeTo)
          Register a MIME type mapping, associating one MIME type to another MIME type.
 Category: Signed static void registerType(String extension, String mimeType, int mediaType)
          Register a media and MIME type associated with an extension.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MEDIA_TYPE_APPLICATION

public static final int MEDIA_TYPE_APPLICATION
Media Type Application.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

MEDIA_TYPE_ARCHIVE

public static final int MEDIA_TYPE_ARCHIVE
Media Type Archive.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

MEDIA_TYPE_AUDIO

public static final int MEDIA_TYPE_AUDIO
Media Type Audio.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

MEDIA_TYPE_IMAGE

public static final int MEDIA_TYPE_IMAGE
Media Type Image.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

MEDIA_TYPE_PLAY_LIST

public static final int MEDIA_TYPE_PLAY_LIST
Media Type Audio play list.
Since:
JDE 4.3.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

MEDIA_TYPE_TEXT

public static final int MEDIA_TYPE_TEXT
Media Type Text.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

MEDIA_TYPE_UNKNOWN

public static final int MEDIA_TYPE_UNKNOWN
Media Type Unknown.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

MEDIA_TYPE_VIDEO

public static final int MEDIA_TYPE_VIDEO
Media Type Video.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Method Detail

getExtensionFromMIMEType

public static String getExtensionFromMIMEType(String mimeType)
Return the file extension associated with the MIME type.
Parameters:
mimeType - The MIME type to query on.
Returns:
The file extension that the MIME type is associated with, or null if the MIME type is unknown or null.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

getMediaType

public static int getMediaType(String filename)
Return the media type associated with a filename. If the media type cannot be determined from the filename, this method returns MEDIA_TYPE_UNKNOWN.
Parameters:
filename - The filename to query on.
Returns:
The associated media type (eg. MEDIA_TYPE_IMAGE) or MEDIA_TYPE_UNKNOWN if filename is null.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

getMediaTypeFromMIMEType

public static int getMediaTypeFromMIMEType(String mimeType)
Return the media type associated with the MIME type. If the MIME type is unknown or null, this method returns MEDIA_TYPE_UNKNOWN.
Parameters:
mimeType - The MIME type to query on.
Returns:
The media type that the MIME type is associated with.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

getMIMEType

public static String getMIMEType(String filename)
Return the MIME type associated with a filename.
Parameters:
filename - The filename to query on.
Returns:
The associated MIME type (eg. "image/gif"), or null if the type could not be determined from the filename; the input is an invalid MIME type, or the input is null.
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

getNormalizedType

public static String getNormalizedType(String mimeType)
Return a normalized MIME type for the provided type. The normalized type is the first mime type that was registered for a type, for example, image/jpeg might return image/jpg for its normalized type.

This method removes parameters on the content type and maps MIME type aliases to the preferred MIME type. For example, the normalized MIME type for "audio/mp3" (non-standard) is "audio/mpeg" (as defined in RFC 3003 and registered with the IANA).

If the MIME type is unknown, the type is returned with any parameters removed. For example, the normalized type for "text/x-unknown-type; charset=utf-8" is "text/x-unknown-type".

Parameters:
mimeType - The MIME type to be normalized (may be null, in which case this method returns null).
Returns:
The normalized MIME type.
Since:
JDE 4.2.0
See Also:
MIME types registered with the IANA
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

registerMIMETypeMapping

public static void registerMIMETypeMapping(String typeFrom,
                                           String typeTo)
Register a MIME type mapping, associating one MIME type to another MIME type.
Parameters:
typeFrom - The MIME type that the mapping is queried from.
typeTo - The MIME type that should be returned as a result of the mapping.
Throws:
NullPointerException - if typeFrom or typeTo is null
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.

registerType

public static void registerType(String extension,
                                String mimeType,
                                int mediaType)
Register a media and MIME type associated with an extension.

Note that this method does not override previously registered types or extensions. If the extension is already registered, this method does nothing.

Parameters:
extension - The file extension to associate with.
mimeType - The MIME type the extension is associated with.
mediaType - The media type the extension is associated with; this can be MEDIA_TYPE_UNKNOWN or a private constant, but it should typically be one of MEDIA_TYPE_APPLICATION, MEDIA_TYPE_AUDIO, etc.
Throws:
NullPointerException - if mimeType or extension is null
Since:
JDE 4.2.0
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.



Copyright 1999-2009 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.