Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:16

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XMLURL_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XMLURL_HPP
0024 
0025 #include <xercesc/util/PlatformUtils.hpp>
0026 
0027 XERCES_CPP_NAMESPACE_BEGIN
0028 
0029 class BinInputStream;
0030 
0031 //
0032 //  This class supports file, http, and ftp style URLs. All others are
0033 //  rejected
0034 //
0035 class XMLUTIL_EXPORT XMLURL : public XMemory
0036 {
0037 public:
0038     // -----------------------------------------------------------------------
0039     //  Class types
0040     //
0041     //  And they must remain in this order because they are indexes into an
0042     //  array internally!
0043     // -----------------------------------------------------------------------
0044     enum Protocols
0045     {
0046         File
0047         , HTTP
0048         , FTP
0049         , HTTPS
0050 
0051         , Protocols_Count
0052         , Unknown
0053     };
0054 
0055 
0056     // -----------------------------------------------------------------------
0057     //  Public static methods
0058     // -----------------------------------------------------------------------
0059     static Protocols lookupByName(const XMLCh* const protoName);
0060     static bool parse(const XMLCh* const urlText, XMLURL& xmlURL);
0061 
0062     // -----------------------------------------------------------------------
0063     //  Constructors and Destructor
0064     // -----------------------------------------------------------------------
0065     XMLURL(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0066     XMLURL
0067     (
0068         const   XMLCh* const    baseURL
0069         , const XMLCh* const    relativeURL
0070         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
0071     );
0072     XMLURL
0073     (
0074         const   XMLCh* const    baseURL
0075         , const char* const     relativeURL
0076         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
0077     );
0078     XMLURL
0079     (
0080         const   XMLURL&         baseURL
0081         , const XMLCh* const    relativeURL
0082     );
0083     XMLURL
0084     (
0085         const   XMLURL&         baseURL
0086         , const char* const     relativeURL
0087     );
0088     XMLURL
0089     (
0090         const   XMLCh* const    urlText
0091         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0092     );
0093     XMLURL
0094     (
0095         const   char* const     urlText
0096         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0097     );
0098     XMLURL(const XMLURL& toCopy);
0099     virtual ~XMLURL();
0100 
0101 
0102     // -----------------------------------------------------------------------
0103     //  Operators
0104     // -----------------------------------------------------------------------
0105     XMLURL& operator=(const XMLURL& toAssign);
0106     bool operator==(const XMLURL& toCompare) const;
0107     bool operator!=(const XMLURL& toCompare) const;
0108 
0109 
0110     // -----------------------------------------------------------------------
0111     //  Getter methods
0112     // -----------------------------------------------------------------------
0113     const XMLCh* getFragment() const;
0114     const XMLCh* getHost() const;
0115     const XMLCh* getPassword() const;
0116     const XMLCh* getPath() const;
0117     unsigned int getPortNum() const;
0118     Protocols getProtocol() const;
0119     const XMLCh* getProtocolName() const;
0120     const XMLCh* getQuery() const;
0121     const XMLCh* getURLText() const;
0122     const XMLCh* getUser() const;
0123     MemoryManager* getMemoryManager() const;
0124 
0125 
0126     // -----------------------------------------------------------------------
0127     //  Setter methods
0128     // -----------------------------------------------------------------------
0129     void setURL(const XMLCh* const urlText);
0130     void setURL
0131     (
0132         const   XMLCh* const    baseURL
0133         , const XMLCh* const    relativeURL
0134     );
0135     void setURL
0136     (
0137         const   XMLURL&         baseURL
0138         , const XMLCh* const    relativeURL
0139     );
0140     // a version of setURL that doesn't throw malformed url exceptions
0141     bool setURL(
0142         const XMLCh* const    baseURL
0143         , const XMLCh* const    relativeURL
0144         , XMLURL& xmlURL);
0145     // -----------------------------------------------------------------------
0146     //  Miscellaneous methods
0147     // -----------------------------------------------------------------------
0148     bool isRelative() const;
0149     bool hasInvalidChar() const;
0150     BinInputStream* makeNewStream() const;
0151     void makeRelativeTo(const XMLCh* const baseURLText);
0152     void makeRelativeTo(const XMLURL& baseURL);
0153 
0154 
0155 private:
0156     // -----------------------------------------------------------------------
0157     //  Private helper methods
0158     // -----------------------------------------------------------------------
0159     void buildFullText();
0160     void cleanUp();
0161     bool conglomerateWithBase(const XMLURL& baseURL, bool useExceptions=true);
0162     void parse
0163     (
0164         const   XMLCh* const    urlText
0165     );
0166 
0167 
0168     // -----------------------------------------------------------------------
0169     //  Data members
0170     //
0171     //  fFragment
0172     //      The fragment part of the URL, if any. If none, its a null.
0173     //
0174     //  fHost
0175     //      The host part of the URL that was parsed out. This one will often
0176     //      be null (or "localhost", which also means the current machine.)
0177     //
0178     //  fPassword
0179     //      The password found, if any. If none then its a null.
0180     //
0181     //  fPath
0182     //      The path part of the URL that was parsed out, if any. If none,
0183     //      then its a null.
0184     //
0185     //  fPortNum
0186     //      The port that was indicated in the URL. If no port was provided
0187     //      explicitly, then its left zero.
0188     //
0189     //  fProtocol
0190     //      Indicates the type of the URL's source. The text of the prefix
0191     //      can be gotten from this.
0192     //
0193     //  fQuery
0194     //      The query part of the URL, if any. If none, then its a null.
0195     //
0196     //  fUser
0197     //      The username found, if any. If none, then its a null.
0198     //
0199     //  fURLText
0200     //      This is a copy of the URL text, after it has been taken apart,
0201     //      made relative if needed, canonicalized, and then put back
0202     //      together. Its only created upon demand.
0203     //
0204     //  fHasInvalidChar
0205     //      This indicates if the URL Text contains invalid characters as per
0206     //      RFC 2396 standard.
0207     // -----------------------------------------------------------------------
0208     MemoryManager*  fMemoryManager;
0209     XMLCh*          fFragment;
0210     XMLCh*          fHost;
0211     XMLCh*          fPassword;
0212     XMLCh*          fPath;
0213     unsigned int    fPortNum;
0214     Protocols       fProtocol;
0215     XMLCh*          fQuery;
0216     XMLCh*          fUser;
0217     XMLCh*          fURLText;
0218     bool            fHasInvalidChar;
0219 };
0220 
0221 
0222 // ---------------------------------------------------------------------------
0223 //  XMLURL: Public operators
0224 // ---------------------------------------------------------------------------
0225 inline bool XMLURL::operator!=(const XMLURL& toCompare) const
0226 {
0227     return !operator==(toCompare);
0228 }
0229 
0230 
0231 // ---------------------------------------------------------------------------
0232 //  XMLURL: Getter methods
0233 // ---------------------------------------------------------------------------
0234 inline const XMLCh* XMLURL::getFragment() const
0235 {
0236     return fFragment;
0237 }
0238 
0239 inline const XMLCh* XMLURL::getHost() const
0240 {
0241     return fHost;
0242 }
0243 
0244 inline const XMLCh* XMLURL::getPassword() const
0245 {
0246     return fPassword;
0247 }
0248 
0249 inline const XMLCh* XMLURL::getPath() const
0250 {
0251     return fPath;
0252 }
0253 
0254 inline XMLURL::Protocols XMLURL::getProtocol() const
0255 {
0256     return fProtocol;
0257 }
0258 
0259 inline const XMLCh* XMLURL::getQuery() const
0260 {
0261     return fQuery;
0262 }
0263 
0264 inline const XMLCh* XMLURL::getUser() const
0265 {
0266     return fUser;
0267 }
0268 
0269 inline const XMLCh* XMLURL::getURLText() const
0270 {
0271     //
0272     //  Fault it in if not already. Since this is a const method and we
0273     //  can't use mutable members due the compilers we have to support,
0274     //  we have to cast off the constness.
0275     //
0276     if (!fURLText)
0277         ((XMLURL*)this)->buildFullText();
0278 
0279     return fURLText;
0280 }
0281 
0282 inline MemoryManager* XMLURL::getMemoryManager() const
0283 {
0284     return fMemoryManager;
0285 }
0286 
0287 MakeXMLException(MalformedURLException, XMLUTIL_EXPORT)
0288 
0289 XERCES_CPP_NAMESPACE_END
0290 
0291 
0292 #endif