| 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.2 2002/02/20 18:17:02 tng Exp $
    00059  */
    00060
    00061 #if !defined(XMLURL_HPP)
    00062 #define XMLURL_HPP
    00063
    00064 #include <xercesc/util/XercesDefs.hpp>
    00065 #include <xercesc/util/XMLException.hpp>
    00066
    00067 class BinInputStream;
    00068
    00069 //
    00070 //  This class supports file, http, and ftp style URLs. All others are
    00071 //  rejected
    00072 //
    00073 class  XMLURL
    00074 {
    00075 public:
    00076     // -----------------------------------------------------------------------
    00077     //  Class types
    00078     //
    00079     //  And they must remain in this order because they are indexes into an
    00080     //  array internally!
    00081     // -----------------------------------------------------------------------
    00082     enum Protocols
    00083     {
    00084         File
    00085         , HTTP
    00086         , FTP
    00087
    00088         , Protocols_Count
    00089         , Unknown
    00090     };
    00091
    00092
    00093     // -----------------------------------------------------------------------
    00094     //  Public static methods
    00095     // -----------------------------------------------------------------------
    00096     Protocols lookupByName(const XMLCh* const protoName);
    00097
    00098
    00099     // -----------------------------------------------------------------------
    00100     //  Constructors and Destructor
    00101     // -----------------------------------------------------------------------
    00102     XMLURL();
    00103     XMLURL
    00104     (
    00105         const   XMLCh* const    baseURL
    00106         , const XMLCh* const    relativeURL
    00107     );
    00108     XMLURL
    00109     (
    00110         const   XMLCh* const    baseURL
    00111         , const char* const     relativeURL
    00112     );
    00113     XMLURL
    00114     (
    00115         const   XMLURL&         baseURL
    00116         , const XMLCh* const    relativeURL
    00117     );
    00118     XMLURL
    00119     (
    00120         const   XMLURL&         baseURL
    00121         , const char* const     relativeURL
    00122     );
    00123     XMLURL
    00124     (
    00125         const   XMLCh* const    urlText
    00126     );
    00127     XMLURL
    00128     (
    00129         const   char* const     urlText
    00130     );
    00131     XMLURL(const XMLURL& toCopy);
    00132     virtual ~XMLURL();
    00133
    00134
    00135     // -----------------------------------------------------------------------
    00136     //  Operators
    00137     // -----------------------------------------------------------------------
    00138     XMLURL& operator=(const XMLURL& toAssign);
    00139     bool operator==(const XMLURL& toCompare) const;
    00140     bool operator!=(const XMLURL& toCompare) const;
    00141
    00142
    00143     // -----------------------------------------------------------------------
    00144     //  Getter methods
    00145     // -----------------------------------------------------------------------
    00146     const XMLCh* getFragment() const;
    00147     const XMLCh* getHost() const;
    00148     const XMLCh* getPassword() const;
    00149     const XMLCh* getPath() const;
    00150     unsigned int getPortNum() const;
    00151     Protocols getProtocol() const;
    00152     const XMLCh* getProtocolName() const;
    00153     const XMLCh* getQuery() const;
    00154     const XMLCh* getURLText() const;
    00155     const XMLCh* getUser() const;
    00156
    00157
    00158     // -----------------------------------------------------------------------
    00159     //  Setter methods
    00160     // -----------------------------------------------------------------------
    00161     void setURL(const XMLCh* const urlText);
    00162     void setURL
    00163     (
    00164         const   XMLCh* const    baseURL
    00165         , const XMLCh* const    relativeURL
    00166     );
    00167     void setURL
    00168     (
    00169         const   XMLURL&         baseURL
    00170         , const XMLCh* const    relativeURL
    00171     );
    00172
    00173
    00174     // -----------------------------------------------------------------------
    00175     //  Miscellaneous methods
    00176     // -----------------------------------------------------------------------
    00177     bool isRelative() const;
    00178     BinInputStream* makeNewStream() const;
    00179     void makeRelativeTo(const XMLCh* const baseURLText);
    00180     void makeRelativeTo(const XMLURL& baseURL);
    00181
    00182
    00183 private:
    00184     // -----------------------------------------------------------------------
    00185     //  Private helper methods
    00186     // -----------------------------------------------------------------------
    00187     void buildFullText();
    00188     void cleanup();
    00189     bool conglomerateWithBase(const XMLURL& baseURL, bool useExceptions=true);
    00190     void parse
    00191     (
    00192         const   XMLCh* const    urlText
    00193     );
    00194     void weavePaths(const XMLCh* const basePart);
    00195
    00196
    00197     // -----------------------------------------------------------------------
    00198     //  Data members
    00199     //
    00200     //  fFragment
    00201     //      The fragment part of the URL, if any. If none, its a null.
    00202     //
    00203     //  fHost
    00204     //      The host part of the URL that was parsed out. This one will often
    00205     //      be null (or "localhost", which also means the current machine.)
    00206     //
    00207     //  fPassword
    00208     //      The password found, if any. If none then its a null.
    00209     //
    00210     //  fPath
    00211     //      The path part of the URL that was parsed out, if any. If none,
    00212     //      then its a null.
    00213     //
    00214     //  fPortNum
    00215     //      The port that was indicated in the URL. If no port was provided
    00216     //      explicitly, then its left zero.
    00217     //
    00218     //  fProtocol
    00219     //      Indicates the type of the URL's source. The text of the prefix
    00220     //      can be gotten from this.
    00221     //
    00222     //  fQuery
    00223     //      The query part of the URL, if any. If none, then its a null.
    00224     //
    00225     //  fUser
    00226     //      The username found, if any. If none, then its a null.
    00227     //
    00228     //  fURLText
    00229     //      This is a copy of the URL text, after it has been taken apart,
    00230     //      made relative if needed, canonicalized, and then put back
    00231     //      together. Its only created upon demand.
    00232     // -----------------------------------------------------------------------
    00233     XMLCh*          fFragment;
    00234     XMLCh*          fHost;
    00235     XMLCh*          fPassword;
    00236     XMLCh*          fPath;
    00237     unsigned int    fPortNum;
    00238     Protocols       fProtocol;
    00239     XMLCh*          fQuery;
    00240     XMLCh*          fUser;
    00241     XMLCh*          fURLText;
    00242 };
    00243
    00244
    00245 // ---------------------------------------------------------------------------
    00246 //  XMLURL: Public operators
    00247 // ---------------------------------------------------------------------------
    00248 inline bool XMLURL::operator!=(const XMLURL& toCompare) const
    00249 {
    00250     return !operator==(toCompare);
    00251 }
    00252
    00253
    00254 // ---------------------------------------------------------------------------
    00255 //  XMLURL: Getter methods
    00256 // ---------------------------------------------------------------------------
    00257 inline const XMLCh* XMLURL::getFragment() const
    00258 {
    00259     return fFragment;
    00260 }
    00261
    00262 inline const XMLCh* XMLURL::getHost() const
    00263 {
    00264     return fHost;
    00265 }
    00266
    00267 inline const XMLCh* XMLURL::getPassword() const
    00268 {
    00269     return fPassword;
    00270 }
    00271
    00272 inline const XMLCh* XMLURL::getPath() const
    00273 {
    00274     return fPath;
    00275 }
    00276
    00277 inline XMLURL::Protocols XMLURL::getProtocol() const
    00278 {
    00279     return fProtocol;
    00280 }
    00281
    00282 inline const XMLCh* XMLURL::getQuery() const
    00283 {
    00284     return fQuery;
    00285 }
    00286
    00287 inline const XMLCh* XMLURL::getUser() const
    00288 {
    00289     return fUser;
    00290 }
    00291
    00292 inline const XMLCh* XMLURL::getURLText() const
    00293 {
    00294     //
    00295     //  Fault it in if not already. Since this is a const method and we
    00296     //  can't use mutable members due the compilers we have to support,
    00297     //  we have to cast off the constness.
    00298     //
    00299     if (!fURLText)
    00300         ((XMLURL*)this)->buildFullText();
    00301
    00302     return fURLText;
    00303 }
    00304
    00305 MakeXMLException(MalformedURLException, )
    00306
    00307
    00308 #endif

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