Main Page | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

MediaType Class Reference

Inheritance diagram for MediaType:

FieldBody Node List of all members.

Detailed Description

MediaType represents a field body for the content-type header field as described in RFC 2045. This field body identifies the kind of data contained in the body of a message or a body part. A media type is described by two keywords: a primary type (or just type) and a subtype. RFC 2046 specifies the seven primary types text, multipart, message, image, audio, video, and application. RFC 2077 adds the new primary type model.

MediaType has member functions that allow you to set or get the type and subtype as either enumerated values or as strings. It also contains a list of Parameter objects that represent the parameters of the field body. You can use convenience functions to directly access the boundary parameter of a multipart media type, or to access the name parameter that is often used with several media types, such as application/octet-stream.

Some MIME parsers have problems with folded header fields, and this especially seems to be a problem with the content-type field. To disable folding when the MediaType object is assembled, call the inherited member function FieldBody::setFoldingEnabled() with an argument of false.


Public Member Functions

 MediaType ()
 Default constructor.
 MediaType (const MediaType &other)
 Copy constructor.
 MediaType (const String &str, Node *parent=0)
 Constructor that takes an initial string and parent node.
virtual ~MediaType ()
 Destructor.
const MediaTypeoperator= (const MediaType &other)
 Assignment operator.
virtual void parse ()
 Parses the string representation.
virtual void assemble ()
 Assembles the string representation.
virtual Nodeclone () const
 Creates a copy of this object.
MType typeAsEnum () const
 Gets the primary type as an enumerated value.
void typeFromEnum (MType type)
 Sets the primary type from an enumerated value.
const Stringtype () const
 Gets the primary type as a string.
void setType (const String &str)
 Sets the primary type from a string.
const Stringsubtype () const
 Gets the subtype as a string.
void setSubtype (const String &str)
 Sets the subtype from a string.
const Stringboundary () const
 Gets the value of the boundary parameter, if present.
void setBoundary (const String &str)
 Sets the value of the boundary parameter.
virtual const StringcreateBoundary (unsigned level=0)
 Creates and adds a boundary parameter.
const Stringname () const
 Gets the value of the name parameter, if present.
void setName (const String &str)
 Sets the value of the name parameter.
const Stringcharset () const
 Gets the value of the charset parameter, if present.
void setCharset (const String &str)
 Sets the value of the charset parameter.
int numParameters () const
 Gets the number of parameters in the list.
void addParameter (Parameter *param)
 Adds a parameter to the end of the list.
void deleteAllParameters ()
 Deletes all parameters in the list.
ParameterparameterAt (int index) const
 Gets the parameter at the specified position in the list.
void insertParameterAt (int index, Parameter *param)
 Inserts a parameter at the specified position in the list.
ParameterremoveParameterAt (int index)
 Removes the parameter at the specified position in the list.

Static Public Member Functions

MediaTypenewMediaType ()
 Creates a new instance.

Static Public Attributes

MediaType *(* sNewMediaType )()
 Provides a class factory hook.

Protected Member Functions

void _copyParameters (const MediaType &type)
 Copies all parameters from another list.
void _addParameter (Parameter *parameter)
 Adds a parameter to the end of the list.
void _insertParameterAt (int index, Parameter *param)
 Inserts a parameter at the specified position in the list.
Parameter_removeParameterAt (int index)
 Removes the parameter at the specified position in the list.
void _deleteAllParameters ()
 Deletes all parameters in the list.


Constructor & Destructor Documentation

MediaType  ) 
 

This constructor sets the MediaType object's string representation to the empty string and sets its parent node to NULL.

MediaType const MediaType other  ) 
 

This constructor performs a deep copy of its argument. The parent node of the new MediaType object is set to NULL.

Parameters:
other MediaType instance to copy

MediaType const String str,
Node parent = 0
 

This constructor sets the MediaType object's string representation to str and sets its parent node to parent.

Normally, you call the virtual function parse() immediately after this constructor to create the broken-down representation.

Parameters:
str initial value for the string representation
parent parent node for this object

~MediaType  )  [virtual]
 

Destructor


Member Function Documentation

void _addParameter Parameter param  )  [protected]
 

Same as addParameter(), but does not set the is-modified flag.

See also:
addParameter()

void _copyParameters const MediaType type  )  [protected]
 

Copies the list of Parameter objects from type. Assumes the list in this MediaType object is emtpy. Does not set the is-modified flag.

Parameters:
type MediaType object to copy Parameter objects from

void _deleteAllParameters  )  [protected]
 

Same as deleteAllParameters(), but does not set the is-modified flag.

See also:
deleteAllParameters()

void _insertParameterAt int  index,
Parameter param
[protected]
 

Same as insertParameterAt(), but does not set the is-modified flag.

See also:
insertParameterAt()

Parameter * _removeParameterAt int  index  )  [protected]
 

Same as removeParameterAt(), but does not set the is-modified flag.

See also:
removeParameterAt()

void addParameter Parameter param  ) 
 

Adds param to the end of the parameter list.

The MediaType destructor deletes the Parameter objects in the list.

Parameters:
param Parameter object to add

void assemble  )  [virtual]
 

This virtual function, inherited from Node, executes the assemble operation for MediaType objects. The assemble operation creates or updates the string representation from the broken-down representation. For MediaType objects, the assemble operation builds the string representation from the type, subtype, and list of Parameter objects. Before it builds the string representation for the MediaType object, this function first calls the assemble() member function of each Parameter object in its list.

You should call this member function after you set or modify the type, subtype, or any of the contained Parameter objects, and before you retrieve the string representation.

This function clears the is-modified flag.

Reimplemented from FieldBody.

const String & boundary  )  const
 

Gets the value of the boundary parameter.

The boundary parameter is required if the primary type is multipart. If there is no boundary parameter, this member function returns an empty string. This member function is a convenience function that searches the list of Parameter objects.

Returns:
value of the boundary parameter; or the empty string if there is no boundary parameter

const String & charset  )  const
 

Gets the value of the charset parameter, if such a parameter is present.

The charset parameter is often found in text media types. It indicates the character encoding of the text content.

This member function is a convenience function that searches the list of Parameter objects.

Returns:
value of the charset parameter; or the empty string if there is no charset parameter

Node * clone  )  const [virtual]
 

This virtual function, inherited from Node, creates a new MediaType object that has the same value as this MediaType object. The parent node of the new MediaType object is set to NULL.

Returns:
a copy of this object

Reimplemented from FieldBody.

const String & createBoundary unsigned  level = 0  )  [virtual]
 

Creates a boundary string and sets it as the value of the boundary parameter.

The boundary parameter is required if the primary type is multipart. level indicates the level of a nested multipart body part; if it is positive, it is used to form part of the created boundary string. This member function is a convenience function that accesses the list of Parameter objects.

Parameters:
level nesting level of the body part (optional)
Returns:
new value of the boundary parameter

void deleteAllParameters  ) 
 

Removes and deletes all Parameter objects in the parameter list.

void insertParameterAt int  index,
Parameter param
 

Inserts param into the parameter list at position index.

If index is zero, then the function inserts param into the first position in the list. If index equals numParameters(), then the function inserts param into the last position in the list. If index is less than numParameters(), then the function moves the Parameter objects at position index or greater to a higher position in the list.

The MediaType destructor deletes the Parameter objects in the list.

The function's behavior is undefined if index is out of range. Valid values for index are 0 <= index <= numParameters().

Parameters:
index position in the list to insert the Parameter object
param Parameter object to insert

const String & name  )  const
 

Gets the value of the name parameter, if such a parameter is present.

The name parameter is often found in several media types, including the application/octet-stream media type; it suggests a file name for saving the content to a disk file. (The filename parameter in the content-disposition header field is an alternative way to indicate a file name.) This member function is a convenience function that searches the list of Parameter objects.

Returns:
value of the name parameter; or the empty string if there is no name parameter

MediaType * newMediaType  )  [static]
 

Creates a new MediaType object.

If the static data member sNewMediaType is NULL, this member function creates a new MediaType object and returns it. Otherwise, newMediaType() calls the user-supplied function that sNewMediaType points to and returns the object created by that function.

Returns:
new MediaType instance
See also:
sNewMediaType

int numParameters  )  const
 

Gets the number of Parameter objects in the parameter list.

Returns:
number of Parameter objects in the list

const MediaType & operator= const MediaType other  ) 
 

Performs a deep copy of its argument. The parent node of this MediaType object is not changed.

Parameters:
other MediaType instance to copy

Parameter & parameterAt int  index  )  const
 

Gets the Parameter object at position index in the parameter list.

The function's behavior is undefined if index is out of range. Valid values for index are 0 <= index < numParameters().

Parameters:
index position of the Parameter object to get
Returns:
reference to the Parameter object at the specified position

void parse  )  [virtual]
 

This virtual function, inherited from Node, executes the parse operation for MediaType objects. The parse operation creates or updates the broken-down representation from the string representation. For MediaType objects, the parse operation parses the string representation to extract the type, subtype, and the list of Parameter objects. This member function also calls the parse() member function of each Parameter object in its list.

You should call this member function after you set or modify the string representation, and before you access the type, subtype, or any of the contained Parameter objects.

This function clears the is-modified flag.

Reimplemented from FieldBody.

Parameter * removeParameterAt int  index  ) 
 

Removes the Parameter object at position index from the parameter list and returns it.

If index is less than numParameters()-1, then the function moves the Parameter objects at position (index + 1) or greater to a lower position in the list.

The function's behavior is undefined if index is out of range. Valid values for index are 0 <= index < numParameters().

Parameters:
index position of the Parameter object to remove
Returns:
pointer to the removed Parameter object

void setBoundary const String str  ) 
 

Sets the value of the boundary parameter.

The boundary parameter is required if the primary type is multipart. If no boundary parameter exists when this function is called, this function will create a new boundary parameter and add it to the list. This member function is a convenience function that accesses the list of Parameter objects.

Parameters:
str value of the boundary parameter

void setCharset const String str  ) 
 

Sets the value of the charset parameter.

If a charset parameter is not already present, it is added.

The charset parameter is often found in text media types. It character encoding for the text content.

This member function is a convenience function that accesses the list of Parameter objects.

Parameters:
str value of the charset parameter

void setName const String str  ) 
 

Sets the value of the name parameter.

If a name parameter is not already present, it is added. The name parameter is often found in several media types, including the application/octet-stream media type; it suggests a file name for saving the content to a disk file. (The filename parameter in the content-disposition header field is an alternative way to indicate a file name.) This member function is a convenience function that accesses the list of Parameter objects.

Parameters:
str value of the name parameter

void setSubtype const String str  ) 
 

Sets the subtype from a string.

Parameters:
str subtype

void setType const String str  ) 
 

Sets the primary type from a string.

Parameters:
str primary type

const String & subtype  )  const
 

Gets the subtype as a string.

Returns:
subtype

const String & type  )  const
 

Gets the primary type as a string.

Returns:
primary type

MediaType::MType typeAsEnum  )  const
 

Gets the primary type as an enumerated value.

Returns:
primary type enumerated value

void typeFromEnum MediaType::MType  type  ) 
 

Sets the primary type from an enumerated value.

Parameters:
type primary type enumerated value


Member Data Documentation

MediaType *(* sNewMediaType)()=0 [static]
 

If sNewMediaType is not NULL, it must point to a user-supplied function that returns a new instance of a subclass of MediaType.

See also:
newMediaType()

Copyright © 2001-2007 Hunny Software, Inc. All rights reserved.