/src/libreoffice/ucbhelper/source/provider/contentinfo.cxx
Line | Count | Source |
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 <com/sun/star/beans/XPropertySetInfo.hpp> |
21 | | #include <com/sun/star/ucb/UnsupportedCommandException.hpp> |
22 | | #include <com/sun/star/ucb/XPersistentPropertySet.hpp> |
23 | | #include <com/sun/star/ucb/XCommandInfo.hpp> |
24 | | |
25 | | #include <ucbhelper/contenthelper.hxx> |
26 | | #include <utility> |
27 | | #include "contentinfo.hxx" |
28 | | |
29 | | using namespace com::sun::star; |
30 | | |
31 | | |
32 | | // PropertySetInfo Implementation. |
33 | | |
34 | | |
35 | | namespace ucbhelper { |
36 | | |
37 | | PropertySetInfo::PropertySetInfo( |
38 | | uno::Reference< css::ucb::XCommandEnvironment > xEnv, |
39 | | ContentImplHelper* pContent ) |
40 | 0 | : m_xEnv(std::move( xEnv )), |
41 | 0 | m_pContent( pContent ) |
42 | 0 | { |
43 | 0 | } |
44 | | |
45 | | |
46 | | // virtual |
47 | | PropertySetInfo::~PropertySetInfo() |
48 | 0 | { |
49 | 0 | } |
50 | | |
51 | | |
52 | | // XPropertySetInfo methods. |
53 | | |
54 | | |
55 | | // virtual |
56 | | uno::Sequence< beans::Property > SAL_CALL PropertySetInfo::getProperties() |
57 | 0 | { |
58 | 0 | std::unique_lock aGuard( m_aMutex ); |
59 | 0 | return getPropertiesImpl(); |
60 | 0 | } |
61 | | |
62 | | const uno::Sequence< beans::Property > & PropertySetInfo::getPropertiesImpl() |
63 | 0 | { |
64 | 0 | if ( m_xProps ) |
65 | 0 | return *m_xProps; |
66 | | |
67 | | // Get info for core ( native) properties. |
68 | | |
69 | 0 | try |
70 | 0 | { |
71 | 0 | m_xProps = m_pContent->getProperties( m_xEnv ); |
72 | 0 | } |
73 | 0 | catch ( uno::RuntimeException const & ) |
74 | 0 | { |
75 | 0 | throw; |
76 | 0 | } |
77 | 0 | catch ( uno::Exception const & ) |
78 | 0 | { |
79 | 0 | m_xProps.emplace(); |
80 | 0 | } |
81 | | |
82 | | // Get info for additional properties. |
83 | | |
84 | 0 | uno::Reference< css::ucb::XPersistentPropertySet > |
85 | 0 | xSet ( m_pContent->getAdditionalPropertySet( false ) ); |
86 | |
|
87 | 0 | if ( xSet.is() ) |
88 | 0 | { |
89 | | // Get property set info. |
90 | 0 | uno::Reference< beans::XPropertySetInfo > xInfo( |
91 | 0 | xSet->getPropertySetInfo() ); |
92 | 0 | if ( xInfo.is() ) |
93 | 0 | { |
94 | 0 | const uno::Sequence< beans::Property > aAddProps |
95 | 0 | = xInfo->getProperties(); |
96 | 0 | sal_Int32 nAddProps = aAddProps.getLength(); |
97 | 0 | if ( nAddProps > 0 ) |
98 | 0 | { |
99 | 0 | sal_Int32 nPos = m_xProps->getLength(); |
100 | 0 | m_xProps->realloc( nPos + nAddProps ); |
101 | |
|
102 | 0 | std::copy(aAddProps.begin(), aAddProps.end(), |
103 | 0 | std::next(m_xProps->getArray(), nPos)); |
104 | 0 | } |
105 | 0 | } |
106 | 0 | } |
107 | 0 | return *m_xProps; |
108 | 0 | } |
109 | | |
110 | | |
111 | | // virtual |
112 | | beans::Property SAL_CALL PropertySetInfo::getPropertyByName( |
113 | | const OUString& aName ) |
114 | 0 | { |
115 | 0 | beans::Property aProp; |
116 | 0 | if ( queryProperty( aName, aProp ) ) |
117 | 0 | return aProp; |
118 | | |
119 | 0 | throw beans::UnknownPropertyException(aName); |
120 | 0 | } |
121 | | |
122 | | |
123 | | // virtual |
124 | | sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( |
125 | | const OUString& Name ) |
126 | 0 | { |
127 | 0 | beans::Property aProp; |
128 | 0 | return queryProperty( Name, aProp ); |
129 | 0 | } |
130 | | |
131 | | |
132 | | // Non-Interface methods. |
133 | | |
134 | | |
135 | | void PropertySetInfo::reset() |
136 | 0 | { |
137 | 0 | std::unique_lock aGuard( m_aMutex ); |
138 | 0 | m_xProps.reset(); |
139 | 0 | } |
140 | | |
141 | | |
142 | | bool PropertySetInfo::queryProperty( |
143 | | std::u16string_view rName, beans::Property& rProp ) |
144 | 0 | { |
145 | 0 | std::unique_lock aGuard( m_aMutex ); |
146 | |
|
147 | 0 | getPropertiesImpl(); |
148 | |
|
149 | 0 | const beans::Property* pProps = m_xProps->getConstArray(); |
150 | 0 | sal_Int32 nCount = m_xProps->getLength(); |
151 | 0 | for ( sal_Int32 n = 0; n < nCount; ++n ) |
152 | 0 | { |
153 | 0 | const beans::Property& rCurrProp = pProps[ n ]; |
154 | 0 | if ( rCurrProp.Name == rName ) |
155 | 0 | { |
156 | 0 | rProp = rCurrProp; |
157 | 0 | return true; |
158 | 0 | } |
159 | 0 | } |
160 | | |
161 | 0 | return false; |
162 | 0 | } |
163 | | |
164 | | |
165 | | // CommandProcessorInfo Implementation. |
166 | | |
167 | | |
168 | | CommandProcessorInfo::CommandProcessorInfo( |
169 | | uno::Reference< css::ucb::XCommandEnvironment > xEnv, |
170 | | ContentImplHelper* pContent ) |
171 | 0 | : m_xEnv(std::move( xEnv )), |
172 | 0 | m_pContent( pContent ) |
173 | 0 | { |
174 | 0 | } |
175 | | |
176 | | |
177 | | // virtual |
178 | | CommandProcessorInfo::~CommandProcessorInfo() |
179 | 0 | { |
180 | 0 | } |
181 | | |
182 | | |
183 | | // XCommandInfo methods. |
184 | | |
185 | | |
186 | | // virtual |
187 | | uno::Sequence< css::ucb::CommandInfo > SAL_CALL CommandProcessorInfo::getCommands() |
188 | 0 | { |
189 | 0 | std::unique_lock aGuard( m_aMutex ); |
190 | 0 | return getCommandsImpl(); |
191 | 0 | } |
192 | | |
193 | | const uno::Sequence< css::ucb::CommandInfo > & CommandProcessorInfo::getCommandsImpl() |
194 | 0 | { |
195 | 0 | if ( m_xCommands ) |
196 | 0 | return *m_xCommands; |
197 | | |
198 | | // Get info for commands. |
199 | | |
200 | 0 | try |
201 | 0 | { |
202 | 0 | m_xCommands = m_pContent->getCommands( m_xEnv ); |
203 | 0 | } |
204 | 0 | catch ( uno::RuntimeException const & ) |
205 | 0 | { |
206 | 0 | throw; |
207 | 0 | } |
208 | 0 | catch ( uno::Exception const & ) |
209 | 0 | { |
210 | 0 | m_xCommands.emplace(); |
211 | 0 | } |
212 | 0 | return *m_xCommands; |
213 | 0 | } |
214 | | |
215 | | |
216 | | // virtual |
217 | | css::ucb::CommandInfo SAL_CALL |
218 | | CommandProcessorInfo::getCommandInfoByName( |
219 | | const OUString& Name ) |
220 | 0 | { |
221 | 0 | css::ucb::CommandInfo aInfo; |
222 | 0 | if ( queryCommand( Name, aInfo ) ) |
223 | 0 | return aInfo; |
224 | | |
225 | 0 | throw css::ucb::UnsupportedCommandException(); |
226 | 0 | } |
227 | | |
228 | | |
229 | | // virtual |
230 | | css::ucb::CommandInfo SAL_CALL |
231 | | CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle ) |
232 | 0 | { |
233 | 0 | css::ucb::CommandInfo aInfo; |
234 | 0 | if ( queryCommand( Handle, aInfo ) ) |
235 | 0 | return aInfo; |
236 | | |
237 | 0 | throw css::ucb::UnsupportedCommandException(); |
238 | 0 | } |
239 | | |
240 | | |
241 | | // virtual |
242 | | sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName( |
243 | | const OUString& Name ) |
244 | 0 | { |
245 | 0 | css::ucb::CommandInfo aInfo; |
246 | 0 | return queryCommand( Name, aInfo ); |
247 | 0 | } |
248 | | |
249 | | |
250 | | // virtual |
251 | | sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle ) |
252 | 0 | { |
253 | 0 | css::ucb::CommandInfo aInfo; |
254 | 0 | return queryCommand( Handle, aInfo ); |
255 | 0 | } |
256 | | |
257 | | |
258 | | // Non-Interface methods. |
259 | | |
260 | | |
261 | | void CommandProcessorInfo::reset() |
262 | 0 | { |
263 | 0 | std::unique_lock aGuard( m_aMutex ); |
264 | 0 | m_xCommands.reset(); |
265 | 0 | } |
266 | | |
267 | | |
268 | | bool CommandProcessorInfo::queryCommand( |
269 | | std::u16string_view rName, |
270 | | css::ucb::CommandInfo& rCommand ) |
271 | 0 | { |
272 | 0 | std::unique_lock aGuard( m_aMutex ); |
273 | |
|
274 | 0 | getCommandsImpl(); |
275 | |
|
276 | 0 | const css::ucb::CommandInfo* pCommands |
277 | 0 | = m_xCommands->getConstArray(); |
278 | 0 | sal_Int32 nCount = m_xCommands->getLength(); |
279 | 0 | for ( sal_Int32 n = 0; n < nCount; ++n ) |
280 | 0 | { |
281 | 0 | const css::ucb::CommandInfo& rCurrCommand = pCommands[ n ]; |
282 | 0 | if ( rCurrCommand.Name == rName ) |
283 | 0 | { |
284 | 0 | rCommand = rCurrCommand; |
285 | 0 | return true; |
286 | 0 | } |
287 | 0 | } |
288 | | |
289 | 0 | return false; |
290 | 0 | } |
291 | | |
292 | | |
293 | | bool CommandProcessorInfo::queryCommand( |
294 | | sal_Int32 nHandle, |
295 | | css::ucb::CommandInfo& rCommand ) |
296 | 0 | { |
297 | 0 | std::unique_lock aGuard( m_aMutex ); |
298 | |
|
299 | 0 | getCommandsImpl(); |
300 | |
|
301 | 0 | const css::ucb::CommandInfo* pCommands = m_xCommands->getConstArray(); |
302 | 0 | sal_Int32 nCount = m_xCommands->getLength(); |
303 | 0 | for ( sal_Int32 n = 0; n < nCount; ++n ) |
304 | 0 | { |
305 | 0 | const css::ucb::CommandInfo& rCurrCommand = pCommands[ n ]; |
306 | 0 | if ( rCurrCommand.Handle == nHandle ) |
307 | 0 | { |
308 | 0 | rCommand = rCurrCommand; |
309 | 0 | return true; |
310 | 0 | } |
311 | 0 | } |
312 | | |
313 | 0 | return false; |
314 | 0 | } |
315 | | |
316 | | } // namespace ucbhelper |
317 | | |
318 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |