4
// $Id: //poco/1.2/Net/include/Poco/Net/MediaType.h#1 $
10
// Definition of the MediaType class.
12
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
15
// Permission is hereby granted, free of charge, to any person or organization
16
// obtaining a copy of the software and accompanying documentation covered by
17
// this license (the "Software") to use, reproduce, display, distribute,
18
// execute, and transmit the Software, and to prepare derivative works of the
19
// Software, and to permit third-parties to whom the Software is furnished to
20
// do so, all subject to the following:
22
// The copyright notices in the Software and this entire statement, including
23
// the above license grant, this restriction and the following disclaimer,
24
// must be included in all copies of the Software, in whole or in part, and
25
// all derivative works of the Software, unless such copies or derivative
26
// works are solely in the form of machine-executable object code generated by
27
// a source language processor.
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35
// DEALINGS IN THE SOFTWARE.
39
#ifndef Net_MediaType_INCLUDED
40
#define Net_MediaType_INCLUDED
43
#include "Poco/Net/Net.h"
44
#include "Poco/Net/NameValueCollection.h"
51
class Net_API MediaType
52
/// This class represents a MIME media type, consisting of
53
/// a top-level type, a subtype and an optional set of
56
/// The implementation conforms with RFC 2045 and RFC 2046.
59
MediaType(const std::string& mediaType);
60
/// Creates the MediaType from the given string, which
61
/// must have the format <type>/<subtype>{;<parameter>=<value>}.
63
MediaType(const std::string& type, const std::string& subType);
64
/// Creates the MediaType, using the given type and subtype.
66
MediaType(const MediaType& mediaType);
67
/// Creates a MediaType from another one.
70
/// Destroys the MediaType.
72
MediaType& operator = (const MediaType& mediaType);
73
/// Assigns another media type.
75
MediaType& operator = (const std::string& mediaType);
76
/// Assigns another media type.
78
void swap(MediaType& mediaType);
79
/// Swaps the MediaType with another one.
81
void setType(const std::string& type);
82
/// Sets the top-level type.
84
const std::string& getType() const;
85
/// Returns the top-level type.
87
void setSubType(const std::string& subType);
88
/// Sets the sub type.
90
const std::string& getSubType() const;
91
/// Returns the sub type.
93
void setParameter(const std::string& name, const std::string& value);
94
/// Sets the parameter with the given name.
96
const std::string& getParameter(const std::string& name) const;
97
/// Returns the parameter with the given name.
99
/// Throws a NotFoundException if the parameter does not exist.
101
bool hasParameter(const std::string& name) const;
102
/// Returns true iff a parameter with the given name exists.
104
void removeParameter(const std::string& name);
105
/// Removes the parameter with the given name.
107
const NameValueCollection& parameters() const;
108
/// Returns the parameters.
110
std::string toString() const;
111
/// Returns the string representation of the media type
112
/// which is <type>/<subtype>{;<parameter>=<value>}
114
bool matches(const MediaType& mediaType) const;
115
/// Returns true iff the type and subtype match
116
/// the type and subtype of the given media type.
117
/// Matching is case insensitive.
119
bool matches(const std::string& type, const std::string& subType) const;
120
/// Returns true iff the type and subtype match
121
/// the given type and subtype.
122
/// Matching is case insensitive.
124
bool matches(const std::string& type) const;
125
/// Returns true iff the type matches the given type.
126
/// Matching is case insensitive.
129
void parse(const std::string& mediaType);
135
std::string _subType;
136
NameValueCollection _parameters;
143
inline const std::string& MediaType::getType() const
149
inline const std::string& MediaType::getSubType() const
155
inline const NameValueCollection& MediaType::parameters() const
161
inline void swap(MediaType& m1, MediaType& m2)
167
} } // namespace Poco::Net
170
#endif // Net_MediaType_INCLUDED