de.hedenus.www
Class ContentType

java.lang.Object
  extended by de.hedenus.www.ContentType
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class ContentType
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

An (immuatable) internet content type (MIME). See RFC 1521.

Author:
Michael Hedenus
See Also:
Serialized Form

Field Summary
static ContentType DEFAULT_CONTENT_TYPE
          The default type is application/octet-stream.
 
Constructor Summary
ContentType(java.lang.String spec)
          Creates a new content type.
ContentType(java.lang.String spec, java.lang.String title)
          Creates a new content type.
ContentType(java.lang.String mediaType, java.lang.String subType, java.util.Map parameters)
          Creates a new content type.
ContentType(java.lang.String mediaType, java.lang.String subType, java.util.Map parameters, java.lang.String title)
          Creates a new content type.
 
Method Summary
 int compareTo(java.lang.Object obj)
          Content types are ordered by their type string.
 boolean equals(java.lang.Object obj)
          Two content types are equal iff their type strings are equal.
 java.lang.String[] getAttributes()
          Returns all attributes (parameter keys).
 java.lang.String getMediaType()
          The media type, e.g.
 java.lang.String getParameter(java.lang.String key)
          Returns the value of parameter with the specified attribute key,. e.g. the key 'charset' may return 'US-ASCII'.
 java.lang.String getSubType()
          The sub type, e.g.
 java.lang.String getTitle()
          A human readable name for the type.
 java.lang.String getType()
          The full type, e.g.
 java.lang.String getTypeString()
          The complete type string, e.g.
 int hashCode()
           
static java.lang.String parseType(java.lang.String s)
          Parses the content type of a type string, i.e. media-type/sub-type without parameters.
 java.lang.String toString()
           
 boolean typeEquals(ContentType that)
          Returns true iff media-type and sub-type of this and the specified type are equal.
 boolean typeEquals(java.lang.String s)
          Returns true iff media-type and sub-type of this and the specified type string are equal.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CONTENT_TYPE

public static final ContentType DEFAULT_CONTENT_TYPE
The default type is application/octet-stream.

Constructor Detail

ContentType

public ContentType(java.lang.String mediaType,
                   java.lang.String subType,
                   java.util.Map parameters)
Creates a new content type.
Note: the parameter keys should be lowercase.

Parameters:
mediaType -
subType -
parameters -

ContentType

public ContentType(java.lang.String mediaType,
                   java.lang.String subType,
                   java.util.Map parameters,
                   java.lang.String title)
Creates a new content type.
Note: the parameter keys should be lowercase.

Parameters:
mediaType -
subType -
parameters -
title -

ContentType

public ContentType(java.lang.String spec)
Creates a new content type.

Parameters:
spec -

ContentType

public ContentType(java.lang.String spec,
                   java.lang.String title)
Creates a new content type.

Parameters:
spec -
title -
Method Detail

getType

public java.lang.String getType()
The full type, e.g. "text/plain".


getMediaType

public java.lang.String getMediaType()
The media type, e.g. "text" of "text/plain".


getSubType

public java.lang.String getSubType()
The sub type, e.g. "plain" of "text/plain".


getTypeString

public java.lang.String getTypeString()
The complete type string, e.g. "text/plain;charset=US-ASCII".


getTitle

public java.lang.String getTitle()
A human readable name for the type.


getParameter

public java.lang.String getParameter(java.lang.String key)
Returns the value of parameter with the specified attribute key,. e.g. the key 'charset' may return 'US-ASCII'.
Note: the key should belowercase.


getAttributes

public java.lang.String[] getAttributes()
Returns all attributes (parameter keys).


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

typeEquals

public boolean typeEquals(ContentType that)
Returns true iff media-type and sub-type of this and the specified type are equal.


typeEquals

public boolean typeEquals(java.lang.String s)
Returns true iff media-type and sub-type of this and the specified type string are equal.


parseType

public static java.lang.String parseType(java.lang.String s)
Parses the content type of a type string, i.e. media-type/sub-type without parameters.


hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Two content types are equal iff their type strings are equal.

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object obj)
Content types are ordered by their type string.

Specified by:
compareTo in interface java.lang.Comparable