public class ContentNegotiationManager extends Object implements ContentNegotiationStrategy, MediaTypeFileExtensionResolver
HeaderContentNegotiationStrategy
will be configured by default.
This class may also be used to look up file extensions associated with a
MediaType. This is done by consulting the list of configured
MediaTypeFileExtensionResolver
instances. Note that some
ContentNegotiationStrategy implementations also implement
MediaTypeFileExtensionResolver and the class constructor accepting the former
will also detect if they implement the latter. If you need to register additional
resolvers, you can use the method
addFileExtensionResolvers(MediaTypeFileExtensionResolver...)
.
Constructor and Description |
---|
ContentNegotiationManager()
Create an instance with a
HeaderContentNegotiationStrategy . |
ContentNegotiationManager(ContentNegotiationStrategy... strategies)
Create an instance with the given ContentNegotiationStrategy instances.
|
Modifier and Type | Method and Description |
---|---|
void |
addFileExtensionResolvers(MediaTypeFileExtensionResolver... resolvers)
Add MediaTypeFileExtensionResolver instances.
|
List<String> |
getAllFileExtensions()
Delegate to all configured MediaTypeFileExtensionResolver instances and aggregate
the list of all known file extensions.
|
List<String> |
resolveFileExtensions(MediaType mediaType)
Delegate to all configured MediaTypeFileExtensionResolver instances and aggregate
the list of all file extensions found.
|
List<MediaType> |
resolveMediaTypes(NativeWebRequest webRequest)
Delegate to all configured ContentNegotiationStrategy instances until one
returns a non-empty list.
|
public ContentNegotiationManager(ContentNegotiationStrategy... strategies)
Each instance is checked to see if it is also an implementation of MediaTypeFileExtensionResolver, and if so it is registered as such.
strategies
- one more more ContentNegotiationStrategy instancespublic ContentNegotiationManager()
HeaderContentNegotiationStrategy
.public void addFileExtensionResolvers(MediaTypeFileExtensionResolver... resolvers)
Note that some ContentNegotiationStrategy
implementations also
implement MediaTypeFileExtensionResolver
and the class constructor
accepting the former will also detect implementations of the latter. Therefore
you only need to use this method to register additional instances.
resolvers
- one or more resolverspublic List<MediaType> resolveMediaTypes(NativeWebRequest webRequest) throws HttpMediaTypeNotAcceptableException
resolveMediaTypes
in interface ContentNegotiationStrategy
webRequest
- the current requestnull
HttpMediaTypeNotAcceptableException
- if the requested media types cannot be parsedpublic List<String> resolveFileExtensions(MediaType mediaType)
resolveFileExtensions
in interface MediaTypeFileExtensionResolver
mediaType
- the media type to resolvenull
public List<String> getAllFileExtensions()
getAllFileExtensions
in interface MediaTypeFileExtensionResolver
null