source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/util/XMLURL.hpp @ 2674

Revision 2674, 8.6 KB checked in by mattausch, 16 years ago (diff)
Line 
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: XMLURL.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22#if !defined(XMLURL_HPP)
23#define XMLURL_HPP
24
25#include <xercesc/util/PlatformUtils.hpp>
26
27XERCES_CPP_NAMESPACE_BEGIN
28
29class BinInputStream;
30
31//
32//  This class supports file, http, and ftp style URLs. All others are
33//  rejected
34//
35class 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// ---------------------------------------------------------------------------
225inline bool XMLURL::operator!=(const XMLURL& toCompare) const
226{
227    return !operator==(toCompare);
228}
229
230
231// ---------------------------------------------------------------------------
232//  XMLURL: Getter methods
233// ---------------------------------------------------------------------------
234inline const XMLCh* XMLURL::getFragment() const
235{
236    return fFragment;
237}
238
239inline const XMLCh* XMLURL::getHost() const
240{
241    return fHost;
242}
243
244inline const XMLCh* XMLURL::getPassword() const
245{
246    return fPassword;
247}
248
249inline const XMLCh* XMLURL::getPath() const
250{
251    return fPath;
252}
253
254inline XMLURL::Protocols XMLURL::getProtocol() const
255{
256    return fProtocol;
257}
258
259inline const XMLCh* XMLURL::getQuery() const
260{
261    return fQuery;
262}
263
264inline const XMLCh* XMLURL::getUser() const
265{
266    return fUser;
267}
268
269inline 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
282inline MemoryManager* XMLURL::getMemoryManager() const
283{
284    return fMemoryManager;
285}
286
287MakeXMLException(MalformedURLException, XMLUTIL_EXPORT)
288
289XERCES_CPP_NAMESPACE_END
290
291
292#endif
Note: See TracBrowser for help on using the repository browser.