1*ac9096f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*ac9096f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*ac9096f4SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*ac9096f4SAndrew Rist * distributed with this work for additional information
6*ac9096f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*ac9096f4SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*ac9096f4SAndrew Rist * "License"); you may not use this file except in compliance
9*ac9096f4SAndrew Rist * with the License. You may obtain a copy of the License at
10*ac9096f4SAndrew Rist *
11*ac9096f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*ac9096f4SAndrew Rist *
13*ac9096f4SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*ac9096f4SAndrew Rist * software distributed under the License is distributed on an
15*ac9096f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ac9096f4SAndrew Rist * KIND, either express or implied. See the License for the
17*ac9096f4SAndrew Rist * specific language governing permissions and limitations
18*ac9096f4SAndrew Rist * under the License.
19*ac9096f4SAndrew Rist *
20*ac9096f4SAndrew Rist *************************************************************/
21*ac9096f4SAndrew Rist
22*ac9096f4SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucbhelper.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir TODO
29cdf0e10cSrcweir **************************************************************************
30cdf0e10cSrcweir
31cdf0e10cSrcweir *************************************************************************/
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <hash_map>
34cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyAccess.hpp>
35cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
36cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
37cdf0e10cSrcweir #include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp>
38cdf0e10cSrcweir #include <com/sun/star/ucb/XPropertySetRegistry.hpp>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include "osl/diagnose.h"
41cdf0e10cSrcweir #include "osl/mutex.hxx"
42cdf0e10cSrcweir #include "cppuhelper/weakref.hxx"
43cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx>
44cdf0e10cSrcweir #include <ucbhelper/providerhelper.hxx>
45cdf0e10cSrcweir #include <ucbhelper/contenthelper.hxx>
46cdf0e10cSrcweir
47cdf0e10cSrcweir using namespace com::sun::star;
48cdf0e10cSrcweir
49cdf0e10cSrcweir namespace ucbhelper_impl
50cdf0e10cSrcweir {
51cdf0e10cSrcweir
52cdf0e10cSrcweir //=========================================================================
53cdf0e10cSrcweir //
54cdf0e10cSrcweir // Contents.
55cdf0e10cSrcweir //
56cdf0e10cSrcweir //=========================================================================
57cdf0e10cSrcweir
58cdf0e10cSrcweir struct equalString
59cdf0e10cSrcweir {
operator ()ucbhelper_impl::equalString60cdf0e10cSrcweir bool operator()(
61cdf0e10cSrcweir const rtl::OUString& rKey11, const rtl::OUString& rKey22 ) const
62cdf0e10cSrcweir {
63cdf0e10cSrcweir return !!( rKey11 == rKey22 );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir };
66cdf0e10cSrcweir
67cdf0e10cSrcweir struct hashString
68cdf0e10cSrcweir {
operator ()ucbhelper_impl::hashString69cdf0e10cSrcweir size_t operator()( const rtl::OUString & rName ) const
70cdf0e10cSrcweir {
71cdf0e10cSrcweir return rName.hashCode();
72cdf0e10cSrcweir }
73cdf0e10cSrcweir };
74cdf0e10cSrcweir
75cdf0e10cSrcweir typedef std::hash_map
76cdf0e10cSrcweir <
77cdf0e10cSrcweir rtl::OUString,
78cdf0e10cSrcweir uno::WeakReference< ucb::XContent >,
79cdf0e10cSrcweir hashString,
80cdf0e10cSrcweir equalString
81cdf0e10cSrcweir >
82cdf0e10cSrcweir Contents;
83cdf0e10cSrcweir
84cdf0e10cSrcweir //=========================================================================
85cdf0e10cSrcweir //
86cdf0e10cSrcweir // struct ContentProviderImplHelper_Impl.
87cdf0e10cSrcweir //
88cdf0e10cSrcweir //=========================================================================
89cdf0e10cSrcweir
90cdf0e10cSrcweir struct ContentProviderImplHelper_Impl
91cdf0e10cSrcweir {
92cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XPropertySetRegistry >
93cdf0e10cSrcweir m_xPropertySetRegistry;
94cdf0e10cSrcweir Contents
95cdf0e10cSrcweir m_aContents;
96cdf0e10cSrcweir };
97cdf0e10cSrcweir
98cdf0e10cSrcweir } // namespace ucbhelper_impl
99cdf0e10cSrcweir
100cdf0e10cSrcweir //=========================================================================
101cdf0e10cSrcweir //=========================================================================
102cdf0e10cSrcweir //
103cdf0e10cSrcweir // ContentProviderImplHelper Implementation.
104cdf0e10cSrcweir //
105cdf0e10cSrcweir //=========================================================================
106cdf0e10cSrcweir //=========================================================================
107cdf0e10cSrcweir
108cdf0e10cSrcweir namespace ucbhelper {
109cdf0e10cSrcweir
ContentProviderImplHelper(const uno::Reference<lang::XMultiServiceFactory> & rXSMgr)110cdf0e10cSrcweir ContentProviderImplHelper::ContentProviderImplHelper(
111cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rXSMgr )
112cdf0e10cSrcweir : m_pImpl( new ucbhelper_impl::ContentProviderImplHelper_Impl ),
113cdf0e10cSrcweir m_xSMgr( rXSMgr )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir }
116cdf0e10cSrcweir
117cdf0e10cSrcweir //=========================================================================
118cdf0e10cSrcweir // virtual
~ContentProviderImplHelper()119cdf0e10cSrcweir ContentProviderImplHelper::~ContentProviderImplHelper()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir delete m_pImpl;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir //=========================================================================
125cdf0e10cSrcweir //
126cdf0e10cSrcweir // XInterface methods.
127cdf0e10cSrcweir //
128cdf0e10cSrcweir //=========================================================================
129cdf0e10cSrcweir
130cdf0e10cSrcweir XINTERFACE_IMPL_3( ContentProviderImplHelper,
131cdf0e10cSrcweir lang::XTypeProvider,
132cdf0e10cSrcweir lang::XServiceInfo,
133cdf0e10cSrcweir com::sun::star::ucb::XContentProvider );
134cdf0e10cSrcweir
135cdf0e10cSrcweir //=========================================================================
136cdf0e10cSrcweir //
137cdf0e10cSrcweir // XTypeProvider methods.
138cdf0e10cSrcweir //
139cdf0e10cSrcweir //=========================================================================
140cdf0e10cSrcweir
141cdf0e10cSrcweir XTYPEPROVIDER_IMPL_3( ContentProviderImplHelper,
142cdf0e10cSrcweir lang::XTypeProvider,
143cdf0e10cSrcweir lang::XServiceInfo,
144cdf0e10cSrcweir com::sun::star::ucb::XContentProvider );
145cdf0e10cSrcweir
146cdf0e10cSrcweir //=========================================================================
147cdf0e10cSrcweir //
148cdf0e10cSrcweir // XServiceInfo methods.
149cdf0e10cSrcweir //
150cdf0e10cSrcweir //=========================================================================
151cdf0e10cSrcweir
152cdf0e10cSrcweir // virtual
supportsService(const rtl::OUString & ServiceName)153cdf0e10cSrcweir sal_Bool SAL_CALL ContentProviderImplHelper::supportsService(
154cdf0e10cSrcweir const rtl::OUString& ServiceName )
155cdf0e10cSrcweir throw( uno::RuntimeException )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir uno::Sequence< rtl::OUString > aSNL = getSupportedServiceNames();
158cdf0e10cSrcweir const rtl::OUString* pArray = aSNL.getConstArray();
159cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir if ( pArray[ i ] == ServiceName )
162cdf0e10cSrcweir return sal_True;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir
165cdf0e10cSrcweir return sal_False;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir //=========================================================================
169cdf0e10cSrcweir //
170cdf0e10cSrcweir // XContentProvider methods.
171cdf0e10cSrcweir //
172cdf0e10cSrcweir //=========================================================================
173cdf0e10cSrcweir
174cdf0e10cSrcweir // virtual
compareContentIds(const uno::Reference<com::sun::star::ucb::XContentIdentifier> & Id1,const uno::Reference<com::sun::star::ucb::XContentIdentifier> & Id2)175cdf0e10cSrcweir sal_Int32 SAL_CALL ContentProviderImplHelper::compareContentIds(
176cdf0e10cSrcweir const uno::Reference< com::sun::star::ucb::XContentIdentifier >& Id1,
177cdf0e10cSrcweir const uno::Reference< com::sun::star::ucb::XContentIdentifier >& Id2 )
178cdf0e10cSrcweir throw( uno::RuntimeException )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir // Simply do a string compare.
181cdf0e10cSrcweir
182cdf0e10cSrcweir rtl::OUString aURL1( Id1->getContentIdentifier() );
183cdf0e10cSrcweir rtl::OUString aURL2( Id2->getContentIdentifier() );
184cdf0e10cSrcweir
185cdf0e10cSrcweir return aURL1.compareTo( aURL2 );;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir //=========================================================================
189cdf0e10cSrcweir //
190cdf0e10cSrcweir // Non-interface methods
191cdf0e10cSrcweir //
192cdf0e10cSrcweir //=========================================================================
193cdf0e10cSrcweir
cleanupRegisteredContents()194cdf0e10cSrcweir void ContentProviderImplHelper::cleanupRegisteredContents()
195cdf0e10cSrcweir {
196cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
197cdf0e10cSrcweir
198cdf0e10cSrcweir ucbhelper_impl::Contents::iterator it
199cdf0e10cSrcweir = m_pImpl->m_aContents.begin();
200cdf0e10cSrcweir while( it != m_pImpl->m_aContents.end() )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir uno::Reference< ucb::XContent > xContent( (*it).second );
203cdf0e10cSrcweir if ( !xContent.is() )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir ucbhelper_impl::Contents::iterator tmp = it;
206cdf0e10cSrcweir ++it;
207cdf0e10cSrcweir m_pImpl->m_aContents.erase( tmp );
208cdf0e10cSrcweir }
209cdf0e10cSrcweir else
210cdf0e10cSrcweir {
211cdf0e10cSrcweir ++it;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir }
214cdf0e10cSrcweir }
215cdf0e10cSrcweir
216cdf0e10cSrcweir //=========================================================================
217cdf0e10cSrcweir
removeContent(ContentImplHelper * pContent)218cdf0e10cSrcweir void ContentProviderImplHelper::removeContent( ContentImplHelper* pContent )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
221cdf0e10cSrcweir
222cdf0e10cSrcweir cleanupRegisteredContents();
223cdf0e10cSrcweir
224cdf0e10cSrcweir const rtl::OUString aURL(
225cdf0e10cSrcweir pContent->getIdentifier()->getContentIdentifier() );
226cdf0e10cSrcweir
227cdf0e10cSrcweir ucbhelper_impl::Contents::iterator it = m_pImpl->m_aContents.find( aURL );
228cdf0e10cSrcweir
229cdf0e10cSrcweir if ( it != m_pImpl->m_aContents.end() )
230cdf0e10cSrcweir m_pImpl->m_aContents.erase( it );
231cdf0e10cSrcweir }
232cdf0e10cSrcweir
233cdf0e10cSrcweir //=========================================================================
234cdf0e10cSrcweir rtl::Reference< ContentImplHelper >
queryExistingContent(const uno::Reference<com::sun::star::ucb::XContentIdentifier> & Identifier)235cdf0e10cSrcweir ContentProviderImplHelper::queryExistingContent(
236cdf0e10cSrcweir const uno::Reference< com::sun::star::ucb::XContentIdentifier >&
237cdf0e10cSrcweir Identifier )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir return queryExistingContent( Identifier->getContentIdentifier() );
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
242cdf0e10cSrcweir //=========================================================================
243cdf0e10cSrcweir rtl::Reference< ContentImplHelper >
queryExistingContent(const rtl::OUString & rURL)244cdf0e10cSrcweir ContentProviderImplHelper::queryExistingContent( const rtl::OUString& rURL )
245cdf0e10cSrcweir {
246cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
247cdf0e10cSrcweir
248cdf0e10cSrcweir cleanupRegisteredContents();
249cdf0e10cSrcweir
250cdf0e10cSrcweir // Check, if a content with given id already exists...
251cdf0e10cSrcweir
252cdf0e10cSrcweir ucbhelper_impl::Contents::const_iterator it
253cdf0e10cSrcweir = m_pImpl->m_aContents.find( rURL );
254cdf0e10cSrcweir if ( it != m_pImpl->m_aContents.end() )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir uno::Reference< ucb::XContent > xContent( (*it).second );
257cdf0e10cSrcweir if ( xContent.is() )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir return rtl::Reference< ContentImplHelper >(
260cdf0e10cSrcweir static_cast< ContentImplHelper * >( xContent.get() ) );
261cdf0e10cSrcweir }
262cdf0e10cSrcweir }
263cdf0e10cSrcweir return rtl::Reference< ContentImplHelper >();
264cdf0e10cSrcweir }
265cdf0e10cSrcweir
266cdf0e10cSrcweir //=========================================================================
queryExistingContents(ContentRefList & rContents)267cdf0e10cSrcweir void ContentProviderImplHelper::queryExistingContents(
268cdf0e10cSrcweir ContentRefList& rContents )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
271cdf0e10cSrcweir
272cdf0e10cSrcweir cleanupRegisteredContents();
273cdf0e10cSrcweir
274cdf0e10cSrcweir ucbhelper_impl::Contents::const_iterator it
275cdf0e10cSrcweir = m_pImpl->m_aContents.begin();
276cdf0e10cSrcweir ucbhelper_impl::Contents::const_iterator end
277cdf0e10cSrcweir = m_pImpl->m_aContents.end();
278cdf0e10cSrcweir
279cdf0e10cSrcweir while ( it != end )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir uno::Reference< ucb::XContent > xContent( (*it).second );
282cdf0e10cSrcweir if ( xContent.is() )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir rContents.push_back(
285cdf0e10cSrcweir rtl::Reference< ContentImplHelper >(
286cdf0e10cSrcweir static_cast< ContentImplHelper * >( xContent.get() ) ) );
287cdf0e10cSrcweir }
288cdf0e10cSrcweir ++it;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir }
291cdf0e10cSrcweir
292cdf0e10cSrcweir //=========================================================================
registerNewContent(const uno::Reference<ucb::XContent> & xContent)293cdf0e10cSrcweir void ContentProviderImplHelper::registerNewContent(
294cdf0e10cSrcweir const uno::Reference< ucb::XContent > & xContent )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir if ( xContent.is() )
297cdf0e10cSrcweir {
298cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
299cdf0e10cSrcweir
300cdf0e10cSrcweir cleanupRegisteredContents();
301cdf0e10cSrcweir
302cdf0e10cSrcweir const rtl::OUString aURL(
303cdf0e10cSrcweir xContent->getIdentifier()->getContentIdentifier() );
304cdf0e10cSrcweir ucbhelper_impl::Contents::const_iterator it
305cdf0e10cSrcweir = m_pImpl->m_aContents.find( aURL );
306cdf0e10cSrcweir if ( it == m_pImpl->m_aContents.end() )
307cdf0e10cSrcweir m_pImpl->m_aContents[ aURL ] = xContent;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir }
310cdf0e10cSrcweir
311cdf0e10cSrcweir //=========================================================================
312cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XPropertySetRegistry >
getAdditionalPropertySetRegistry()313cdf0e10cSrcweir ContentProviderImplHelper::getAdditionalPropertySetRegistry()
314cdf0e10cSrcweir {
315cdf0e10cSrcweir // Get propertyset registry.
316cdf0e10cSrcweir
317cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
318cdf0e10cSrcweir
319cdf0e10cSrcweir if ( !m_pImpl->m_xPropertySetRegistry.is() )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XPropertySetRegistryFactory >
322cdf0e10cSrcweir xRegFac(
323cdf0e10cSrcweir m_xSMgr->createInstance(
324cdf0e10cSrcweir rtl::OUString::createFromAscii(
325cdf0e10cSrcweir "com.sun.star.ucb.Store" ) ),
326cdf0e10cSrcweir uno::UNO_QUERY );
327cdf0e10cSrcweir
328cdf0e10cSrcweir OSL_ENSURE( xRegFac.is(),
329cdf0e10cSrcweir "ContentProviderImplHelper::getAdditionalPropertySet - "
330cdf0e10cSrcweir "No UCB-Store service!" );
331cdf0e10cSrcweir
332cdf0e10cSrcweir if ( xRegFac.is() )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir // Open/create a registry.
335cdf0e10cSrcweir m_pImpl->m_xPropertySetRegistry
336cdf0e10cSrcweir = xRegFac->createPropertySetRegistry( rtl::OUString() );
337cdf0e10cSrcweir
338cdf0e10cSrcweir OSL_ENSURE( m_pImpl->m_xPropertySetRegistry.is(),
339cdf0e10cSrcweir "ContentProviderImplHelper::getAdditionalPropertySet - "
340cdf0e10cSrcweir "Error opening registry!" );
341cdf0e10cSrcweir }
342cdf0e10cSrcweir }
343cdf0e10cSrcweir
344cdf0e10cSrcweir return m_pImpl->m_xPropertySetRegistry;
345cdf0e10cSrcweir }
346cdf0e10cSrcweir
347cdf0e10cSrcweir
348cdf0e10cSrcweir //=========================================================================
349cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XPersistentPropertySet >
getAdditionalPropertySet(const rtl::OUString & rKey,sal_Bool bCreate)350cdf0e10cSrcweir ContentProviderImplHelper::getAdditionalPropertySet(
351cdf0e10cSrcweir const rtl::OUString& rKey, sal_Bool bCreate )
352cdf0e10cSrcweir {
353cdf0e10cSrcweir // Get propertyset registry.
354cdf0e10cSrcweir getAdditionalPropertySetRegistry();
355cdf0e10cSrcweir
356cdf0e10cSrcweir if ( m_pImpl->m_xPropertySetRegistry.is() )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir // Open/create persistent property set.
359cdf0e10cSrcweir return uno::Reference< com::sun::star::ucb::XPersistentPropertySet >(
360cdf0e10cSrcweir m_pImpl->m_xPropertySetRegistry->openPropertySet(
361cdf0e10cSrcweir rKey, bCreate ) );
362cdf0e10cSrcweir }
363cdf0e10cSrcweir
364cdf0e10cSrcweir return uno::Reference< com::sun::star::ucb::XPersistentPropertySet >();
365cdf0e10cSrcweir }
366cdf0e10cSrcweir
367cdf0e10cSrcweir //=========================================================================
renameAdditionalPropertySet(const rtl::OUString & rOldKey,const rtl::OUString & rNewKey,sal_Bool bRecursive)368cdf0e10cSrcweir sal_Bool ContentProviderImplHelper::renameAdditionalPropertySet(
369cdf0e10cSrcweir const rtl::OUString& rOldKey,
370cdf0e10cSrcweir const rtl::OUString& rNewKey,
371cdf0e10cSrcweir sal_Bool bRecursive )
372cdf0e10cSrcweir {
373cdf0e10cSrcweir if ( rOldKey == rNewKey )
374cdf0e10cSrcweir return sal_True;
375cdf0e10cSrcweir
376cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
377cdf0e10cSrcweir
378cdf0e10cSrcweir if ( bRecursive )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir // Get propertyset registry.
381cdf0e10cSrcweir getAdditionalPropertySetRegistry();
382cdf0e10cSrcweir
383cdf0e10cSrcweir if ( m_pImpl->m_xPropertySetRegistry.is() )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess(
386cdf0e10cSrcweir m_pImpl->m_xPropertySetRegistry, uno::UNO_QUERY );
387cdf0e10cSrcweir if ( xNameAccess.is() )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir uno::Sequence< rtl::OUString > aKeys
390cdf0e10cSrcweir = xNameAccess->getElementNames();
391cdf0e10cSrcweir sal_Int32 nCount = aKeys.getLength();
392cdf0e10cSrcweir if ( nCount > 0 )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir rtl::OUString aOldKeyWithSlash = rOldKey;
395cdf0e10cSrcweir rtl::OUString aOldKeyWithoutSlash;
396cdf0e10cSrcweir if ( aOldKeyWithSlash.lastIndexOf(
397cdf0e10cSrcweir sal_Unicode('/')
398cdf0e10cSrcweir != aOldKeyWithSlash.getLength() - 1 ) )
399cdf0e10cSrcweir {
400cdf0e10cSrcweir aOldKeyWithSlash += rtl::OUString( sal_Unicode('/') );
401cdf0e10cSrcweir aOldKeyWithoutSlash = rOldKey;
402cdf0e10cSrcweir }
403cdf0e10cSrcweir else if ( rOldKey.getLength() )
404cdf0e10cSrcweir aOldKeyWithoutSlash
405cdf0e10cSrcweir = rOldKey.copy( 0, rOldKey.getLength() - 1 );
406cdf0e10cSrcweir
407cdf0e10cSrcweir const rtl::OUString* pKeys = aKeys.getConstArray();
408cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
409cdf0e10cSrcweir {
410cdf0e10cSrcweir const rtl::OUString& rKey = pKeys[ n ];
411cdf0e10cSrcweir if ( rKey.compareTo(
412cdf0e10cSrcweir aOldKeyWithSlash,
413cdf0e10cSrcweir aOldKeyWithSlash.getLength() ) == 0
414cdf0e10cSrcweir || rKey.equals( aOldKeyWithoutSlash ) )
415cdf0e10cSrcweir {
416cdf0e10cSrcweir rtl::OUString aNewKey
417cdf0e10cSrcweir = rKey.replaceAt(
418cdf0e10cSrcweir 0, rOldKey.getLength(), rNewKey );
419cdf0e10cSrcweir if ( !renameAdditionalPropertySet(
420cdf0e10cSrcweir rKey, aNewKey, sal_False ) )
421cdf0e10cSrcweir return sal_False;
422cdf0e10cSrcweir }
423cdf0e10cSrcweir }
424cdf0e10cSrcweir }
425cdf0e10cSrcweir }
426cdf0e10cSrcweir else
427cdf0e10cSrcweir return sal_False;
428cdf0e10cSrcweir }
429cdf0e10cSrcweir else
430cdf0e10cSrcweir return sal_False;
431cdf0e10cSrcweir }
432cdf0e10cSrcweir else
433cdf0e10cSrcweir {
434cdf0e10cSrcweir // Get old property set, if exists.
435cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XPersistentPropertySet > xOldSet
436cdf0e10cSrcweir = getAdditionalPropertySet( rOldKey, sal_False );
437cdf0e10cSrcweir if ( xOldSet.is() )
438cdf0e10cSrcweir {
439cdf0e10cSrcweir // Rename property set.
440cdf0e10cSrcweir uno::Reference< container::XNamed > xNamed(
441cdf0e10cSrcweir xOldSet, uno::UNO_QUERY );
442cdf0e10cSrcweir if ( xNamed.is() )
443cdf0e10cSrcweir {
444cdf0e10cSrcweir // ??? throws no exceptions and has no return value ???
445cdf0e10cSrcweir xNamed->setName( rNewKey );
446cdf0e10cSrcweir }
447cdf0e10cSrcweir else
448cdf0e10cSrcweir return sal_False;
449cdf0e10cSrcweir }
450cdf0e10cSrcweir }
451cdf0e10cSrcweir return sal_True;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir
454cdf0e10cSrcweir //=========================================================================
copyAdditionalPropertySet(const rtl::OUString & rSourceKey,const rtl::OUString & rTargetKey,sal_Bool bRecursive)455cdf0e10cSrcweir sal_Bool ContentProviderImplHelper::copyAdditionalPropertySet(
456cdf0e10cSrcweir const rtl::OUString& rSourceKey,
457cdf0e10cSrcweir const rtl::OUString& rTargetKey,
458cdf0e10cSrcweir sal_Bool bRecursive )
459cdf0e10cSrcweir {
460cdf0e10cSrcweir if ( rSourceKey == rTargetKey )
461cdf0e10cSrcweir return sal_True;
462cdf0e10cSrcweir
463cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
464cdf0e10cSrcweir
465cdf0e10cSrcweir if ( bRecursive )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir // Get propertyset registry.
468cdf0e10cSrcweir getAdditionalPropertySetRegistry();
469cdf0e10cSrcweir
470cdf0e10cSrcweir if ( m_pImpl->m_xPropertySetRegistry.is() )
471cdf0e10cSrcweir {
472cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess(
473cdf0e10cSrcweir m_pImpl->m_xPropertySetRegistry, uno::UNO_QUERY );
474cdf0e10cSrcweir if ( xNameAccess.is() )
475cdf0e10cSrcweir {
476cdf0e10cSrcweir uno::Sequence< rtl::OUString > aKeys
477cdf0e10cSrcweir = xNameAccess->getElementNames();
478cdf0e10cSrcweir sal_Int32 nCount = aKeys.getLength();
479cdf0e10cSrcweir if ( nCount > 0 )
480cdf0e10cSrcweir {
481cdf0e10cSrcweir rtl::OUString aSrcKeyWithSlash = rSourceKey;
482cdf0e10cSrcweir rtl::OUString aSrcKeyWithoutSlash;
483cdf0e10cSrcweir if ( aSrcKeyWithSlash.lastIndexOf(
484cdf0e10cSrcweir sal_Unicode('/')
485cdf0e10cSrcweir != aSrcKeyWithSlash.getLength() - 1 ) )
486cdf0e10cSrcweir {
487cdf0e10cSrcweir aSrcKeyWithSlash += rtl::OUString( sal_Unicode('/') );
488cdf0e10cSrcweir aSrcKeyWithoutSlash = rSourceKey;
489cdf0e10cSrcweir }
490cdf0e10cSrcweir else if ( rSourceKey.getLength() )
491cdf0e10cSrcweir aSrcKeyWithoutSlash = rSourceKey.copy(
492cdf0e10cSrcweir 0, rSourceKey.getLength() - 1 );
493cdf0e10cSrcweir
494cdf0e10cSrcweir const rtl::OUString* pKeys = aKeys.getConstArray();
495cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
496cdf0e10cSrcweir {
497cdf0e10cSrcweir const rtl::OUString& rKey = pKeys[ n ];
498cdf0e10cSrcweir if ( rKey.compareTo(
499cdf0e10cSrcweir aSrcKeyWithSlash,
500cdf0e10cSrcweir aSrcKeyWithSlash.getLength() ) == 0
501cdf0e10cSrcweir || rKey.equals( aSrcKeyWithoutSlash ) )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir rtl::OUString aNewKey
504cdf0e10cSrcweir = rKey.replaceAt(
505cdf0e10cSrcweir 0, rSourceKey.getLength(), rTargetKey );
506cdf0e10cSrcweir if ( !copyAdditionalPropertySet(
507cdf0e10cSrcweir rKey, aNewKey, sal_False ) )
508cdf0e10cSrcweir return sal_False;
509cdf0e10cSrcweir }
510cdf0e10cSrcweir }
511cdf0e10cSrcweir }
512cdf0e10cSrcweir }
513cdf0e10cSrcweir else
514cdf0e10cSrcweir return sal_False;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir else
517cdf0e10cSrcweir return sal_False;
518cdf0e10cSrcweir }
519cdf0e10cSrcweir else
520cdf0e10cSrcweir {
521cdf0e10cSrcweir // Get old property set, if exists.
522cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XPersistentPropertySet >
523cdf0e10cSrcweir xOldPropSet = getAdditionalPropertySet( rSourceKey, sal_False );
524cdf0e10cSrcweir if ( !xOldPropSet.is() )
525cdf0e10cSrcweir return sal_False;
526cdf0e10cSrcweir
527cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > xPropSetInfo
528cdf0e10cSrcweir = xOldPropSet->getPropertySetInfo();
529cdf0e10cSrcweir if ( !xPropSetInfo.is() )
530cdf0e10cSrcweir return sal_False;
531cdf0e10cSrcweir
532cdf0e10cSrcweir uno::Reference< beans::XPropertyAccess > xOldPropAccess(
533cdf0e10cSrcweir xOldPropSet, uno::UNO_QUERY );
534cdf0e10cSrcweir if ( !xOldPropAccess.is() )
535cdf0e10cSrcweir return sal_False;
536cdf0e10cSrcweir
537cdf0e10cSrcweir // Obtain all values from old set.
538cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aValues
539cdf0e10cSrcweir = xOldPropAccess->getPropertyValues();
540cdf0e10cSrcweir sal_Int32 nCount = aValues.getLength();
541cdf0e10cSrcweir
542cdf0e10cSrcweir uno::Sequence< beans::Property > aProps
543cdf0e10cSrcweir = xPropSetInfo->getProperties();
544cdf0e10cSrcweir
545cdf0e10cSrcweir if ( nCount )
546cdf0e10cSrcweir {
547cdf0e10cSrcweir // Fail, if property set with new key already exists.
548cdf0e10cSrcweir uno::Reference< com::sun::star::ucb::XPersistentPropertySet >
549cdf0e10cSrcweir xNewPropSet
550cdf0e10cSrcweir = getAdditionalPropertySet( rTargetKey, sal_False );
551cdf0e10cSrcweir if ( xNewPropSet.is() )
552cdf0e10cSrcweir return sal_False;
553cdf0e10cSrcweir
554cdf0e10cSrcweir // Create new, empty set.
555cdf0e10cSrcweir xNewPropSet = getAdditionalPropertySet( rTargetKey, sal_True );
556cdf0e10cSrcweir if ( !xNewPropSet.is() )
557cdf0e10cSrcweir return sal_False;
558cdf0e10cSrcweir
559cdf0e10cSrcweir uno::Reference< beans::XPropertyContainer > xNewPropContainer(
560cdf0e10cSrcweir xNewPropSet, uno::UNO_QUERY );
561cdf0e10cSrcweir if ( !xNewPropContainer.is() )
562cdf0e10cSrcweir return sal_False;
563cdf0e10cSrcweir
564cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
565cdf0e10cSrcweir {
566cdf0e10cSrcweir const beans::PropertyValue& rValue = aValues[ n ];
567cdf0e10cSrcweir
568cdf0e10cSrcweir sal_Int16 nAttribs = 0;
569cdf0e10cSrcweir for ( sal_Int32 m = 0; m < aProps.getLength(); ++m )
570cdf0e10cSrcweir {
571cdf0e10cSrcweir if ( aProps[ m ].Name == rValue.Name )
572cdf0e10cSrcweir {
573cdf0e10cSrcweir nAttribs = aProps[ m ].Attributes;
574cdf0e10cSrcweir break;
575cdf0e10cSrcweir }
576cdf0e10cSrcweir }
577cdf0e10cSrcweir
578cdf0e10cSrcweir try
579cdf0e10cSrcweir {
580cdf0e10cSrcweir xNewPropContainer->addProperty(
581cdf0e10cSrcweir rValue.Name, nAttribs, rValue.Value );
582cdf0e10cSrcweir }
583cdf0e10cSrcweir catch ( beans::PropertyExistException & )
584cdf0e10cSrcweir {
585cdf0e10cSrcweir }
586cdf0e10cSrcweir catch ( beans::IllegalTypeException & )
587cdf0e10cSrcweir {
588cdf0e10cSrcweir }
589cdf0e10cSrcweir catch ( lang::IllegalArgumentException & )
590cdf0e10cSrcweir {
591cdf0e10cSrcweir }
592cdf0e10cSrcweir }
593cdf0e10cSrcweir }
594cdf0e10cSrcweir }
595cdf0e10cSrcweir return sal_True;
596cdf0e10cSrcweir }
597cdf0e10cSrcweir
598cdf0e10cSrcweir //=========================================================================
removeAdditionalPropertySet(const rtl::OUString & rKey,sal_Bool bRecursive)599cdf0e10cSrcweir sal_Bool ContentProviderImplHelper::removeAdditionalPropertySet(
600cdf0e10cSrcweir const rtl::OUString& rKey, sal_Bool bRecursive )
601cdf0e10cSrcweir {
602cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
603cdf0e10cSrcweir
604cdf0e10cSrcweir if ( bRecursive )
605cdf0e10cSrcweir {
606cdf0e10cSrcweir // Get propertyset registry.
607cdf0e10cSrcweir getAdditionalPropertySetRegistry();
608cdf0e10cSrcweir
609cdf0e10cSrcweir if ( m_pImpl->m_xPropertySetRegistry.is() )
610cdf0e10cSrcweir {
611cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess(
612cdf0e10cSrcweir m_pImpl->m_xPropertySetRegistry, uno::UNO_QUERY );
613cdf0e10cSrcweir if ( xNameAccess.is() )
614cdf0e10cSrcweir {
615cdf0e10cSrcweir uno::Sequence< rtl::OUString > aKeys
616cdf0e10cSrcweir = xNameAccess->getElementNames();
617cdf0e10cSrcweir sal_Int32 nCount = aKeys.getLength();
618cdf0e10cSrcweir if ( nCount > 0 )
619cdf0e10cSrcweir {
620cdf0e10cSrcweir rtl::OUString aKeyWithSlash = rKey;
621cdf0e10cSrcweir rtl::OUString aKeyWithoutSlash;
622cdf0e10cSrcweir if ( aKeyWithSlash.lastIndexOf(
623cdf0e10cSrcweir sal_Unicode('/')
624cdf0e10cSrcweir != aKeyWithSlash.getLength() - 1 ) )
625cdf0e10cSrcweir {
626cdf0e10cSrcweir aKeyWithSlash += rtl::OUString( (sal_Unicode)'/' );
627cdf0e10cSrcweir aKeyWithoutSlash = rKey;
628cdf0e10cSrcweir }
629cdf0e10cSrcweir else if ( rKey.getLength() )
630cdf0e10cSrcweir aKeyWithoutSlash
631cdf0e10cSrcweir = rKey.copy( 0, rKey.getLength() - 1 );
632cdf0e10cSrcweir
633cdf0e10cSrcweir const rtl::OUString* pKeys = aKeys.getConstArray();
634cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n )
635cdf0e10cSrcweir {
636cdf0e10cSrcweir const rtl::OUString& rCurrKey = pKeys[ n ];
637cdf0e10cSrcweir if ( rCurrKey.compareTo(
638cdf0e10cSrcweir aKeyWithSlash,
639cdf0e10cSrcweir aKeyWithSlash.getLength() ) == 0
640cdf0e10cSrcweir || rCurrKey.equals( aKeyWithoutSlash ) )
641cdf0e10cSrcweir {
642cdf0e10cSrcweir if ( !removeAdditionalPropertySet(
643cdf0e10cSrcweir rCurrKey, sal_False ) )
644cdf0e10cSrcweir return sal_False;
645cdf0e10cSrcweir }
646cdf0e10cSrcweir }
647cdf0e10cSrcweir }
648cdf0e10cSrcweir }
649cdf0e10cSrcweir else
650cdf0e10cSrcweir return sal_False;
651cdf0e10cSrcweir }
652cdf0e10cSrcweir else
653cdf0e10cSrcweir return sal_False;
654cdf0e10cSrcweir }
655cdf0e10cSrcweir else
656cdf0e10cSrcweir {
657cdf0e10cSrcweir // Get propertyset registry.
658cdf0e10cSrcweir getAdditionalPropertySetRegistry();
659cdf0e10cSrcweir
660cdf0e10cSrcweir if ( m_pImpl->m_xPropertySetRegistry.is() )
661cdf0e10cSrcweir m_pImpl->m_xPropertySetRegistry->removePropertySet( rKey );
662cdf0e10cSrcweir else
663cdf0e10cSrcweir return sal_False;
664cdf0e10cSrcweir }
665cdf0e10cSrcweir return sal_True;
666cdf0e10cSrcweir }
667cdf0e10cSrcweir
668cdf0e10cSrcweir } // namespace ucbhelper
669