Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/ucb/source/ucp/tdoc/tdoc_contentcaps.cxx
Line
Count
Source
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
    Props/Commands:
28
29
                        root  document folder  folder  stream  stream
30
                                                (new)          (new)
31
    ----------------------------------------------------------------
32
    ContentType         r       r       r       r       r       r
33
    IsDocument          r       r       r       r       r       r
34
    IsFolder            r       r       r       r       r       r
35
    Title               r       r       w       w       w       w
36
    CreatableContentsInfo r     r       r       r       r       r
37
    DateModified        -       -       -       -       r       r
38
    Storage             -       -       r       r       -       -
39
    DocumentModel       -       r       -       -       -       -
40
41
    getCommandInfo      x       x       x       x       x       x
42
    getPropertySetInfo  x       x       x       x       x       x
43
    getPropertyValues   x       x       x       x       x       x
44
    setPropertyValues   x       x       x       x       x       x
45
    insert              -       -       x       x       x(*)    x(*)
46
    delete              -       -       x       -       x       -
47
    open                x       x       x       -       x       -
48
    transfer            -       x       x       -       -       -
49
    createNewContent    -       x       x       -       -       -
50
51
52
 *************************************************************************/
53
54
#include <com/sun/star/beans/Property.hpp>
55
#include <com/sun/star/beans/PropertyAttribute.hpp>
56
#include <com/sun/star/beans/PropertyValue.hpp>
57
#include <com/sun/star/embed/XStorage.hpp>
58
#include <com/sun/star/frame/XModel.hpp>
59
#include <com/sun/star/ucb/CommandInfo.hpp>
60
#include <com/sun/star/ucb/OpenCommandArgument2.hpp>
61
#include <com/sun/star/ucb/TransferInfo.hpp>
62
#include <com/sun/star/util/DateTime.hpp>
63
#include <osl/diagnose.h>
64
#include <sal/macros.h>
65
#include "tdoc_content.hxx"
66
67
namespace com::sun::star::embed {
68
    class XStorage;
69
}
70
71
using namespace com::sun::star;
72
using namespace tdoc_ucp;
73
74
75
// Content implementation.
76
77
78
#define MAKEPROPSEQUENCE( a ) \
79
0
    uno::Sequence< beans::Property >( a, SAL_N_ELEMENTS(a) )
80
81
#define MAKECMDSEQUENCE( a ) \
82
0
    uno::Sequence< ucb::CommandInfo >( a, SAL_N_ELEMENTS(a) )
83
84
85
// IMPORTANT: If any property data ( name / type / ... ) are changed, then
86
//            Content::getPropertyValues(...) must be adapted too!
87
88
89
// virtual
90
uno::Sequence< beans::Property > Content::getProperties(
91
            const uno::Reference< ucb::XCommandEnvironment > & /*xEnv*/ )
92
0
{
93
0
    osl::Guard< osl::Mutex > aGuard( m_aMutex );
94
95
0
    if ( m_aProps.getType() == STREAM )
96
0
    {
97
98
99
        // Stream: Supported properties
100
101
102
0
        static const beans::Property aStreamPropertyInfoTable[] =
103
0
        {
104
105
            // Mandatory properties
106
107
0
            beans::Property(
108
0
                u"ContentType"_ustr,
109
0
                -1,
110
0
                cppu::UnoType<OUString>::get(),
111
0
                beans::PropertyAttribute::BOUND
112
0
                    | beans::PropertyAttribute::READONLY
113
0
            ),
114
0
            beans::Property(
115
0
                u"IsDocument"_ustr,
116
0
                -1,
117
0
                cppu::UnoType<bool>::get(),
118
0
                beans::PropertyAttribute::BOUND
119
0
                    | beans::PropertyAttribute::READONLY
120
0
            ),
121
0
            beans::Property(
122
0
                u"IsFolder"_ustr,
123
0
                -1,
124
0
                cppu::UnoType<bool>::get(),
125
0
                beans::PropertyAttribute::BOUND
126
0
                    | beans::PropertyAttribute::READONLY
127
0
            ),
128
0
            beans::Property(
129
0
                u"Title"_ustr,
130
0
                -1,
131
0
                cppu::UnoType<OUString>::get(),
132
0
                beans::PropertyAttribute::BOUND
133
0
            ),
134
135
            // Optional standard properties
136
137
0
            beans::Property(
138
0
                u"CreatableContentsInfo"_ustr,
139
0
                -1,
140
0
                cppu::UnoType<uno::Sequence< ucb::ContentInfo >>::get(),
141
0
                beans::PropertyAttribute::BOUND
142
0
                    | beans::PropertyAttribute::READONLY
143
0
            ),
144
0
            beans::Property(
145
0
                u"DateModified"_ustr,
146
0
                -1,
147
0
                cppu::UnoType<css::util::DateTime>::get(),
148
0
                beans::PropertyAttribute::BOUND
149
0
                    | beans::PropertyAttribute::READONLY
150
0
            )
151
152
            // New properties
153
154
0
        };
155
0
        return MAKEPROPSEQUENCE( aStreamPropertyInfoTable );
156
0
    }
157
0
    else if ( m_aProps.getType() == FOLDER )
158
0
    {
159
160
161
        // Folder: Supported properties
162
163
164
0
        static const beans::Property aFolderPropertyInfoTable[] =
165
0
        {
166
167
            // Mandatory properties
168
169
0
            beans::Property(
170
0
                u"ContentType"_ustr,
171
0
                -1,
172
0
                cppu::UnoType<OUString>::get(),
173
0
                beans::PropertyAttribute::BOUND
174
0
                    | beans::PropertyAttribute::READONLY
175
0
            ),
176
0
            beans::Property(
177
0
                u"IsDocument"_ustr,
178
0
                -1,
179
0
                cppu::UnoType<bool>::get(),
180
0
                beans::PropertyAttribute::BOUND
181
0
                    | beans::PropertyAttribute::READONLY
182
0
            ),
183
0
            beans::Property(
184
0
                u"IsFolder"_ustr,
185
0
                -1,
186
0
                cppu::UnoType<bool>::get(),
187
0
                beans::PropertyAttribute::BOUND
188
0
                    | beans::PropertyAttribute::READONLY
189
0
            ),
190
0
            beans::Property(
191
0
                u"Title"_ustr,
192
0
                -1,
193
0
                cppu::UnoType<OUString>::get(),
194
0
                beans::PropertyAttribute::BOUND
195
0
            ),
196
197
            // Optional standard properties
198
199
0
            beans::Property(
200
0
                u"CreatableContentsInfo"_ustr,
201
0
                -1,
202
0
                cppu::UnoType<uno::Sequence< ucb::ContentInfo >>::get(),
203
0
                beans::PropertyAttribute::BOUND
204
0
                    | beans::PropertyAttribute::READONLY
205
0
            ),
206
207
            // New properties
208
209
0
            beans::Property(
210
0
                u"Storage"_ustr,
211
0
                -1,
212
0
                cppu::UnoType<embed::XStorage>::get(),
213
0
                beans::PropertyAttribute::BOUND
214
0
                    | beans::PropertyAttribute::READONLY
215
0
            )
216
0
        };
217
0
        return MAKEPROPSEQUENCE( aFolderPropertyInfoTable );
218
0
    }
219
0
    else if ( m_aProps.getType() == DOCUMENT )
220
0
    {
221
222
223
        // Document: Supported properties
224
225
226
0
        static const beans::Property aDocPropertyInfoTable[] =
227
0
        {
228
229
            // Mandatory properties
230
231
0
            beans::Property(
232
0
                u"ContentType"_ustr,
233
0
                -1,
234
0
                cppu::UnoType<OUString>::get(),
235
0
                beans::PropertyAttribute::BOUND
236
0
                    | beans::PropertyAttribute::READONLY
237
0
            ),
238
0
            beans::Property(
239
0
                u"IsDocument"_ustr,
240
0
                -1,
241
0
                cppu::UnoType<bool>::get(),
242
0
                beans::PropertyAttribute::BOUND
243
0
                    | beans::PropertyAttribute::READONLY
244
0
            ),
245
0
            beans::Property(
246
0
                u"IsFolder"_ustr,
247
0
                -1,
248
0
                cppu::UnoType<bool>::get(),
249
0
                beans::PropertyAttribute::BOUND
250
0
                    | beans::PropertyAttribute::READONLY
251
0
            ),
252
0
            beans::Property(
253
0
                u"Title"_ustr,
254
0
                -1,
255
0
                cppu::UnoType<OUString>::get(),
256
0
                beans::PropertyAttribute::BOUND
257
0
                    | beans::PropertyAttribute::READONLY
258
0
            ),
259
260
            // Optional standard properties
261
262
0
            beans::Property(
263
0
                u"CreatableContentsInfo"_ustr,
264
0
                -1,
265
0
                cppu::UnoType<uno::Sequence< ucb::ContentInfo >>::get(),
266
0
                beans::PropertyAttribute::BOUND
267
0
                    | beans::PropertyAttribute::READONLY
268
0
            ),
269
270
            // New properties
271
272
0
            beans::Property(
273
0
                u"DocumentModel"_ustr,
274
0
                -1,
275
0
                cppu::UnoType<frame::XModel>::get(),
276
0
                beans::PropertyAttribute::BOUND
277
0
                    | beans::PropertyAttribute::READONLY
278
0
            )
279
0
        };
280
0
        return MAKEPROPSEQUENCE( aDocPropertyInfoTable );
281
0
    }
282
0
    else
283
0
    {
284
285
286
        // Root: Supported properties
287
288
289
0
        OSL_ENSURE( m_aProps.getType() == ROOT, "Wrong content type!" );
290
291
0
        static const beans::Property aRootPropertyInfoTable[] =
292
0
        {
293
294
            // Mandatory properties
295
296
0
            beans::Property(
297
0
                u"ContentType"_ustr,
298
0
                -1,
299
0
                cppu::UnoType<OUString>::get(),
300
0
                beans::PropertyAttribute::BOUND
301
0
                    | beans::PropertyAttribute::READONLY
302
0
            ),
303
0
            beans::Property(
304
0
                u"IsDocument"_ustr,
305
0
                -1,
306
0
                cppu::UnoType<bool>::get(),
307
0
                beans::PropertyAttribute::BOUND
308
0
                    | beans::PropertyAttribute::READONLY
309
0
            ),
310
0
            beans::Property(
311
0
                u"IsFolder"_ustr,
312
0
                -1,
313
0
                cppu::UnoType<bool>::get(),
314
0
                beans::PropertyAttribute::BOUND
315
0
                    | beans::PropertyAttribute::READONLY
316
0
            ),
317
0
            beans::Property(
318
0
                u"Title"_ustr,
319
0
                -1,
320
0
                cppu::UnoType<OUString>::get(),
321
0
                beans::PropertyAttribute::BOUND
322
0
                    | beans::PropertyAttribute::READONLY
323
0
            ),
324
325
            // Optional standard properties
326
327
0
            beans::Property(
328
0
                u"CreatableContentsInfo"_ustr,
329
0
                -1,
330
0
                cppu::UnoType<uno::Sequence< ucb::ContentInfo >>::get(),
331
0
                beans::PropertyAttribute::BOUND
332
0
                    | beans::PropertyAttribute::READONLY
333
0
            )
334
335
            // New properties
336
337
0
        };
338
0
        return MAKEPROPSEQUENCE( aRootPropertyInfoTable );
339
0
    }
340
0
}
341
342
343
// virtual
344
uno::Sequence< ucb::CommandInfo > Content::getCommands(
345
            const uno::Reference< ucb::XCommandEnvironment > & /*xEnv*/ )
346
0
{
347
0
    osl::Guard< osl::Mutex > aGuard( m_aMutex );
348
349
0
    if ( m_aProps.getType() == STREAM )
350
0
    {
351
0
        Uri aUri( m_xIdentifier->getContentIdentifier() );
352
0
        Uri aParentUri( aUri.getParentUri() );
353
354
0
        if ( aParentUri.isDocument() )
355
0
        {
356
357
358
            // Stream, that is a child of a document: Supported commands
359
360
361
0
            static const ucb::CommandInfo aStreamCommandInfoTable1[] =
362
0
            {
363
364
                // Mandatory commands
365
366
0
                ucb::CommandInfo(
367
0
                    u"getCommandInfo"_ustr,
368
0
                    -1,
369
0
                    cppu::UnoType<void>::get()
370
0
                ),
371
0
                ucb::CommandInfo(
372
0
                    u"getPropertySetInfo"_ustr,
373
0
                    -1,
374
0
                    cppu::UnoType<void>::get()
375
0
                ),
376
0
                ucb::CommandInfo(
377
0
                    u"getPropertyValues"_ustr,
378
0
                    -1,
379
0
                    cppu::UnoType<uno::Sequence< beans::Property >>::get()
380
0
                ),
381
0
                ucb::CommandInfo(
382
0
                    u"setPropertyValues"_ustr,
383
0
                    -1,
384
0
                    cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get()
385
0
                ),
386
387
                // Optional standard commands
388
389
0
                ucb::CommandInfo(
390
0
                    u"delete"_ustr,
391
0
                    -1,
392
0
                    cppu::UnoType<bool>::get()
393
0
                ),
394
0
                ucb::CommandInfo(
395
0
                    u"open"_ustr,
396
0
                    -1,
397
0
                    cppu::UnoType<ucb::OpenCommandArgument2>::get()
398
0
                )
399
400
                // New commands
401
402
0
            };
403
0
            return MAKECMDSEQUENCE( aStreamCommandInfoTable1 );
404
0
        }
405
406
407
        // Stream: Supported commands
408
409
410
0
        static const ucb::CommandInfo aStreamCommandInfoTable[] =
411
0
        {
412
413
            // Mandatory commands
414
415
0
            ucb::CommandInfo(
416
0
                u"getCommandInfo"_ustr,
417
0
                -1,
418
0
                cppu::UnoType<void>::get()
419
0
            ),
420
0
            ucb::CommandInfo(
421
0
                u"getPropertySetInfo"_ustr,
422
0
                -1,
423
0
                cppu::UnoType<void>::get()
424
0
            ),
425
0
            ucb::CommandInfo(
426
0
                u"getPropertyValues"_ustr,
427
0
                -1,
428
0
                cppu::UnoType< uno::Sequence< beans::Property >>::get()
429
0
            ),
430
0
            ucb::CommandInfo(
431
0
                u"setPropertyValues"_ustr,
432
0
                -1,
433
0
                cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get()
434
0
            ),
435
436
            // Optional standard commands
437
438
0
            ucb::CommandInfo(
439
0
                u"delete"_ustr,
440
0
                -1,
441
0
                cppu::UnoType<bool>::get()
442
0
            ),
443
0
            ucb::CommandInfo(
444
0
                u"insert"_ustr,
445
0
                -1,
446
0
                cppu::UnoType<void>::get()
447
0
            ),
448
0
            ucb::CommandInfo(
449
0
                u"open"_ustr,
450
0
                -1,
451
0
                cppu::UnoType<ucb::OpenCommandArgument2>::get()
452
0
            )
453
454
            // New commands
455
456
0
        };
457
0
        return MAKECMDSEQUENCE( aStreamCommandInfoTable );
458
0
    }
459
0
    else if ( m_aProps.getType() == FOLDER )
460
0
    {
461
462
463
        // Folder: Supported commands
464
465
466
0
        static const ucb::CommandInfo aFolderCommandInfoTable[] =
467
0
        {
468
469
            // Mandatory commands
470
471
0
            ucb::CommandInfo(
472
0
                u"getCommandInfo"_ustr,
473
0
                -1,
474
0
                cppu::UnoType<void>::get()
475
0
            ),
476
0
            ucb::CommandInfo(
477
0
                u"getPropertySetInfo"_ustr,
478
0
                -1,
479
0
                cppu::UnoType<void>::get()
480
0
            ),
481
0
            ucb::CommandInfo(
482
0
                u"getPropertyValues"_ustr,
483
0
                -1,
484
0
                cppu::UnoType<uno::Sequence< beans::Property >>::get()
485
0
            ),
486
0
            ucb::CommandInfo(
487
0
                u"setPropertyValues"_ustr,
488
0
                -1,
489
0
                cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get()
490
0
            ),
491
492
            // Optional standard commands
493
494
0
            ucb::CommandInfo(
495
0
                u"delete"_ustr,
496
0
                -1,
497
0
                cppu::UnoType<bool>::get()
498
0
            ),
499
0
            ucb::CommandInfo(
500
0
                u"insert"_ustr,
501
0
                -1,
502
0
                cppu::UnoType<void>::get()
503
0
            ),
504
0
            ucb::CommandInfo(
505
0
                u"open"_ustr,
506
0
                -1,
507
0
                cppu::UnoType<ucb::OpenCommandArgument2>::get()
508
0
            ),
509
0
            ucb::CommandInfo(
510
0
                u"transfer"_ustr,
511
0
                -1,
512
0
                cppu::UnoType<ucb::TransferInfo>::get()
513
0
            ),
514
0
            ucb::CommandInfo(
515
0
                u"createNewContent"_ustr,
516
0
                -1,
517
0
                cppu::UnoType<ucb::ContentInfo>::get()
518
0
            )
519
520
            // New commands
521
522
0
        };
523
0
        return MAKECMDSEQUENCE( aFolderCommandInfoTable );
524
0
    }
525
0
    else if ( m_aProps.getType() == DOCUMENT )
526
0
    {
527
528
529
        // Document: Supported commands
530
531
532
0
        static const ucb::CommandInfo aDocCommandInfoTable[] =
533
0
        {
534
535
            // Mandatory commands
536
537
0
            ucb::CommandInfo(
538
0
                u"getCommandInfo"_ustr,
539
0
                -1,
540
0
                cppu::UnoType<void>::get()
541
0
            ),
542
0
            ucb::CommandInfo(
543
0
                u"getPropertySetInfo"_ustr,
544
0
                -1,
545
0
                cppu::UnoType<void>::get()
546
0
            ),
547
0
            ucb::CommandInfo(
548
0
                u"getPropertyValues"_ustr,
549
0
                -1,
550
0
                cppu::UnoType<uno::Sequence< beans::Property >>::get()
551
0
            ),
552
0
            ucb::CommandInfo(
553
0
                u"setPropertyValues"_ustr,
554
0
                -1,
555
0
                cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get()
556
0
            ),
557
558
            // Optional standard commands
559
560
0
            ucb::CommandInfo(
561
0
                u"open"_ustr,
562
0
                -1,
563
0
                cppu::UnoType<ucb::OpenCommandArgument2>::get()
564
0
            ),
565
0
            ucb::CommandInfo(
566
0
                u"transfer"_ustr,
567
0
                -1,
568
0
                cppu::UnoType<ucb::TransferInfo>::get()
569
0
            ),
570
0
            ucb::CommandInfo(
571
0
                u"createNewContent"_ustr,
572
0
                -1,
573
0
                cppu::UnoType<ucb::ContentInfo>::get()
574
0
            )
575
576
            // New commands
577
578
0
        };
579
0
        return MAKECMDSEQUENCE( aDocCommandInfoTable );
580
0
    }
581
0
    else
582
0
    {
583
584
585
        // Root: Supported commands
586
587
588
0
        OSL_ENSURE( m_aProps.getType() == ROOT, "Wrong content type!" );
589
590
0
        static const ucb::CommandInfo aRootCommandInfoTable[] =
591
0
        {
592
593
            // Mandatory commands
594
595
0
            ucb::CommandInfo(
596
0
                u"getCommandInfo"_ustr,
597
0
                -1,
598
0
                cppu::UnoType<void>::get()
599
0
            ),
600
0
            ucb::CommandInfo(
601
0
                u"getPropertySetInfo"_ustr,
602
0
                -1,
603
0
                cppu::UnoType<void>::get()
604
0
            ),
605
0
            ucb::CommandInfo(
606
0
                u"getPropertyValues"_ustr,
607
0
                -1,
608
0
                cppu::UnoType<uno::Sequence< beans::Property >>::get()
609
0
            ),
610
0
            ucb::CommandInfo(
611
0
                u"setPropertyValues"_ustr,
612
0
                -1,
613
0
                cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get()
614
0
            ),
615
616
            // Optional standard commands
617
618
0
            ucb::CommandInfo(
619
0
                u"open"_ustr,
620
0
                -1,
621
0
                cppu::UnoType<ucb::OpenCommandArgument2>::get()
622
0
            )
623
624
            // New commands
625
626
0
        };
627
0
        return MAKECMDSEQUENCE( aRootCommandInfoTable );
628
0
    }
629
0
}
630
631
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */