1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 /**************************************************************************
23 **************************************************************************
25 **************************************************************************
29 root document folder folder stream stream
31 ----------------------------------------------------------------
32 ContentType r r r r r r
33 IsDocument r r r r r r
36 CreatableContentsInfo r r r r 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(*)
48 createNewContent - x x - - -
50 #ifdef NO_STREAM_CREATION_WITHIN_DOCUMENT_ROOT
51 (*) not supported by streams that are direct children of document
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
{
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 //=========================================================================
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 ///////////////////////////////////////////////////////////
114 RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
116 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
117 beans::PropertyAttribute::BOUND
118 | beans::PropertyAttribute::READONLY
122 RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
124 getCppuBooleanType(),
125 beans::PropertyAttribute::BOUND
126 | beans::PropertyAttribute::READONLY
129 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
131 getCppuBooleanType(),
132 beans::PropertyAttribute::BOUND
133 | beans::PropertyAttribute::READONLY
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 ///////////////////////////////////////////////////////////
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 ///////////////////////////////////////////////////////////
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 ///////////////////////////////////////////////////////////
174 RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
176 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
177 beans::PropertyAttribute::BOUND
178 | beans::PropertyAttribute::READONLY
182 RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
184 getCppuBooleanType(),
185 beans::PropertyAttribute::BOUND
186 | beans::PropertyAttribute::READONLY
189 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
191 getCppuBooleanType(),
192 beans::PropertyAttribute::BOUND
193 | beans::PropertyAttribute::READONLY
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 ///////////////////////////////////////////////////////////
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 ///////////////////////////////////////////////////////////
215 ///////////////////////////////////////////////////////////
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 ///////////////////////////////////////////////////////////
242 RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
244 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
245 beans::PropertyAttribute::BOUND
246 | beans::PropertyAttribute::READONLY
250 RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
252 getCppuBooleanType(),
253 beans::PropertyAttribute::BOUND
254 | beans::PropertyAttribute::READONLY
257 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
259 getCppuBooleanType(),
260 beans::PropertyAttribute::BOUND
261 | beans::PropertyAttribute::READONLY
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 ///////////////////////////////////////////////////////////
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 ///////////////////////////////////////////////////////////
284 ///////////////////////////////////////////////////////////
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
);
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 ///////////////////////////////////////////////////////////////
312 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
314 getCppuType( static_cast< const rtl::OUString
* >( 0 ) ),
315 beans::PropertyAttribute::BOUND
316 | beans::PropertyAttribute::READONLY
319 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
321 getCppuBooleanType(),
322 beans::PropertyAttribute::BOUND
323 | beans::PropertyAttribute::READONLY
326 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
328 getCppuBooleanType(),
329 beans::PropertyAttribute::BOUND
330 | beans::PropertyAttribute::READONLY
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 ///////////////////////////////////////////////////////////////
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 ///////////////////////////////////////////////////////////////
353 ///////////////////////////////////////////////////////////////
355 return MAKEPROPSEQUENCE( aRootPropertyInfoTable
);
359 //=========================================================================
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 ///////////////////////////////////////////////////////////
387 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
393 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
399 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
402 static_cast< uno::Sequence
< beans::Property
> * >( 0 ) )
406 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
410 uno::Sequence
< beans::PropertyValue
> * >( 0 ) )
412 ///////////////////////////////////////////////////////////
413 // Optional standard commands
414 ///////////////////////////////////////////////////////////
416 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
421 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
424 static_cast< ucb::OpenCommandArgument2
* >( 0 ) )
426 ///////////////////////////////////////////////////////////
428 ///////////////////////////////////////////////////////////
430 return MAKECMDSEQUENCE( aStreamCommandInfoTable1
);
433 //=================================================================
435 // Stream: Supported commands
437 //=================================================================
439 static const ucb::CommandInfo aStreamCommandInfoTable
[] =
441 ///////////////////////////////////////////////////////////
442 // Mandatory commands
443 ///////////////////////////////////////////////////////////
446 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
452 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
458 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
461 static_cast< uno::Sequence
< beans::Property
> * >( 0 ) )
465 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
469 uno::Sequence
< beans::PropertyValue
> * >( 0 ) )
471 ///////////////////////////////////////////////////////////
472 // Optional standard commands
473 ///////////////////////////////////////////////////////////
475 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
480 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
485 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
488 static_cast< ucb::OpenCommandArgument2
* >( 0 ) )
490 ///////////////////////////////////////////////////////////
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 ///////////////////////////////////////////////////////////
511 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
517 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
523 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
526 static_cast< uno::Sequence
< beans::Property
> * >( 0 ) )
530 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
534 uno::Sequence
< beans::PropertyValue
> * >( 0 ) )
536 ///////////////////////////////////////////////////////////
537 // Optional standard commands
538 ///////////////////////////////////////////////////////////
540 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
545 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
550 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
553 static_cast< ucb::OpenCommandArgument2
* >( 0 ) )
556 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
558 getCppuType( static_cast< ucb::TransferInfo
* >( 0 ) )
562 RTL_CONSTASCII_USTRINGPARAM( "createNewContent" ) ),
564 getCppuType( static_cast< ucb::ContentInfo
* >( 0 ) )
566 ///////////////////////////////////////////////////////////
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 ///////////////////////////////////////////////////////////
587 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
593 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
599 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
602 static_cast< uno::Sequence
< beans::Property
> * >( 0 ) )
606 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
610 uno::Sequence
< beans::PropertyValue
> * >( 0 ) )
612 ///////////////////////////////////////////////////////////
613 // Optional standard commands
614 ///////////////////////////////////////////////////////////
616 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
619 static_cast< ucb::OpenCommandArgument2
* >( 0 ) )
622 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
624 getCppuType( static_cast< ucb::TransferInfo
* >( 0 ) )
628 RTL_CONSTASCII_USTRINGPARAM( "createNewContent" ) ),
630 getCppuType( static_cast< ucb::ContentInfo
* >( 0 ) )
632 ///////////////////////////////////////////////////////////
634 ///////////////////////////////////////////////////////////
636 return MAKECMDSEQUENCE( aDocCommandInfoTable
);
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 ///////////////////////////////////////////////////////////
655 RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
661 RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
667 RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
670 static_cast< uno::Sequence
< beans::Property
> * >( 0 ) )
674 RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
678 uno::Sequence
< beans::PropertyValue
> * >( 0 ) )
680 ///////////////////////////////////////////////////////////
681 // Optional standard commands
682 ///////////////////////////////////////////////////////////
684 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
687 static_cast< ucb::OpenCommandArgument2
* >( 0 ) )
689 ///////////////////////////////////////////////////////////
691 ///////////////////////////////////////////////////////////
693 return MAKECMDSEQUENCE( aRootCommandInfoTable
);
697 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */