Xerces-C++: XMLURL.hpp Source File

Xerces-C++ 3.3.0

XMLURL.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id$
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_XMLURL_HPP)
23#define XERCESC_INCLUDE_GUARD_XMLURL_HPP
24
25#include <xercesc/util/PlatformUtils.hpp>
26
27 XERCES_CPP_NAMESPACE_BEGIN
28
29class BinInputStream;
30
31//
32// This class supports file, http, and ftp style URLs. All others are
33// rejected
34//
35 class XMLUTIL_EXPORT XMLURL : public XMemory
36{
37public:
38 // -----------------------------------------------------------------------
39 // Class types
40 //
41 // And they must remain in this order because they are indexes into an
42 // array internally!
43 // -----------------------------------------------------------------------
44 enum Protocols
45 {
46 File
47 , HTTP
48 , FTP
49 , HTTPS
50
51 , Protocols_Count
52 , Unknown
53 };
54
55
56 // -----------------------------------------------------------------------
57 // Public static methods
58 // -----------------------------------------------------------------------
59 static Protocols lookupByName(const XMLCh* const protoName);
60 static bool parse(const XMLCh* const urlText, XMLURL& xmlURL);
61
62 // -----------------------------------------------------------------------
63 // Constructors and Destructor
64 // -----------------------------------------------------------------------
65 XMLURL(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
66 XMLURL
67 (
68 const XMLCh* const baseURL
69 , const XMLCh* const relativeURL
70 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
71 );
72 XMLURL
73 (
74 const XMLCh* const baseURL
75 , const char* const relativeURL
76 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
77 );
78 XMLURL
79 (
80 const XMLURL& baseURL
81 , const XMLCh* const relativeURL
82 );
83 XMLURL
84 (
85 const XMLURL& baseURL
86 , const char* const relativeURL
87 );
88 XMLURL
89 (
90 const XMLCh* const urlText
91 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
92 );
93 XMLURL
94 (
95 const char* const urlText
96 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
97 );
98 XMLURL(const XMLURL& toCopy);
99 virtual ~XMLURL();
100
101
102 // -----------------------------------------------------------------------
103 // Operators
104 // -----------------------------------------------------------------------
105 XMLURL& operator=(const XMLURL& toAssign);
106 bool operator==(const XMLURL& toCompare) const;
107 bool operator!=(const XMLURL& toCompare) const;
108
109
110 // -----------------------------------------------------------------------
111 // Getter methods
112 // -----------------------------------------------------------------------
113 const XMLCh* getFragment() const;
114 const XMLCh* getHost() const;
115 const XMLCh* getPassword() const;
116 const XMLCh* getPath() const;
117 unsigned int getPortNum() const;
118 Protocols getProtocol() const;
119 const XMLCh* getProtocolName() const;
120 const XMLCh* getQuery() const;
121 const XMLCh* getURLText() const;
122 const XMLCh* getUser() const;
123 MemoryManager* getMemoryManager() const;
124
125
126 // -----------------------------------------------------------------------
127 // Setter methods
128 // -----------------------------------------------------------------------
129 void setURL(const XMLCh* const urlText);
130 void setURL
131 (
132 const XMLCh* const baseURL
133 , const XMLCh* const relativeURL
134 );
135 void setURL
136 (
137 const XMLURL& baseURL
138 , const XMLCh* const relativeURL
139 );
140 // a version of setURL that doesn't throw malformed url exceptions
141 bool setURL(
142 const XMLCh* const baseURL
143 , const XMLCh* const relativeURL
144 , XMLURL& xmlURL);
145 // -----------------------------------------------------------------------
146 // Miscellaneous methods
147 // -----------------------------------------------------------------------
148 bool isRelative() const;
149 bool hasInvalidChar() const;
150 BinInputStream* makeNewStream() const;
151 void makeRelativeTo(const XMLCh* const baseURLText);
152 void makeRelativeTo(const XMLURL& baseURL);
153
154
155private:
156 // -----------------------------------------------------------------------
157 // Private helper methods
158 // -----------------------------------------------------------------------
159 void buildFullText();
160 void cleanUp();
161 bool conglomerateWithBase(const XMLURL& baseURL, bool useExceptions=true);
162 void parse
163 (
164 const XMLCh* const urlText
165 );
166
167
168 // -----------------------------------------------------------------------
169 // Data members
170 //
171 // fFragment
172 // The fragment part of the URL, if any. If none, its a null.
173 //
174 // fHost
175 // The host part of the URL that was parsed out. This one will often
176 // be null (or "localhost", which also means the current machine.)
177 //
178 // fPassword
179 // The password found, if any. If none then its a null.
180 //
181 // fPath
182 // The path part of the URL that was parsed out, if any. If none,
183 // then its a null.
184 //
185 // fPortNum
186 // The port that was indicated in the URL. If no port was provided
187 // explicitly, then its left zero.
188 //
189 // fProtocol
190 // Indicates the type of the URL's source. The text of the prefix
191 // can be gotten from this.
192 //
193 // fQuery
194 // The query part of the URL, if any. If none, then its a null.
195 //
196 // fUser
197 // The username found, if any. If none, then its a null.
198 //
199 // fURLText
200 // This is a copy of the URL text, after it has been taken apart,
201 // made relative if needed, canonicalized, and then put back
202 // together. Its only created upon demand.
203 //
204 // fHasInvalidChar
205 // This indicates if the URL Text contains invalid characters as per
206 // RFC 2396 standard.
207 // -----------------------------------------------------------------------
208 MemoryManager* fMemoryManager;
209 XMLCh* fFragment;
210 XMLCh* fHost;
211 XMLCh* fPassword;
212 XMLCh* fPath;
213 unsigned int fPortNum;
214 Protocols fProtocol;
215 XMLCh* fQuery;
216 XMLCh* fUser;
217 XMLCh* fURLText;
218 bool fHasInvalidChar;
219};
220
221
222// ---------------------------------------------------------------------------
223// XMLURL: Public operators
224// ---------------------------------------------------------------------------
225 inline bool XMLURL::operator!=(const XMLURL& toCompare) const
226{
227 return !operator==(toCompare);
228}
229
230
231// ---------------------------------------------------------------------------
232// XMLURL: Getter methods
233// ---------------------------------------------------------------------------
234 inline const XMLCh* XMLURL::getFragment() const
235{
236 return fFragment;
237}
238
239 inline const XMLCh* XMLURL::getHost() const
240{
241 return fHost;
242}
243
244 inline const XMLCh* XMLURL::getPassword() const
245{
246 return fPassword;
247}
248
249 inline const XMLCh* XMLURL::getPath() const
250{
251 return fPath;
252}
253
254 inline XMLURL::Protocols XMLURL::getProtocol() const
255{
256 return fProtocol;
257}
258
259 inline const XMLCh* XMLURL::getQuery() const
260{
261 return fQuery;
262}
263
264 inline const XMLCh* XMLURL::getUser() const
265{
266 return fUser;
267}
268
269 inline const XMLCh* XMLURL::getURLText() const
270{
271 //
272 // Fault it in if not already. Since this is a const method and we
273 // can't use mutable members due the compilers we have to support,
274 // we have to cast off the constness.
275 //
276 if (!fURLText)
277 ((XMLURL*)this)->buildFullText();
278
279 return fURLText;
280}
281
282 inline MemoryManager* XMLURL::getMemoryManager() const
283{
284 return fMemoryManager;
285}
286
287 MakeXMLException(MalformedURLException, XMLUTIL_EXPORT)
288
289 XERCES_CPP_NAMESPACE_END
290
291
292#endif
PlatformUtils.hpp
MakeXMLException
#define MakeXMLException(theType, expKeyword)
Definition XMLException.hpp:178
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition XercesDefs.hpp:112
XMLUTIL_EXPORT
#define XMLUTIL_EXPORT
Definition XercesDefs.hpp:162
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition XercesDefs.hpp:113
XMLCh
char16_t XMLCh
Definition Xerces_autoconf_config.hpp:120
BinInputStream
Definition BinInputStream.hpp:30
MemoryManager
Configurable memory manager.
Definition MemoryManager.hpp:40
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition PlatformUtils.hpp:121
XMLURL
Definition XMLURL.hpp:36
XMLURL::operator==
bool operator==(const XMLURL &toCompare) const
XMLURL::getPath
const XMLCh * getPath() const
Definition XMLURL.hpp:249
XMLURL::setURL
bool setURL(const XMLCh *const baseURL, const XMLCh *const relativeURL, XMLURL &xmlURL)
XMLURL::XMLURL
XMLURL(const XMLCh *const urlText, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLURL::hasInvalidChar
bool hasInvalidChar() const
XMLURL::getHost
const XMLCh * getHost() const
Definition XMLURL.hpp:239
XMLURL::makeRelativeTo
void makeRelativeTo(const XMLURL &baseURL)
XMLURL::XMLURL
XMLURL(const XMLURL &baseURL, const char *const relativeURL)
XMLURL::isRelative
bool isRelative() const
XMLURL::getProtocol
Protocols getProtocol() const
Definition XMLURL.hpp:254
XMLURL::Protocols
Protocols
Definition XMLURL.hpp:45
XMLURL::getQuery
const XMLCh * getQuery() const
Definition XMLURL.hpp:259
XMLURL::XMLURL
XMLURL(const XMLURL &baseURL, const XMLCh *const relativeURL)
XMLURL::~XMLURL
virtual ~XMLURL()
XMLURL::getFragment
const XMLCh * getFragment() const
Definition XMLURL.hpp:234
XMLURL::XMLURL
XMLURL(MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLURL::XMLURL
XMLURL(const char *const urlText, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLURL::XMLURL
XMLURL(const XMLCh *const baseURL, const XMLCh *const relativeURL, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLURL::makeNewStream
BinInputStream * makeNewStream() const
XMLURL::setURL
void setURL(const XMLURL &baseURL, const XMLCh *const relativeURL)
XMLURL::XMLURL
XMLURL(const XMLURL &toCopy)
XMLURL::setURL
void setURL(const XMLCh *const urlText)
XMLURL::getProtocolName
const XMLCh * getProtocolName() const
XMLURL::parse
static bool parse(const XMLCh *const urlText, XMLURL &xmlURL)
XMLURL::lookupByName
static Protocols lookupByName(const XMLCh *const protoName)
XMLURL::getURLText
const XMLCh * getURLText() const
Definition XMLURL.hpp:269
XMLURL::getUser
const XMLCh * getUser() const
Definition XMLURL.hpp:264
XMLURL::getPassword
const XMLCh * getPassword() const
Definition XMLURL.hpp:244
XMLURL::XMLURL
XMLURL(const XMLCh *const baseURL, const char *const relativeURL, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
XMLURL::setURL
void setURL(const XMLCh *const baseURL, const XMLCh *const relativeURL)
XMLURL::makeRelativeTo
void makeRelativeTo(const XMLCh *const baseURLText)
XMLURL::getPortNum
unsigned int getPortNum() const
XMLURL::operator!=
bool operator!=(const XMLURL &toCompare) const
Definition XMLURL.hpp:225
XMLURL::operator=
XMLURL & operator=(const XMLURL &toAssign)
XMLURL::getMemoryManager
MemoryManager * getMemoryManager() const
Definition XMLURL.hpp:282
XMemory
This class makes it possible to override the C++ memory management by adding new/delete operators to ...
Definition XMemory.hpp:41