activemq-cpp-3.4.0

src/main/decaf/net/URI.h

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef _DECAF_NET_URI_H_
00019 #define _DECAF_NET_URI_H_
00020 
00021 #include <decaf/util/Config.h>
00022 #include <decaf/lang/Comparable.h>
00023 #include <decaf/lang/exceptions/IllegalArgumentException.h>
00024 #include <decaf/net/URISyntaxException.h>
00025 #include <decaf/net/MalformedURLException.h>
00026 #include <decaf/net/URL.h>
00027 #include <decaf/internal/net/URIType.h>
00028 #include <string>
00029 
00030 namespace decaf{
00031 namespace net{
00032 
00036     class DECAF_API URI : public lang::Comparable<URI> {
00037     private:
00038 
00039         // The structure that holds the parsed URI data.
00040         decaf::internal::net::URIType uri;
00041 
00042         // The original string entered from URI( string ), empty if not set.
00043         mutable std::string uriString;
00044 
00045         static const std::string unreserved;
00046         static const std::string punct;
00047         static const std::string reserved;
00048         static const std::string someLegal;
00049         static const std::string allLegal;
00050 
00051     public:
00052 
00056         URI();
00057 
00065         URI( const URI& uri );
00066 
00074         URI( const std::string& uri );
00075 
00085         URI( const std::string& scheme, const std::string& ssp, const std::string& fragment );
00086 
00100         URI( const std::string& scheme, const std::string& userInfo,
00101              const std::string& host, int port,
00102              const std::string& path, const std::string& query,
00103              const std::string& fragment );
00104 
00114         URI( const std::string& scheme, const std::string& host,
00115              const std::string& path, const std::string& fragment );
00116 
00127         URI( const std::string& scheme, const std::string& authority,
00128              const std::string& path, const std::string& query,
00129              const std::string& fragment );
00130 
00131         virtual ~URI() {}
00132 
00140         virtual int compareTo( const URI& value ) const;
00141 
00145         virtual bool equals( const URI& value ) const;
00146 
00152         virtual bool operator==( const URI& value ) const;
00153 
00160         virtual bool operator<( const URI& value ) const;
00161 
00165         std::string getAuthority() const;
00166 
00170         std::string getFragment() const;
00171 
00175         std::string getHost() const;
00176 
00180         std::string getPath() const;
00181 
00185         int getPort() const;
00186 
00190         std::string getQuery() const;
00191 
00195         std::string getScheme() const;
00196 
00200         std::string getUserInfo() const;
00201 
00212         std::string getRawAuthority() const;
00213 
00221         std::string getRawFragment() const;
00222 
00231         std::string getRawPath() const;
00232 
00238         std::string getRawQuery() const;
00239 
00246         std::string getRawSchemeSpecificPart() const;
00247 
00255         std::string getSchemeSpecificPart() const;
00256 
00263         std::string getRawUserInfo() const;
00264 
00270         bool isAbsolute() const;
00271 
00279         bool isOpaque() const;
00280 
00305         URI normalize() const;
00306 
00324         URI parseServerAuthority() const;
00325 
00342         URI relativize( const URI& uri ) const;
00343 
00354         URI resolve( const std::string& str ) const;
00355 
00392         URI resolve( const URI& uri ) const;
00393 
00405         std::string toString() const;
00406 
00418         URL toURL() const;
00419 
00420     public:   // Static Methods
00421 
00432         static URI create( const std::string uri );
00433 
00434     private:
00435 
00444         void parseURI( const std::string& uri, bool forceServer );
00445 
00446         /*
00447          * Quote illegal chars for each component, but not the others
00448          *
00449          * @param component the component to be converted
00450          * @param legalset the legal character set allowed in the component strng
00451          * @return the converted string
00452          */
00453         std::string quoteComponent( const std::string& component,
00454                                     const std::string& legalset );
00455 
00456         /*
00457          * Encode Unicode chars that are not part of US-ASCII char set into the
00458          * escaped form
00459          *
00460          * i.e. The Euro currency symbol is encoded as "%E2%82%AC".
00461          *
00462          * @param src the string to be encoded
00463          * @return the converted string
00464          */
00465         std::string encodeOthers( const std::string& src ) const;
00466 
00473         std::string decode( const std::string& src ) const;
00474 
00481         bool equalsHexCaseInsensitive( const std::string& first,
00482                                        const std::string& second ) const;
00483 
00484         /*
00485          * Takes a string that may contain hex sequences like %F1 or %2b and
00486          * converts the hex values following the '%' to lowercase.
00487          *
00488          * @param s - String to convert the hex in.
00489          */
00490         std::string convertHexToLowerCase( const std::string& s ) const;
00491 
00492         /*
00493          * Normalize path, and return the resulting string.
00494          *
00495          * @param path - the path value to normalize.
00496          */
00497         std::string normalize( const std::string& path ) const;
00498 
00503         void setSchemeSpecificPart();
00504 
00505     };
00506 
00507 }}
00508 
00509 #endif /*_DECAF_NET_URI_H_*/