URL.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/common/URL.h
22 
23  \brief A helper class for URL encode/decode.
24 */
25 
26 #ifndef __TERRALIB_COMMON_INTERNAL_URL_H
27 #define __TERRALIB_COMMON_INTERNAL_URL_H
28 
29 // TerraLib
30 #include "Config.h"
31 
32 // STL
33 #include <cassert>
34 #include <string>
35 
36 // uripp - MIT
37 #include "URI/uri.h"
38 
39 namespace te
40 {
41  namespace common
42  {
43  /*!
44  \class URL
45 
46  \brief A class URL represents a Uniform Resource Locator,
47  a pointer to a "resource" on the World Wide Web. A resource
48  can be something as simple as a file or a directory, or it
49  can be a reference to a more complicated object, such as a
50  query to a database or to a search engine. This class is
51  based on the MIT code uripp http://uripp.sourceforge.net/ .
52 
53  \ingroup common
54  */
56  {
57  public:
58  typedef uri::query::iterator queryIterator; ///< query iterator type
59  typedef uri::query::const_iterator const_queryIterator; ///< query const iterator type
60  typedef uri::path::const_iterator const_pathIterator; ///< path const iterator type
61 
62  /** @name Initializer Methods
63  * Methods related to instantiation and destruction.
64  */
65  //@{
66 
67  /*! \brief Default constructor of a new URL. */
68  URL();
69 
70  /*!
71  \brief It initializes a new URL with the given valid string url.
72 
73  \param s The valid encoded string url.
74  */
75  URL(const std::string& s);
76 
77  /*! \brief Destructor */
78  ~URL();
79 
80  //@}
81 
82  /** @name Accessor methods
83  * Methods used to get or set properties.
84  */
85  //@{
86 
87  /*!
88  \brief It returns URL string.
89 
90  \return The protocol.
91  */
92  std::string getString();
93 
94  /*!
95  \brief It returns encoded URL string.
96 
97  \return The protocol.
98  */
99  std::string getEncodedString();
100 
101  /*!
102  \brief It sets the encoded URL string.
103 
104  \return The protocol.
105  */
106  void setEncodedString(const std::string&);
107 
108  /*!
109  \brief It returns the protocol.
110 
111  \return The protocol.
112  */
113  const std::string& getProtocol() const;
114 
115  /*!
116  \brief It sets the protocol.
117 
118  \param s The protocol
119  */
120  void setProtocol(const std::string& s);
121 
122  /*!
123  \brief It returns the host.
124 
125  \return The host.
126  */
127  const std::string& getHost() const;
128 
129  /*!
130  \brief It sets the host.
131 
132  \param s The host.
133  */
134  void setHost(const std::string& s);
135 
136  /*!
137  \brief It returns the host type.
138 
139  \return The host type.
140  \note it can be: null, DOMAIN_NAME, IP_ADDRESS or IPV6_ADDRESS
141  */
142  uri::authority::host_type_e getHostType() const;
143 
144  /*!
145  \brief It returns the host port.
146 
147  \return The host port.
148  */
149  unsigned short getHostPort() const;
150 
151  /*!
152  \brief It sets the host port.
153 
154  \param p The host port.
155  */
156  void setHostPort(unsigned short p);
157 
158  /*!
159  \brief It returns the login.
160 
161  \return The login.
162  */
163  std::string getLogin() const;
164 
165  /*!
166  \brief It sets the login.
167 
168  \param s The login.
169  */
170  void setLogin(const std::string& s);
171 
172  /*!
173  \brief It returns the password.
174 
175  \return The login.
176  */
177  std::string getPassword() const;
178 
179  /*!
180  \brief It sets the password.
181 
182  \param s The login.
183  */
184  void setPassword(const std::string& s);
185 
186  /*!
187  \brief It returns the path.
188 
189  \return The path string.
190  */
191  std::string getPathString() const;
192 
193  /*!
194  \brief It returns the encoded path.
195 
196  \return The encoded path string.
197  */
198  std::string getEncodedPathString() const;
199 
200  /*!
201  \brief It sets the encoded path.
202 
203  \param path The encoded path string.
204  */
205  void setEncodedPathString(const std::string& path);
206 
207  /*!
208  \brief It cleans the path.
209 
210  */
211  void clearPath();
212 
213  /*!
214  \brief It adds the path.
215 
216  \param p The path string to be added.
217  \note The input path string can not be encoded.
218  */
219  void addPath(const std::string& p);
220 
221  /*!
222  \brief It Checks if the path is absolute.
223 
224  \return True if the path is absolute, false otherwise.
225  */
226  bool isAbsolutePath() const;
227 
228  /*!
229  \brief It sets the absolute path propertie.
230 
231  \param v True for absolute path, false otherwise.
232  */
233  void setIsAbsolutePath(bool v);
234 
235  /*!
236  \brief It Checks if the path is directory.
237 
238  \return True if the path is directory, false otherwise.
239  */
240  bool isDirectoryPath() const;
241 
242  /*!
243  \brief It sets the directory path propertie.
244 
245  \param v True for directory path, false otherwise.
246  */
247  void setIsDirectoryPath(bool v);
248 
249  /*!
250  \brief It Checks if the path is empty.
251 
252  \return True if the path is empty, false otherwise.
253  */
254  bool isEmptyPath() const;
255 
256  /*!
257  \brief It returns the begin const path iterator.
258 
259  \return The begin const path iterator.
260  */
261  const_pathIterator beginPath() const;
262 
263  /*!
264  \brief It returns the end const path iterator.
265 
266  \return The end const path iterator.
267  */
268  const_pathIterator endPath() const;
269 
270  /*!
271  \brief It returns the query string.
272 
273  \return The query string.
274  */
275  std::string getQueryString();
276 
277  /*!
278  \brief It returns the encoded query.
279 
280  \return The encoded query string.
281  */
282  std::string getEncodedQueryString() const;
283 
284  /*!
285  \brief It sets the encoded query.
286 
287  \param query The encoded query string.
288  */
289  void setEncodedQueryString(const std::string& query);
290 
291  /*!
292  \brief It returns the query size.
293 
294  \return The query size.
295  */
296  int getQuerySize() const;
297 
298  /*!
299  \brief It cleans the vector of queries.
300 
301  */
302  void clearQuery();
303 
304  /*!
305  \brief It cleans the vector of queries.
306 
307  \param query The query string.
308  \note The input query string can not be encoded.
309  */
310  void addQuery(const std::string& key, const std::string& value);
311 
312  /*!
313  \brief It returns the begin query iterator.
314 
315  \return The begin query iterator.
316  */
317  queryIterator beginQuery();
318 
319  /*!
320  \brief It returns the end query iterator.
321 
322  \return The end query iterator.
323  */
324  queryIterator endQuery();
325 
326  /*!
327  \brief It returns the begin const query iterator.
328 
329  \return The begin const query iterator.
330  */
331  const_queryIterator beginQuery() const;
332 
333  /*!
334  \brief It returns the end const query iterator.
335 
336  \return The end const query iterator.
337  */
338  const_queryIterator endQuery()const;
339 
340  /*!
341  \brief it finds the key and return query iterator.
342  \param key The key to be found.
343 
344  \return The query iterator.
345  */
346  te::common::URL::queryIterator findQueryKey(const std::string& key);
347 
348  /*!
349  \brief it finds the key and return const query iterator.
350  \param key The key to be found.
351 
352  \return The const query iterator.
353  */
354  te::common::URL::const_queryIterator findQueryKey(const std::string& key) const;
355 
356  /*!
357  \brief It returns the fragment.
358 
359  \return The fragment string.
360  */
361  std::string getFragmentString() const;
362 
363  /*!
364  \brief It returns encoded the fragment.
365 
366  \return The encoded fragment string.
367  */
368  std::string getEncodedFragmentString() const;
369 
370  /*!
371  \brief It sets the fragment.
372 
373  \param f The fragment string.
374  */
375  void setFragmentString(const std::string& f);
376 
377  /*!
378  \brief It sets the encoded fragment.
379 
380  \param f The encoded fragment string.
381  */
382  void setEncodedFragmentString(const std::string& f);
383 
384  //@}
385 
386  private:
387 
389  };
390  } // end namespace common
391 } // end namespace te
392 
393 #endif // __TERRALIB_COMMON_INTERNAL_URL_H
394 
uri::query::iterator queryIterator
query iterator type
Definition: URL.h:58
Configuration flags for the TerraLib Common Runtime module.
Uniform Resource Identifier (URI) reference.
Definition: uri.h:110
segments_type::const_iterator const_iterator
segments const iterator type
Definition: path.h:54
A class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web...
Definition: URL.h:55
URI C++ Library.
#define TECOMMONEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:65
uri::uri m_uri
Definition: URL.h:388
host_type_e
Enumeration.
Definition: authority.h:52
uri::path::const_iterator const_pathIterator
path const iterator type
Definition: URL.h:60
uri::query::const_iterator const_queryIterator
query const iterator type
Definition: URL.h:59