Class MediaTypes
java.lang.Object
org.glassfish.jersey.message.internal.MediaTypes
Common media types and functionality.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<List<? extends javax.ws.rs.core.MediaType>> Comparator for lists of media types.static final Comparator<javax.ws.rs.core.MediaType> A comparator for media types, that implements the "partial order" defined in the resource matching algorithm section of the JAX-RS specification, except that this comparator is "inverted" so that it allows for natural sorting in Java collections, where "lower" values are put to the front of a collection.Predicate for constructing filtering parameter maps that ignore the "q" and "qs" parameters.static final javax.ws.rs.core.MediaTypeWADL Media type.static final AcceptableMediaTypeAn acceptable media type corresponding to a wildcard type.static final QualitySourceMediaTypeAn acceptable media type corresponding to a wildcard type.static final List<javax.ws.rs.core.MediaType> A singleton list containing the wildcard media type.Cache containing frequently requested media type values with a wildcard subtype.static final List<javax.ws.rs.core.MediaType> A singleton list containing the wildcard media type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertToString(Iterable<javax.ws.rs.core.MediaType> mediaTypes) Convert media types intoString.static List<javax.ws.rs.core.MediaType> createFrom(String[] mediaTypes) Create an unmodifiable list of media type from a string array of media types.static List<javax.ws.rs.core.MediaType> createFrom(javax.ws.rs.Consumes annotation) Create an unmodifiable list of media types from the values declared in theConsumesannotation.static List<javax.ws.rs.core.MediaType> createFrom(javax.ws.rs.Produces annotation) Create an unmodifiable list of media types from the values declared in theProducesannotation.static List<QualitySourceMediaType> createQualitySourceMediaTypes(String[] mediaTypes) Create a list of quality source media type from an array of media types.static List<javax.ws.rs.core.MediaType> createQualitySourceMediaTypes(javax.ws.rs.Produces mime) Create a list of quality source media type from the Produces annotation.static intgetQuality(javax.ws.rs.core.MediaType mt) Reads quality factor from given media type.static javax.ws.rs.core.MediaTypegetTypeWildCart(javax.ws.rs.core.MediaType mediaType) Returns MediaType with wildcard in subtype.static booleanintersect(List<? extends javax.ws.rs.core.MediaType> ml1, List<? extends javax.ws.rs.core.MediaType> ml2) Determine if the two list of media types share a commontype-equalsub-list.static booleanisWildcard(javax.ws.rs.core.MediaType mediaType) Check if the given media type is a wildcard type.static javax.ws.rs.core.MediaTypemostSpecific(javax.ws.rs.core.MediaType m1, javax.ws.rs.core.MediaType m2) Get the most specific media type from a pair of media types.private static intreadQualityFactor(String qParam) static javax.ws.rs.core.MediaTypestripQualityParams(javax.ws.rs.core.MediaType mediaType) Strips any quality parameters, i.e.static booleantypeEqual(javax.ws.rs.core.MediaType m1, javax.ws.rs.core.MediaType m2) Determine if the two media types are type-equal (theirtypeandsubtypeare equal).
-
Field Details
-
WADL_TYPE
public static final javax.ws.rs.core.MediaType WADL_TYPEWADL Media type. -
PARTIAL_ORDER_COMPARATOR
A comparator for media types, that implements the "partial order" defined in the resource matching algorithm section of the JAX-RS specification, except that this comparator is "inverted" so that it allows for natural sorting in Java collections, where "lower" values are put to the front of a collection. IOW, when used to sort a collection, the resulting collection can be iterated in a way that the more specific media types are preferred over the less specific ones:m/n < m/* < */*
The actual media type values are ignored, i.e. the different media types are considered equal if they are comparably specific:compare(m/n, x/y) == 0 compare(m/*, x/*) == 0
-
MEDIA_TYPE_LIST_COMPARATOR
public static final Comparator<List<? extends javax.ws.rs.core.MediaType>> MEDIA_TYPE_LIST_COMPARATORComparator for lists of media types.The least specific content type of each list is obtained and then compared using
PARTIAL_ORDER_COMPARATOR.Assumes each list is already ordered according to
PARTIAL_ORDER_COMPARATORand therefore the least specific media type is at the end of the list. -
WILDCARD_TYPE_SINGLETON_LIST
A singleton list containing the wildcard media type. -
WILDCARD_ACCEPTABLE_TYPE
An acceptable media type corresponding to a wildcard type. -
WILDCARD_QS_TYPE
An acceptable media type corresponding to a wildcard type. -
WILDCARD_QS_TYPE_SINGLETON_LIST
A singleton list containing the wildcard media type. -
WILDCARD_SUBTYPE_CACHE
-
QUALITY_PARAM_FILTERING_PREDICATE
-
-
Constructor Details
-
MediaTypes
private MediaTypes()Prevents initialization.
-
-
Method Details
-
typeEqual
public static boolean typeEqual(javax.ws.rs.core.MediaType m1, javax.ws.rs.core.MediaType m2) Determine if the two media types are type-equal (theirtypeandsubtypeare equal). For example:m/n == m/n m/n;p1 == m/n;p2 m/n != m/y m/n != x/n m/n != x/y
- Parameters:
m1- first media type.m2- second media type.- Returns:
trueif the two media types are of the same type and subtype,falseotherwise.
-
intersect
public static boolean intersect(List<? extends javax.ws.rs.core.MediaType> ml1, List<? extends javax.ws.rs.core.MediaType> ml2) Determine if the two list of media types share a commontype-equalsub-list.- Parameters:
ml1- first media type list.ml2- second media type list.- Returns:
trueif the two media type lists intersect by sharing a common type-equal sub-list,falseotherwise.
-
mostSpecific
public static javax.ws.rs.core.MediaType mostSpecific(javax.ws.rs.core.MediaType m1, javax.ws.rs.core.MediaType m2) Get the most specific media type from a pair of media types. The most specific media type is the media type from the pair that has least wild cards present, or has more parameters specified.- Parameters:
m1- the first media type.m2- the second media type.- Returns:
- the most specific media type. If the media types are equally specific then the first media type is returned.
-
createFrom
Create an unmodifiable list of media types from the values declared in theConsumesannotation.- Parameters:
annotation- the Consumes annotation.- Returns:
- the list of
MediaType, ordered according toPARTIAL_ORDER_COMPARATOR.
-
createFrom
Create an unmodifiable list of media types from the values declared in theProducesannotation.- Parameters:
annotation- the Produces annotation.- Returns:
- the list of
MediaType, ordered according toPARTIAL_ORDER_COMPARATOR.
-
createFrom
Create an unmodifiable list of media type from a string array of media types.- Parameters:
mediaTypes- the string array of media types.- Returns:
- the list of
MediaType, ordered according toPARTIAL_ORDER_COMPARATOR.
-
createQualitySourceMediaTypes
public static List<javax.ws.rs.core.MediaType> createQualitySourceMediaTypes(javax.ws.rs.Produces mime) Create a list of quality source media type from the Produces annotation.- Parameters:
mime- the Produces annotation.- Returns:
- the list of
QualitySourceMediaType, ordered according toQualitySourceMediaType.COMPARATOR.
-
createQualitySourceMediaTypes
Create a list of quality source media type from an array of media types.- Parameters:
mediaTypes- the array of media types.- Returns:
- the list of
QualitySourceMediaType, ordered according to the quality source as the primary key andPARTIAL_ORDER_COMPARATORas the secondary key.
-
getQuality
public static int getQuality(javax.ws.rs.core.MediaType mt) Reads quality factor from given media type.- Parameters:
mt- media type to read quality parameter from- Returns:
- quality factor of input media type
-
readQualityFactor
- Throws:
IllegalArgumentException
-
stripQualityParams
public static javax.ws.rs.core.MediaType stripQualityParams(javax.ws.rs.core.MediaType mediaType) Strips any quality parameters, i.e. q and qs from given media type.- Parameters:
mediaType- type to strip quality parameters from- Returns:
- media type instance corresponding to the given one with quality parameters stripped off or the original instance if no such parameters are present
-
getTypeWildCart
public static javax.ws.rs.core.MediaType getTypeWildCart(javax.ws.rs.core.MediaType mediaType) Returns MediaType with wildcard in subtype.- Parameters:
mediaType- original MediaType.- Returns:
- MediaType with wildcard in subtype.
-
convertToString
Convert media types intoString. The result string contains media types in the same order, separated by comma ',' and enclosed into quotes. For example for input media typesMediaType.TEXT_PLAIN_TYPE,MediaType.TEXT_PLAIN_TYPEandMediaType.APPLICATION_JSON_TYPEthe result will be "text/plain", "application/json", "text/html".- Parameters:
mediaTypes-iterablewithmedia types.- Returns:
- Media types converted into String.
-
isWildcard
public static boolean isWildcard(javax.ws.rs.core.MediaType mediaType) Check if the given media type is a wildcard type. A media type is considered to be a wildcard if either the media type's type or subtype is a wildcard type.- Parameters:
mediaType- media type.- Returns:
trueif the media type is a wildcard type,falseotherwise.
-