Project JXTA

net.jxta.document
Class MimeMediaType

java.lang.Object
  extended bynet.jxta.document.MimeMediaType
All Implemented Interfaces:
Serializable

public class MimeMediaType
extends Object
implements Serializable

MIME Media Types are used to describe the format of data streams. MIME Media Types are defined by IETF RFC 2046 MIME : Media Types. This class manages parsing of Mime Media Types from strings and piecemeal construction of Mime Media Type descriptors.

Note : This implementation does not include support for the character encoding techniques described by : IETF RFC 2046 MIME : Media Types.

See Also:
Document, StructuredDocument, StructuredDocumentFactory, StructuredTextDocument, Serialized Form

Field Summary
static MimeMediaType AOS
          Common Mime Media Type for arbitrary unparsed data.
static MimeMediaType TEXT_DEFAULTENCODING
          Common Mime Media Type for text encoded using the default character encoding for this JVM.
static MimeMediaType TEXTUTF8
          Common Mime Media Type for plain text encoded as UTF-8 characters.
static MimeMediaType XML_DEFAULTENCODING
          Common Mime Media Type for XML encoded using the default character encoding for this JVM.
static MimeMediaType XMLUTF8
          Common Mime Media Type for XML encoded as UTF-8 characters.
 
Constructor Summary
MimeMediaType(MimeMediaType type, String params, boolean replace)
          Creates a new type/subtype MimeMediaType with the specified parameters.
MimeMediaType(String mimetype)
          Creates a new MimeMediaType
MimeMediaType(String type, String subtype)
          Creates a new type/subtype MimeMediaType
MimeMediaType(String type, String subtype, String parameters)
          Creates a new type/subtype MimeMediaType
 
Method Summary
 boolean equals(Object obj)
          
 boolean equalsIngoringParams(Object obj)
          Similar to equals(Object), but ignores any parameters.
 String getMimeMediaType()
          Get the "root" mime-type/subtype without any of the parameters.
 String getParameter(String param)
          Get the value of the first occurance of the specified parameter from the parameter list.
 String getSubtype()
          Get the Subtype of the mime-type
 String getType()
          Get type of the mime-type
 int hashCode()
          
 MimeMediaType intern()
          Returns a canonical representation for the MimeMediaType object.
 boolean isExperimentalSubtype()
          Check if the mime-type is for debugging.
 boolean isExperimentalType()
          Check if the mime-type is for provisional.
 String toString()
          
static MimeMediaType valueOf(String mimetype)
          Returns a MimeMediaType with a value represented by the specified String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

AOS

public static final MimeMediaType AOS
Common Mime Media Type for arbitrary unparsed data.


TEXT_DEFAULTENCODING

public static final MimeMediaType TEXT_DEFAULTENCODING
Common Mime Media Type for text encoded using the default character encoding for this JVM. The default character encoding is specified by the JDK System property "file.encoding".

The default encoding varies with host platform and locale. This media type must not be used for any documents which will be exchanged with other peers (as they may be using different default character encodings).


TEXTUTF8

public static final MimeMediaType TEXTUTF8
Common Mime Media Type for plain text encoded as UTF-8 characters. This type is used by JXTA for all strings.


XML_DEFAULTENCODING

public static final MimeMediaType XML_DEFAULTENCODING
Common Mime Media Type for XML encoded using the default character encoding for this JVM. The default character encoding is specified by the JDK System property "file.encoding".

The default encoding varies with host platform and locale. This media type must not be used for any documents which will be exchanged with other peers (as they may be using different default character encodings).


XMLUTF8

public static final MimeMediaType XMLUTF8
Common Mime Media Type for XML encoded as UTF-8 characters. This type is used by JXTA for all protocol messages and metadata.

Constructor Detail

MimeMediaType

public MimeMediaType(String mimetype)
Creates a new MimeMediaType

Parameters:
mimetype - string representing a mime-type

MimeMediaType

public MimeMediaType(String type,
                     String subtype)
Creates a new type/subtype MimeMediaType

Parameters:
type - string representing a mime type
subtype - string representing a mime subtype

MimeMediaType

public MimeMediaType(String type,
                     String subtype,
                     String parameters)
Creates a new type/subtype MimeMediaType

Parameters:
type - string representing a mime type
subtype - string representing a mime subtype
parameters - parameters to the mime-type constructor

MimeMediaType

public MimeMediaType(MimeMediaType type,
                     String params,
                     boolean replace)
Creates a new type/subtype MimeMediaType with the specified parameters. The parameters are copied from the source mime type and additional params are added. If replace is true, then the provided params will overwrite the params from the source mime type.

Parameters:
type - the source mime type
params - parameters to the mime-type constructor
replace - parameters if true then provided params should replace existing params else they are accumulated.
Method Detail

equals

public boolean equals(Object obj)


equalsIngoringParams

public boolean equalsIngoringParams(Object obj)
Similar to equals(Object), but ignores any parameters. Compares only the type and sub-type.


hashCode

public int hashCode()


toString

public String toString()


getMimeMediaType

public String getMimeMediaType()
Get the "root" mime-type/subtype without any of the parameters.

Returns:
full mime-type/subtype

getType

public String getType()
Get type of the mime-type

Returns:
type of the mime-type

isExperimentalType

public boolean isExperimentalType()
Check if the mime-type is for provisional. See Section 2.1 of IETF RFC 2048 MIME : Registration Procedures

Returns:
boolean true if it is a provisional type

getSubtype

public String getSubtype()
Get the Subtype of the mime-type

Returns:
subtype of the mime-type

isExperimentalSubtype

public boolean isExperimentalSubtype()
Check if the mime-type is for debugging. This method will be removed

Returns:
boolean true if it is a debugging type

getParameter

public String getParameter(String param)
Get the value of the first occurance of the specified parameter from the parameter list.

Parameters:
param - the parameter to retrieve.
Returns:
the value of the specifid parameter or null if the parameter was not found.

valueOf

public static MimeMediaType valueOf(String mimetype)
Returns a MimeMediaType with a value represented by the specified String. This method may produce better results than using the constructor the same parameter set in that: new MimeMediaType( string ) != new MimeMediaType( string ) while for common types: MimeMediaType.valueOf( string ) == MimeMediaType.valueOf( string )


intern

public MimeMediaType intern()
Returns a canonical representation for the MimeMediaType object.

A pool of MimeMediaType, is maintained privately by the class.

When the intern method is invoked, if the pool already contains a MimeMediaType equal to this MimeMediaType object as determined by the equals(Object) method, then the MimeMediaType from the pool is returned. Otherwise, this MimeMediaType object is added to the pool and a reference to this MimeMediaType object is returned.

It follows that for any two MimeMediaType s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true

Returns:
a MimeMediaType that has the same value as this type, but is guaranteed to be from a pool of unique types.

JXTA J2SE