public final class ProducesRequestCondition extends AbstractRequestCondition<ProducesRequestCondition>
RequestMapping.produces()
and
RequestMapping.headers()
where the header name is 'Accept'.
Regardless of which syntax is used, the semantics are the same.Modifier and Type | Class and Description |
---|---|
(package private) class |
ProducesRequestCondition.ProduceMediaTypeExpression
Parses and matches a single media type expression to a request's 'Accept' header.
|
Modifier and Type | Field and Description |
---|---|
private ContentNegotiationManager |
contentNegotiationManager |
private java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> |
expressions |
private java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> |
MEDIA_TYPE_ALL_LIST |
Modifier | Constructor and Description |
---|---|
private |
ProducesRequestCondition(java.util.Collection<ProducesRequestCondition.ProduceMediaTypeExpression> expressions,
ContentNegotiationManager manager)
Private constructor with already parsed media type expressions.
|
|
ProducesRequestCondition(java.lang.String... produces)
Creates a new instance from "produces" expressions.
|
|
ProducesRequestCondition(java.lang.String[] produces,
java.lang.String[] headers)
Creates a new instance with "produces" and "header" expressions.
|
|
ProducesRequestCondition(java.lang.String[] produces,
java.lang.String[] headers,
ContentNegotiationManager manager)
Same as
ProducesRequestCondition(String[], String[]) but also
accepting a ContentNegotiationManager . |
Modifier and Type | Method and Description |
---|---|
ProducesRequestCondition |
combine(ProducesRequestCondition other)
Returns the "other" instance if it has any expressions; returns "this"
instance otherwise.
|
private int |
compareMatchingMediaTypes(ProducesRequestCondition condition1,
int index1,
ProducesRequestCondition condition2,
int index2) |
int |
compareTo(ProducesRequestCondition other,
HttpServletRequest request)
Compares this and another "produces" condition as follows:
Sort 'Accept' header media types by quality value via
MediaType.sortByQualityValue(List) and iterate the list. |
private java.util.List<MediaType> |
getAcceptedMediaTypes(HttpServletRequest request) |
protected java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> |
getContent()
Return the discrete items a request condition is composed of.
|
java.util.Set<MediaTypeExpression> |
getExpressions()
Return the contained "produces" expressions.
|
private java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> |
getExpressionsToCompare()
Return the contained "produces" expressions or if that's empty, a list
with a
MediaType_ALL expression. |
ProducesRequestCondition |
getMatchingCondition(HttpServletRequest 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.
|
java.util.Set<MediaType> |
getProducibleMediaTypes()
Return the contained producible media types excluding negated expressions.
|
protected java.lang.String |
getToStringInfix()
The notation to use when printing discrete items of content.
|
private int |
indexOfEqualMediaType(MediaType mediaType) |
private int |
indexOfIncludedMediaType(MediaType mediaType) |
boolean |
isEmpty()
Whether the condition has any media type expressions.
|
private java.util.Set<ProducesRequestCondition.ProduceMediaTypeExpression> |
parseExpressions(java.lang.String[] produces,
java.lang.String[] headers) |
equals, hashCode, toString
private final java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> MEDIA_TYPE_ALL_LIST
private final java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> expressions
private final ContentNegotiationManager contentNegotiationManager
public ProducesRequestCondition(java.lang.String... produces)
produces
- expressions with syntax defined by RequestMapping.produces()
public ProducesRequestCondition(java.lang.String[] produces, java.lang.String[] headers)
produces
- expressions with syntax defined by RequestMapping.produces()
headers
- expressions with syntax defined by RequestMapping.headers()
public ProducesRequestCondition(java.lang.String[] produces, java.lang.String[] headers, ContentNegotiationManager manager)
ProducesRequestCondition(String[], String[])
but also
accepting a ContentNegotiationManager
.produces
- expressions with syntax defined by RequestMapping.produces()
headers
- expressions with syntax defined by RequestMapping.headers()
manager
- used to determine requested media typesprivate ProducesRequestCondition(java.util.Collection<ProducesRequestCondition.ProduceMediaTypeExpression> expressions, ContentNegotiationManager manager)
private java.util.Set<ProducesRequestCondition.ProduceMediaTypeExpression> parseExpressions(java.lang.String[] produces, java.lang.String[] headers)
public java.util.Set<MediaTypeExpression> getExpressions()
public java.util.Set<MediaType> getProducibleMediaTypes()
public boolean isEmpty()
protected java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> getContent()
AbstractRequestCondition
getContent
in class AbstractRequestCondition<ProducesRequestCondition>
null
protected java.lang.String getToStringInfix()
AbstractRequestCondition
getToStringInfix
in class AbstractRequestCondition<ProducesRequestCondition>
public ProducesRequestCondition combine(ProducesRequestCondition other)
other
- the condition to combine with.public ProducesRequestCondition getMatchingCondition(HttpServletRequest request)
MediaType.isCompatibleWith(MediaType)
.request
- the current requestnull
if no expressions match.public int compareTo(ProducesRequestCondition other, HttpServletRequest request)
MediaType.sortByQualityValue(List)
and iterate the list.
MediaType.equals(Object)
and
then with MediaType.includes(MediaType)
.
MediaType.SPECIFICITY_COMPARATOR
.
It is assumed that both instances have been obtained via
getMatchingCondition(HttpServletRequest)
and each instance
contains the matching producible media type expression only or
is otherwise empty.
private java.util.List<MediaType> getAcceptedMediaTypes(HttpServletRequest request) throws HttpMediaTypeNotAcceptableException
private int indexOfEqualMediaType(MediaType mediaType)
private int indexOfIncludedMediaType(MediaType mediaType)
private int compareMatchingMediaTypes(ProducesRequestCondition condition1, int index1, ProducesRequestCondition condition2, int index2)
private java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> getExpressionsToCompare()
MediaType_ALL
expression.