00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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;
00061 string authority;
00062 string path;
00063 string query;
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;
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