File: | stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTexpand.cxx |
Location: | line 152, column 12 |
Description: | Called C++ object pointer is null |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | /* |
3 | * This file is part of the LibreOffice project. |
4 | * |
5 | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | * |
9 | * This file incorporates work covered by the following license notice: |
10 | * |
11 | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | * contributor license agreements. See the NOTICE file distributed |
13 | * with this work for additional information regarding copyright |
14 | * ownership. The ASF licenses this file to you under the Apache |
15 | * License, Version 2.0 (the "License"); you may not use this file |
16 | * except in compliance with the License. You may obtain a copy of |
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | */ |
19 | |
20 | #include "sal/config.h" |
21 | |
22 | #include "stocservices.hxx" |
23 | |
24 | #include <new> |
25 | |
26 | #include "com/sun/star/lang/IllegalArgumentException.hpp" |
27 | #include "com/sun/star/lang/XServiceInfo.hpp" |
28 | #include "com/sun/star/uno/Reference.hxx" |
29 | #include "com/sun/star/uno/RuntimeException.hpp" |
30 | #include "com/sun/star/uno/Sequence.hxx" |
31 | #include "com/sun/star/uno/XInterface.hpp" |
32 | #include "com/sun/star/uri/XUriReference.hpp" |
33 | #include "com/sun/star/uri/XUriSchemeParser.hpp" |
34 | #include "com/sun/star/uri/XVndSunStarExpandUrlReference.hpp" |
35 | #include "com/sun/star/util/XMacroExpander.hpp" |
36 | #include "cppuhelper/implbase1.hxx" |
37 | #include "cppuhelper/implbase2.hxx" |
38 | #include "cppuhelper/weak.hxx" |
39 | #include "rtl/textenc.h" |
40 | #include "rtl/uri.h" |
41 | #include "rtl/uri.hxx" |
42 | #include "rtl/ustring.h" |
43 | #include "rtl/ustring.hxx" |
44 | #include "sal/types.h" |
45 | |
46 | #include "UriReference.hxx" |
47 | #include "supportsService.hxx" |
48 | |
49 | namespace { |
50 | |
51 | namespace css = ::com::sun::star; |
52 | |
53 | bool parseSchemeSpecificPart(::rtl::OUString const & part) { |
54 | // Liberally accepts both an empty opaque_part and an opaque_part that |
55 | // starts with a non-escaped "/": |
56 | return part.isEmpty() |
57 | || (!::rtl::Uri::decode(part, ::rtl_UriDecodeStrict, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76))).isEmpty()); |
58 | } |
59 | |
60 | class UrlReference: |
61 | public ::cppu::WeakImplHelper1< css::uri::XVndSunStarExpandUrlReference > |
62 | { |
63 | public: |
64 | UrlReference(::rtl::OUString const & scheme, ::rtl::OUString const & path): |
65 | base_( |
66 | scheme, false, false, ::rtl::OUString(), path, false, |
67 | ::rtl::OUString()) |
68 | {} |
69 | |
70 | virtual ::rtl::OUString SAL_CALL getUriReference() |
71 | throw (css::uno::RuntimeException) |
72 | { return base_.getUriReference(); } |
73 | |
74 | virtual ::sal_Bool SAL_CALL isAbsolute() throw (css::uno::RuntimeException) |
75 | { return base_.isAbsolute(); } |
76 | |
77 | virtual ::rtl::OUString SAL_CALL getScheme() |
78 | throw (css::uno::RuntimeException) |
79 | { return base_.getScheme(); } |
80 | |
81 | virtual ::rtl::OUString SAL_CALL getSchemeSpecificPart() |
82 | throw (css::uno::RuntimeException) |
83 | { return base_.getSchemeSpecificPart(); } |
84 | |
85 | virtual ::sal_Bool SAL_CALL isHierarchical() |
86 | throw (css::uno::RuntimeException) |
87 | { return base_.isHierarchical(); } |
88 | |
89 | virtual ::sal_Bool SAL_CALL hasAuthority() |
90 | throw (css::uno::RuntimeException) |
91 | { return base_.hasAuthority(); } |
92 | |
93 | virtual ::rtl::OUString SAL_CALL getAuthority() |
94 | throw (css::uno::RuntimeException) |
95 | { return base_.getAuthority(); } |
96 | |
97 | virtual ::rtl::OUString SAL_CALL getPath() |
98 | throw (css::uno::RuntimeException) |
99 | { return base_.getPath(); } |
100 | |
101 | virtual ::sal_Bool SAL_CALL hasRelativePath() |
102 | throw (css::uno::RuntimeException) |
103 | { return base_.hasRelativePath(); } |
104 | |
105 | virtual ::sal_Int32 SAL_CALL getPathSegmentCount() |
106 | throw (css::uno::RuntimeException) |
107 | { return base_.getPathSegmentCount(); } |
108 | |
109 | virtual ::rtl::OUString SAL_CALL getPathSegment(sal_Int32 index) |
110 | throw (css::uno::RuntimeException) |
111 | { return base_.getPathSegment(index); } |
112 | |
113 | virtual ::sal_Bool SAL_CALL hasQuery() throw (css::uno::RuntimeException) |
114 | { return base_.hasQuery(); } |
115 | |
116 | virtual ::rtl::OUString SAL_CALL getQuery() |
117 | throw (css::uno::RuntimeException) |
118 | { return base_.getQuery(); } |
119 | |
120 | virtual ::sal_Bool SAL_CALL hasFragment() throw (css::uno::RuntimeException) |
121 | { return base_.hasFragment(); } |
122 | |
123 | virtual ::rtl::OUString SAL_CALL getFragment() |
124 | throw (css::uno::RuntimeException) |
125 | { return base_.getFragment(); } |
126 | |
127 | virtual void SAL_CALL setFragment(::rtl::OUString const & fragment) |
128 | throw (css::uno::RuntimeException) |
129 | { base_.setFragment(fragment); } |
130 | |
131 | virtual void SAL_CALL clearFragment() throw (css::uno::RuntimeException) |
132 | { base_.clearFragment(); } |
133 | |
134 | virtual ::rtl::OUString SAL_CALL expand( |
135 | css::uno::Reference< css::util::XMacroExpander > const & expander) |
136 | throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); |
137 | |
138 | private: |
139 | UrlReference(UrlReference &); // not defined |
140 | void operator =(UrlReference); // not defined |
141 | |
142 | virtual ~UrlReference() {} |
143 | |
144 | stoc::uriproc::UriReference base_; |
145 | }; |
146 | |
147 | ::rtl::OUString UrlReference::expand( |
148 | css::uno::Reference< css::util::XMacroExpander > const & expander) |
149 | throw (css::lang::IllegalArgumentException, css::uno::RuntimeException) |
150 | { |
151 | OSL_ASSERT(expander.is())do { if (true && (!(expander.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/uriproc/UriSchemeParser_vndDOTsunDOTstarDOTexpand.cxx" ":" "151" ": "), "OSL_ASSERT: %s", "expander.is()"); } } while (false); |
152 | return expander->expandMacros( |
Called C++ object pointer is null | |
153 | ::rtl::Uri::decode( |
154 | getPath(), ::rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)))); |
155 | } |
156 | |
157 | class Parser: public ::cppu::WeakImplHelper2< |
158 | css::lang::XServiceInfo, css::uri::XUriSchemeParser > |
159 | { |
160 | public: |
161 | Parser() {} |
162 | |
163 | virtual ::rtl::OUString SAL_CALL getImplementationName() |
164 | throw (css::uno::RuntimeException); |
165 | |
166 | virtual ::sal_Bool SAL_CALL supportsService( |
167 | ::rtl::OUString const & serviceName) |
168 | throw (css::uno::RuntimeException); |
169 | |
170 | virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL |
171 | getSupportedServiceNames() throw (css::uno::RuntimeException); |
172 | |
173 | virtual css::uno::Reference< css::uri::XUriReference > SAL_CALL |
174 | parse( |
175 | ::rtl::OUString const & scheme, |
176 | ::rtl::OUString const & schemeSpecificPart) |
177 | throw (css::uno::RuntimeException); |
178 | |
179 | private: |
180 | Parser(Parser &); // not defined |
181 | void operator =(Parser); // not defined |
182 | |
183 | virtual ~Parser() {} |
184 | }; |
185 | |
186 | ::rtl::OUString Parser::getImplementationName() |
187 | throw (css::uno::RuntimeException) |
188 | { |
189 | return ::stoc_services::UriSchemeParser_vndDOTsunDOTstarDOTexpand:: |
190 | getImplementationName(); |
191 | } |
192 | |
193 | ::sal_Bool Parser::supportsService(::rtl::OUString const & serviceName) |
194 | throw (css::uno::RuntimeException) |
195 | { |
196 | return ::stoc::uriproc::supportsService( |
197 | getSupportedServiceNames(), serviceName); |
198 | } |
199 | |
200 | css::uno::Sequence< ::rtl::OUString > Parser::getSupportedServiceNames() |
201 | throw (css::uno::RuntimeException) |
202 | { |
203 | return ::stoc_services::UriSchemeParser_vndDOTsunDOTstarDOTexpand:: |
204 | getSupportedServiceNames(); |
205 | } |
206 | |
207 | css::uno::Reference< css::uri::XUriReference > Parser::parse( |
208 | ::rtl::OUString const & scheme, ::rtl::OUString const & schemeSpecificPart) |
209 | throw (css::uno::RuntimeException) |
210 | { |
211 | if (!parseSchemeSpecificPart(schemeSpecificPart)) { |
212 | return css::uno::Reference< css::uri::XUriReference >(); |
213 | } |
214 | try { |
215 | return new UrlReference(scheme, schemeSpecificPart); |
216 | } catch (::std::bad_alloc &) { |
217 | throw css::uno::RuntimeException( |
218 | ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")(&("std::bad_alloc")[0]), ((sal_Int32)((sizeof ("std::bad_alloc" ) / sizeof (("std::bad_alloc")[0]))-1)), (((rtl_TextEncoding) 11))), |
219 | css::uno::Reference< css::uno::XInterface >()); |
220 | } |
221 | } |
222 | |
223 | } |
224 | |
225 | namespace stoc_services { namespace UriSchemeParser_vndDOTsunDOTstarDOTexpand { |
226 | |
227 | css::uno::Reference< css::uno::XInterface > create( |
228 | SAL_UNUSED_PARAMETER__attribute__ ((unused)) css::uno::Reference< css::uno::XComponentContext > |
229 | const &) |
230 | SAL_THROW((css::uno::Exception)) |
231 | { |
232 | //TODO: single instance |
233 | try { |
234 | return static_cast< ::cppu::OWeakObject * >(new Parser); |
235 | } catch (::std::bad_alloc &) { |
236 | throw css::uno::RuntimeException( |
237 | ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("std::bad_alloc")(&("std::bad_alloc")[0]), ((sal_Int32)((sizeof ("std::bad_alloc" ) / sizeof (("std::bad_alloc")[0]))-1)), (((rtl_TextEncoding) 11))), |
238 | css::uno::Reference< css::uno::XInterface >()); |
239 | } |
240 | } |
241 | |
242 | ::rtl::OUString getImplementationName() { |
243 | return ::rtl::OUString( |
244 | RTL_CONSTASCII_USTRINGPARAM((&("com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" )[0]), ((sal_Int32)((sizeof ("com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" ) / sizeof (("com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" )[0]))-1)), (((rtl_TextEncoding) 11)) |
245 | "com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand")(&("com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" )[0]), ((sal_Int32)((sizeof ("com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" ) / sizeof (("com.sun.star.comp.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" )[0]))-1)), (((rtl_TextEncoding) 11))); |
246 | } |
247 | |
248 | css::uno::Sequence< ::rtl::OUString > getSupportedServiceNames() { |
249 | css::uno::Sequence< ::rtl::OUString > s(1); |
250 | s[0] = ::rtl::OUString( |
251 | RTL_CONSTASCII_USTRINGPARAM((&("com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" )[0]), ((sal_Int32)((sizeof ("com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" ) / sizeof (("com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" )[0]))-1)), (((rtl_TextEncoding) 11)) |
252 | "com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand")(&("com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" )[0]), ((sal_Int32)((sizeof ("com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" ) / sizeof (("com.sun.star.uri.UriSchemeParser_vndDOTsunDOTstarDOTexpand" )[0]))-1)), (((rtl_TextEncoding) 11))); |
253 | return s; |
254 | } |
255 | |
256 | } } |
257 | |
258 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |