xref: /aoo41x/main/sal/inc/rtl/uri.hxx (revision 565d668c)
1*565d668cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*565d668cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*565d668cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*565d668cSAndrew Rist  * distributed with this work for additional information
6*565d668cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*565d668cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*565d668cSAndrew Rist  * "License"); you may not use this file except in compliance
9*565d668cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*565d668cSAndrew Rist  *
11*565d668cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*565d668cSAndrew Rist  *
13*565d668cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*565d668cSAndrew Rist  * software distributed under the License is distributed on an
15*565d668cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*565d668cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*565d668cSAndrew Rist  * specific language governing permissions and limitations
18*565d668cSAndrew Rist  * under the License.
19*565d668cSAndrew Rist  *
20*565d668cSAndrew Rist  *************************************************************/
21*565d668cSAndrew Rist 
22*565d668cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _RTL_URI_HXX_
25cdf0e10cSrcweir #define _RTL_URI_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "rtl/malformeduriexception.hxx"
28cdf0e10cSrcweir #include "rtl/uri.h"
29cdf0e10cSrcweir #include "rtl/textenc.h"
30cdf0e10cSrcweir #include "rtl/ustring.hxx"
31cdf0e10cSrcweir #include "sal/types.h"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace rtl {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /** A wrapper around the C functions from <rtl/uri.h>.
36cdf0e10cSrcweir  */
37cdf0e10cSrcweir class Uri
38cdf0e10cSrcweir {
39cdf0e10cSrcweir public:
40cdf0e10cSrcweir     /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
41cdf0e10cSrcweir         an array of 128 booleans as char class.
42cdf0e10cSrcweir      */
43cdf0e10cSrcweir     static inline rtl::OUString encode(rtl::OUString const & rText,
44cdf0e10cSrcweir                                        sal_Bool const * pCharClass,
45cdf0e10cSrcweir                                        rtl_UriEncodeMechanism eMechanism,
46cdf0e10cSrcweir                                        rtl_TextEncoding eCharset)
47cdf0e10cSrcweir         SAL_THROW(());
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
50cdf0e10cSrcweir         a predefined rtl_UriCharClass enumeration member.
51cdf0e10cSrcweir      */
52cdf0e10cSrcweir     static inline rtl::OUString encode(rtl::OUString const & rText,
53cdf0e10cSrcweir                                        rtl_UriCharClass eCharClass,
54cdf0e10cSrcweir                                        rtl_UriEncodeMechanism eMechanism,
55cdf0e10cSrcweir                                        rtl_TextEncoding eCharset)
56cdf0e10cSrcweir         SAL_THROW(());
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     /** A wrapper around rtl_uriDecode() from <rtl/uri.h> (see there).
59cdf0e10cSrcweir      */
60cdf0e10cSrcweir     static inline rtl::OUString decode(rtl::OUString const & rText,
61cdf0e10cSrcweir                                        rtl_UriDecodeMechanism eMechanism,
62cdf0e10cSrcweir                                        rtl_TextEncoding eCharset)
63cdf0e10cSrcweir         SAL_THROW(());
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /** A wrapper around rtl_uriConvertRelToAbs() from <rtl/uri.h> (see there).
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         @exception MalformedUriException
68cdf0e10cSrcweir         Thrown in case rtl_uriConvertRelToAbs() signals an exception due to a
69cdf0e10cSrcweir         malformed base URI.
70cdf0e10cSrcweir      */
71cdf0e10cSrcweir     static inline rtl::OUString convertRelToAbs(
72cdf0e10cSrcweir         rtl::OUString const & rBaseUriRef, rtl::OUString const & rRelUriRef);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir private:
75cdf0e10cSrcweir     /** not implemented
76cdf0e10cSrcweir         @internal */
77cdf0e10cSrcweir     Uri();
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     /** not implemented
80cdf0e10cSrcweir         @internal */
81cdf0e10cSrcweir     Uri(Uri &);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     /** not implemented
84cdf0e10cSrcweir         @internal */
85cdf0e10cSrcweir     ~Uri();
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     /** not implemented
88cdf0e10cSrcweir         @internal */
89cdf0e10cSrcweir     void operator =(Uri);
90cdf0e10cSrcweir };
91cdf0e10cSrcweir 
encode(rtl::OUString const & rText,sal_Bool const * pCharClass,rtl_UriEncodeMechanism eMechanism,rtl_TextEncoding eCharset)92cdf0e10cSrcweir inline rtl::OUString Uri::encode(rtl::OUString const & rText,
93cdf0e10cSrcweir                                  sal_Bool const * pCharClass,
94cdf0e10cSrcweir                                  rtl_UriEncodeMechanism eMechanism,
95cdf0e10cSrcweir                                  rtl_TextEncoding eCharset)
96cdf0e10cSrcweir     SAL_THROW(())
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     rtl::OUString aResult;
99cdf0e10cSrcweir     rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
100cdf0e10cSrcweir                   pCharClass,
101cdf0e10cSrcweir                   eMechanism,
102cdf0e10cSrcweir                   eCharset,
103cdf0e10cSrcweir                   &aResult.pData);
104cdf0e10cSrcweir     return aResult;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
encode(rtl::OUString const & rText,rtl_UriCharClass eCharClass,rtl_UriEncodeMechanism eMechanism,rtl_TextEncoding eCharset)107cdf0e10cSrcweir inline rtl::OUString Uri::encode(rtl::OUString const & rText,
108cdf0e10cSrcweir                                  rtl_UriCharClass eCharClass,
109cdf0e10cSrcweir                                  rtl_UriEncodeMechanism eMechanism,
110cdf0e10cSrcweir                                  rtl_TextEncoding eCharset)
111cdf0e10cSrcweir     SAL_THROW(())
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     rtl::OUString aResult;
114cdf0e10cSrcweir     rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
115cdf0e10cSrcweir                   rtl_getUriCharClass(eCharClass),
116cdf0e10cSrcweir                   eMechanism,
117cdf0e10cSrcweir                   eCharset,
118cdf0e10cSrcweir                   &aResult.pData);
119cdf0e10cSrcweir     return aResult;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
decode(rtl::OUString const & rText,rtl_UriDecodeMechanism eMechanism,rtl_TextEncoding eCharset)122cdf0e10cSrcweir inline rtl::OUString Uri::decode(rtl::OUString const & rText,
123cdf0e10cSrcweir                                  rtl_UriDecodeMechanism eMechanism,
124cdf0e10cSrcweir                                  rtl_TextEncoding eCharset)
125cdf0e10cSrcweir     SAL_THROW(())
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     rtl::OUString aResult;
128cdf0e10cSrcweir     rtl_uriDecode(const_cast< rtl::OUString & >(rText).pData,
129cdf0e10cSrcweir                   eMechanism,
130cdf0e10cSrcweir                   eCharset,
131cdf0e10cSrcweir                   &aResult.pData);
132cdf0e10cSrcweir     return aResult;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
convertRelToAbs(rtl::OUString const & rBaseUriRef,rtl::OUString const & rRelUriRef)135cdf0e10cSrcweir inline rtl::OUString Uri::convertRelToAbs(rtl::OUString const & rBaseUriRef,
136cdf0e10cSrcweir                                           rtl::OUString const & rRelUriRef)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     rtl::OUString aResult;
139cdf0e10cSrcweir     rtl::OUString aException;
140cdf0e10cSrcweir     if (!rtl_uriConvertRelToAbs(
141cdf0e10cSrcweir             const_cast< rtl::OUString & >(rBaseUriRef).pData,
142cdf0e10cSrcweir             const_cast< rtl::OUString & >(rRelUriRef).pData, &aResult.pData,
143cdf0e10cSrcweir             &aException.pData))
144cdf0e10cSrcweir         throw MalformedUriException(aException);
145cdf0e10cSrcweir     return aResult;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir #endif // _RTL_URI_HXX_
151