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
ConstructorDescriptionMappingMediaTypeFileExtensionResolver
(Map<String, MediaType> mediaTypes) Create an instance with the given map of file extensions and media types. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addMapping
(String extension, MediaType mediaType) Map an extension to a MediaType.Get all registered file extensions.protected MediaType
lookupMediaType
(String extension) Use this method for a reverse lookup from extension to MediaType.resolveFileExtensions
(MediaType mediaType) Resolve the given media type to a list of file extensions.
-
Constructor Details
-
MappingMediaTypeFileExtensionResolver
Create an instance with the given map of file extensions and media types.
-
-
Method Details
-
getMediaTypes
-
getAllMediaTypes
-
addMapping
Map an extension to a MediaType. Ignore if extension already mapped. -
resolveFileExtensions
Description copied from interface:MediaTypeFileExtensionResolver
Resolve the given media type to a list of file extensions.- Specified by:
resolveFileExtensions
in interfaceMediaTypeFileExtensionResolver
- Parameters:
mediaType
- the media type to resolve- Returns:
- a list of extensions or an empty list (never
null
)
-
getAllFileExtensions
Description copied from interface:MediaTypeFileExtensionResolver
Get all registered file extensions.- Specified by:
getAllFileExtensions
in interfaceMediaTypeFileExtensionResolver
- Returns:
- a list of extensions or an empty list (never
null
)
-
lookupMediaType
Use this method for a reverse lookup from extension to MediaType.- Returns:
- a MediaType for the extension, or
null
if none found
-