public class ContentNegotiationManager extends java.lang.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(java.util.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. |
java.util.List<java.lang.String> |
getAllFileExtensions()
Return all registered file extensions.
|
java.util.List<ContentNegotiationStrategy> |
getStrategies()
Return the configured content negotiation strategies.
|
<T extends ContentNegotiationStrategy> |
getStrategy(java.lang.Class<T> strategyType)
Find a
ContentNegotiationStrategy of the given type. |
java.util.List<java.lang.String> |
resolveFileExtensions(MediaType mediaType)
Resolve the given media type to a list of path extensions.
|
java.util.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(java.util.Collection<ContentNegotiationStrategy> strategies)
ContentNegotiationManager(ContentNegotiationStrategy...)
.strategies
- the strategies to usepublic ContentNegotiationManager()
HeaderContentNegotiationStrategy
.public java.util.List<ContentNegotiationStrategy> getStrategies()
public <T extends ContentNegotiationStrategy> T getStrategy(java.lang.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 java.util.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 java.util.List<java.lang.String> resolveFileExtensions(MediaType mediaType)
MediaTypeFileExtensionResolver
resolveFileExtensions
in interface MediaTypeFileExtensionResolver
mediaType
- the media type to resolvenull
)public java.util.List<java.lang.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
)