1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ucb.hxx"
26 
27 /**************************************************************************
28                                 TODO
29  **************************************************************************
30 
31     Props/Commands:
32 
33                         rootfolder folder  stream
34     ---------------------------------------------
35     ContentType           r         r         r
36     IsDocument            r         r         r
37     IsFolder              r         r         r
38     MediaType            (w)       (w)        w
39     Title                 r         w         w
40     Size                  -         -         r
41     CreatableContentsInfo r         r         r
42     Compressed            -         -         w
43     Encrypted             -         -         w
44     HasEncryptedEntries   r         -         -
45 
46     getCommandInfo        x         x         x
47     getPropertySetInfo    x         x         x
48     getPropertyValues     x         x         x
49     setPropertyValues     x         x         x
50     insert                -         x         x
51     delete                -         x         x
52     open                  x         x         x
53     transfer              x         x         -
54     flush                 x         x         -
55     createNewContent      x         x         -
56 
57  *************************************************************************/
58 #include <com/sun/star/beans/Property.hpp>
59 #include <com/sun/star/beans/PropertyAttribute.hpp>
60 #include <com/sun/star/beans/PropertyValue.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 <com/sun/star/uno/Sequence.hxx>
65 #include "pkgcontent.hxx"
66 
67 using namespace com::sun::star;
68 using namespace package_ucp;
69 
70 //=========================================================================
71 //
72 // Content implementation.
73 //
74 //=========================================================================
75 
76 #define MAKEPROPSEQUENCE( a ) \
77     uno::Sequence< beans::Property >( a, sizeof( a )  / sizeof( a[ 0 ] ) )
78 
79 #define MAKECMDSEQUENCE( a ) \
80     uno::Sequence< ucb::CommandInfo >( a, sizeof( a )  / sizeof( a[ 0 ] ) )
81 
82 //=========================================================================
83 //
84 // IMPORTENT: If any property data ( name / type / ... ) are changed, then
85 //            Content::getPropertyValues(...) must be adapted too!
86 //
87 //=========================================================================
88 
89 // virtual
90 uno::Sequence< beans::Property > Content::getProperties(
91             const uno::Reference< ucb::XCommandEnvironment > & /*xEnv*/ )
92 {
93     osl::Guard< osl::Mutex > aGuard( m_aMutex );
94 
95     if ( isFolder() )
96     {
97         if ( m_aUri.isRootFolder() )
98         {
99             //=================================================================
100             //
101             // Root Folder: Supported properties
102             //
103             //=================================================================
104 
105             static const beans::Property aRootFolderPropertyInfoTable[] =
106             {
107                 ///////////////////////////////////////////////////////////////
108                 // Required properties
109                 ///////////////////////////////////////////////////////////////
110                 beans::Property(
111                     rtl::OUString(
112                         RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
113                     -1,
114                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
115                     beans::PropertyAttribute::BOUND
116                         | beans::PropertyAttribute::READONLY
117                 ),
118                 beans::Property(
119                     rtl::OUString(
120                         RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
121                     -1,
122                     getCppuBooleanType(),
123                     beans::PropertyAttribute::BOUND
124                         | beans::PropertyAttribute::READONLY
125                 ),
126                 beans::Property(
127                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
128                     -1,
129                     getCppuBooleanType(),
130                     beans::PropertyAttribute::BOUND
131                         | beans::PropertyAttribute::READONLY
132                 ),
133                 beans::Property(
134                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
135                     -1,
136                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
137                     beans::PropertyAttribute::BOUND
138                         | beans::PropertyAttribute::READONLY
139                 ),
140                 ///////////////////////////////////////////////////////////////
141                 // Optional standard properties
142                 ///////////////////////////////////////////////////////////////
143                 beans::Property(
144                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
145                     -1,
146                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
147                     beans::PropertyAttribute::BOUND
148                 ),
149                 beans::Property(
150                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
151                         "CreatableContentsInfo" ) ),
152                     -1,
153                     getCppuType( static_cast<
154                         const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
155                     beans::PropertyAttribute::BOUND
156                         | beans::PropertyAttribute::READONLY
157                 ),
158                 ///////////////////////////////////////////////////////////////
159                 // New properties
160                 ///////////////////////////////////////////////////////////////
161                 beans::Property(
162                     rtl::OUString(
163                         RTL_CONSTASCII_USTRINGPARAM( "HasEncryptedEntries" ) ),
164                     -1,
165                     getCppuBooleanType(),
166                     beans::PropertyAttribute::BOUND
167                         | beans::PropertyAttribute::READONLY
168                 )
169             };
170             return MAKEPROPSEQUENCE( aRootFolderPropertyInfoTable );
171         }
172         else
173         {
174             //=================================================================
175             //
176             // Folder: Supported properties
177             //
178             //=================================================================
179 
180             static const beans::Property aFolderPropertyInfoTable[] =
181             {
182                 ///////////////////////////////////////////////////////////////
183                 // Required properties
184                 ///////////////////////////////////////////////////////////////
185                 beans::Property(
186                     rtl::OUString(
187                         RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
188                     -1,
189                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
190                     beans::PropertyAttribute::BOUND
191                         | beans::PropertyAttribute::READONLY
192                 ),
193                 beans::Property(
194                     rtl::OUString(
195                         RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
196                     -1,
197                     getCppuBooleanType(),
198                     beans::PropertyAttribute::BOUND
199                         | beans::PropertyAttribute::READONLY
200                 ),
201                 beans::Property(
202                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
203                     -1,
204                     getCppuBooleanType(),
205                     beans::PropertyAttribute::BOUND
206                         | beans::PropertyAttribute::READONLY
207                 ),
208                 beans::Property(
209                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
210                     -1,
211                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
212                     beans::PropertyAttribute::BOUND
213                 ),
214                 ///////////////////////////////////////////////////////////////
215                 // Optional standard properties
216                 ///////////////////////////////////////////////////////////////
217                 beans::Property(
218                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
219                     -1,
220                     getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
221                     beans::PropertyAttribute::BOUND
222                 ),
223                 beans::Property(
224                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
225                         "CreatableContentsInfo" ) ),
226                     -1,
227                     getCppuType( static_cast<
228                         const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
229                     beans::PropertyAttribute::BOUND
230                         | beans::PropertyAttribute::READONLY
231                 )
232                 ///////////////////////////////////////////////////////////////
233                 // New properties
234                 ///////////////////////////////////////////////////////////////
235             };
236             return MAKEPROPSEQUENCE( aFolderPropertyInfoTable );
237         }
238     }
239     else
240     {
241         //=================================================================
242         //
243         // Stream: Supported properties
244         //
245         //=================================================================
246 
247         static const beans::Property aStreamPropertyInfoTable[] =
248         {
249             ///////////////////////////////////////////////////////////////
250             // Required properties
251             ///////////////////////////////////////////////////////////////
252             beans::Property(
253                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ContentType" ) ),
254                 -1,
255                 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
256                 beans::PropertyAttribute::BOUND
257                     | beans::PropertyAttribute::READONLY
258             ),
259             beans::Property(
260                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ),
261                 -1,
262                 getCppuBooleanType(),
263                 beans::PropertyAttribute::BOUND
264                     | beans::PropertyAttribute::READONLY
265             ),
266             beans::Property(
267                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ),
268                 -1,
269                 getCppuBooleanType(),
270                 beans::PropertyAttribute::BOUND
271                     | beans::PropertyAttribute::READONLY
272             ),
273             beans::Property(
274                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ),
275                 -1,
276                 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
277                 beans::PropertyAttribute::BOUND
278             ),
279             ///////////////////////////////////////////////////////////////
280             // Optional standard properties
281             ///////////////////////////////////////////////////////////////
282             beans::Property(
283                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ),
284                 -1,
285                 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
286                 beans::PropertyAttribute::BOUND
287             ),
288             beans::Property(
289                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ),
290                 -1,
291                 getCppuType( static_cast< const sal_Int64 * >( 0 ) ),
292                 beans::PropertyAttribute::BOUND
293                     | beans::PropertyAttribute::READONLY
294             ),
295             beans::Property(
296                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
297                     "CreatableContentsInfo" ) ),
298                 -1,
299                 getCppuType( static_cast<
300                     const uno::Sequence< ucb::ContentInfo > * >( 0 ) ),
301                 beans::PropertyAttribute::BOUND
302                 | beans::PropertyAttribute::READONLY
303             ),
304             ///////////////////////////////////////////////////////////////
305             // New properties
306             ///////////////////////////////////////////////////////////////
307             beans::Property(
308                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ),
309                 -1,
310                 getCppuBooleanType(),
311                 beans::PropertyAttribute::BOUND
312             ),
313             beans::Property(
314                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) ),
315                 -1,
316                 getCppuBooleanType(),
317                 beans::PropertyAttribute::BOUND
318             )
319         };
320         return MAKEPROPSEQUENCE( aStreamPropertyInfoTable );
321     }
322 }
323 
324 //=========================================================================
325 // virtual
326 uno::Sequence< ucb::CommandInfo > Content::getCommands(
327             const uno::Reference< ucb::XCommandEnvironment > & /*xEnv*/ )
328 {
329     osl::Guard< osl::Mutex > aGuard( m_aMutex );
330 
331     if ( isFolder() )
332     {
333         if ( m_aUri.isRootFolder() )
334         {
335             //=================================================================
336             //
337             // Root Folder: Supported commands
338             //
339             //=================================================================
340 
341             static const ucb::CommandInfo aRootFolderCommandInfoTable[] =
342             {
343                 ///////////////////////////////////////////////////////////
344                 // Required commands
345                 ///////////////////////////////////////////////////////////
346                 ucb::CommandInfo(
347                     rtl::OUString(
348                         RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
349                     -1,
350                     getCppuVoidType()
351                 ),
352                 ucb::CommandInfo(
353                     rtl::OUString(
354                         RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
355                     -1,
356                     getCppuVoidType()
357                 ),
358                 ucb::CommandInfo(
359                     rtl::OUString(
360                         RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
361                     -1,
362                     getCppuType(
363                         static_cast<
364                             uno::Sequence< beans::Property > * >( 0 ) )
365                 ),
366                 ucb::CommandInfo(
367                     rtl::OUString(
368                         RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
369                     -1,
370                     getCppuType(
371                         static_cast<
372                             uno::Sequence< beans::PropertyValue > * >( 0 ) )
373                 ),
374                 ///////////////////////////////////////////////////////////
375                 // Optional standard commands
376                 ///////////////////////////////////////////////////////////
377                 ucb::CommandInfo(
378                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
379                     -1,
380                     getCppuType(
381                         static_cast< ucb::OpenCommandArgument2 * >( 0 ) )
382                 ),
383                 ucb::CommandInfo(
384                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
385                     -1,
386                     getCppuType(
387                         static_cast< ucb::TransferInfo * >( 0 ) )
388                 ),
389                 ucb::CommandInfo(
390                     rtl::OUString(
391                         RTL_CONSTASCII_USTRINGPARAM( "createNewContent" ) ),
392                     -1,
393                     getCppuType( static_cast< ucb::ContentInfo * >( 0 ) )
394                 ),
395                 ///////////////////////////////////////////////////////////
396                 // New commands
397                 ///////////////////////////////////////////////////////////
398                 ucb::CommandInfo(
399                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "flush" ) ),
400                     -1,
401                     getCppuVoidType()
402                 )
403             };
404 
405             return MAKECMDSEQUENCE( aRootFolderCommandInfoTable );
406         }
407         else
408         {
409             //=================================================================
410             //
411             // Folder: Supported commands
412             //
413             //=================================================================
414 
415             static const ucb::CommandInfo aFolderCommandInfoTable[] =
416             {
417                 ///////////////////////////////////////////////////////////
418                 // Required commands
419                 ///////////////////////////////////////////////////////////
420                 ucb::CommandInfo(
421                     rtl::OUString(
422                         RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
423                     -1,
424                     getCppuVoidType()
425                 ),
426                 ucb::CommandInfo(
427                     rtl::OUString(
428                         RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
429                     -1,
430                     getCppuVoidType()
431                 ),
432                 ucb::CommandInfo(
433                     rtl::OUString(
434                         RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
435                     -1,
436                     getCppuType(
437                         static_cast<
438                             uno::Sequence< beans::Property > * >( 0 ) )
439                 ),
440                 ucb::CommandInfo(
441                     rtl::OUString(
442                         RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
443                     -1,
444                     getCppuType(
445                         static_cast<
446                             uno::Sequence< beans::PropertyValue > * >( 0 ) )
447                 ),
448                 ///////////////////////////////////////////////////////////
449                 // Optional standard commands
450                 ///////////////////////////////////////////////////////////
451                 ucb::CommandInfo(
452                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
453                     -1,
454                     getCppuBooleanType()
455                 ),
456                 ucb::CommandInfo(
457                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
458                     -1,
459                     getCppuVoidType()
460                 ),
461                 ucb::CommandInfo(
462                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
463                     -1,
464                     getCppuType(
465                         static_cast< ucb::OpenCommandArgument2 * >( 0 ) )
466                 ),
467                 ucb::CommandInfo(
468                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ),
469                     -1,
470                     getCppuType(
471                         static_cast< ucb::TransferInfo * >( 0 ) )
472                 ),
473                 ucb::CommandInfo(
474                     rtl::OUString(
475                         RTL_CONSTASCII_USTRINGPARAM( "createNewContent" ) ),
476                     -1,
477                     getCppuType( static_cast< ucb::ContentInfo * >( 0 ) )
478                 ),
479                 ///////////////////////////////////////////////////////////
480                 // New commands
481                 ///////////////////////////////////////////////////////////
482                 ucb::CommandInfo(
483                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "flush" ) ),
484                     -1,
485                     getCppuVoidType()
486                 )
487             };
488 
489             return MAKECMDSEQUENCE( aFolderCommandInfoTable );
490         }
491     }
492     else
493     {
494         //=================================================================
495         //
496         // Stream: Supported commands
497         //
498         //=================================================================
499 
500         static const ucb::CommandInfo aStreamCommandInfoTable[] =
501         {
502             ///////////////////////////////////////////////////////////////
503             // Required commands
504             ///////////////////////////////////////////////////////////////
505             ucb::CommandInfo(
506                 rtl::OUString(
507                     RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ),
508                 -1,
509                 getCppuVoidType()
510             ),
511             ucb::CommandInfo(
512                 rtl::OUString(
513                     RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ),
514                 -1,
515                 getCppuVoidType()
516             ),
517             ucb::CommandInfo(
518                 rtl::OUString(
519                     RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ),
520                 -1,
521                 getCppuType(
522                     static_cast< uno::Sequence< beans::Property > * >( 0 ) )
523             ),
524             ucb::CommandInfo(
525                 rtl::OUString(
526                     RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ),
527                 -1,
528                 getCppuType(
529                     static_cast<
530                         uno::Sequence< beans::PropertyValue > * >( 0 ) )
531             ),
532             ///////////////////////////////////////////////////////////////
533             // Optional standard commands
534             ///////////////////////////////////////////////////////////////
535             ucb::CommandInfo(
536                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ),
537                 -1,
538                 getCppuBooleanType()
539             ),
540             ucb::CommandInfo(
541                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ),
542                 -1,
543                 getCppuVoidType()
544             ),
545             ucb::CommandInfo(
546                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ),
547                 -1,
548                 getCppuType(
549                     static_cast< ucb::OpenCommandArgument2 * >( 0 ) )
550             )
551             ///////////////////////////////////////////////////////////////
552             // New commands
553             ///////////////////////////////////////////////////////////////
554         };
555 
556         return MAKECMDSEQUENCE( aStreamCommandInfoTable );
557     }
558 }
559