22#include <com/sun/star/beans/IllegalTypeException.hpp>
23#include <com/sun/star/beans/PropertyExistException.hpp>
24#include <com/sun/star/beans/XPropertyAccess.hpp>
25#include <com/sun/star/container/XNameAccess.hpp>
26#include <com/sun/star/container/XNamed.hpp>
27#include <com/sun/star/ucb/Store.hpp>
28#include <com/sun/star/ucb/XPropertySetRegistry.hpp>
29#include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp>
34#include <osl/diagnose.h>
35#include <osl/mutex.hxx>
38#include <unordered_map>
46typedef std::unordered_map
49 uno::WeakReference< ucb::XContent >
64 uno::Reference< uno::XComponentContext > xContext )
77 const OUString& ServiceName )
84 const uno::Reference< css::ucb::XContentIdentifier >& Id1,
85 const uno::Reference< css::ucb::XContentIdentifier >& Id2 )
89 OUString aURL1( Id1->getContentIdentifier() );
90 OUString aURL2( Id2->getContentIdentifier() );
92 return aURL1.compareTo( aURL2 );
99 ucbhelper_impl::Contents::iterator it
100 =
m_pImpl->m_aContents.begin();
101 while( it !=
m_pImpl->m_aContents.end() )
103 uno::Reference< ucb::XContent > xContent( (*it).second );
104 if ( !xContent.is() )
106 ucbhelper_impl::Contents::iterator tmp = it;
108 m_pImpl->m_aContents.erase( tmp );
126 ucbhelper_impl::Contents::iterator it =
m_pImpl->m_aContents.find(
aURL );
128 if ( it !=
m_pImpl->m_aContents.end() )
129 m_pImpl->m_aContents.erase( it );
134 const uno::Reference< css::ucb::XContentIdentifier >& Identifier )
148 ucbhelper_impl::Contents::const_iterator it
149 =
m_pImpl->m_aContents.find( rURL );
150 if ( it !=
m_pImpl->m_aContents.end() )
152 uno::Reference< ucb::XContent > xContent( (*it).second );
169 for (
const auto& rContent :
m_pImpl->m_aContents )
171 uno::Reference< ucb::XContent > xContent( rContent.second );
174 rContents.emplace_back(
181 const uno::Reference< ucb::XContent > & xContent )
183 if ( !xContent.is() )
191 xContent->getIdentifier()->getContentIdentifier() );
192 ucbhelper_impl::Contents::const_iterator it
194 if ( it ==
m_pImpl->m_aContents.end() )
198uno::Reference< css::ucb::XPropertySetRegistry >
205 if ( !
m_pImpl->m_xPropertySetRegistry.is() )
207 uno::Reference< css::ucb::XPropertySetRegistryFactory >
208 xRegFac = css::ucb::Store::create(
m_xContext );
211 m_pImpl->m_xPropertySetRegistry
212 = xRegFac->createPropertySetRegistry( OUString() );
214 OSL_ENSURE(
m_pImpl->m_xPropertySetRegistry.is(),
215 "ContentProviderImplHelper::getAdditionalPropertySet - "
216 "Error opening registry!" );
219 return m_pImpl->m_xPropertySetRegistry;
222uno::Reference< css::ucb::XPersistentPropertySet >
224 const OUString& rKey,
bool bCreate )
229 if (
m_pImpl->m_xPropertySetRegistry.is() )
232 return m_pImpl->m_xPropertySetRegistry->openPropertySet(
236 return uno::Reference< css::ucb::XPersistentPropertySet >();
240 const OUString& rOldKey,
241 const OUString& rNewKey,
244 if ( rOldKey == rNewKey )
254 if ( !
m_pImpl->m_xPropertySetRegistry.is() )
257 uno::Reference< container::XNameAccess > xNameAccess(
258 m_pImpl->m_xPropertySetRegistry, uno::UNO_QUERY );
259 if ( !xNameAccess.is() )
262 const uno::Sequence< OUString > aKeys
263 = xNameAccess->getElementNames();
264 if ( aKeys.hasElements() )
266 OUString aOldKeyWithSlash = rOldKey;
267 OUString aOldKeyWithoutSlash;
268 if ( !aOldKeyWithSlash.endsWith(
"/") )
270 aOldKeyWithSlash +=
"/";
271 aOldKeyWithoutSlash = rOldKey;
273 else if ( !rOldKey.isEmpty() )
275 = rOldKey.copy( 0, rOldKey.getLength() - 1 );
277 for (
const OUString& rKey : aKeys )
279 if ( rKey.startsWith( aOldKeyWithSlash )
280 || rKey == aOldKeyWithoutSlash )
284 0, rOldKey.getLength(), rNewKey );
286 rKey, aNewKey,
false ) )
295 uno::Reference< css::ucb::XPersistentPropertySet > xOldSet
300 uno::Reference< container::XNamed > xNamed(
301 xOldSet, uno::UNO_QUERY );
306 xNamed->setName( rNewKey );
313 const OUString& rSourceKey,
314 const OUString& rTargetKey,
317 if ( rSourceKey == rTargetKey )
327 if ( !
m_pImpl->m_xPropertySetRegistry.is() )
330 uno::Reference< container::XNameAccess > xNameAccess(
331 m_pImpl->m_xPropertySetRegistry, uno::UNO_QUERY );
332 if ( !xNameAccess.is() )
335 const uno::Sequence< OUString > aKeys
336 = xNameAccess->getElementNames();
337 if ( aKeys.hasElements() )
339 OUString aSrcKeyWithSlash = rSourceKey;
340 OUString aSrcKeyWithoutSlash;
341 if ( !aSrcKeyWithSlash.endsWith(
"/") )
343 aSrcKeyWithSlash +=
"/";
344 aSrcKeyWithoutSlash = rSourceKey;
346 else if ( !rSourceKey.isEmpty() )
347 aSrcKeyWithoutSlash = rSourceKey.copy(
348 0, rSourceKey.getLength() - 1 );
350 for (
const OUString& rKey : aKeys )
352 if ( rKey.startsWith(aSrcKeyWithSlash )
353 || rKey == aSrcKeyWithoutSlash )
357 0, rSourceKey.getLength(), rTargetKey );
359 rKey, aNewKey,
false ) )
368 uno::Reference< css::ucb::XPersistentPropertySet >
370 if ( !xOldPropSet.is() )
373 uno::Reference< beans::XPropertySetInfo > xPropSetInfo
374 = xOldPropSet->getPropertySetInfo();
375 if ( !xPropSetInfo.is() )
378 uno::Reference< beans::XPropertyAccess > xOldPropAccess(
379 xOldPropSet, uno::UNO_QUERY );
380 if ( !xOldPropAccess.is() )
384 const uno::Sequence< beans::PropertyValue > aValues
385 = xOldPropAccess->getPropertyValues();
387 const uno::Sequence< beans::Property > aProps
388 = xPropSetInfo->getProperties();
390 if ( aValues.hasElements() )
393 uno::Reference< css::ucb::XPersistentPropertySet >
396 if ( xNewPropSet.is() )
401 if ( !xNewPropSet.is() )
404 uno::Reference< beans::XPropertyContainer > xNewPropContainer(
405 xNewPropSet, uno::UNO_QUERY );
406 if ( !xNewPropContainer.is() )
409 for (
const beans::PropertyValue& rValue : aValues )
411 sal_Int16 nAttribs = 0;
412 auto pProp = std::find_if(aProps.begin(), aProps.end(),
413 [&rValue](
const beans::Property& rProp) { return rProp.Name == rValue.Name; });
414 if (pProp != aProps.end())
415 nAttribs = pProp->Attributes;
419 xNewPropContainer->addProperty(
420 rValue.Name, nAttribs, rValue.Value );
422 catch ( beans::PropertyExistException & )
425 catch ( beans::IllegalTypeException & )
428 catch ( lang::IllegalArgumentException & )
438 const OUString& rKey,
bool bRecursive )
447 if ( !
m_pImpl->m_xPropertySetRegistry.is() )
450 uno::Reference< container::XNameAccess > xNameAccess(
451 m_pImpl->m_xPropertySetRegistry, uno::UNO_QUERY );
452 if ( !xNameAccess.is() )
455 const uno::Sequence< OUString > aKeys
456 = xNameAccess->getElementNames();
457 if ( aKeys.hasElements() )
459 OUString aKeyWithSlash = rKey;
460 OUString aKeyWithoutSlash;
461 if ( !aKeyWithSlash.endsWith(
"/") )
463 aKeyWithSlash +=
"/";
464 aKeyWithoutSlash = rKey;
466 else if ( !rKey.isEmpty() )
468 = rKey.copy( 0, rKey.getLength() - 1 );
470 for (
const OUString& rCurrKey : aKeys )
472 if ( rCurrKey.startsWith(aKeyWithSlash )
473 || rCurrKey == aKeyWithoutSlash )
487 if ( !
m_pImpl->m_xPropertySetRegistry.is() )
490 m_pImpl->m_xPropertySetRegistry->removePropertySet( rKey );
Reference< XComponentContext > m_xContext
This is an abstract base class for implementations of the service com.sun.star.ucb....
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL getIdentifier() override
bool renameAdditionalPropertySet(const OUString &rOldKey, const OUString &rNewKey, bool bRecursive)
This method renames the propertyset containing the Additional Core Properties of a content.
bool removeAdditionalPropertySet(const OUString &rKey, bool bRecursive)
This method removes the propertyset containing the Additional Core Properties of a content.
rtl::Reference< ContentImplHelper > queryExistingContent(const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier)
This method returns a content with the given id, if it already exists.
bool copyAdditionalPropertySet(const OUString &rSourceKey, const OUString &rTargetKey, bool bRecursive)
This method copies the propertyset containing the Additional Core Properties of a content.
void registerNewContent(const css::uno::Reference< css::ucb::XContent > &xContent)
This method registers a newly created content instance with the content provider.
void queryExistingContents(ContentRefList &rContents)
This method fills a list with all contents existing at calling time.
ContentProviderImplHelper(css::uno::Reference< css::uno::XComponentContext > xContext)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
UCBHELPER_DLLPRIVATE void removeContent(ContentImplHelper *pContent)
css::uno::Reference< css::ucb::XPersistentPropertySet > getAdditionalPropertySet(const OUString &rKey, bool bCreate)
This method returns the propertyset containing the Additional Core Properties of a content.
std::unique_ptr< ucbhelper_impl::ContentProviderImplHelper_Impl > m_pImpl
UCBHELPER_DLLPRIVATE css::uno::Reference< css::ucb::XPropertySetRegistry > getAdditionalPropertySetRegistry()
virtual ~ContentProviderImplHelper() override
UCBHELPER_DLLPRIVATE void cleanupRegisteredContents()
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual sal_Int32 SAL_CALL compareContentIds(const css::uno::Reference< css::ucb::XContentIdentifier > &Id1, const css::uno::Reference< css::ucb::XContentIdentifier > &Id2) override
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::unordered_map< OUString, uno::WeakReference< ucb::XContent > > Contents
std::vector< ContentImplHelperRef > ContentRefList
uno::Reference< css::ucb::XPropertySetRegistry > m_xPropertySetRegistry