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