xref: /aoo42x/main/sal/inc/rtl/uri.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _RTL_URI_HXX_
29 #define _RTL_URI_HXX_
30 
31 #include "rtl/malformeduriexception.hxx"
32 #include "rtl/uri.h"
33 #include "rtl/textenc.h"
34 #include "rtl/ustring.hxx"
35 #include "sal/types.h"
36 
37 namespace rtl {
38 
39 /** A wrapper around the C functions from <rtl/uri.h>.
40  */
41 class Uri
42 {
43 public:
44     /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
45         an array of 128 booleans as char class.
46      */
47     static inline rtl::OUString encode(rtl::OUString const & rText,
48                                        sal_Bool const * pCharClass,
49                                        rtl_UriEncodeMechanism eMechanism,
50                                        rtl_TextEncoding eCharset)
51         SAL_THROW(());
52 
53     /** A wrapper around rtl_uriEncode() from <rtl/uri.h> (see there), using
54         a predefined rtl_UriCharClass enumeration member.
55      */
56     static inline rtl::OUString encode(rtl::OUString const & rText,
57                                        rtl_UriCharClass eCharClass,
58                                        rtl_UriEncodeMechanism eMechanism,
59                                        rtl_TextEncoding eCharset)
60         SAL_THROW(());
61 
62     /** A wrapper around rtl_uriDecode() from <rtl/uri.h> (see there).
63      */
64     static inline rtl::OUString decode(rtl::OUString const & rText,
65                                        rtl_UriDecodeMechanism eMechanism,
66                                        rtl_TextEncoding eCharset)
67         SAL_THROW(());
68 
69     /** A wrapper around rtl_uriConvertRelToAbs() from <rtl/uri.h> (see there).
70 
71         @exception MalformedUriException
72         Thrown in case rtl_uriConvertRelToAbs() signals an exception due to a
73         malformed base URI.
74      */
75     static inline rtl::OUString convertRelToAbs(
76         rtl::OUString const & rBaseUriRef, rtl::OUString const & rRelUriRef);
77 
78 private:
79     /** not implemented
80         @internal */
81     Uri();
82 
83     /** not implemented
84         @internal */
85     Uri(Uri &);
86 
87     /** not implemented
88         @internal */
89     ~Uri();
90 
91     /** not implemented
92         @internal */
93     void operator =(Uri);
94 };
95 
96 inline rtl::OUString Uri::encode(rtl::OUString const & rText,
97                                  sal_Bool const * pCharClass,
98                                  rtl_UriEncodeMechanism eMechanism,
99                                  rtl_TextEncoding eCharset)
100     SAL_THROW(())
101 {
102     rtl::OUString aResult;
103     rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
104                   pCharClass,
105                   eMechanism,
106                   eCharset,
107                   &aResult.pData);
108     return aResult;
109 }
110 
111 inline rtl::OUString Uri::encode(rtl::OUString const & rText,
112                                  rtl_UriCharClass eCharClass,
113                                  rtl_UriEncodeMechanism eMechanism,
114                                  rtl_TextEncoding eCharset)
115     SAL_THROW(())
116 {
117     rtl::OUString aResult;
118     rtl_uriEncode(const_cast< rtl::OUString & >(rText).pData,
119                   rtl_getUriCharClass(eCharClass),
120                   eMechanism,
121                   eCharset,
122                   &aResult.pData);
123     return aResult;
124 }
125 
126 inline rtl::OUString Uri::decode(rtl::OUString const & rText,
127                                  rtl_UriDecodeMechanism eMechanism,
128                                  rtl_TextEncoding eCharset)
129     SAL_THROW(())
130 {
131     rtl::OUString aResult;
132     rtl_uriDecode(const_cast< rtl::OUString & >(rText).pData,
133                   eMechanism,
134                   eCharset,
135                   &aResult.pData);
136     return aResult;
137 }
138 
139 inline rtl::OUString Uri::convertRelToAbs(rtl::OUString const & rBaseUriRef,
140                                           rtl::OUString const & rRelUriRef)
141 {
142     rtl::OUString aResult;
143     rtl::OUString aException;
144     if (!rtl_uriConvertRelToAbs(
145             const_cast< rtl::OUString & >(rBaseUriRef).pData,
146             const_cast< rtl::OUString & >(rRelUriRef).pData, &aResult.pData,
147             &aException.pData))
148         throw MalformedUriException(aException);
149     return aResult;
150 }
151 
152 }
153 
154 #endif // _RTL_URI_HXX_
155