1 | /*
|
---|
2 | * The Apache Software License, Version 1.1
|
---|
3 | *
|
---|
4 | * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
|
---|
5 | * reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * 1. Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | *
|
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
15 | * notice, this list of conditions and the following disclaimer in
|
---|
16 | * the documentation and/or other materials provided with the
|
---|
17 | * distribution.
|
---|
18 | *
|
---|
19 | * 3. The end-user documentation included with the redistribution,
|
---|
20 | * if any, must include the following acknowledgment:
|
---|
21 | * "This product includes software developed by the
|
---|
22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
25 | *
|
---|
26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
27 | * not be used to endorse or promote products derived from this
|
---|
28 | * software without prior written permission. For written
|
---|
29 | * permission, please contact apache\@apache.org.
|
---|
30 | *
|
---|
31 | * 5. Products derived from this software may not be called "Apache",
|
---|
32 | * nor may "Apache" appear in their name, without prior written
|
---|
33 | * permission of the Apache Software Foundation.
|
---|
34 | *
|
---|
35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
46 | * SUCH DAMAGE.
|
---|
47 | * ====================================================================
|
---|
48 | *
|
---|
49 | * This software consists of voluntary contributions made by many
|
---|
50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
51 | * originally based on software copyright (c) 1999, International
|
---|
52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
53 | * on the Apache Software Foundation, please see
|
---|
54 | * <http://www.apache.org/>.
|
---|
55 | */
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * $Id: XMLURL.hpp,v 1.12 2004/01/12 16:15:57 cargilld Exp $
|
---|
59 | */
|
---|
60 |
|
---|
61 | #if !defined(XMLURL_HPP)
|
---|
62 | #define XMLURL_HPP
|
---|
63 |
|
---|
64 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
65 |
|
---|
66 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
67 |
|
---|
68 | class BinInputStream;
|
---|
69 |
|
---|
70 | //
|
---|
71 | // This class supports file, http, and ftp style URLs. All others are
|
---|
72 | // rejected
|
---|
73 | //
|
---|
74 | class XMLUTIL_EXPORT XMLURL : public XMemory
|
---|
75 | {
|
---|
76 | public:
|
---|
77 | // -----------------------------------------------------------------------
|
---|
78 | // Class types
|
---|
79 | //
|
---|
80 | // And they must remain in this order because they are indexes into an
|
---|
81 | // array internally!
|
---|
82 | // -----------------------------------------------------------------------
|
---|
83 | enum Protocols
|
---|
84 | {
|
---|
85 | File
|
---|
86 | , HTTP
|
---|
87 | , FTP
|
---|
88 |
|
---|
89 | , Protocols_Count
|
---|
90 | , Unknown
|
---|
91 | };
|
---|
92 |
|
---|
93 |
|
---|
94 | // -----------------------------------------------------------------------
|
---|
95 | // Public static methods
|
---|
96 | // -----------------------------------------------------------------------
|
---|
97 | static Protocols lookupByName(const XMLCh* const protoName);
|
---|
98 | static bool parse(const XMLCh* const urlText, XMLURL& xmlURL);
|
---|
99 |
|
---|
100 | // -----------------------------------------------------------------------
|
---|
101 | // Constructors and Destructor
|
---|
102 | // -----------------------------------------------------------------------
|
---|
103 | XMLURL(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
104 | XMLURL
|
---|
105 | (
|
---|
106 | const XMLCh* const baseURL
|
---|
107 | , const XMLCh* const relativeURL
|
---|
108 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
109 | );
|
---|
110 | XMLURL
|
---|
111 | (
|
---|
112 | const XMLCh* const baseURL
|
---|
113 | , const char* const relativeURL
|
---|
114 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
115 | );
|
---|
116 | XMLURL
|
---|
117 | (
|
---|
118 | const XMLURL& baseURL
|
---|
119 | , const XMLCh* const relativeURL
|
---|
120 | );
|
---|
121 | XMLURL
|
---|
122 | (
|
---|
123 | const XMLURL& baseURL
|
---|
124 | , const char* const relativeURL
|
---|
125 | );
|
---|
126 | XMLURL
|
---|
127 | (
|
---|
128 | const XMLCh* const urlText
|
---|
129 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
130 | );
|
---|
131 | XMLURL
|
---|
132 | (
|
---|
133 | const char* const urlText
|
---|
134 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
135 | );
|
---|
136 | XMLURL(const XMLURL& toCopy);
|
---|
137 | virtual ~XMLURL();
|
---|
138 |
|
---|
139 |
|
---|
140 | // -----------------------------------------------------------------------
|
---|
141 | // Operators
|
---|
142 | // -----------------------------------------------------------------------
|
---|
143 | XMLURL& operator=(const XMLURL& toAssign);
|
---|
144 | bool operator==(const XMLURL& toCompare) const;
|
---|
145 | bool operator!=(const XMLURL& toCompare) const;
|
---|
146 |
|
---|
147 |
|
---|
148 | // -----------------------------------------------------------------------
|
---|
149 | // Getter methods
|
---|
150 | // -----------------------------------------------------------------------
|
---|
151 | const XMLCh* getFragment() const;
|
---|
152 | const XMLCh* getHost() const;
|
---|
153 | const XMLCh* getPassword() const;
|
---|
154 | const XMLCh* getPath() const;
|
---|
155 | unsigned int getPortNum() const;
|
---|
156 | Protocols getProtocol() const;
|
---|
157 | const XMLCh* getProtocolName() const;
|
---|
158 | const XMLCh* getQuery() const;
|
---|
159 | const XMLCh* getURLText() const;
|
---|
160 | const XMLCh* getUser() const;
|
---|
161 | MemoryManager* getMemoryManager() const;
|
---|
162 |
|
---|
163 |
|
---|
164 | // -----------------------------------------------------------------------
|
---|
165 | // Setter methods
|
---|
166 | // -----------------------------------------------------------------------
|
---|
167 | void setURL(const XMLCh* const urlText);
|
---|
168 | void setURL
|
---|
169 | (
|
---|
170 | const XMLCh* const baseURL
|
---|
171 | , const XMLCh* const relativeURL
|
---|
172 | );
|
---|
173 | void setURL
|
---|
174 | (
|
---|
175 | const XMLURL& baseURL
|
---|
176 | , const XMLCh* const relativeURL
|
---|
177 | );
|
---|
178 | // a version of setURL that doesn't throw malformed url exceptions
|
---|
179 | bool setURL(
|
---|
180 | const XMLCh* const baseURL
|
---|
181 | , const XMLCh* const relativeURL
|
---|
182 | , XMLURL& xmlURL);
|
---|
183 | // -----------------------------------------------------------------------
|
---|
184 | // Miscellaneous methods
|
---|
185 | // -----------------------------------------------------------------------
|
---|
186 | bool isRelative() const;
|
---|
187 | bool hasInvalidChar() const;
|
---|
188 | BinInputStream* makeNewStream() const;
|
---|
189 | void makeRelativeTo(const XMLCh* const baseURLText);
|
---|
190 | void makeRelativeTo(const XMLURL& baseURL);
|
---|
191 |
|
---|
192 |
|
---|
193 | private:
|
---|
194 | // -----------------------------------------------------------------------
|
---|
195 | // Private helper methods
|
---|
196 | // -----------------------------------------------------------------------
|
---|
197 | void buildFullText();
|
---|
198 | void cleanup();
|
---|
199 | bool conglomerateWithBase(const XMLURL& baseURL, bool useExceptions=true);
|
---|
200 | void parse
|
---|
201 | (
|
---|
202 | const XMLCh* const urlText
|
---|
203 | );
|
---|
204 |
|
---|
205 |
|
---|
206 | // -----------------------------------------------------------------------
|
---|
207 | // Data members
|
---|
208 | //
|
---|
209 | // fFragment
|
---|
210 | // The fragment part of the URL, if any. If none, its a null.
|
---|
211 | //
|
---|
212 | // fHost
|
---|
213 | // The host part of the URL that was parsed out. This one will often
|
---|
214 | // be null (or "localhost", which also means the current machine.)
|
---|
215 | //
|
---|
216 | // fPassword
|
---|
217 | // The password found, if any. If none then its a null.
|
---|
218 | //
|
---|
219 | // fPath
|
---|
220 | // The path part of the URL that was parsed out, if any. If none,
|
---|
221 | // then its a null.
|
---|
222 | //
|
---|
223 | // fPortNum
|
---|
224 | // The port that was indicated in the URL. If no port was provided
|
---|
225 | // explicitly, then its left zero.
|
---|
226 | //
|
---|
227 | // fProtocol
|
---|
228 | // Indicates the type of the URL's source. The text of the prefix
|
---|
229 | // can be gotten from this.
|
---|
230 | //
|
---|
231 | // fQuery
|
---|
232 | // The query part of the URL, if any. If none, then its a null.
|
---|
233 | //
|
---|
234 | // fUser
|
---|
235 | // The username found, if any. If none, then its a null.
|
---|
236 | //
|
---|
237 | // fURLText
|
---|
238 | // This is a copy of the URL text, after it has been taken apart,
|
---|
239 | // made relative if needed, canonicalized, and then put back
|
---|
240 | // together. Its only created upon demand.
|
---|
241 | //
|
---|
242 | // fHasInvalidChar
|
---|
243 | // This indicates if the URL Text contains invalid characters as per
|
---|
244 | // RFC 2396 standard.
|
---|
245 | // -----------------------------------------------------------------------
|
---|
246 | MemoryManager* fMemoryManager;
|
---|
247 | XMLCh* fFragment;
|
---|
248 | XMLCh* fHost;
|
---|
249 | XMLCh* fPassword;
|
---|
250 | XMLCh* fPath;
|
---|
251 | unsigned int fPortNum;
|
---|
252 | Protocols fProtocol;
|
---|
253 | XMLCh* fQuery;
|
---|
254 | XMLCh* fUser;
|
---|
255 | XMLCh* fURLText;
|
---|
256 | bool fHasInvalidChar;
|
---|
257 | };
|
---|
258 |
|
---|
259 |
|
---|
260 | // ---------------------------------------------------------------------------
|
---|
261 | // XMLURL: Public operators
|
---|
262 | // ---------------------------------------------------------------------------
|
---|
263 | inline bool XMLURL::operator!=(const XMLURL& toCompare) const
|
---|
264 | {
|
---|
265 | return !operator==(toCompare);
|
---|
266 | }
|
---|
267 |
|
---|
268 |
|
---|
269 | // ---------------------------------------------------------------------------
|
---|
270 | // XMLURL: Getter methods
|
---|
271 | // ---------------------------------------------------------------------------
|
---|
272 | inline const XMLCh* XMLURL::getFragment() const
|
---|
273 | {
|
---|
274 | return fFragment;
|
---|
275 | }
|
---|
276 |
|
---|
277 | inline const XMLCh* XMLURL::getHost() const
|
---|
278 | {
|
---|
279 | return fHost;
|
---|
280 | }
|
---|
281 |
|
---|
282 | inline const XMLCh* XMLURL::getPassword() const
|
---|
283 | {
|
---|
284 | return fPassword;
|
---|
285 | }
|
---|
286 |
|
---|
287 | inline const XMLCh* XMLURL::getPath() const
|
---|
288 | {
|
---|
289 | return fPath;
|
---|
290 | }
|
---|
291 |
|
---|
292 | inline XMLURL::Protocols XMLURL::getProtocol() const
|
---|
293 | {
|
---|
294 | return fProtocol;
|
---|
295 | }
|
---|
296 |
|
---|
297 | inline const XMLCh* XMLURL::getQuery() const
|
---|
298 | {
|
---|
299 | return fQuery;
|
---|
300 | }
|
---|
301 |
|
---|
302 | inline const XMLCh* XMLURL::getUser() const
|
---|
303 | {
|
---|
304 | return fUser;
|
---|
305 | }
|
---|
306 |
|
---|
307 | inline const XMLCh* XMLURL::getURLText() const
|
---|
308 | {
|
---|
309 | //
|
---|
310 | // Fault it in if not already. Since this is a const method and we
|
---|
311 | // can't use mutable members due the compilers we have to support,
|
---|
312 | // we have to cast off the constness.
|
---|
313 | //
|
---|
314 | if (!fURLText)
|
---|
315 | ((XMLURL*)this)->buildFullText();
|
---|
316 |
|
---|
317 | return fURLText;
|
---|
318 | }
|
---|
319 |
|
---|
320 | inline MemoryManager* XMLURL::getMemoryManager() const
|
---|
321 | {
|
---|
322 | return fMemoryManager;
|
---|
323 | }
|
---|
324 |
|
---|
325 | MakeXMLException(MalformedURLException, XMLUTIL_EXPORT)
|
---|
326 |
|
---|
327 | XERCES_CPP_NAMESPACE_END
|
---|
328 |
|
---|
329 |
|
---|
330 | #endif
|
---|