|
|
|
@ -30,13 +30,13 @@ import org.springframework.core.CollectionFactory; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Represents an Internet Media Type, as defined in the HTTP specification. |
|
|
|
* Represents an Internet Media Type, as defined in the HTTP specification. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>Consists of a {@linkplain #getType() type} |
|
|
|
* <p>Consists of a {@linkplain #getType() type} and a {@linkplain #getSubtype() subtype}. Also has functionality to |
|
|
|
* and a {@linkplain #getSubtype() subtype}. Also has functionality to parse media types from a string using |
|
|
|
* parse media types from a string using {@link #parseMediaType(String)}, or multiple comma-separated media types using |
|
|
|
* {@link #parseMediaType(String)}, or multiple comma-separated media types using {@link #parseMediaTypes(String)}. |
|
|
|
* {@link #parseMediaTypes(String)}. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @since 3.0 |
|
|
|
|
|
|
|
* @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7">HTTP 1.1</a> |
|
|
|
* @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7">HTTP 1.1</a> |
|
|
|
|
|
|
|
* @since 3.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public final class MediaType implements Comparable<MediaType> { |
|
|
|
public final class MediaType implements Comparable<MediaType> { |
|
|
|
|
|
|
|
|
|
|
|
@ -150,8 +150,8 @@ public final class MediaType implements Comparable<MediaType> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Parses the given, comma-seperated string into a list of {@link MediaType} objects. This method can be used to |
|
|
|
* Parses the given, comma-seperated string into a list of {@link MediaType} objects. This method can be used to parse |
|
|
|
* parse an Accept or Content-Type header. |
|
|
|
* an Accept or Content-Type header. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param mediaTypes the string to parse |
|
|
|
* @param mediaTypes the string to parse |
|
|
|
* @return the list of media types |
|
|
|
* @return the list of media types |
|
|
|
@ -234,8 +234,8 @@ public final class MediaType implements Comparable<MediaType> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Indicates whether this {@link MediaType} includes the given media type. For instance, <code>text/*</code> |
|
|
|
* Indicates whether this {@link MediaType} includes the given media type. For instance, <code>text/*</code> includes |
|
|
|
* includes <code>text/plain</code>, <code>text/html</code>, etc. |
|
|
|
* <code>text/plain</code>, <code>text/html</code>, etc. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param other the reference media type with which to compare |
|
|
|
* @param other the reference media type with which to compare |
|
|
|
* @return <code>true</code> if this media type includes the given media type; <code>false</code> otherwise |
|
|
|
* @return <code>true</code> if this media type includes the given media type; <code>false</code> otherwise |
|
|
|
@ -254,13 +254,13 @@ public final class MediaType implements Comparable<MediaType> { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Compares this {@link MediaType} to another. Sorting with this comparator follows the general rule: <blockquote> |
|
|
|
* Compares this {@link MediaType} to another. Sorting with this comparator follows the general rule: <blockquote> |
|
|
|
* audio/basic < audio/* < */* </blockquote>. That is, an explicit media type is sorted before an |
|
|
|
* audio/basic < audio/* < */* </blockquote>. That is, an explicit media type is sorted before an unspecific |
|
|
|
* unspecific media type. Quality parameters are also considered, so that <blockquote> audio/* < audio/*;q=0.7; |
|
|
|
* media type. Quality parameters are also considered, so that <blockquote> audio/* < audio/*;q=0.7; |
|
|
|
* audio/*;q=0.3</blockquote>. |
|
|
|
* audio/*;q=0.3</blockquote>. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param other the media type to compare to |
|
|
|
* @param other the media type to compare to |
|
|
|
* @return a negative integer, zero, or a positive integer as this media type is less than, equal to, or greater |
|
|
|
* @return a negative integer, zero, or a positive integer as this media type is less than, equal to, or greater than |
|
|
|
* than the specified media type |
|
|
|
* the specified media type |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public int compareTo(MediaType other) { |
|
|
|
public int compareTo(MediaType other) { |
|
|
|
double qVal1 = this.getQualityValue(); |
|
|
|
double qVal1 = this.getQualityValue(); |
|
|
|
@ -339,7 +339,7 @@ public final class MediaType implements Comparable<MediaType> { |
|
|
|
MediaType mediaType = iterator.next(); |
|
|
|
MediaType mediaType = iterator.next(); |
|
|
|
mediaType.appendTo(builder); |
|
|
|
mediaType.appendTo(builder); |
|
|
|
if (iterator.hasNext()) { |
|
|
|
if (iterator.hasNext()) { |
|
|
|
builder.append(','); |
|
|
|
builder.append(", "); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return builder.toString(); |
|
|
|
return builder.toString(); |
|
|
|
|