Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_contentcaps.cxx
bloba8d6d847ae461c566a54e1e5a0044e250fd997c4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 /**************************************************************************
22 TODO
23 **************************************************************************
25 **************************************************************************
27 Props/Commands:
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 Storage - - r r - -
38 DocumentModel - r - - - -
40 getCommandInfo x x x x x x
41 getPropertySetInfo x x x x x x
42 getPropertyValues x x x x x x
43 setPropertyValues x x x x x x
44 insert - - x x x(*) x(*)
45 delete - - x - x -
46 open x x x - x -
47 transfer - x x - - -
48 createNewContent - x x - - -
50 #ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT
51 (*) not supported by streams that are direct children of document
52 #endif
54 *************************************************************************/
56 #include <com/sun/star/beans/Property.hpp>
57 #include <com/sun/star/beans/PropertyAttribute.hpp>
58 #include <com/sun/star/beans/PropertyValue.hpp>
59 #include <com/sun/star/embed/XStorage.hpp>
60 #include <com/sun/star/frame/XModel.hpp>
61 #include <com/sun/star/ucb/CommandInfo.hpp>
62 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
63 #include <com/sun/star/ucb/TransferInfo.hpp>
64 #include <sal/macros.h>
65 #include <tdoc_content.hxx>
67 namespace com { namespace sun { namespace star { namespace embed {
68 class XStorage;
69 } } } }
71 using namespace com::sun::star;
72 using namespace tdoc_ucp;
74 //=========================================================================
76 // Content implementation.
78 //=========================================================================
80 #define MAKEPROPSEQUENCE( a ) \
81 uno::Sequence< beans::Property >( a, (sizeof (a) / sizeof (a[0])) )
83 #define MAKECMDSEQUENCE( a ) \
84 uno::Sequence< ucb::CommandInfo >( a, (sizeof (a) / sizeof (a[0])) )
86 //=========================================================================
88 // IMPORTENT: If any property data ( name / type / ... ) are changed, then
89 // Content::getPropertyValues(...) must be adapted too!
91 //=========================================================================
93 // virtual
94 uno::Sequence< beans::Property > Content::getProperties(
95 const uno::Reference< ucb::XCommandEnvironment > & /*xEnv*/ )
97 osl::Guard< osl::Mutex > aGuard( m_aMutex );
99 if ( m_aProps.getType() == STREAM )
101 //=================================================================
103 // Stream: Supported properties
105 //=================================================================
107 static const beans::Property aStreamPropertyInfoTable[] =
109 ///////////////////////////////////////////////////////////
110 // Mandatory properties
111 ///////////////////////////////////////////////////////////
112 beans::Property(
113 rtl::OUString(
114 RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
116 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
117 beans::PropertyAttribute::BOUND
118 | beans::PropertyAttribute::READONLY
120 beans::Property(
121 rtl::OUString(
122 RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
124 getCppuBooleanType(),
125 beans::PropertyAttribute::BOUND
126 | beans::PropertyAttribute::READONLY
128 beans::Property(
129 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
131 getCppuBooleanType(),
132 beans::PropertyAttribute::BOUND
133 | beans::PropertyAttribute::READONLY
135 beans::Property(
136 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
138 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
139 beans::PropertyAttribute::BOUND
141 ///////////////////////////////////////////////////////////
142 // Optional standard properties
143 ///////////////////////////////////////////////////////////
144 beans::Property(
145 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
146 "CreatableContentsInfo" ) ),
148 getCppuType( static_cast<
149 const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
150 beans::PropertyAttribute::BOUND
151 | beans::PropertyAttribute::READONLY
153 ///////////////////////////////////////////////////////////
154 // New properties
155 ///////////////////////////////////////////////////////////
157 return MAKEPROPSEQUENCE( aStreamPropertyInfoTable );
159 else if ( m_aProps.getType() == FOLDER )
161 //=================================================================
163 // Folder: Supported properties
165 //=================================================================
167 static const beans::Property aFolderPropertyInfoTable[] =
169 ///////////////////////////////////////////////////////////
170 // Mandatory properties
171 ///////////////////////////////////////////////////////////
172 beans::Property(
173 rtl::OUString(
174 RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
176 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
177 beans::PropertyAttribute::BOUND
178 | beans::PropertyAttribute::READONLY
180 beans::Property(
181 rtl::OUString(
182 RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
184 getCppuBooleanType(),
185 beans::PropertyAttribute::BOUND
186 | beans::PropertyAttribute::READONLY
188 beans::Property(
189 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
191 getCppuBooleanType(),
192 beans::PropertyAttribute::BOUND
193 | beans::PropertyAttribute::READONLY
195 beans::Property(
196 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
198 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
199 beans::PropertyAttribute::BOUND
201 ///////////////////////////////////////////////////////////
202 // Optional standard properties
203 ///////////////////////////////////////////////////////////
204 beans::Property(
205 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
206 "CreatableContentsInfo" ) ),
208 getCppuType( static_cast<
209 const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
210 beans::PropertyAttribute::BOUND
211 | beans::PropertyAttribute::READONLY
213 ///////////////////////////////////////////////////////////
214 // New properties
215 ///////////////////////////////////////////////////////////
216 beans::Property(
217 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Storage" ) ),
219 getCppuType( static_cast<
220 const uno::Reference< embed::XStorage > * >( 0 ) ),
221 beans::PropertyAttribute::BOUND
222 | beans::PropertyAttribute::READONLY
225 return MAKEPROPSEQUENCE( aFolderPropertyInfoTable );
227 else if ( m_aProps.getType() == DOCUMENT )
229 //=================================================================
231 // Document: Supported properties
233 //=================================================================
235 static const beans::Property aDocPropertyInfoTable[] =
237 ///////////////////////////////////////////////////////////
238 // Mandatory properties
239 ///////////////////////////////////////////////////////////
240 beans::Property(
241 rtl::OUString(
242 RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
244 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
245 beans::PropertyAttribute::BOUND
246 | beans::PropertyAttribute::READONLY
248 beans::Property(
249 rtl::OUString(
250 RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
252 getCppuBooleanType(),
253 beans::PropertyAttribute::BOUND
254 | beans::PropertyAttribute::READONLY
256 beans::Property(
257 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
259 getCppuBooleanType(),
260 beans::PropertyAttribute::BOUND
261 | beans::PropertyAttribute::READONLY
263 beans::Property(
264 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
266 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
267 beans::PropertyAttribute::BOUND
268 | beans::PropertyAttribute::READONLY
270 ///////////////////////////////////////////////////////////
271 // Optional standard properties
272 ///////////////////////////////////////////////////////////
273 beans::Property(
274 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
275 "CreatableContentsInfo" ) ),
277 getCppuType( static_cast<
278 const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
279 beans::PropertyAttribute::BOUND
280 | beans::PropertyAttribute::READONLY
282 ///////////////////////////////////////////////////////////
283 // New properties
284 ///////////////////////////////////////////////////////////
285 beans::Property(
286 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocumentModel" ) ),
288 getCppuType( static_cast<
289 const uno::Reference< frame::XModel > * >( 0 ) ),
290 beans::PropertyAttribute::BOUND
291 | beans::PropertyAttribute::READONLY
294 return MAKEPROPSEQUENCE( aDocPropertyInfoTable );
296 else
298 //=================================================================
300 // Root: Supported properties
302 //=================================================================
304 OSL_ENSURE( m_aProps.getType() == ROOT, "Wrong content type!" );
306 static const beans::Property aRootPropertyInfoTable[] =
308 ///////////////////////////////////////////////////////////////
309 // Mandatory properties
310 ///////////////////////////////////////////////////////////////
311 beans::Property(
312 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
314 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
315 beans::PropertyAttribute::BOUND
316 | beans::PropertyAttribute::READONLY
318 beans::Property(
319 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
321 getCppuBooleanType(),
322 beans::PropertyAttribute::BOUND
323 | beans::PropertyAttribute::READONLY
325 beans::Property(
326 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
328 getCppuBooleanType(),
329 beans::PropertyAttribute::BOUND
330 | beans::PropertyAttribute::READONLY
332 beans::Property(
333 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
335 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
336 beans::PropertyAttribute::BOUND
337 | beans::PropertyAttribute::READONLY
339 ///////////////////////////////////////////////////////////////
340 // Optional standard properties
341 ///////////////////////////////////////////////////////////////
342 beans::Property(
343 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
344 "CreatableContentsInfo" ) ),
346 getCppuType( static_cast<
347 const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
348 beans::PropertyAttribute::BOUND
349 | beans::PropertyAttribute::READONLY
351 ///////////////////////////////////////////////////////////////
352 // New properties
353 ///////////////////////////////////////////////////////////////
355 return MAKEPROPSEQUENCE( aRootPropertyInfoTable );
359 //=========================================================================
360 // virtual
361 uno::Sequence< ucb::CommandInfo > Content::getCommands(
362 const uno::Reference< ucb::XCommandEnvironment > & /*xEnv*/ )
364 osl::Guard< osl::Mutex > aGuard( m_aMutex );
366 if ( m_aProps.getType() == STREAM )
368 #ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT
369 Uri aUri( m_xIdentifier->getContentIdentifier() );
370 Uri aParentUri( aUri.getParentUri() );
372 if ( aParentUri.isDocument() )
374 //=================================================================
376 // Stream, that is a child of a document: Supported commands
378 //=================================================================
380 static const ucb::CommandInfo aStreamCommandInfoTable1[] =
382 ///////////////////////////////////////////////////////////
383 // Mandatory commands
384 ///////////////////////////////////////////////////////////
385 ucb::CommandInfo(
386 rtl::OUString(
387 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
389 getCppuVoidType()
391 ucb::CommandInfo(
392 rtl::OUString(
393 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
395 getCppuVoidType()
397 ucb::CommandInfo(
398 rtl::OUString(
399 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
401 getCppuType(
402 static_cast< uno::Sequence< beans::Property > * >( 0 ) )
404 ucb::CommandInfo(
405 rtl::OUString(
406 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
408 getCppuType(
409 static_cast<
410 uno::Sequence< beans::PropertyValue > * >( 0 ) )
412 ///////////////////////////////////////////////////////////
413 // Optional standard commands
414 ///////////////////////////////////////////////////////////
415 ucb::CommandInfo(
416 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
418 getCppuBooleanType()
420 ucb::CommandInfo(
421 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
423 getCppuType(
424 static_cast< ucb::OpenCommandArgument2 * >( 0 ) )
426 ///////////////////////////////////////////////////////////
427 // New commands
428 ///////////////////////////////////////////////////////////
430 return MAKECMDSEQUENCE( aStreamCommandInfoTable1 );
432 #endif
433 //=================================================================
435 // Stream: Supported commands
437 //=================================================================
439 static const ucb::CommandInfo aStreamCommandInfoTable[] =
441 ///////////////////////////////////////////////////////////
442 // Mandatory commands
443 ///////////////////////////////////////////////////////////
444 ucb::CommandInfo(
445 rtl::OUString(
446 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
448 getCppuVoidType()
450 ucb::CommandInfo(
451 rtl::OUString(
452 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
454 getCppuVoidType()
456 ucb::CommandInfo(
457 rtl::OUString(
458 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
460 getCppuType(
461 static_cast< uno::Sequence< beans::Property > * >( 0 ) )
463 ucb::CommandInfo(
464 rtl::OUString(
465 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
467 getCppuType(
468 static_cast<
469 uno::Sequence< beans::PropertyValue > * >( 0 ) )
471 ///////////////////////////////////////////////////////////
472 // Optional standard commands
473 ///////////////////////////////////////////////////////////
474 ucb::CommandInfo(
475 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
477 getCppuBooleanType()
479 ucb::CommandInfo(
480 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
482 getCppuVoidType()
484 ucb::CommandInfo(
485 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
487 getCppuType(
488 static_cast< ucb::OpenCommandArgument2 * >( 0 ) )
490 ///////////////////////////////////////////////////////////
491 // New commands
492 ///////////////////////////////////////////////////////////
494 return MAKECMDSEQUENCE( aStreamCommandInfoTable );
496 else if ( m_aProps.getType() == FOLDER )
498 //=================================================================
500 // Folder: Supported commands
502 //=================================================================
504 static const ucb::CommandInfo aFolderCommandInfoTable[] =
506 ///////////////////////////////////////////////////////////
507 // Mandatory commands
508 ///////////////////////////////////////////////////////////
509 ucb::CommandInfo(
510 rtl::OUString(
511 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
513 getCppuVoidType()
515 ucb::CommandInfo(
516 rtl::OUString(
517 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
519 getCppuVoidType()
521 ucb::CommandInfo(
522 rtl::OUString(
523 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
525 getCppuType(
526 static_cast< uno::Sequence< beans::Property > * >( 0 ) )
528 ucb::CommandInfo(
529 rtl::OUString(
530 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
532 getCppuType(
533 static_cast<
534 uno::Sequence< beans::PropertyValue > * >( 0 ) )
536 ///////////////////////////////////////////////////////////
537 // Optional standard commands
538 ///////////////////////////////////////////////////////////
539 ucb::CommandInfo(
540 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
542 getCppuBooleanType()
544 ucb::CommandInfo(
545 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
547 getCppuVoidType()
549 ucb::CommandInfo(
550 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
552 getCppuType(
553 static_cast< ucb::OpenCommandArgument2 * >( 0 ) )
555 ucb::CommandInfo(
556 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
558 getCppuType( static_cast< ucb::TransferInfo * >( 0 ) )
560 ucb::CommandInfo(
561 rtl::OUString(
562 RTL_CONSTASCII_USTRINGPARAM( "createNewContent" ) ),
564 getCppuType( static_cast< ucb::ContentInfo * >( 0 ) )
566 ///////////////////////////////////////////////////////////
567 // New commands
568 ///////////////////////////////////////////////////////////
570 return MAKECMDSEQUENCE( aFolderCommandInfoTable );
572 else if ( m_aProps.getType() == DOCUMENT )
574 //=================================================================
576 // Document: Supported commands
578 //=================================================================
580 static const ucb::CommandInfo aDocCommandInfoTable[] =
582 ///////////////////////////////////////////////////////////
583 // Mandatory commands
584 ///////////////////////////////////////////////////////////
585 ucb::CommandInfo(
586 rtl::OUString(
587 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
589 getCppuVoidType()
591 ucb::CommandInfo(
592 rtl::OUString(
593 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
595 getCppuVoidType()
597 ucb::CommandInfo(
598 rtl::OUString(
599 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
601 getCppuType(
602 static_cast< uno::Sequence< beans::Property > * >( 0 ) )
604 ucb::CommandInfo(
605 rtl::OUString(
606 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
608 getCppuType(
609 static_cast<
610 uno::Sequence< beans::PropertyValue > * >( 0 ) )
612 ///////////////////////////////////////////////////////////
613 // Optional standard commands
614 ///////////////////////////////////////////////////////////
615 ucb::CommandInfo(
616 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
618 getCppuType(
619 static_cast< ucb::OpenCommandArgument2 * >( 0 ) )
621 ucb::CommandInfo(
622 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
624 getCppuType( static_cast< ucb::TransferInfo * >( 0 ) )
626 ucb::CommandInfo(
627 rtl::OUString(
628 RTL_CONSTASCII_USTRINGPARAM( "createNewContent" ) ),
630 getCppuType( static_cast< ucb::ContentInfo * >( 0 ) )
632 ///////////////////////////////////////////////////////////
633 // New commands
634 ///////////////////////////////////////////////////////////
636 return MAKECMDSEQUENCE( aDocCommandInfoTable );
638 else
640 //=================================================================
642 // Root: Supported commands
644 //=================================================================
646 OSL_ENSURE( m_aProps.getType() == ROOT, "Wrong content type!" );
648 static const ucb::CommandInfo aRootCommandInfoTable[] =
650 ///////////////////////////////////////////////////////////
651 // Mandatory commands
652 ///////////////////////////////////////////////////////////
653 ucb::CommandInfo(
654 rtl::OUString(
655 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
657 getCppuVoidType()
659 ucb::CommandInfo(
660 rtl::OUString(
661 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
663 getCppuVoidType()
665 ucb::CommandInfo(
666 rtl::OUString(
667 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
669 getCppuType(
670 static_cast< uno::Sequence< beans::Property > * >( 0 ) )
672 ucb::CommandInfo(
673 rtl::OUString(
674 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
676 getCppuType(
677 static_cast<
678 uno::Sequence< beans::PropertyValue > * >( 0 ) )
680 ///////////////////////////////////////////////////////////
681 // Optional standard commands
682 ///////////////////////////////////////////////////////////
683 ucb::CommandInfo(
684 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
686 getCppuType(
687 static_cast< ucb::OpenCommandArgument2 * >( 0 ) )
689 ///////////////////////////////////////////////////////////
690 // New commands
691 ///////////////////////////////////////////////////////////
693 return MAKECMDSEQUENCE( aRootCommandInfoTable );
697 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */