|
|
@ -234,16 +234,15 @@ public class MediaType extends MimeType implements Serializable { |
|
|
|
* Create a new {@code MediaType} for the given type, subtype, and character set. |
|
|
|
* Create a new {@code MediaType} for the given type, subtype, and character set. |
|
|
|
* @param type the primary type |
|
|
|
* @param type the primary type |
|
|
|
* @param subtype the subtype |
|
|
|
* @param subtype the subtype |
|
|
|
* @param charSet the character set |
|
|
|
* @param charset the character set |
|
|
|
* @throws IllegalArgumentException if any of the parameters contain illegal characters |
|
|
|
* @throws IllegalArgumentException if any of the parameters contain illegal characters |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MediaType(String type, String subtype, Charset charSet) { |
|
|
|
public MediaType(String type, String subtype, Charset charset) { |
|
|
|
super(type, subtype, charSet); |
|
|
|
super(type, subtype, charset); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new {@code MediaType} for the given type, subtype, and quality value. |
|
|
|
* Create a new {@code MediaType} for the given type, subtype, and quality value. |
|
|
|
* |
|
|
|
|
|
|
|
* @param type the primary type |
|
|
|
* @param type the primary type |
|
|
|
* @param subtype the subtype |
|
|
|
* @param subtype the subtype |
|
|
|
* @param qualityValue the quality value |
|
|
|
* @param qualityValue the quality value |
|
|
@ -275,6 +274,7 @@ public class MediaType extends MimeType implements Serializable { |
|
|
|
super(type, subtype, parameters); |
|
|
|
super(type, subtype, parameters); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void checkParameters(String attribute, String value) { |
|
|
|
protected void checkParameters(String attribute, String value) { |
|
|
|
super.checkParameters(attribute, value); |
|
|
|
super.checkParameters(attribute, value); |
|
|
|
if (PARAM_QUALITY_FACTOR.equals(attribute)) { |
|
|
|
if (PARAM_QUALITY_FACTOR.equals(attribute)) { |
|
|
@ -343,6 +343,7 @@ public class MediaType extends MimeType implements Serializable { |
|
|
|
return new MediaType(this, params); |
|
|
|
return new MediaType(this, params); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Parse the given String value into a {@code MediaType} object, |
|
|
|
* Parse the given String value into a {@code MediaType} object, |
|
|
|
* with this method name following the 'valueOf' naming convention |
|
|
|
* with this method name following the 'valueOf' naming convention |
|
|
@ -360,7 +361,6 @@ public class MediaType extends MimeType implements Serializable { |
|
|
|
* @throws InvalidMediaTypeException if the string cannot be parsed |
|
|
|
* @throws InvalidMediaTypeException if the string cannot be parsed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static MediaType parseMediaType(String mediaType) { |
|
|
|
public static MediaType parseMediaType(String mediaType) { |
|
|
|
|
|
|
|
|
|
|
|
MimeType type; |
|
|
|
MimeType type; |
|
|
|
try { |
|
|
|
try { |
|
|
|
type = MimeTypeUtils.parseMimeType(mediaType); |
|
|
|
type = MimeTypeUtils.parseMimeType(mediaType); |
|
|
@ -368,7 +368,6 @@ public class MediaType extends MimeType implements Serializable { |
|
|
|
catch (InvalidMimeTypeException ex) { |
|
|
|
catch (InvalidMimeTypeException ex) { |
|
|
|
throw new InvalidMediaTypeException(ex); |
|
|
|
throw new InvalidMediaTypeException(ex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
return new MediaType(type.getType(), type.getSubtype(), type.getParameters()); |
|
|
|
return new MediaType(type.getType(), type.getSubtype(), type.getParameters()); |
|
|
|
} |
|
|
|
} |
|
|
@ -412,18 +411,18 @@ public class MediaType extends MimeType implements Serializable { |
|
|
|
* Sorts the given list of {@code MediaType} objects by specificity. |
|
|
|
* Sorts the given list of {@code MediaType} objects by specificity. |
|
|
|
* <p>Given two media types: |
|
|
|
* <p>Given two media types: |
|
|
|
* <ol> |
|
|
|
* <ol> |
|
|
|
* <li>if either media type has a {@linkplain #isWildcardType() wildcard type}, then the media type without the |
|
|
|
* <li>if either media type has a {@linkplain #isWildcardType() wildcard type}, then the media type without the |
|
|
|
* wildcard is ordered before the other.</li> |
|
|
|
* wildcard is ordered before the other.</li> |
|
|
|
* <li>if the two media types have different {@linkplain #getType() types}, then they are considered equal and |
|
|
|
* <li>if the two media types have different {@linkplain #getType() types}, then they are considered equal and |
|
|
|
* remain their current order.</li> |
|
|
|
* remain their current order.</li> |
|
|
|
* <li>if either media type has a {@linkplain #isWildcardSubtype() wildcard subtype}, then the media type without |
|
|
|
* <li>if either media type has a {@linkplain #isWildcardSubtype() wildcard subtype}, then the media type without |
|
|
|
* the wildcard is sorted before the other.</li> |
|
|
|
* the wildcard is sorted before the other.</li> |
|
|
|
* <li>if the two media types have different {@linkplain #getSubtype() subtypes}, then they are considered equal |
|
|
|
* <li>if the two media types have different {@linkplain #getSubtype() subtypes}, then they are considered equal |
|
|
|
* and remain their current order.</li> |
|
|
|
* and remain their current order.</li> |
|
|
|
* <li>if the two media types have different {@linkplain #getQualityValue() quality value}, then the media type |
|
|
|
* <li>if the two media types have different {@linkplain #getQualityValue() quality value}, then the media type |
|
|
|
* with the highest quality value is ordered before the other.</li> |
|
|
|
* with the highest quality value is ordered before the other.</li> |
|
|
|
* <li>if the two media types have a different amount of {@linkplain #getParameter(String) parameters}, then the |
|
|
|
* <li>if the two media types have a different amount of {@linkplain #getParameter(String) parameters}, then the |
|
|
|
* media type with the most parameters is ordered before the other.</li> |
|
|
|
* media type with the most parameters is ordered before the other.</li> |
|
|
|
* </ol> |
|
|
|
* </ol> |
|
|
|
* <p>For example: |
|
|
|
* <p>For example: |
|
|
|
* <blockquote>audio/basic < audio/* < */*</blockquote> |
|
|
|
* <blockquote>audio/basic < audio/* < */*</blockquote> |
|
|
@ -445,18 +444,18 @@ public class MediaType extends MimeType implements Serializable { |
|
|
|
* Sorts the given list of {@code MediaType} objects by quality value. |
|
|
|
* Sorts the given list of {@code MediaType} objects by quality value. |
|
|
|
* <p>Given two media types: |
|
|
|
* <p>Given two media types: |
|
|
|
* <ol> |
|
|
|
* <ol> |
|
|
|
* <li>if the two media types have different {@linkplain #getQualityValue() quality value}, then the media type |
|
|
|
* <li>if the two media types have different {@linkplain #getQualityValue() quality value}, then the media type |
|
|
|
* with the highest quality value is ordered before the other.</li> |
|
|
|
* with the highest quality value is ordered before the other.</li> |
|
|
|
* <li>if either media type has a {@linkplain #isWildcardType() wildcard type}, then the media type without the |
|
|
|
* <li>if either media type has a {@linkplain #isWildcardType() wildcard type}, then the media type without the |
|
|
|
* wildcard is ordered before the other.</li> |
|
|
|
* wildcard is ordered before the other.</li> |
|
|
|
* <li>if the two media types have different {@linkplain #getType() types}, then they are considered equal and |
|
|
|
* <li>if the two media types have different {@linkplain #getType() types}, then they are considered equal and |
|
|
|
* remain their current order.</li> |
|
|
|
* remain their current order.</li> |
|
|
|
* <li>if either media type has a {@linkplain #isWildcardSubtype() wildcard subtype}, then the media type without |
|
|
|
* <li>if either media type has a {@linkplain #isWildcardSubtype() wildcard subtype}, then the media type without |
|
|
|
* the wildcard is sorted before the other.</li> |
|
|
|
* the wildcard is sorted before the other.</li> |
|
|
|
* <li>if the two media types have different {@linkplain #getSubtype() subtypes}, then they are considered equal |
|
|
|
* <li>if the two media types have different {@linkplain #getSubtype() subtypes}, then they are considered equal |
|
|
|
* and remain their current order.</li> |
|
|
|
* and remain their current order.</li> |
|
|
|
* <li>if the two media types have a different amount of {@linkplain #getParameter(String) parameters}, then the |
|
|
|
* <li>if the two media types have a different amount of {@linkplain #getParameter(String) parameters}, then the |
|
|
|
* media type with the most parameters is ordered before the other.</li> |
|
|
|
* media type with the most parameters is ordered before the other.</li> |
|
|
|
* </ol> |
|
|
|
* </ol> |
|
|
|
* @param mediaTypes the list of media types to be sorted |
|
|
|
* @param mediaTypes the list of media types to be sorted |
|
|
|
* @see #getQualityValue() |
|
|
|
* @see #getQualityValue() |
|
|
@ -524,6 +523,7 @@ public class MediaType extends MimeType implements Serializable { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Comparator used by {@link #sortBySpecificity(List)}. |
|
|
|
* Comparator used by {@link #sortBySpecificity(List)}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|