org.norther.tammi.acorn.mime
Class MimeType

java.lang.Object
  extended by org.norther.tammi.acorn.mime.MimeType
All Implemented Interfaces:
Serializable, Cloneable

public class MimeType
extends Object
implements Cloneable, Serializable

MimeType is used to represent parsed MIME types. The representation is parsed from a string based representation of the MIME type, as defined in the RFC1345.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
static String ANY_APPLICATION
          Any application type as a string.
static String ANY_TEXT
          Any text type as a string.
static String ANY_TYPE
          The wildcard.
static String APPLICATION_OCTET_STREAM
          Octet stream type as a string.
static MimeType APPLICATION_OCTET_STREAM_TYPE
          Octet stream type.
static String APPLICATION_POSTSCRIPT
          PostScript type as a string.
static MimeType APPLICATION_POSTSCRIPT_TYPE
          PostScript type.
static MimeType APPLICATION_TYPE
          Any application type.
static String APPLICATION_X_JAVA_AGENT
          Java agent type as a string.
static MimeType APPLICATION_X_JAVA_AGENT_TYPE
          Java agent type.
static String APPLICATION_X_WWW_FORM_URLENCODED
          WWW form type as a string.
static MimeType APPLICATION_X_WWW_FORM_URLENCODED_TYPE
          WWW form type.
static String APPLICATION_XHTML
          XHTML type as a string.
static MimeType APPLICATION_XHTML_TYPE
          XHTML type.
static String CHTML
          Extension .chtml.
static String DEFAULT
          The default type as a string.
static MimeType DEFAULT_TYPE
          The default type.
static String GIF
          Extension .gif.
static String HDM
          Extension .hdm.
static String HDML
          Extension .hdml.
static String HTM
          Extension .htm.
static String HTML
          Extension .html.
static String IMAGE_GIF
          GIF type as a string.
static MimeType IMAGE_GIF_TYPE
          GIF type.
static String IMAGE_JPEG
          JPEG type as a string.
static MimeType IMAGE_JPEG_TYPE
          JPEG type.
static String IMAGE_WBMP
          WBMP type as a string.
static MimeType IMAGE_WBMP_TYPE
          WBMP type.
static String JPEG
          Extension .jpeg.
static String JPG
          Extension .jpg.
static int MATCH_SPECIFIC_SUBTYPE
          Match specific subtype.
static int MATCH_SUBTYPE
          Match subtype.
static int MATCH_TYPE
          Match main type.
static String MESSAGE_HTTP
          HTTP message type as a string.
static MimeType MESSAGE_HTTP_TYPE
          HTTP Message type.
static String MULTIPART
          Multipart type as a string.
static String MULTIPART_FORM_DATA
          HTML form data type as a string.
static MimeType MULTIPART_FORM_DATA_TYPE
          HTML form data type.
static MimeType MULTIPART_TYPE
          Multipart type.
static int NO_MATCH
          No type match.
static String SMS
          Extension .sms.
static String TEXT_CSS
          CSS type as a string.
static MimeType TEXT_CSS_TYPE
          CSS type.
static String TEXT_HDML
          XHDML type as a string.
static MimeType TEXT_HDML_TYPE
          HDML type.
static String TEXT_HTML
          HTML type as a string.
static MimeType TEXT_HTML_TYPE
          HTML type.
static String TEXT_PLAIN
          Plain text type as a string.
static MimeType TEXT_PLAIN_TYPE
          Plain text type.
static MimeType TEXT_TYPE
          Any text type.
static String TEXT_WML
          WML type as a string.
static MimeType TEXT_WML_TYPE
          WML type.
static String TXT
          Extension .txt.
static String WBMP
          Extension .wbmp.
static String WML
          Extension .wml.
static String XHTML
          Extension .xhtml.
 
Constructor Summary
MimeType(String spec)
          Constructs a new MIME type by parsing a specification string.
MimeType(String spec, boolean parsep)
          Constructs a new MIME type by parsing a specification string.
MimeType(String type, String subtype)
          Contructs a new MIME type from specified types.
MimeType(String type, String subtype, String[] names, String[] values)
          Contructs a new MIME type from specified parameters.
 
Method Summary
 void addParameter(String param, String value)
          Adds a parameter to the MIME type.
 void addParameters(String[] params, String[] values)
          Adds parameters to the MIME type.
 Object clone()
          Clones this object.
 boolean containsParameter(String param)
          Checks whether the MIME type contains the specified parameter.
 String getParameter(String param)
          Gets the value of a MIME type parameter.
 String getSubtype()
          Gets the subtype of the MIME type.
 String getType()
          Gets the main type of the MIME type.
 int match(MimeType other)
          Compares the specified MIME type to this one and returns a matching level: NO_MATCH=types do not match, MATCH=types match, MATCH_SPECIFIC=types match exactly, MATCH_SUBTYPE=types match, subtypes match too, MATCH_SPECIFIC_SUBTYPE=types match, subtypes match exactly.
 int match(String other)
          Compares the specified MIME string to this one and returns a matching level: NO_MATCH=types do not match, MATCH=types match, MATCH_SPECIFIC=types match exactly, MATCH_SUBTYPE=types match, subtypes match too, MATCH_SPECIFIC_SUBTYPE=types match, subtypes match exactly.
 void removeParameter(String param)
          Removes a parameter from the MIME type.
 void setParameter(String param, String value)
          Sets the value of a MIME type parameter replacing the old one.
 String toString()
          Converts the MIME type into a string.
 String toString(boolean params)
          Converts the MIME type into a string with or without parameters.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANY_TYPE

public static final String ANY_TYPE
The wildcard.

See Also:
Constant Field Values

HTML

public static final String HTML
Extension .html.

See Also:
Constant Field Values

HTM

public static final String HTM
Extension .htm.

See Also:
Constant Field Values

WML

public static final String WML
Extension .wml.

See Also:
Constant Field Values

HDML

public static final String HDML
Extension .hdml.

See Also:
Constant Field Values

HDM

public static final String HDM
Extension .hdm.

See Also:
Constant Field Values

CHTML

public static final String CHTML
Extension .chtml.

See Also:
Constant Field Values

XHTML

public static final String XHTML
Extension .xhtml.

See Also:
Constant Field Values

TXT

public static final String TXT
Extension .txt.

See Also:
Constant Field Values

GIF

public static final String GIF
Extension .gif.

See Also:
Constant Field Values

JPEG

public static final String JPEG
Extension .jpeg.

See Also:
Constant Field Values

JPG

public static final String JPG
Extension .jpg.

See Also:
Constant Field Values

WBMP

public static final String WBMP
Extension .wbmp.

See Also:
Constant Field Values

SMS

public static final String SMS
Extension .sms.

See Also:
Constant Field Values

TEXT_HTML

public static final String TEXT_HTML
HTML type as a string.

See Also:
Constant Field Values

TEXT_WML

public static final String TEXT_WML
WML type as a string.

See Also:
Constant Field Values

TEXT_HDML

public static final String TEXT_HDML
XHDML type as a string.

See Also:
Constant Field Values

TEXT_PLAIN

public static final String TEXT_PLAIN
Plain text type as a string.

See Also:
Constant Field Values

MULTIPART

public static final String MULTIPART
Multipart type as a string.

See Also:
Constant Field Values

MULTIPART_FORM_DATA

public static final String MULTIPART_FORM_DATA
HTML form data type as a string.

See Also:
Constant Field Values

APPLICATION_XHTML

public static final String APPLICATION_XHTML
XHTML type as a string.

See Also:
Constant Field Values

APPLICATION_POSTSCRIPT

public static final String APPLICATION_POSTSCRIPT
PostScript type as a string.

See Also:
Constant Field Values

APPLICATION_OCTET_STREAM

public static final String APPLICATION_OCTET_STREAM
Octet stream type as a string.

See Also:
Constant Field Values

APPLICATION_X_JAVA_AGENT

public static final String APPLICATION_X_JAVA_AGENT
Java agent type as a string.

See Also:
Constant Field Values

APPLICATION_X_WWW_FORM_URLENCODED

public static final String APPLICATION_X_WWW_FORM_URLENCODED
WWW form type as a string.

See Also:
Constant Field Values

MESSAGE_HTTP

public static final String MESSAGE_HTTP
HTTP message type as a string.

See Also:
Constant Field Values

TEXT_CSS

public static final String TEXT_CSS
CSS type as a string.

See Also:
Constant Field Values

ANY_TEXT

public static final String ANY_TEXT
Any text type as a string.

See Also:
Constant Field Values

IMAGE_GIF

public static final String IMAGE_GIF
GIF type as a string.

See Also:
Constant Field Values

IMAGE_JPEG

public static final String IMAGE_JPEG
JPEG type as a string.

See Also:
Constant Field Values

IMAGE_WBMP

public static final String IMAGE_WBMP
WBMP type as a string.

See Also:
Constant Field Values

ANY_APPLICATION

public static final String ANY_APPLICATION
Any application type as a string.

See Also:
Constant Field Values

DEFAULT

public static final String DEFAULT
The default type as a string.

See Also:
Constant Field Values

TEXT_HTML_TYPE

public static final MimeType TEXT_HTML_TYPE
HTML type.


TEXT_WML_TYPE

public static final MimeType TEXT_WML_TYPE
WML type.


TEXT_HDML_TYPE

public static final MimeType TEXT_HDML_TYPE
HDML type.


TEXT_PLAIN_TYPE

public static final MimeType TEXT_PLAIN_TYPE
Plain text type.


MULTIPART_TYPE

public static final MimeType MULTIPART_TYPE
Multipart type.


MULTIPART_FORM_DATA_TYPE

public static final MimeType MULTIPART_FORM_DATA_TYPE
HTML form data type.


APPLICATION_XHTML_TYPE

public static final MimeType APPLICATION_XHTML_TYPE
XHTML type.


APPLICATION_POSTSCRIPT_TYPE

public static final MimeType APPLICATION_POSTSCRIPT_TYPE
PostScript type.


APPLICATION_OCTET_STREAM_TYPE

public static final MimeType APPLICATION_OCTET_STREAM_TYPE
Octet stream type.


APPLICATION_X_JAVA_AGENT_TYPE

public static final MimeType APPLICATION_X_JAVA_AGENT_TYPE
Java agent type.


APPLICATION_X_WWW_FORM_URLENCODED_TYPE

public static final MimeType APPLICATION_X_WWW_FORM_URLENCODED_TYPE
WWW form type.


MESSAGE_HTTP_TYPE

public static final MimeType MESSAGE_HTTP_TYPE
HTTP Message type.


TEXT_CSS_TYPE

public static final MimeType TEXT_CSS_TYPE
CSS type.


TEXT_TYPE

public static final MimeType TEXT_TYPE
Any text type.


IMAGE_GIF_TYPE

public static final MimeType IMAGE_GIF_TYPE
GIF type.


IMAGE_JPEG_TYPE

public static final MimeType IMAGE_JPEG_TYPE
JPEG type.


IMAGE_WBMP_TYPE

public static final MimeType IMAGE_WBMP_TYPE
WBMP type.


APPLICATION_TYPE

public static final MimeType APPLICATION_TYPE
Any application type.


DEFAULT_TYPE

public static final MimeType DEFAULT_TYPE
The default type.


NO_MATCH

public static final int NO_MATCH
No type match.

See Also:
Constant Field Values

MATCH_TYPE

public static final int MATCH_TYPE
Match main type.

See Also:
Constant Field Values

MATCH_SUBTYPE

public static final int MATCH_SUBTYPE
Match subtype.

See Also:
Constant Field Values

MATCH_SPECIFIC_SUBTYPE

public static final int MATCH_SPECIFIC_SUBTYPE
Match specific subtype.

See Also:
Constant Field Values
Constructor Detail

MimeType

public MimeType(String spec)
Constructs a new MIME type by parsing a specification string.

Parameters:
spec - a string representing a MIME type.
Throws:
IllegalArgumentException - for parsing errors.

MimeType

public MimeType(String spec,
                boolean parsep)
Constructs a new MIME type by parsing a specification string.

Parameters:
spec - a string representing a MIME type.
parsep - a flag for parsing parameters also.
Throws:
IllegalArgumentException - for parsing errors.

MimeType

public MimeType(String type,
                String subtype)
Contructs a new MIME type from specified types.

Parameters:
type - a type.
subtype - a subtype.
Throws:
NullPointerException - if type or subtype are nulls.

MimeType

public MimeType(String type,
                String subtype,
                String[] names,
                String[] values)
Contructs a new MIME type from specified parameters.

Parameters:
type - a type.
subtype - a subtype.
names - parameters names.
values - parameter values.
Throws:
NullPointerException - if type or subtype are nulls.
Method Detail

clone

public Object clone()
Clones this object.

Overrides:
clone in class Object
Returns:
the cloned object.

match

public int match(MimeType other)
Compares the specified MIME type to this one and returns a matching level: NO_MATCH=types do not match, MATCH=types match, MATCH_SPECIFIC=types match exactly, MATCH_SUBTYPE=types match, subtypes match too, MATCH_SPECIFIC_SUBTYPE=types match, subtypes match exactly.

Parameters:
other - the MimeType to compare.
Returns:
the matching level.

match

public int match(String other)
Compares the specified MIME string to this one and returns a matching level: NO_MATCH=types do not match, MATCH=types match, MATCH_SPECIFIC=types match exactly, MATCH_SUBTYPE=types match, subtypes match too, MATCH_SPECIFIC_SUBTYPE=types match, subtypes match exactly.

Parameters:
other - the MIME string to compare.
Returns:
the matching level.

getType

public String getType()
Gets the main type of the MIME type.

Returns:
the main type as a string.

getSubtype

public String getSubtype()
Gets the subtype of the MIME type.

Returns:
the subtype as a string.

containsParameter

public boolean containsParameter(String param)
Checks whether the MIME type contains the specified parameter.

Parameters:
param - the name opf the parameter.
Returns:
true if the parameter found, otherwise false.

getParameter

public String getParameter(String param)
Gets the value of a MIME type parameter. The first parameter with the specifed name will be returned.

Parameters:
param - the name of the parameter.
Returns:
the value of the parameter, or null.

setParameter

public void setParameter(String param,
                         String value)
Sets the value of a MIME type parameter replacing the old one.

Parameters:
param - the name of the parameter.
value - the value of the parameter.

addParameter

public void addParameter(String param,
                         String value)
Adds a parameter to the MIME type.

Parameters:
param - the name of the parameter.
value - the value of the parameter.

addParameters

public void addParameters(String[] params,
                          String[] values)
Adds parameters to the MIME type.

Parameters:
params - an array of parameter names.
values - an array of parameter values.
Throws:
IllegalArgumentException - for incorrect parameters.

removeParameter

public void removeParameter(String param)
Removes a parameter from the MIME type.

Parameters:
param - the name of the parameter.

toString

public String toString()
Converts the MIME type into a string.

Overrides:
toString in class Object
Returns:
the string representation of the MIME type.

toString

public String toString(boolean params)
Converts the MIME type into a string with or without parameters.

Parameters:
params - if true, include parameters.
Returns:
the string representation of the MIME type.


Copyright © 2004 The Norther Organization. All rights reserved.