Overview

The MimeType Service maintains mappings between MIME types and the corresponding file name extensions (extremely useful in conjunction with file upload), and between locales and character encodings. The mappings are dependent upon the implementation, and are typically defined in properties or files located in user's home directory, Java home directory, or the current class's JAR.

It is written for use in Turbine but it can be used in any container compatible with Avalon's ECM container.

Configuration

First, here is the role configuration.


    <role
        name="org.apache.fulcrum.mimetype.MimeTypeService"
        shorthand="mimetype"
        default-class="org.apache.fulcrum.mimetype.DefaultMimeTypeService"/>

And here is the configuration:



        <mimetype/>

Usage

The default RunData implementation uses the MimeType Service internally when resolving the character encoding of the servlet response. In addition, applications can use it for customized encoding and content type resolving.

The mappings between locales and the corresponding character encodings are specified using the Java property file syntax, where the locale specification is the key of the property key and the charset is the value of the property. The locale specification consists of three parts:

<lang>_<country>_<variant>

The variant can be whatever is appropriate for the application, like a markup language specification, a browser specification, etc. The service looks for charsets using the following search order:

<lang>_<country>_<variant>=<charset>
_<country>_<variant>=<charset>
<lang>__<variant>=<charset>
__<variant>=<charset>
<lang>_<country>=<charset>
_<country>=<charset>
<lang>=<charset>

The service contains defaults for several language mappings and more specific ones can be specified in an optional property file, e.g. __wml=UTF-8. The name of the property file can be given with a service property named "charsets". The service caches results of the search, which should guarantee good performance.

The mappings between MIME types and the corresponding file name extensions are specified using the same syntax as the mime.types file of the Apache Server, i.e.:

<mimetype> <ext1> <ext2>...

The service contains defaults for most common MIME types, like text/plain, text/html, text/x-hdml, text/vnd.wap.wml, image/gif and image/jpeg. More specific ones can be specified in an optional MIME types file. The name of the MIME types file can be given with a service property named "mime.types".

The TurbineMimeTypes class is a static accessor for the most common MimeType Service methods.