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

java.lang.Object
  |
  +--org.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,v 1.2 2001/09/09 01:31:29 fedor Exp $
Author:
Ilkka Priha

Field Summary
private static MimeTypeMapper commonMapper
          A common MIME type mapper.
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
           
private static int MAP_COM
           
private static int MAP_HOME
           
private static int MAP_JAR
           
private static int MAP_PROG
          Priorities of available mappers.
private static int MAP_SYS
           
private  MimeTypeMapper[] mappers
          An array of available MIME type mappers.
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
(package private) static void ()
           
 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, registerNatives, 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.

EXT_HTML

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

EXT_HTM

public static final java.lang.String EXT_HTM

EXT_WML

public static final java.lang.String EXT_WML

EXT_HDML

public static final java.lang.String EXT_HDML

EXT_HDM

public static final java.lang.String EXT_HDM

EXT_CHTML

public static final java.lang.String EXT_CHTML

EXT_TEXT

public static final java.lang.String EXT_TEXT

EXT_GIF

public static final java.lang.String EXT_GIF

EXT_JPEG

public static final java.lang.String EXT_JPEG

EXT_JPG

public static final java.lang.String EXT_JPG

EXT_WBMP

public static final java.lang.String EXT_WBMP

MAP_PROG

private static final int MAP_PROG
Priorities of available mappers.

MAP_HOME

private static final int MAP_HOME

MAP_SYS

private static final int MAP_SYS

MAP_JAR

private static final int MAP_JAR

MAP_COM

private static final int MAP_COM

commonMapper

private static MimeTypeMapper commonMapper
A common MIME type mapper.

mappers

private MimeTypeMapper[] mappers
An array of available MIME type mappers.
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.
Parameters:
path - an input 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

static void ()

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-2002 Apache Software Foundation. All Rights Reserved.