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 .
25 #include <cppuhelper/weak.hxx>
26 #include <cppuhelper/interfacecontainer.hxx>
27 #include <cppuhelper/typeprovider.hxx>
29 #include <boost/unordered_map.hpp>
30 #include <boost/unordered_set.hpp>
32 #include <osl/file.hxx>
34 #include "osl/mutex.hxx"
35 #include <rtl/ustring.hxx>
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
38 #include <com/sun/star/ucb/XCommandInfo.hpp>
39 #include <com/sun/star/beans/Property.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <com/sun/star/io/XStream.hpp>
42 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
43 #include <com/sun/star/ucb/XCommandProcessor.hpp>
44 #include <com/sun/star/io/XOutputStream.hpp>
45 #include <com/sun/star/io/XInputStream.hpp>
46 #include <com/sun/star/beans/XPropertySetInfo.hpp>
47 #include <com/sun/star/beans/XPropertiesChangeNotifier.hpp>
48 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
49 #include <com/sun/star/sdbc/XRow.hpp>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/uno/XComponentContext.hpp>
52 #include <com/sun/star/ucb/XContentProvider.hpp>
53 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
54 #include <com/sun/star/beans/XPropertyContainer.hpp>
55 #include <com/sun/star/beans/XPropertyAccess.hpp>
56 #include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp>
57 #include <com/sun/star/ucb/TransferInfo.hpp>
58 #include <com/sun/star/ucb/ContentInfo.hpp>
59 #include "filtask.hxx"
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
;
79 typedef rtl::OUString UniquePath
;
80 typedef equalOUString eUniquePath
;
81 typedef hashOUString hUniquePath
;
86 rtl::OUString PropertyName
;
89 com::sun::star::uno::Type Typ
; // Duplicates information in Value
90 com::sun::star::uno::Any Value
;
91 com::sun::star::beans::PropertyState State
;
95 MyProperty( const rtl::OUString
& __PropertyName
);
96 MyProperty( const sal_Bool
& __isNative
,
97 const rtl::OUString
& __PropertyName
,
98 const sal_Int32
& __Handle
,
99 const com::sun::star::uno::Type
& __Typ
,
100 const com::sun::star::uno::Any
& __Value
,
101 const com::sun::star::beans::PropertyState
& __State
,
102 const sal_Int16
& __Attributes
);
105 inline const sal_Bool
& SAL_CALL
IsNative() const;
106 inline const rtl::OUString
& SAL_CALL
getPropertyName() const { return PropertyName
; }
107 inline const sal_Int32
& SAL_CALL
getHandle() const;
108 inline const com::sun::star::uno::Type
& SAL_CALL
getType() const;
109 inline const com::sun::star::uno::Any
& SAL_CALL
getValue() const;
110 inline const com::sun::star::beans::PropertyState
& SAL_CALL
getState() const;
111 inline const sal_Int16
& SAL_CALL
getAttributes() const;
113 // The set* functions are declared const, because the key of "this" stays intact
114 inline void SAL_CALL
setHandle( const sal_Int32
& __Handle
) const;
115 inline void SAL_CALL
setType( const com::sun::star::uno::Type
& __Type
) const;
116 inline void SAL_CALL
setValue( const com::sun::star::uno::Any
& __Value
) const;
117 inline void SAL_CALL
setState( const com::sun::star::beans::PropertyState
& __State
) const;
118 inline void SAL_CALL
setAttributes( const sal_Int16
& __Attributes
) const;
123 bool operator()( const MyProperty
& rKey1
, const MyProperty
& rKey2
) const
125 return !!( rKey1
.getPropertyName() == rKey2
.getPropertyName() );
131 size_t operator()( const MyProperty
& rName
) const
133 return rName
.getPropertyName().hashCode();
137 typedef boost::unordered_set
< MyProperty
,hMyProperty
,eMyProperty
> PropertySet
;
138 typedef std::list
< Notifier
* > NotifierList
;
146 UnqPathData( const UnqPathData
& );
147 UnqPathData
& operator=( UnqPathData
& );
149 PropertySet
* properties
;
150 NotifierList
* notifier
;
152 // Three views on the PersistentPropertySet
153 com::sun::star::uno::Reference
< com::sun::star::ucb::XPersistentPropertySet
> xS
;
154 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertyContainer
> xC
;
155 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertyAccess
> xA
;
158 typedef boost::unordered_map
< UniquePath
,UnqPathData
,hUniquePath
,eUniquePath
> ContentMap
;
162 // MethodenDefinitionen
163 shell( const com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
>& rxContext
,
164 FileProvider
* pProvider
,sal_Bool bWithConfig
);
171 * This two methods register and deregister a change listener for the content belonging
175 void SAL_CALL
registerNotifier( const rtl::OUString
& aUnqPath
,Notifier
* pNotifier
);
177 void SAL_CALL
deregisterNotifier( const rtl::OUString
& aUnqPath
,Notifier
* pNotifier
);
182 * Used to associate and deassociate a new property with
183 * the content belonging to URL UnqPath.
184 * The default value and the the attributes are input
187 void SAL_CALL
associate( const rtl::OUString
& UnqPath
,
188 const rtl::OUString
& PropertyName
,
189 const com::sun::star::uno::Any
& DefaultValue
,
190 const sal_Int16 Attributes
)
191 throw( com::sun::star::beans::PropertyExistException
,
192 com::sun::star::beans::IllegalTypeException
,
193 com::sun::star::uno::RuntimeException
);
196 void SAL_CALL
deassociate( const rtl::OUString
& UnqPath
,
197 const rtl::OUString
& PropertyName
)
198 throw( com::sun::star::beans::UnknownPropertyException
,
199 com::sun::star::beans::NotRemoveableException
,
200 com::sun::star::uno::RuntimeException
);
205 // Every method having a command id is not allowed to throw anything,
206 // but instead must install every error code in the task handler
211 * Given an xOutputStream, this method writes the content of the file belonging to
212 * URL aUnqPath into the XOutputStream
215 void SAL_CALL
page( sal_Int32 CommandId
,
216 const rtl::OUString
& aUnqPath
,
217 const com::sun::star::uno::Reference
< com::sun::star::io::XOutputStream
>& xOutputStream
)
222 * Given a file URL aUnqPath, this methods returns a XInputStream which reads from the open file.
225 com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> SAL_CALL
226 open( sal_Int32 CommandId
,
227 const rtl::OUString
& aUnqPath
,
233 * Given a file URL aUnqPath, this methods returns a XStream which can be used
234 * to read and write from/to the file.
237 com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
238 open_rw( sal_Int32 CommandId
,
239 const rtl::OUString
& aUnqPath
,
245 * This method returns the result set containing the the children of the directory belonging
246 * to file URL aUnqPath
249 com::sun::star::uno::Reference
< com::sun::star::ucb::XDynamicResultSet
> SAL_CALL
250 ls( sal_Int32 CommandId
,
251 const rtl::OUString
& aUnqPath
,
252 const sal_Int32 OpenMode
,
253 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& sProperty
,
254 const com::sun::star::uno::Sequence
< com::sun::star::ucb::NumberedSortingInfo
> & sSortingInfo
)
263 com::sun::star::uno::Reference
< com::sun::star::ucb::XCommandInfo
> SAL_CALL
267 // Info for the properties
268 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySetInfo
> SAL_CALL
269 info_p( const rtl::OUString
& aUnqPath
)
274 * Sets the values of the properties belonging to fileURL aUnqPath
277 com::sun::star::uno::Sequence
< com::sun::star::uno::Any
> SAL_CALL
278 setv( const rtl::OUString
& aUnqPath
,
279 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>& values
)
284 * Reads the values of the properties belonging to fileURL aUnqPath;
285 * Returns an XRow object containing the values in the requested order.
288 com::sun::star::uno::Reference
< com::sun::star::sdbc::XRow
> SAL_CALL
289 getv( sal_Int32 CommandId
,
290 const rtl::OUString
& aUnqPath
,
291 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& properties
)
295 /********************************************************************************/
296 /* transfer-commands */
297 /********************************************************************************/
300 * Moves the content belonging to fileURL srcUnqPath to fileURL dstUnqPath( files and directories )
304 move( sal_Int32 CommandId
,
305 const rtl::OUString srcUnqPath
, // Full file(folder)-path
306 const rtl::OUString dstUnqPath
, // Path to the destination-directory
307 const sal_Int32 NameClash
)
311 * Copies the content belonging to fileURL srcUnqPath to fileURL dstUnqPath ( files and directories )
315 copy( sal_Int32 CommandId
, // See "move"
316 const rtl::OUString srcUnqPath
,
317 const rtl::OUString dstUnqPath
,
318 sal_Int32 NameClash
)
321 #define RemoveFolder 1
322 #define RemoveFile -1
323 #define RemoveUnknown 0
326 * Deletes the content belonging to fileURL aUnqPath( recursively in case of directory )
330 remove( sal_Int32 CommandId
,
331 const rtl::OUString
& aUnqPath
,
332 sal_Int32 TypeToMove
= RemoveUnknown
,
333 sal_Bool MustExist
= sal_True
)
341 /********************************************************************************/
342 /* write and create - commandos */
343 /********************************************************************************/
346 * Creates new directory with given URL, recursively if necessary
347 * Return:: success of operation
351 mkdir( sal_Int32 CommandId
,
352 const rtl::OUString
& aDirectoryName
,
358 * Creates new file with given URL.
359 * The content of aInputStream becomes the content of the file
360 * Return:: success of operation
364 mkfil( sal_Int32 CommandId
,
365 const rtl::OUString
& aFileName
,
367 const com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
>& aInputStream
)
372 * writes to the file with given URL.
373 * The content of aInputStream becomes the content of the file
374 * Return:: success of operation
377 write( sal_Int32 CommandId
,
378 const rtl::OUString
& aUnqPath
,
380 const com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
>& aInputStream
)
385 void SAL_CALL
insertDefaultProperties( const rtl::OUString
& aUnqPath
);
387 com::sun::star::uno::Sequence
< com::sun::star::ucb::ContentInfo
>
388 queryCreatableContentsInfo();
391 /******************************************************************************/
393 /* mapping of file urls */
394 /* to uncpath and vice versa */
396 /******************************************************************************/
398 sal_Bool SAL_CALL
getUnqFromUrl( const rtl::OUString
& Url
, rtl::OUString
& Unq
);
400 sal_Bool SAL_CALL
getUrlFromUnq( const rtl::OUString
& Unq
, rtl::OUString
& Url
);
403 sal_Bool m_bWithConfig
;
404 FileProvider
* m_pProvider
;
405 com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_xContext
;
406 com::sun::star::uno::Reference
< com::sun::star::ucb::XPropertySetRegistry
> m_xFileRegistry
;
410 /********************************************************************************/
411 /* get eventListeners */
412 /********************************************************************************/
414 std::list
< ContentEventNotifier
* >* SAL_CALL
415 getContentEventListeners( const rtl::OUString
& aName
);
417 std::list
< ContentEventNotifier
* >* SAL_CALL
418 getContentDeletedEventListeners( const rtl::OUString
& aName
);
420 std::vector
< std::list
< ContentEventNotifier
* >* >* SAL_CALL
421 getContentExchangedEventListeners( const rtl::OUString aOldPrefix
,
422 const rtl::OUString aNewPrefix
,
423 sal_Bool withChildren
);
425 std::list
< PropertyChangeNotifier
* >* SAL_CALL
426 getPropertyChangeNotifier( const rtl::OUString
& aName
);
428 std::list
< PropertySetInfoChangeNotifier
* >* SAL_CALL
429 getPropertySetListeners( const rtl::OUString
& aName
);
432 /********************************************************************************/
433 /* notify eventListeners */
434 /********************************************************************************/
436 void SAL_CALL
notifyPropertyChanges(
437 std::list
< PropertyChangeNotifier
* >* listeners
,
438 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyChangeEvent
>& seqChanged
);
440 void SAL_CALL
notifyContentExchanged(
441 std::vector
< std::list
< ContentEventNotifier
* >* >* listeners_vec
);
443 void SAL_CALL
notifyInsert(
444 std::list
< ContentEventNotifier
* >* listeners
,const rtl::OUString
& aChildName
);
446 void SAL_CALL
notifyContentDeleted(
447 std::list
< ContentEventNotifier
* >* listeners
);
449 void SAL_CALL
notifyContentRemoved(
450 std::list
< ContentEventNotifier
* >* listeners
,
451 const rtl::OUString
& aChildName
);
453 void SAL_CALL
notifyPropertyAdded(
454 std::list
< PropertySetInfoChangeNotifier
* >* listeners
,
455 const rtl::OUString
& aPropertyName
);
457 void SAL_CALL
notifyPropertyRemoved(
458 std::list
< PropertySetInfoChangeNotifier
* >* listeners
,
459 const rtl::OUString
& aPropertyName
);
462 /********************************************************************************/
463 /* remove persistent propertyset */
464 /********************************************************************************/
466 void SAL_CALL
erasePersistentSet( const rtl::OUString
& aUnqPath
,
467 sal_Bool withChildren
= false );
469 /********************************************************************************/
470 /* copy persistent propertyset */
471 /* from srcUnqPath to dstUnqPath */
472 /********************************************************************************/
474 void SAL_CALL
copyPersistentSet( const rtl::OUString
& srcUnqPath
,
475 const rtl::OUString
& dstUnqPath
,
476 sal_Bool withChildren
= false );
479 // Special optimized method for getting the properties of a directoryitem, which
480 // is returned by osl::DirectoryItem::getNextItem()
482 com::sun::star::uno::Reference
< com::sun::star::sdbc::XRow
> SAL_CALL
483 getv( Notifier
* pNotifier
,
484 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& properties
,
485 osl::DirectoryItem
& DirItem
,
486 rtl::OUString
& aUnqPath
,
487 sal_Bool
& bIsRegular
);
491 * Load the properties from configuration, if create == true create them.
492 * The Properties are stored under the url belonging to it->first.
495 void SAL_CALL
load( const shell::ContentMap::iterator
& it
,
499 * Commit inserts the determined properties in the filestatus object into
500 * the internal map, so that is possible to determine on a subsequent
501 * setting of file properties which properties have changed without filestat
506 const shell::ContentMap::iterator
& it
,
507 const osl::FileStatus
& aFileStatus
);
510 * Given a Sequence of properties seq, this method determines the mask
511 * used to instantiate a osl::FileStatus, so that a call to
512 * osl::DirectoryItem::getFileStatus fills the required fields.
516 getMaskFromProperties(
518 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& seq
);
523 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>& values
,
524 sal_Int32 numberOfValues
)
528 // Helper function for public copy
530 osl::FileBase::RC SAL_CALL
532 const rtl::OUString
& srcUnqPath
,
533 const rtl::OUString
& dstUnqPath
,
534 sal_Int32 TypeToCopy
,
535 sal_Bool testExistence
)
539 // Helper function for mkfil,mkdir and write
540 // Creates whole path
541 // returns success of the operation
542 // The calle determines the errorCode, which should be used to install
546 ensuredir( sal_Int32 CommandId
,
547 const rtl::OUString
& aDirectoryName
,
548 sal_Int32 errorCode
)
553 ContentMap m_aContent
;
555 // Default properties
557 const rtl::OUString Title
;
558 const rtl::OUString CasePreservingURL
;
559 const rtl::OUString IsDocument
;
560 const rtl::OUString IsFolder
;
561 const rtl::OUString DateModified
;
562 const rtl::OUString Size
;
563 const rtl::OUString IsVolume
;
564 const rtl::OUString IsRemoveable
;
565 const rtl::OUString IsRemote
;
566 const rtl::OUString IsCompactDisc
;
567 const rtl::OUString IsFloppy
;
568 const rtl::OUString IsHidden
;
569 const rtl::OUString ContentType
;
570 const rtl::OUString IsReadOnly
;
571 const rtl::OUString CreatableContentsInfo
;
575 const rtl::OUString FolderContentType
;
576 const rtl::OUString FileContentType
;
581 PropertySet m_aDefaultProperties
;
582 com::sun::star::uno::Sequence
< com::sun::star::ucb::CommandInfo
> m_sCommandInfo
;
586 // Methods for "writeComponentInfo" and "createComponentFactory"
588 static void SAL_CALL
getScheme( rtl::OUString
& Scheme
);
590 static rtl::OUString SAL_CALL
getImplementationName_static( void );
592 static com::sun::star::uno::Sequence
< rtl::OUString
> SAL_CALL
getSupportedServiceNames_static( void );
594 }; // end class shell
596 } // end namespace fileaccess
600 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */