source: obsolete/trunk/VUT/GtpVisibilityPreprocessor/support/xerces/include/xercesc/util/XMLURL.hpp @ 358

Revision 358, 8.7 KB checked in by bittner, 19 years ago (diff)

xerces added

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