Package org.springframework.web.accept

# Class MappingMediaTypeFileExtensionResolver

java.lang.Object
org.springframework.web.accept.MappingMediaTypeFileExtensionResolver

All Implemented Interfaces:
  `MediaTypeFileExtensionResolver`

Direct Known Subclasses:
  `AbstractMappingContentNegotiationStrategy`

public class MappingMediaTypeFileExtensionResolver extends Object implements MediaTypeFileExtensionResolver
An implementation of `MediaTypeFileExtensionResolver` that maintains lookups between file extensions and MediaTypes in both directions.

Initially created with a map of file extensions and media types. Subsequently, subclasses can use `addMapping(java.lang.String, org.springframework.http.MediaType)` to add more mappings.

Since:
  3.2
Author:
  Rossen Stoyanchev, Juergen Hoeller

## Constructor Summary

Constructors
Constructor
Description
`MappingMediaTypeFileExtensionResolver(Map<String,MediaType> mediaTypes)`
Create an instance with the given map of file extensions and media types.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`addMapping(String extension, MediaType mediaType)`
Map an extension to a MediaType.
`List<String>`
`getAllFileExtensions()`
Get all registered file extensions.
`protected List<MediaType>`
`getAllMediaTypes()`
`Map<String,MediaType>`
`getMediaTypes()`
`protected MediaType`
`lookupMediaType(String extension)`
Use this method for a reverse lookup from extension to MediaType.
`List<String>`
`resolveFileExtensions(MediaType mediaType)`
Resolve the given media type to a list of file extensions.

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

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

## Constructor Details

### MappingMediaTypeFileExtensionResolver

public MappingMediaTypeFileExtensionResolver(@Nullable Map<String,MediaType> mediaTypes)
Create an instance with the given map of file extensions and media types.

## Method Details

### getMediaTypes

public Map<String,MediaType> getMediaTypes()

### getAllMediaTypes

protected List<MediaType> getAllMediaTypes()

### addMapping

protected void addMapping(String extension, MediaType mediaType)
Map an extension to a MediaType. Ignore if extension already mapped.

### resolveFileExtensions

public List<String> resolveFileExtensions(MediaType mediaType)
Description copied from interface: `MediaTypeFileExtensionResolver`
Resolve the given media type to a list of file extensions.

Specified by:
  `resolveFileExtensions` in interface `MediaTypeFileExtensionResolver`
Parameters:
  `mediaType` - the media type to resolve
Returns:
  a list of extensions or an empty list (never `null`)

### getAllFileExtensions

public List<String> getAllFileExtensions()
Description copied from interface: `MediaTypeFileExtensionResolver`
Get all registered file extensions.

Specified by:
  `getAllFileExtensions` in interface `MediaTypeFileExtensionResolver`
Returns:
  a list of extensions or an empty list (never `null`)

### lookupMediaType

@Nullable protected MediaType lookupMediaType(String extension)
Use this method for a reverse lookup from extension to MediaType.

Returns:
  a MediaType for the extension, or `null` if none found