SourcePro® 2024.1 |
SourcePro® API Reference Guide |
Represents the value of a MIME Content-Type
header.
More...
#include <rw/mime/RWMimeContentType.h>
Public Member Functions | |
RWMimeContentType (const RWCString &mediaType, const RWCString &subType, const RWMimeParameterList ¶meters=RWMimeParameterList()) | |
RWMimeContentType (const RWMimeContentType &second) | |
RWMimeContentType (void) | |
virtual | ~RWMimeContentType (void) |
RWCString | asString (void) const |
size_t | findParameter (const RWCString &name, size_t start=0) const |
void | fromString (const RWCString &contentType) |
RWCString | getMediaType (void) const |
RWMimeParameter | getParameter (size_t i) const |
size_t | getParameterCount (void) const |
RWCString | getParameterValue (const RWCString &name, size_t start=0) const |
RWCString | getSubType (void) const |
void | insertParameter (const RWMimeParameter ¶meter) |
RWMimeContentType & | operator= (const RWMimeContentType &second) |
void | removeAllParameters (void) |
void | removeParameter (size_t position) |
void | setParameterValue (const RWCString &name, const RWCString &value, size_t start=0) |
Public Member Functions inherited from RWHandleBase | |
bool | isValid (void) const |
bool | operator!= (const RWHandleBase &second) const |
bool | operator== (const RWHandleBase &second) const |
Protected Member Functions | |
RWMimeContentTypeImp & | body (void) const |
virtual bool | checkType (const RWCString &mediaType, const RWCString &subType) const |
Protected Member Functions inherited from RWHandleBase | |
RWHandleBase (const RWHandleBase &second) | |
RWHandleBase (RWBodyBase *body) | |
RWHandleBase (RWStaticCtor) | |
RWHandleBase (void) | |
~RWHandleBase (void) | |
RWBodyBase & | body (void) const |
RWHandleBase & | operator= (const RWHandleBase &second) |
Friends | |
bool | operator!= (const RWMimeContentType &first, const RWMimeContentType &second) |
bool | operator== (const RWMimeContentType &first, const RWMimeContentType &second) |
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 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::RWMimeContentType | ( | void | ) |
Default constructor. Constructs a content type with no media type, an empty subtype, and no parameters.
RWMimeContentType::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::RWMimeContentType | ( | const RWMimeContentType & | second | ) |
Copy constructor. Constructs a new handle to the body second refers to.
|
virtual |
Destructor.
RWCString RWMimeContentType::asString | ( | void | ) | const |
Returns a string representation of self. The returned string is formatted as specified by RFC 2045 for a Content-Type value.
RWMimeError | Thrown if self cannot be represented as valid MIME. The RWCString should contain 7-bit US-ASCII data. |
|
protected |
Returns a reference to the underlying implementation.
|
protectedvirtual |
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.
Reimplemented in RWMimeMultipartRelatedType, RWMimeMultipartType, and RWMimeTextType.
size_t RWMimeContentType::findParameter | ( | const RWCString & | name, |
size_t | start = 0 ) const |
void RWMimeContentType::fromString | ( | const RWCString & | contentType | ) |
Populates self from contentType. The function parses but does not validate contentType.
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.
RWMimeParseError | Thrown if contentType is not in the format of a Content-Type value. |
RWCString RWMimeContentType::getMediaType | ( | void | ) | const |
Returns self's media type. The RWCString should contain 7-bit US-ASCII data.
RWMimeParameter RWMimeContentType::getParameter | ( | size_t | i | ) | const |
Returns the parameter at the specified position.
RWBoundsErr | Thrown if i is greater than or equal to getParameterCount(). |
size_t RWMimeContentType::getParameterCount | ( | void | ) | const |
Returns the total number of parameters in self.
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 RWMimeContentType::getSubType | ( | void | ) | const |
Returns self's subtype. The RWCString should contain 7-bit US-ASCII data.
void RWMimeContentType::insertParameter | ( | const RWMimeParameter & | parameter | ) |
Inserts parameter at the end of self's parameter list.
RWMimeContentType & RWMimeContentType::operator= | ( | const RWMimeContentType & | second | ) |
Assignment operator. Makes self a handle identical to second.
void RWMimeContentType::removeAllParameters | ( | void | ) |
Removes all parameters from self.
void RWMimeContentType::removeParameter | ( | size_t | position | ) |
Removes the parameter located at position from the parameter list.
RWBoundsErr | Thrown if position is greater than or equal to getParameterCount(). |
void RWMimeContentType::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.
|
friend |
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.
|
friend |
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.
Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |