22#include <rtl/ustrbuf.hxx>
24#include <com/sun/star/ucb/UnsupportedCommandException.hpp>
25#include <com/sun/star/lang/IllegalArgumentException.hpp>
26#include <com/sun/star/lang/IllegalAccessException.hpp>
27#include <com/sun/star/beans/IllegalTypeException.hpp>
28#include <com/sun/star/beans/PropertyAttribute.hpp>
29#include <com/sun/star/beans/PropertyValue.hpp>
30#include <com/sun/star/beans/XPropertySet.hpp>
31#include <com/sun/star/container/ElementExistException.hpp>
54using namespace ::
cppu;
57 : m_pDataSource(nullptr)
66 ,
const Reference< XInterface >& _xParentContainer
70 ,m_aPropertyChangeListeners(
m_aMutex)
83 EventObject aEvt(*
this);
91 return "com.sun.star.comp.sdb.Content";
96 for (
const OUString& s : aSupported)
97 if (s == _rServiceName)
104 return {
"com.sun.star.ucb.Content" };
110 return css::uno::Sequence<sal_Int8>();
118 return new ::ucbhelper::ContentIdentifier( aIdentifier );
123 OUStringBuffer aHierarchicalName(
m_pImpl->m_aProps.aTitle );
125 while( xParent.is() )
127 Reference<XPropertySet> xProp( xParent, UNO_QUERY );
128 Reference< XChild > xChild( xParent, UNO_QUERY );
129 xParent.set( xChild.is() ? xChild->getParent() : Reference< XInterface >(), UNO_QUERY );
130 if ( xProp.is() && xParent.is() )
135 OUString sPrevious = aHierarchicalName.makeStringAndClear();
136 aHierarchicalName.append(
sName +
"/" + sPrevious );
139 OUString sHierarchicalName( aHierarchicalName.makeStringAndClear() );
140 if ( !_includingRootContainer )
141 sHierarchicalName = sHierarchicalName.copy( sHierarchicalName.indexOf(
'/' ) + 1 );
142 return sHierarchicalName;
149 if ( !
m_pImpl->m_aProps.aContentType )
154 return *
m_pImpl->m_aProps.aContentType;
160 if ( _rxListener.is() )
167 if (_rxListener.is())
182 if (
aCommand.Name ==
"getPropertyValues" )
189 OSL_FAIL(
"Wrong argument type!" );
191 Any( IllegalArgumentException(
200 else if (
aCommand.Name ==
"setPropertyValues" )
207 OSL_FAIL(
"Wrong argument type!" );
209 Any( IllegalArgumentException(
219 OSL_FAIL(
"No properties!" );
221 Any( IllegalArgumentException(
231 else if (
aCommand.Name ==
"getPropertySetInfo" )
235 Reference<XPropertySet> xProp(*
this,UNO_QUERY);
237 aRet <<= xProp->getPropertySetInfo();
244 OSL_FAIL(
"Content::execute - unsupported command!" );
247 Any( UnsupportedCommandException(
265 sal_Int32
nCount = PropertyNames.getLength();
273 const OUString* pSeq = PropertyNames.getConstArray();
277 const OUString& rName = pSeq[
n ];
278 if ( !rName.isEmpty() )
287 sal_Int32
nCount = PropertyNames.getLength();
295 const OUString* pSeq = PropertyNames.getConstArray();
299 const OUString& rName = pSeq[
n ];
300 if ( !rName.isEmpty() )
309 OSL_FAIL(
"OContentHelper::addProperty: not implemented!" );
314 OSL_FAIL(
"OContentHelper::removeProperty: not implemented!" );
320 const Any* pBegin = _aArguments.getConstArray();
321 const Any* pEnd = pBegin + _aArguments.getLength();
322 PropertyValue aValue;
323 for(;pBegin != pEnd;++pBegin)
326 if ( aValue.Name ==
"Parent" )
332 aValue.Value >>=
m_pImpl->m_aProps.aTitle;
336 aValue.Value >>=
m_pImpl->m_aProps.sPersistentName;
343 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex );
345 Sequence< Any > aRet( rValues.getLength() );
346 auto aRetRange = asNonConstRange(aRet);
347 Sequence< PropertyChangeEvent > aChanges( rValues.getLength() );
348 sal_Int32 nChanged = 0;
350 PropertyChangeEvent
aEvent;
353 aEvent.PropertyHandle = -1;
355 const PropertyValue*
pValues = rValues.getConstArray();
356 sal_Int32
nCount = rValues.getLength();
360 const PropertyValue& rValue =
pValues[
n ];
362 if ( rValue.Name ==
"ContentType" || rValue.Name ==
"IsDocument" || rValue.Name ==
"IsFolder" )
365 aRetRange[
n ] <<= IllegalAccessException(
"Property is read-only!",
368 else if ( rValue.Name ==
"Title" )
371 if ( rValue.Value >>= aNewValue )
373 if ( aNewValue !=
m_pImpl->m_aProps.aTitle )
375 aEvent.PropertyName = rValue.Name;
381 OSL_ENSURE(
m_pImpl->m_aProps.aTitle == aNewValue,
"OContentHelper::setPropertyValues('Title'): rename did not work!" );
383 aEvent.NewValue <<= aNewValue;
384 aChanges.getArray()[ nChanged ] =
aEvent;
389 TOOLS_WARN_EXCEPTION(
"dbaccess",
"OContentHelper::setPropertyValues('Title'): caught an exception while renaming!" );
399 aRetRange[
n ] <<= IllegalTypeException(
"Property value has wrong type!",
406 aRetRange[
n ] <<=
Exception(
"No property set for storing the value!",
415 aChanges.realloc( nChanged );
429 sal_Int32
nCount = rProperties.getLength();
432 const Property* pProps = rProperties.getConstArray();
439 if ( rProp.Name ==
"ContentType" )
443 else if ( rProp.Name ==
"Title" )
445 xRow->appendString ( rProp,
m_pImpl->m_aProps.aTitle );
447 else if ( rProp.Name ==
"IsDocument" )
449 xRow->appendBoolean( rProp,
m_pImpl->m_aProps.bIsDocument );
451 else if ( rProp.Name ==
"IsFolder" )
453 xRow->appendBoolean( rProp,
m_pImpl->m_aProps.bIsFolder );
456 xRow->appendVoid(rProp);
465 PropertyAttribute::BOUND
466 | PropertyAttribute::READONLY ),
471 PropertyAttribute::BOUND ),
476 PropertyAttribute::BOUND
477 | PropertyAttribute::READONLY ),
478 m_pImpl->m_aProps.bIsDocument );
482 PropertyAttribute::BOUND
483 | PropertyAttribute::READONLY ),
495 sal_Int32
nCount = evt.getLength();
501 if ( pAllPropsContainer )
502 pAllPropsContainer->
notifyEach( &XPropertiesChangeListener::propertiesChange, evt );
507 const PropertyChangeEvent* propertyChangeEvent = evt.getConstArray();
509 for ( sal_Int32
n = 0;
n <
nCount; ++
n, ++propertyChangeEvent )
511 const PropertyChangeEvent& rEvent = *propertyChangeEvent;
512 const OUString& rName = rEvent.PropertyName;
515 if ( pPropsContainer )
520 Sequence< PropertyChangeEvent >* propertyEvents;
522 XPropertiesChangeListener* pListener = aIter.
next().get();
523 PropertiesEventListenerMap::iterator it =
aListeners.find( pListener );
527 auto pair =
aListeners.emplace( pListener, Sequence< PropertyChangeEvent >(
nCount ));
528 propertyEvents = &pair.first->second;
531 propertyEvents = &(*it).second;
533 propertyEvents->getArray()[
n] = rEvent;
541 XPropertiesChangeListener* pListener = rPair.first;
542 Sequence< PropertyChangeEvent >& rSeq = rPair.second;
545 pListener->propertiesChange( rSeq );
563 osl::ClearableGuard< osl::Mutex > aGuard(
m_aMutex);
564 if ( _sNewName ==
m_pImpl->m_aProps.aTitle )
568 Sequence<PropertyChangeEvent> aChanges{
579 m_pImpl->m_aProps.aTitle = _sNewName;
584 catch(
const PropertyVetoException&)
586 throw ElementExistException(_sNewName,*
this);
const PropertyValue * pValues
PropertiesInfo aProperties
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
bool hasMoreElements() const
css::uno::Reference< ListenerT > const & next()
sal_Int32 addInterface(const key &rKey, const css::uno::Reference< listener > &rListener)
sal_Int32 removeInterface(const key &rKey, const css::uno::Reference< listener > &rListener)
OInterfaceContainerHelper3< listener > * getContainer(const key &rKey) const
mutable::osl::Mutex m_aMutex
virtual ~OContentHelper_Impl()
virtual void SAL_CALL addContentEventListener(const css::uno::Reference< css::ucb::XContentEventListener > &Listener) override
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
css::uno::Sequence< css::uno::Any > setPropertyValues(const css::uno::Sequence< css::beans::PropertyValue > &rValues)
void notifyDataSourceModified()
OUString impl_getHierarchicalName(bool _includingRootContainer) const
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
::comphelper::OInterfaceContainerHelper3< css::ucb::XContentEventListener > m_aContentListeners
virtual OUString determineContentType() const =0
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 disposing() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
virtual sal_Int32 SAL_CALL createCommandIdentifier() override
const css::uno::Reference< css::uno::XComponentContext > m_aContext
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
virtual void SAL_CALL removeContentEventListener(const css::uno::Reference< css::ucb::XContentEventListener > &Listener) override
virtual void SAL_CALL addPropertiesChangeListener(const css::uno::Sequence< OUString > &PropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &Listener) override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL addProperty(const OUString &Name, sal_Int16 Attributes, const css::uno::Any &DefaultValue) override
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL getIdentifier() override
OContentHelper(const css::uno::Reference< css::uno::XComponentContext > &_xORB, const css::uno::Reference< css::uno::XInterface > &_xParentContainer, TContentPtr _pImpl)
virtual void SAL_CALL abort(sal_Int32 CommandId) override
virtual OUString SAL_CALL getContentType() override
virtual void SAL_CALL removePropertiesChangeListener(const css::uno::Sequence< OUString > &PropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &Listener) override
PropertyChangeListenerContainer m_aPropertyChangeListeners
void impl_rename_throw(const OUString &_sNewName, bool _bNotify=true)
virtual void SAL_CALL rename(const OUString &newName) override
css::uno::Reference< css::uno::XInterface > m_xParentContainer
virtual void SAL_CALL removeProperty(const OUString &Name) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &rProperties)
Reference< XComponentContext > m_aContext
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XContent > m_xParentContainer
std::shared_ptr< OContentHelper_Impl > TContentPtr
void notifyDataSourceModified(const css::uno::Reference< css::uno::XInterface > &_rxObject)
::cppu::WeakComponentImplHelper< css::ucb::XContent, css::ucb::XCommandProcessor, css::lang::XServiceInfo, css::beans::XPropertiesChangeNotifier, css::beans::XPropertyContainer, css::lang::XInitialization, css::container::XChild, css::sdbcx::XRename > OContentHelper_COMPBASE
std::set< PropertyValue, PropertyValueLess > PropertyValueSet
OUString newName(std::u16string_view aNewPrefix, std::u16string_view aOldPrefix, std::u16string_view old_Name)
std::unordered_map< XPropertiesChangeListenerPtr, PropertyEventSequence, hashPtr, equalPtr > PropertiesEventListenerMap
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)
constexpr OUStringLiteral PROPERTY_PERSISTENT_NAME(u"PersistentName")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")