| API Docs for SAX and DOM |

- Main Page
- Classes
- Files
- Related Pages

# XMLURL.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Licensed to the Apache Software Foundation (ASF) under one or more
    00003  * contributor license agreements.  See the NOTICE file distributed with
    00004  * this work for additional information regarding copyright ownership.
    00005  * The ASF licenses this file to You under the Apache License, Version 2.0
    00006  * (the "License"); you may not use this file except in compliance with
    00007  * the License.  You may obtain a copy of the License at
    00008  *
    00009  *      http://www.apache.org/licenses/LICENSE-2.0
    00010  *
    00011  * Unless required by applicable law or agreed to in writing, software
    00012  * distributed under the License is distributed on an "AS IS" BASIS,
    00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00014  * See the License for the specific language governing permissions and
    00015  * limitations under the License.
    00016  */
    00017
    00018 /*
    00019  * $Id: XMLURL.hpp 568078 2007-08-21 11:43:25Z amassari $
    00020  */
    00021
    00022 #if !defined(XMLURL_HPP)
    00023 #define XMLURL_HPP
    00024
    00025 #include <xercesc/util/PlatformUtils.hpp>
    00026
    00027 XERCES_CPP_NAMESPACE_BEGIN
    00028
    00029 class BinInputStream;
    00030
    00031 //
    00032 //  This class supports file, http, and ftp style URLs. All others are
    00033 //  rejected
    00034 //
    00035 class  XMLURL : public XMemory
    00036 {
    00037 public:
    00038     // -----------------------------------------------------------------------
    00039     //  Class types
    00040     //
    00041     //  And they must remain in this order because they are indexes into an
    00042     //  array internally!
    00043     // -----------------------------------------------------------------------
    00044     enum Protocols
    00045     {
    00046         File
    00047         , HTTP
    00048         , FTP
    00049         , HTTPS
    00050
    00051         , Protocols_Count
    00052         , Unknown
    00053     };
    00054
    00055
    00056     // -----------------------------------------------------------------------
    00057     //  Public static methods
    00058     // -----------------------------------------------------------------------
    00059     static Protocols lookupByName(const XMLCh* const protoName);
    00060     static bool parse(const XMLCh* const urlText, XMLURL& xmlURL);
    00061
    00062     // -----------------------------------------------------------------------
    00063     //  Constructors and Destructor
    00064     // -----------------------------------------------------------------------
    00065     XMLURL(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00066     XMLURL
    00067     (
    00068         const   XMLCh* const    baseURL
    00069         , const XMLCh* const    relativeURL
    00070         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
    00071     );
    00072     XMLURL
    00073     (
    00074         const   XMLCh* const    baseURL
    00075         , const char* const     relativeURL
    00076         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
    00077     );
    00078     XMLURL
    00079     (
    00080         const   XMLURL&         baseURL
    00081         , const XMLCh* const    relativeURL
    00082     );
    00083     XMLURL
    00084     (
    00085         const   XMLURL&         baseURL
    00086         , const char* const     relativeURL
    00087     );
    00088     XMLURL
    00089     (
    00090         const   XMLCh* const    urlText
    00091         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00092     );
    00093     XMLURL
    00094     (
    00095         const   char* const     urlText
    00096         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00097     );
    00098     XMLURL(const XMLURL& toCopy);
    00099     virtual ~XMLURL();
    00100
    00101
    00102     // -----------------------------------------------------------------------
    00103     //  Operators
    00104     // -----------------------------------------------------------------------
    00105     XMLURL& operator=(const XMLURL& toAssign);
    00106     bool operator==(const XMLURL& toCompare) const;
    00107     bool operator!=(const XMLURL& toCompare) const;
    00108
    00109
    00110     // -----------------------------------------------------------------------
    00111     //  Getter methods
    00112     // -----------------------------------------------------------------------
    00113     const XMLCh* getFragment() const;
    00114     const XMLCh* getHost() const;
    00115     const XMLCh* getPassword() const;
    00116     const XMLCh* getPath() const;
    00117     unsigned int getPortNum() const;
    00118     Protocols getProtocol() const;
    00119     const XMLCh* getProtocolName() const;
    00120     const XMLCh* getQuery() const;
    00121     const XMLCh* getURLText() const;
    00122     const XMLCh* getUser() const;
    00123     MemoryManager* getMemoryManager() const;
    00124
    00125
    00126     // -----------------------------------------------------------------------
    00127     //  Setter methods
    00128     // -----------------------------------------------------------------------
    00129     void setURL(const XMLCh* const urlText);
    00130     void setURL
    00131     (
    00132         const   XMLCh* const    baseURL
    00133         , const XMLCh* const    relativeURL
    00134     );
    00135     void setURL
    00136     (
    00137         const   XMLURL&         baseURL
    00138         , const XMLCh* const    relativeURL
    00139     );
    00140     // a version of setURL that doesn't throw malformed url exceptions
    00141     bool setURL(
    00142         const XMLCh* const    baseURL
    00143         , const XMLCh* const    relativeURL
    00144         , XMLURL& xmlURL);
    00145     // -----------------------------------------------------------------------
    00146     //  Miscellaneous methods
    00147     // -----------------------------------------------------------------------
    00148     bool isRelative() const;
    00149     bool hasInvalidChar() const;
    00150     BinInputStream* makeNewStream() const;
    00151     void makeRelativeTo(const XMLCh* const baseURLText);
    00152     void makeRelativeTo(const XMLURL& baseURL);
    00153
    00154
    00155 private:
    00156     // -----------------------------------------------------------------------
    00157     //  Private helper methods
    00158     // -----------------------------------------------------------------------
    00159     void buildFullText();
    00160     void cleanUp();
    00161     bool conglomerateWithBase(const XMLURL& baseURL, bool useExceptions=true);
    00162     void parse
    00163     (
    00164         const   XMLCh* const    urlText
    00165     );
    00166
    00167
    00168     // -----------------------------------------------------------------------
    00169     //  Data members
    00170     //
    00171     //  fFragment
    00172     //      The fragment part of the URL, if any. If none, its a null.
    00173     //
    00174     //  fHost
    00175     //      The host part of the URL that was parsed out. This one will often
    00176     //      be null (or "localhost", which also means the current machine.)
    00177     //
    00178     //  fPassword
    00179     //      The password found, if any. If none then its a null.
    00180     //
    00181     //  fPath
    00182     //      The path part of the URL that was parsed out, if any. If none,
    00183     //      then its a null.
    00184     //
    00185     //  fPortNum
    00186     //      The port that was indicated in the URL. If no port was provided
    00187     //      explicitly, then its left zero.
    00188     //
    00189     //  fProtocol
    00190     //      Indicates the type of the URL's source. The text of the prefix
    00191     //      can be gotten from this.
    00192     //
    00193     //  fQuery
    00194     //      The query part of the URL, if any. If none, then its a null.
    00195     //
    00196     //  fUser
    00197     //      The username found, if any. If none, then its a null.
    00198     //
    00199     //  fURLText
    00200     //      This is a copy of the URL text, after it has been taken apart,
    00201     //      made relative if needed, canonicalized, and then put back
    00202     //      together. Its only created upon demand.
    00203     //
    00204     //  fHasInvalidChar
    00205     //      This indicates if the URL Text contains invalid characters as per
    00206     //      RFC 2396 standard.
    00207     // -----------------------------------------------------------------------
    00208     MemoryManager*  fMemoryManager;
    00209     XMLCh*          fFragment;
    00210     XMLCh*          fHost;
    00211     XMLCh*          fPassword;
    00212     XMLCh*          fPath;
    00213     unsigned int    fPortNum;
    00214     Protocols       fProtocol;
    00215     XMLCh*          fQuery;
    00216     XMLCh*          fUser;
    00217     XMLCh*          fURLText;
    00218     bool            fHasInvalidChar;
    00219 };
    00220
    00221
    00222 // ---------------------------------------------------------------------------
    00223 //  XMLURL: Public operators
    00224 // ---------------------------------------------------------------------------
    00225 inline bool XMLURL::operator!=(const XMLURL& toCompare) const
    00226 {
    00227     return !operator==(toCompare);
    00228 }
    00229
    00230
    00231 // ---------------------------------------------------------------------------
    00232 //  XMLURL: Getter methods
    00233 // ---------------------------------------------------------------------------
    00234 inline const XMLCh* XMLURL::getFragment() const
    00235 {
    00236     return fFragment;
    00237 }
    00238
    00239 inline const XMLCh* XMLURL::getHost() const
    00240 {
    00241     return fHost;
    00242 }
    00243
    00244 inline const XMLCh* XMLURL::getPassword() const
    00245 {
    00246     return fPassword;
    00247 }
    00248
    00249 inline const XMLCh* XMLURL::getPath() const
    00250 {
    00251     return fPath;
    00252 }
    00253
    00254 inline XMLURL::Protocols XMLURL::getProtocol() const
    00255 {
    00256     return fProtocol;
    00257 }
    00258
    00259 inline const XMLCh* XMLURL::getQuery() const
    00260 {
    00261     return fQuery;
    00262 }
    00263
    00264 inline const XMLCh* XMLURL::getUser() const
    00265 {
    00266     return fUser;
    00267 }
    00268
    00269 inline const XMLCh* XMLURL::getURLText() const
    00270 {
    00271     //
    00272     //  Fault it in if not already. Since this is a const method and we
    00273     //  can't use mutable members due the compilers we have to support,
    00274     //  we have to cast off the constness.
    00275     //
    00276     if (!fURLText)
    00277         ((XMLURL*)this)->buildFullText();
    00278
    00279     return fURLText;
    00280 }
    00281
    00282 inline MemoryManager* XMLURL::getMemoryManager() const
    00283 {
    00284     return fMemoryManager;
    00285 }
    00286
    00287 MakeXMLException(MalformedURLException, )
    00288
    00289 XERCES_CPP_NAMESPACE_END
    00290
    00291
    00292 #endif

Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.