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