uri.H

00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
00018  */
00019 
00020 #ifndef ARCHON_UTILITIES_URI_H
00021 #define ARCHON_UTILITIES_URI_H
00022 
00023 #include <string>
00024 #include <vector>
00025 #include <utility>
00026 #include <iostream>
00027 
00028 #include <archon/util/exception.H>
00029 #include <archon/util/ref.H>
00030 #include <archon/util/text.H>
00031 #include <archon/util/stream.H>
00032 #include <archon/util/mutex.H>
00033 
00034 namespace Archon
00035 {
00036   namespace Utilities
00037   {
00038     using namespace std;
00039 
00040 
00047     struct Uri
00048     {
00049       struct SyntaxException: virtual Exception
00050       {
00051         string val;
00052         int indexFrom;
00053         int indexTo;
00054         SyntaxException(string l, string m, string v, int f, int t):
00055           Exception(l, m), val(v), indexFrom(f), indexTo(t) {}
00056         virtual ~SyntaxException() throw() {}
00057       };
00058 
00059     private:
00060       string scheme;    // eg. 'http:'
00061       string authority; // eg. '//www.ietf.org'
00062       string path;      // eg. '/rfc/rfc2396.txt'
00063       string query;     // eg. '?foo=bar'
00064 
00065       void canonicalizePath();
00066       void resolveRelative(const Uri &);
00067 
00068     public:
00072       Uri();
00073 
00084       Uri(const string &uri, const Uri &baseUri = Uri());
00085 
00086       ~Uri() {}
00087 
00088       bool isFileScheme() const;
00089 
00094       string getScheme() const
00095       {
00096         return scheme;
00097       }
00098 
00103       string getAuthority() const
00104       {
00105         return authority;
00106       }
00107 
00112       string getPath() const
00113       {
00114         return path;
00115       }
00116 
00121       string getQuery() const
00122       {
00123         return query;
00124       }
00125 
00126       string getFile() const;
00127 
00137       static string encode(const string &s, bool plusForSpace);
00138 
00148       static string decode(const string &s, bool plusForSpace);
00149 
00154       static string explain(const SyntaxException &);
00155 
00156       string toString() const;
00157     };
00158 
00159     ostream &operator<<(ostream &, const Uri &);
00160 
00161 
00169     class UriReference
00170     {
00171       Uri uri;
00172       string fragmentIdentifier; // eg. '#foobar'
00173 
00174     public:
00178       UriReference(): uri(Uri()) {}
00179 
00190       UriReference(const string &uriReference,
00191                    const UriReference &baseReference = UriReference());
00192 
00193       Uri getUri() const { return uri; }
00194 
00199       string getFragmentIdentifier() const { return fragmentIdentifier; }
00200 
00201       string toString() const;
00202     };
00203 
00204     ostream &operator<<(ostream &, const UriReference &);
00205   }
00206 }
00207 
00208 #endif // ARCHON_UTILITIES_URI_H

Generated on Sun Jul 30 22:55:46 2006 for Archon by  doxygen 1.4.4