org.springframework.mail.javamail

## Class ConfigurableMimeFileTypeMap

- java.lang.Object
- - javax.activation.FileTypeMap
  - - org.springframework.mail.javamail.ConfigurableMimeFileTypeMap

- All Implemented Interfaces:
    InitializingBean

      public class ConfigurableMimeFileTypeMap
      extends FileTypeMap
      implements InitializingBean

  Spring-configurable `FileTypeMap` implementation that will read MIME type to file extension mappings from a standard JavaMail MIME type mapping file, using a standard `MimetypesFileTypeMap` underneath.

  The mapping file should be in the following format, as specified by the Java Activation Framework:

       # map text/html to .htm and .html files
       text/html  html htm HTML HTM

  Lines starting with `#` are treated as comments and are ignored. All other lines are treated as mappings. Each mapping line should contain the MIME type as the first entry and then each file extension to map to that MIME type as subsequent entries. Each entry is separated by spaces or tabs.

  By default, the mappings in the `mime.types` file located in the same package as this class are used, which cover many common file extensions (in contrast to the out-of-the-box mappings in `activation.jar`). This can be overridden using the `mappingLocation` property.

  Additional mappings can be added via the `mappings` bean property, as lines that follow the `mime.types` file format.

  Since:
    1.2
  Author:
    Rob Harrop, Juergen Hoeller
  See Also:
    `setMappingLocation(org.springframework.core.io.Resource)`, `setMappings(java.lang.String[])`, `MimetypesFileTypeMap`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConfigurableMimeFileTypeMap()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()` Creates the final merged mapping set.
    `protected FileTypeMap` | `createFileTypeMap(Resource mappingLocation, String[] mappings)` Compile a `FileTypeMap` from the mappings in the given mapping file and the given mapping entries.
    `String` | `getContentType(File file)` Delegates to the underlying FileTypeMap.
    `String` | `getContentType(String fileName)` Delegates to the underlying FileTypeMap.
    `protected FileTypeMap` | `getFileTypeMap()` Return the delegate FileTypeMap, compiled from the mappings in the mapping file and the entries in the `mappings` property.
    `void` | `setMappingLocation(Resource mappingLocation)` Specify the `Resource` from which mappings are loaded.
    `void` | `setMappings(String[] mappings)` Specify additional MIME type mappings as lines that follow the `mime.types` file format, as specified by the Java Activation Framework, for example: `text/html html htm HTML HTM`

    - ### Methods inherited from class javax.activation.FileTypeMap

      `getDefaultFileTypeMap, setDefaultFileTypeMap`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ConfigurableMimeFileTypeMap

          public ConfigurableMimeFileTypeMap()

  - ### Method Detail

    - #### setMappingLocation

          public void setMappingLocation(Resource mappingLocation)

      Specify the `Resource` from which mappings are loaded.

      Needs to follow the `mime.types` file format, as specified by the Java Activation Framework, containing lines such as:
      `text/html html htm HTML HTM`

    - #### setMappings

          public void setMappings(String[] mappings)

      Specify additional MIME type mappings as lines that follow the `mime.types` file format, as specified by the Java Activation Framework, for example:
      `text/html html htm HTML HTM`

    - #### afterPropertiesSet

          public void afterPropertiesSet()

      Creates the final merged mapping set.
      Specified by:
        `afterPropertiesSet` in interface `InitializingBean`

    - #### getFileTypeMap

          protected final FileTypeMap getFileTypeMap()

      Return the delegate FileTypeMap, compiled from the mappings in the mapping file and the entries in the `mappings` property.
      See Also:
        `setMappingLocation(org.springframework.core.io.Resource)`, `setMappings(java.lang.String[])`, `createFileTypeMap(org.springframework.core.io.Resource, java.lang.String[])`

    - #### createFileTypeMap

          protected FileTypeMap createFileTypeMap(Resource mappingLocation,
                                      String[] mappings)
                                           throws IOException

      Compile a `FileTypeMap` from the mappings in the given mapping file and the given mapping entries.

      The default implementation creates an Activation Framework `MimetypesFileTypeMap`, passing in an InputStream from the mapping resource (if any) and registering the mapping lines programmatically.

      Parameters:
        `mappingLocation` - a `mime.types` mapping resource (can be `null`)
        `mappings` - MIME type mapping lines (can be `null`)
      Returns:
        the compiled FileTypeMap
      Throws:
        `IOException` - if resource access failed
      See Also:
        `MimetypesFileTypeMap.MimetypesFileTypeMap(java.io.InputStream)`, `MimetypesFileTypeMap.addMimeTypes(String)`

    - #### getContentType

          public String getContentType(File file)

      Delegates to the underlying FileTypeMap.
      Specified by:
        `getContentType` in class `FileTypeMap`
      See Also:
        `getFileTypeMap()`

    - #### getContentType

          public String getContentType(String fileName)

      Delegates to the underlying FileTypeMap.
      Specified by:
        `getContentType` in class `FileTypeMap`
      See Also:
        `getFileTypeMap()`