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

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

public class MimeTypeMapper
extends java.lang.Object

This class defines 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.

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

Field Summary
protected  java.util.HashMap extensionMimeTypes
           
 
Constructor Summary
MimeTypeMapper()
          Constructs an empty MIME type mapper.
MimeTypeMapper(java.io.File file)
          Constructs a mapper reading from a file.
MimeTypeMapper(java.io.InputStream input)
          Constructs a mapper reading from a stream.
MimeTypeMapper(java.lang.String path)
          Constructs a mapper reading from a file path.
 
Method Summary
 java.lang.String getContentType(java.lang.String ext)
          Gets a MIME content type corresponding to a specified file name extension.
 java.lang.String getExtension(java.lang.String type)
          Gets a file name extension corresponding to a specified MIME content type.
protected  void parse(java.io.BufferedReader reader)
          Parses MIME type extensions.
protected  int parseMimeTypeExtension(java.lang.String spec, java.util.Map mimeTypes, java.util.Map extensions)
          Parses a MIME type extension.
 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

extensionMimeTypes

protected java.util.HashMap extensionMimeTypes
Constructor Detail

MimeTypeMapper

public MimeTypeMapper()
Constructs an empty MIME type mapper.


MimeTypeMapper

public MimeTypeMapper(java.io.InputStream input)
               throws java.io.IOException
Constructs a mapper reading from a stream.

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

MimeTypeMapper

public MimeTypeMapper(java.io.File file)
               throws java.io.IOException
Constructs a mapper reading from a file.

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

MimeTypeMapper

public MimeTypeMapper(java.lang.String path)
               throws java.io.IOException
Constructs a mapper reading from a file path.

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

setContentType

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

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

getContentType

public java.lang.String getContentType(java.lang.String ext)
Gets a MIME content type corresponding to a specified file name extension.

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

getExtension

public java.lang.String getExtension(java.lang.String type)
Gets a file name extension corresponding to a specified MIME content type.

Returns:
the corresponding file name extension or null.

parse

protected void parse(java.io.BufferedReader reader)
              throws java.io.IOException
Parses MIME type extensions.

Parameters:
reader - a reader to parse.
Throws:
java.io.IOException - for an incorrect reader.

parseMimeTypeExtension

protected int parseMimeTypeExtension(java.lang.String spec,
                                     java.util.Map mimeTypes,
                                     java.util.Map extensions)
Parses a MIME type extension.

Parameters:
spec - an extension specification to parse.
mimeTypes - a map of MIME types.
extensions - a map of extensions.
Returns:
the number of file name extensions parsed.


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