类 AbstractMappingContentNegotiationStrategy
java.lang.Object
cn.taketoday.web.accept.MappingMediaTypeFileExtensionResolver
cn.taketoday.web.accept.AbstractMappingContentNegotiationStrategy
public abstract class AbstractMappingContentNegotiationStrategy
extends MappingMediaTypeFileExtensionResolver
implements ContentNegotiationStrategy
Base class for
ContentNegotiationStrategy implementations with the
steps to resolve a request to media types.
First a key (e.g. "json", "pdf") must be extracted from the request (e.g.
file extension, query param). The key must then be resolved to media type(s)
through the base class MappingMediaTypeFileExtensionResolver which
stores such mappings.
The method handleNoMatch(cn.taketoday.web.RequestContext, java.lang.String) allow sub-classes to plug in additional
ways of looking up media types (e.g. through the Java Activation framework,
or ServletContext.getMimeType(java.lang.String). Media types resolved
via base classes are then added to the base class
MappingMediaTypeFileExtensionResolver, i.e. cached for new lookups.
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
-
字段概要
字段从接口继承的字段 cn.taketoday.web.accept.ContentNegotiationStrategy
MEDIA_TYPE_ALL_LIST -
构造器概要
构造器构造器说明AbstractMappingContentNegotiationStrategy(Map<String, MediaType> mediaTypes) Create an instance with the given map of file extensions and media types. -
方法概要
修饰符和类型方法说明protected abstract StringgetMediaTypeKey(RequestContext request) Extract a key from the request to use to look up media types.protected voidhandleMatch(String key, MediaType mediaType) Override to provide handling when a key is successfully resolved viaMappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String).protected MediaTypehandleNoMatch(RequestContext request, String key) Override to provide handling when a key is not resolved via.booleanbooleanresolveMediaTypeKey(RequestContext webRequest, String key) An alternative toresolveMediaTypes(RequestContext)that accepts an already extracted key.resolveMediaTypes(RequestContext context) Resolve the given request to a list of media types.voidsetIgnoreUnknownExtensions(boolean ignoreUnknownExtensions) Whether to ignore requests with unknown file extension.voidsetUseRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly) Whether to only use the registered mappings to look up file extensions, or also to use dynamic resolution (e.g. viaMediaType.从类继承的方法 cn.taketoday.web.accept.MappingMediaTypeFileExtensionResolver
addMapping, getAllFileExtensions, getAllMediaTypes, getMediaTypes, lookupMediaType, resolveFileExtensions
-
字段详细资料
-
useRegisteredExtensionsOnly
private boolean useRegisteredExtensionsOnly -
ignoreUnknownExtensions
private boolean ignoreUnknownExtensions
-
-
构造器详细资料
-
AbstractMappingContentNegotiationStrategy
Create an instance with the given map of file extensions and media types.
-
-
方法详细资料
-
setUseRegisteredExtensionsOnly
public void setUseRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly) Whether to only use the registered mappings to look up file extensions, or also to use dynamic resolution (e.g. viaMediaType.By default this is set to
false. -
isUseRegisteredExtensionsOnly
public boolean isUseRegisteredExtensionsOnly() -
setIgnoreUnknownExtensions
public void setIgnoreUnknownExtensions(boolean ignoreUnknownExtensions) Whether to ignore requests with unknown file extension. Setting this tofalseresults inHttpMediaTypeNotAcceptableException.By default this is set to false.
-
isIgnoreUnknownExtensions
public boolean isIgnoreUnknownExtensions() -
resolveMediaTypes
public List<MediaType> resolveMediaTypes(RequestContext context) throws HttpMediaTypeNotAcceptableException 从接口复制的说明:ContentNegotiationStrategyResolve the given request to a list of media types. The returned list is ordered by specificity first and by quality parameter second.- 指定者:
resolveMediaTypes在接口中ContentNegotiationStrategy- 参数:
context- the current request context- 返回:
- the requested media types, or
ContentNegotiationStrategy.MEDIA_TYPE_ALL_LISTif none were requested. - 抛出:
HttpMediaTypeNotAcceptableException- if the requested media types cannot be parsed
-
resolveMediaTypeKey
public List<MediaType> resolveMediaTypeKey(RequestContext webRequest, @Nullable String key) throws HttpMediaTypeNotAcceptableException An alternative toresolveMediaTypes(RequestContext)that accepts an already extracted key. -
getMediaTypeKey
Extract a key from the request to use to look up media types.- 返回:
- the lookup key, or
nullif none
-
handleMatch
Override to provide handling when a key is successfully resolved viaMappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String). -
handleNoMatch
@Nullable protected MediaType handleNoMatch(RequestContext request, String key) throws HttpMediaTypeNotAcceptableException 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.
-