build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / include / ucbhelper / content.hxx
blob2d1eb030b261da1e3ea4a391625aeda279f4437b
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 InsertOperation
81 InsertOperation_COPY, // copy source data
82 InsertOperation_MOVE, // move source data
83 InsertOperation_LINK, // create a link to source
84 InsertOperation_CHECKIN // check-in source data
88 class Content_Impl;
90 /**
91 * This class simplifies access to UCB contents by providing a more
92 * convenient API for frequently used functionality then the "raw"
93 * UCB-API does.
95 class UCBHELPER_DLLPUBLIC Content
97 rtl::Reference< Content_Impl > m_xImpl;
99 protected:
100 css::uno::Any createCursorAny( const css::uno::Sequence< OUString >& rPropertyNames,
101 ResultSetInclude eMode )
102 throw( css::ucb::CommandAbortedException,
103 css::uno::RuntimeException,
104 css::uno::Exception );
106 public:
108 * Constructor.
110 Content();
113 * Constructor.
115 * @param rURL is the URL of the content to create.
116 * @param rEnv is the environment to use for commands executed by the
117 * content. The command environment is used by the content
118 * implementation to interact with the client and to propagate
119 * errors.
121 Content( const OUString& rURL,
122 const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnv,
123 const css::uno::Reference< css::uno::XComponentContext >& rCtx )
124 throw ( css::ucb::ContentCreationException,
125 css::uno::RuntimeException );
127 * Constructor.
129 * @param rContent is the content object of the content to create.
130 * @param rEnv is the environment to use for commands executed by the
131 * content. The command environment is used by the content
132 * implementation to interact with the client and to propagate
133 * errors.
135 Content( const css::uno::Reference< css::ucb::XContent >& rContent,
136 const css::uno::Reference< css::ucb::XCommandEnvironment >& rEnv,
137 const css::uno::Reference< css::uno::XComponentContext >& rCtx )
138 throw ( css::ucb::ContentCreationException,
139 css::uno::RuntimeException );
141 * Copy Constructor.
143 * @param rContent is the content this content shall be a copy of.
145 Content( const Content& rOther );
148 * Move constructor.
150 Content( Content&& rOther );
153 * Destructor.
155 ~Content();
158 * Assignment operator.
160 * @param rContent is the content this content shall be a copy of.
162 Content& operator=( const Content& rOther );
165 * Move assignment operator.
167 Content& operator=( Content&& rOther );
170 * Constructor. This method should be used, if the exception thrown
171 * by the direct ctors of this class are to 'expensive' for your
172 * application
174 * @param rURL is the URL of the content to create.
175 * @param rEnv is the environment to use for commands executed by the
176 * content. The command environment is used by the content
177 * implementation to interact with the client and to propagate
178 * errors.
179 * @param rContent will be filled by this method with the content created.
180 * @return true, if the operation was successful - false, otherwise.
182 static bool
183 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 );
189 // Direct access to UCB content.
193 * This method provides access to the "native" UCB content interface(s).
194 * This is useful in case the convenience methods provided by this
195 * class are insufficient for your needs. You may obtain all interfaces
196 * supported by the underlying UCB content by calling this method and
197 * after that doing a queryInterface call.
199 * @return the XContent interface of the underlying UCB content.
201 css::uno::Reference< css::ucb::XContent > get() const;
204 // Object identity.
208 * This method returns the URL of the content.
210 * @return the URL of the content.
212 const OUString& getURL() const;
215 // Command environment.
219 * This method returns the environment to use when executing commands.
221 * @return the command environment.
223 const css::uno::Reference< css::ucb::XCommandEnvironment >&
224 getCommandEnvironment() const;
227 * This method sets a new command environment.
229 * @param xNewEnv is the new command environment.
231 void setCommandEnvironment(
232 const css::uno::Reference< css::ucb::XCommandEnvironment >& xNewEnv );
235 // Access to supported commands/properties.
239 * This methods provides access to meta data of the commands supported
240 * by this content.
242 * @return an XCommandInfo interface implementation, which can be used
243 * to obtain meta data of the commands supported by this content.
245 css::uno::Reference< css::ucb::XCommandInfo >
246 getCommands()
247 throw( css::ucb::CommandAbortedException,
248 css::uno::RuntimeException,
249 css::uno::Exception );
251 * This methods provides access to meta data of the properties supported
252 * by this content.
254 * @return an XPropertSetInfo interface implementation, which can be used
255 * to obtain meta data of the properties supported by this content.
257 css::uno::Reference< css::beans::XPropertySetInfo >
258 getProperties()
259 throw( css::ucb::CommandAbortedException,
260 css::uno::RuntimeException,
261 css::uno::Exception );
264 // Access to property value(s).
268 * This method can be used to read a single property value.
270 * @param rPropertyName is the name of the property for that the value
271 * shall be obtained.
272 * @return the property value.
274 css::uno::Any
275 getPropertyValue( const OUString& rPropertyName )
276 throw( css::ucb::CommandAbortedException,
277 css::uno::RuntimeException,
278 css::uno::Exception );
280 * This method can be used to set a single property value.
282 * @param rPropertyName is the name of the property for that the
283 * value shall be set.
284 * @return an any containing:
285 * - No value indicates, that the property value was set
286 * successfully.
287 * - css::beans::UnknownPropertyException indicates,
288 * that the property is not known to the content implementation.
289 * - css::beans::IllegalTypeException indicates, that
290 * the data type of the property value is not acceptable.
291 * - css::lang::IllegalAccessException indicates, that
292 * the property is constant.
293 * - css::lang::IllegalArgumentException indicates,
294 * that the property value is not acceptable. For instance,
295 * setting an empty title may be illegal.
296 * - Any other exception derived from
297 * css::uno::Exception indicates, that the value was
298 * not set successfully. For example, this can be a
299 * com::sun:star::ucb::InteractiveAugmentedIOException
300 * transporting the error code
301 * css::ucb::IOErrorCode::ACCESS_DENIED.
303 css::uno::Any
304 setPropertyValue( const OUString& rPropertyName,
305 const css::uno::Any& rValue )
306 throw( css::ucb::CommandAbortedException,
307 css::uno::RuntimeException,
308 css::uno::Exception );
310 * This method can be used to read multiple property values.
312 * @param rPropertyNames is a sequence of names of properties for
313 * that the values shall be obtained.
314 * @return the property values.
316 css::uno::Sequence< css::uno::Any >
317 getPropertyValues( const css::uno::Sequence< OUString >& rPropertyNames )
318 throw( css::ucb::CommandAbortedException,
319 css::uno::RuntimeException,
320 css::uno::Exception );
322 * This method can be used to read multiple property values.
324 * @param rPropertyNames is a sequence of names of properties for
325 * that the values shall be obtained.
326 * @return the property values.
328 css::uno::Reference< css::sdbc::XRow >
329 getPropertyValuesInterface( const css::uno::Sequence< OUString >& rPropertyNames )
330 throw( css::ucb::CommandAbortedException,
331 css::uno::RuntimeException,
332 css::uno::Exception );
335 * This method can be used to set multiple property values.
337 * @param rPropertyNames is a sequence of names of properties for
338 * that values shall be set.
339 * @return a sequence of any's which has exactly the same number
340 * of elements as the number of properties to set. Every
341 * sequence element contains the status for a property. The
342 * first sequence elements corresponds to the first element in
343 * the sequence of property names and so on.
345 * An any containing:
346 * - No value indicates, that the property value was set
347 * successfully.
348 * - css::beans::UnknownPropertyException indicates,
349 * that the property is not known to the content implementation.
350 * - css::beans::IllegalTypeException indicates, that
351 * the data type of the property value is not acceptable.
352 * - css::lang::IllegalAccessException indicates, that
353 * the property is constant.
354 * - css::lang::IllegalArgumentException indicates,
355 * that the property value is not acceptable. For instance,
356 * setting an empty title may be illegal.
357 * - Any other exception derived from
358 * css::uno::Exception indicates, that the value was
359 * not set successfully. For example, this can be a
360 * com::sun:star::ucb::InteractiveAugmentedIOException
361 * transporting the error code
362 * css::ucb::IOErrorCode::ACCESS_DENIED.
364 css::uno::Sequence< css::uno::Any >
365 setPropertyValues( const css::uno::Sequence< OUString >& rPropertyNames,
366 const css::uno::Sequence< css::uno::Any >& rValues )
367 throw( css::ucb::CommandAbortedException,
368 css::uno::RuntimeException,
369 css::uno::Exception );
372 // General command execution.
376 * This method can be used to execute any command supported by the
377 * content.
379 * @param rCommandName is the name of the command to execute.
380 * @param rCommandArgument is the argument for the command. Type and
381 * values of this parameter must correspond to the command
382 * specification.
383 * @return the result of the command according to its specification.
385 css::uno::Any
386 executeCommand( const OUString& rCommandName,
387 const css::uno::Any& rCommandArgument )
388 throw( css::ucb::CommandAbortedException,
389 css::uno::RuntimeException,
390 css::uno::Exception );
393 // Special commands.
397 * This methods gives access to the children of a folder content.
398 * Additionally, the result set returned provides efficient access to
399 * preselected property values of the children.
400 * Internally it executes the command "open" at the content.
402 * @param rPropertyNames is a sequence of names of properties for
403 * that the values should be accessible via the resultset
404 * returned by this method.
405 * @param eMode is a very simple filter for the children contained
406 * in the resultset.
407 * @return an implementation of the service
408 * com.cun.star.ucb.ContentResultSet, which can be used to
409 * get access to the children of a content.
411 css::uno::Reference< css::sdbc::XResultSet >
412 createCursor( const css::uno::Sequence< OUString >& rPropertyNames,
413 ResultSetInclude eMode = INCLUDE_FOLDERS_AND_DOCUMENTS )
414 throw( css::ucb::CommandAbortedException,
415 css::uno::RuntimeException,
416 css::uno::Exception );
418 * This methods gives access to the children of a folder content.
419 * Additionally, the result set returned provides efficient access to
420 * preselected property values of the children.
421 * Internally it executes the command "open" at the content.
423 * @param rPropertyNames is a sequence of names of properties for
424 * that the values should be accessible via the resultset
425 * returned by this method.
426 * @param eMode is a very simple filter for the children contained
427 * in the resultset.
428 * @return an implementation of the service
429 * com.cun.star.ucb.DynamicResultSet, which can be used to
430 * get access to the children of a content.
432 css::uno::Reference< css::ucb::XDynamicResultSet >
433 createDynamicCursor( const css::uno::Sequence< OUString >& rPropertyNames,
434 ResultSetInclude eMode = INCLUDE_FOLDERS_AND_DOCUMENTS )
435 throw( css::ucb::CommandAbortedException,
436 css::uno::RuntimeException,
437 css::uno::Exception );
439 css::uno::Reference< css::sdbc::XResultSet >
440 createSortedCursor( const css::uno::Sequence< OUString >& rPropertyNames,
441 const css::uno::Sequence< css::ucb::NumberedSortingInfo >& rSortInfo,
442 const css::uno::Reference< css::ucb::XAnyCompareFactory >& rAnyCompareFactory,
443 ResultSetInclude eMode = INCLUDE_FOLDERS_AND_DOCUMENTS )
444 throw( css::ucb::CommandAbortedException,
445 css::uno::RuntimeException,
446 css::uno::Exception );
449 * This methods gives read access to the content stream of a content (i.e
450 * the content of a file located at the local file system).
451 * Internally it executes the command "open" at the content.
453 * @return an implementation of the interface XInputStream, which can
454 * be used to read the content's data.
456 css::uno::Reference< css::io::XInputStream >
457 openStream()
458 throw( css::ucb::CommandAbortedException,
459 css::uno::RuntimeException,
460 css::uno::Exception );
462 * This methods gives read access to the content stream of a content (i.e
463 * the content of a file located at the local file system).
464 * Internally it executes the command "open" at the content.
465 * The method requests opening without locking.
467 * @return an implementation of the interface XInputStream, which can
468 * be used to read the content's data.
470 css::uno::Reference< css::io::XInputStream >
471 openStreamNoLock()
472 throw( css::ucb::CommandAbortedException,
473 css::uno::RuntimeException,
474 css::uno::Exception );
477 * This methods gives read/write access to the content stream of a content (i.e
478 * the content of a file located at the local file system).
479 * Internally it executes the command "open" at the content.
481 * @return an implementation of the interface XStream, which can
482 * be used to read/write the content's data.
484 css::uno::Reference< css::io::XStream >
485 openWriteableStream()
486 throw( css::ucb::CommandAbortedException,
487 css::uno::RuntimeException,
488 css::uno::Exception );
490 * This methods gives read/write access to the content stream of a content (i.e
491 * the content of a file located at the local file system).
492 * Internally it executes the command "open" at the content.
493 * The method requests opening without locking.
495 * @return an implementation of the interface XStream, which can
496 * be used to read/write the content's data.
498 css::uno::Reference< css::io::XStream >
499 openWriteableStreamNoLock()
500 throw( css::ucb::CommandAbortedException,
501 css::uno::RuntimeException,
502 css::uno::Exception );
505 * This methods gives read access to the content stream of a content (i.e
506 * the content of a file located at the local file system).
507 * Internally it executes the command "open" at the content.
509 * @param rSink is the implementation of an XActiveDataSink interface,
510 * which shall be used by the content to deliver the data.
512 bool
513 openStream( const css::uno::Reference< css::io::XActiveDataSink >& rSink )
514 throw( css::ucb::CommandAbortedException,
515 css::uno::RuntimeException,
516 css::uno::Exception );
518 * This methods gives read access to the content stream of a content (i.e
519 * the content of a file located at the local file system).
520 * Internally it executes the command "open" at the content.
522 * @param rStream is the implementation of an XOutputStream interface,
523 * which shall be used by the content to deliver the data.
525 bool
526 openStream( const css::uno::Reference< css::io::XOutputStream >& rStream )
527 throw( css::ucb::CommandAbortedException,
528 css::uno::RuntimeException,
529 css::uno::Exception );
531 * This methods gives write access to the content stream of a content (i.e
532 * the content of a file located at the local file system).
533 * Internally it executes the command "insert" at the content.
535 * @param rStream is the implementation of an XInputStream interface,
536 * which contains the content data to write.
537 * @param bReplaceExisting specifies, whether any existing content data
538 * shall be overwritten.
540 void
541 writeStream( const css::uno::Reference< css::io::XInputStream >& rStream,
542 bool bReplaceExisting )
543 throw( css::ucb::CommandAbortedException,
544 css::uno::RuntimeException,
545 css::uno::Exception );
548 * This method returns the different types of contents this content
549 * can create.
551 * @return the content types or an empty sequence if no contents can be
552 * created by this content.
554 css::uno::Sequence< css::ucb::ContentInfo >
555 queryCreatableContentsInfo()
556 throw( css::ucb::CommandAbortedException,
557 css::uno::RuntimeException,
558 css::uno::Exception );
561 * This method creates, initializes and inserts ( commits ) a new content
562 * (i.e. it could be used to create a new file system folder).
563 * Internally this method does a
564 * XCommandProcessor::execute( "createNewContent", ... );
565 * XCommandProcessor::execute( "setPropertyValues", ... );
566 * XCommandProcessor::execute( "insert", ... ); calling sequence.
568 * @param rContentType is the type for the new UCB content. Each content
569 * provider implementation may introduce own types for its content
570 * objects (See queryCreatableContentsInfo()).
571 * @param rPropertyNames is a sequence of names of properties for that
572 * values are to set at the new content before it will be inserted
573 * ( committed ).
574 * The order of the names must correspond to the order of the
575 * property values.
576 * @param rPropertyValues is a sequence of property values that are to
577 * set at the new content before it will be inserted ( committed ).
578 * The order of the values must correspond to the order of the
579 * property names.
580 * @param rNewContent will be filled by the implementation of this method
581 * with the new content.
583 bool
584 insertNewContent( const OUString& rContentType,
585 const css::uno::Sequence< OUString >& rPropertyNames,
586 const css::uno::Sequence< css::uno::Any >& rPropertyValues,
587 Content& rNewContent )
588 throw( css::ucb::CommandAbortedException,
589 css::uno::RuntimeException,
590 css::uno::Exception );
592 * This method creates, initializes and inserts (commits) a new content
593 * inside this (the target folder) content. For example, it can be used to
594 * create a new file system file.
595 * Internally this method does a
596 * XCommandProcessor::execute( "createNewContent", ... );
597 * XCommandProcessor::execute( "setPropertyValues", ... );
598 * XCommandProcessor::execute( "insert", ... ); calling sequence.
600 * @param rContentType is the type for the new UCB content. Each content
601 * provider implementation may introduce own types for its content
602 * objects (See queryCreatableContentsInfo()).
603 * @param rPropertyNames is a sequence of names of properties for that
604 * values are to set at the new content before it will be inserted
605 * ( committed ).
606 * The order of the names must correspond to the order of the
607 * property values.
608 * @param rPropertyValues is a sequence of property values that are to
609 * set at the new content before it will be inserted ( committed ).
610 * The order of the values must correspond to the order of the
611 * property names.
612 * @param rStream is a stream containing the content data for the new
613 * content (i.e. the content of a file to create)
614 * @param rNewContent will be filled by the implementation of this method
615 * with the new content.
617 bool
618 insertNewContent( const OUString& rContentType,
619 const css::uno::Sequence< OUString >& rPropertyNames,
620 const css::uno::Sequence< css::uno::Any >& rPropertyValues,
621 const css::uno::Reference< css::io::XInputStream >& rStream,
622 Content& rNewContent )
623 throw( css::ucb::CommandAbortedException,
624 css::uno::RuntimeException,
625 css::uno::Exception );
628 * This method transfers (copies/moves) a content. It creates a new
629 * resource inside this (the target folder) content.
630 * The implementation is able to do cross-provider transfers (like copying
631 * a file from the local file system to a directory located on an HTTP
632 * server).
633 * Internally this method executes the command "globalTransfer" at the UCB.
635 * @param rSourceContent is the content that contains the data for the
636 * new UCB content.
637 * @param eOperation defines what shall be done with the source data
638 * ( COPY, MOVE, LINK ).
639 * @param rTitle contains a title for the new content. If this is an empty
640 * string, the new content will have the same title as the source
641 * content.
642 * @param rNameClashAction describes how the implementation shall behave
643 * in case a content with a clashing name exists in the target
644 * folder.
645 * NameClash::ERROR will abort the operation, NameClash::OVERWRITE
646 * will overwrite the clashing content and all its data,
647 * NameClash::RENAME will generate and supply a non-clashing title.
648 * @see com/sun/star/ucb/NameClash.idl
649 * @param rMimeType contains the MIME type of the document to write.
650 * @param bMajorVersion tells to create a new major version for checkin operations
651 * @param rCommentVersion contains the comment to use for checkin operations
652 * @param rResultURL is a hacky way to get the update URL after the operation in
653 * case there was a change (introduced for the checkin operation)
654 * @param rDocumentId is the document Id ( in case of CMIS ).
656 bool
657 transferContent( const Content& rSourceContent,
658 InsertOperation eOperation,
659 const OUString & rTitle,
660 const sal_Int32 nNameClashAction,
661 const OUString & rMimeType = OUString( ),
662 bool bMajorVersion = false,
663 const OUString & rCommentVersion = OUString( ),
664 OUString* pResultURL = nullptr,
665 const OUString & rDocumentId = OUString( ) )
666 throw( css::ucb::CommandAbortedException,
667 css::uno::RuntimeException,
668 css::uno::Exception );
671 * This method lock the resource.
674 void
675 lock()
676 throw( css::ucb::CommandAbortedException,
677 css::uno::RuntimeException,
678 css::uno::Exception );
681 * This method unlock the resource.
684 void
685 unlock()
686 throw( css::ucb::CommandAbortedException,
687 css::uno::RuntimeException,
688 css::uno::Exception );
690 // Required properties.
694 * This method returns the value of the content's property "IsFolder".
696 * @return true, if the content is a folder ( it can contain other
697 * UCB contents). false, otherwise.
699 bool
700 isFolder()
701 throw( css::ucb::CommandAbortedException,
702 css::uno::RuntimeException,
703 css::uno::Exception );
705 * This method returns the value of the content's property "IsDocument".
707 * @return true, if the content is a document ( it has a content stream ).
708 * false, otherwise.
710 bool
711 isDocument()
712 throw( css::ucb::CommandAbortedException,
713 css::uno::RuntimeException,
714 css::uno::Exception );
718 } /* namespace ucbhelper */
720 #endif /* ! INCLUDED_UCBHELPER_CONTENT_HXX */
722 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */