1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: contenthelper.cxx,v $
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 /**************************************************************************
35 **************************************************************************
37 *************************************************************************/
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
;
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!
92 bool operator()( const XPropertiesChangeListenerPtr
& rp1
,
93 const XPropertiesChangeListenerPtr
& rp2
) const
95 return ( rp1
== rp2
);
101 size_t operator()( const XPropertiesChangeListenerPtr
& rp
) const
107 typedef std::hash_map
109 XPropertiesChangeListenerPtr
,
110 PropertyEventSequence
*,
114 PropertiesEventListenerMap
;
116 //=========================================================================
118 // PropertyChangeListenerContainer.
120 //=========================================================================
124 bool operator()( const rtl::OUString
& s1
, const rtl::OUString
& s2
) const
126 return !!( s1
== s2
);
132 size_t operator()( const rtl::OUString
& rName
) const
134 return rName
.hashCode();
138 typedef cppu::OMultiTypeInterfaceContainerHelperVar
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
),
199 m_xIdentifier( Identifier
),
200 m_xProvider( rxProvider
),
205 //=========================================================================
207 ContentImplHelper::~ContentImplHelper()
212 //=========================================================================
214 // XInterface methods.
216 //=========================================================================
218 void SAL_CALL
ContentImplHelper::acquire()
221 cppu::OWeakObject::acquire();
224 void SAL_CALL
ContentImplHelper::release()
227 // #144882# - Call to OWeakObject::release may destroy m_xProvider.
229 rtl::Reference
< ContentProviderImplHelper
> xKeepProviderAlive(
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
,
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
,
273 //=========================================================================
275 // XServiceInfo methods.
277 //=========================================================================
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
)
295 //=========================================================================
297 // XComponent methods.
299 //=========================================================================
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
;
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
;
344 = static_cast< beans::XPropertiesChangeNotifier
* >( this );
345 m_pImpl
->m_pPropertyChangeListeners
->disposeAndClear( aEvt
);
349 //=========================================================================
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 //=========================================================================
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 //=========================================================================
380 //=========================================================================
383 uno::Reference
< com::sun::star::ucb::XContentIdentifier
> SAL_CALL
384 ContentImplHelper::getIdentifier()
385 throw( uno::RuntimeException
)
387 return m_xIdentifier
;
390 //=========================================================================
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 //=========================================================================
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 //=========================================================================
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 //=========================================================================
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();
454 // Note: An empty sequence means a listener for "all" properties.
455 m_pImpl
->m_pPropertyChangeListeners
->addInterface(
456 rtl::OUString(), Listener
);
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(
472 //=========================================================================
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
)
484 sal_Int32 nCount
= PropertyNames
.getLength();
487 // Note: An empty sequence means a listener for "all" properties.
488 m_pImpl
->m_pPropertyChangeListeners
->removeInterface(
489 rtl::OUString(), Listener
);
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(
505 //=========================================================================
507 // XCommandInfoChangeNotifier methods.
509 //=========================================================================
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 //=========================================================================
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 //=========================================================================
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!" );
584 uno::Reference
< beans::XPropertyContainer
> xContainer(
585 xSet
, uno::UNO_QUERY
);
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!" );
606 catch ( beans::IllegalTypeException
const & )
608 OSL_ENSURE( sal_False
,
609 "ContentImplHelper::addProperty - Wrong Type!" );
612 catch ( lang::IllegalArgumentException
const & )
614 OSL_ENSURE( sal_False
,
615 "ContentImplHelper::addProperty - Illegal Arg!" );
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 ),
634 -1, // No handle available
635 beans::PropertySetInfoChange::PROPERTY_INSERTED
);
636 notifyPropertySetInfoChange( evt
);
642 //=========================================================================
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
) )
664 throw beans::NotRemoveableException();
667 catch ( beans::UnknownPropertyException
const & )
669 OSL_ENSURE( sal_False
, "ContentImplHelper::removeProperty - Unknown!" );
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
) );
682 uno::Reference
< beans::XPropertyContainer
> xContainer(
683 xSet
, uno::UNO_QUERY
);
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!" );
701 catch ( beans::NotRemoveableException
const & )
705 "ContentImplHelper::removeProperty - Unremoveable!" );
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();
720 rtl::OUString
aKey( xSet
->getKey() );
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 ),
739 -1, // No handle available
740 beans::PropertySetInfoChange::PROPERTY_REMOVED
);
741 notifyPropertySetInfoChange( evt
);
747 //=========================================================================
749 // XPropertySetInfoChangeNotifier methods.
751 //=========================================================================
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 //=========================================================================
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 //=========================================================================
783 //=========================================================================
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 & )
808 //=========================================================================
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
)
865 sal_Int32 nCount
= evt
.getLength();
868 // First, notify listeners interested in changes of every property.
869 cppu::OInterfaceContainerHelper
* pAllPropsContainer
870 = m_pImpl
->m_pPropertyChangeListeners
->getContainer(
872 if ( pAllPropsContainer
)
874 cppu::OInterfaceIteratorHelper
aIter( *pAllPropsContainer
);
875 while ( aIter
.hasMoreElements() )
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
* >(
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
;
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
);
935 pListener
->propertiesChange( pSeq
->getEvents() );
939 it
= aListeners
.begin();
944 //=========================================================================
945 void ContentImplHelper::notifyPropertySetInfoChange(
946 const beans::PropertySetInfoChangeEvent
& evt
) const
948 if ( !m_pImpl
->m_pPropSetChangeListeners
)
951 // Notify event listeners.
952 cppu::OInterfaceIteratorHelper
aIter( *m_pImpl
->m_pPropSetChangeListeners
);
953 while ( aIter
.hasMoreElements() )
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
)
970 // Notify event listeners.
971 cppu::OInterfaceIteratorHelper
aIter(
972 *m_pImpl
->m_pCommandChangeListeners
);
973 while ( aIter
.hasMoreElements() )
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
)
990 // Notify event listeners.
991 cppu::OInterfaceIteratorHelper
aIter( *m_pImpl
->m_pContentEventListeners
);
992 while ( aIter
.hasMoreElements() )
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() );
1017 com::sun::star::ucb::ContentEvent
aEvt(
1018 static_cast< cppu::OWeakObject
* >( xParent
.get() ), // Source
1019 com::sun::star::ucb::ContentAction::INSERTED
, // Action
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() );
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
,
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
,
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() )
1069 // Big trouble. Another object with the new identity exists.
1070 // How shall I mutate to / merge with the other object?
1074 uno::Reference
< com::sun::star::ucb::XContentIdentifier
> xOldId
1077 // Re-insert at provider.
1078 m_xProvider
->removeContent( this );
1079 m_xIdentifier
= rNewId
;
1080 m_xProvider
->registerNewContent( this );
1084 // Notify "EXCHANGED" event.
1085 com::sun::star::ucb::ContentEvent
aEvt(
1086 static_cast< cppu::OWeakObject
* >( this ),
1087 com::sun::star::ucb::ContentAction::EXCHANGED
,
1090 notifyContentEvent( aEvt
);
1094 //=========================================================================
1095 uno::Reference
< com::sun::star::ucb::XCommandInfo
>
1096 ContentImplHelper::getCommandInfo(
1097 const uno::Reference
< com::sun::star::ucb::XCommandEnvironment
> & xEnv
,
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 );
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
,
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 );
1124 m_pImpl
->m_xPropSetInfo
->reset();
1126 return uno::Reference
< beans::XPropertySetInfo
>(
1127 m_pImpl
->m_xPropSetInfo
.get() );
1130 } // namespace ucbhelper