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>
41#include <osl/diagnose.h>
42#include <osl/mutex.hxx>
45#include <unordered_map>
55class PropertyEventSequence
57 uno::Sequence< beans::PropertyChangeEvent >
m_aSeq;
61 explicit PropertyEventSequence( sal_uInt32 nSize )
64 void append(
const beans::PropertyChangeEvent& rEvt )
67 const uno::Sequence< beans::PropertyChangeEvent >& getEvents()
82 return ( rp1 == rp2 );
90 return reinterpret_cast<size_t>(rp);
96typedef std::unordered_map
99 PropertyEventSequence,
113 std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::ucb::XContentEventListener>>
115 std::unique_ptr<comphelper::OInterfaceContainerHelper3<beans::XPropertySetInfoChangeListener>>
128 uno::Reference< uno::XComponentContext > xContext,
131 css::ucb::XContentIdentifier > Identifier )
135 m_xProvider(
std::move( xProvider )),
154 OWeakObject::release();
160 static_cast< lang::XTypeProvider *
>(
this),
161 static_cast< lang::XServiceInfo *
>(
this),
162 static_cast< lang::XComponent *
>(
this),
163 static_cast< css::ucb::XContent *
>(
this),
164 static_cast< css::ucb::XCommandProcessor *
>(
this),
165 static_cast< beans::XPropertiesChangeNotifier *
>(
this),
166 static_cast< css::ucb::XCommandInfoChangeNotifier *
>(
this),
167 static_cast< beans::XPropertyContainer *
>(
this),
168 static_cast< beans::XPropertySetInfoChangeNotifier *
>(
this),
169 static_cast< container::XChild *
>(
this));
178 css::ucb::XCommandProcessor,
179 beans::XPropertiesChangeNotifier,
180 css::ucb::XCommandInfoChangeNotifier,
181 beans::XPropertyContainer,
182 beans::XPropertySetInfoChangeNotifier,
187 const OUString& ServiceName )
197 if (
m_pImpl->m_pDisposeEventListeners &&
198 m_pImpl->m_pDisposeEventListeners->getLength() )
200 lang::EventObject aEvt;
201 aEvt.Source =
static_cast< lang::XComponent *
>( this );
202 m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt );
205 if (
m_pImpl->m_pContentEventListeners &&
206 m_pImpl->m_pContentEventListeners->getLength() )
208 lang::EventObject aEvt;
209 aEvt.Source =
static_cast< css::ucb::XContent *
>( this );
210 m_pImpl->m_pContentEventListeners->disposeAndClear( aEvt );
213 if (
m_pImpl->m_pPropSetChangeListeners &&
214 m_pImpl->m_pPropSetChangeListeners->getLength() )
216 lang::EventObject aEvt;
218 =
static_cast< beans::XPropertySetInfoChangeNotifier *
>( this );
219 m_pImpl->m_pPropSetChangeListeners->disposeAndClear( aEvt );
222 if (
m_pImpl->m_pCommandChangeListeners &&
223 m_pImpl->m_pCommandChangeListeners->getLength() )
225 lang::EventObject aEvt;
226 aEvt.Source =
static_cast< css::ucb::XCommandInfoChangeNotifier *
>( this );
227 m_pImpl->m_pCommandChangeListeners->disposeAndClear( aEvt );
230 if (
m_pImpl->m_pPropertyChangeListeners )
232 lang::EventObject aEvt;
234 =
static_cast< beans::XPropertiesChangeNotifier *
>( this );
235 m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt );
241 const uno::Reference< lang::XEventListener >& Listener )
245 if ( !
m_pImpl->m_pDisposeEventListeners )
246 m_pImpl->m_pDisposeEventListeners.reset(
249 m_pImpl->m_pDisposeEventListeners->addInterface( Listener );
254 const uno::Reference< lang::XEventListener >& Listener )
258 if (
m_pImpl->m_pDisposeEventListeners )
259 m_pImpl->m_pDisposeEventListeners->removeInterface( Listener );
263uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
271 const uno::Reference< css::ucb::XContentEventListener >& Listener )
275 if ( !
m_pImpl->m_pContentEventListeners )
276 m_pImpl->m_pContentEventListeners.reset(
279 m_pImpl->m_pContentEventListeners->addInterface( Listener );
284 const uno::Reference< css::ucb::XContentEventListener >& Listener )
288 if (
m_pImpl->m_pContentEventListeners )
289 m_pImpl->m_pContentEventListeners->removeInterface( Listener );
303 const uno::Sequence< OUString >& PropertyNames,
304 const uno::Reference< beans::XPropertiesChangeListener >& Listener )
308 if ( !
m_pImpl->m_pPropertyChangeListeners )
309 m_pImpl->m_pPropertyChangeListeners.reset(
312 if ( !PropertyNames.hasElements() )
315 m_pImpl->m_pPropertyChangeListeners->addInterface(
316 OUString(), Listener );
320 for (
const OUString& rName : PropertyNames )
322 if ( !rName.isEmpty() )
323 m_pImpl->m_pPropertyChangeListeners->addInterface(
331 const uno::Sequence< OUString >& PropertyNames,
332 const uno::Reference< beans::XPropertiesChangeListener >& Listener )
336 if ( !
m_pImpl->m_pPropertyChangeListeners )
339 if ( !PropertyNames.hasElements() )
342 m_pImpl->m_pPropertyChangeListeners->removeInterface(
343 OUString(), Listener );
347 for (
const OUString& rName : PropertyNames )
349 if ( !rName.isEmpty() )
350 m_pImpl->m_pPropertyChangeListeners->removeInterface(
358 const uno::Reference< css::ucb::XCommandInfoChangeListener >& Listener )
362 if ( !
m_pImpl->m_pCommandChangeListeners )
363 m_pImpl->m_pCommandChangeListeners.reset(
366 m_pImpl->m_pCommandChangeListeners->addInterface( Listener );
371 const uno::Reference< css::ucb::XCommandInfoChangeListener >& Listener )
375 if (
m_pImpl->m_pCommandChangeListeners )
376 m_pImpl->m_pCommandChangeListeners->removeInterface( Listener );
381 const OUString& Name,
382 sal_Int16 Attributes,
393 uno::Reference< css::ucb::XCommandEnvironment > xEnv;
398 throw beans::PropertyExistException();
403 uno::Reference< css::ucb::XPersistentPropertySet > xSet(
406 OSL_ENSURE( xSet.is(),
407 "ContentImplHelper::addProperty - No property set!" );
412 uno::Reference< beans::XPropertyContainer > xContainer(
413 xSet, uno::UNO_QUERY );
417 "ContentImplHelper::addProperty - No property container!" );
419 if ( !xContainer.is() )
423 Attributes |= beans::PropertyAttribute::REMOVABLE;
427 xContainer->addProperty(
Name, Attributes, DefaultValue );
429 catch ( beans::PropertyExistException
const & )
431 OSL_FAIL(
"ContentImplHelper::addProperty - Exists!" );
434 catch ( beans::IllegalTypeException
const & )
436 OSL_FAIL(
"ContentImplHelper::addProperty - Wrong Type!" );
439 catch ( lang::IllegalArgumentException
const & )
441 OSL_FAIL(
"ContentImplHelper::addProperty - Illegal Arg!" );
447 if (
m_pImpl->m_xPropSetInfo.is() )
450 m_pImpl->m_xPropSetInfo->reset();
454 if (
m_pImpl->m_pPropSetChangeListeners &&
455 m_pImpl->m_pPropSetChangeListeners->getLength() )
457 beans::PropertySetInfoChangeEvent evt(
461 beans::PropertySetInfoChange::PROPERTY_INSERTED );
476 uno::Reference< css::ucb::XCommandEnvironment > xEnv;
478 beans::Property aProp
481 if ( !( aProp.Attributes & beans::PropertyAttribute::REMOVABLE ) )
484 throw beans::NotRemoveableException();
487 catch ( beans::UnknownPropertyException
const & )
489 OSL_FAIL(
"ContentImplHelper::removeProperty - Unknown!" );
495 uno::Reference< css::ucb::XPersistentPropertySet > xSet(
500 uno::Reference< beans::XPropertyContainer > xContainer(
501 xSet, uno::UNO_QUERY );
505 "ContentImplHelper::removeProperty - No property container!" );
507 if ( !xContainer.is() )
512 xContainer->removeProperty(
Name );
514 catch ( beans::UnknownPropertyException
const & )
516 OSL_FAIL(
"ContentImplHelper::removeProperty - Unknown!" );
519 catch ( beans::NotRemoveableException
const & )
522 "ContentImplHelper::removeProperty - Unremovable!" );
526 xContainer =
nullptr;
530 if ( !xSet->getPropertySetInfo()->getProperties().hasElements() )
533 uno::Reference< css::ucb::XPropertySetRegistry >
534 xReg = xSet->getRegistry();
537 OUString aKey( xSet->getKey() );
539 xReg->removePropertySet( aKey );
543 if (
m_pImpl->m_xPropSetInfo.is() )
546 m_pImpl->m_xPropSetInfo->reset();
550 if (
m_pImpl->m_pPropSetChangeListeners &&
551 m_pImpl->m_pPropSetChangeListeners->getLength() )
553 beans::PropertySetInfoChangeEvent evt(
557 beans::PropertySetInfoChange::PROPERTY_REMOVED );
564 const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener )
568 if ( !
m_pImpl->m_pPropSetChangeListeners )
569 m_pImpl->m_pPropSetChangeListeners.reset(
572 m_pImpl->m_pPropSetChangeListeners->addInterface( Listener );
577 const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener )
581 if (
m_pImpl->m_pPropSetChangeListeners )
582 m_pImpl->m_pPropSetChangeListeners->removeInterface( Listener );
588 uno::Reference< uno::XInterface > xParent;
591 if ( !
aURL.isEmpty() )
593 uno::Reference< css::ucb::XContentIdentifier > xId(
599 catch ( css::ucb::IllegalIdentifierException
const & )
609 const uno::Reference< uno::XInterface >& )
611 throw lang::NoSupportException();
614uno::Reference< css::ucb::XPersistentPropertySet >
623 const OUString& rOldKey,
624 const OUString& rNewKey )
627 rOldKey, rNewKey,
true );
631 const OUString& rSourceKey,
632 const OUString& rTargetKey )
635 rSourceKey, rTargetKey,
true );
645 const uno::Sequence< beans::PropertyChangeEvent >& evt )
const
647 if ( !
m_pImpl->m_pPropertyChangeListeners )
650 sal_Int32
nCount = evt.getLength();
656 =
m_pImpl->m_pPropertyChangeListeners->getContainer(
658 if ( pAllPropsContainer )
664 static_cast< beans::XPropertiesChangeListener*
>(
665 aIter.
next())->propertiesChange( evt );
671 for (
const beans::PropertyChangeEvent& rEvent : evt )
673 const OUString& rName = rEvent.PropertyName;
676 =
m_pImpl->m_pPropertyChangeListeners->getContainer( rName );
677 if ( pPropsContainer )
682 PropertyEventSequence*
p =
nullptr;
684 beans::XPropertiesChangeListener* pListener =
685 static_cast< beans::XPropertiesChangeListener *
>(
687 PropertiesEventListenerMap::iterator it =
704 PropertiesEventListenerMap::iterator it =
aListeners.begin();
707 beans::XPropertiesChangeListener* pListener =
708 static_cast< beans::XPropertiesChangeListener *
>( (*it).first );
709 PropertyEventSequence pSeq = std::move(it->second);
715 pListener->propertiesChange( pSeq.getEvents() );
722 const beans::PropertySetInfoChangeEvent& evt )
const
724 if ( !
m_pImpl->m_pPropSetChangeListeners )
728 m_pImpl->m_pPropSetChangeListeners->notifyEach( &beans::XPropertySetInfoChangeListener::propertySetInfoChange, evt );
732 const css::ucb::ContentEvent& evt )
const
734 if ( !
m_pImpl->m_pContentEventListeners )
738 m_pImpl->m_pContentEventListeners->notifyEach( &css::ucb::XContentEventListener::contentEvent, evt);
754 css::ucb::ContentEvent aEvt(
756 css::ucb::ContentAction::INSERTED,
758 xParent->getIdentifier() );
759 xParent->notifyContentEvent( aEvt );
765 uno::Reference< css::ucb::XContent > xThis =
this;
773 css::ucb::ContentEvent aEvt(
775 css::ucb::ContentAction::REMOVED,
777 xParent->getIdentifier() );
778 xParent->notifyContentEvent( aEvt );
782 css::ucb::ContentEvent aEvt1(
784 css::ucb::ContentAction::DELETED,
793 const uno::Reference< css::ucb::XContentIdentifier >& rNewId )
795 uno::Reference< css::ucb::XContent > xThis =
this;
797 osl::ClearableMutexGuard aGuard(
m_aMutex );
809 uno::Reference< css::ucb::XContentIdentifier > xOldId
820 css::ucb::ContentEvent aEvt(
822 css::ucb::ContentAction::EXCHANGED,
829uno::Reference< css::ucb::XCommandInfo >
831 const uno::Reference< css::ucb::XCommandEnvironment > & xEnv,
836 if ( !
m_pImpl->m_xCommandsInfo.is() )
840 m_pImpl->m_xCommandsInfo->reset();
842 return m_pImpl->m_xCommandsInfo;
845uno::Reference< beans::XPropertySetInfo >
847 const uno::Reference< css::ucb::XCommandEnvironment > & xEnv,
852 if ( !
m_pImpl->m_xPropSetInfo.is() )
856 m_pImpl->m_xPropSetInfo->reset();
858 return m_pImpl->m_xPropSetInfo;
Reference< XComponentContext > m_xContext
css::uno::XInterface *SAL_CALL next()
bool SAL_CALL hasMoreElements() const
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) SAL_OVERRIDE
This class implements a simple identifier object for UCB contents.
This is an abstract base class for implementations of the service com.sun.star.ucb....
virtual void SAL_CALL addCommandInfoChangeListener(const css::uno::Reference< css::ucb::XCommandInfoChangeListener > &Listener) override
void deleted()
Use this method to announce the destruction of this content at the end of your implementation of the ...
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
The implementation of this method always throws a NoSupportException.
friend class CommandProcessorInfo
css::uno::Reference< css::ucb::XPersistentPropertySet > getAdditionalPropertySet(bool bCreate)
Use this method to get access to the Additional Core Properties of the content ( added using content'...
void notifyPropertySetInfoChange(const css::beans::PropertySetInfoChangeEvent &evt) const
This method can be used to propagate changes of the propertyset info of your content (i....
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
virtual ~ContentImplHelper() override
Destructor.
virtual void SAL_CALL addPropertiesChangeListener(const css::uno::Sequence< OUString > &PropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &Listener) override
virtual UCBHELPER_DLLPRIVATE OUString getParentURL()=0
The implementation of this method shall return the URL of the parent of your content.
void inserted()
Use this method to announce the insertion of this content at the end of your implementation of the co...
css::uno::Reference< css::ucb::XCommandInfo > getCommandInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
This method returns complete meta data for the commands supported by the content.
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &Listener) override
bool renameAdditionalPropertySet(const OUString &rOldKey, const OUString &rNewKey)
This method renames the propertyset containing the Additional Core Properties of the content.
virtual void SAL_CALL removePropertySetInfoChangeListener(const css::uno::Reference< css::beans::XPropertySetInfoChangeListener > &Listener) override
virtual void SAL_CALL removePropertiesChangeListener(const css::uno::Sequence< OUString > &PropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &Listener) override
rtl::Reference< ContentProviderImplHelper > m_xProvider
virtual void SAL_CALL release() noexcept override
void notifyContentEvent(const css::ucb::ContentEvent &evt) const
This method can be used to propagate content events.
virtual void SAL_CALL addPropertySetInfoChangeListener(const css::uno::Reference< css::beans::XPropertySetInfoChangeListener > &Listener) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
std::unique_ptr< ucbhelper_impl::ContentImplHelper_Impl > m_pImpl
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL getIdentifier() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
This method returns the content representing the parent of a content, if such a parent exists.
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
bool removeAdditionalPropertySet()
This method removes the propertyset containing the Additional Core Properties of the content.
virtual void SAL_CALL addContentEventListener(const css::uno::Reference< css::ucb::XContentEventListener > &Listener) override
ContentImplHelper(css::uno::Reference< css::uno::XComponentContext > xContext, rtl::Reference< ContentProviderImplHelper > xProvider, css::uno::Reference< css::ucb::XContentIdentifier > Identifier)
Constructor.
bool copyAdditionalPropertySet(const OUString &rSourceKey, const OUString &rTargetKey)
This method copies the propertyset containing the Additional Core Properties of the content.
virtual void SAL_CALL removeProperty(const OUString &Name) override
This method removes a property from the content according to the interface specification.
bool exchange(const css::uno::Reference< css::ucb::XContentIdentifier > &rNewId)
Use this method to change the identity of a content.
virtual void SAL_CALL addProperty(const OUString &Name, sal_Int16 Attributes, const css::uno::Any &DefaultValue) override
This method adds a property to the content according to the interface specification.
css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
This method returns complete meta data for the properties ( including Additional Core Properties supp...
friend class PropertySetInfo
virtual sal_Int32 SAL_CALL createCommandIdentifier() override
css::uno::Reference< css::ucb::XContentIdentifier > m_xIdentifier
virtual void SAL_CALL removeContentEventListener(const css::uno::Reference< css::ucb::XContentEventListener > &Listener) override
virtual void SAL_CALL removeCommandInfoChangeListener(const css::uno::Reference< css::ucb::XCommandInfoChangeListener > &Listener) override
void notifyPropertiesChange(const css::uno::Sequence< css::beans::PropertyChangeEvent > &evt) const
This method can be used to propagate changes of property values.
virtual void SAL_CALL dispose() override
uno::Sequence< beans::PropertyChangeEvent > m_aSeq
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral first
cppu::OMultiTypeInterfaceContainerHelperVar< OUString > PropertyChangeListeners
std::unordered_map< XPropertiesChangeListenerPtr, PropertyEventSequence, hashPtr, equalPtr > PropertiesEventListenerMap
void * XPropertiesChangeListenerPtr
XTYPEPROVIDER_IMPL_10(ContentImplHelper, lang::XTypeProvider, lang::XServiceInfo, lang::XComponent, css::ucb::XContent, css::ucb::XCommandProcessor, beans::XPropertiesChangeNotifier, css::ucb::XCommandInfoChangeNotifier, beans::XPropertyContainer, beans::XPropertySetInfoChangeNotifier, container::XChild)
std::unique_ptr< cppu::OInterfaceContainerHelper > m_pCommandChangeListeners
rtl::Reference< ::ucbhelper::PropertySetInfo > m_xPropSetInfo
std::unique_ptr< comphelper::OInterfaceContainerHelper3< beans::XPropertySetInfoChangeListener > > m_pPropSetChangeListeners
std::unique_ptr< comphelper::OInterfaceContainerHelper3< css::ucb::XContentEventListener > > m_pContentEventListeners
std::unique_ptr< PropertyChangeListeners > m_pPropertyChangeListeners
std::unique_ptr< cppu::OInterfaceContainerHelper > m_pDisposeEventListeners
rtl::Reference< ::ucbhelper::CommandProcessorInfo > m_xCommandsInfo