Bump version to 6.4.7.2.M8
[LibreOffice.git] / ucbhelper / source / provider / contenthelper.cxx
bloba7f39fced3d83e04bf40a182f16e447a035df9d3
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 <sal/config.h>
22 #include <com/sun/star/lang/NoSupportException.hpp>
23 #include <com/sun/star/ucb/ContentAction.hpp>
24 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
25 #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
26 #include <com/sun/star/beans/IllegalTypeException.hpp>
27 #include <com/sun/star/beans/NotRemoveableException.hpp>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/beans/PropertyExistException.hpp>
30 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
31 #include <cppuhelper/interfacecontainer.hxx>
32 #include <cppuhelper/supportsservice.hxx>
33 #include <cppuhelper/queryinterface.hxx>
34 #include <ucbhelper/contenthelper.hxx>
35 #include <ucbhelper/contentidentifier.hxx>
36 #include <ucbhelper/contentinfo.hxx>
37 #include <ucbhelper/providerhelper.hxx>
38 #include <ucbhelper/macros.hxx>
40 #include <osl/diagnose.h>
41 #include <osl/mutex.hxx>
42 #include <rtl/ref.hxx>
44 #include <unordered_map>
46 using namespace com::sun::star;
48 namespace ucbhelper_impl
51 class PropertyEventSequence
53 uno::Sequence< beans::PropertyChangeEvent > m_aSeq;
54 sal_uInt32 m_nPos;
56 public:
57 explicit PropertyEventSequence( sal_uInt32 nSize )
58 : m_aSeq( nSize ), m_nPos( 0 ) {};
60 void append( const beans::PropertyChangeEvent& rEvt )
61 { m_aSeq.getArray()[ m_nPos ] = rEvt; ++m_nPos; }
63 const uno::Sequence< beans::PropertyChangeEvent >& getEvents()
64 { m_aSeq.realloc( m_nPos ); return m_aSeq; }
67 typedef void* XPropertiesChangeListenerPtr; // -> Compiler problems!
69 struct equalPtr
71 bool operator()( const XPropertiesChangeListenerPtr& rp1,
72 const XPropertiesChangeListenerPtr& rp2 ) const
74 return ( rp1 == rp2 );
78 struct hashPtr
80 size_t operator()( const XPropertiesChangeListenerPtr& rp ) const
82 return reinterpret_cast<size_t>(rp);
86 typedef std::unordered_map
88 XPropertiesChangeListenerPtr,
89 PropertyEventSequence,
90 hashPtr,
91 equalPtr
93 PropertiesEventListenerMap;
95 typedef cppu::OMultiTypeInterfaceContainerHelperVar<OUString>
96 PropertyChangeListeners;
98 struct ContentImplHelper_Impl
100 rtl::Reference< ::ucbhelper::PropertySetInfo > m_xPropSetInfo;
101 rtl::Reference< ::ucbhelper::CommandProcessorInfo > m_xCommandsInfo;
102 std::unique_ptr<cppu::OInterfaceContainerHelper> m_pDisposeEventListeners;
103 std::unique_ptr<cppu::OInterfaceContainerHelper> m_pContentEventListeners;
104 std::unique_ptr<cppu::OInterfaceContainerHelper> m_pPropSetChangeListeners;
105 std::unique_ptr<cppu::OInterfaceContainerHelper> m_pCommandChangeListeners;
106 std::unique_ptr<PropertyChangeListeners> m_pPropertyChangeListeners;
109 } // namespace ucbhelper_impl
111 using namespace ucbhelper_impl;
113 namespace ucbhelper {
115 ContentImplHelper::ContentImplHelper(
116 const uno::Reference< uno::XComponentContext >& rxContext,
117 const rtl::Reference< ContentProviderImplHelper >& rxProvider,
118 const uno::Reference<
119 css::ucb::XContentIdentifier >& Identifier )
120 : m_pImpl( new ContentImplHelper_Impl ),
121 m_xContext( rxContext ),
122 m_xIdentifier( Identifier ),
123 m_xProvider( rxProvider ),
124 m_nCommandId( 0 )
128 // virtual
129 ContentImplHelper::~ContentImplHelper()
133 void SAL_CALL ContentImplHelper::acquire()
134 throw()
136 cppu::OWeakObject::acquire();
139 void SAL_CALL ContentImplHelper::release()
140 throw()
142 // #144882# - Call to OWeakObject::release may destroy m_xProvider.
143 // Prevent this.
144 rtl::Reference< ContentProviderImplHelper > xKeepProviderAlive(
145 m_xProvider );
147 osl::MutexGuard aGuard( m_xProvider->m_aMutex );
148 OWeakObject::release();
151 uno::Any SAL_CALL ContentImplHelper::queryInterface( const uno::Type & rType )
153 css::uno::Any aRet = cppu::queryInterface( rType,
154 static_cast< lang::XTypeProvider * >(this),
155 static_cast< lang::XServiceInfo * >(this),
156 static_cast< lang::XComponent * >(this),
157 static_cast< css::ucb::XContent * >(this),
158 static_cast< css::ucb::XCommandProcessor * >(this),
159 static_cast< beans::XPropertiesChangeNotifier * >(this),
160 static_cast< css::ucb::XCommandInfoChangeNotifier * >(this),
161 static_cast< beans::XPropertyContainer * >(this),
162 static_cast< beans::XPropertySetInfoChangeNotifier * >(this),
163 static_cast< container::XChild * >(this));
164 return aRet.hasValue() ? aRet : cppu::OWeakObject::queryInterface( rType );
167 XTYPEPROVIDER_IMPL_10( ContentImplHelper,
168 lang::XTypeProvider,
169 lang::XServiceInfo,
170 lang::XComponent,
171 css::ucb::XContent,
172 css::ucb::XCommandProcessor,
173 beans::XPropertiesChangeNotifier,
174 css::ucb::XCommandInfoChangeNotifier,
175 beans::XPropertyContainer,
176 beans::XPropertySetInfoChangeNotifier,
177 container::XChild );
179 // virtual
180 sal_Bool SAL_CALL ContentImplHelper::supportsService(
181 const OUString& ServiceName )
183 return cppu::supportsService(this, ServiceName);
186 // virtual
187 void SAL_CALL ContentImplHelper::dispose()
189 osl::MutexGuard aGuard( m_aMutex );
191 if ( m_pImpl->m_pDisposeEventListeners &&
192 m_pImpl->m_pDisposeEventListeners->getLength() )
194 lang::EventObject aEvt;
195 aEvt.Source = static_cast< lang::XComponent * >( this );
196 m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt );
199 if ( m_pImpl->m_pContentEventListeners &&
200 m_pImpl->m_pContentEventListeners->getLength() )
202 lang::EventObject aEvt;
203 aEvt.Source = static_cast< css::ucb::XContent * >( this );
204 m_pImpl->m_pContentEventListeners->disposeAndClear( aEvt );
207 if ( m_pImpl->m_pPropSetChangeListeners &&
208 m_pImpl->m_pPropSetChangeListeners->getLength() )
210 lang::EventObject aEvt;
211 aEvt.Source
212 = static_cast< beans::XPropertySetInfoChangeNotifier * >( this );
213 m_pImpl->m_pPropSetChangeListeners->disposeAndClear( aEvt );
216 if ( m_pImpl->m_pCommandChangeListeners &&
217 m_pImpl->m_pCommandChangeListeners->getLength() )
219 lang::EventObject aEvt;
220 aEvt.Source = static_cast< css::ucb::XCommandInfoChangeNotifier * >( this );
221 m_pImpl->m_pCommandChangeListeners->disposeAndClear( aEvt );
224 if ( m_pImpl->m_pPropertyChangeListeners )
226 lang::EventObject aEvt;
227 aEvt.Source
228 = static_cast< beans::XPropertiesChangeNotifier * >( this );
229 m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt );
233 // virtual
234 void SAL_CALL ContentImplHelper::addEventListener(
235 const uno::Reference< lang::XEventListener >& Listener )
237 osl::MutexGuard aGuard( m_aMutex );
239 if ( !m_pImpl->m_pDisposeEventListeners )
240 m_pImpl->m_pDisposeEventListeners.reset(
241 new cppu::OInterfaceContainerHelper( m_aMutex ));
243 m_pImpl->m_pDisposeEventListeners->addInterface( Listener );
246 // virtual
247 void SAL_CALL ContentImplHelper::removeEventListener(
248 const uno::Reference< lang::XEventListener >& Listener )
250 osl::MutexGuard aGuard( m_aMutex );
252 if ( m_pImpl->m_pDisposeEventListeners )
253 m_pImpl->m_pDisposeEventListeners->removeInterface( Listener );
256 // virtual
257 uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
258 ContentImplHelper::getIdentifier()
260 return m_xIdentifier;
263 // virtual
264 void SAL_CALL ContentImplHelper::addContentEventListener(
265 const uno::Reference< css::ucb::XContentEventListener >& Listener )
267 osl::MutexGuard aGuard( m_aMutex );
269 if ( !m_pImpl->m_pContentEventListeners )
270 m_pImpl->m_pContentEventListeners.reset(
271 new cppu::OInterfaceContainerHelper( m_aMutex ));
273 m_pImpl->m_pContentEventListeners->addInterface( Listener );
276 // virtual
277 void SAL_CALL ContentImplHelper::removeContentEventListener(
278 const uno::Reference< css::ucb::XContentEventListener >& Listener )
280 osl::MutexGuard aGuard( m_aMutex );
282 if ( m_pImpl->m_pContentEventListeners )
283 m_pImpl->m_pContentEventListeners->removeInterface( Listener );
286 // virtual
287 sal_Int32 SAL_CALL ContentImplHelper::createCommandIdentifier()
289 osl::MutexGuard aGuard( m_aMutex );
291 // Just increase counter on every call to generate an identifier.
292 return ++m_nCommandId;
295 // virtual
296 void SAL_CALL ContentImplHelper::addPropertiesChangeListener(
297 const uno::Sequence< OUString >& PropertyNames,
298 const uno::Reference< beans::XPropertiesChangeListener >& Listener )
300 osl::MutexGuard aGuard( m_aMutex );
302 if ( !m_pImpl->m_pPropertyChangeListeners )
303 m_pImpl->m_pPropertyChangeListeners.reset(
304 new PropertyChangeListeners( m_aMutex ));
306 if ( !PropertyNames.hasElements() )
308 // Note: An empty sequence means a listener for "all" properties.
309 m_pImpl->m_pPropertyChangeListeners->addInterface(
310 OUString(), Listener );
312 else
314 for ( const OUString& rName : PropertyNames )
316 if ( !rName.isEmpty() )
317 m_pImpl->m_pPropertyChangeListeners->addInterface(
318 rName, Listener );
323 // virtual
324 void SAL_CALL ContentImplHelper::removePropertiesChangeListener(
325 const uno::Sequence< OUString >& PropertyNames,
326 const uno::Reference< beans::XPropertiesChangeListener >& Listener )
328 osl::MutexGuard aGuard( m_aMutex );
330 if ( !m_pImpl->m_pPropertyChangeListeners )
331 return;
333 if ( !PropertyNames.hasElements() )
335 // Note: An empty sequence means a listener for "all" properties.
336 m_pImpl->m_pPropertyChangeListeners->removeInterface(
337 OUString(), Listener );
339 else
341 for ( const OUString& rName : PropertyNames )
343 if ( !rName.isEmpty() )
344 m_pImpl->m_pPropertyChangeListeners->removeInterface(
345 rName, Listener );
350 // virtual
351 void SAL_CALL ContentImplHelper::addCommandInfoChangeListener(
352 const uno::Reference< css::ucb::XCommandInfoChangeListener >& Listener )
354 osl::MutexGuard aGuard( m_aMutex );
356 if ( !m_pImpl->m_pCommandChangeListeners )
357 m_pImpl->m_pCommandChangeListeners.reset(
358 new cppu::OInterfaceContainerHelper( m_aMutex ));
360 m_pImpl->m_pCommandChangeListeners->addInterface( Listener );
363 // virtual
364 void SAL_CALL ContentImplHelper::removeCommandInfoChangeListener(
365 const uno::Reference< css::ucb::XCommandInfoChangeListener >& Listener )
367 osl::MutexGuard aGuard( m_aMutex );
369 if ( m_pImpl->m_pCommandChangeListeners )
370 m_pImpl->m_pCommandChangeListeners->removeInterface( Listener );
373 // virtual
374 void SAL_CALL ContentImplHelper::addProperty(
375 const OUString& Name,
376 sal_Int16 Attributes,
377 const uno::Any& DefaultValue )
379 osl::MutexGuard aGuard( m_aMutex );
381 // Make sure a property with the requested name does not already
382 // exist in dynamic and static(!) properties.
384 // @@@ Need real command environment here, but where to get it from?
385 // XPropertyContainer interface should be replaced by
386 // XCommandProcessor commands!
387 uno::Reference< css::ucb::XCommandEnvironment > xEnv;
389 if ( getPropertySetInfo( xEnv )->hasPropertyByName( Name ) )
391 // Property does already exist.
392 throw beans::PropertyExistException();
395 // Add a new dynamic property.
396 // Open/create persistent property set.
397 uno::Reference< css::ucb::XPersistentPropertySet > xSet(
398 getAdditionalPropertySet( true ) );
400 OSL_ENSURE( xSet.is(),
401 "ContentImplHelper::addProperty - No property set!" );
403 if ( xSet.is() )
405 uno::Reference< beans::XPropertyContainer > xContainer(
406 xSet, uno::UNO_QUERY );
408 OSL_ENSURE(
409 xContainer.is(),
410 "ContentImplHelper::addProperty - No property container!" );
412 if ( xContainer.is() )
414 // Property is always removable.
415 Attributes |= beans::PropertyAttribute::REMOVABLE;
419 xContainer->addProperty( Name, Attributes, DefaultValue );
421 catch ( beans::PropertyExistException const & )
423 OSL_FAIL( "ContentImplHelper::addProperty - Exists!" );
424 throw;
426 catch ( beans::IllegalTypeException const & )
428 OSL_FAIL( "ContentImplHelper::addProperty - Wrong Type!" );
429 throw;
431 catch ( lang::IllegalArgumentException const & )
433 OSL_FAIL( "ContentImplHelper::addProperty - Illegal Arg!" );
434 throw;
437 // Success!
439 if ( m_pImpl->m_xPropSetInfo.is() )
441 // Info cached in propertyset info is invalid now!
442 m_pImpl->m_xPropSetInfo->reset();
445 // Notify propertyset info change listeners.
446 if ( m_pImpl->m_pPropSetChangeListeners &&
447 m_pImpl->m_pPropSetChangeListeners->getLength() )
449 beans::PropertySetInfoChangeEvent evt(
450 static_cast< cppu::OWeakObject * >( this ),
451 Name,
452 -1, // No handle available
453 beans::PropertySetInfoChange::PROPERTY_INSERTED );
454 notifyPropertySetInfoChange( evt );
460 // virtual
461 void SAL_CALL ContentImplHelper::removeProperty( const OUString& Name )
463 osl::MutexGuard aGuard( m_aMutex );
467 // @@@ Need real command environment here, but where to get it from?
468 // XPropertyContainer interface should be replaced by
469 // XCommandProcessor commands!
470 uno::Reference< css::ucb::XCommandEnvironment > xEnv;
472 beans::Property aProp
473 = getPropertySetInfo( xEnv )->getPropertyByName( Name );
475 if ( !( aProp.Attributes & beans::PropertyAttribute::REMOVABLE ) )
477 // Not removable!
478 throw beans::NotRemoveableException();
481 catch ( beans::UnknownPropertyException const & )
483 OSL_FAIL( "ContentImplHelper::removeProperty - Unknown!" );
484 throw;
487 // Try to remove property from dynamic property set.
488 // Open persistent property set, if exists.
489 uno::Reference< css::ucb::XPersistentPropertySet > xSet(
490 getAdditionalPropertySet( false ) );
491 if ( xSet.is() )
493 uno::Reference< beans::XPropertyContainer > xContainer(
494 xSet, uno::UNO_QUERY );
496 OSL_ENSURE(
497 xContainer.is(),
498 "ContentImplHelper::removeProperty - No property container!" );
500 if ( xContainer.is() )
504 xContainer->removeProperty( Name );
506 catch ( beans::UnknownPropertyException const & )
508 OSL_FAIL( "ContentImplHelper::removeProperty - Unknown!" );
509 throw;
511 catch ( beans::NotRemoveableException const & )
513 OSL_FAIL(
514 "ContentImplHelper::removeProperty - Unremovable!" );
515 throw;
518 xContainer = nullptr;
520 // Success!
522 if ( !xSet->getPropertySetInfo()->getProperties().hasElements() )
524 // Remove empty propertyset from registry.
525 uno::Reference< css::ucb::XPropertySetRegistry >
526 xReg = xSet->getRegistry();
527 if ( xReg.is() )
529 OUString aKey( xSet->getKey() );
530 xSet = nullptr;
531 xReg->removePropertySet( aKey );
535 if ( m_pImpl->m_xPropSetInfo.is() )
537 // Info cached in propertyset info is invalid now!
538 m_pImpl->m_xPropSetInfo->reset();
541 // Notify propertyset info change listeners.
542 if ( m_pImpl->m_pPropSetChangeListeners &&
543 m_pImpl->m_pPropSetChangeListeners->getLength() )
545 beans::PropertySetInfoChangeEvent evt(
546 static_cast< cppu::OWeakObject * >( this ),
547 Name,
548 -1, // No handle available
549 beans::PropertySetInfoChange::PROPERTY_REMOVED );
550 notifyPropertySetInfoChange( evt );
556 // virtual
557 void SAL_CALL ContentImplHelper::addPropertySetInfoChangeListener(
558 const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener )
560 osl::MutexGuard aGuard( m_aMutex );
562 if ( !m_pImpl->m_pPropSetChangeListeners )
563 m_pImpl->m_pPropSetChangeListeners.reset(
564 new cppu::OInterfaceContainerHelper( m_aMutex ));
566 m_pImpl->m_pPropSetChangeListeners->addInterface( Listener );
569 // virtual
570 void SAL_CALL ContentImplHelper::removePropertySetInfoChangeListener(
571 const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener )
573 osl::MutexGuard aGuard( m_aMutex );
575 if ( m_pImpl->m_pPropSetChangeListeners )
576 m_pImpl->m_pPropSetChangeListeners->removeInterface( Listener );
579 // virtual
580 uno::Reference< uno::XInterface > SAL_CALL ContentImplHelper::getParent()
582 uno::Reference< uno::XInterface > xParent;
583 OUString aURL = getParentURL();
585 if ( !aURL.isEmpty() )
587 uno::Reference< css::ucb::XContentIdentifier > xId(
588 new ContentIdentifier( aURL ) );
591 xParent.set( m_xProvider->queryContent( xId ) );
593 catch ( css::ucb::IllegalIdentifierException const & )
598 return xParent;
601 // virtual
602 void SAL_CALL ContentImplHelper::setParent(
603 const uno::Reference< uno::XInterface >& )
605 throw lang::NoSupportException();
608 uno::Reference< css::ucb::XPersistentPropertySet >
609 ContentImplHelper::getAdditionalPropertySet( bool bCreate )
611 // Get propertyset from provider.
612 return m_xProvider->getAdditionalPropertySet(
613 m_xIdentifier->getContentIdentifier(), bCreate );
616 bool ContentImplHelper::renameAdditionalPropertySet(
617 const OUString& rOldKey,
618 const OUString& rNewKey )
620 return m_xProvider->renameAdditionalPropertySet(
621 rOldKey, rNewKey, true/*bRecursive*/ );
624 bool ContentImplHelper::copyAdditionalPropertySet(
625 const OUString& rSourceKey,
626 const OUString& rTargetKey )
628 return m_xProvider->copyAdditionalPropertySet(
629 rSourceKey, rTargetKey, true/*bRecursive*/ );
632 bool ContentImplHelper::removeAdditionalPropertySet()
634 return m_xProvider->removeAdditionalPropertySet(
635 m_xIdentifier->getContentIdentifier(), true/*bRecursive*/ );
638 void ContentImplHelper::notifyPropertiesChange(
639 const uno::Sequence< beans::PropertyChangeEvent >& evt ) const
641 if ( !m_pImpl->m_pPropertyChangeListeners )
642 return;
644 sal_Int32 nCount = evt.getLength();
645 if ( nCount )
647 // First, notify listeners interested in changes of every property.
648 cppu::OInterfaceContainerHelper* pAllPropsContainer
649 = m_pImpl->m_pPropertyChangeListeners->getContainer(
650 OUString() );
651 if ( pAllPropsContainer )
653 cppu::OInterfaceIteratorHelper aIter( *pAllPropsContainer );
654 while ( aIter.hasMoreElements() )
656 // Propagate event.
657 uno::Reference< beans::XPropertiesChangeListener > xListener(
658 aIter.next(), uno::UNO_QUERY );
659 if ( xListener.is() )
660 xListener->propertiesChange( evt );
664 PropertiesEventListenerMap aListeners;
666 for ( const beans::PropertyChangeEvent& rEvent : evt )
668 const OUString& rName = rEvent.PropertyName;
670 cppu::OInterfaceContainerHelper* pPropsContainer
671 = m_pImpl->m_pPropertyChangeListeners->getContainer( rName );
672 if ( pPropsContainer )
674 cppu::OInterfaceIteratorHelper aIter( *pPropsContainer );
675 while ( aIter.hasMoreElements() )
677 PropertyEventSequence* p = nullptr;
679 beans::XPropertiesChangeListener* pListener =
680 static_cast< beans::XPropertiesChangeListener * >(
681 aIter.next() );
682 PropertiesEventListenerMap::iterator it =
683 aListeners.find( pListener );
684 if ( it == aListeners.end() )
686 // Not in map - create and insert new entry.
687 p = &aListeners.emplace( pListener, PropertyEventSequence(nCount)).first->second;
689 else
690 p = &it->second;
692 if ( p )
693 p->append( rEvent );
698 // Notify listeners.
699 PropertiesEventListenerMap::iterator it = aListeners.begin();
700 while ( !aListeners.empty() )
702 beans::XPropertiesChangeListener* pListener =
703 static_cast< beans::XPropertiesChangeListener * >( (*it).first );
704 PropertyEventSequence pSeq = std::move(it->second);
706 // Remove current element.
707 aListeners.erase( it );
709 // Propagate event.
710 pListener->propertiesChange( pSeq.getEvents() );
712 it = aListeners.begin();
717 void ContentImplHelper::notifyPropertySetInfoChange(
718 const beans::PropertySetInfoChangeEvent& evt ) const
720 if ( !m_pImpl->m_pPropSetChangeListeners )
721 return;
723 // Notify event listeners.
724 cppu::OInterfaceIteratorHelper aIter( *m_pImpl->m_pPropSetChangeListeners );
725 while ( aIter.hasMoreElements() )
727 // Propagate event.
728 uno::Reference< beans::XPropertySetInfoChangeListener >
729 xListener( aIter.next(), uno::UNO_QUERY );
730 if ( xListener.is() )
731 xListener->propertySetInfoChange( evt );
735 void ContentImplHelper::notifyContentEvent(
736 const css::ucb::ContentEvent& evt ) const
738 if ( !m_pImpl->m_pContentEventListeners )
739 return;
741 // Notify event listeners.
742 cppu::OInterfaceIteratorHelper aIter( *m_pImpl->m_pContentEventListeners );
743 while ( aIter.hasMoreElements() )
745 // Propagate event.
746 uno::Reference<
747 css::ucb::XContentEventListener > xListener(
748 aIter.next(), uno::UNO_QUERY );
749 if ( xListener.is() )
750 xListener->contentEvent( evt );
754 void ContentImplHelper::inserted()
756 // Content is not yet registered at provider.
757 m_xProvider->registerNewContent( this );
759 // If the parent content is currently not instantiated, there can be
760 // no listeners interested in changes ;-)
762 rtl::Reference< ContentImplHelper > xParent
763 = m_xProvider->queryExistingContent( getParentURL() );
765 if ( xParent.is() )
767 css::ucb::ContentEvent aEvt(
768 static_cast< cppu::OWeakObject * >( xParent.get() ), // Source
769 css::ucb::ContentAction::INSERTED, // Action
770 this, // Content
771 xParent->getIdentifier() ); // Id
772 xParent->notifyContentEvent( aEvt );
776 void ContentImplHelper::deleted()
778 uno::Reference< css::ucb::XContent > xThis = this;
780 rtl::Reference< ContentImplHelper > xParent
781 = m_xProvider->queryExistingContent( getParentURL() );
783 if ( xParent.is() )
785 // Let parent notify "REMOVED" event.
786 css::ucb::ContentEvent aEvt(
787 static_cast< cppu::OWeakObject * >( xParent.get() ),
788 css::ucb::ContentAction::REMOVED,
789 this,
790 xParent->getIdentifier() );
791 xParent->notifyContentEvent( aEvt );
794 // Notify "DELETED" event.
795 css::ucb::ContentEvent aEvt1(
796 static_cast< cppu::OWeakObject * >( this ),
797 css::ucb::ContentAction::DELETED,
798 this,
799 getIdentifier() );
800 notifyContentEvent( aEvt1 );
802 m_xProvider->removeContent( this );
805 bool ContentImplHelper::exchange(
806 const uno::Reference< css::ucb::XContentIdentifier >& rNewId )
808 uno::Reference< css::ucb::XContent > xThis = this;
810 osl::ClearableMutexGuard aGuard( m_aMutex );
812 rtl::Reference< ContentImplHelper > xContent
813 = m_xProvider->queryExistingContent( rNewId );
814 if ( xContent.is() )
816 // @@@
817 // Big trouble. Another object with the new identity exists.
818 // How shall I mutate to / merge with the other object?
819 return false;
822 uno::Reference< css::ucb::XContentIdentifier > xOldId
823 = getIdentifier();
825 // Re-insert at provider.
826 m_xProvider->removeContent( this );
827 m_xIdentifier = rNewId;
828 m_xProvider->registerNewContent( this );
830 aGuard.clear();
832 // Notify "EXCHANGED" event.
833 css::ucb::ContentEvent aEvt(
834 static_cast< cppu::OWeakObject * >( this ),
835 css::ucb::ContentAction::EXCHANGED,
836 this,
837 xOldId );
838 notifyContentEvent( aEvt );
839 return true;
842 uno::Reference< css::ucb::XCommandInfo >
843 ContentImplHelper::getCommandInfo(
844 const uno::Reference< css::ucb::XCommandEnvironment > & xEnv,
845 bool bCache )
847 osl::MutexGuard aGuard( m_aMutex );
849 if ( !m_pImpl->m_xCommandsInfo.is() )
850 m_pImpl->m_xCommandsInfo
851 = new CommandProcessorInfo( xEnv, this );
852 else if ( !bCache )
853 m_pImpl->m_xCommandsInfo->reset();
855 return uno::Reference< css::ucb::XCommandInfo >(
856 m_pImpl->m_xCommandsInfo.get() );
859 uno::Reference< beans::XPropertySetInfo >
860 ContentImplHelper::getPropertySetInfo(
861 const uno::Reference< css::ucb::XCommandEnvironment > & xEnv,
862 bool bCache )
864 osl::MutexGuard aGuard( m_aMutex );
866 if ( !m_pImpl->m_xPropSetInfo.is() )
867 m_pImpl->m_xPropSetInfo
868 = new PropertySetInfo( xEnv, this );
869 else if ( !bCache )
870 m_pImpl->m_xPropSetInfo->reset();
872 return uno::Reference< beans::XPropertySetInfo >(
873 m_pImpl->m_xPropSetInfo.get() );
876 } // namespace ucbhelper
878 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */