This is an old revision of the document!
Warning: Declaration of syntax_plugin_iframe::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/html/terralib5/wiki/lib/plugins/iframe/syntax.php on line 18
Warning: Declaration of syntax_plugin_iframe::render($mode, &$R, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/html/terralib5/wiki/lib/plugins/iframe/syntax.php on line 18
Warning: Declaration of syntax_plugin_externallink::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /var/www/html/terralib5/wiki/lib/plugins/externallink/syntax.php on line 107
Warning: Declaration of syntax_plugin_externallink::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /var/www/html/terralib5/wiki/lib/plugins/externallink/syntax.php on line 107
Table of Contents
TerraLib.Core: URI
A classe te::core::URI fornece o suporte para manipulação de URIs (identificador uniforme de recurso) que é uma string utilizada para identificar ou denominar um recurso na Internet.
API
C++
A API para manipulação de URIs na TerraLib é definida pela classe URI
, mostrada abaixo:
namespace te { namespace core { /*! \class URI \brief A class for representing an Uniform Resource Identifier (URI). */ class TECOREEXPORT URI { public: /*! \brief Default constructor. */ URI(); /*! \brief A constructor from a string. This constructor check the URI enconding, then parse it and validate. \param uri A string with the URI to be parsed. \exception URIException when the given URI isn't valid. */ explicit URI(const std::string& uri); /*! \brief Copy constructor. */ URI(const URI& other); /*! Default destructor. */ ~URI() = default; /*! \brief Assingment operator. */ URI& operator=(const URI& other); /*! \brief Retrieving the full URI \return Returns the complete URI. */ const std::string& uri() const; /*! \brief Retrieving the scheme \return Returns the URI scheme. */ std::string scheme() const; /*! \brief Retrieving the user information \return Returns the URI user information. */ std::string user() const; /*! \brief Retrieving the password information \return Returns the URI password information. */ std::string password() const; /*! \brief Retrieving the host \return Returns the URI host. */ std::string host() const; /*! \brief Retrieving the port \return Returns the URI port. */ std::string port() const; /*! \brief Retrieving the path \return Returns the URI path. */ std::string path() const; /*! \brief Retrieving the query \return Returns the URI query. */ std::string query() const; /*! \brief Retrieving the fragment \return Returns the URI fragment. */ std::string fragment() const; /*! \brief Return if the given URI is valid or not. \return Returns true if the given URI is valid. */ bool isValid() const; private: /*! \brief Swap operation. */ void swap(URI& other); /*! \brief Parse the URI stored in uri_ member. It uses regex to validate and parse the given URI. After this, if the given URI is valid, the match_ member will have the references to all parts of the URI. The regex split the URI by using named groups in regex, "(?<name>...)", so knowing the group name, you can require the corresponding group, from match_. \exception URIException when the given URI isn't valid. */ void parse(); /*! \brief Check if the uri_ contains any invalid character and parse it to his hexadecimal value */ void encode(); std::string hexToLetter(int i); private: std::string uri_; boost::match_results< std::string::const_iterator > match_; bool isValid_; }; } // end namespace core } // end namespace te
Exemplos
A seguir alguns exemplos para ilustrar o uso da classe URI:
// TerraLib #include <terralib/core/uri/URI.h> // STL #include <cassert> #include <cstdlib> #include <iostream> int main(int argc, char *argv[]) { { te::core::URI uri("http://www.dpi.inpe.br/terralib5/wiki/doku.php?id=wiki:documentation:devguide#modules"); if(!uri.isValid()) { std::cout << "Uri isn't valid!" << std::endl; return EXIT_FAILURE; } assert(uri.scheme() == "http"); assert(uri.user() == ""); assert(uri.password() == ""); assert(uri.host() == "www.dpi.inpe.br"); assert(uri.port() == ""); assert(uri.path() == "/terralib5/wiki/doku.php"); assert(uri.query() == "id=wiki:documentation:devguide"); assert(uri.fragment() == "modules"); } { std::string address("xmpp:example-node@example.com?message;subject=Hello%20World"); te::core::URI uri(address); if(!uri.isValid()) { std::cout << "Uri isn't valid!" << std::endl; return EXIT_FAILURE; } assert(uri.scheme() == "xmpp"); assert(uri.user() == ""); assert(uri.password() == ""); assert(uri.host() == ""); assert(uri.port() == ""); assert(uri.path() == "example-node@example.com"); assert(uri.query() == "message;subject=Hello%20World"); assert(uri.fragment() == ""); } { te::core::URI uri("ftp://user:password@ftp.dpi.inpe.br:21/path/"); if(!uri.isValid()) { std::cout << "Uri isn't valid!" << std::endl; return EXIT_FAILURE; } assert(uri.scheme() == "ftp"); assert(uri.user() == "user"); assert(uri.password() == "password"); assert(uri.host() == "ftp.dpi.inpe.br"); assert(uri.port() == "21"); assert(uri.path() == "/path/"); assert(uri.query() == ""); assert(uri.fragment() == ""); } { te::core::URI uri("InvalidURI"); if(uri.isValid()) { std::cout << "Uri isn't valid!" << std::endl; return EXIT_FAILURE; } } return EXIT_SUCCESS; }