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