Update ooo320-m1
[ooovba.git] / ucbhelper / source / provider / contenthelper.cxx
blob917ddba4772924d249c8eb388a586158fe7f03ef
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: contenthelper.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucbhelper.hxx"
33 /**************************************************************************
34 TODO
35 **************************************************************************
37 *************************************************************************/
39 #include <hash_map>
40 #include <com/sun/star/ucb/ContentAction.hpp>
41 #include <com/sun/star/ucb/CommandInfoChange.hpp>
42 #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
43 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 #include <com/sun/star/beans/PropertySetInfoChange.hpp>
45 #include <cppuhelper/interfacecontainer.hxx>
47 #include "osl/diagnose.h"
48 #include "osl/mutex.hxx"
49 #include "rtl/ref.hxx"
50 #include <ucbhelper/contentidentifier.hxx>
51 #include <ucbhelper/contenthelper.hxx>
52 #include <ucbhelper/providerhelper.hxx>
53 #include <ucbhelper/contentinfo.hxx>
55 using namespace com::sun::star;
57 namespace ucbhelper_impl
60 //=========================================================================
62 // class PropertyEventSequence.
64 //=========================================================================
66 class PropertyEventSequence
68 uno::Sequence< beans::PropertyChangeEvent > m_aSeq;
69 sal_uInt32 m_nPos;
71 public:
72 PropertyEventSequence( sal_uInt32 nSize )
73 : m_aSeq( nSize ), m_nPos( 0 ) {};
75 void append( const beans::PropertyChangeEvent& rEvt )
76 { m_aSeq.getArray()[ m_nPos ] = rEvt; ++m_nPos; }
78 const uno::Sequence< beans::PropertyChangeEvent >& getEvents()
79 { m_aSeq.realloc( m_nPos ); return m_aSeq; }
82 //=========================================================================
84 // PropertiesEventListenerMap.
86 //=========================================================================
88 typedef void* XPropertiesChangeListenerPtr; // -> Compiler problems!
90 struct equalPtr
92 bool operator()( const XPropertiesChangeListenerPtr& rp1,
93 const XPropertiesChangeListenerPtr& rp2 ) const
95 return ( rp1 == rp2 );
99 struct hashPtr
101 size_t operator()( const XPropertiesChangeListenerPtr& rp ) const
103 return (size_t)rp;
107 typedef std::hash_map
109 XPropertiesChangeListenerPtr,
110 PropertyEventSequence*,
111 hashPtr,
112 equalPtr
114 PropertiesEventListenerMap;
116 //=========================================================================
118 // PropertyChangeListenerContainer.
120 //=========================================================================
122 struct equalStr
124 bool operator()( const rtl::OUString& s1, const rtl::OUString& s2 ) const
126 return !!( s1 == s2 );
130 struct hashStr
132 size_t operator()( const rtl::OUString& rName ) const
134 return rName.hashCode();
138 typedef cppu::OMultiTypeInterfaceContainerHelperVar
140 rtl::OUString,
141 hashStr,
142 equalStr
143 > PropertyChangeListeners;
145 //=========================================================================
147 // struct ContentImplHelper_Impl
149 //=========================================================================
151 struct ContentImplHelper_Impl
153 rtl::Reference< ::ucbhelper::PropertySetInfo > m_xPropSetInfo;
154 rtl::Reference< ::ucbhelper::CommandProcessorInfo > m_xCommandsInfo;
155 cppu::OInterfaceContainerHelper* m_pDisposeEventListeners;
156 cppu::OInterfaceContainerHelper* m_pContentEventListeners;
157 cppu::OInterfaceContainerHelper* m_pPropSetChangeListeners;
158 cppu::OInterfaceContainerHelper* m_pCommandChangeListeners;
159 PropertyChangeListeners* m_pPropertyChangeListeners;
161 ContentImplHelper_Impl()
162 : m_pDisposeEventListeners( 0 ),
163 m_pContentEventListeners( 0 ),
164 m_pPropSetChangeListeners( 0 ),
165 m_pCommandChangeListeners( 0 ),
166 m_pPropertyChangeListeners( 0 ) {}
168 ~ContentImplHelper_Impl()
170 delete m_pDisposeEventListeners;
171 delete m_pContentEventListeners;
172 delete m_pPropSetChangeListeners;
173 delete m_pCommandChangeListeners;
174 delete m_pPropertyChangeListeners;
178 } // namespace ucbhelper_impl
180 using namespace ucbhelper_impl;
182 //=========================================================================
183 //=========================================================================
185 // ContentImplHelper Implementation.
187 //=========================================================================
188 //=========================================================================
190 namespace ucbhelper {
192 ContentImplHelper::ContentImplHelper(
193 const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
194 const rtl::Reference< ContentProviderImplHelper >& rxProvider,
195 const uno::Reference<
196 com::sun::star::ucb::XContentIdentifier >& Identifier )
197 : m_pImpl( new ContentImplHelper_Impl ),
198 m_xSMgr( rxSMgr ),
199 m_xIdentifier( Identifier ),
200 m_xProvider( rxProvider ),
201 m_nCommandId( 0 )
205 //=========================================================================
206 // virtual
207 ContentImplHelper::~ContentImplHelper()
209 delete m_pImpl;
212 //=========================================================================
214 // XInterface methods.
216 //=========================================================================
218 void SAL_CALL ContentImplHelper::acquire()
219 throw()
221 cppu::OWeakObject::acquire();
224 void SAL_CALL ContentImplHelper::release()
225 throw()
227 // #144882# - Call to OWeakObject::release may destroy m_xProvider.
228 // Prevent this.
229 rtl::Reference< ContentProviderImplHelper > xKeepProviderAlive(
230 m_xProvider );
233 osl::MutexGuard aGuard( m_xProvider->m_aMutex );
234 OWeakObject::release();
238 uno::Any SAL_CALL ContentImplHelper::queryInterface( const uno::Type & rType )
239 throw( uno::RuntimeException )
241 com::sun::star::uno::Any aRet = cppu::queryInterface( rType,
242 static_cast< lang::XTypeProvider * >(this),
243 static_cast< lang::XServiceInfo * >(this),
244 static_cast< lang::XComponent * >(this),
245 static_cast< com::sun::star::ucb::XContent * >(this),
246 static_cast< com::sun::star::ucb::XCommandProcessor * >(this),
247 static_cast< beans::XPropertiesChangeNotifier * >(this),
248 static_cast< com::sun::star::ucb::XCommandInfoChangeNotifier * >(this),
249 static_cast< beans::XPropertyContainer * >(this),
250 static_cast< beans::XPropertySetInfoChangeNotifier * >(this),
251 static_cast< container::XChild * >(this));
252 return aRet.hasValue() ? aRet : cppu::OWeakObject::queryInterface( rType );
255 //=========================================================================
257 // XTypeProvider methods.
259 //=========================================================================
261 XTYPEPROVIDER_IMPL_10( ContentImplHelper,
262 lang::XTypeProvider,
263 lang::XServiceInfo,
264 lang::XComponent,
265 com::sun::star::ucb::XContent,
266 com::sun::star::ucb::XCommandProcessor,
267 beans::XPropertiesChangeNotifier,
268 com::sun::star::ucb::XCommandInfoChangeNotifier,
269 beans::XPropertyContainer,
270 beans::XPropertySetInfoChangeNotifier,
271 container::XChild );
273 //=========================================================================
275 // XServiceInfo methods.
277 //=========================================================================
279 // virtual
280 sal_Bool SAL_CALL ContentImplHelper::supportsService(
281 const rtl::OUString& ServiceName )
282 throw( uno::RuntimeException )
284 uno::Sequence< rtl::OUString > aSNL = getSupportedServiceNames();
285 const rtl::OUString* pArray = aSNL.getConstArray();
286 for ( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
288 if ( pArray[ i ] == ServiceName )
289 return sal_True;
292 return sal_False;
295 //=========================================================================
297 // XComponent methods.
299 //=========================================================================
301 // virtual
302 void SAL_CALL ContentImplHelper::dispose()
303 throw( uno::RuntimeException )
305 osl::MutexGuard aGuard( m_aMutex );
307 if ( m_pImpl->m_pDisposeEventListeners &&
308 m_pImpl->m_pDisposeEventListeners->getLength() )
310 lang::EventObject aEvt;
311 aEvt.Source = static_cast< lang::XComponent * >( this );
312 m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt );
315 if ( m_pImpl->m_pContentEventListeners &&
316 m_pImpl->m_pContentEventListeners->getLength() )
318 lang::EventObject aEvt;
319 aEvt.Source = static_cast< com::sun::star::ucb::XContent * >( this );
320 m_pImpl->m_pContentEventListeners->disposeAndClear( aEvt );
323 if ( m_pImpl->m_pPropSetChangeListeners &&
324 m_pImpl->m_pPropSetChangeListeners->getLength() )
326 lang::EventObject aEvt;
327 aEvt.Source
328 = static_cast< beans::XPropertySetInfoChangeNotifier * >( this );
329 m_pImpl->m_pPropSetChangeListeners->disposeAndClear( aEvt );
332 if ( m_pImpl->m_pCommandChangeListeners &&
333 m_pImpl->m_pCommandChangeListeners->getLength() )
335 lang::EventObject aEvt;
336 aEvt.Source = static_cast< com::sun::star::ucb::XCommandInfoChangeNotifier * >( this );
337 m_pImpl->m_pCommandChangeListeners->disposeAndClear( aEvt );
340 if ( m_pImpl->m_pPropertyChangeListeners )
342 lang::EventObject aEvt;
343 aEvt.Source
344 = static_cast< beans::XPropertiesChangeNotifier * >( this );
345 m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt );
349 //=========================================================================
350 // virtual
351 void SAL_CALL ContentImplHelper::addEventListener(
352 const uno::Reference< lang::XEventListener >& Listener )
353 throw( uno::RuntimeException )
355 osl::MutexGuard aGuard( m_aMutex );
357 if ( !m_pImpl->m_pDisposeEventListeners )
358 m_pImpl->m_pDisposeEventListeners
359 = new cppu::OInterfaceContainerHelper( m_aMutex );
361 m_pImpl->m_pDisposeEventListeners->addInterface( Listener );
364 //=========================================================================
365 // virtual
366 void SAL_CALL ContentImplHelper::removeEventListener(
367 const uno::Reference< lang::XEventListener >& Listener )
368 throw( uno::RuntimeException )
370 osl::MutexGuard aGuard( m_aMutex );
372 if ( m_pImpl->m_pDisposeEventListeners )
373 m_pImpl->m_pDisposeEventListeners->removeInterface( Listener );
376 //=========================================================================
378 // XContent methods.
380 //=========================================================================
382 // virtual
383 uno::Reference< com::sun::star::ucb::XContentIdentifier > SAL_CALL
384 ContentImplHelper::getIdentifier()
385 throw( uno::RuntimeException )
387 return m_xIdentifier;
390 //=========================================================================
391 // virtual
392 void SAL_CALL ContentImplHelper::addContentEventListener(
393 const uno::Reference< com::sun::star::ucb::XContentEventListener >& Listener )
394 throw( uno::RuntimeException )
396 osl::MutexGuard aGuard( m_aMutex );
398 if ( !m_pImpl->m_pContentEventListeners )
399 m_pImpl->m_pContentEventListeners
400 = new cppu::OInterfaceContainerHelper( m_aMutex );
402 m_pImpl->m_pContentEventListeners->addInterface( Listener );
405 //=========================================================================
406 // virtual
407 void SAL_CALL ContentImplHelper::removeContentEventListener(
408 const uno::Reference< com::sun::star::ucb::XContentEventListener >& Listener )
409 throw( uno::RuntimeException )
411 osl::MutexGuard aGuard( m_aMutex );
413 if ( m_pImpl->m_pContentEventListeners )
414 m_pImpl->m_pContentEventListeners->removeInterface( Listener );
417 //=========================================================================
419 // XCommandProcessor methods.
421 //=========================================================================
423 // virtual
424 sal_Int32 SAL_CALL ContentImplHelper::createCommandIdentifier()
425 throw( uno::RuntimeException )
427 osl::MutexGuard aGuard( m_aMutex );
429 // Just increase counter on every call to generate an identifier.
430 return ++m_nCommandId;
433 //=========================================================================
435 // XPropertiesChangeNotifier methods.
437 //=========================================================================
439 // virtual
440 void SAL_CALL ContentImplHelper::addPropertiesChangeListener(
441 const uno::Sequence< rtl::OUString >& PropertyNames,
442 const uno::Reference< beans::XPropertiesChangeListener >& Listener )
443 throw( uno::RuntimeException )
445 osl::MutexGuard aGuard( m_aMutex );
447 if ( !m_pImpl->m_pPropertyChangeListeners )
448 m_pImpl->m_pPropertyChangeListeners
449 = new PropertyChangeListeners( m_aMutex );
451 sal_Int32 nCount = PropertyNames.getLength();
452 if ( !nCount )
454 // Note: An empty sequence means a listener for "all" properties.
455 m_pImpl->m_pPropertyChangeListeners->addInterface(
456 rtl::OUString(), Listener );
458 else
460 const rtl::OUString* pSeq = PropertyNames.getConstArray();
462 for ( sal_Int32 n = 0; n < nCount; ++n )
464 const rtl::OUString& rName = pSeq[ n ];
465 if ( rName.getLength() )
466 m_pImpl->m_pPropertyChangeListeners->addInterface(
467 rName, Listener );
472 //=========================================================================
473 // virtual
474 void SAL_CALL ContentImplHelper::removePropertiesChangeListener(
475 const uno::Sequence< rtl::OUString >& PropertyNames,
476 const uno::Reference< beans::XPropertiesChangeListener >& Listener )
477 throw( uno::RuntimeException )
479 osl::MutexGuard aGuard( m_aMutex );
481 if ( !m_pImpl->m_pPropertyChangeListeners )
482 return;
484 sal_Int32 nCount = PropertyNames.getLength();
485 if ( !nCount )
487 // Note: An empty sequence means a listener for "all" properties.
488 m_pImpl->m_pPropertyChangeListeners->removeInterface(
489 rtl::OUString(), Listener );
491 else
493 const rtl::OUString* pSeq = PropertyNames.getConstArray();
495 for ( sal_Int32 n = 0; n < nCount; ++n )
497 const rtl::OUString& rName = pSeq[ n ];
498 if ( rName.getLength() )
499 m_pImpl->m_pPropertyChangeListeners->removeInterface(
500 rName, Listener );
505 //=========================================================================
507 // XCommandInfoChangeNotifier methods.
509 //=========================================================================
511 // virtual
512 void SAL_CALL ContentImplHelper::addCommandInfoChangeListener(
513 const uno::Reference< com::sun::star::ucb::XCommandInfoChangeListener >& Listener )
514 throw( uno::RuntimeException )
516 osl::MutexGuard aGuard( m_aMutex );
518 if ( !m_pImpl->m_pCommandChangeListeners )
519 m_pImpl->m_pCommandChangeListeners
520 = new cppu::OInterfaceContainerHelper( m_aMutex );
522 m_pImpl->m_pCommandChangeListeners->addInterface( Listener );
525 //=========================================================================
526 // virtual
527 void SAL_CALL ContentImplHelper::removeCommandInfoChangeListener(
528 const uno::Reference< com::sun::star::ucb::XCommandInfoChangeListener >& Listener )
529 throw( uno::RuntimeException )
531 osl::MutexGuard aGuard( m_aMutex );
533 if ( m_pImpl->m_pCommandChangeListeners )
534 m_pImpl->m_pCommandChangeListeners->removeInterface( Listener );
537 //=========================================================================
539 // XPropertyContainer methods.
541 //=========================================================================
543 // virtual
544 void SAL_CALL ContentImplHelper::addProperty(
545 const rtl::OUString& Name,
546 sal_Int16 Attributes,
547 const uno::Any& DefaultValue )
548 throw( beans::PropertyExistException,
549 beans::IllegalTypeException,
550 lang::IllegalArgumentException,
551 uno::RuntimeException )
553 osl::MutexGuard aGuard( m_aMutex );
555 //////////////////////////////////////////////////////////////////////
556 // Make sure a property with the requested name does not already
557 // exist in dynamic and static(!) properties.
558 //////////////////////////////////////////////////////////////////////
560 // @@@ Need real command environment here, but where to get it from?
561 // XPropertyContainer interface should be replaced by
562 // XCommandProcessor commands!
563 uno::Reference< com::sun::star::ucb::XCommandEnvironment > xEnv;
565 if ( getPropertySetInfo( xEnv )->hasPropertyByName( Name ) )
567 // Property does already exist.
568 throw beans::PropertyExistException();
571 //////////////////////////////////////////////////////////////////////
572 // Add a new dynamic property.
573 //////////////////////////////////////////////////////////////////////
575 // Open/create persistent property set.
576 uno::Reference< com::sun::star::ucb::XPersistentPropertySet > xSet(
577 getAdditionalPropertySet( sal_True ) );
579 OSL_ENSURE( xSet.is(),
580 "ContentImplHelper::addProperty - No property set!" );
582 if ( xSet.is() )
584 uno::Reference< beans::XPropertyContainer > xContainer(
585 xSet, uno::UNO_QUERY );
587 OSL_ENSURE(
588 xContainer.is(),
589 "ContentImplHelper::addProperty - No property container!" );
591 if ( xContainer.is() )
593 // Property is always removeable.
594 Attributes |= beans::PropertyAttribute::REMOVEABLE;
598 xContainer->addProperty( Name, Attributes, DefaultValue );
600 catch ( beans::PropertyExistException const & )
602 OSL_ENSURE( sal_False,
603 "ContentImplHelper::addProperty - Exists!" );
604 throw;
606 catch ( beans::IllegalTypeException const & )
608 OSL_ENSURE( sal_False,
609 "ContentImplHelper::addProperty - Wrong Type!" );
610 throw;
612 catch ( lang::IllegalArgumentException const & )
614 OSL_ENSURE( sal_False,
615 "ContentImplHelper::addProperty - Illegal Arg!" );
616 throw;
619 // Success!
621 if ( m_pImpl->m_xPropSetInfo.is() )
623 // Info cached in propertyset info is invalid now!
624 m_pImpl->m_xPropSetInfo->reset();
627 // Notify propertyset info change listeners.
628 if ( m_pImpl->m_pPropSetChangeListeners &&
629 m_pImpl->m_pPropSetChangeListeners->getLength() )
631 beans::PropertySetInfoChangeEvent evt(
632 static_cast< cppu::OWeakObject * >( this ),
633 Name,
634 -1, // No handle available
635 beans::PropertySetInfoChange::PROPERTY_INSERTED );
636 notifyPropertySetInfoChange( evt );
642 //=========================================================================
643 // virtual
644 void SAL_CALL ContentImplHelper::removeProperty( const rtl::OUString& Name )
645 throw( beans::UnknownPropertyException,
646 beans::NotRemoveableException,
647 uno::RuntimeException )
649 osl::MutexGuard aGuard( m_aMutex );
653 // @@@ Need real command environment here, but where to get it from?
654 // XPropertyContainer interface should be replaced by
655 // XCommandProcessor commands!
656 uno::Reference< com::sun::star::ucb::XCommandEnvironment > xEnv;
658 beans::Property aProp
659 = getPropertySetInfo( xEnv )->getPropertyByName( Name );
661 if ( !( aProp.Attributes & beans::PropertyAttribute::REMOVEABLE ) )
663 // Not removeable!
664 throw beans::NotRemoveableException();
667 catch ( beans::UnknownPropertyException const & )
669 OSL_ENSURE( sal_False, "ContentImplHelper::removeProperty - Unknown!" );
670 throw;
673 //////////////////////////////////////////////////////////////////////
674 // Try to remove property from dynamic property set.
675 //////////////////////////////////////////////////////////////////////
677 // Open persistent property set, if exists.
678 uno::Reference< com::sun::star::ucb::XPersistentPropertySet > xSet(
679 getAdditionalPropertySet( sal_False ) );
680 if ( xSet.is() )
682 uno::Reference< beans::XPropertyContainer > xContainer(
683 xSet, uno::UNO_QUERY );
685 OSL_ENSURE(
686 xContainer.is(),
687 "ContentImplHelper::removeProperty - No property container!" );
689 if ( xContainer.is() )
693 xContainer->removeProperty( Name );
695 catch ( beans::UnknownPropertyException const & )
697 OSL_ENSURE( sal_False,
698 "ContentImplHelper::removeProperty - Unknown!" );
699 throw;
701 catch ( beans::NotRemoveableException const & )
703 OSL_ENSURE(
704 sal_False,
705 "ContentImplHelper::removeProperty - Unremoveable!" );
706 throw;
709 xContainer = 0;
711 // Success!
713 if ( xSet->getPropertySetInfo()->getProperties().getLength() == 0 )
715 // Remove empty propertyset from registry.
716 uno::Reference< com::sun::star::ucb::XPropertySetRegistry >
717 xReg = xSet->getRegistry();
718 if ( xReg.is() )
720 rtl::OUString aKey( xSet->getKey() );
721 xSet = 0;
722 xReg->removePropertySet( aKey );
726 if ( m_pImpl->m_xPropSetInfo.is() )
728 // Info cached in propertyset info is invalid now!
729 m_pImpl->m_xPropSetInfo->reset();
732 // Notify propertyset info change listeners.
733 if ( m_pImpl->m_pPropSetChangeListeners &&
734 m_pImpl->m_pPropSetChangeListeners->getLength() )
736 beans::PropertySetInfoChangeEvent evt(
737 static_cast< cppu::OWeakObject * >( this ),
738 Name,
739 -1, // No handle available
740 beans::PropertySetInfoChange::PROPERTY_REMOVED );
741 notifyPropertySetInfoChange( evt );
747 //=========================================================================
749 // XPropertySetInfoChangeNotifier methods.
751 //=========================================================================
753 // virtual
754 void SAL_CALL ContentImplHelper::addPropertySetInfoChangeListener(
755 const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener )
756 throw( uno::RuntimeException )
758 osl::MutexGuard aGuard( m_aMutex );
760 if ( !m_pImpl->m_pPropSetChangeListeners )
761 m_pImpl->m_pPropSetChangeListeners
762 = new cppu::OInterfaceContainerHelper( m_aMutex );
764 m_pImpl->m_pPropSetChangeListeners->addInterface( Listener );
767 //=========================================================================
768 // virtual
769 void SAL_CALL ContentImplHelper::removePropertySetInfoChangeListener(
770 const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener )
771 throw( uno::RuntimeException )
773 osl::MutexGuard aGuard( m_aMutex );
775 if ( m_pImpl->m_pPropSetChangeListeners )
776 m_pImpl->m_pPropSetChangeListeners->removeInterface( Listener );
779 //=========================================================================
781 // XChild methods.
783 //=========================================================================
785 // virtual
786 uno::Reference< uno::XInterface > SAL_CALL ContentImplHelper::getParent()
787 throw( uno::RuntimeException )
789 uno::Reference< uno::XInterface > xParent;
790 rtl::OUString aURL = getParentURL();
792 if ( aURL.getLength() )
794 uno::Reference< com::sun::star::ucb::XContentIdentifier > xId(
795 new ContentIdentifier( m_xSMgr, aURL ) );
798 xParent.set( m_xProvider->queryContent( xId ) );
800 catch ( com::sun::star::ucb::IllegalIdentifierException const & )
805 return xParent;
808 //=========================================================================
809 // virtual
810 void SAL_CALL ContentImplHelper::setParent(
811 const uno::Reference< uno::XInterface >& )
812 throw( lang::NoSupportException, uno::RuntimeException )
814 throw lang::NoSupportException();
817 //=========================================================================
819 // Non-interface methods
821 //=========================================================================
823 uno::Reference< com::sun::star::ucb::XPersistentPropertySet >
824 ContentImplHelper::getAdditionalPropertySet( sal_Bool bCreate )
826 // Get propertyset from provider.
827 return m_xProvider->getAdditionalPropertySet(
828 m_xIdentifier->getContentIdentifier(), bCreate );
831 //=========================================================================
832 sal_Bool ContentImplHelper::renameAdditionalPropertySet(
833 const rtl::OUString& rOldKey,
834 const rtl::OUString& rNewKey,
835 sal_Bool bRecursive )
837 return m_xProvider->renameAdditionalPropertySet(
838 rOldKey, rNewKey, bRecursive );
841 //=========================================================================
842 sal_Bool ContentImplHelper::copyAdditionalPropertySet(
843 const rtl::OUString& rSourceKey,
844 const rtl::OUString& rTargetKey,
845 sal_Bool bRecursive )
847 return m_xProvider->copyAdditionalPropertySet(
848 rSourceKey, rTargetKey, bRecursive );
851 //=========================================================================
852 sal_Bool ContentImplHelper::removeAdditionalPropertySet( sal_Bool bRecursive )
854 return m_xProvider->removeAdditionalPropertySet(
855 m_xIdentifier->getContentIdentifier(), bRecursive );
858 //=========================================================================
859 void ContentImplHelper::notifyPropertiesChange(
860 const uno::Sequence< beans::PropertyChangeEvent >& evt ) const
862 if ( !m_pImpl->m_pPropertyChangeListeners )
863 return;
865 sal_Int32 nCount = evt.getLength();
866 if ( nCount )
868 // First, notify listeners interested in changes of every property.
869 cppu::OInterfaceContainerHelper* pAllPropsContainer
870 = m_pImpl->m_pPropertyChangeListeners->getContainer(
871 rtl::OUString() );
872 if ( pAllPropsContainer )
874 cppu::OInterfaceIteratorHelper aIter( *pAllPropsContainer );
875 while ( aIter.hasMoreElements() )
877 // Propagate event.
878 uno::Reference< beans::XPropertiesChangeListener > xListener(
879 aIter.next(), uno::UNO_QUERY );
880 if ( xListener.is() )
881 xListener->propertiesChange( evt );
885 PropertiesEventListenerMap aListeners;
887 const beans::PropertyChangeEvent* pEvents = evt.getConstArray();
889 for ( sal_Int32 n = 0; n < nCount; ++n )
891 const beans::PropertyChangeEvent& rEvent = pEvents[ n ];
892 const rtl::OUString& rName = rEvent.PropertyName;
894 cppu::OInterfaceContainerHelper* pPropsContainer
895 = m_pImpl->m_pPropertyChangeListeners->getContainer( rName );
896 if ( pPropsContainer )
898 cppu::OInterfaceIteratorHelper aIter( *pPropsContainer );
899 while ( aIter.hasMoreElements() )
901 PropertyEventSequence* p = NULL;
903 beans::XPropertiesChangeListener* pListener =
904 static_cast< beans::XPropertiesChangeListener * >(
905 aIter.next() );
906 PropertiesEventListenerMap::iterator it =
907 aListeners.find( pListener );
908 if ( it == aListeners.end() )
910 // Not in map - create and insert new entry.
911 p = new PropertyEventSequence( nCount );
912 aListeners[ pListener ] = p;
914 else
915 p = (*it).second;
917 if ( p )
918 p->append( rEvent );
923 // Notify listeners.
924 PropertiesEventListenerMap::iterator it = aListeners.begin();
925 while ( !aListeners.empty() )
927 beans::XPropertiesChangeListener* pListener =
928 static_cast< beans::XPropertiesChangeListener * >( (*it).first );
929 PropertyEventSequence* pSeq = (*it).second;
931 // Remove current element.
932 aListeners.erase( it );
934 // Propagate event.
935 pListener->propertiesChange( pSeq->getEvents() );
937 delete pSeq;
939 it = aListeners.begin();
944 //=========================================================================
945 void ContentImplHelper::notifyPropertySetInfoChange(
946 const beans::PropertySetInfoChangeEvent& evt ) const
948 if ( !m_pImpl->m_pPropSetChangeListeners )
949 return;
951 // Notify event listeners.
952 cppu::OInterfaceIteratorHelper aIter( *m_pImpl->m_pPropSetChangeListeners );
953 while ( aIter.hasMoreElements() )
955 // Propagate event.
956 uno::Reference< beans::XPropertySetInfoChangeListener >
957 xListener( aIter.next(), uno::UNO_QUERY );
958 if ( xListener.is() )
959 xListener->propertySetInfoChange( evt );
963 //=========================================================================
964 void ContentImplHelper::notifyCommandInfoChange(
965 const com::sun::star::ucb::CommandInfoChangeEvent& evt ) const
967 if ( !m_pImpl->m_pCommandChangeListeners )
968 return;
970 // Notify event listeners.
971 cppu::OInterfaceIteratorHelper aIter(
972 *m_pImpl->m_pCommandChangeListeners );
973 while ( aIter.hasMoreElements() )
975 // Propagate event.
976 uno::Reference< com::sun::star::ucb::XCommandInfoChangeListener >
977 xListener( aIter.next(), uno::UNO_QUERY );
978 if ( xListener.is() )
979 xListener->commandInfoChange( evt );
983 //=========================================================================
984 void ContentImplHelper::notifyContentEvent(
985 const com::sun::star::ucb::ContentEvent& evt ) const
987 if ( !m_pImpl->m_pContentEventListeners )
988 return;
990 // Notify event listeners.
991 cppu::OInterfaceIteratorHelper aIter( *m_pImpl->m_pContentEventListeners );
992 while ( aIter.hasMoreElements() )
994 // Propagate event.
995 uno::Reference<
996 com::sun::star::ucb::XContentEventListener > xListener(
997 aIter.next(), uno::UNO_QUERY );
998 if ( xListener.is() )
999 xListener->contentEvent( evt );
1003 //=========================================================================
1004 void ContentImplHelper::inserted()
1006 // Content is not yet registered at provider.
1007 m_xProvider->registerNewContent( this );
1009 // If the parent content is currently not instanciated, there can be
1010 // no listeners interested in changes ;-)
1012 rtl::Reference< ContentImplHelper > xParent
1013 = m_xProvider->queryExistingContent( getParentURL() );
1015 if ( xParent.is() )
1017 com::sun::star::ucb::ContentEvent aEvt(
1018 static_cast< cppu::OWeakObject * >( xParent.get() ), // Source
1019 com::sun::star::ucb::ContentAction::INSERTED, // Action
1020 this, // Content
1021 xParent->getIdentifier() ); // Id
1022 xParent->notifyContentEvent( aEvt );
1026 //=========================================================================
1027 void ContentImplHelper::deleted()
1029 uno::Reference< com::sun::star::ucb::XContent > xThis = this;
1031 rtl::Reference< ContentImplHelper > xParent
1032 = m_xProvider->queryExistingContent( getParentURL() );
1034 if ( xParent.is() )
1036 // Let parent notify "REMOVED" event.
1037 com::sun::star::ucb::ContentEvent aEvt(
1038 static_cast< cppu::OWeakObject * >( xParent.get() ),
1039 com::sun::star::ucb::ContentAction::REMOVED,
1040 this,
1041 xParent->getIdentifier() );
1042 xParent->notifyContentEvent( aEvt );
1045 // Notify "DELETED" event.
1046 com::sun::star::ucb::ContentEvent aEvt1(
1047 static_cast< cppu::OWeakObject * >( this ),
1048 com::sun::star::ucb::ContentAction::DELETED,
1049 this,
1050 getIdentifier() );
1051 notifyContentEvent( aEvt1 );
1053 m_xProvider->removeContent( this );
1056 //=========================================================================
1057 sal_Bool ContentImplHelper::exchange(
1058 const uno::Reference< com::sun::star::ucb::XContentIdentifier >& rNewId )
1060 uno::Reference< com::sun::star::ucb::XContent > xThis = this;
1062 osl::ClearableMutexGuard aGuard( m_aMutex );
1064 rtl::Reference< ContentImplHelper > xContent
1065 = m_xProvider->queryExistingContent( rNewId );
1066 if ( xContent.is() )
1068 // @@@
1069 // Big trouble. Another object with the new identity exists.
1070 // How shall I mutate to / merge with the other object?
1071 return sal_False;
1074 uno::Reference< com::sun::star::ucb::XContentIdentifier > xOldId
1075 = getIdentifier();
1077 // Re-insert at provider.
1078 m_xProvider->removeContent( this );
1079 m_xIdentifier = rNewId;
1080 m_xProvider->registerNewContent( this );
1082 aGuard.clear();
1084 // Notify "EXCHANGED" event.
1085 com::sun::star::ucb::ContentEvent aEvt(
1086 static_cast< cppu::OWeakObject * >( this ),
1087 com::sun::star::ucb::ContentAction::EXCHANGED,
1088 this,
1089 xOldId );
1090 notifyContentEvent( aEvt );
1091 return sal_True;
1094 //=========================================================================
1095 uno::Reference< com::sun::star::ucb::XCommandInfo >
1096 ContentImplHelper::getCommandInfo(
1097 const uno::Reference< com::sun::star::ucb::XCommandEnvironment > & xEnv,
1098 sal_Bool bCache )
1100 osl::MutexGuard aGuard( m_aMutex );
1102 if ( !m_pImpl->m_xCommandsInfo.is() )
1103 m_pImpl->m_xCommandsInfo
1104 = new CommandProcessorInfo( m_xSMgr, xEnv, this );
1105 else if ( !bCache )
1106 m_pImpl->m_xCommandsInfo->reset();
1108 return uno::Reference< com::sun::star::ucb::XCommandInfo >(
1109 m_pImpl->m_xCommandsInfo.get() );
1112 //=========================================================================
1113 uno::Reference< beans::XPropertySetInfo >
1114 ContentImplHelper::getPropertySetInfo(
1115 const uno::Reference< com::sun::star::ucb::XCommandEnvironment > & xEnv,
1116 sal_Bool bCache )
1118 osl::MutexGuard aGuard( m_aMutex );
1120 if ( !m_pImpl->m_xPropSetInfo.is() )
1121 m_pImpl->m_xPropSetInfo
1122 = new PropertySetInfo( m_xSMgr, xEnv, this );
1123 else if ( !bCache )
1124 m_pImpl->m_xPropSetInfo->reset();
1126 return uno::Reference< beans::XPropertySetInfo >(
1127 m_pImpl->m_xPropSetInfo.get() );
1130 } // namespace ucbhelper