http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Release Info

Installation
Download
Build

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

CVS Repository
Mail Archive

API Docs for SAX and DOM
 

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

XMLURL.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
00005  * reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  * 3. The end-user documentation included with the redistribution,
00020  *    if any, must include the following acknowledgment:
00021  *       "This product includes software developed by the
00022  *        Apache Software Foundation (http://www.apache.org/)."
00023  *    Alternately, this acknowledgment may appear in the software itself,
00024  *    if and wherever such third-party acknowledgments normally appear.
00025  *
00026  * 4. The names "Xerces" and "Apache Software Foundation" must
00027  *    not be used to endorse or promote products derived from this
00028  *    software without prior written permission. For written
00029  *    permission, please contact apache\@apache.org.
00030  *
00031  * 5. Products derived from this software may not be called "Apache",
00032  *    nor may "Apache" appear in their name, without prior written
00033  *    permission of the Apache Software Foundation.
00034  *
00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  * ====================================================================
00048  *
00049  * This software consists of voluntary contributions made by many
00050  * individuals on behalf of the Apache Software Foundation, and was
00051  * originally based on software copyright (c) 1999, International
00052  * Business Machines, Inc., http://www.ibm.com .  For more information
00053  * on the Apache Software Foundation, please see
00054  * <http://www.apache.org/>.
00055  */
00056 
00057 /*
00058  * $Id: XMLURL.hpp,v 1.12 2004/01/12 16:15:57 cargilld Exp $
00059  */
00060 
00061 #if !defined(XMLURL_HPP)
00062 #define XMLURL_HPP
00063 
00064 #include <xercesc/util/PlatformUtils.hpp>
00065 
00066 XERCES_CPP_NAMESPACE_BEGIN
00067 
00068 class BinInputStream;
00069 
00070 //
00071 //  This class supports file, http, and ftp style URLs. All others are
00072 //  rejected
00073 //
00074 class  XMLURL : public XMemory
00075 {
00076 public:
00077     // -----------------------------------------------------------------------
00078     //  Class types
00079     //
00080     //  And they must remain in this order because they are indexes into an
00081     //  array internally!
00082     // -----------------------------------------------------------------------
00083     enum Protocols
00084     {
00085         File
00086         , HTTP
00087         , FTP
00088 
00089         , Protocols_Count
00090         , Unknown
00091     };
00092 
00093 
00094     // -----------------------------------------------------------------------
00095     //  Public static methods
00096     // -----------------------------------------------------------------------
00097     static Protocols lookupByName(const XMLCh* const protoName);
00098     static bool parse(const XMLCh* const urlText, XMLURL& xmlURL);
00099 
00100     // -----------------------------------------------------------------------
00101     //  Constructors and Destructor
00102     // -----------------------------------------------------------------------
00103     XMLURL(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00104     XMLURL
00105     (
00106         const   XMLCh* const    baseURL
00107         , const XMLCh* const    relativeURL
00108         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
00109     );
00110     XMLURL
00111     (
00112         const   XMLCh* const    baseURL
00113         , const char* const     relativeURL
00114         , MemoryManager* const manager  = XMLPlatformUtils::fgMemoryManager
00115     );
00116     XMLURL
00117     (
00118         const   XMLURL&         baseURL
00119         , const XMLCh* const    relativeURL
00120     );
00121     XMLURL
00122     (
00123         const   XMLURL&         baseURL
00124         , const char* const     relativeURL
00125     );
00126     XMLURL
00127     (
00128         const   XMLCh* const    urlText
00129         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00130     );
00131     XMLURL
00132     (
00133         const   char* const     urlText
00134         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00135     );
00136     XMLURL(const XMLURL& toCopy);
00137     virtual ~XMLURL();
00138 
00139 
00140     // -----------------------------------------------------------------------
00141     //  Operators
00142     // -----------------------------------------------------------------------
00143     XMLURL& operator=(const XMLURL& toAssign);
00144     bool operator==(const XMLURL& toCompare) const;
00145     bool operator!=(const XMLURL& toCompare) const;
00146 
00147 
00148     // -----------------------------------------------------------------------
00149     //  Getter methods
00150     // -----------------------------------------------------------------------
00151     const XMLCh* getFragment() const;
00152     const XMLCh* getHost() const;
00153     const XMLCh* getPassword() const;
00154     const XMLCh* getPath() const;
00155     unsigned int getPortNum() const;
00156     Protocols getProtocol() const;
00157     const XMLCh* getProtocolName() const;
00158     const XMLCh* getQuery() const;
00159     const XMLCh* getURLText() const;
00160     const XMLCh* getUser() const;
00161     MemoryManager* getMemoryManager() const;
00162 
00163 
00164     // -----------------------------------------------------------------------
00165     //  Setter methods
00166     // -----------------------------------------------------------------------
00167     void setURL(const XMLCh* const urlText);
00168     void setURL
00169     (
00170         const   XMLCh* const    baseURL
00171         , const XMLCh* const    relativeURL
00172     );
00173     void setURL
00174     (
00175         const   XMLURL&         baseURL
00176         , const XMLCh* const    relativeURL
00177     );
00178     // a version of setURL that doesn't throw malformed url exceptions
00179     bool setURL(
00180         const XMLCh* const    baseURL
00181         , const XMLCh* const    relativeURL
00182         , XMLURL& xmlURL);
00183     // -----------------------------------------------------------------------
00184     //  Miscellaneous methods
00185     // -----------------------------------------------------------------------
00186     bool isRelative() const;
00187     bool hasInvalidChar() const;
00188     BinInputStream* makeNewStream() const;
00189     void makeRelativeTo(const XMLCh* const baseURLText);
00190     void makeRelativeTo(const XMLURL& baseURL);
00191 
00192 
00193 private:
00194     // -----------------------------------------------------------------------
00195     //  Private helper methods
00196     // -----------------------------------------------------------------------
00197     void buildFullText();
00198     void cleanup();
00199     bool conglomerateWithBase(const XMLURL& baseURL, bool useExceptions=true);
00200     void parse
00201     (
00202         const   XMLCh* const    urlText
00203     );
00204 
00205 
00206     // -----------------------------------------------------------------------
00207     //  Data members
00208     //
00209     //  fFragment
00210     //      The fragment part of the URL, if any. If none, its a null.
00211     //
00212     //  fHost
00213     //      The host part of the URL that was parsed out. This one will often
00214     //      be null (or "localhost", which also means the current machine.)
00215     //
00216     //  fPassword
00217     //      The password found, if any. If none then its a null.
00218     //
00219     //  fPath
00220     //      The path part of the URL that was parsed out, if any. If none,
00221     //      then its a null.
00222     //
00223     //  fPortNum
00224     //      The port that was indicated in the URL. If no port was provided
00225     //      explicitly, then its left zero.
00226     //
00227     //  fProtocol
00228     //      Indicates the type of the URL's source. The text of the prefix
00229     //      can be gotten from this.
00230     //
00231     //  fQuery
00232     //      The query part of the URL, if any. If none, then its a null.
00233     //
00234     //  fUser
00235     //      The username found, if any. If none, then its a null.
00236     //
00237     //  fURLText
00238     //      This is a copy of the URL text, after it has been taken apart,
00239     //      made relative if needed, canonicalized, and then put back
00240     //      together. Its only created upon demand.
00241     //
00242     //  fHasInvalidChar
00243     //      This indicates if the URL Text contains invalid characters as per
00244     //      RFC 2396 standard.
00245     // -----------------------------------------------------------------------
00246     MemoryManager*  fMemoryManager;
00247     XMLCh*          fFragment;
00248     XMLCh*          fHost;
00249     XMLCh*          fPassword;
00250     XMLCh*          fPath;
00251     unsigned int    fPortNum;
00252     Protocols       fProtocol;
00253     XMLCh*          fQuery;
00254     XMLCh*          fUser;
00255     XMLCh*          fURLText;
00256     bool            fHasInvalidChar;
00257 };
00258 
00259 
00260 // ---------------------------------------------------------------------------
00261 //  XMLURL: Public operators
00262 // ---------------------------------------------------------------------------
00263 inline bool XMLURL::operator!=(const XMLURL& toCompare) const
00264 {
00265     return !operator==(toCompare);
00266 }
00267 
00268 
00269 // ---------------------------------------------------------------------------
00270 //  XMLURL: Getter methods
00271 // ---------------------------------------------------------------------------
00272 inline const XMLCh* XMLURL::getFragment() const
00273 {
00274     return fFragment;
00275 }
00276 
00277 inline const XMLCh* XMLURL::getHost() const
00278 {
00279     return fHost;
00280 }
00281 
00282 inline const XMLCh* XMLURL::getPassword() const
00283 {
00284     return fPassword;
00285 }
00286 
00287 inline const XMLCh* XMLURL::getPath() const
00288 {
00289     return fPath;
00290 }
00291 
00292 inline XMLURL::Protocols XMLURL::getProtocol() const
00293 {
00294     return fProtocol;
00295 }
00296 
00297 inline const XMLCh* XMLURL::getQuery() const
00298 {
00299     return fQuery;
00300 }
00301 
00302 inline const XMLCh* XMLURL::getUser() const
00303 {
00304     return fUser;
00305 }
00306 
00307 inline const XMLCh* XMLURL::getURLText() const
00308 {
00309     //
00310     //  Fault it in if not already. Since this is a const method and we
00311     //  can't use mutable members due the compilers we have to support,
00312     //  we have to cast off the constness.
00313     //
00314     if (!fURLText)
00315         ((XMLURL*)this)->buildFullText();
00316 
00317     return fURLText;
00318 }
00319 
00320 inline MemoryManager* XMLURL::getMemoryManager() const
00321 {
00322     return fMemoryManager;
00323 }
00324 
00325 MakeXMLException(MalformedURLException, )
00326 
00327 XERCES_CPP_NAMESPACE_END
00328 
00329 
00330 #endif


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