SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWMimeContentType Class Reference

Represents the value of a MIME Content-Type header. More...

#include <rw/mime/RWMimeContentType.h>

Inheritance diagram for RWMimeContentType:
RWHandleBase RWMimeMultipartType RWMimeTextType RWMimeMultipartRelatedType

Public Member Functions

 RWMimeContentType (const RWCString &mediaType, const RWCString &subType, const RWMimeParameterList &parameters=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 &parameter)
 
RWMimeContentTypeoperator= (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)
 
RWBodyBasebody (void) const
 
RWHandleBaseoperator= (const RWHandleBase &second)
 

Friends

bool operator!= (const RWMimeContentType &first, const RWMimeContentType &second)
 
bool operator== (const RWMimeContentType &first, const RWMimeContentType &second)
 

Detailed Description

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.

text/xml;charset=US-ASCII

An instance of this class is a handle to a private, reference-counted body.

Reference
RWMimeContentType conforms to the Content-Type header requirements specified in RFC 2045, section 5 (p. 10). For details on the content types that the MIME specification defines, see RFC 2046.

Constructor & Destructor Documentation

◆ RWMimeContentType() [1/3]

RWMimeContentType::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() [2/3]

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() [3/3]

RWMimeContentType::RWMimeContentType ( const RWMimeContentType & second)

Copy constructor. Constructs a new handle to the body second refers to.

◆ ~RWMimeContentType()

virtual RWMimeContentType::~RWMimeContentType ( void )
virtual

Destructor.

Member Function Documentation

◆ asString()

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.

Exceptions
RWMimeErrorThrown if self cannot be represented as valid MIME. The RWCString should contain 7-bit US-ASCII data.

◆ body()

RWMimeContentTypeImp & RWMimeContentType::body ( void ) const
protected

Returns a reference to the underlying implementation.

◆ checkType()

virtual bool RWMimeContentType::checkType ( const RWCString & mediaType,
const RWCString & subType ) const
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.

◆ findParameter()

size_t RWMimeContentType::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.

◆ fromString()

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.

Exceptions
RWMimeParseErrorThrown if contentType is not in the format of a Content-Type value.

◆ getMediaType()

RWCString RWMimeContentType::getMediaType ( void ) const

Returns self's media type. The RWCString should contain 7-bit US-ASCII data.

◆ getParameter()

RWMimeParameter RWMimeContentType::getParameter ( size_t i) const

Returns the parameter at the specified position.

Exceptions
RWBoundsErrThrown if i is greater than or equal to getParameterCount().

◆ getParameterCount()

size_t RWMimeContentType::getParameterCount ( void ) const

Returns the total number of parameters in self.

◆ getParameterValue()

RWCString RWMimeContentType::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.

◆ getSubType()

RWCString RWMimeContentType::getSubType ( void ) const

Returns self's subtype. The RWCString should contain 7-bit US-ASCII data.

◆ insertParameter()

void RWMimeContentType::insertParameter ( const RWMimeParameter & parameter)

Inserts parameter at the end of self's parameter list.

◆ operator=()

RWMimeContentType & RWMimeContentType::operator= ( const RWMimeContentType & second)

Assignment operator. Makes self a handle identical to second.

◆ removeAllParameters()

void RWMimeContentType::removeAllParameters ( void )

Removes all parameters from self.

◆ removeParameter()

void RWMimeContentType::removeParameter ( size_t position)

Removes the parameter located at position from the parameter list.

Exceptions
RWBoundsErrThrown if position is greater than or equal to getParameterCount().

◆ setParameterValue()

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.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const RWMimeContentType & first,
const RWMimeContentType & second )
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.

◆ operator==

bool operator== ( const RWMimeContentType & first,
const RWMimeContentType & second )
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.