update credits
[LibreOffice.git] / include / ucbhelper / content.hxx
blob6f4a7b2d4316ced9660ea16ebe83899de36e2e24
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/uno/Reference.h>
24 #include <com/sun/star/uno/Sequence.h>
25 #include <ucbhelper/ucbhelperdllapi.h>
27 namespace com::sun::star::beans
29 class XPropertySetInfo;
32 namespace com::sun::star::io
34 class XActiveDataSink;
35 class XOutputStream;
36 class XInputStream;
37 class XStream;
40 namespace com::sun::star::sdbc
42 class XResultSet;
43 class XRow;
46 namespace com::sun::star::ucb
48 class XCommandEnvironment;
49 class XCommandInfo;
50 class XContent;
51 class XDynamicResultSet;
52 class XAnyCompareFactory;
53 struct ContentInfo;
54 struct NumberedSortingInfo;
57 namespace com::sun::star::uno
59 class XComponentContext;
62 namespace com::sun::star::uno
64 class Any;
67 namespace ucbhelper
69 /**
70 * These are the possible values for the parameter eMode of method
71 * ucbhelper::Content::createCursor.
73 enum ResultSetInclude
75 INCLUDE_FOLDERS_ONLY,
76 INCLUDE_DOCUMENTS_ONLY,
77 INCLUDE_FOLDERS_AND_DOCUMENTS
80 /**
81 * These are the possible values for the parameter eOperation of method
82 * ucbhelper::Content::insertNewContent.
84 enum class InsertOperation
86 Copy, // copy source data
87 Move, // move source data
88 Checkin // check-in source data
91 class Content_Impl;
93 /**
94 * This class simplifies access to UCB contents by providing a more
95 * convenient API for frequently used functionality then the "raw"
96 * UCB-API does.
98 class UCBHELPER_DLLPUBLIC Content final
100 rtl::Reference<Content_Impl> m_xImpl;
102 /// @throws css::ucb::CommandAbortedException
103 /// @throws css::uno::RuntimeException,
104 /// @throws css::uno::Exception
105 css::uno::Any createCursorAny(const css::uno::Sequence<OUString>& rPropertyNames,
106 ResultSetInclude eMode);
108 public:
110 * Constructor.
112 Content();
115 * Constructor.
117 * @param rURL is the URL of the content to create.
118 * @param rEnv is the environment to use for commands executed by the
119 * content. The command environment is used by the content
120 * implementation to interact with the client and to propagate
121 * errors.
122 * @throws css::ucb::ContentCreationException
123 * @throws css::uno::RuntimeException
125 Content(const OUString& rURL, const css::uno::Reference<css::ucb::XCommandEnvironment>& rEnv,
126 const css::uno::Reference<css::uno::XComponentContext>& rCtx);
128 * Constructor.
130 * @param rContent is the content object of the content to create.
131 * @param rEnv is the environment to use for commands executed by the
132 * content. The command environment is used by the content
133 * implementation to interact with the client and to propagate
134 * errors.
135 * @throws css::ucb::ContentCreationException
136 * @throws css::uno::RuntimeException
138 Content(const css::uno::Reference<css::ucb::XContent>& rContent,
139 const css::uno::Reference<css::ucb::XCommandEnvironment>& rEnv,
140 const css::uno::Reference<css::uno::XComponentContext>& rCtx);
142 * Copy Constructor.
144 * @param rContent is the content this content shall be a copy of.
146 Content(const Content& rOther);
149 * Move constructor.
151 Content(Content&& rOther) noexcept;
154 * Destructor.
156 ~Content();
159 * Assignment operator.
161 * @param rContent is the content this content shall be a copy of.
163 Content& operator=(const Content& rOther);
166 * Move assignment operator.
168 Content& operator=(Content&& rOther) noexcept;
171 * Constructor. This method should be used, if the exception thrown
172 * by the direct ctors of this class are to 'expensive' for your
173 * application
175 * @param rURL is the URL of the content to create.
176 * @param rEnv is the environment to use for commands executed by the
177 * content. The command environment is used by the content
178 * implementation to interact with the client and to propagate
179 * errors.
180 * @param rContent will be filled by this method with the content created.
181 * @return true, if the operation was successful - false, otherwise.
183 static bool create(const OUString& rURL,
184 const css::uno::Reference<css::ucb::XCommandEnvironment>& rEnv,
185 const css::uno::Reference<css::uno::XComponentContext>& rCtx,
186 Content& rContent);
188 // Direct access to UCB content.
191 * This method provides access to the "native" UCB content interface(s).
192 * This is useful in case the convenience methods provided by this
193 * class are insufficient for your needs. You may obtain all interfaces
194 * supported by the underlying UCB content by calling this method and
195 * after that doing a queryInterface call.
197 * @return the XContent interface of the underlying UCB content.
199 css::uno::Reference<css::ucb::XContent> get() const;
201 // Object identity.
204 * This method returns the URL of the content.
206 * @return the URL of the content.
208 const OUString& getURL() const;
210 // Command environment.
213 * This method returns the environment to use when executing commands.
215 * @return the command environment.
217 const css::uno::Reference<css::ucb::XCommandEnvironment>& getCommandEnvironment() const;
220 * This method sets a new command environment.
222 * @param xNewEnv is the new command environment.
224 void setCommandEnvironment(const css::uno::Reference<css::ucb::XCommandEnvironment>& xNewEnv);
226 // Access to supported commands/properties.
229 * This methods provides access to meta data of the commands supported
230 * by this content.
232 * @return an XCommandInfo interface implementation, which can be used
233 * to obtain meta data of the commands supported by this content.
234 * @throws css::ucb::CommandAbortedException
235 * @throws css::uno::RuntimeException
236 * @throws css::uno::Exception
238 css::uno::Reference<css::ucb::XCommandInfo> getCommands();
240 * This methods provides access to meta data of the properties supported
241 * by this content.
243 * @return an XPropertSetInfo interface implementation, which can be used
244 * to obtain meta data of the properties supported by this content.
245 * @throws css::ucb::CommandAbortedException
246 * @throws css::uno::RuntimeException
247 * @throws css::uno::Exception
249 css::uno::Reference<css::beans::XPropertySetInfo> getProperties();
251 // Access to property value(s).
254 * This method can be used to read a single property value.
256 * @param rPropertyName is the name of the property for that the value
257 * shall be obtained.
258 * @return the property value.
259 * @throws css::ucb::CommandAbortedException
260 * @throws css::uno::RuntimeException
261 * @throws css::uno::Exception
263 css::uno::Any getPropertyValue(const OUString& rPropertyName);
265 * This method can be used to set a single property value.
267 * @param rPropertyName is the name of the property for that the
268 * value shall be set.
269 * @return an any containing:
270 * - No value indicates, that the property value was set
271 * successfully.
272 * - css::beans::UnknownPropertyException indicates,
273 * that the property is not known to the content implementation.
274 * - css::beans::IllegalTypeException indicates, that
275 * the data type of the property value is not acceptable.
276 * - css::lang::IllegalAccessException indicates, that
277 * the property is constant.
278 * - css::lang::IllegalArgumentException indicates,
279 * that the property value is not acceptable. For instance,
280 * setting an empty title may be illegal.
281 * - Any other exception derived from
282 * css::uno::Exception indicates, that the value was
283 * not set successfully. For example, this can be a
284 * com::sun:star::ucb::InteractiveAugmentedIOException
285 * transporting the error code
286 * css::ucb::IOErrorCode::ACCESS_DENIED.
287 * @throws css::ucb::CommandAbortedException
288 * @throws css::uno::RuntimeException
289 * @throws css::uno::Exception
291 css::uno::Any setPropertyValue(const OUString& rPropertyName, const css::uno::Any& rValue);
293 * This method can be used to read multiple property values.
295 * @param rPropertyNames is a sequence of names of properties for
296 * that the values shall be obtained.
297 * @return the property values.
298 * @throws css::ucb::CommandAbortedException
299 * @throws css::uno::RuntimeException
300 * @throws css::uno::Exception
302 css::uno::Sequence<css::uno::Any>
303 getPropertyValues(const css::uno::Sequence<OUString>& rPropertyNames);
305 * This method can be used to read multiple property values.
307 * @param rPropertyNames is a sequence of names of properties for
308 * that the values shall be obtained.
309 * @return the property values.
310 * @throws css::ucb::CommandAbortedException
311 * @throws css::uno::RuntimeException
312 * @throws css::uno::Exception
314 css::uno::Reference<css::sdbc::XRow>
315 getPropertyValuesInterface(const css::uno::Sequence<OUString>& rPropertyNames);
318 * This method can be used to set multiple property values.
320 * @param rPropertyNames is a sequence of names of properties for
321 * that values shall be set.
322 * @return a sequence of any's which has exactly the same number
323 * of elements as the number of properties to set. Every
324 * sequence element contains the status for a property. The
325 * first sequence elements corresponds to the first element in
326 * the sequence of property names and so on.
328 * An any containing:
329 * - No value indicates, that the property value was set
330 * successfully.
331 * - css::beans::UnknownPropertyException indicates,
332 * that the property is not known to the content implementation.
333 * - css::beans::IllegalTypeException indicates, that
334 * the data type of the property value is not acceptable.
335 * - css::lang::IllegalAccessException indicates, that
336 * the property is constant.
337 * - css::lang::IllegalArgumentException indicates,
338 * that the property value is not acceptable. For instance,
339 * setting an empty title may be illegal.
340 * - Any other exception derived from
341 * css::uno::Exception indicates, that the value was
342 * not set successfully. For example, this can be a
343 * com::sun:star::ucb::InteractiveAugmentedIOException
344 * transporting the error code
345 * css::ucb::IOErrorCode::ACCESS_DENIED.
346 * @throws css::ucb::CommandAbortedException
347 * @throws css::uno::RuntimeException
348 * @throws css::uno::Exception
350 css::uno::Sequence<css::uno::Any>
351 setPropertyValues(const css::uno::Sequence<OUString>& rPropertyNames,
352 const css::uno::Sequence<css::uno::Any>& rValues);
354 // General command execution.
357 * This method can be used to execute any command supported by the
358 * content.
360 * @param rCommandName is the name of the command to execute.
361 * @param rCommandArgument is the argument for the command. Type and
362 * values of this parameter must correspond to the command
363 * specification.
364 * @return the result of the command according to its specification.
365 * @throws css::ucb::CommandAbortedException
366 * @throws css::uno::RuntimeException
367 * @throws css::uno::Exception
369 css::uno::Any executeCommand(const OUString& rCommandName,
370 const css::uno::Any& rCommandArgument);
372 // Special commands.
375 * This methods gives access to the children of a folder content.
376 * Additionally, the result set returned provides efficient access to
377 * preselected property values of the children.
378 * Internally it executes the command "open" at the content.
380 * @param rPropertyNames is a sequence of names of properties for
381 * that the values should be accessible via the resultset
382 * returned by this method.
383 * @param eMode is a very simple filter for the children contained
384 * in the resultset.
385 * @return an implementation of the service
386 * com.cun.star.ucb.ContentResultSet, which can be used to
387 * get access to the children of a content.
388 * @throws css::ucb::CommandAbortedException
389 * @throws css::uno::RuntimeException
390 * @throws css::uno::Exception
392 css::uno::Reference<css::sdbc::XResultSet>
393 createCursor(const css::uno::Sequence<OUString>& rPropertyNames,
394 ResultSetInclude eMode = INCLUDE_FOLDERS_AND_DOCUMENTS);
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.DynamicResultSet, 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::ucb::XDynamicResultSet>
414 createDynamicCursor(const css::uno::Sequence<OUString>& rPropertyNames,
415 ResultSetInclude eMode = INCLUDE_FOLDERS_AND_DOCUMENTS);
417 /// @throws css::ucb::CommandAbortedException
418 /// @throws css::uno::RuntimeException
419 /// @throws css::uno::Exception
420 css::uno::Reference<css::sdbc::XResultSet>
421 createSortedCursor(const css::uno::Sequence<OUString>& rPropertyNames,
422 const css::uno::Sequence<css::ucb::NumberedSortingInfo>& rSortInfo,
423 const css::uno::Reference<css::ucb::XAnyCompareFactory>& rAnyCompareFactory,
424 ResultSetInclude eMode = INCLUDE_FOLDERS_AND_DOCUMENTS);
427 * This methods gives read access to the content stream of a content (i.e
428 * the content of a file located at the local file system).
429 * Internally it executes the command "open" at the content.
431 * @return an implementation of the interface XInputStream, which can
432 * be used to read the content's data.
433 * @throws css::ucb::CommandAbortedException
434 * @throws css::uno::RuntimeException
435 * @throws css::uno::Exception
437 css::uno::Reference<css::io::XInputStream> openStream();
439 * This methods gives read access to the content stream of a content (i.e
440 * the content of a file located at the local file system).
441 * Internally it executes the command "open" at the content.
442 * The method requests opening without locking.
444 * @return an implementation of the interface XInputStream, which can
445 * be used to read the content's data.
446 * @throws css::ucb::CommandAbortedException
447 * @throws css::uno::RuntimeException
448 * @throws css::uno::Exception
450 css::uno::Reference<css::io::XInputStream> openStreamNoLock();
453 * This methods gives read/write access to the content stream of a content (i.e
454 * the content of a file located at the local file system).
455 * Internally it executes the command "open" at the content.
457 * @return an implementation of the interface XStream, which can
458 * be used to read/write the content's data.
459 * @throws css::ucb::CommandAbortedException
460 * @throws css::uno::RuntimeException
461 * @throws css::uno::Exception
463 css::uno::Reference<css::io::XStream> openWriteableStream();
465 * This methods gives read/write access to the content stream of a content (i.e
466 * the content of a file located at the local file system).
467 * Internally it executes the command "open" at the content.
468 * The method requests opening without locking.
470 * @return an implementation of the interface XStream, which can
471 * be used to read/write the content's data.
472 * @throws css::ucb::CommandAbortedException
473 * @throws css::uno::RuntimeException
474 * @throws css::uno::Exception
476 css::uno::Reference<css::io::XStream> openWriteableStreamNoLock();
479 * This methods gives read access to the content stream of a content (i.e
480 * the content of a file located at the local file system).
481 * Internally it executes the command "open" at the content.
483 * @param rSink is the implementation of an XActiveDataSink interface,
484 * which shall be used by the content to deliver the data.
485 * @throws css::ucb::CommandAbortedException
486 * @throws css::uno::RuntimeException
487 * @throws css::uno::Exception
489 bool openStream(const css::uno::Reference<css::io::XActiveDataSink>& rSink);
491 * This methods gives read access to the content stream of a content (i.e
492 * the content of a file located at the local file system).
493 * Internally it executes the command "open" at the content.
495 * @param rStream is the implementation of an XOutputStream interface,
496 * which shall be used by the content to deliver the data.
497 * @throws css::ucb::CommandAbortedException
498 * @throws css::uno::RuntimeException
499 * @throws css::uno::Exception
501 bool openStream(const css::uno::Reference<css::io::XOutputStream>& rStream);
503 * This methods gives write access to the content stream of a content (i.e
504 * the content of a file located at the local file system).
505 * Internally it executes the command "insert" at the content.
507 * @param rStream is the implementation of an XInputStream interface,
508 * which contains the content data to write.
509 * @param bReplaceExisting specifies, whether any existing content data
510 * shall be overwritten.
511 * @throws css::ucb::CommandAbortedException
512 * @throws css::uno::RuntimeException
513 * @throws css::uno::Exception
515 void writeStream(const css::uno::Reference<css::io::XInputStream>& rStream,
516 bool bReplaceExisting);
519 * This method returns the different types of contents this content
520 * can create.
522 * @return the content types or an empty sequence if no contents can be
523 * created by this content.
524 * @throws css::ucb::CommandAbortedException
525 * @throws css::uno::RuntimeException
526 * @throws css::uno::Exception
528 css::uno::Sequence<css::ucb::ContentInfo> queryCreatableContentsInfo();
531 * This method creates, initializes and inserts ( commits ) a new content
532 * (i.e. it could be used to create a new file system folder).
533 * Internally this method does a
534 * XCommandProcessor::execute( "createNewContent", ... );
535 * XCommandProcessor::execute( "setPropertyValues", ... );
536 * XCommandProcessor::execute( "insert", ... ); calling sequence.
538 * @param rContentType is the type for the new UCB content. Each content
539 * provider implementation may introduce own types for its content
540 * objects (See queryCreatableContentsInfo()).
541 * @param rPropertyNames is a sequence of names of properties for that
542 * values are to set at the new content before it will be inserted
543 * ( committed ).
544 * The order of the names must correspond to the order of the
545 * property values.
546 * @param rPropertyValues is a sequence of property values that are to
547 * set at the new content before it will be inserted ( committed ).
548 * The order of the values must correspond to the order of the
549 * property names.
550 * @param rNewContent will be filled by the implementation of this method
551 * with the new content.
552 * @throws css::ucb::CommandAbortedException
553 * @throws css::uno::RuntimeException
554 * @throws css::uno::Exception
556 bool insertNewContent(const OUString& rContentType,
557 const css::uno::Sequence<OUString>& rPropertyNames,
558 const css::uno::Sequence<css::uno::Any>& rPropertyValues,
559 Content& rNewContent);
561 * This method creates, initializes and inserts (commits) a new content
562 * inside this (the target folder) content. For example, it can be used to
563 * create a new file system file.
564 * Internally this method does a
565 * XCommandProcessor::execute( "createNewContent", ... );
566 * XCommandProcessor::execute( "setPropertyValues", ... );
567 * XCommandProcessor::execute( "insert", ... ); calling sequence.
569 * @param rContentType is the type for the new UCB content. Each content
570 * provider implementation may introduce own types for its content
571 * objects (See queryCreatableContentsInfo()).
572 * @param rPropertyNames is a sequence of names of properties for that
573 * values are to set at the new content before it will be inserted
574 * ( committed ).
575 * The order of the names must correspond to the order of the
576 * property values.
577 * @param rPropertyValues is a sequence of property values that are to
578 * set at the new content before it will be inserted ( committed ).
579 * The order of the values must correspond to the order of the
580 * property names.
581 * @param rStream is a stream containing the content data for the new
582 * content (i.e. the content of a file to create)
583 * @param rNewContent will be filled by the implementation of this method
584 * with the new content.
585 * @throws css::ucb::CommandAbortedException
586 * @throws css::uno::RuntimeException
587 * @throws css::uno::Exception
589 bool insertNewContent(const OUString& rContentType,
590 const css::uno::Sequence<OUString>& rPropertyNames,
591 const css::uno::Sequence<css::uno::Any>& rPropertyValues,
592 const css::uno::Reference<css::io::XInputStream>& rStream,
593 Content& rNewContent);
596 * This method transfers (copies/moves) a content. It creates a new
597 * resource inside this (the target folder) content.
598 * The implementation is able to do cross-provider transfers (like copying
599 * a file from the local file system to a directory located on an HTTP
600 * server).
601 * Internally this method executes the command "globalTransfer" at the UCB.
603 * @param rSourceContent is the content that contains the data for the
604 * new UCB content.
605 * @param eOperation defines what shall be done with the source data
606 * ( COPY, MOVE, LINK ).
607 * @param rTitle contains a title for the new content. If this is an empty
608 * string, the new content will have the same title as the source
609 * content.
610 * @param rNameClashAction describes how the implementation shall behave
611 * in case a content with a clashing name exists in the target
612 * folder.
613 * NameClash::ERROR will abort the operation, NameClash::OVERWRITE
614 * will overwrite the clashing content and all its data,
615 * NameClash::RENAME will generate and supply a non-clashing title.
616 * @see com/sun/star/ucb/NameClash.idl
617 * @param rMimeType contains the MIME type of the document to write.
618 * @param bMajorVersion tells to create a new major version for checkin operations
619 * @param rCommentVersion contains the comment to use for checkin operations
620 * @param rResultURL is a hacky way to get the update URL after the operation in
621 * case there was a change (introduced for the checkin operation)
622 * @param rDocumentId is the document Id ( in case of CMIS ).
623 * @throws css::ucb::CommandAbortedException
624 * @throws css::uno::RuntimeException
625 * @throws css::uno::Exception
627 void transferContent(const Content& rSourceContent, InsertOperation eOperation,
628 const OUString& rTitle, const sal_Int32 nNameClashAction,
629 const OUString& rMimeType = OUString(), bool bMajorVersion = false,
630 const OUString& rCommentVersion = OUString(),
631 OUString* pResultURL = nullptr,
632 const OUString& rDocumentId = OUString()) const;
635 * This method lock the resource.
637 * @throws css::ucb::CommandAbortedException
638 * @throws css::uno::RuntimeException
639 * @throws css::uno::Exception
641 void lock();
644 * This method unlock the resource.
646 * @throws css::ucb::CommandAbortedException
647 * @throws css::uno::RuntimeException
648 * @throws css::uno::Exception
650 void unlock();
652 // Required properties.
655 * This method returns the value of the content's property "IsFolder".
657 * @return true, if the content is a folder ( it can contain other
658 * UCB contents). false, otherwise.
659 * @throws css::ucb::CommandAbortedException
660 * @throws css::uno::RuntimeException
661 * @throws css::uno::Exception
663 bool isFolder();
665 * This method returns the value of the content's property "IsDocument".
667 * @return true, if the content is a document ( it has a content stream ).
668 * false, otherwise.
669 * @throws css::ucb::CommandAbortedException
670 * @throws css::uno::RuntimeException
671 * @throws css::uno::Exception
673 bool isDocument();
676 } /* namespace ucbhelper */
678 #endif /* ! INCLUDED_UCBHELPER_CONTENT_HXX */
680 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */