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) static 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 static ContentNegotiationManager |
DEFAULT_CONTENT_NEGOTIATION_MANAGER |
private static ProducesRequestCondition |
EMPTY_CONDITION |
private java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> |
expressions |
private static java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> |
MEDIA_TYPE_ALL_LIST |
private static java.lang.String |
MEDIA_TYPES_ATTRIBUTE |
Modifier | Constructor and Description |
---|---|
private |
ProducesRequestCondition(java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> expressions,
ProducesRequestCondition other)
Private constructor for internal use to create matching conditions.
|
|
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 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.
|
private java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> |
getMatchingExpressions(java.util.List<MediaType> acceptedMediaTypes) |
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 static final ContentNegotiationManager DEFAULT_CONTENT_NEGOTIATION_MANAGER
private static final ProducesRequestCondition EMPTY_CONDITION
private static final java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> MEDIA_TYPE_ALL_LIST
private static final java.lang.String MEDIA_TYPES_ATTRIBUTE
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, @Nullable 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, @Nullable java.lang.String[] headers, @Nullable 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.List<ProducesRequestCondition.ProduceMediaTypeExpression> expressions, ProducesRequestCondition other)
private java.util.Set<ProducesRequestCondition.ProduceMediaTypeExpression> parseExpressions(java.lang.String[] produces, @Nullable java.lang.String[] headers)
public java.util.Set<MediaTypeExpression> getExpressions()
public java.util.Set<MediaType> getProducibleMediaTypes()
public boolean isEmpty()
isEmpty
in class AbstractRequestCondition<ProducesRequestCondition>
true
if empty; false
otherwiseprotected java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> getContent()
AbstractRequestCondition
For example URL patterns, HTTP request methods, param expressions, etc.
getContent
in class AbstractRequestCondition<ProducesRequestCondition>
null
)protected java.lang.String getToStringInfix()
AbstractRequestCondition
For example " || "
for URL patterns or " && "
for param expressions.
getToStringInfix
in class AbstractRequestCondition<ProducesRequestCondition>
public ProducesRequestCondition combine(ProducesRequestCondition other)
other
- the condition to combine with.@Nullable public ProducesRequestCondition getMatchingCondition(HttpServletRequest request)
MediaType.isCompatibleWith(MediaType)
.request
- the current requestnull
if no expressions match.@Nullable private java.util.List<ProducesRequestCondition.ProduceMediaTypeExpression> getMatchingExpressions(java.util.List<MediaType> acceptedMediaTypes)
public int compareTo(ProducesRequestCondition other, HttpServletRequest request)
MediaType.sortByQualityValue(List)
and iterate the list.
MimeType.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()