⇒ Index (Frames) |  ⇒ Index (No Frames) |  ⇒ Package |  ⇒ Package Tree |  ⇒ Full Tree 
javax.mail.internet

Class ContentType

java.lang.Object
|
+--javax.mail.internet.ContentType


public class ContentType
extends java.lang.Object

This class represents a MIME Content-Type value. It provides methods to parse a Content-Type string into individual components and to generate a MIME style Content-Type string.
Author:

Constructor Summary

ContentType()

No-arg Constructor.

ContentType(String primaryType, String subType, ParameterList list)

Constructor.

ContentType(String s)

Constructor that takes a Content-Type string.

Method Summary

String

getBaseType()

Return the MIME type string, without the parameters.

String

getParameter(String name)

Return the specified parameter value.

ParameterList

getParameterList()

Return a ParameterList object that holds all the available parameters.

String

getPrimaryType()

Return the primary type.

String

getSubType()

Return the subtype.

boolean

match(ContentType cType)

Match with the specified ContentType object.

boolean

match(String s)

Match with the specified content-type string.

void

setParameter(String name, String value)

Set the specified parameter.

void

setParameterList(ParameterList list)

Set a new parameter list.

void

setPrimaryType(String primaryType)

Set the primary type.

void

setSubType(String subType)

Set the subtype.

String

toString()

Retrieve a RFC2045 style string representation of this Content-Type.

Constructor Details

ContentType

public ContentType()

No-arg Constructor.


ContentType

public ContentType(String s)

Constructor that takes a Content-Type string. The String is parsed into its constituents: primaryType, subType and parameters. A ParseException is thrown if the parse fails.

Parameters:
s - the Content-Type string.
Throws:
ParseException - if the parse fails.

ContentType

public ContentType(String primaryType, String subType, ParameterList list)

Constructor.

Parameters:
primaryType - the primary type
subType - the subtype
list - the list of additional parameters

Method Details

getBaseType

public String getBaseType()

Return the MIME type string, without the parameters. The returned value is basically the concatenation of the primaryType, the '/' character and the secondaryType.


getParameter

public String getParameter(String name)

Return the specified parameter value. Returns null if this parameter is absent.

Parameters:
name

getParameterList

public ParameterList getParameterList()

Return a ParameterList object that holds all the available parameters. Returns null if no parameters are available.


getPrimaryType

public String getPrimaryType()

Return the primary type.


getSubType

public String getSubType()

Return the subtype.


match

public boolean match(String s)

Match with the specified content-type string. This method compares only the primaryType and subType. The parameters of both operands are ignored.

For example, this method will return true when comparing the ContentType for "text/plain" with "text/plain; charset=foobar". If the subType of either operand is the special character '*', then the subtype is ignored during the match. For example, this method will return true when comparing the ContentType for "text/plain" with "text/*"

Parameters:
s - the string representation of the content type to match

match

public boolean match(ContentType cType)

Match with the specified ContentType object. This method compares only the primaryType and subType. The parameters of both operands are ignored.

For example, this method will return true when comparing the ContentTypes for "text/plain" and "text/plain; charset=foobar". If the subType of either operand is the special character '*', then the subtype is ignored during the match. For example, this method will return true when comparing the ContentTypes for "text/plain" and "text/*"

Parameters:
cType - the content type to compare this against

setParameter

public void setParameter(String name, String value)

Set the specified parameter. If this parameter already exists, it is replaced by this new value.

Parameters:
name - the parameter name
value - the parameter value

setParameterList

public void setParameterList(ParameterList list)

Set a new parameter list.

Parameters:
list - the Parameter list

setPrimaryType

public void setPrimaryType(String primaryType)

Set the primary type. Overrides existing primary type.

Parameters:
primaryType - the primary type

setSubType

public void setSubType(String subType)

Set the subtype. Overrides existing subtype

Parameters:
subType - the subtype

toString

public String toString()

Retrieve a RFC2045 style string representation of this Content-Type. Returns null if the conversion failed.

Returns:
RFC2045 style string