bump product version to 4.1.6.2
[LibreOffice.git] / ucbhelper / source / provider / contentinfo.cxx
blobb9e8a258ed0d83531eb6a6441bee4c39abafbe01
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 /**************************************************************************
21 TODO
22 **************************************************************************
24 *************************************************************************/
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/ucb/XPropertySetRegistry.hpp>
28 #include "osl/diagnose.h"
29 #include "osl/mutex.hxx"
30 #include <ucbhelper/contenthelper.hxx>
31 #include <ucbhelper/contentinfo.hxx>
33 using namespace com::sun::star;
35 //=========================================================================
36 //=========================================================================
38 // PropertySetInfo Implementation.
40 //=========================================================================
41 //=========================================================================
43 namespace ucbhelper {
45 PropertySetInfo::PropertySetInfo(
46 const uno::Reference< com::sun::star::ucb::XCommandEnvironment >& rxEnv,
47 ContentImplHelper* pContent )
48 : m_xEnv( rxEnv ),
49 m_pProps( 0 ),
50 m_pContent( pContent )
54 //=========================================================================
55 // virtual
56 PropertySetInfo::~PropertySetInfo()
58 delete m_pProps;
61 //=========================================================================
63 // XInterface methods.
65 //=========================================================================
67 XINTERFACE_IMPL_2( PropertySetInfo,
68 lang::XTypeProvider,
69 beans::XPropertySetInfo );
71 //=========================================================================
73 // XTypeProvider methods.
75 //=========================================================================
77 XTYPEPROVIDER_IMPL_2( PropertySetInfo,
78 lang::XTypeProvider,
79 beans::XPropertySetInfo );
81 //=========================================================================
83 // XPropertySetInfo methods.
85 //=========================================================================
87 // virtual
88 uno::Sequence< beans::Property > SAL_CALL PropertySetInfo::getProperties()
89 throw( uno::RuntimeException )
91 if ( !m_pProps )
93 osl::MutexGuard aGuard( m_aMutex );
94 if ( !m_pProps )
96 //////////////////////////////////////////////////////////////
97 // Get info for core ( native) properties.
98 //////////////////////////////////////////////////////////////
102 uno::Sequence< beans::Property > aProps
103 = m_pContent->getProperties( m_xEnv );
104 m_pProps = new uno::Sequence< beans::Property >( aProps );
106 catch ( uno::RuntimeException const & )
108 throw;
110 catch ( uno::Exception const & )
112 m_pProps = new uno::Sequence< beans::Property >( 0 );
115 //////////////////////////////////////////////////////////////
116 // Get info for additional properties.
117 //////////////////////////////////////////////////////////////
119 uno::Reference< com::sun::star::ucb::XPersistentPropertySet >
120 xSet ( m_pContent->getAdditionalPropertySet( sal_False ) );
122 if ( xSet.is() )
124 // Get property set info.
125 uno::Reference< beans::XPropertySetInfo > xInfo(
126 xSet->getPropertySetInfo() );
127 if ( xInfo.is() )
129 const uno::Sequence< beans::Property >& rAddProps
130 = xInfo->getProperties();
131 sal_Int32 nAddProps = rAddProps.getLength();
132 if ( nAddProps > 0 )
134 sal_Int32 nPos = m_pProps->getLength();
135 m_pProps->realloc( nPos + nAddProps );
137 beans::Property* pProps = m_pProps->getArray();
138 const beans::Property* pAddProps
139 = rAddProps.getConstArray();
141 for ( sal_Int32 n = 0; n < nAddProps; ++n, ++nPos )
142 pProps[ nPos ] = pAddProps[ n ];
148 return *m_pProps;
151 //=========================================================================
152 // virtual
153 beans::Property SAL_CALL PropertySetInfo::getPropertyByName(
154 const OUString& aName )
155 throw( beans::UnknownPropertyException, uno::RuntimeException )
157 beans::Property aProp;
158 if ( queryProperty( aName, aProp ) )
159 return aProp;
161 throw beans::UnknownPropertyException();
164 //=========================================================================
165 // virtual
166 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName(
167 const OUString& Name )
168 throw( uno::RuntimeException )
170 beans::Property aProp;
171 return queryProperty( Name, aProp );
174 //=========================================================================
176 // Non-Interface methods.
178 //=========================================================================
180 void PropertySetInfo::reset()
182 osl::MutexGuard aGuard( m_aMutex );
183 delete m_pProps;
184 m_pProps = 0;
187 //=========================================================================
188 sal_Bool PropertySetInfo::queryProperty(
189 const OUString& rName, beans::Property& rProp )
191 osl::MutexGuard aGuard( m_aMutex );
193 getProperties();
195 const beans::Property* pProps = m_pProps->getConstArray();
196 sal_Int32 nCount = m_pProps->getLength();
197 for ( sal_Int32 n = 0; n < nCount; ++n )
199 const beans::Property& rCurrProp = pProps[ n ];
200 if ( rCurrProp.Name == rName )
202 rProp = rCurrProp;
203 return sal_True;
207 return sal_False;
210 //=========================================================================
211 //=========================================================================
213 // CommandProcessorInfo Implementation.
215 //=========================================================================
216 //=========================================================================
218 CommandProcessorInfo::CommandProcessorInfo(
219 const uno::Reference< com::sun::star::ucb::XCommandEnvironment >& rxEnv,
220 ContentImplHelper* pContent )
221 : m_xEnv( rxEnv ),
222 m_pCommands( 0 ),
223 m_pContent( pContent )
227 //=========================================================================
228 // virtual
229 CommandProcessorInfo::~CommandProcessorInfo()
231 delete m_pCommands;
234 //=========================================================================
236 // XInterface methods.
238 //=========================================================================
240 XINTERFACE_IMPL_2( CommandProcessorInfo,
241 lang::XTypeProvider,
242 com::sun::star::ucb::XCommandInfo );
244 //=========================================================================
246 // XTypeProvider methods.
248 //=========================================================================
250 XTYPEPROVIDER_IMPL_2( CommandProcessorInfo,
251 lang::XTypeProvider,
252 com::sun::star::ucb::XCommandInfo );
254 //=========================================================================
256 // XCommandInfo methods.
258 //=========================================================================
260 // virtual
261 uno::Sequence< com::sun::star::ucb::CommandInfo > SAL_CALL
262 CommandProcessorInfo::getCommands()
263 throw( uno::RuntimeException )
265 if ( !m_pCommands )
267 osl::MutexGuard aGuard( m_aMutex );
268 if ( !m_pCommands )
270 //////////////////////////////////////////////////////////////
271 // Get info for commands.
272 //////////////////////////////////////////////////////////////
276 uno::Sequence< com::sun::star::ucb::CommandInfo > aCmds
277 = m_pContent->getCommands( m_xEnv );
278 m_pCommands
279 = new uno::Sequence< com::sun::star::ucb::CommandInfo >(
280 aCmds );
282 catch ( uno::RuntimeException const & )
284 throw;
286 catch ( uno::Exception const & )
288 m_pCommands
289 = new uno::Sequence< com::sun::star::ucb::CommandInfo >(
290 0 );
294 return *m_pCommands;
297 //=========================================================================
298 // virtual
299 com::sun::star::ucb::CommandInfo SAL_CALL
300 CommandProcessorInfo::getCommandInfoByName(
301 const OUString& Name )
302 throw( com::sun::star::ucb::UnsupportedCommandException,
303 uno::RuntimeException )
305 com::sun::star::ucb::CommandInfo aInfo;
306 if ( queryCommand( Name, aInfo ) )
307 return aInfo;
309 throw com::sun::star::ucb::UnsupportedCommandException();
312 //=========================================================================
313 // virtual
314 com::sun::star::ucb::CommandInfo SAL_CALL
315 CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle )
316 throw( com::sun::star::ucb::UnsupportedCommandException,
317 uno::RuntimeException )
319 com::sun::star::ucb::CommandInfo aInfo;
320 if ( queryCommand( Handle, aInfo ) )
321 return aInfo;
323 throw com::sun::star::ucb::UnsupportedCommandException();
326 //=========================================================================
327 // virtual
328 sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName(
329 const OUString& Name )
330 throw( uno::RuntimeException )
332 com::sun::star::ucb::CommandInfo aInfo;
333 return queryCommand( Name, aInfo );
336 //=========================================================================
337 // virtual
338 sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle )
339 throw( uno::RuntimeException )
341 com::sun::star::ucb::CommandInfo aInfo;
342 return queryCommand( Handle, aInfo );
345 //=========================================================================
347 // Non-Interface methods.
349 //=========================================================================
351 void CommandProcessorInfo::reset()
353 osl::MutexGuard aGuard( m_aMutex );
354 delete m_pCommands;
355 m_pCommands = 0;
359 //=========================================================================
360 sal_Bool CommandProcessorInfo::queryCommand(
361 const OUString& rName,
362 com::sun::star::ucb::CommandInfo& rCommand )
364 osl::MutexGuard aGuard( m_aMutex );
366 getCommands();
368 const com::sun::star::ucb::CommandInfo* pCommands
369 = m_pCommands->getConstArray();
370 sal_Int32 nCount = m_pCommands->getLength();
371 for ( sal_Int32 n = 0; n < nCount; ++n )
373 const com::sun::star::ucb::CommandInfo& rCurrCommand = pCommands[ n ];
374 if ( rCurrCommand.Name == rName )
376 rCommand = rCurrCommand;
377 return sal_True;
381 return sal_False;
384 //=========================================================================
385 sal_Bool CommandProcessorInfo::queryCommand(
386 sal_Int32 nHandle,
387 com::sun::star::ucb::CommandInfo& rCommand )
389 osl::MutexGuard aGuard( m_aMutex );
391 getCommands();
393 const com::sun::star::ucb::CommandInfo* pCommands
394 = m_pCommands->getConstArray();
395 sal_Int32 nCount = m_pCommands->getLength();
396 for ( sal_Int32 n = 0; n < nCount; ++n )
398 const com::sun::star::ucb::CommandInfo& rCurrCommand = pCommands[ n ];
399 if ( rCurrCommand.Handle == nHandle )
401 rCommand = rCurrCommand;
402 return sal_True;
406 return sal_False;
409 } // namespace ucbhelper
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */