Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / ucbhelper / content.hxx
blob90a28229f9dd6aeb5ffbaf39ac48c907541d33b0
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 .
19 #ifndef INCLUDED_UCBHELPER_CONTENT_HXX
20 #define INCLUDED_UCBHELPER_CONTENT_HXX
22 #include <rtl/ref.hxx>
23 #include <com/sun/star/ucb/ContentCreationException.hpp>
24 #include <com/sun/star/ucb/CommandAbortedException.hpp>
25 #include <com/sun/star/io/XStream.hpp>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <ucbhelper/ucbhelperdllapi.h>
30 namespace com { namespace sun { namespace star { namespace beans {
31 class XPropertySetInfo;
32 } } } }
34 namespace com { namespace sun { namespace star { namespace io {
35 class XActiveDataSink;
36 class XOutputStream;
37 class XInputStream;
38 } } } }
40 namespace com { namespace sun { namespace star { namespace sdbc {
41 class XResultSet;
42 class XRow;
43 } } } }
45 namespace com { namespace sun { namespace star { namespace ucb {
46 class XCommandEnvironment;
47 class XCommandInfo;
48 class XContent;
49 class XContentIdentifier;
50 class XDynamicResultSet;
51 class XAnyCompareFactory;
52 struct ContentInfo;
53 struct NumberedSortingInfo;
54 } } } }
56 namespace com { namespace sun { namespace star { namespace uno {
57 class XComponentContext;
58 } } } }
60 namespace ucbhelper
64 /**
65 * These are the possible values for the parameter eMode of method
66 * ucbhelper::Content::createCursor.
68 enum ResultSetInclude
70 INCLUDE_FOLDERS_ONLY,
71 INCLUDE_DOCUMENTS_ONLY,
72 INCLUDE_FOLDERS_AND_DOCUMENTS
75 /**
76 * These are the possible values for the parameter eOperation of method
77 * ucbhelper::Content::insertNewContent.
79 enum class InsertOperation
81 Copy, // copy source data
82 Move, // move source data
83 Checkin // check-in source data
87 class Content_Impl;
89 /**
90 * This class simplifies access to UCB contents by providing a more
91 * convenient API for frequently used functionality then the "raw"
92 * UCB-API does.
94 class UCBHELPER_DLLPUBLIC Content
96 rtl::Reference< Content_Impl > m_xImpl;
98 protected:
99 /// @throws css::ucb::CommandAbortedException
100 /// @throws css::uno::RuntimeException,
101 /// @throws css::uno::Exception
102 css::uno::Any createCursorAny( const css::uno::Sequence< OUString >& rPropertyNames,
103 ResultSetInclude eMode );
105 public:
107 * Constructor.
109 Content();
112 * Constructor.
114 * @param rURL is the URL of the content to create.
115 * @param rEnv is the environment to use for commands executed by the
116 * content. The command environment is used by the content
117 * implementation to interact with the client and to propagate
118 * errors.
119 * @throws css::ucb::ContentCreationException
120 * @throws css::uno::RuntimeException
122 Content( const OUString& rURL,
123 const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnv,
124 const css::uno::Reference< css::uno::XComponentContext >& rCtx );
126 * Constructor.
128 * @param rContent is the content object of the content to create.
129 * @param rEnv is the environment to use for commands executed by the
130 * content. The command environment is used by the content
131 * implementation to interact with the client and to propagate
132 * errors.
133 * @throws css::ucb::ContentCreationException
134 * @throws css::uno::RuntimeException
136 Content( const css::uno::Reference< css::ucb::XContent >& rContent,
137 const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnv,
138 const css::uno::Reference< css::uno::XComponentContext >& rCtx );
140 * Copy Constructor.
142 * @param rContent is the content this content shall be a copy of.
144 Content( const Content& rOther );
147 * Move constructor.
149 Content( Content&& rOther );
152 * Destructor.
154 ~Content();
157 * Assignment operator.
159 * @param rContent is the content this content shall be a copy of.
161 Content& operator=( const Content& rOther );
164 * Move assignment operator.
166 Content& operator=( Content&& rOther );
169 * Constructor. This method should be used, if the exception thrown
170 * by the direct ctors of this class are to 'expensive' for your
171 * application
173 * @param rURL is the URL of the content to create.
174 * @param rEnv is the environment to use for commands executed by the
175 * content. The command environment is used by the content
176 * implementation to interact with the client and to propagate
177 * errors.
178 * @param rContent will be filled by this method with the content created.
179 * @return true, if the operation was successful - false, otherwise.
181 static bool
182 create( const OUString& rURL,
183 const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnv,
184 const css::uno::Reference< css::uno::XComponentContext >& rCtx,
185 Content& rContent );
188 // Direct access to UCB content.
192 * This method provides access to the "native" UCB content interface(s).
193 * This is useful in case the convenience methods provided by this
194 * class are insufficient for your needs. You may obtain all interfaces
195 * supported by the underlying UCB content by calling this method and
196 * after that doing a queryInterface call.
198 * @return the XContent interface of the underlying UCB content.
200 css::uno::Reference< css::ucb::XContent > get() const;
203 // Object identity.
207 * This method returns the URL of the content.
209 * @return the URL of the content.
211 const OUString& getURL() const;
214 // Command environment.
218 * This method returns the environment to use when executing commands.
220 * @return the command environment.
222 const css::uno::Reference< css::ucb::XCommandEnvironment >&
223 getCommandEnvironment() const;
226 * This method sets a new command environment.
228 * @param xNewEnv is the new command environment.
230 void setCommandEnvironment(
231 const css::uno::Reference< css::ucb::XCommandEnvironment >& xNewEnv );
234 // Access to supported commands/properties.
238 * This methods provides access to meta data of the commands supported
239 * by this content.
241 * @return an XCommandInfo interface implementation, which can be used
242 * to obtain meta data of the commands supported by this content.
243 * @throws css::ucb::CommandAbortedException
244 * @throws css::uno::RuntimeException
245 * @throws css::uno::Exception
247 css::uno::Reference< css::ucb::XCommandInfo >
248 getCommands();
250 * This methods provides access to meta data of the properties supported
251 * by this content.
253 * @return an XPropertSetInfo interface implementation, which can be used
254 * to obtain meta data of the properties supported by this content.
255 * @throws css::ucb::CommandAbortedException
256 * @throws css::uno::RuntimeException
257 * @throws css::uno::Exception
259 css::uno::Reference< css::beans::XPropertySetInfo >
260 getProperties();
263 // Access to property value(s).
267 * This method can be used to read a single property value.
269 * @param rPropertyName is the name of the property for that the value
270 * shall be obtained.
271 * @return the property value.
272 * @throws css::ucb::CommandAbortedException
273 * @throws css::uno::RuntimeException
274 * @throws css::uno::Exception
276 css::uno::Any
277 getPropertyValue( const OUString& rPropertyName );
279 * This method can be used to set a single property value.
281 * @param rPropertyName is the name of the property for that the
282 * value shall be set.
283 * @return an any containing:
284 * - No value indicates, that the property value was set
285 * successfully.
286 * - css::beans::UnknownPropertyException indicates,
287 * that the property is not known to the content implementation.
288 * - css::beans::IllegalTypeException indicates, that
289 * the data type of the property value is not acceptable.
290 * - css::lang::IllegalAccessException indicates, that
291 * the property is constant.
292 * - css::lang::IllegalArgumentException indicates,
293 * that the property value is not acceptable. For instance,
294 * setting an empty title may be illegal.
295 * - Any other exception derived from
296 * css::uno::Exception indicates, that the value was
297 * not set successfully. For example, this can be a
298 * com::sun:star::ucb::InteractiveAugmentedIOException
299 * transporting the error code
300 * css::ucb::IOErrorCode::ACCESS_DENIED.
301 * @throws css::ucb::CommandAbortedException
302 * @throws css::uno::RuntimeException
303 * @throws css::uno::Exception
305 css::uno::Any
306 setPropertyValue( const OUString& rPropertyName,
307 const css::uno::Any& rValue );
309 * This method can be used to read multiple property values.
311 * @param rPropertyNames is a sequence of names of properties for
312 * that the values shall be obtained.
313 * @return the property values.
314 * @throws css::ucb::CommandAbortedException
315 * @throws css::uno::RuntimeException
316 * @throws css::uno::Exception
318 css::uno::Sequence< css::uno::Any >
319 getPropertyValues( const css::uno::Sequence< OUString >& rPropertyNames );
321 * This method can be used to read multiple property values.
323 * @param rPropertyNames is a sequence of names of properties for
324 * that the values shall be obtained.
325 * @return the property values.
326 * @throws css::ucb::CommandAbortedException
327 * @throws css::uno::RuntimeException
328 * @throws css::uno::Exception
330 css::uno::Reference< css::sdbc::XRow >
331 getPropertyValuesInterface( const css::uno::Sequence< OUString >& rPropertyNames );
334 * This method can be used to set multiple property values.
336 * @param rPropertyNames is a sequence of names of properties for
337 * that values shall be set.
338 * @return a sequence of any's which has exactly the same number
339 * of elements as the number of properties to set. Every
340 * sequence element contains the status for a property. The
341 * first sequence elements corresponds to the first element in
342 * the sequence of property names and so on.
344 * An any containing:
345 * - No value indicates, that the property value was set
346 * successfully.
347 * - css::beans::UnknownPropertyException indicates,
348 * that the property is not known to the content implementation.
349 * - css::beans::IllegalTypeException indicates, that
350 * the data type of the property value is not acceptable.
351 * - css::lang::IllegalAccessException indicates, that
352 * the property is constant.
353 * - css::lang::IllegalArgumentException indicates,
354 * that the property value is not acceptable. For instance,
355 * setting an empty title may be illegal.
356 * - Any other exception derived from
357 * css::uno::Exception indicates, that the value was
358 * not set successfully. For example, this can be a
359 * com::sun:star::ucb::InteractiveAugmentedIOException
360 * transporting the error code
361 * css::ucb::IOErrorCode::ACCESS_DENIED.
362 * @throws css::ucb::CommandAbortedException
363 * @throws css::uno::RuntimeException
364 * @throws css::uno::Exception
366 css::uno::Sequence< css::uno::Any >
367 setPropertyValues( const css::uno::Sequence< OUString >& rPropertyNames,
368 const css::uno::Sequence< css::uno::Any >& rValues );
371 // General command execution.
375 * This method can be used to execute any command supported by the
376 * content.
378 * @param rCommandName is the name of the command to execute.
379 * @param rCommandArgument is the argument for the command. Type and
380 * values of this parameter must correspond to the command
381 * specification.
382 * @return the result of the command according to its specification.
383 * @throws css::ucb::CommandAbortedException
384 * @throws css::uno::RuntimeException
385 * @throws css::uno::Exception
387 css::uno::Any
388 executeCommand( const OUString& rCommandName,
389 const css::uno::Any& rCommandArgument );
392 // Special commands.
396 * This methods gives access to the children of a folder content.
397 * Additionally, the result set returned provides efficient access to
398 * preselected property values of the children.
399 * Internally it executes the command "open" at the content.
401 * @param rPropertyNames is a sequence of names of properties for
402 * that the values should be accessible via the resultset
403 * returned by this method.
404 * @param eMode is a very simple filter for the children contained
405 * in the resultset.
406 * @return an implementation of the service
407 * com.cun.star.ucb.ContentResultSet, which can be used to
408 * get access to the children of a content.
409 * @throws css::ucb::CommandAbortedException
410 * @throws css::uno::RuntimeException
411 * @throws css::uno::Exception
413 css::uno::Reference< css::sdbc::XResultSet >
414 createCursor( const css::uno::Sequence< OUString >& rPropertyNames,
415 ResultSetInclude eMode = INCLUDE_FOLDERS_AND_DOCUMENTS );
417 * This methods gives access to the children of a folder content.
418 * Additionally, the result set returned provides efficient access to
419 * preselected property values of the children.
420 * Internally it executes the command "open" at the content.
422 * @param rPropertyNames is a sequence of names of properties for
423 * that the values should be accessible via the resultset
424 * returned by this method.
425 * @param eMode is a very simple filter for the children contained
426 * in the resultset.
427 * @return an implementation of the service
428 * com.cun.star.ucb.DynamicResultSet, which can be used to
429 * get access to the children of a content.
430 * @throws css::ucb::CommandAbortedException
431 * @throws css::uno::RuntimeException
432 * @throws css::uno::Exception
434 css::uno::Reference< css::ucb::XDynamicResultSet >
435 createDynamicCursor( const css::uno::Sequence< OUString >& rPropertyNames,
436 ResultSetInclude eMode = INCLUDE_FOLDERS_AND_DOCUMENTS );
438 /// @throws css::ucb::CommandAbortedException
439 /// @throws css::uno::RuntimeException
440 /// @throws css::uno::Exception
441 css::uno::Reference< css::sdbc::XResultSet >
442 createSortedCursor( const css::uno::Sequence< OUString >& rPropertyNames,
443 const css::uno::Sequence< css::ucb::NumberedSortingInfo >& rSortInfo,
444 const css::uno::Reference< css::ucb::XAnyCompareFactory >& rAnyCompareFactory,
445 ResultSetInclude eMode = INCLUDE_FOLDERS_AND_DOCUMENTS );
448 * This methods gives read access to the content stream of a content (i.e
449 * the content of a file located at the local file system).
450 * Internally it executes the command "open" at the content.
452 * @return an implementation of the interface XInputStream, which can
453 * be used to read the content's data.
454 * @throws css::ucb::CommandAbortedException
455 * @throws css::uno::RuntimeException
456 * @throws css::uno::Exception
458 css::uno::Reference< css::io::XInputStream >
459 openStream();
461 * This methods gives read access to the content stream of a content (i.e
462 * the content of a file located at the local file system).
463 * Internally it executes the command "open" at the content.
464 * The method requests opening without locking.
466 * @return an implementation of the interface XInputStream, which can
467 * be used to read the content's data.
468 * @throws css::ucb::CommandAbortedException
469 * @throws css::uno::RuntimeException
470 * @throws css::uno::Exception
472 css::uno::Reference< css::io::XInputStream >
473 openStreamNoLock();
476 * This methods gives read/write access to the content stream of a content (i.e
477 * the content of a file located at the local file system).
478 * Internally it executes the command "open" at the content.
480 * @return an implementation of the interface XStream, which can
481 * be used to read/write the content's data.
482 * @throws css::ucb::CommandAbortedException
483 * @throws css::uno::RuntimeException
484 * @throws css::uno::Exception
486 css::uno::Reference< css::io::XStream >
487 openWriteableStream();
489 * This methods gives read/write access to the content stream of a content (i.e
490 * the content of a file located at the local file system).
491 * Internally it executes the command "open" at the content.
492 * The method requests opening without locking.
494 * @return an implementation of the interface XStream, which can
495 * be used to read/write the content's data.
496 * @throws css::ucb::CommandAbortedException
497 * @throws css::uno::RuntimeException
498 * @throws css::uno::Exception
500 css::uno::Reference< css::io::XStream >
501 openWriteableStreamNoLock();
504 * This methods gives read access to the content stream of a content (i.e
505 * the content of a file located at the local file system).
506 * Internally it executes the command "open" at the content.
508 * @param rSink is the implementation of an XActiveDataSink interface,
509 * which shall be used by the content to deliver the data.
510 * @throws css::ucb::CommandAbortedException
511 * @throws css::uno::RuntimeException
512 * @throws css::uno::Exception
514 bool
515 openStream( const css::uno::Reference< css::io::XActiveDataSink >& rSink );
517 * This methods gives read access to the content stream of a content (i.e
518 * the content of a file located at the local file system).
519 * Internally it executes the command "open" at the content.
521 * @param rStream is the implementation of an XOutputStream interface,
522 * which shall be used by the content to deliver the data.
523 * @throws css::ucb::CommandAbortedException
524 * @throws css::uno::RuntimeException
525 * @throws css::uno::Exception
527 bool
528 openStream( const css::uno::Reference< css::io::XOutputStream >& rStream );
530 * This methods gives write access to the content stream of a content (i.e
531 * the content of a file located at the local file system).
532 * Internally it executes the command "insert" at the content.
534 * @param rStream is the implementation of an XInputStream interface,
535 * which contains the content data to write.
536 * @param bReplaceExisting specifies, whether any existing content data
537 * shall be overwritten.
538 * @throws css::ucb::CommandAbortedException
539 * @throws css::uno::RuntimeException
540 * @throws css::uno::Exception
542 void
543 writeStream( const css::uno::Reference< css::io::XInputStream >& rStream,
544 bool bReplaceExisting );
547 * This method returns the different types of contents this content
548 * can create.
550 * @return the content types or an empty sequence if no contents can be
551 * created by this content.
552 * @throws css::ucb::CommandAbortedException
553 * @throws css::uno::RuntimeException
554 * @throws css::uno::Exception
556 css::uno::Sequence< css::ucb::ContentInfo >
557 queryCreatableContentsInfo();
560 * This method creates, initializes and inserts ( commits ) a new content
561 * (i.e. it could be used to create a new file system folder).
562 * Internally this method does a
563 * XCommandProcessor::execute( "createNewContent", ... );
564 * XCommandProcessor::execute( "setPropertyValues", ... );
565 * XCommandProcessor::execute( "insert", ... ); calling sequence.
567 * @param rContentType is the type for the new UCB content. Each content
568 * provider implementation may introduce own types for its content
569 * objects (See queryCreatableContentsInfo()).
570 * @param rPropertyNames is a sequence of names of properties for that
571 * values are to set at the new content before it will be inserted
572 * ( committed ).
573 * The order of the names must correspond to the order of the
574 * property values.
575 * @param rPropertyValues is a sequence of property values that are to
576 * set at the new content before it will be inserted ( committed ).
577 * The order of the values must correspond to the order of the
578 * property names.
579 * @param rNewContent will be filled by the implementation of this method
580 * with the new content.
581 * @throws css::ucb::CommandAbortedException
582 * @throws css::uno::RuntimeException
583 * @throws css::uno::Exception
585 bool
586 insertNewContent( const OUString& rContentType,
587 const css::uno::Sequence< OUString >& rPropertyNames,
588 const css::uno::Sequence< css::uno::Any >& rPropertyValues,
589 Content& rNewContent );
591 * This method creates, initializes and inserts (commits) a new content
592 * inside this (the target folder) content. For example, it can be used to
593 * create a new file system file.
594 * Internally this method does a
595 * XCommandProcessor::execute( "createNewContent", ... );
596 * XCommandProcessor::execute( "setPropertyValues", ... );
597 * XCommandProcessor::execute( "insert", ... ); calling sequence.
599 * @param rContentType is the type for the new UCB content. Each content
600 * provider implementation may introduce own types for its content
601 * objects (See queryCreatableContentsInfo()).
602 * @param rPropertyNames is a sequence of names of properties for that
603 * values are to set at the new content before it will be inserted
604 * ( committed ).
605 * The order of the names must correspond to the order of the
606 * property values.
607 * @param rPropertyValues is a sequence of property values that are to
608 * set at the new content before it will be inserted ( committed ).
609 * The order of the values must correspond to the order of the
610 * property names.
611 * @param rStream is a stream containing the content data for the new
612 * content (i.e. the content of a file to create)
613 * @param rNewContent will be filled by the implementation of this method
614 * with the new content.
615 * @throws css::ucb::CommandAbortedException
616 * @throws css::uno::RuntimeException
617 * @throws css::uno::Exception
619 bool
620 insertNewContent( const OUString& rContentType,
621 const css::uno::Sequence< OUString >& rPropertyNames,
622 const css::uno::Sequence< css::uno::Any >& rPropertyValues,
623 const css::uno::Reference< css::io::XInputStream >& rStream,
624 Content& rNewContent );
627 * This method transfers (copies/moves) a content. It creates a new
628 * resource inside this (the target folder) content.
629 * The implementation is able to do cross-provider transfers (like copying
630 * a file from the local file system to a directory located on an HTTP
631 * server).
632 * Internally this method executes the command "globalTransfer" at the UCB.
634 * @param rSourceContent is the content that contains the data for the
635 * new UCB content.
636 * @param eOperation defines what shall be done with the source data
637 * ( COPY, MOVE, LINK ).
638 * @param rTitle contains a title for the new content. If this is an empty
639 * string, the new content will have the same title as the source
640 * content.
641 * @param rNameClashAction describes how the implementation shall behave
642 * in case a content with a clashing name exists in the target
643 * folder.
644 * NameClash::ERROR will abort the operation, NameClash::OVERWRITE
645 * will overwrite the clashing content and all its data,
646 * NameClash::RENAME will generate and supply a non-clashing title.
647 * @see com/sun/star/ucb/NameClash.idl
648 * @param rMimeType contains the MIME type of the document to write.
649 * @param bMajorVersion tells to create a new major version for checkin operations
650 * @param rCommentVersion contains the comment to use for checkin operations
651 * @param rResultURL is a hacky way to get the update URL after the operation in
652 * case there was a change (introduced for the checkin operation)
653 * @param rDocumentId is the document Id ( in case of CMIS ).
654 * @throws css::ucb::CommandAbortedException
655 * @throws css::uno::RuntimeException
656 * @throws css::uno::Exception
658 bool
659 transferContent( const Content& rSourceContent,
660 InsertOperation eOperation,
661 const OUString & rTitle,
662 const sal_Int32 nNameClashAction,
663 const OUString & rMimeType = OUString( ),
664 bool bMajorVersion = false,
665 const OUString & rCommentVersion = OUString( ),
666 OUString* pResultURL = nullptr,
667 const OUString & rDocumentId = OUString( ) );
670 * This method lock the resource.
672 * @throws css::ucb::CommandAbortedException
673 * @throws css::uno::RuntimeException
674 * @throws css::uno::Exception
676 void
677 lock();
680 * This method unlock the resource.
682 * @throws css::ucb::CommandAbortedException
683 * @throws css::uno::RuntimeException
684 * @throws css::uno::Exception
686 void
687 unlock();
689 // Required properties.
693 * This method returns the value of the content's property "IsFolder".
695 * @return true, if the content is a folder ( it can contain other
696 * UCB contents). false, otherwise.
697 * @throws css::ucb::CommandAbortedException
698 * @throws css::uno::RuntimeException
699 * @throws css::uno::Exception
701 bool
702 isFolder();
704 * This method returns the value of the content's property "IsDocument".
706 * @return true, if the content is a document ( it has a content stream ).
707 * false, otherwise.
708 * @throws css::ucb::CommandAbortedException
709 * @throws css::uno::RuntimeException
710 * @throws css::uno::Exception
712 bool
713 isDocument();
717 } /* namespace ucbhelper */
719 #endif /* ! INCLUDED_UCBHELPER_CONTENT_HXX */
721 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */