Branch libreoffice-5-0-4
[LibreOffice.git] / ucbhelper / source / provider / contentinfo.cxx
blobb3f0ca9d95a299dff8333d1725805d16b70b7306
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;
38 // PropertySetInfo Implementation.
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 )
55 // virtual
56 PropertySetInfo::~PropertySetInfo()
58 delete m_pProps;
63 // XInterface methods.
65 void SAL_CALL PropertySetInfo::acquire()
66 throw()
68 OWeakObject::acquire();
71 void SAL_CALL PropertySetInfo::release()
72 throw()
74 OWeakObject::release();
77 css::uno::Any SAL_CALL PropertySetInfo::queryInterface( const css::uno::Type & rType )
78 throw( css::uno::RuntimeException, std::exception )
80 css::uno::Any aRet = cppu::queryInterface( rType,
81 (static_cast< lang::XTypeProvider* >(this)),
82 (static_cast< beans::XPropertySetInfo* >(this))
84 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
87 // XTypeProvider methods.
88 XTYPEPROVIDER_IMPL_2( PropertySetInfo,
89 lang::XTypeProvider,
90 beans::XPropertySetInfo );
93 // XPropertySetInfo methods.
97 // virtual
98 uno::Sequence< beans::Property > SAL_CALL PropertySetInfo::getProperties()
99 throw( uno::RuntimeException, std::exception )
101 if ( !m_pProps )
103 osl::MutexGuard aGuard( m_aMutex );
104 if ( !m_pProps )
107 // Get info for core ( native) properties.
112 uno::Sequence< beans::Property > aProps
113 = m_pContent->getProperties( m_xEnv );
114 m_pProps = new uno::Sequence< beans::Property >( aProps );
116 catch ( uno::RuntimeException const & )
118 throw;
120 catch ( uno::Exception const & )
122 m_pProps = new uno::Sequence< beans::Property >( 0 );
126 // Get info for additional properties.
129 uno::Reference< com::sun::star::ucb::XPersistentPropertySet >
130 xSet ( m_pContent->getAdditionalPropertySet( false ) );
132 if ( xSet.is() )
134 // Get property set info.
135 uno::Reference< beans::XPropertySetInfo > xInfo(
136 xSet->getPropertySetInfo() );
137 if ( xInfo.is() )
139 const uno::Sequence< beans::Property >& rAddProps
140 = xInfo->getProperties();
141 sal_Int32 nAddProps = rAddProps.getLength();
142 if ( nAddProps > 0 )
144 sal_Int32 nPos = m_pProps->getLength();
145 m_pProps->realloc( nPos + nAddProps );
147 beans::Property* pProps = m_pProps->getArray();
148 const beans::Property* pAddProps
149 = rAddProps.getConstArray();
151 for ( sal_Int32 n = 0; n < nAddProps; ++n, ++nPos )
152 pProps[ nPos ] = pAddProps[ n ];
158 return *m_pProps;
162 // virtual
163 beans::Property SAL_CALL PropertySetInfo::getPropertyByName(
164 const OUString& aName )
165 throw( beans::UnknownPropertyException, uno::RuntimeException, std::exception )
167 beans::Property aProp;
168 if ( queryProperty( aName, aProp ) )
169 return aProp;
171 throw beans::UnknownPropertyException();
175 // virtual
176 sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName(
177 const OUString& Name )
178 throw( uno::RuntimeException, std::exception )
180 beans::Property aProp;
181 return queryProperty( Name, aProp );
186 // Non-Interface methods.
190 void PropertySetInfo::reset()
192 osl::MutexGuard aGuard( m_aMutex );
193 delete m_pProps;
194 m_pProps = 0;
198 bool PropertySetInfo::queryProperty(
199 const OUString& rName, beans::Property& rProp )
201 osl::MutexGuard aGuard( m_aMutex );
203 getProperties();
205 const beans::Property* pProps = m_pProps->getConstArray();
206 sal_Int32 nCount = m_pProps->getLength();
207 for ( sal_Int32 n = 0; n < nCount; ++n )
209 const beans::Property& rCurrProp = pProps[ n ];
210 if ( rCurrProp.Name == rName )
212 rProp = rCurrProp;
213 return true;
217 return false;
223 // CommandProcessorInfo Implementation.
228 CommandProcessorInfo::CommandProcessorInfo(
229 const uno::Reference< com::sun::star::ucb::XCommandEnvironment >& rxEnv,
230 ContentImplHelper* pContent )
231 : m_xEnv( rxEnv ),
232 m_pCommands( 0 ),
233 m_pContent( pContent )
238 // virtual
239 CommandProcessorInfo::~CommandProcessorInfo()
241 delete m_pCommands;
246 // XInterface methods.
249 void SAL_CALL CommandProcessorInfo::acquire()
250 throw()
252 OWeakObject::acquire();
255 void SAL_CALL CommandProcessorInfo::release()
256 throw()
258 OWeakObject::release();
261 css::uno::Any SAL_CALL CommandProcessorInfo::queryInterface( const css::uno::Type & rType )
262 throw( css::uno::RuntimeException, std::exception )
264 css::uno::Any aRet = cppu::queryInterface( rType,
265 (static_cast< lang::XTypeProvider* >(this)),
266 (static_cast< css::ucb::XCommandInfo* >(this))
268 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
271 // XTypeProvider methods.
275 XTYPEPROVIDER_IMPL_2( CommandProcessorInfo,
276 lang::XTypeProvider,
277 com::sun::star::ucb::XCommandInfo );
281 // XCommandInfo methods.
285 // virtual
286 uno::Sequence< com::sun::star::ucb::CommandInfo > SAL_CALL
287 CommandProcessorInfo::getCommands()
288 throw( uno::RuntimeException, std::exception )
290 if ( !m_pCommands )
292 osl::MutexGuard aGuard( m_aMutex );
293 if ( !m_pCommands )
296 // Get info for commands.
301 uno::Sequence< com::sun::star::ucb::CommandInfo > aCmds
302 = m_pContent->getCommands( m_xEnv );
303 m_pCommands
304 = new uno::Sequence< com::sun::star::ucb::CommandInfo >(
305 aCmds );
307 catch ( uno::RuntimeException const & )
309 throw;
311 catch ( uno::Exception const & )
313 m_pCommands
314 = new uno::Sequence< com::sun::star::ucb::CommandInfo >(
315 0 );
319 return *m_pCommands;
323 // virtual
324 com::sun::star::ucb::CommandInfo SAL_CALL
325 CommandProcessorInfo::getCommandInfoByName(
326 const OUString& Name )
327 throw( com::sun::star::ucb::UnsupportedCommandException,
328 uno::RuntimeException, std::exception )
330 com::sun::star::ucb::CommandInfo aInfo;
331 if ( queryCommand( Name, aInfo ) )
332 return aInfo;
334 throw com::sun::star::ucb::UnsupportedCommandException();
338 // virtual
339 com::sun::star::ucb::CommandInfo SAL_CALL
340 CommandProcessorInfo::getCommandInfoByHandle( sal_Int32 Handle )
341 throw( com::sun::star::ucb::UnsupportedCommandException,
342 uno::RuntimeException, std::exception )
344 com::sun::star::ucb::CommandInfo aInfo;
345 if ( queryCommand( Handle, aInfo ) )
346 return aInfo;
348 throw com::sun::star::ucb::UnsupportedCommandException();
352 // virtual
353 sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName(
354 const OUString& Name )
355 throw( uno::RuntimeException, std::exception )
357 com::sun::star::ucb::CommandInfo aInfo;
358 return queryCommand( Name, aInfo );
362 // virtual
363 sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle )
364 throw( uno::RuntimeException, std::exception )
366 com::sun::star::ucb::CommandInfo aInfo;
367 return queryCommand( Handle, aInfo );
372 // Non-Interface methods.
376 void CommandProcessorInfo::reset()
378 osl::MutexGuard aGuard( m_aMutex );
379 delete m_pCommands;
380 m_pCommands = 0;
385 bool CommandProcessorInfo::queryCommand(
386 const OUString& rName,
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.Name == rName )
401 rCommand = rCurrCommand;
402 return true;
406 return false;
410 bool CommandProcessorInfo::queryCommand(
411 sal_Int32 nHandle,
412 com::sun::star::ucb::CommandInfo& rCommand )
414 osl::MutexGuard aGuard( m_aMutex );
416 getCommands();
418 const com::sun::star::ucb::CommandInfo* pCommands
419 = m_pCommands->getConstArray();
420 sal_Int32 nCount = m_pCommands->getLength();
421 for ( sal_Int32 n = 0; n < nCount; ++n )
423 const com::sun::star::ucb::CommandInfo& rCurrCommand = pCommands[ n ];
424 if ( rCurrCommand.Handle == nHandle )
426 rCommand = rCurrCommand;
427 return true;
431 return false;
434 } // namespace ucbhelper
436 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */