public class ContentNegotiationManager extends Object implements ContentNegotiationStrategy, MediaTypeFileExtensionResolver
ContentNegotiationStrategy
instances.
Also provides methods to look up file extensions for a media type.
This is done by delegating to the list of configured
MediaTypeFileExtensionResolver
instances.
Constructor and Description |
---|
ContentNegotiationManager()
Create a default instance with a
HeaderContentNegotiationStrategy . |
ContentNegotiationManager(Collection<ContentNegotiationStrategy> strategies)
A collection-based alternative to
ContentNegotiationManager(ContentNegotiationStrategy...) . |
ContentNegotiationManager(ContentNegotiationStrategy... strategies)
Create an instance with the given list of
ContentNegotiationStrategy strategies each of which may also be
an instance of MediaTypeFileExtensionResolver . |
Modifier and Type | Method and Description |
---|---|
void |
addFileExtensionResolvers(MediaTypeFileExtensionResolver... resolvers)
Register more
MediaTypeFileExtensionResolver instances in addition
to those detected at construction. |
List<String> |
getAllFileExtensions()
Return all registered file extensions.
|
List<ContentNegotiationStrategy> |
getStrategies()
Return the configured content negotiation strategies.
|
<T extends ContentNegotiationStrategy> |
getStrategy(Class<T> strategyType)
Find a
ContentNegotiationStrategy of the given type. |
List<String> |
resolveFileExtensions(MediaType mediaType)
Resolve the given media type to a list of path extensions.
|
List<MediaType> |
resolveMediaTypes(NativeWebRequest request)
Resolve the given request to a list of media types.
|
public ContentNegotiationManager(ContentNegotiationStrategy... strategies)
ContentNegotiationStrategy
strategies each of which may also be
an instance of MediaTypeFileExtensionResolver
.strategies
- the strategies to usepublic ContentNegotiationManager(Collection<ContentNegotiationStrategy> strategies)
ContentNegotiationManager(ContentNegotiationStrategy...)
.strategies
- the strategies to usepublic ContentNegotiationManager()
HeaderContentNegotiationStrategy
.public List<ContentNegotiationStrategy> getStrategies()
public <T extends ContentNegotiationStrategy> T getStrategy(Class<T> strategyType)
ContentNegotiationStrategy
of the given type.strategyType
- the strategy typenull
if nonepublic void addFileExtensionResolvers(MediaTypeFileExtensionResolver... resolvers)
MediaTypeFileExtensionResolver
instances in addition
to those detected at construction.resolvers
- the resolvers to addpublic List<MediaType> resolveMediaTypes(NativeWebRequest request) throws HttpMediaTypeNotAcceptableException
ContentNegotiationStrategy
resolveMediaTypes
in interface ContentNegotiationStrategy
request
- the current requestnull
)HttpMediaTypeNotAcceptableException
- if the requested media
types cannot be parsedpublic List<String> resolveFileExtensions(MediaType mediaType)
MediaTypeFileExtensionResolver
resolveFileExtensions
in interface MediaTypeFileExtensionResolver
mediaType
- the media type to resolvenull
)public List<String> getAllFileExtensions()
At startup this method returns extensions explicitly registered with
either PathExtensionContentNegotiationStrategy
or
ParameterContentNegotiationStrategy
. At runtime if there is a
"path extension" strategy and its
useJaf
property is set to "true", the list of extensions may
increase as file extensions are resolved via JAF and cached.
getAllFileExtensions
in interface MediaTypeFileExtensionResolver
null
)