org.restlet.client.data
Class MediaType

java.lang.Object
  extended by org.restlet.client.data.Metadata
      extended by org.restlet.client.data.MediaType

public final class MediaType
extends Metadata

Media type used in representations and preferences. The Metadata.getName() method returns a full String representation of the media type including the parameters.

Author:
Jerome Louvel
See Also:
MIME types on Wikipedia

Field Summary
static MediaType ALL
           
static MediaType APPLICATION_ALL
           
static MediaType APPLICATION_ALL_XML
           
static MediaType APPLICATION_ATOM
           
static MediaType APPLICATION_JAVA_OBJECT_GWT
           
static MediaType APPLICATION_JAVASCRIPT
           
static MediaType APPLICATION_JSON
           
static MediaType APPLICATION_WWW_FORM
           
static MediaType APPLICATION_XHTML
           
static MediaType APPLICATION_XHTML_XML
          Deprecated. Use APPLICATION_XHTML instead.
static MediaType APPLICATION_XMI_XML
           
static MediaType APPLICATION_XML
           
static MediaType TEXT_ALL
           
static MediaType TEXT_CSS
           
static MediaType TEXT_HTML
           
static MediaType TEXT_JAVASCRIPT
           
static MediaType TEXT_PLAIN
           
static MediaType TEXT_URI_LIST
           
static MediaType TEXT_XML
           
 
Constructor Summary
MediaType(String name)
          Constructor.
MediaType(String name, Series<Parameter> parameters)
          Constructor.
MediaType(String name, Series<Parameter> parameters, String description)
          Constructor.
MediaType(String name, String description)
          Constructor.
 
Method Summary
 boolean equals(Object obj)
          
 boolean equals(Object obj, boolean ignoreParameters)
          Test the equality of two media types, with the possibility to ignore the parameters.
 String getMainType()
          Returns the main type.
static MediaType getMostSpecific(MediaType... mediaTypes)
          Returns the first of the most specific media type of the given array of MediaTypes.
 Series<Parameter> getParameters()
          Returns the unmodifiable list of parameters.
 MediaType getParent()
          Returns the parent metadata if available or null.
In case the media type has parameters, this method returns the concatenation of the main type and the subtype.
 String getSubType()
          Returns the sub-type.
 int hashCode()
          
 boolean includes(Metadata included)
          Indicates if a given media type is included in the current one.
 boolean isConcrete()
          Checks if the current media type is concrete.
static MediaType register(String name, String description)
          Register a media type as a known type that can later be retrieved using valueOf(String).
 String toString()
          Returns the metadata name.
static MediaType valueOf(String name)
          Returns the media type associated to a name.
 
Methods inherited from class org.restlet.client.data.Metadata
getDescription, getName, isCompatible
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ALL

public static final MediaType ALL

APPLICATION_ALL

public static final MediaType APPLICATION_ALL

APPLICATION_ALL_XML

public static final MediaType APPLICATION_ALL_XML

APPLICATION_ATOM

public static final MediaType APPLICATION_ATOM

APPLICATION_JAVA_OBJECT_GWT

public static final MediaType APPLICATION_JAVA_OBJECT_GWT

APPLICATION_JAVASCRIPT

public static final MediaType APPLICATION_JAVASCRIPT

APPLICATION_JSON

public static final MediaType APPLICATION_JSON

APPLICATION_WWW_FORM

public static final MediaType APPLICATION_WWW_FORM

APPLICATION_XHTML

public static final MediaType APPLICATION_XHTML

APPLICATION_XHTML_XML

@Deprecated
public static final MediaType APPLICATION_XHTML_XML
Deprecated. Use APPLICATION_XHTML instead.

APPLICATION_XMI_XML

public static final MediaType APPLICATION_XMI_XML

APPLICATION_XML

public static final MediaType APPLICATION_XML

TEXT_ALL

public static final MediaType TEXT_ALL

TEXT_CSS

public static final MediaType TEXT_CSS

TEXT_HTML

public static final MediaType TEXT_HTML

TEXT_JAVASCRIPT

public static final MediaType TEXT_JAVASCRIPT

TEXT_PLAIN

public static final MediaType TEXT_PLAIN

TEXT_URI_LIST

public static final MediaType TEXT_URI_LIST

TEXT_XML

public static final MediaType TEXT_XML
Constructor Detail

MediaType

public MediaType(String name)
Constructor.

Parameters:
name - The name.

MediaType

public MediaType(String name,
                 Series<Parameter> parameters)
Constructor.

Parameters:
name - The name.
parameters - The list of parameters.

MediaType

public MediaType(String name,
                 Series<Parameter> parameters,
                 String description)
Constructor.

Parameters:
name - The name.
parameters - The list of parameters.
description - The description.

MediaType

public MediaType(String name,
                 String description)
Constructor.

Parameters:
name - The name.
description - The description.
Method Detail

getMostSpecific

public static MediaType getMostSpecific(MediaType... mediaTypes)
                                 throws IllegalArgumentException
Returns the first of the most specific media type of the given array of MediaTypes.

Examples:

Parameters:
mediaTypes - An array of media types.
Returns:
The most concrete MediaType.
Throws:
IllegalArgumentException - If the array is null or empty.

register

public static MediaType register(String name,
                                 String description)
Register a media type as a known type that can later be retrieved using valueOf(String). If the type already exists, the existing type is returned, otherwise a new instance is created.

Parameters:
name - The name.
description - The description.
Returns:
The registered media type

valueOf

public static MediaType valueOf(String name)
Returns the media type associated to a name. If an existing constant exists then it is returned, otherwise a new instance is created.

Parameters:
name - The name.
Returns:
The associated media type.

equals

public boolean equals(Object obj)

Overrides:
equals in class Metadata

equals

public boolean equals(Object obj,
                      boolean ignoreParameters)
Test the equality of two media types, with the possibility to ignore the parameters.

Parameters:
obj - The object to compare to.
ignoreParameters - Indicates if parameters should be ignored during comparison.
Returns:
True if both media types are equal.

getMainType

public String getMainType()
Returns the main type.

Returns:
The main type.

getParameters

public Series<Parameter> getParameters()
Returns the unmodifiable list of parameters. Creates a new instance if no one has been set.

Returns:
The list of parameters.

getParent

public MediaType getParent()
Returns the parent metadata if available or null.
In case the media type has parameters, this method returns the concatenation of the main type and the subtype. If the subtype is not equal to "*", it returns the concatenation of the main type and "*". Otherwise, it returns either the ALL media type if it is already the ALL media type, or null.

Specified by:
getParent in class Metadata
Returns:
The parent metadata.

getSubType

public String getSubType()
Returns the sub-type.

Returns:
The sub-type.

hashCode

public int hashCode()

Overrides:
hashCode in class Metadata

includes

public boolean includes(Metadata included)
Indicates if a given media type is included in the current one. The test is true if both types are equal or if the given media type is within the range of the current one. For example, ALL includes all media types. Parameters are ignored for this comparison. A null media type is considered as included into the current one.

Examples:

Specified by:
includes in class Metadata
Parameters:
included - The media type to test for inclusion.
Returns:
True if the given media type is included in the current one.
See Also:
Metadata.isCompatible(Metadata)

isConcrete

public boolean isConcrete()
Checks if the current media type is concrete. A media type is concrete if neither the main type nor the sub-type are equal to "*".

Returns:
True if this media type is concrete.

toString

public String toString()
Description copied from class: Metadata
Returns the metadata name.

Overrides:
toString in class Metadata
Returns:
The metadata name.


Copyright © 2005-2011 Noelios Technologies.