org.apache.turbine.services.mimetype.util
Class MimeTypeMap

java.lang.Object
  extended byorg.apache.turbine.services.mimetype.util.MimeTypeMap

public class MimeTypeMap
extends java.lang.Object

This class maintains a set of mappers defining mappings between MIME types and the corresponding file name extensions. The mappings are defined as lines formed by a MIME type name followed by a list of extensions separated by a whitespace. The definitions can be listed in MIME type files located in user's home directory, Java home directory or the current class jar. In addition, this class maintains static default mappings and constructors support application specific mappings.

Version:
$Id: MimeTypeMap.java 534527 2007-05-02 16:10:59Z tv $
Author:
Ilkka Priha

Field Summary
static MimeType DEFAULT_MIMETYPE
          The default MIME type when nothing else is applicable.
static java.lang.String DEFAULT_TYPE
          The default MIME type as a string.
static java.lang.String EXT_CHTML
           
static java.lang.String EXT_GIF
           
static java.lang.String EXT_HDM
           
static java.lang.String EXT_HDML
           
static java.lang.String EXT_HTM
           
static java.lang.String EXT_HTML
          Common MIME type extensions.
static java.lang.String EXT_JPEG
           
static java.lang.String EXT_JPG
           
static java.lang.String EXT_TEXT
           
static java.lang.String EXT_WBMP
           
static java.lang.String EXT_WML
           
static java.lang.String MIMETYPE_RESOURCE
          The name for MIME type mapper resources.
 
Constructor Summary
MimeTypeMap()
          Constructs a new MIME type map with default mappers.
MimeTypeMap(java.io.File file)
          Contructs a MIME type map read from a file.
MimeTypeMap(java.io.InputStream input)
          Contructs a MIME type map read from a stream.
MimeTypeMap(java.lang.String path)
          Contructs a MIME type map read from a file path.
 
Method Summary
 java.lang.String getContentType(java.io.File file)
          Gets the MIME content type for a file as a string.
 java.lang.String getContentType(java.lang.String name)
          Gets the MIME content type for a named file as a string.
 java.lang.String getContentType(java.lang.String ext, java.lang.String def)
          Gets the MIME content type for a file name extension as a string.
 java.lang.String getDefaultExtension(MimeType mime)
          Gets the default file name extension for a MIME type.
 java.lang.String getDefaultExtension(java.lang.String type)
          Gets the default file name extension for a MIME type.
 MimeType getMimeContentType(java.io.File file)
          Gets the MIME content type for a file.
 MimeType getMimeContentType(java.lang.String name)
          Gets the MIME content type for a named file.
 MimeType getMimeContentType(java.lang.String ext, java.lang.String def)
          Gets the MIME content type for a file name extension.
protected static MimeTypeMapper loadPath(java.lang.String path)
          Loads mappings from a file path.
protected static MimeTypeMapper loadResource(java.lang.String name)
          Loads mappings from a resource.
protected  void setCommonContentType(java.lang.String spec)
          Sets a common MIME content type mapping to extensions.
 void setContentType(java.lang.String spec)
          Sets a MIME content type mapping to extensions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MIMETYPE

public static final MimeType DEFAULT_MIMETYPE
The default MIME type when nothing else is applicable.


DEFAULT_TYPE

public static final java.lang.String DEFAULT_TYPE
The default MIME type as a string.


MIMETYPE_RESOURCE

public static final java.lang.String MIMETYPE_RESOURCE
The name for MIME type mapper resources.

See Also:
Constant Field Values

EXT_HTML

public static final java.lang.String EXT_HTML
Common MIME type extensions.

See Also:
Constant Field Values

EXT_HTM

public static final java.lang.String EXT_HTM
See Also:
Constant Field Values

EXT_WML

public static final java.lang.String EXT_WML
See Also:
Constant Field Values

EXT_HDML

public static final java.lang.String EXT_HDML
See Also:
Constant Field Values

EXT_HDM

public static final java.lang.String EXT_HDM
See Also:
Constant Field Values

EXT_CHTML

public static final java.lang.String EXT_CHTML
See Also:
Constant Field Values

EXT_TEXT

public static final java.lang.String EXT_TEXT
See Also:
Constant Field Values

EXT_GIF

public static final java.lang.String EXT_GIF
See Also:
Constant Field Values

EXT_JPEG

public static final java.lang.String EXT_JPEG
See Also:
Constant Field Values

EXT_JPG

public static final java.lang.String EXT_JPG
See Also:
Constant Field Values

EXT_WBMP

public static final java.lang.String EXT_WBMP
See Also:
Constant Field Values
Constructor Detail

MimeTypeMap

public MimeTypeMap()
Constructs a new MIME type map with default mappers.


MimeTypeMap

public MimeTypeMap(java.io.InputStream input)
            throws java.io.IOException
Contructs a MIME type map read from a stream.

Parameters:
input - an input stream.
Throws:
java.io.IOException - for an incorrect stream.

MimeTypeMap

public MimeTypeMap(java.io.File file)
            throws java.io.IOException
Contructs a MIME type map read from a file.

Throws:
java.io.IOException - for an incorrect input file.

MimeTypeMap

public MimeTypeMap(java.lang.String path)
            throws java.io.IOException
Contructs a MIME type map read from a file path.

Parameters:
path - an input file path.
Throws:
java.io.IOException - for an incorrect input file.
Method Detail

loadPath

protected static MimeTypeMapper loadPath(java.lang.String path)
                                  throws java.io.IOException
Loads mappings from a file path.

Parameters:
path - a file path.
Returns:
the mappings.
Throws:
java.io.IOException - for an incorrect file.

loadResource

protected static MimeTypeMapper loadResource(java.lang.String name)
Loads mappings from a resource.

Parameters:
name - a resource name.
Returns:
the mappings.

setContentType

public void setContentType(java.lang.String spec)
Sets a MIME content type mapping to extensions.

Parameters:
spec - a MIME type extension specification to set.

getContentType

public java.lang.String getContentType(java.io.File file)
Gets the MIME content type for a file as a string.

Parameters:
file - the file.
Returns:
the MIME type string.

getContentType

public java.lang.String getContentType(java.lang.String name)
Gets the MIME content type for a named file as a string.

Parameters:
name - the name of the file.
Returns:
the MIME type string.

getContentType

public java.lang.String getContentType(java.lang.String ext,
                                       java.lang.String def)
Gets the MIME content type for a file name extension as a string.

Parameters:
ext - the file name extension.
def - the default type if none is found.
Returns:
the MIME type string.

getMimeContentType

public MimeType getMimeContentType(java.io.File file)
Gets the MIME content type for a file.

Parameters:
file - the file.
Returns:
the MIME type.

getMimeContentType

public MimeType getMimeContentType(java.lang.String name)
Gets the MIME content type for a named file.

Parameters:
name - the name of the file.
Returns:
the MIME type.

getMimeContentType

public MimeType getMimeContentType(java.lang.String ext,
                                   java.lang.String def)
Gets the MIME content type for a file name extension.

Parameters:
ext - the file name extension.
def - the default type if none is found.
Returns:
the MIME type.

getDefaultExtension

public java.lang.String getDefaultExtension(java.lang.String type)
Gets the default file name extension for a MIME type. Note that the mappers are called in the reverse order.

Parameters:
type - the MIME type as a string.
Returns:
the file name extension or null.

getDefaultExtension

public java.lang.String getDefaultExtension(MimeType mime)
Gets the default file name extension for a MIME type. Note that the mappers are called in the reverse order.

Parameters:
mime - the MIME type.
Returns:
the file name extension or null.

setCommonContentType

protected void setCommonContentType(java.lang.String spec)
Sets a common MIME content type mapping to extensions.

Parameters:
spec - a MIME type extension specification to set.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.