1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
34 #include <cppuhelper/weak.hxx>
35 #include <cppuhelper/interfacecontainer.hxx>
36 #include <cppuhelper/typeprovider.hxx>
38 #include <boost/unordered_map.hpp>
39 #include <boost/unordered_set.hpp>
41 #include <osl/file.hxx>
43 #include "osl/mutex.hxx"
44 #include <rtl/ustring.hxx>
45 #include <com/sun/star/uno/Sequence.hxx>
46 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
47 #include <com/sun/star/ucb/XCommandInfo.hpp>
48 #include <com/sun/star/beans/Property.hpp>
49 #include <com/sun/star/beans/PropertyValue.hpp>
50 #include <com/sun/star/io/XStream.hpp>
51 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
52 #include <com/sun/star/ucb/XCommandProcessor.hpp>
53 #include <com/sun/star/io/XOutputStream.hpp>
54 #include <com/sun/star/io/XInputStream.hpp>
55 #include <com/sun/star/beans/XPropertySetInfo.hpp>
56 #include <com/sun/star/beans/XPropertiesChangeNotifier.hpp>
57 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
58 #include <com/sun/star/sdbc/XRow.hpp>
59 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
60 #include <com/sun/star/ucb/XContentProvider.hpp>
61 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
62 #include <com/sun/star/beans/XPropertyContainer.hpp>
63 #include <com/sun/star/beans/XPropertyAccess.hpp>
64 #include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp>
65 #include <com/sun/star/ucb/TransferInfo.hpp>
66 #include <com/sun/star/ucb/ContentInfo.hpp>
67 #include "filtask.hxx"
70 namespace fileaccess
{
73 class XPropertySetInfo_impl
;
74 class XCommandInfo_impl
;
75 class XResultSet_impl
;
80 : public virtual TaskManager
82 friend class XPropertySetInfo_impl
;
83 friend class XResultSet_impl
;
84 friend class XCommandInfo_impl
;
88 typedef rtl::OUString UniquePath
;
89 typedef equalOUString eUniquePath
;
90 typedef hashOUString hUniquePath
;
95 rtl::OUString PropertyName
;
98 com::sun::star::uno::Type Typ
; // Duplicates information in Value
99 com::sun::star::uno::Any Value
;
100 com::sun::star::beans::PropertyState State
;
101 sal_Int16 Attributes
;
104 MyProperty( const rtl::OUString
& __PropertyName
);
105 MyProperty( const sal_Bool
& __isNative
,
106 const rtl::OUString
& __PropertyName
,
107 const sal_Int32
& __Handle
,
108 const com::sun::star::uno::Type
& __Typ
,
109 const com::sun::star::uno::Any
& __Value
,
110 const com::sun::star::beans::PropertyState
& __State
,
111 const sal_Int16
& __Attributes
);
114 inline const sal_Bool
& SAL_CALL
IsNative() const;
115 inline const rtl::OUString
& SAL_CALL
getPropertyName() const { return PropertyName
; }
116 inline const sal_Int32
& SAL_CALL
getHandle() const;
117 inline const com::sun::star::uno::Type
& SAL_CALL
getType() const;
118 inline const com::sun::star::uno::Any
& SAL_CALL
getValue() const;
119 inline const com::sun::star::beans::PropertyState
& SAL_CALL
getState() const;
120 inline const sal_Int16
& SAL_CALL
getAttributes() const;
122 // The set* functions are declared const, because the key of "this" stays intact
123 inline void SAL_CALL
setHandle( const sal_Int32
& __Handle
) const;
124 inline void SAL_CALL
setType( const com::sun::star::uno::Type
& __Type
) const;
125 inline void SAL_CALL
setValue( const com::sun::star::uno::Any
& __Value
) const;
126 inline void SAL_CALL
setState( const com::sun::star::beans::PropertyState
& __State
) const;
127 inline void SAL_CALL
setAttributes( const sal_Int16
& __Attributes
) const;
132 bool operator()( const MyProperty
& rKey1
, const MyProperty
& rKey2
) const
134 return !!( rKey1
.getPropertyName() == rKey2
.getPropertyName() );
140 size_t operator()( const MyProperty
& rName
) const
142 return rName
.getPropertyName().hashCode();
146 typedef boost::unordered_set
< MyProperty
,hMyProperty
,eMyProperty
> PropertySet
;
147 typedef std::list
< Notifier
* > NotifierList
;
155 UnqPathData( const UnqPathData
& );
156 UnqPathData
& operator=( UnqPathData
& );
158 PropertySet
* properties
;
159 NotifierList
* notifier
;
161 // Three views on the PersistentPropertySet
162 com::sun::star::uno::Reference
< com::sun::star::ucb::XPersistentPropertySet
> xS
;
163 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertyContainer
> xC
;
164 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertyAccess
> xA
;
167 typedef boost::unordered_map
< UniquePath
,UnqPathData
,hUniquePath
,eUniquePath
> ContentMap
;
171 // MethodenDefinitionen
172 shell( const com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
>& xMultiServiceFactory
,
173 FileProvider
* pProvider
,sal_Bool bWithConfig
);
180 * This two methods register and deregister a change listener for the content belonging
184 void SAL_CALL
registerNotifier( const rtl::OUString
& aUnqPath
,Notifier
* pNotifier
);
186 void SAL_CALL
deregisterNotifier( const rtl::OUString
& aUnqPath
,Notifier
* pNotifier
);
191 * Used to associate and deassociate a new property with
192 * the content belonging to URL UnqPath.
193 * The default value and the the attributes are input
196 void SAL_CALL
associate( const rtl::OUString
& UnqPath
,
197 const rtl::OUString
& PropertyName
,
198 const com::sun::star::uno::Any
& DefaultValue
,
199 const sal_Int16 Attributes
)
200 throw( com::sun::star::beans::PropertyExistException
,
201 com::sun::star::beans::IllegalTypeException
,
202 com::sun::star::uno::RuntimeException
);
205 void SAL_CALL
deassociate( const rtl::OUString
& UnqPath
,
206 const rtl::OUString
& PropertyName
)
207 throw( com::sun::star::beans::UnknownPropertyException
,
208 com::sun::star::beans::NotRemoveableException
,
209 com::sun::star::uno::RuntimeException
);
214 // Every method having a command id is not allowed to throw anything,
215 // but instead must install every error code in the task handler
220 * Given an xOutputStream, this method writes the content of the file belonging to
221 * URL aUnqPath into the XOutputStream
224 void SAL_CALL
page( sal_Int32 CommandId
,
225 const rtl::OUString
& aUnqPath
,
226 const com::sun::star::uno::Reference
< com::sun::star::io::XOutputStream
>& xOutputStream
)
231 * Given a file URL aUnqPath, this methods returns a XInputStream which reads from the open file.
234 com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
> SAL_CALL
235 open( sal_Int32 CommandId
,
236 const rtl::OUString
& aUnqPath
,
242 * Given a file URL aUnqPath, this methods returns a XStream which can be used
243 * to read and write from/to the file.
246 com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
247 open_rw( sal_Int32 CommandId
,
248 const rtl::OUString
& aUnqPath
,
254 * This method returns the result set containing the the children of the directory belonging
255 * to file URL aUnqPath
258 com::sun::star::uno::Reference
< com::sun::star::ucb::XDynamicResultSet
> SAL_CALL
259 ls( sal_Int32 CommandId
,
260 const rtl::OUString
& aUnqPath
,
261 const sal_Int32 OpenMode
,
262 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& sProperty
,
263 const com::sun::star::uno::Sequence
< com::sun::star::ucb::NumberedSortingInfo
> & sSortingInfo
)
272 com::sun::star::uno::Reference
< com::sun::star::ucb::XCommandInfo
> SAL_CALL
276 // Info for the properties
277 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySetInfo
> SAL_CALL
278 info_p( const rtl::OUString
& aUnqPath
)
283 * Sets the values of the properties belonging to fileURL aUnqPath
286 com::sun::star::uno::Sequence
< com::sun::star::uno::Any
> SAL_CALL
287 setv( const rtl::OUString
& aUnqPath
,
288 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>& values
)
293 * Reads the values of the properties belonging to fileURL aUnqPath;
294 * Returns an XRow object containing the values in the requested order.
297 com::sun::star::uno::Reference
< com::sun::star::sdbc::XRow
> SAL_CALL
298 getv( sal_Int32 CommandId
,
299 const rtl::OUString
& aUnqPath
,
300 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& properties
)
304 /********************************************************************************/
305 /* transfer-commands */
306 /********************************************************************************/
309 * Moves the content belonging to fileURL srcUnqPath to fileURL dstUnqPath( files and directories )
313 move( sal_Int32 CommandId
,
314 const rtl::OUString srcUnqPath
, // Full file(folder)-path
315 const rtl::OUString dstUnqPath
, // Path to the destination-directory
316 const sal_Int32 NameClash
)
320 * Copies the content belonging to fileURL srcUnqPath to fileURL dstUnqPath ( files and directories )
324 copy( sal_Int32 CommandId
, // See "move"
325 const rtl::OUString srcUnqPath
,
326 const rtl::OUString dstUnqPath
,
327 sal_Int32 NameClash
)
330 #define RemoveFolder 1
331 #define RemoveFile -1
332 #define RemoveUnknown 0
335 * Deletes the content belonging to fileURL aUnqPath( recursively in case of directory )
339 remove( sal_Int32 CommandId
,
340 const rtl::OUString
& aUnqPath
,
341 sal_Int32 TypeToMove
= RemoveUnknown
,
342 sal_Bool MustExist
= sal_True
)
350 /********************************************************************************/
351 /* write and create - commandos */
352 /********************************************************************************/
355 * Creates new directory with given URL, recursively if necessary
356 * Return:: success of operation
360 mkdir( sal_Int32 CommandId
,
361 const rtl::OUString
& aDirectoryName
,
367 * Creates new file with given URL.
368 * The content of aInputStream becomes the content of the file
369 * Return:: success of operation
373 mkfil( sal_Int32 CommandId
,
374 const rtl::OUString
& aFileName
,
376 const com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
>& aInputStream
)
381 * writes to the file with given URL.
382 * The content of aInputStream becomes the content of the file
383 * Return:: success of operation
386 write( sal_Int32 CommandId
,
387 const rtl::OUString
& aUnqPath
,
389 const com::sun::star::uno::Reference
< com::sun::star::io::XInputStream
>& aInputStream
)
394 void SAL_CALL
insertDefaultProperties( const rtl::OUString
& aUnqPath
);
396 com::sun::star::uno::Sequence
< com::sun::star::ucb::ContentInfo
>
397 queryCreatableContentsInfo();
400 /******************************************************************************/
402 /* mapping of file urls */
403 /* to uncpath and vice versa */
405 /******************************************************************************/
407 sal_Bool SAL_CALL
getUnqFromUrl( const rtl::OUString
& Url
, rtl::OUString
& Unq
);
409 sal_Bool SAL_CALL
getUrlFromUnq( const rtl::OUString
& Unq
, rtl::OUString
& Url
);
412 sal_Bool m_bWithConfig
;
413 FileProvider
* m_pProvider
;
414 com::sun::star::uno::Reference
< com::sun::star::lang::XMultiServiceFactory
> m_xMultiServiceFactory
;
415 com::sun::star::uno::Reference
< com::sun::star::ucb::XPropertySetRegistry
> m_xFileRegistry
;
419 /********************************************************************************/
420 /* get eventListeners */
421 /********************************************************************************/
423 std::list
< ContentEventNotifier
* >* SAL_CALL
424 getContentEventListeners( const rtl::OUString
& aName
);
426 std::list
< ContentEventNotifier
* >* SAL_CALL
427 getContentDeletedEventListeners( const rtl::OUString
& aName
);
429 std::vector
< std::list
< ContentEventNotifier
* >* >* SAL_CALL
430 getContentExchangedEventListeners( const rtl::OUString aOldPrefix
,
431 const rtl::OUString aNewPrefix
,
432 sal_Bool withChildren
);
434 std::list
< PropertyChangeNotifier
* >* SAL_CALL
435 getPropertyChangeNotifier( const rtl::OUString
& aName
);
437 std::list
< PropertySetInfoChangeNotifier
* >* SAL_CALL
438 getPropertySetListeners( const rtl::OUString
& aName
);
441 /********************************************************************************/
442 /* notify eventListeners */
443 /********************************************************************************/
445 void SAL_CALL
notifyPropertyChanges(
446 std::list
< PropertyChangeNotifier
* >* listeners
,
447 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyChangeEvent
>& seqChanged
);
449 void SAL_CALL
notifyContentExchanged(
450 std::vector
< std::list
< ContentEventNotifier
* >* >* listeners_vec
);
452 void SAL_CALL
notifyInsert(
453 std::list
< ContentEventNotifier
* >* listeners
,const rtl::OUString
& aChildName
);
455 void SAL_CALL
notifyContentDeleted(
456 std::list
< ContentEventNotifier
* >* listeners
);
458 void SAL_CALL
notifyContentRemoved(
459 std::list
< ContentEventNotifier
* >* listeners
,
460 const rtl::OUString
& aChildName
);
462 void SAL_CALL
notifyPropertyAdded(
463 std::list
< PropertySetInfoChangeNotifier
* >* listeners
,
464 const rtl::OUString
& aPropertyName
);
466 void SAL_CALL
notifyPropertyRemoved(
467 std::list
< PropertySetInfoChangeNotifier
* >* listeners
,
468 const rtl::OUString
& aPropertyName
);
471 /********************************************************************************/
472 /* remove persistent propertyset */
473 /********************************************************************************/
475 void SAL_CALL
erasePersistentSet( const rtl::OUString
& aUnqPath
,
476 sal_Bool withChildren
= false );
478 /********************************************************************************/
479 /* copy persistent propertyset */
480 /* from srcUnqPath to dstUnqPath */
481 /********************************************************************************/
483 void SAL_CALL
copyPersistentSet( const rtl::OUString
& srcUnqPath
,
484 const rtl::OUString
& dstUnqPath
,
485 sal_Bool withChildren
= false );
488 // Special optimized method for getting the properties of a directoryitem, which
489 // is returned by osl::DirectoryItem::getNextItem()
491 com::sun::star::uno::Reference
< com::sun::star::sdbc::XRow
> SAL_CALL
492 getv( Notifier
* pNotifier
,
493 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& properties
,
494 osl::DirectoryItem
& DirItem
,
495 rtl::OUString
& aUnqPath
,
496 sal_Bool
& bIsRegular
);
500 * Load the properties from configuration, if create == true create them.
501 * The Properties are stored under the url belonging to it->first.
504 void SAL_CALL
load( const shell::ContentMap::iterator
& it
,
508 * Commit inserts the determined properties in the filestatus object into
509 * the internal map, so that is possible to determine on a subsequent
510 * setting of file properties which properties have changed without filestat
515 const shell::ContentMap::iterator
& it
,
516 const osl::FileStatus
& aFileStatus
);
519 * Given a Sequence of properties seq, this method determines the mask
520 * used to instantiate a osl::FileStatus, so that a call to
521 * osl::DirectoryItem::getFileStatus fills the required fields.
525 getMaskFromProperties(
527 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
>& seq
);
532 const com::sun::star::uno::Sequence
< com::sun::star::beans::PropertyValue
>& values
,
533 sal_Int32 numberOfValues
)
537 // Helper function for public copy
539 osl::FileBase::RC SAL_CALL
541 const rtl::OUString
& srcUnqPath
,
542 const rtl::OUString
& dstUnqPath
,
543 sal_Int32 TypeToCopy
,
544 sal_Bool testExistence
)
548 // Helper function for mkfil,mkdir and write
549 // Creates whole path
550 // returns success of the operation
551 // The calle determines the errorCode, which should be used to install
555 ensuredir( sal_Int32 CommandId
,
556 const rtl::OUString
& aDirectoryName
,
557 sal_Int32 errorCode
)
562 ContentMap m_aContent
;
564 // Default properties
566 const rtl::OUString Title
;
567 const rtl::OUString CasePreservingURL
;
568 const rtl::OUString IsDocument
;
569 const rtl::OUString IsFolder
;
570 const rtl::OUString DateModified
;
571 const rtl::OUString Size
;
572 const rtl::OUString IsVolume
;
573 const rtl::OUString IsRemoveable
;
574 const rtl::OUString IsRemote
;
575 const rtl::OUString IsCompactDisc
;
576 const rtl::OUString IsFloppy
;
577 const rtl::OUString IsHidden
;
578 const rtl::OUString ContentType
;
579 const rtl::OUString IsReadOnly
;
580 const rtl::OUString CreatableContentsInfo
;
584 const rtl::OUString FolderContentType
;
585 const rtl::OUString FileContentType
;
590 PropertySet m_aDefaultProperties
;
591 com::sun::star::uno::Sequence
< com::sun::star::ucb::CommandInfo
> m_sCommandInfo
;
595 // Methods for "writeComponentInfo" and "createComponentFactory"
597 static void SAL_CALL
getScheme( rtl::OUString
& Scheme
);
599 static rtl::OUString SAL_CALL
getImplementationName_static( void );
601 static com::sun::star::uno::Sequence
< rtl::OUString
> SAL_CALL
getSupportedServiceNames_static( void );
603 }; // end class shell
605 } // end namespace fileaccess
609 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */