1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <com/sun/star/lang/NoSupportException.hpp>
#include <com/sun/star/ucb/ContentAction.hpp>
#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
#include <com/sun/star/ucb/XPersistentPropertySet.hpp>
#include <com/sun/star/beans/IllegalTypeException.hpp>
#include <com/sun/star/beans/NotRemoveableException.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/beans/PropertyExistException.hpp>
#include <com/sun/star/beans/PropertySetInfoChange.hpp>
#include <comphelper/interfacecontainer3.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <ucbhelper/contenthelper.hxx>
#include <ucbhelper/contentidentifier.hxx>
#include "contentinfo.hxx"
#include <ucbhelper/providerhelper.hxx>
#include <ucbhelper/macros.hxx>
#include <osl/diagnose.h>
#include <osl/mutex.hxx>
#include <rtl/ref.hxx>
#include <unordered_map>
using namespace com::sun::star;
namespace ucbhelper_impl
{
namespace {
class PropertyEventSequence
{
uno::Sequence< beans::PropertyChangeEvent > m_aSeq;
sal_uInt32 m_nPos;
public:
explicit PropertyEventSequence( sal_uInt32 nSize )
: m_aSeq( nSize ), m_nPos( 0 ) {};
void append( const beans::PropertyChangeEvent& rEvt )
{ m_aSeq.getArray()[ m_nPos ] = rEvt; ++m_nPos; }
const uno::Sequence< beans::PropertyChangeEvent >& getEvents()
{ m_aSeq.realloc( m_nPos ); return m_aSeq; }
};
}
typedef void* XPropertiesChangeListenerPtr; // -> Compiler problems!
namespace {
struct equalPtr
{
bool operator()( const XPropertiesChangeListenerPtr& rp1,
const XPropertiesChangeListenerPtr& rp2 ) const
{
return ( rp1 == rp2 );
}
};
struct hashPtr
{
size_t operator()( const XPropertiesChangeListenerPtr& rp ) const
{
return reinterpret_cast<size_t>(rp);
}
};
}
typedef std::unordered_map
<
XPropertiesChangeListenerPtr,
PropertyEventSequence,
hashPtr,
equalPtr
>
PropertiesEventListenerMap;
typedef cppu::OMultiTypeInterfaceContainerHelperVar<OUString>
PropertyChangeListeners;
struct ContentImplHelper_Impl
{
rtl::Reference< ::ucbhelper::PropertySetInfo > m_xPropSetInfo;
rtl::Reference< ::ucbhelper::CommandProcessorInfo > m_xCommandsInfo;
std::unique_ptr<cppu::OInterfaceContainerHelper> m_pDisposeEventListeners;
std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::ucb::XContentEventListener>>
m_pContentEventListeners;
std::unique_ptr<comphelper::OInterfaceContainerHelper3<beans::XPropertySetInfoChangeListener>>
m_pPropSetChangeListeners;
std::unique_ptr<cppu::OInterfaceContainerHelper> m_pCommandChangeListeners;
std::unique_ptr<PropertyChangeListeners> m_pPropertyChangeListeners;
};
} // namespace ucbhelper_impl
using namespace ucbhelper_impl;
namespace ucbhelper {
ContentImplHelper::ContentImplHelper(
const uno::Reference< uno::XComponentContext >& rxContext,
const rtl::Reference< ContentProviderImplHelper >& rxProvider,
const uno::Reference<
css::ucb::XContentIdentifier >& Identifier )
: m_pImpl( new ContentImplHelper_Impl ),
m_xContext( rxContext ),
m_xIdentifier( Identifier ),
m_xProvider( rxProvider ),
m_nCommandId( 0 )
{
}
// virtual
ContentImplHelper::~ContentImplHelper()
{
}
void SAL_CALL ContentImplHelper::release()
noexcept
{
// #144882# - Call to OWeakObject::release may destroy m_xProvider.
// Prevent this.
rtl::Reference< ContentProviderImplHelper > xKeepProviderAlive(
m_xProvider );
osl::MutexGuard aGuard( m_xProvider->m_aMutex );
OWeakObject::release();
}
uno::Any SAL_CALL ContentImplHelper::queryInterface( const uno::Type & rType )
{
css::uno::Any aRet = cppu::queryInterface( rType,
static_cast< lang::XTypeProvider * >(this),
static_cast< lang::XServiceInfo * >(this),
static_cast< lang::XComponent * >(this),
static_cast< css::ucb::XContent * >(this),
static_cast< css::ucb::XCommandProcessor * >(this),
static_cast< beans::XPropertiesChangeNotifier * >(this),
static_cast< css::ucb::XCommandInfoChangeNotifier * >(this),
static_cast< beans::XPropertyContainer * >(this),
static_cast< beans::XPropertySetInfoChangeNotifier * >(this),
static_cast< container::XChild * >(this));
return aRet.hasValue() ? aRet : cppu::OWeakObject::queryInterface( rType );
}
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 );
// virtual
sal_Bool SAL_CALL ContentImplHelper::supportsService(
const OUString& ServiceName )
{
return cppu::supportsService(this, ServiceName);
}
// virtual
void SAL_CALL ContentImplHelper::dispose()
{
osl::MutexGuard aGuard( m_aMutex );
if ( m_pImpl->m_pDisposeEventListeners &&
m_pImpl->m_pDisposeEventListeners->getLength() )
{
lang::EventObject aEvt;
aEvt.Source = static_cast< lang::XComponent * >( this );
m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt );
}
if ( m_pImpl->m_pContentEventListeners &&
m_pImpl->m_pContentEventListeners->getLength() )
{
lang::EventObject aEvt;
aEvt.Source = static_cast< css::ucb::XContent * >( this );
m_pImpl->m_pContentEventListeners->disposeAndClear( aEvt );
}
if ( m_pImpl->m_pPropSetChangeListeners &&
m_pImpl->m_pPropSetChangeListeners->getLength() )
{
lang::EventObject aEvt;
aEvt.Source
= static_cast< beans::XPropertySetInfoChangeNotifier * >( this );
m_pImpl->m_pPropSetChangeListeners->disposeAndClear( aEvt );
}
if ( m_pImpl->m_pCommandChangeListeners &&
m_pImpl->m_pCommandChangeListeners->getLength() )
{
lang::EventObject aEvt;
aEvt.Source = static_cast< css::ucb::XCommandInfoChangeNotifier * >( this );
m_pImpl->m_pCommandChangeListeners->disposeAndClear( aEvt );
}
if ( m_pImpl->m_pPropertyChangeListeners )
{
lang::EventObject aEvt;
aEvt.Source
= static_cast< beans::XPropertiesChangeNotifier * >( this );
m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt );
}
}
// virtual
void SAL_CALL ContentImplHelper::addEventListener(
const uno::Reference< lang::XEventListener >& Listener )
{
osl::MutexGuard aGuard( m_aMutex );
if ( !m_pImpl->m_pDisposeEventListeners )
m_pImpl->m_pDisposeEventListeners.reset(
new cppu::OInterfaceContainerHelper( m_aMutex ));
m_pImpl->m_pDisposeEventListeners->addInterface( Listener );
}
// virtual
void SAL_CALL ContentImplHelper::removeEventListener(
const uno::Reference< lang::XEventListener >& Listener )
{
osl::MutexGuard aGuard( m_aMutex );
if ( m_pImpl->m_pDisposeEventListeners )
m_pImpl->m_pDisposeEventListeners->removeInterface( Listener );
}
// virtual
uno::Reference< css::ucb::XContentIdentifier > SAL_CALL
ContentImplHelper::getIdentifier()
{
return m_xIdentifier;
}
// virtual
void SAL_CALL ContentImplHelper::addContentEventListener(
const uno::Reference< css::ucb::XContentEventListener >& Listener )
{
osl::MutexGuard aGuard( m_aMutex );
if ( !m_pImpl->m_pContentEventListeners )
m_pImpl->m_pContentEventListeners.reset(
new comphelper::OInterfaceContainerHelper3<css::ucb::XContentEventListener>( m_aMutex ));
m_pImpl->m_pContentEventListeners->addInterface( Listener );
}
// virtual
void SAL_CALL ContentImplHelper::removeContentEventListener(
const uno::Reference< css::ucb::XContentEventListener >& Listener )
{
osl::MutexGuard aGuard( m_aMutex );
if ( m_pImpl->m_pContentEventListeners )
m_pImpl->m_pContentEventListeners->removeInterface( Listener );
}
// virtual
sal_Int32 SAL_CALL ContentImplHelper::createCommandIdentifier()
{
osl::MutexGuard aGuard( m_aMutex );
// Just increase counter on every call to generate an identifier.
return ++m_nCommandId;
}
// virtual
void SAL_CALL ContentImplHelper::addPropertiesChangeListener(
const uno::Sequence< OUString >& PropertyNames,
const uno::Reference< beans::XPropertiesChangeListener >& Listener )
{
osl::MutexGuard aGuard( m_aMutex );
if ( !m_pImpl->m_pPropertyChangeListeners )
m_pImpl->m_pPropertyChangeListeners.reset(
new PropertyChangeListeners( m_aMutex ));
if ( !PropertyNames.hasElements() )
{
// Note: An empty sequence means a listener for "all" properties.
m_pImpl->m_pPropertyChangeListeners->addInterface(
OUString(), Listener );
}
else
{
for ( const OUString& rName : PropertyNames )
{
if ( !rName.isEmpty() )
m_pImpl->m_pPropertyChangeListeners->addInterface(
rName, Listener );
}
}
}
// virtual
void SAL_CALL ContentImplHelper::removePropertiesChangeListener(
const uno::Sequence< OUString >& PropertyNames,
const uno::Reference< beans::XPropertiesChangeListener >& Listener )
{
osl::MutexGuard aGuard( m_aMutex );
if ( !m_pImpl->m_pPropertyChangeListeners )
return;
if ( !PropertyNames.hasElements() )
{
// Note: An empty sequence means a listener for "all" properties.
m_pImpl->m_pPropertyChangeListeners->removeInterface(
OUString(), Listener );
}
else
{
for ( const OUString& rName : PropertyNames )
{
if ( !rName.isEmpty() )
m_pImpl->m_pPropertyChangeListeners->removeInterface(
rName, Listener );
}
}
}
// virtual
void SAL_CALL ContentImplHelper::addCommandInfoChangeListener(
const uno::Reference< css::ucb::XCommandInfoChangeListener >& Listener )
{
osl::MutexGuard aGuard( m_aMutex );
if ( !m_pImpl->m_pCommandChangeListeners )
m_pImpl->m_pCommandChangeListeners.reset(
new cppu::OInterfaceContainerHelper( m_aMutex ));
m_pImpl->m_pCommandChangeListeners->addInterface( Listener );
}
// virtual
void SAL_CALL ContentImplHelper::removeCommandInfoChangeListener(
const uno::Reference< css::ucb::XCommandInfoChangeListener >& Listener )
{
osl::MutexGuard aGuard( m_aMutex );
if ( m_pImpl->m_pCommandChangeListeners )
m_pImpl->m_pCommandChangeListeners->removeInterface( Listener );
}
// virtual
void SAL_CALL ContentImplHelper::addProperty(
const OUString& Name,
sal_Int16 Attributes,
const uno::Any& DefaultValue )
{
osl::MutexGuard aGuard( m_aMutex );
// Make sure a property with the requested name does not already
// exist in dynamic and static(!) properties.
// @@@ Need real command environment here, but where to get it from?
// XPropertyContainer interface should be replaced by
// XCommandProcessor commands!
uno::Reference< css::ucb::XCommandEnvironment > xEnv;
if ( getPropertySetInfo( xEnv )->hasPropertyByName( Name ) )
{
// Property does already exist.
throw beans::PropertyExistException();
}
// Add a new dynamic property.
// Open/create persistent property set.
uno::Reference< css::ucb::XPersistentPropertySet > xSet(
getAdditionalPropertySet( true ) );
OSL_ENSURE( xSet.is(),
"ContentImplHelper::addProperty - No property set!" );
if ( !xSet.is() )
return;
uno::Reference< beans::XPropertyContainer > xContainer(
xSet, uno::UNO_QUERY );
OSL_ENSURE(
xContainer.is(),
"ContentImplHelper::addProperty - No property container!" );
if ( !xContainer.is() )
return;
// Property is always removable.
Attributes |= beans::PropertyAttribute::REMOVABLE;
try
{
xContainer->addProperty( Name, Attributes, DefaultValue );
}
catch ( beans::PropertyExistException const & )
{
OSL_FAIL( "ContentImplHelper::addProperty - Exists!" );
throw;
}
catch ( beans::IllegalTypeException const & )
{
OSL_FAIL( "ContentImplHelper::addProperty - Wrong Type!" );
throw;
}
catch ( lang::IllegalArgumentException const & )
{
OSL_FAIL( "ContentImplHelper::addProperty - Illegal Arg!" );
throw;
}
// Success!
if ( m_pImpl->m_xPropSetInfo.is() )
{
// Info cached in propertyset info is invalid now!
m_pImpl->m_xPropSetInfo->reset();
}
// Notify propertyset info change listeners.
if ( m_pImpl->m_pPropSetChangeListeners &&
m_pImpl->m_pPropSetChangeListeners->getLength() )
{
beans::PropertySetInfoChangeEvent evt(
static_cast< cppu::OWeakObject * >( this ),
Name,
-1, // No handle available
beans::PropertySetInfoChange::PROPERTY_INSERTED );
notifyPropertySetInfoChange( evt );
}
}
// virtual
void SAL_CALL ContentImplHelper::removeProperty( const OUString& Name )
{
osl::MutexGuard aGuard( m_aMutex );
try
{
// @@@ Need real command environment here, but where to get it from?
// XPropertyContainer interface should be replaced by
// XCommandProcessor commands!
uno::Reference< css::ucb::XCommandEnvironment > xEnv;
beans::Property aProp
= getPropertySetInfo( xEnv )->getPropertyByName( Name );
if ( !( aProp.Attributes & beans::PropertyAttribute::REMOVABLE ) )
{
// Not removable!
throw beans::NotRemoveableException();
}
}
catch ( beans::UnknownPropertyException const & )
{
OSL_FAIL( "ContentImplHelper::removeProperty - Unknown!" );
throw;
}
// Try to remove property from dynamic property set.
// Open persistent property set, if exists.
uno::Reference< css::ucb::XPersistentPropertySet > xSet(
getAdditionalPropertySet( false ) );
if ( !xSet.is() )
return;
uno::Reference< beans::XPropertyContainer > xContainer(
xSet, uno::UNO_QUERY );
OSL_ENSURE(
xContainer.is(),
"ContentImplHelper::removeProperty - No property container!" );
if ( !xContainer.is() )
return;
try
{
xContainer->removeProperty( Name );
}
catch ( beans::UnknownPropertyException const & )
{
OSL_FAIL( "ContentImplHelper::removeProperty - Unknown!" );
throw;
}
catch ( beans::NotRemoveableException const & )
{
OSL_FAIL(
"ContentImplHelper::removeProperty - Unremovable!" );
throw;
}
xContainer = nullptr;
// Success!
if ( !xSet->getPropertySetInfo()->getProperties().hasElements() )
{
// Remove empty propertyset from registry.
uno::Reference< css::ucb::XPropertySetRegistry >
xReg = xSet->getRegistry();
if ( xReg.is() )
{
OUString aKey( xSet->getKey() );
xSet = nullptr;
xReg->removePropertySet( aKey );
}
}
if ( m_pImpl->m_xPropSetInfo.is() )
{
// Info cached in propertyset info is invalid now!
m_pImpl->m_xPropSetInfo->reset();
}
// Notify propertyset info change listeners.
if ( m_pImpl->m_pPropSetChangeListeners &&
m_pImpl->m_pPropSetChangeListeners->getLength() )
{
beans::PropertySetInfoChangeEvent evt(
static_cast< cppu::OWeakObject * >( this ),
Name,
-1, // No handle available
beans::PropertySetInfoChange::PROPERTY_REMOVED );
notifyPropertySetInfoChange( evt );
}
}
// virtual
void SAL_CALL ContentImplHelper::addPropertySetInfoChangeListener(
const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener )
{
osl::MutexGuard aGuard( m_aMutex );
if ( !m_pImpl->m_pPropSetChangeListeners )
m_pImpl->m_pPropSetChangeListeners.reset(
new comphelper::OInterfaceContainerHelper3<beans::XPropertySetInfoChangeListener>( m_aMutex ));
m_pImpl->m_pPropSetChangeListeners->addInterface( Listener );
}
// virtual
void SAL_CALL ContentImplHelper::removePropertySetInfoChangeListener(
const uno::Reference< beans::XPropertySetInfoChangeListener >& Listener )
{
osl::MutexGuard aGuard( m_aMutex );
if ( m_pImpl->m_pPropSetChangeListeners )
m_pImpl->m_pPropSetChangeListeners->removeInterface( Listener );
}
// virtual
uno::Reference< uno::XInterface > SAL_CALL ContentImplHelper::getParent()
{
uno::Reference< uno::XInterface > xParent;
OUString aURL = getParentURL();
if ( !aURL.isEmpty() )
{
uno::Reference< css::ucb::XContentIdentifier > xId(
new ContentIdentifier( aURL ) );
try
{
xParent.set( m_xProvider->queryContent( xId ) );
}
catch ( css::ucb::IllegalIdentifierException const & )
{
}
}
return xParent;
}
// virtual
void SAL_CALL ContentImplHelper::setParent(
const uno::Reference< uno::XInterface >& )
{
throw lang::NoSupportException();
}
uno::Reference< css::ucb::XPersistentPropertySet >
ContentImplHelper::getAdditionalPropertySet( bool bCreate )
{
// Get propertyset from provider.
return m_xProvider->getAdditionalPropertySet(
m_xIdentifier->getContentIdentifier(), bCreate );
}
bool ContentImplHelper::renameAdditionalPropertySet(
const OUString& rOldKey,
const OUString& rNewKey )
{
return m_xProvider->renameAdditionalPropertySet(
rOldKey, rNewKey, true/*bRecursive*/ );
}
bool ContentImplHelper::copyAdditionalPropertySet(
const OUString& rSourceKey,
const OUString& rTargetKey )
{
return m_xProvider->copyAdditionalPropertySet(
rSourceKey, rTargetKey, true/*bRecursive*/ );
}
bool ContentImplHelper::removeAdditionalPropertySet()
{
return m_xProvider->removeAdditionalPropertySet(
m_xIdentifier->getContentIdentifier(), true/*bRecursive*/ );
}
void ContentImplHelper::notifyPropertiesChange(
const uno::Sequence< beans::PropertyChangeEvent >& evt ) const
{
if ( !m_pImpl->m_pPropertyChangeListeners )
return;
sal_Int32 nCount = evt.getLength();
if ( !nCount )
return;
// First, notify listeners interested in changes of every property.
cppu::OInterfaceContainerHelper* pAllPropsContainer
= m_pImpl->m_pPropertyChangeListeners->getContainer(
OUString() );
if ( pAllPropsContainer )
{
cppu::OInterfaceIteratorHelper aIter( *pAllPropsContainer );
while ( aIter.hasMoreElements() )
{
// Propagate event.
static_cast< beans::XPropertiesChangeListener* >(
aIter.next())->propertiesChange( evt );
}
}
PropertiesEventListenerMap aListeners;
for ( const beans::PropertyChangeEvent& rEvent : evt )
{
const OUString& rName = rEvent.PropertyName;
cppu::OInterfaceContainerHelper* pPropsContainer
= m_pImpl->m_pPropertyChangeListeners->getContainer( rName );
if ( pPropsContainer )
{
cppu::OInterfaceIteratorHelper aIter( *pPropsContainer );
while ( aIter.hasMoreElements() )
{
PropertyEventSequence* p = nullptr;
beans::XPropertiesChangeListener* pListener =
static_cast< beans::XPropertiesChangeListener * >(
aIter.next() );
PropertiesEventListenerMap::iterator it =
aListeners.find( pListener );
if ( it == aListeners.end() )
{
// Not in map - create and insert new entry.
p = &aListeners.emplace( pListener, PropertyEventSequence(nCount)).first->second;
}
else
p = &it->second;
if ( p )
p->append( rEvent );
}
}
}
// Notify listeners.
PropertiesEventListenerMap::iterator it = aListeners.begin();
while ( !aListeners.empty() )
{
beans::XPropertiesChangeListener* pListener =
static_cast< beans::XPropertiesChangeListener * >( (*it).first );
PropertyEventSequence pSeq = std::move(it->second);
// Remove current element.
aListeners.erase( it );
// Propagate event.
pListener->propertiesChange( pSeq.getEvents() );
it = aListeners.begin();
}
}
void ContentImplHelper::notifyPropertySetInfoChange(
const beans::PropertySetInfoChangeEvent& evt ) const
{
if ( !m_pImpl->m_pPropSetChangeListeners )
return;
// Notify event listeners.
m_pImpl->m_pPropSetChangeListeners->notifyEach( &beans::XPropertySetInfoChangeListener::propertySetInfoChange, evt );
}
void ContentImplHelper::notifyContentEvent(
const css::ucb::ContentEvent& evt ) const
{
if ( !m_pImpl->m_pContentEventListeners )
return;
// Notify event listeners.
m_pImpl->m_pContentEventListeners->notifyEach( &css::ucb::XContentEventListener::contentEvent, evt);
}
void ContentImplHelper::inserted()
{
// Content is not yet registered at provider.
m_xProvider->registerNewContent( this );
// If the parent content is currently not instantiated, there can be
// no listeners interested in changes ;-)
rtl::Reference< ContentImplHelper > xParent
= m_xProvider->queryExistingContent( getParentURL() );
if ( xParent.is() )
{
css::ucb::ContentEvent aEvt(
static_cast< cppu::OWeakObject * >( xParent.get() ), // Source
css::ucb::ContentAction::INSERTED, // Action
this, // Content
xParent->getIdentifier() ); // Id
xParent->notifyContentEvent( aEvt );
}
}
void ContentImplHelper::deleted()
{
uno::Reference< css::ucb::XContent > xThis = this;
rtl::Reference< ContentImplHelper > xParent
= m_xProvider->queryExistingContent( getParentURL() );
if ( xParent.is() )
{
// Let parent notify "REMOVED" event.
css::ucb::ContentEvent aEvt(
static_cast< cppu::OWeakObject * >( xParent.get() ),
css::ucb::ContentAction::REMOVED,
this,
xParent->getIdentifier() );
xParent->notifyContentEvent( aEvt );
}
// Notify "DELETED" event.
css::ucb::ContentEvent aEvt1(
static_cast< cppu::OWeakObject * >( this ),
css::ucb::ContentAction::DELETED,
this,
getIdentifier() );
notifyContentEvent( aEvt1 );
m_xProvider->removeContent( this );
}
bool ContentImplHelper::exchange(
const uno::Reference< css::ucb::XContentIdentifier >& rNewId )
{
uno::Reference< css::ucb::XContent > xThis = this;
osl::ClearableMutexGuard aGuard( m_aMutex );
rtl::Reference< ContentImplHelper > xContent
= m_xProvider->queryExistingContent( rNewId );
if ( xContent.is() )
{
// @@@
// Big trouble. Another object with the new identity exists.
// How shall I mutate to / merge with the other object?
return false;
}
uno::Reference< css::ucb::XContentIdentifier > xOldId
= getIdentifier();
// Re-insert at provider.
m_xProvider->removeContent( this );
m_xIdentifier = rNewId;
m_xProvider->registerNewContent( this );
aGuard.clear();
// Notify "EXCHANGED" event.
css::ucb::ContentEvent aEvt(
static_cast< cppu::OWeakObject * >( this ),
css::ucb::ContentAction::EXCHANGED,
this,
xOldId );
notifyContentEvent( aEvt );
return true;
}
uno::Reference< css::ucb::XCommandInfo >
ContentImplHelper::getCommandInfo(
const uno::Reference< css::ucb::XCommandEnvironment > & xEnv,
bool bCache )
{
osl::MutexGuard aGuard( m_aMutex );
if ( !m_pImpl->m_xCommandsInfo.is() )
m_pImpl->m_xCommandsInfo
= new CommandProcessorInfo( xEnv, this );
else if ( !bCache )
m_pImpl->m_xCommandsInfo->reset();
return m_pImpl->m_xCommandsInfo;
}
uno::Reference< beans::XPropertySetInfo >
ContentImplHelper::getPropertySetInfo(
const uno::Reference< css::ucb::XCommandEnvironment > & xEnv,
bool bCache )
{
osl::MutexGuard aGuard( m_aMutex );
if ( !m_pImpl->m_xPropSetInfo.is() )
m_pImpl->m_xPropSetInfo
= new PropertySetInfo( xEnv, this );
else if ( !bCache )
m_pImpl->m_xPropSetInfo->reset();
return m_pImpl->m_xPropSetInfo;
}
} // namespace ucbhelper
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|