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

Home

Readme
Installation
Build

API Docs
Samples
Programming
Migration
FAQs

Releases
Feedback
Bug-Todo

Download
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-2000 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.7 2000/06/02 00:21:38 aruna1 Exp $

00059  */
00060 
00061 #if !defined(XMLURL_HPP)
00062 #define XMLURL_HPP
00063 
00064 #include <util/XercesDefs.hpp>
00065 #include <util/XMLException.hpp>
00066 
00067 class BinInputStream;
00068 
00069 MakeXMLException(MalformedURLException, )
00070 
00071 
00072 //
00073 //  This class supports file, http, and ftp style URLs. All others are
00074 //  rejected
00075 //
00076 class  XMLURL
00077 {
00078 public:
00079     // -----------------------------------------------------------------------
00080     //  Class types
00081     //
00082     //  And they must remain in this order because they are indexes into an
00083     //  array internally!
00084     // -----------------------------------------------------------------------
00085     enum Protocols
00086     {
00087         File
00088         , HTTP
00089         , FTP
00090 
00091         , Protocols_Count
00092         , Unknown
00093     };
00094 
00095 
00096     // -----------------------------------------------------------------------
00097     //  Public static methods
00098     // -----------------------------------------------------------------------
00099     Protocols lookupByName(const XMLCh* const protoName);
00100 
00101 
00102     // -----------------------------------------------------------------------
00103     //  Constructors and Destructor
00104     // -----------------------------------------------------------------------
00105     XMLURL();
00106     XMLURL
00107     (
00108         const   XMLCh* const    baseURL
00109         , const XMLCh* const    relativeURL
00110     );
00111     XMLURL
00112     (
00113         const   XMLCh* const    baseURL
00114         , const char* const     relativeURL
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     );
00130     XMLURL
00131     (
00132         const   char* const     urlText
00133     );
00134     XMLURL(const XMLURL& toCopy);
00135     virtual ~XMLURL();
00136 
00137 
00138     // -----------------------------------------------------------------------
00139     //  Operators
00140     // -----------------------------------------------------------------------
00141     XMLURL& operator=(const XMLURL& toAssign);
00142     bool operator==(const XMLURL& toCompare) const;
00143     bool operator!=(const XMLURL& toCompare) const;
00144 
00145 
00146     // -----------------------------------------------------------------------
00147     //  Getter methods
00148     // -----------------------------------------------------------------------
00149     const XMLCh* getFragment() const;
00150     const XMLCh* getHost() const;
00151     const XMLCh* getPassword() const;
00152     const XMLCh* getPath() const;
00153     unsigned int getPortNum() const;
00154     Protocols getProtocol() const;
00155     const XMLCh* getProtocolName() const;
00156     const XMLCh* getQuery() const;
00157     const XMLCh* getURLText() const;
00158     const XMLCh* getUser() const;
00159 
00160 
00161     // -----------------------------------------------------------------------
00162     //  Setter methods
00163     // -----------------------------------------------------------------------
00164     void setURL(const XMLCh* const urlText);
00165     void setURL
00166     (
00167         const   XMLCh* const    baseURL
00168         , const XMLCh* const    relativeURL
00169     );
00170     void setURL
00171     (
00172         const   XMLURL&         baseURL
00173         , const XMLCh* const    relativeURL
00174     );
00175 
00176 
00177     // -----------------------------------------------------------------------
00178     //  Miscellaneous methods
00179     // -----------------------------------------------------------------------
00180     bool isRelative() const;
00181     BinInputStream* makeNewStream() const;
00182     void makeRelativeTo(const XMLCh* const baseURLText);
00183     void makeRelativeTo(const XMLURL& baseURL);
00184 
00185 
00186 private:
00187     // -----------------------------------------------------------------------
00188     //  Private helper methods
00189     // -----------------------------------------------------------------------
00190     void buildFullText();
00191     void cleanup();
00192     bool conglomerateWithBase(const XMLURL& baseURL, bool useExceptions=true);
00193     void parse
00194     (
00195         const   XMLCh* const    urlText
00196     );
00197     void weavePaths(const XMLCh* const basePart);
00198 
00199 
00200     // -----------------------------------------------------------------------
00201     //  Data members
00202     //
00203     //  fFragment
00204     //      The fragment part of the URL, if any. If none, its a null.
00205     //
00206     //  fHost
00207     //      The host part of the URL that was parsed out. This one will often
00208     //      be null (or "localhost", which also means the current machine.)
00209     //
00210     //  fPassword
00211     //      The password found, if any. If none then its a null.
00212     //
00213     //  fPath
00214     //      The path part of the URL that was parsed out, if any. If none,
00215     //      then its a null.
00216     //
00217     //  fPortNum
00218     //      The port that was indicated in the URL. If no port was provided
00219     //      explicitly, then its left zero.
00220     //
00221     //  fProtocol
00222     //      Indicates the type of the URL's source. The text of the prefix
00223     //      can be gotten from this.
00224     //
00225     //  fQuery
00226     //      The query part of the URL, if any. If none, then its a null.
00227     //
00228     //  fUser
00229     //      The username found, if any. If none, then its a null.
00230     //
00231     //  fURLText
00232     //      This is a copy of the URL text, after it has been taken apart,
00233     //      made relative if needed, canonicalized, and then put back
00234     //      together. Its only created upon demand.
00235     // -----------------------------------------------------------------------
00236     XMLCh*          fFragment;
00237     XMLCh*          fHost;
00238     XMLCh*          fPassword;
00239     XMLCh*          fPath;
00240     unsigned int    fPortNum;
00241     Protocols       fProtocol;
00242     XMLCh*          fQuery;
00243     XMLCh*          fUser;
00244     XMLCh*          fURLText;
00245 };
00246 
00247 
00248 // ---------------------------------------------------------------------------
00249 //  XMLURL: Public operators
00250 // ---------------------------------------------------------------------------
00251 inline bool XMLURL::operator!=(const XMLURL& toCompare) const

00252 {
00253     return !operator==(toCompare);
00254 }
00255 
00256 
00257 // ---------------------------------------------------------------------------
00258 //  XMLURL: Getter methods
00259 // ---------------------------------------------------------------------------
00260 inline const XMLCh* XMLURL::getFragment() const

00261 {
00262     return fFragment;
00263 }
00264 
00265 inline const XMLCh* XMLURL::getHost() const

00266 {
00267     return fHost;
00268 }
00269 
00270 inline const XMLCh* XMLURL::getPassword() const

00271 {
00272     return fPassword;
00273 }
00274 
00275 inline const XMLCh* XMLURL::getPath() const

00276 {
00277     return fPath;
00278 }
00279 
00280 inline XMLURL::Protocols XMLURL::getProtocol() const

00281 {
00282     return fProtocol;
00283 }
00284 
00285 inline const XMLCh* XMLURL::getQuery() const

00286 {
00287     return fQuery;
00288 }
00289 
00290 inline const XMLCh* XMLURL::getUser() const

00291 {
00292     return fUser;
00293 }
00294 
00295 inline const XMLCh* XMLURL::getURLText() const

00296 {
00297     //
00298     //  Fault it in if not already. Since this is a const method and we
00299     //  can't use mutable members due the compilers we have to support,
00300     //  we have to cast off the constness.
00301     //
00302     if (!fURLText)
00303         ((XMLURL*)this)->buildFullText();
00304 
00305     return fURLText;
00306 }
00307 
00308 #endif


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