1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #ifndef INCLUDED_UCB_SOURCE_UCP_FILE_SHELL_HXX
22 #define INCLUDED_UCB_SOURCE_UCP_FILE_SHELL_HXX
25 #include <cppuhelper/weak.hxx>
26 #include <cppuhelper/interfacecontainer.hxx>
27 #include <cppuhelper/typeprovider.hxx>
28 #include <osl/file.hxx>
30 #include "osl/mutex.hxx"
31 #include <rtl/ustring.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
33 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
34 #include <com/sun/star/ucb/XCommandInfo.hpp>
35 #include <com/sun/star/beans/Property.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/io/XStream.hpp>
38 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
39 #include <com/sun/star/ucb/XCommandProcessor.hpp>
40 #include <com/sun/star/io/XOutputStream.hpp>
41 #include <com/sun/star/io/XInputStream.hpp>
42 #include <com/sun/star/beans/XPropertySetInfo.hpp>
43 #include <com/sun/star/beans/XPropertiesChangeNotifier.hpp>
44 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
45 #include <com/sun/star/sdbc/XRow.hpp>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <com/sun/star/uno/XComponentContext.hpp>
48 #include <com/sun/star/ucb/XContentProvider.hpp>
49 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
50 #include <com/sun/star/beans/XPropertyContainer.hpp>
51 #include <com/sun/star/beans/XPropertyAccess.hpp>
52 #include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp>
53 #include <com/sun/star/ucb/TransferInfo.hpp>
54 #include <com/sun/star/ucb/ContentInfo.hpp>
55 #include "filtask.hxx"
58 #include <unordered_map>
59 #include <unordered_set>
62 namespace fileaccess
{
65 class XPropertySetInfo_impl
;
66 class XCommandInfo_impl
;
67 class XResultSet_impl
;
71 : public virtual TaskManager
73 friend class XPropertySetInfo_impl
;
74 friend class XResultSet_impl
;
75 friend class XCommandInfo_impl
;
82 OUString PropertyName
;
85 com::sun::star::uno::Type Typ
; // Duplicates information in Value
86 com::sun::star::uno::Any Value
;
87 com::sun::star::beans::PropertyState State
;
91 MyProperty( const OUString
& __PropertyName
);
92 MyProperty( const bool& __isNative
,
93 const OUString
& __PropertyName
,
94 const sal_Int32
& __Handle
,
95 const com::sun::star::uno::Type
& __Typ
,
96 const com::sun::star::uno::Any
& __Value
,
97 const com::sun::star::beans::PropertyState
& __State
,
98 const sal_Int16
& __Attributes
);
101 inline const bool& SAL_CALL
IsNative() const;
102 inline const OUString
& SAL_CALL
getPropertyName() const { return PropertyName
; }
103 inline const sal_Int32
& SAL_CALL
getHandle() const;
104 inline const com::sun::star::uno::Type
& SAL_CALL
getType() const;
105 inline const com::sun::star::uno::Any
& SAL_CALL
getValue() const;
106 inline const com::sun::star::beans::PropertyState
& SAL_CALL
getState() const;
107 inline const sal_Int16
& SAL_CALL
getAttributes() const;
109 // The set* functions are declared const, because the key of "this" stays intact
110 inline void SAL_CALL
setHandle( const sal_Int32
& __Handle
) const;
111 inline void SAL_CALL
setType( const com::sun::star::uno::Type
& __Type
) const;
112 inline void SAL_CALL
setValue( const com::sun::star::uno::Any
& __Value
) const;
113 inline void SAL_CALL
setState( const com::sun::star::beans::PropertyState
& __State
) const;
114 inline void SAL_CALL
setAttributes( const sal_Int16
& __Attributes
) const;
119 bool operator()( const MyProperty
& rKey1
, const MyProperty
& rKey2
) const
121 return !!( rKey1
.getPropertyName() == rKey2
.getPropertyName() );
127 size_t operator()( const MyProperty
& rName
) const
129 return rName
.getPropertyName().hashCode();
133 typedef std::unordered_set
< MyProperty
,hMyProperty
,eMyProperty
> PropertySet
;
134 typedef std::list
< Notifier
* > NotifierList
;
142 UnqPathData( const UnqPathData
& );
143 UnqPathData
& operator=( UnqPathData
& );
145 PropertySet
* properties
;
146 NotifierList
* notifier
;
148 // Three views on the PersistentPropertySet
149 com::sun::star::uno::Reference
< com::sun::star::ucb::XPersistentPropertySet
> xS
;
150 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertyContainer
> xC
;
151 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertyAccess
> xA
;
154 typedef std::unordered_map
< OUString
,UnqPathData
,OUStringHash
> ContentMap
;
158 // MethodenDefinitionen
159 shell( const com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
>& rxContext
,
160 FileProvider
* pProvider
, bool bWithConfig
);
167 * This two methods register and deregister a change listener for the content belonging
171 void SAL_CALL
registerNotifier( const OUString
& aUnqPath
,Notifier
* pNotifier
);
173 void SAL_CALL
deregisterNotifier( const OUString
& aUnqPath
,Notifier
* pNotifier
);
178 * Used to associate and deassociate a new property with
179 * the content belonging to URL UnqPath.
180 * The default value and the attributes are input
183 void SAL_CALL
associate( const OUString
& UnqPath
,
184 const OUString
& PropertyName
,
185 const com::sun::star::uno::Any
& DefaultValue
,
186 const sal_Int16 Attributes
)
187 throw( com::sun::star::beans::PropertyExistException
,
188 com::sun::star::beans::IllegalTypeException
,
189 com::sun::star::uno::RuntimeException
);
192 void SAL_CALL
deassociate( const OUString
& UnqPath
,
193 const OUString
& PropertyName
)
194 throw( com::sun::star::beans::UnknownPropertyException
,
195 com::sun::star::beans::NotRemoveableException
,
196 com::sun::star::uno::RuntimeException
);
201 // Every method having a command id is not allowed to throw anything,
202 // but instead must install every error code in the task handler
207 * Given an xOutputStream, this method writes the content of the file belonging to
208 * URL aUnqPath into the XOutputStream
211 void SAL_CALL
page( sal_Int32 CommandId
,
212 const OUString
& aUnqPath
,
213 const com::sun::star::uno::Reference
< com::sun::star::io::XOutputStream
>& xOutputStream
)
218 * Given a file URL aUnqPath, this methods returns a XInputStream which reads from the open file.
221 com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> SAL_CALL
222 open( sal_Int32 CommandId
,
223 const OUString
& aUnqPath
,
229 * Given a file URL aUnqPath, this methods returns a XStream which can be used
230 * to read and write from/to the file.
233 com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
234 open_rw( sal_Int32 CommandId
,
235 const OUString
& aUnqPath
,
241 * This method returns the result set containing the children of the directory belonging
242 * to file URL aUnqPath
245 com::sun::star::uno::Reference
< com::sun::star::ucb::XDynamicResultSet
> SAL_CALL
246 ls( sal_Int32 CommandId
,
247 const OUString
& aUnqPath
,
248 const sal_Int32 OpenMode
,
249 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& sProperty
,
250 const com::sun::star::uno::Sequence
< com::sun::star::ucb::NumberedSortingInfo
> & sSortingInfo
)
259 com::sun::star::uno::Reference
< com::sun::star::ucb::XCommandInfo
> SAL_CALL
263 // Info for the properties
264 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySetInfo
> SAL_CALL
265 info_p( const OUString
& aUnqPath
)
270 * Sets the values of the properties belonging to fileURL aUnqPath
273 com::sun::star::uno::Sequence
< com::sun::star::uno::Any
> SAL_CALL
274 setv( const OUString
& aUnqPath
,
275 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>& values
)
280 * Reads the values of the properties belonging to fileURL aUnqPath;
281 * Returns an XRow object containing the values in the requested order.
284 com::sun::star::uno::Reference
< com::sun::star::sdbc::XRow
> SAL_CALL
285 getv( sal_Int32 CommandId
,
286 const OUString
& aUnqPath
,
287 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& properties
)
291 /********************************************************************************/
292 /* transfer-commands */
293 /********************************************************************************/
296 * Moves the content belonging to fileURL srcUnqPath to fileURL dstUnqPath( files and directories )
300 move( sal_Int32 CommandId
,
301 const OUString
& srcUnqPath
, // Full file(folder)-path
302 const OUString
& dstUnqPath
, // Path to the destination-directory
303 const sal_Int32 NameClash
)
307 * Copies the content belonging to fileURL srcUnqPath to fileURL dstUnqPath ( files and directories )
311 copy( sal_Int32 CommandId
, // See "move"
312 const OUString
& srcUnqPath
,
313 const OUString
& dstUnqPath
,
314 sal_Int32 NameClash
)
317 #define RemoveFolder 1
318 #define RemoveFile -1
319 #define RemoveUnknown 0
322 * Deletes the content belonging to fileURL aUnqPath( recursively in case of directory )
326 remove( sal_Int32 CommandId
,
327 const OUString
& aUnqPath
,
328 sal_Int32 TypeToMove
= RemoveUnknown
,
329 bool MustExist
= true )
337 /********************************************************************************/
338 /* write and create - commandos */
339 /********************************************************************************/
342 * Creates new directory with given URL, recursively if necessary
343 * Return:: success of operation
347 mkdir( sal_Int32 CommandId
,
348 const OUString
& aDirectoryName
,
354 * Creates new file with given URL.
355 * The content of aInputStream becomes the content of the file
356 * Return:: success of operation
360 mkfil( sal_Int32 CommandId
,
361 const OUString
& aFileName
,
363 const com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
>& aInputStream
)
368 * writes to the file with given URL.
369 * The content of aInputStream becomes the content of the file
370 * Return:: success of operation
373 write( sal_Int32 CommandId
,
374 const OUString
& aUnqPath
,
376 const com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
>& aInputStream
)
381 void SAL_CALL
insertDefaultProperties( const OUString
& aUnqPath
);
383 com::sun::star::uno::Sequence
< com::sun::star::ucb::ContentInfo
>
384 queryCreatableContentsInfo();
387 /******************************************************************************/
389 /* mapping of file urls */
390 /* to uncpath and vice versa */
392 /******************************************************************************/
394 static bool SAL_CALL
getUnqFromUrl( const OUString
& Url
, OUString
& Unq
);
396 static bool SAL_CALL
getUrlFromUnq( const OUString
& Unq
, OUString
& Url
);
400 FileProvider
* m_pProvider
;
401 com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_xContext
;
402 com::sun::star::uno::Reference
< com::sun::star::ucb::XPropertySetRegistry
> m_xFileRegistry
;
406 /********************************************************************************/
407 /* get eventListeners */
408 /********************************************************************************/
410 std::list
< ContentEventNotifier
* >* SAL_CALL
411 getContentEventListeners( const OUString
& aName
);
413 std::list
< ContentEventNotifier
* >* SAL_CALL
414 getContentDeletedEventListeners( const OUString
& aName
);
416 std::vector
< std::list
< ContentEventNotifier
* >* >* SAL_CALL
417 getContentExchangedEventListeners( const OUString
& aOldPrefix
,
418 const OUString
& aNewPrefix
,
421 std::list
< PropertyChangeNotifier
* >* SAL_CALL
422 getPropertyChangeNotifier( const OUString
& aName
);
424 std::list
< PropertySetInfoChangeNotifier
* >* SAL_CALL
425 getPropertySetListeners( const OUString
& aName
);
428 /********************************************************************************/
429 /* notify eventListeners */
430 /********************************************************************************/
432 static void SAL_CALL
notifyPropertyChanges(
433 std::list
< PropertyChangeNotifier
* >* listeners
,
434 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyChangeEvent
>& seqChanged
);
436 static void SAL_CALL
notifyContentExchanged(
437 std::vector
< std::list
< ContentEventNotifier
* >* >* listeners_vec
);
439 static void SAL_CALL
notifyInsert(
440 std::list
< ContentEventNotifier
* >* listeners
,const OUString
& aChildName
);
442 static void SAL_CALL
notifyContentDeleted(
443 std::list
< ContentEventNotifier
* >* listeners
);
445 static void SAL_CALL
notifyContentRemoved(
446 std::list
< ContentEventNotifier
* >* listeners
,
447 const OUString
& aChildName
);
449 static void SAL_CALL
notifyPropertyAdded(
450 std::list
< PropertySetInfoChangeNotifier
* >* listeners
,
451 const OUString
& aPropertyName
);
453 static void SAL_CALL
notifyPropertyRemoved(
454 std::list
< PropertySetInfoChangeNotifier
* >* listeners
,
455 const OUString
& aPropertyName
);
458 /********************************************************************************/
459 /* remove persistent propertyset */
460 /********************************************************************************/
462 void SAL_CALL
erasePersistentSet( const OUString
& aUnqPath
,
463 bool withChildren
= false );
465 /********************************************************************************/
466 /* copy persistent propertyset */
467 /* from srcUnqPath to dstUnqPath */
468 /********************************************************************************/
470 void SAL_CALL
copyPersistentSet( const OUString
& srcUnqPath
,
471 const OUString
& dstUnqPath
,
472 bool withChildren
= false );
475 // Special optimized method for getting the properties of a directoryitem, which
476 // is returned by osl::DirectoryItem::getNextItem()
478 com::sun::star::uno::Reference
< com::sun::star::sdbc::XRow
> SAL_CALL
479 getv( Notifier
* pNotifier
,
480 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& properties
,
481 osl::DirectoryItem
& DirItem
,
487 * Load the properties from configuration, if create == true create them.
488 * The Properties are stored under the url belonging to it->first.
491 void SAL_CALL
load( const shell::ContentMap::iterator
& it
,
495 * Commit inserts the determined properties in the filestatus object into
496 * the internal map, so that is possible to determine on a subsequent
497 * setting of file properties which properties have changed without filestat
502 const shell::ContentMap::iterator
& it
,
503 const osl::FileStatus
& aFileStatus
);
506 * Given a Sequence of properties seq, this method determines the mask
507 * used to instantiate a osl::FileStatus, so that a call to
508 * osl::DirectoryItem::getFileStatus fills the required fields.
512 getMaskFromProperties(
514 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& seq
);
519 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>& values
,
520 sal_Int32 numberOfValues
)
524 // Helper function for public copy
526 osl::FileBase::RC SAL_CALL
528 const OUString
& srcUnqPath
,
529 const OUString
& dstUnqPath
,
530 sal_Int32 TypeToCopy
,
535 // Helper function for mkfil,mkdir and write
536 // Creates whole path
537 // returns success of the operation
538 // The calle determines the errorCode, which should be used to install
542 ensuredir( sal_Int32 CommandId
,
543 const OUString
& aDirectoryName
,
544 sal_Int32 errorCode
)
549 ContentMap m_aContent
;
551 // Default properties
553 const OUString Title
;
554 const OUString CasePreservingURL
;
555 const OUString IsDocument
;
556 const OUString IsFolder
;
557 const OUString DateModified
;
559 const OUString IsVolume
;
560 const OUString IsRemoveable
;
561 const OUString IsRemote
;
562 const OUString IsCompactDisc
;
563 const OUString IsFloppy
;
564 const OUString IsHidden
;
565 const OUString ContentType
;
566 const OUString IsReadOnly
;
567 const OUString CreatableContentsInfo
;
571 const OUString FolderContentType
;
572 const OUString FileContentType
;
577 PropertySet m_aDefaultProperties
;
578 com::sun::star::uno::Sequence
< com::sun::star::ucb::CommandInfo
> m_sCommandInfo
;
582 // Methods for "writeComponentInfo" and "createComponentFactory"
584 static void SAL_CALL
getScheme( OUString
& Scheme
);
586 static OUString SAL_CALL
getImplementationName_static();
588 static com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames_static();
590 }; // end class shell
592 } // end namespace fileaccess
596 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */