Module: Internet Protocols Module Package: MIME
RWMimeContentTypeRWHandleBase
#include <rw/mime/RWMimeContentType.h>
RWMimeContentType represents the value of a MIME Content-Type header. A Content-Type value contains a media type, a subtype, and any number of parameters.
The media type declares the type of content in broad terms. The MIME specification itself defines media types of image, text, audio, video, application, message and multipart. The subtype declares the specific file format of the content. For example, the media type image allows subtype values such as gif, jpeg, tiff, and so forth.
Parameters, if present, add information about the media type. For example, the media type text allows a parameter charset which states the character set used for the text.
A complete Content-Type value for a MIME part containing XML
text/xml; charset=us-ascii
has the media type text, the subtype xml, and a single parameter with the name charset and the value us-ascii.
An instance of this class is a handle to a private, reference-counted body.
RWMimeContentType conforms to the Content-Type header requirements specified in RFC 2045, section 5. For details on the content types that the MIME specification defines, see RFC 2046.
RWMimeContentType(void);
Default constructor. Constructs a content type with no media type, an empty subtype, and no parameters.
NOTE -- A Content-Type header with an empty value does not meet the requirements for an Internet Message header.
RWMimeContentType(const RWCString& mediaType, const RWCString& subType, const RWMimeParameterList& parameters = RWMimeParameterList());
Constructs a Content-Type header value with the media type mediaType, the subtype subType, and the parameter list parameters. Does not validate mediaType, subType or parameters. The RWCString should contain 7-bit US-ASCII data.
RWMimeContentType(const RWMimeContentType& second);
Copy constructor. Constructs a new handle to the body second refers to.
virtual ~RWMimeContentType(void);
Destructor.
RWMimeContentType& operator=(const RWMimeContentType& second);
Assignment operator. Makes self a handle identical to second.
bool operator==(const RWMimeContentType& first, const RWMimeContentType& second);
Equality operator. Returns true if first is equal to second, false otherwise. Compares the media type and the subtype using a case-insensitive string comparison. Compares the number of parameters the objects contain, then compares each parameter in each object with the parameter of the same name in the other object. Parameter comparisons use a case-insensitive comparison for parameter name and a case-sensitive comparison for parameter value.
bool operator!=(const RWMimeContentType& first, const RWMimeContentType& second);
Inequality operator. Returns true if first is not equal to second, false otherwise. Compares the media type and the subtype using a case-insensitive string comparison. Compares the number of parameters the objects contain, then compares each parameter in each object with the parameter of the same name in the other object. Parameter comparisons use a case-insensitive comparison for parameter name and a case-sensitive comparison for parameter value.
RWCString asString(void) const;
Returns a string representation of self. The returned string is formatted as specified by RFC 2045 for a Content-Type value. Throws RWMimeError if self cannot be represented as valid MIME. The RWCString should contain 7-bit US-ASCII data.
size_t findParameter(const RWCString& name, size_t start = 0) const;
Returns the index of the first parameter in the collection with a name matching name, or RW_NPOS if no parameter with that name is present. Begins searching at position start. Uses a case-insensitive string comparison to match name. The RWCString should contain 7-bit US-ASCII data.
void fromString(const RWCString& contentType);
Populates self from contentType. The function parses but does not validate contentType. Throws RWMimeParseError if contentType is not in the format of a Content-Type value.
A MIME Content-Type value requires that the media type and subtype appear first in the string, separated by a slash. Each parameter must be preceded by a semicolon and contain the parameter name, an equal sign, and the parameter value. For example, the string "text/xml;charset=us-ascii" is a valid contentType that contains the media type text, the subtype xml, and a single parameter with the name charset and the value us-ascii.
Derived classes may place additional requirements on this function to ensure that the function creates an RWMimeContentType of the appropriate type. The RWCString should contain 7-bit US-ASCII data.
RWCString getMediaType() const;
Returns self's media type. The RWCString should contain 7-bit US-ASCII data.
RWMimeParameter getParameter(size_t i) const;
Returns the parameter at the specified position. Throws RWBoundsErr if i is less than 0 or greater than getParameterCount() -1.
size_t getParameterCount(void) const;
Returns the total number of parameters in self.
RWCString getParameterValue(const RWCString& name, size_t start = 0) const;
Returns the value of the first parameter that contains a name matching name, or the empty string if no such parameter is present. Begins searching at start. Matches parameter names using a case-insensitive string comparison. The RWCString should contain 7-bit US-ASCII data.
RWCString getSubType() const;
Returns self's subtype. The RWCString should contain 7-bit US-ASCII data.
void insertParameter(const RWMimeParameter& parameter);
Inserts parameter at the end of self's parameter list.
void removeAllParameters(void);
Removes all parameters from self.
void removeParameter(size_t position);
Removes the parameter located at position from the parameter list. Throws RWBoundsErr if position is less than 0 or greater than getParameterCount() - 1.
void setParameterValue(const RWCString& name, const RWCString& value, size_t start=0);
Changes the value of the first parameter with a name matching name to value. If no such parameter exists, creates a new parameter and inserts the new parameter at the end of self's parameter list. Begins searching at start. Matches parameter names using a case-insensitive string comparison. The RWCString should contain 7-bit US-ASCII data.
RWMimeContentTypeImp& body(void) const;
Returns a reference to the underlying implementation.
virtual bool checkType(const RWCString& mediaType, constRWCString& subType) const;
Returns true. Since RWMimeContentType does not represent any specific content type value, this class imposes no special requirements on the type. In RWMimeContentType, this class returns true without examining either the mediaType or subType. Derived classes that represent specific content types may require specific values. The RWCString should contain 7-bit US-ASCII data.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.