| API Docs for SAX and DOM |

Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

# XMLURL.hpp

Go to the documentation of this file.

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

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