Package org.springframework.web.accept
Class ParameterContentNegotiationStrategy
- java.lang.Object
- org.springframework.web.accept.MappingMediaTypeFileExtensionResolver
- org.springframework.web.accept.AbstractMappingContentNegotiationStrategy
- org.springframework.web.accept.ParameterContentNegotiationStrategy
- All Implemented Interfaces:
ContentNegotiationStrategy
,MediaTypeFileExtensionResolver
public class ParameterContentNegotiationStrategy extends AbstractMappingContentNegotiationStrategy
AContentNegotiationStrategy
that resolves a query parameter to a key to be used to look up a media type. The default parameter name isformat
.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description ParameterContentNegotiationStrategy(Map<String,MediaType> mediaTypes)
Create an instance with the given map of file extensions and media types.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
getMediaTypeKey(NativeWebRequest request)
Extract a key from the request to use to look up media types.String
getParameterName()
protected void
handleMatch(String mediaTypeKey, MediaType mediaType)
Override to provide handling when a key is successfully resolved viaMappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String)
.protected MediaType
handleNoMatch(NativeWebRequest request, String key)
Override to provide handling when a key is not resolved via.void
setParameterName(String parameterName)
Set the name of the parameter to use to determine requested media types.Methods inherited from class org.springframework.web.accept.AbstractMappingContentNegotiationStrategy
resolveMediaTypeKey, resolveMediaTypes
Methods inherited from class org.springframework.web.accept.MappingMediaTypeFileExtensionResolver
addMapping, getAllFileExtensions, getAllMediaTypes, getMediaTypes, lookupMediaType, resolveFileExtensions
Constructor Detail
ParameterContentNegotiationStrategy
public ParameterContentNegotiationStrategy(Map<String,MediaType> mediaTypes)
Create an instance with the given map of file extensions and media types.
Method Detail
setParameterName
public void setParameterName(String parameterName)
Set the name of the parameter to use to determine requested media types.By default this is set to
"format"
.
getParameterName
public String getParameterName()
getMediaTypeKey
protected String getMediaTypeKey(NativeWebRequest request)
Description copied from class:AbstractMappingContentNegotiationStrategy
Extract a key from the request to use to look up media types.- Specified by:
getMediaTypeKey
in classAbstractMappingContentNegotiationStrategy
- Returns:
- the lookup key, or
null
if none
handleMatch
protected void handleMatch(String mediaTypeKey, MediaType mediaType)
Description copied from class:AbstractMappingContentNegotiationStrategy
Override to provide handling when a key is successfully resolved viaMappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String)
.- Overrides:
handleMatch
in classAbstractMappingContentNegotiationStrategy
handleNoMatch
protected MediaType handleNoMatch(NativeWebRequest request, String key) throws HttpMediaTypeNotAcceptableException
Description copied from class:AbstractMappingContentNegotiationStrategy
Override to provide handling when a key is not resolved via.MappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String)
. Sub-classes can take further steps to determine the media type(s). If a MediaType is returned from this method it will be added to the cache in the base class.- Overrides:
handleNoMatch
in classAbstractMappingContentNegotiationStrategy
- Throws:
HttpMediaTypeNotAcceptableException