org.glassfish.jersey.message.internal
Class MediaTypes

java.lang.Object
  extended by org.glassfish.jersey.message.internal.MediaTypes

public class MediaTypes
extends Object

Common media types and functionality.

Author:
Paul Sandoz, Marek Potociar (marek.potociar at oracle.com)

Field Summary
static javax.ws.rs.core.MediaType FAST_INFOSET
          Fast infoset media type.
static javax.ws.rs.core.MediaType GENERAL_MEDIA_TYPE
          The general media type corresponding to \*\/*.
static List<javax.ws.rs.core.MediaType> GENERAL_MEDIA_TYPE_LIST
          A singleton list containing the general media type.
static List<javax.ws.rs.core.MediaType> GENERAL_QUALITY_SOURCE_MEDIA_TYPE_LIST
          A singleton list containing the general media type.
static Comparator<javax.ws.rs.core.MediaType> MEDIA_TYPE_COMPARATOR
          Comparator for media types.
static Comparator<List<? extends javax.ws.rs.core.MediaType>> MEDIA_TYPE_LIST_COMPARATOR
          Comparator for lists of media types.
static Comparator<QualitySourceMediaType> QUALITY_SOURCE_MEDIA_TYPE_COMPARATOR
          Comparator for lists of quality source media types.
static javax.ws.rs.core.MediaType WADL
          WADL Media type.
 
Method Summary
static String convertToString(Iterable<javax.ws.rs.core.MediaType> mediaTypes)
          Convert media types into String.
static List<javax.ws.rs.core.MediaType> createFrom(javax.ws.rs.Consumes annotation)
          Create the list of media types from the values declared in the Consumes annotation.
static List<javax.ws.rs.core.MediaType> createFrom(javax.ws.rs.Produces annotation)
          Create the list of media types from the values declared in the Produces annotation.
static List<javax.ws.rs.core.MediaType> createFrom(String[] mediaTypes)
          Create a list of media type from a string 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 List<QualitySourceMediaType> createQualitySourceMediaTypes(String[] mediaTypes)
          Create a list of quality source media type from an array of media types.
static int getQuality(javax.ws.rs.core.MediaType mt)
          Reads quality factor from given media type.
static javax.ws.rs.core.MediaType getTypeWildCart(javax.ws.rs.core.MediaType mediaType)
          Returns MediaType with wildcard in subtype.
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 common type-equal sub-list.
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.
static javax.ws.rs.core.MediaType stripQualityParams(javax.ws.rs.core.MediaType mediaType)
          Strips any quality parameters, i.e.
static boolean typeEqual(javax.ws.rs.core.MediaType m1, javax.ws.rs.core.MediaType m2)
          Determine if the two media types are type-equal (their type and subtype are equal).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WADL

public static final javax.ws.rs.core.MediaType WADL
WADL Media type.


FAST_INFOSET

public static final javax.ws.rs.core.MediaType FAST_INFOSET
Fast infoset media type.


MEDIA_TYPE_LIST_COMPARATOR

public static final Comparator<List<? extends javax.ws.rs.core.MediaType>> MEDIA_TYPE_LIST_COMPARATOR
Comparator for lists of media types.

The least specific content type of each list is obtained and then compared using MEDIA_TYPE_COMPARATOR.

Assumes each list is already ordered according to MEDIA_TYPE_COMPARATOR and therefore the least specific media type is at the end of the list.


GENERAL_MEDIA_TYPE

public static final javax.ws.rs.core.MediaType GENERAL_MEDIA_TYPE
The general media type corresponding to \*\/*.


GENERAL_MEDIA_TYPE_LIST

public static final List<javax.ws.rs.core.MediaType> GENERAL_MEDIA_TYPE_LIST
A singleton list containing the general media type.


GENERAL_QUALITY_SOURCE_MEDIA_TYPE_LIST

public static final List<javax.ws.rs.core.MediaType> GENERAL_QUALITY_SOURCE_MEDIA_TYPE_LIST
A singleton list containing the general media type.


QUALITY_SOURCE_MEDIA_TYPE_COMPARATOR

public static final Comparator<QualitySourceMediaType> QUALITY_SOURCE_MEDIA_TYPE_COMPARATOR
Comparator for lists of quality source media types.


MEDIA_TYPE_COMPARATOR

public static final Comparator<javax.ws.rs.core.MediaType> MEDIA_TYPE_COMPARATOR
Comparator for media types. 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

Method Detail

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 (their type and subtype are 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:
true if the two media types are of the same type and subtype, false otherwise.

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 common type-equal sub-list.

Parameters:
ml1 - first media type list.
ml2 - second media type list.
Returns:
true if the two media type lists intersect by sharing a common type-equal sub-list, false otherwise.

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.

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

public static List<javax.ws.rs.core.MediaType> createFrom(javax.ws.rs.Consumes annotation)
Create the list of media types from the values declared in the Consumes annotation.

Parameters:
annotation - the Consumes annotation.
Returns:
the list of MediaType, ordered according to MEDIA_TYPE_COMPARATOR.

createFrom

public static List<javax.ws.rs.core.MediaType> createFrom(javax.ws.rs.Produces annotation)
Create the list of media types from the values declared in the Produces annotation.

Parameters:
annotation - the Produces annotation.
Returns:
the list of MediaType, ordered according to MEDIA_TYPE_COMPARATOR.

createFrom

public static List<javax.ws.rs.core.MediaType> createFrom(String[] mediaTypes)
Create a 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 to MEDIA_TYPE_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 to QUALITY_SOURCE_MEDIA_TYPE_COMPARATOR.

createQualitySourceMediaTypes

public static List<QualitySourceMediaType> createQualitySourceMediaTypes(String[] mediaTypes)
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 and MEDIA_TYPE_COMPARATOR as 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

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

public static String convertToString(Iterable<javax.ws.rs.core.MediaType> mediaTypes)
Convert media types into String. The result string contains media types in the same order, separated by comma ',' and enclosed into quotes. For example for input media types MediaType.TEXT_PLAIN_TYPE, MediaType.TEXT_PLAIN_TYPE and MediaType.APPLICATION_JSON_TYPE the result will be "text/plain", "application/json", "text/html".

Parameters:
mediaTypes - iterable with media types.
Returns:
Media types converted into String.


Copyright © 2007-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.