org.apache.turbine.services.mimetype.util
Class MimeType

java.lang.Object
  extended byorg.apache.turbine.services.mimetype.util.MimeType
All Implemented Interfaces:
java.lang.Cloneable

public class MimeType
extends java.lang.Object
implements java.lang.Cloneable

This class 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.

Version:
$Id: MimeType.java 534527 2007-05-02 16:10:59Z tv $
Author:
Ilkka Priha

Field Summary
static MimeType APPLICATION_OCTET_STREAM
           
static MimeType APPLICATION_POSTSCRIPT
           
static MimeType APPLICATION_X_JAVA_AGENT
           
static MimeType APPLICATION_X_WWW_FORM_URLENCODED
           
static MimeType IMAGE_GIF
           
static MimeType IMAGE_JPEG
           
static MimeType IMAGE_WBMP
           
static int MATCH_SPECIFIC_SUBTYPE
           
static int MATCH_SUBTYPE
           
static int MATCH_TYPE
           
static MimeType MESSAGE_HTTP
           
static MimeType MULTIPART
           
static MimeType MULTIPART_FORM_DATA
           
static int NO_MATCH
          MIME type matching constants.
static MimeType TEXT
           
static MimeType TEXT_CHTML
           
static MimeType TEXT_CSS
           
static MimeType TEXT_HDML
           
static MimeType TEXT_HTML
          A list of well known MIME types.
static MimeType TEXT_PLAIN
           
static MimeType TEXT_WML
           
 
Constructor Summary
MimeType(java.lang.String spec)
          Constructs a new MIME type by parsing a specification string.
MimeType(java.lang.String spec, boolean parsep)
          Constructs a new MIME type by parsing a specification string.
MimeType(java.lang.String type, java.lang.String subtype)
          Contructs a new MIME type from specified types.
MimeType(java.lang.String type, java.lang.String subtype, java.lang.String[] names, java.lang.String[] values)
          Contructs a new MIME type from specified parameters.
 
Method Summary
 void addParameter(java.lang.String param, java.lang.String value)
          Adds a parameter to the MIME type.
 void addParameters(java.lang.String[] params, java.lang.String[] values)
          Adds parameters to the MIME type.
 java.lang.String getParameter(java.lang.String param)
          Gets the value of a MIME type parameter.
 java.lang.String getSubtype()
          Gets the subtype of the MIME type.
 java.lang.String getType()
          Gets the main type of the MIME type.
 java.lang.String getTypes()
          Gets the type and the subtype of the MIME type.
 boolean hasParameter(java.lang.String param)
          Checks whether the MIME type contains the specified parameter.
 int match(MimeType other)
          Compares the specified MIME type to this one and returns a matching level: NO_MATCH=types do not match, MATCH_TYPE=types match, MATCH_SPECIFIC_TYPE=types match exactly, MATCH_SUBTYPE=types match, subtypes match too, MATCH_SPECIFIC_SUBTYPE=types match, subtypes match exactly.
 void setParameter(java.lang.String param, java.lang.String value)
          Sets the value of a MIME type parameter replacing the old one.
 java.lang.String toString()
          Converts the MIME type into a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TEXT_HTML

public static MimeType TEXT_HTML
A list of well known MIME types.


TEXT_WML

public static MimeType TEXT_WML

TEXT_HDML

public static MimeType TEXT_HDML

TEXT_CHTML

public static MimeType TEXT_CHTML

TEXT_PLAIN

public static MimeType TEXT_PLAIN

MULTIPART

public static MimeType MULTIPART

MULTIPART_FORM_DATA

public static MimeType MULTIPART_FORM_DATA

APPLICATION_POSTSCRIPT

public static MimeType APPLICATION_POSTSCRIPT

APPLICATION_OCTET_STREAM

public static MimeType APPLICATION_OCTET_STREAM

APPLICATION_X_JAVA_AGENT

public static MimeType APPLICATION_X_JAVA_AGENT

APPLICATION_X_WWW_FORM_URLENCODED

public static MimeType APPLICATION_X_WWW_FORM_URLENCODED

MESSAGE_HTTP

public static MimeType MESSAGE_HTTP

TEXT_CSS

public static MimeType TEXT_CSS

TEXT

public static MimeType TEXT

IMAGE_GIF

public static MimeType IMAGE_GIF

IMAGE_JPEG

public static MimeType IMAGE_JPEG

IMAGE_WBMP

public static MimeType IMAGE_WBMP

NO_MATCH

public static final int NO_MATCH
MIME type matching constants.

See Also:
Constant Field Values

MATCH_TYPE

public static final int MATCH_TYPE
See Also:
Constant Field Values

MATCH_SUBTYPE

public static final int MATCH_SUBTYPE
See Also:
Constant Field Values

MATCH_SPECIFIC_SUBTYPE

public static final int MATCH_SPECIFIC_SUBTYPE
See Also:
Constant Field Values
Constructor Detail

MimeType

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

Parameters:
spec - a string representing a MIME type.

MimeType

public MimeType(java.lang.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:
java.lang.IllegalArgumentException - for parsing errors.

MimeType

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

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

MimeType

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

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

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_TYPE=types match, MATCH_SPECIFIC_TYPE=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.

getType

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

Returns:
the main type as a string.

getSubtype

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

Returns:
the subtype as a string.

getTypes

public java.lang.String getTypes()
Gets the type and the subtype of the MIME type.

Returns:
the types as a string.

hasParameter

public boolean hasParameter(java.lang.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 java.lang.String getParameter(java.lang.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(java.lang.String param,
                         java.lang.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(java.lang.String param,
                         java.lang.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(java.lang.String[] params,
                          java.lang.String[] values)
Adds parameters to the MIME type.

Parameters:
params - an array of parameter names.
values - an array of parameter values.

toString

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

Returns:
the string representation of the MIME type.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.