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