~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to Net/include/Poco/Net/MediaType.h

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// MediaType.h
 
3
//
 
4
// $Id: //poco/1.2/Net/include/Poco/Net/MediaType.h#1 $
 
5
//
 
6
// Library: Net
 
7
// Package: Messages
 
8
// Module:  MediaType
 
9
//
 
10
// Definition of the MediaType class.
 
11
//
 
12
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
 
13
// and Contributors.
 
14
//
 
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:
 
21
// 
 
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.
 
28
// 
 
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.
 
36
//
 
37
 
 
38
 
 
39
#ifndef Net_MediaType_INCLUDED
 
40
#define Net_MediaType_INCLUDED
 
41
 
 
42
 
 
43
#include "Poco/Net/Net.h"
 
44
#include "Poco/Net/NameValueCollection.h"
 
45
 
 
46
 
 
47
namespace Poco {
 
48
namespace Net {
 
49
 
 
50
 
 
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
 
54
        /// parameters.
 
55
        ///
 
56
        /// The implementation conforms with RFC 2045 and RFC 2046.
 
57
{
 
58
public:
 
59
        MediaType(const std::string& mediaType);
 
60
                /// Creates the MediaType from the given string, which
 
61
                /// must have the format <type>/<subtype>{;<parameter>=<value>}.
 
62
                
 
63
        MediaType(const std::string& type, const std::string& subType);
 
64
                /// Creates the MediaType, using the given type and subtype.
 
65
 
 
66
        MediaType(const MediaType& mediaType);
 
67
                /// Creates a MediaType from another one.
 
68
 
 
69
        ~MediaType();
 
70
                /// Destroys the MediaType.
 
71
 
 
72
        MediaType& operator = (const MediaType& mediaType);
 
73
                /// Assigns another media type.
 
74
                
 
75
        MediaType& operator = (const std::string& mediaType);
 
76
                /// Assigns another media type.
 
77
                
 
78
        void swap(MediaType& mediaType);
 
79
                /// Swaps the MediaType with another one.
 
80
                
 
81
        void setType(const std::string& type);
 
82
                /// Sets the top-level type.
 
83
                
 
84
        const std::string& getType() const;
 
85
                /// Returns the top-level type.
 
86
                
 
87
        void setSubType(const std::string& subType);
 
88
                /// Sets the sub type.
 
89
                
 
90
        const std::string& getSubType() const;
 
91
                /// Returns the sub type.
 
92
                
 
93
        void setParameter(const std::string& name, const std::string& value);
 
94
                /// Sets the parameter with the given name.
 
95
                
 
96
        const std::string& getParameter(const std::string& name) const;
 
97
                /// Returns the parameter with the given name.
 
98
                ///
 
99
                /// Throws a NotFoundException if the parameter does not exist.
 
100
                
 
101
        bool hasParameter(const std::string& name) const;
 
102
                /// Returns true iff a parameter with the given name exists.
 
103
                
 
104
        void removeParameter(const std::string& name);
 
105
                /// Removes the parameter with the given name.  
 
106
                
 
107
        const NameValueCollection& parameters() const;
 
108
                /// Returns the parameters.
 
109
                
 
110
        std::string toString() const;
 
111
                /// Returns the string representation of the media type
 
112
                /// which is <type>/<subtype>{;<parameter>=<value>}
 
113
                
 
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.
 
118
                
 
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.
 
123
 
 
124
        bool matches(const std::string& type) const;
 
125
                /// Returns true iff the type matches the given type.
 
126
                /// Matching is case insensitive.
 
127
 
 
128
protected:
 
129
        void parse(const std::string& mediaType);
 
130
                
 
131
private:
 
132
        MediaType();
 
133
        
 
134
        std::string         _type;
 
135
        std::string         _subType;
 
136
        NameValueCollection _parameters;
 
137
};
 
138
 
 
139
 
 
140
//
 
141
// inlines
 
142
//
 
143
inline const std::string& MediaType::getType() const
 
144
{
 
145
        return _type;
 
146
}
 
147
 
 
148
 
 
149
inline const std::string& MediaType::getSubType() const
 
150
{
 
151
        return _subType;
 
152
}
 
153
 
 
154
 
 
155
inline const NameValueCollection& MediaType::parameters() const
 
156
{
 
157
        return _parameters;
 
158
}
 
159
 
 
160
 
 
161
inline void swap(MediaType& m1, MediaType& m2)
 
162
{
 
163
        m1.swap(m2);
 
164
}
 
165
 
 
166
 
 
167
} } // namespace Poco::Net
 
168
 
 
169
 
 
170
#endif // Net_MediaType_INCLUDED