Branch libreoffice-5-0-4
[LibreOffice.git] / ucbhelper / source / provider / contenthelper.cxx
blob280d2422354c166c2b1f59b8567d81a15d0d1900
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 #include <com/sun/star/ucb/ContentAction.hpp>
21 #include <com/sun/star/ucb/CommandInfoChange.hpp>
22 #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
24 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
25 #include <cppuhelper/interfacecontainer.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <ucbhelper/contenthelper.hxx>
28 #include <ucbhelper/contentidentifier.hxx>
29 #include <ucbhelper/contentinfo.hxx>
30 #include <ucbhelper/providerhelper.hxx>
32 #include "osl/diagnose.h"
33 #include "osl/mutex.hxx"
34 #include "rtl/ref.hxx"
36 #include <unordered_map>
38 using namespace com::sun::star;
40 namespace ucbhelper_impl
43 class PropertyEventSequence
45 uno::Sequence< beans::PropertyChangeEvent > m_aSeq;
46 sal_uInt32 m_nPos;
48 public:
49 PropertyEventSequence( sal_uInt32 nSize )
50 : m_aSeq( nSize ), m_nPos( 0 ) {};
52 void append( const beans::PropertyChangeEvent& rEvt )
53 { m_aSeq.getArray()[ m_nPos ] = rEvt; ++m_nPos; }
55 const uno::Sequence< beans::PropertyChangeEvent >& getEvents()
56 { m_aSeq.realloc( m_nPos ); return m_aSeq; }
59 typedef void* XPropertiesChangeListenerPtr; // -> Compiler problems!
61 struct equalPtr
63 bool operator()( const XPropertiesChangeListenerPtr& rp1,
64 const XPropertiesChangeListenerPtr& rp2 ) const
66 return ( rp1 == rp2 );
70 struct hashPtr
72 size_t operator()( const XPropertiesChangeListenerPtr& rp ) const
74 return reinterpret_cast<size_t>(rp);
78 typedef std::unordered_map
80 XPropertiesChangeListenerPtr,
81 PropertyEventSequence*,
82 hashPtr,
83 equalPtr
85 PropertiesEventListenerMap;
87 typedef cppu::OMultiTypeInterfaceContainerHelperVar<OUString>
88 PropertyChangeListeners;
90 struct ContentImplHelper_Impl
92 rtl::Reference< ::ucbhelper::PropertySetInfo > m_xPropSetInfo;
93 rtl::Reference< ::ucbhelper::CommandProcessorInfo > m_xCommandsInfo;
94 cppu::OInterfaceContainerHelper* m_pDisposeEventListeners;
95 cppu::OInterfaceContainerHelper* m_pContentEventListeners;
96 cppu::OInterfaceContainerHelper* m_pPropSetChangeListeners;
97 cppu::OInterfaceContainerHelper* m_pCommandChangeListeners;
98 PropertyChangeListeners* m_pPropertyChangeListeners;
100 ContentImplHelper_Impl()
101 : m_pDisposeEventListeners( 0 ),
102 m_pContentEventListeners( 0 ),
103 m_pPropSetChangeListeners( 0 ),
104 m_pCommandChangeListeners( 0 ),
105 m_pPropertyChangeListeners( 0 ) {}
107 ~ContentImplHelper_Impl()
109 delete m_pDisposeEventListeners;
110 delete m_pContentEventListeners;
111 delete m_pPropSetChangeListeners;
112 delete m_pCommandChangeListeners;
113 delete m_pPropertyChangeListeners;
117 } // namespace ucbhelper_impl
119 using namespace ucbhelper_impl;
121 namespace ucbhelper {
123 ContentImplHelper::ContentImplHelper(
124 const uno::Reference< uno::XComponentContext >& rxContext,
125 const rtl::Reference< ContentProviderImplHelper >& rxProvider,
126 const uno::Reference<
127 com::sun::star::ucb::XContentIdentifier >& Identifier )
128 : m_pImpl( new ContentImplHelper_Impl ),
129 m_xContext( rxContext ),
130 m_xIdentifier( Identifier ),
131 m_xProvider( rxProvider ),
132 m_nCommandId( 0 )
136 // virtual
137 ContentImplHelper::~ContentImplHelper()
139 delete m_pImpl;
142 void SAL_CALL ContentImplHelper::acquire()
143 throw()
145 cppu::OWeakObject::acquire();
148 void SAL_CALL ContentImplHelper::release()
149 throw()
151 // #144882# - Call to OWeakObject::release may destroy m_xProvider.
152 // Prevent this.
153 rtl::Reference< ContentProviderImplHelper > xKeepProviderAlive(
154 m_xProvider );
157 osl::MutexGuard aGuard( m_xProvider->m_aMutex );
158 OWeakObject::release();
162 uno::Any SAL_CALL ContentImplHelper::queryInterface( const uno::Type & rType )
163 throw( uno::RuntimeException, std::exception )
165 com::sun::star::uno::Any aRet = cppu::queryInterface( rType,
166 static_cast< lang::XTypeProvider * >(this),
167 static_cast< lang::XServiceInfo * >(this),
168 static_cast< lang::XComponent * >(this),
169 static_cast< com::sun::star::ucb::XContent * >(this),
170 static_cast< com::sun::star::ucb::XCommandProcessor * >(this),
171 static_cast< beans::XPropertiesChangeNotifier * >(this),
172 static_cast< com::sun::star::ucb::XCommandInfoChangeNotifier * >(this),
173 static_cast< beans::XPropertyContainer * >(this),
174 static_cast< beans::XPropertySetInfoChangeNotifier * >(this),
175 static_cast< container::XChild * >(this));
176 return aRet.hasValue() ? aRet : cppu::OWeakObject::queryInterface( rType );
179 XTYPEPROVIDER_IMPL_10( ContentImplHelper,
180 lang::XTypeProvider,
181 lang::XServiceInfo,
182 lang::XComponent,
183 com::sun::star::ucb::XContent,
184 com::sun::star::ucb::XCommandProcessor,
185 beans::XPropertiesChangeNotifier,
186 com::sun::star::ucb::XCommandInfoChangeNotifier,
187 beans::XPropertyContainer,
188 beans::XPropertySetInfoChangeNotifier,
189 container::XChild );
191 // virtual
192 sal_Bool SAL_CALL ContentImplHelper::supportsService(
193 const OUString& ServiceName )
194 throw( uno::RuntimeException, std::exception )
196 return cppu::supportsService(this, ServiceName);
199 // virtual
200 void SAL_CALL ContentImplHelper::dispose()
201 throw( uno::RuntimeException, std::exception )
203 osl::MutexGuard aGuard( m_aMutex );
205 if ( m_pImpl->m_pDisposeEventListeners &&
206 m_pImpl->m_pDisposeEventListeners->getLength() )
208 lang::EventObject aEvt;
209 aEvt.Source = static_cast< lang::XComponent * >( this );
210 m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt );
213 if ( m_pImpl->m_pContentEventListeners &&
214 m_pImpl->m_pContentEventListeners->getLength() )
216 lang::EventObject aEvt;
217 aEvt.Source = static_cast< com::sun::star::ucb::XContent * >( this );
218 m_pImpl->m_pContentEventListeners->disposeAndClear( aEvt );
221 if ( m_pImpl->m_pPropSetChangeListeners &&
222 m_pImpl->m_pPropSetChangeListeners->getLength() )
224 lang::EventObject aEvt;
225 aEvt.Source
226 = static_cast< beans::XPropertySetInfoChangeNotifier * >( this );
227 m_pImpl->m_pPropSetChangeListeners->disposeAndClear( aEvt );
230 if ( m_pImpl->m_pCommandChangeListeners &&
231 m_pImpl->m_pCommandChangeListeners->getLength() )
233 lang::EventObject aEvt;
234 aEvt.Source = static_cast< com::sun::star::ucb::XCommandInfoChangeNotifier * >( this );
235 m_pImpl->m_pCommandChangeListeners->disposeAndClear( aEvt );
238 if ( m_pImpl->m_pPropertyChangeListeners )
240 lang::EventObject aEvt;
241 aEvt.Source
242 = static_cast< beans::XPropertiesChangeNotifier * >( this );
243 m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt );
247 // virtual
248 void SAL_CALL ContentImplHelper::addEventListener(
249 const uno::Reference< lang::XEventListener >& Listener )
250 throw( uno::RuntimeException, std::exception )
252 osl::MutexGuard aGuard( m_aMutex );
254 if ( !m_pImpl->m_pDisposeEventListeners )
255 m_pImpl->m_pDisposeEventListeners
256 = new cppu::OInterfaceContainerHelper( m_aMutex );
258 m_pImpl->m_pDisposeEventListeners->addInterface( Listener );
261 // virtual
262 void SAL_CALL ContentImplHelper::removeEventListener(
263 const uno::Reference< lang::XEventListener >& Listener )
264 throw( uno::RuntimeException, std::exception )
266 osl::MutexGuard aGuard( m_aMutex );
268 if ( m_pImpl->m_pDisposeEventListeners )
269 m_pImpl->m_pDisposeEventListeners->removeInterface( Listener );
272 // virtual
273 uno::Reference< com::sun::star::ucb::XContentIdentifier > SAL_CALL
274 ContentImplHelper::getIdentifier()
275 throw( uno::RuntimeException, std::exception )
277 return m_xIdentifier;
280 // virtual
281 void SAL_CALL ContentImplHelper::addContentEventListener(
282 const uno::Reference< com::sun::star::ucb::XContentEventListener >& Listener )
283 throw( uno::RuntimeException, std::exception )
285 osl::MutexGuard aGuard( m_aMutex );
287 if ( !m_pImpl->m_pContentEventListeners )
288 m_pImpl->m_pContentEventListeners
289 = new cppu::OInterfaceContainerHelper( m_aMutex );
291 m_pImpl->m_pContentEventListeners->addInterface( Listener );
294 // virtual
295 void SAL_CALL ContentImplHelper::removeContentEventListener(
296 const uno::Reference< com::sun::star::ucb::XContentEventListener >& Listener )
297 throw( uno::RuntimeException, std::exception )
299 osl::MutexGuard aGuard( m_aMutex );
301 if ( m_pImpl->m_pContentEventListeners )
302 m_pImpl->m_pContentEventListeners->removeInterface( Listener );
305 // virtual
306 sal_Int32 SAL_CALL ContentImplHelper::createCommandIdentifier()
307 throw( uno::RuntimeException, std::exception )
309 osl::MutexGuard aGuard( m_aMutex );
311 // Just increase counter on every call to generate an identifier.
312 return ++m_nCommandId;
315 // virtual
316 void SAL_CALL ContentImplHelper::addPropertiesChangeListener(
317 const uno::Sequence< OUString >& PropertyNames,
318 const uno::Reference< beans::XPropertiesChangeListener >& Listener )
319 throw( uno::RuntimeException, std::exception )
321 osl::MutexGuard aGuard( m_aMutex );
323 if ( !m_pImpl->m_pPropertyChangeListeners )
324 m_pImpl->m_pPropertyChangeListeners
325 = new PropertyChangeListeners( m_aMutex );
327 sal_Int32 nCount = PropertyNames.getLength();
328 if ( !nCount )
330 // Note: An empty sequence means a listener for "all" properties.
331 m_pImpl->m_pPropertyChangeListeners->addInterface(
332 OUString(), Listener );
334 else
336 const OUString* pSeq = PropertyNames.getConstArray();
338 for ( sal_Int32 n = 0; n < nCount; ++n )
340 const OUString& rName = pSeq[ n ];
341 if ( !rName.isEmpty() )
342 m_pImpl->m_pPropertyChangeListeners->addInterface(
343 rName, Listener );
348 // virtual
349 void SAL_CALL ContentImplHelper::removePropertiesChangeListener(
350 const uno::Sequence< OUString >& PropertyNames,
351 const uno::Reference< beans::XPropertiesChangeListener >& Listener )
352 throw( uno::RuntimeException, std::exception )
354 osl::MutexGuard aGuard( m_aMutex );
356 if ( !m_pImpl->m_pPropertyChangeListeners )
357 return;
359 sal_Int32 nCount = PropertyNames.getLength();
360 if ( !nCount )
362 // Note: An empty sequence means a listener for "all" properties.
363 m_pImpl->m_pPropertyChangeListeners->removeInterface(
364 OUString(), Listener );
366 else
368 const OUString* pSeq = PropertyNames.getConstArray();
370 for ( sal_Int32 n = 0; n < nCount; ++n )
372 const OUString& rName = pSeq[ n ];
373 if ( !rName.isEmpty() )
374 m_pImpl->m_pPropertyChangeListeners->removeInterface(
375 rName, Listener );
380 // virtual
381 void SAL_CALL ContentImplHelper::addCommandInfoChangeListener(
382 const uno::Reference< com::sun::star::ucb::XCommandInfoChangeListener >& Listener )
383 throw( uno::RuntimeException, std::exception )
385 osl::MutexGuard aGuard( m_aMutex );
387 if ( !m_pImpl->m_pCommandChangeListeners )
388 m_pImpl->m_pCommandChangeListeners
389 = new cppu::OInterfaceContainerHelper( m_aMutex );
391 m_pImpl->m_pCommandChangeListeners->addInterface( Listener );
394 // virtual
395 void SAL_CALL ContentImplHelper::removeCommandInfoChangeListener(
396 const uno::Reference< com::sun::star::ucb::XCommandInfoChangeListener >& Listener )
397 throw( uno::RuntimeException, std::exception )
399 osl::MutexGuard aGuard( m_aMutex );
401 if ( m_pImpl->m_pCommandChangeListeners )
402 m_pImpl->m_pCommandChangeListeners->removeInterface( Listener );
405 // virtual
406 void SAL_CALL ContentImplHelper::addProperty(
407 const OUString& Name,
408 sal_Int16 Attributes,
409 const uno::Any& DefaultValue )
410 throw( beans::PropertyExistException,
411 beans::IllegalTypeException,
412 lang::IllegalArgumentException,
413 uno::RuntimeException, std::exception )
415 osl::MutexGuard aGuard( m_aMutex );
417 // Make sure a property with the requested name does not already
418 // exist in dynamic and static(!) properties.
420 // @@@ Need real command environment here, but where to get it from?
421 // XPropertyContainer interface should be replaced by
422 // XCommandProcessor commands!
423 uno::Reference< com::sun::star::ucb::XCommandEnvironment > xEnv;
425 if ( getPropertySetInfo( xEnv )->hasPropertyByName( Name ) )
427 // Property does already exist.
428 throw beans::PropertyExistException();
431 // Add a new dynamic property.
432 // Open/create persistent property set.
433 uno::Reference< com::sun::star::ucb::XPersistentPropertySet > xSet(
434 getAdditionalPropertySet( true ) );
436 OSL_ENSURE( xSet.is(),
437 "ContentImplHelper::addProperty - No property set!" );
439 if ( xSet.is() )
441 uno::Reference< beans::XPropertyContainer > xContainer(
442 xSet, uno::UNO_QUERY );
444 OSL_ENSURE(
445 xContainer.is(),
446 "ContentImplHelper::addProperty - No property container!" );
448 if ( xContainer.is() )
450 // Property is always removable.
451 Attributes |= beans::PropertyAttribute::REMOVABLE;
455 xContainer->addProperty( Name, Attributes, DefaultValue );
457 catch ( beans::PropertyExistException const & )
459 OSL_FAIL( "ContentImplHelper::addProperty - Exists!" );
460 throw;
462 catch ( beans::IllegalTypeException const & )
464 OSL_FAIL( "ContentImplHelper::addProperty - Wrong Type!" );
465 throw;
467 catch ( lang::IllegalArgumentException const & )
469 OSL_FAIL( "ContentImplHelper::addProperty - Illegal Arg!" );
470 throw;
473 // Success!
475 if ( m_pImpl->m_xPropSetInfo.is() )
477 // Info cached in propertyset info is invalid now!
478 m_pImpl->m_xPropSetInfo->reset();
481 // Notify propertyset info change listeners.
482 if ( m_pImpl->m_pPropSetChangeListeners &&
483 m_pImpl->m_pPropSetChangeListeners->getLength() )
485 beans::PropertySetInfoChangeEvent evt(
486 static_cast< cppu::OWeakObject * >( this ),
487 Name,
488 -1, // No handle available
489 beans::PropertySetInfoChange::PROPERTY_INSERTED );
490 notifyPropertySetInfoChange( evt );
496 // virtual
497 void SAL_CALL ContentImplHelper::removeProperty( const OUString& Name )
498 throw( beans::UnknownPropertyException,
499 beans::NotRemoveableException,
500 uno::RuntimeException, std::exception )
502 osl::MutexGuard aGuard( m_aMutex );
506 // @@@ Need real command environment here, but where to get it from?
507 // XPropertyContainer interface should be replaced by
508 // XCommandProcessor commands!
509 uno::Reference< com::sun::star::ucb::XCommandEnvironment > xEnv;
511 beans::Property aProp
512 = getPropertySetInfo( xEnv )->getPropertyByName( Name );
514 if ( !( aProp.Attributes & beans::PropertyAttribute::REMOVABLE ) )
516 // Not removable!
517 throw beans::NotRemoveableException();
520 catch ( beans::UnknownPropertyException const & )
522 OSL_FAIL( "ContentImplHelper::removeProperty - Unknown!" );
523 throw;
526 // Try to remove property from dynamic property set.
527 // Open persistent property set, if exists.
528 uno::Reference< com::sun::star::ucb::XPersistentPropertySet > xSet(
529 getAdditionalPropertySet( false ) );
530 if ( xSet.is() )
532 uno::Reference< beans::XPropertyContainer > xContainer(
533 xSet, uno::UNO_QUERY );
535 OSL_ENSURE(
536 xContainer.is(),
537 "ContentImplHelper::removeProperty - No property container!" );
539 if ( xContainer.is() )
543 xContainer->removeProperty( Name );
545 catch ( beans::UnknownPropertyException const & )
547 OSL_FAIL( "ContentImplHelper::removeProperty - Unknown!" );
548 throw;
550 catch ( beans::NotRemoveableException const & )
552 OSL_FAIL(
553 "ContentImplHelper::removeProperty - Unremovable!" );
554 throw;
557 xContainer = 0;
559 // Success!
561 if ( xSet->getPropertySetInfo()->getProperties().getLength() == 0 )
563 // Remove empty propertyset from registry.
564 uno::Reference< com::sun::star::ucb::XPropertySetRegistry >
565 xReg = xSet->getRegistry();
566 if ( xReg.is() )
568 OUString aKey( xSet->getKey() );
569 xSet = 0;
570 xReg->removePropertySet( aKey );
574 if ( m_pImpl->m_xPropSetInfo.is() )
576 // Info cached in propertyset info is invalid now!
577 m_pImpl->m_xPropSetInfo->reset();
580 // Notify propertyset info change listeners.
581 if ( m_pImpl->m_pPropSetChangeListeners &&
582 m_pImpl->m_pPropSetChangeListeners->getLength() )
584 beans::PropertySetInfoChangeEvent evt(
585 static_cast< cppu::OWeakObject * >( this ),
586 Name,
587 -1, // No handle available
588 beans::PropertySetInfoChange::PROPERTY_REMOVED );
589 notifyPropertySetInfoChange( evt );
595 // virtual
596 void SAL_CALL ContentImplHelper::addPropertySetInfoChangeListener(
597 const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener )
598 throw( uno::RuntimeException, std::exception )
600 osl::MutexGuard aGuard( m_aMutex );
602 if ( !m_pImpl->m_pPropSetChangeListeners )
603 m_pImpl->m_pPropSetChangeListeners
604 = new cppu::OInterfaceContainerHelper( m_aMutex );
606 m_pImpl->m_pPropSetChangeListeners->addInterface( Listener );
609 // virtual
610 void SAL_CALL ContentImplHelper::removePropertySetInfoChangeListener(
611 const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener )
612 throw( uno::RuntimeException, std::exception )
614 osl::MutexGuard aGuard( m_aMutex );
616 if ( m_pImpl->m_pPropSetChangeListeners )
617 m_pImpl->m_pPropSetChangeListeners->removeInterface( Listener );
620 // virtual
621 uno::Reference< uno::XInterface > SAL_CALL ContentImplHelper::getParent()
622 throw( uno::RuntimeException, std::exception )
624 uno::Reference< uno::XInterface > xParent;
625 OUString aURL = getParentURL();
627 if ( !aURL.isEmpty() )
629 uno::Reference< com::sun::star::ucb::XContentIdentifier > xId(
630 new ContentIdentifier( aURL ) );
633 xParent.set( m_xProvider->queryContent( xId ) );
635 catch ( com::sun::star::ucb::IllegalIdentifierException const & )
640 return xParent;
643 // virtual
644 void SAL_CALL ContentImplHelper::setParent(
645 const uno::Reference< uno::XInterface >& )
646 throw( lang::NoSupportException, uno::RuntimeException, std::exception )
648 throw lang::NoSupportException();
651 uno::Reference< com::sun::star::ucb::XPersistentPropertySet >
652 ContentImplHelper::getAdditionalPropertySet( bool bCreate )
654 // Get propertyset from provider.
655 return m_xProvider->getAdditionalPropertySet(
656 m_xIdentifier->getContentIdentifier(), bCreate );
659 bool ContentImplHelper::renameAdditionalPropertySet(
660 const OUString& rOldKey,
661 const OUString& rNewKey,
662 bool bRecursive )
664 return m_xProvider->renameAdditionalPropertySet(
665 rOldKey, rNewKey, bRecursive );
668 bool ContentImplHelper::copyAdditionalPropertySet(
669 const OUString& rSourceKey,
670 const OUString& rTargetKey,
671 bool bRecursive )
673 return m_xProvider->copyAdditionalPropertySet(
674 rSourceKey, rTargetKey, bRecursive );
677 bool ContentImplHelper::removeAdditionalPropertySet( bool bRecursive )
679 return m_xProvider->removeAdditionalPropertySet(
680 m_xIdentifier->getContentIdentifier(), bRecursive );
683 void ContentImplHelper::notifyPropertiesChange(
684 const uno::Sequence< beans::PropertyChangeEvent >& evt ) const
686 if ( !m_pImpl->m_pPropertyChangeListeners )
687 return;
689 sal_Int32 nCount = evt.getLength();
690 if ( nCount )
692 // First, notify listeners interested in changes of every property.
693 cppu::OInterfaceContainerHelper* pAllPropsContainer
694 = m_pImpl->m_pPropertyChangeListeners->getContainer(
695 OUString() );
696 if ( pAllPropsContainer )
698 cppu::OInterfaceIteratorHelper aIter( *pAllPropsContainer );
699 while ( aIter.hasMoreElements() )
701 // Propagate event.
702 uno::Reference< beans::XPropertiesChangeListener > xListener(
703 aIter.next(), uno::UNO_QUERY );
704 if ( xListener.is() )
705 xListener->propertiesChange( evt );
709 PropertiesEventListenerMap aListeners;
711 const beans::PropertyChangeEvent* pEvents = evt.getConstArray();
713 for ( sal_Int32 n = 0; n < nCount; ++n )
715 const beans::PropertyChangeEvent& rEvent = pEvents[ n ];
716 const OUString& rName = rEvent.PropertyName;
718 cppu::OInterfaceContainerHelper* pPropsContainer
719 = m_pImpl->m_pPropertyChangeListeners->getContainer( rName );
720 if ( pPropsContainer )
722 cppu::OInterfaceIteratorHelper aIter( *pPropsContainer );
723 while ( aIter.hasMoreElements() )
725 PropertyEventSequence* p = NULL;
727 beans::XPropertiesChangeListener* pListener =
728 static_cast< beans::XPropertiesChangeListener * >(
729 aIter.next() );
730 PropertiesEventListenerMap::iterator it =
731 aListeners.find( pListener );
732 if ( it == aListeners.end() )
734 // Not in map - create and insert new entry.
735 p = new PropertyEventSequence( nCount );
736 aListeners[ pListener ] = p;
738 else
739 p = (*it).second;
741 if ( p )
742 p->append( rEvent );
747 // Notify listeners.
748 PropertiesEventListenerMap::iterator it = aListeners.begin();
749 while ( !aListeners.empty() )
751 beans::XPropertiesChangeListener* pListener =
752 static_cast< beans::XPropertiesChangeListener * >( (*it).first );
753 PropertyEventSequence* pSeq = (*it).second;
755 // Remove current element.
756 aListeners.erase( it );
758 // Propagate event.
759 pListener->propertiesChange( pSeq->getEvents() );
761 delete pSeq;
763 it = aListeners.begin();
768 void ContentImplHelper::notifyPropertySetInfoChange(
769 const beans::PropertySetInfoChangeEvent& evt ) const
771 if ( !m_pImpl->m_pPropSetChangeListeners )
772 return;
774 // Notify event listeners.
775 cppu::OInterfaceIteratorHelper aIter( *m_pImpl->m_pPropSetChangeListeners );
776 while ( aIter.hasMoreElements() )
778 // Propagate event.
779 uno::Reference< beans::XPropertySetInfoChangeListener >
780 xListener( aIter.next(), uno::UNO_QUERY );
781 if ( xListener.is() )
782 xListener->propertySetInfoChange( evt );
786 void ContentImplHelper::notifyContentEvent(
787 const com::sun::star::ucb::ContentEvent& evt ) const
789 if ( !m_pImpl->m_pContentEventListeners )
790 return;
792 // Notify event listeners.
793 cppu::OInterfaceIteratorHelper aIter( *m_pImpl->m_pContentEventListeners );
794 while ( aIter.hasMoreElements() )
796 // Propagate event.
797 uno::Reference<
798 com::sun::star::ucb::XContentEventListener > xListener(
799 aIter.next(), uno::UNO_QUERY );
800 if ( xListener.is() )
801 xListener->contentEvent( evt );
805 void ContentImplHelper::inserted()
807 // Content is not yet registered at provider.
808 m_xProvider->registerNewContent( this );
810 // If the parent content is currently not instantiated, there can be
811 // no listeners interested in changes ;-)
813 rtl::Reference< ContentImplHelper > xParent
814 = m_xProvider->queryExistingContent( getParentURL() );
816 if ( xParent.is() )
818 com::sun::star::ucb::ContentEvent aEvt(
819 static_cast< cppu::OWeakObject * >( xParent.get() ), // Source
820 com::sun::star::ucb::ContentAction::INSERTED, // Action
821 this, // Content
822 xParent->getIdentifier() ); // Id
823 xParent->notifyContentEvent( aEvt );
827 void ContentImplHelper::deleted()
829 uno::Reference< com::sun::star::ucb::XContent > xThis = this;
831 rtl::Reference< ContentImplHelper > xParent
832 = m_xProvider->queryExistingContent( getParentURL() );
834 if ( xParent.is() )
836 // Let parent notify "REMOVED" event.
837 com::sun::star::ucb::ContentEvent aEvt(
838 static_cast< cppu::OWeakObject * >( xParent.get() ),
839 com::sun::star::ucb::ContentAction::REMOVED,
840 this,
841 xParent->getIdentifier() );
842 xParent->notifyContentEvent( aEvt );
845 // Notify "DELETED" event.
846 com::sun::star::ucb::ContentEvent aEvt1(
847 static_cast< cppu::OWeakObject * >( this ),
848 com::sun::star::ucb::ContentAction::DELETED,
849 this,
850 getIdentifier() );
851 notifyContentEvent( aEvt1 );
853 m_xProvider->removeContent( this );
856 bool ContentImplHelper::exchange(
857 const uno::Reference< com::sun::star::ucb::XContentIdentifier >& rNewId )
859 uno::Reference< com::sun::star::ucb::XContent > xThis = this;
861 osl::ClearableMutexGuard aGuard( m_aMutex );
863 rtl::Reference< ContentImplHelper > xContent
864 = m_xProvider->queryExistingContent( rNewId );
865 if ( xContent.is() )
867 // @@@
868 // Big trouble. Another object with the new identity exists.
869 // How shall I mutate to / merge with the other object?
870 return false;
873 uno::Reference< com::sun::star::ucb::XContentIdentifier > xOldId
874 = getIdentifier();
876 // Re-insert at provider.
877 m_xProvider->removeContent( this );
878 m_xIdentifier = rNewId;
879 m_xProvider->registerNewContent( this );
881 aGuard.clear();
883 // Notify "EXCHANGED" event.
884 com::sun::star::ucb::ContentEvent aEvt(
885 static_cast< cppu::OWeakObject * >( this ),
886 com::sun::star::ucb::ContentAction::EXCHANGED,
887 this,
888 xOldId );
889 notifyContentEvent( aEvt );
890 return true;
893 uno::Reference< com::sun::star::ucb::XCommandInfo >
894 ContentImplHelper::getCommandInfo(
895 const uno::Reference< com::sun::star::ucb::XCommandEnvironment > & xEnv,
896 bool bCache )
898 osl::MutexGuard aGuard( m_aMutex );
900 if ( !m_pImpl->m_xCommandsInfo.is() )
901 m_pImpl->m_xCommandsInfo
902 = new CommandProcessorInfo( xEnv, this );
903 else if ( !bCache )
904 m_pImpl->m_xCommandsInfo->reset();
906 return uno::Reference< com::sun::star::ucb::XCommandInfo >(
907 m_pImpl->m_xCommandsInfo.get() );
910 uno::Reference< beans::XPropertySetInfo >
911 ContentImplHelper::getPropertySetInfo(
912 const uno::Reference< com::sun::star::ucb::XCommandEnvironment > & xEnv,
913 bool bCache )
915 osl::MutexGuard aGuard( m_aMutex );
917 if ( !m_pImpl->m_xPropSetInfo.is() )
918 m_pImpl->m_xPropSetInfo
919 = new PropertySetInfo( xEnv, this );
920 else if ( !bCache )
921 m_pImpl->m_xPropSetInfo->reset();
923 return uno::Reference< beans::XPropertySetInfo >(
924 m_pImpl->m_xPropSetInfo.get() );
927 } // namespace ucbhelper
929 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */