类 ProducesRequestCondition
java.lang.Object
cn.taketoday.web.handler.condition.AbstractRequestCondition<ProducesRequestCondition>
cn.taketoday.web.handler.condition.ProducesRequestCondition
- 所有已实现的接口:
RequestCondition<ProducesRequestCondition>
public final class ProducesRequestCondition
extends AbstractRequestCondition<ProducesRequestCondition>
A logical disjunction (' || ') request condition to match a request's 'Accept' header
to a list of media type expressions. Two kinds of media type expressions are
supported, which are described in
RequestMapping.produces() and
RequestMapping.headers() where the header name is 'Accept'.
Regardless of which syntax is used, the semantics are the same.- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Harry Yang
-
字段概要
字段修饰符和类型字段说明private final ContentNegotiationManagerprivate static final ContentNegotiationManagerprivate static final ProducesRequestConditionprivate final List<MediaTypeExpression>private static final List<MediaTypeExpression>private static final String -
构造器概要
构造器限定符构造器说明ProducesRequestCondition(String... produces) Creates a new instance from "produces" expressions.ProducesRequestCondition(String[] produces, String[] headers) Creates a new instance with "produces" and "header" expressions.ProducesRequestCondition(String[] produces, String[] headers, ContentNegotiationManager manager) Same asProducesRequestCondition(String[], String[])but also accepting aContentNegotiationManager.privateProducesRequestCondition(List<MediaTypeExpression> expressions, ProducesRequestCondition other) Private constructor for internal use to create matching conditions. -
方法概要
修饰符和类型方法说明combine(ProducesRequestCondition other) Returns the "other" instance if it has any expressions; returns "this" instance otherwise.private intcompareMatchingMediaTypes(ProducesRequestCondition condition1, int index1, ProducesRequestCondition condition2, int index2) intcompareTo(ProducesRequestCondition other, RequestContext request) Compares this and another "produces" condition as follows: Sort 'Accept' header media types by quality value viaMimeTypeUtils.sortBySpecificity(List)and iterate the list.getAcceptedMediaTypes(RequestContext request) protected List<MediaTypeExpression>Return the discrete items a request condition is composed of.Return the contained "produces" expressions.private List<MediaTypeExpression>Return the contained "produces" expressions or if that's empty, a list with a "*/*" expression.getMatchingCondition(RequestContext request) Checks if any of the contained media type expressions match the given request 'Content-Type' header and returns an instance that is guaranteed to contain matching expressions only.private List<MediaTypeExpression>getMatchingExpressions(List<MediaType> acceptedMediaTypes) Return the contained producible media types excluding negated expressions.protected StringThe notation to use when printing discrete items of content.private intindexOfEqualMediaType(MediaType mediaType) private intindexOfIncludedMediaType(MediaType mediaType) booleanisEmpty()Whether the condition has any media type expressions.从类继承的方法 cn.taketoday.web.handler.condition.AbstractRequestCondition
equals, hashCode, toString
-
字段详细资料
-
MEDIA_TYPES_ATTRIBUTE
-
DEFAULT_CONTENT_NEGOTIATION_MANAGER
-
EMPTY_CONDITION
-
MEDIA_TYPE_ALL_LIST
-
expressions
-
contentNegotiationManager
-
-
构造器详细资料
-
ProducesRequestCondition
Creates a new instance from "produces" expressions. If 0 expressions are provided in total, this condition will match to any request.- 参数:
produces- expressions with syntax defined byRequestMapping.produces()
-
ProducesRequestCondition
Creates a new instance with "produces" and "header" expressions. "Header" expressions where the header name is not 'Accept' or have no header value defined are ignored. If 0 expressions are provided in total, this condition will match to any request.- 参数:
produces- expressions with syntax defined byRequestMapping.produces()headers- expressions with syntax defined byRequestMapping.headers()
-
ProducesRequestCondition
public ProducesRequestCondition(String[] produces, @Nullable String[] headers, @Nullable ContentNegotiationManager manager) Same asProducesRequestCondition(String[], String[])but also accepting aContentNegotiationManager.- 参数:
produces- expressions with syntax defined byRequestMapping.produces()headers- expressions with syntax defined byRequestMapping.headers()manager- used to determine requested media types
-
ProducesRequestCondition
private ProducesRequestCondition(List<MediaTypeExpression> expressions, ProducesRequestCondition other) Private constructor for internal use to create matching conditions. Note the expressions List is neither sorted nor deep copied.
-
-
方法详细资料
-
getExpressions
Return the contained "produces" expressions. -
getProducibleMediaTypes
Return the contained producible media types excluding negated expressions. -
isEmpty
public boolean isEmpty()Whether the condition has any media type expressions.- 覆盖:
isEmpty在类中AbstractRequestCondition<ProducesRequestCondition>- 返回:
trueif empty;falseotherwise
-
getContent
从类复制的说明:AbstractRequestConditionReturn the discrete items a request condition is composed of.For example URL patterns, HTTP request methods, param expressions, etc.
- 指定者:
getContent在类中AbstractRequestCondition<ProducesRequestCondition>- 返回:
- a collection of objects (never
null)
-
getToStringInfix
从类复制的说明:AbstractRequestConditionThe notation to use when printing discrete items of content.For example
" || "for URL patterns or" && "for param expressions. -
combine
Returns the "other" instance if it has any expressions; returns "this" instance otherwise. Practically that means a method-level "produces" overrides a type-level "produces" condition.- 参数:
other- the condition to combine with.- 返回:
- a request condition instance that is the result of combining the two condition instances.
-
getMatchingCondition
Checks if any of the contained media type expressions match the given request 'Content-Type' header and returns an instance that is guaranteed to contain matching expressions only. The match is performed viaMediaType.isCompatibleWith(MediaType).- 参数:
request- the current request- 返回:
- the same instance if there are no expressions;
or a new condition with matching expressions;
or
nullif no expressions match.
-
getMatchingExpressions
@Nullable private List<MediaTypeExpression> getMatchingExpressions(List<MediaType> acceptedMediaTypes) -
compareTo
Compares this and another "produces" condition as follows:- Sort 'Accept' header media types by quality value via
MimeTypeUtils.sortBySpecificity(List)and iterate the list. - Get the first index of matching media types in each "produces"
condition first matching with
MimeType.equals(Object)and then withMediaType.includes(MediaType). - If a lower index is found, the condition at that index wins.
- If both indexes are equal, the media types at the index are
compared further with
MediaType.isMoreSpecific(MimeType).
It is assumed that both instances have been obtained via
getMatchingCondition(RequestContext)and each instance contains the matching producible media type expression only or is otherwise empty.request- the current request context
- Sort 'Accept' header media types by quality value via
-
getAcceptedMediaTypes
private List<MediaType> getAcceptedMediaTypes(RequestContext request) throws HttpMediaTypeNotAcceptableException -
indexOfEqualMediaType
-
indexOfIncludedMediaType
-
compareMatchingMediaTypes
private int compareMatchingMediaTypes(ProducesRequestCondition condition1, int index1, ProducesRequestCondition condition2, int index2) -
getExpressionsToCompare
Return the contained "produces" expressions or if that's empty, a list with a "*/*" expression.
-