Update ooo320-m1
[ooovba.git] / ucb / source / ucp / file / shell.hxx
blob89e2324d74362ab1f33ec1f66be95aeb86025647
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shell.hxx,v $
10 * $Revision: 1.26 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #ifndef _SHELL_HXX_
33 #define _SHELL_HXX_
36 #include <cppuhelper/weak.hxx>
37 #include <cppuhelper/interfacecontainer.hxx>
38 #include <cppuhelper/typeprovider.hxx>
39 #include <vector>
40 #include <hash_map>
41 #include <hash_set>
42 #include <list>
43 #include <osl/file.hxx>
45 #include "osl/mutex.hxx"
46 #include <rtl/ustring.hxx>
47 #include <com/sun/star/uno/Sequence.hxx>
48 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
49 #include <com/sun/star/ucb/XCommandInfo.hpp>
50 #include <com/sun/star/beans/Property.hpp>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/io/XStream.hpp>
53 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
54 #include <com/sun/star/ucb/XCommandProcessor.hpp>
55 #include <com/sun/star/io/XOutputStream.hpp>
56 #include <com/sun/star/io/XInputStream.hpp>
57 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_protected
58 #include <com/sun/star/beans/XPropertySetInfo.hpp>
59 #endif
60 #include <com/sun/star/beans/XPropertiesChangeNotifier.hpp>
61 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
62 #include <com/sun/star/sdbc/XRow.hpp>
63 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
64 #include <com/sun/star/ucb/XContentProvider.hpp>
65 #ifndef _COM_SUN_STAR_UCB_XDYNAMICRESULTSET_HPP__
66 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
67 #endif
68 #include <com/sun/star/beans/XPropertyContainer.hpp>
69 #include <com/sun/star/beans/XPropertyAccess.hpp>
70 #include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp>
71 #include <com/sun/star/ucb/TransferInfo.hpp>
72 #include "filtask.hxx"
73 #include "filnot.hxx"
75 namespace fileaccess {
77 class FileProvider;
78 class XPropertySetInfo_impl;
79 class XCommandInfo_impl;
80 class XResultSet_impl;
81 class BaseContent;
82 class shell;
84 class shell
85 : public virtual TaskManager
87 friend class XPropertySetInfo_impl;
88 friend class XResultSet_impl;
89 friend class XCommandInfo_impl;
90 public:
91 // Type definitions
93 typedef rtl::OUString UniquePath;
94 typedef equalOUString eUniquePath;
95 typedef hashOUString hUniquePath;
97 class MyProperty
99 private:
100 rtl::OUString PropertyName;
101 sal_Int32 Handle;
102 sal_Bool isNative;
103 com::sun::star::uno::Type Typ; // Duplicates information in Value
104 com::sun::star::uno::Any Value;
105 com::sun::star::beans::PropertyState State;
106 sal_Int16 Attributes;
107 public:
108 MyProperty();
109 MyProperty( const rtl::OUString& __PropertyName );
110 MyProperty( const sal_Bool& __isNative,
111 const rtl::OUString& __PropertyName,
112 const sal_Int32& __Handle,
113 const com::sun::star::uno::Type& __Typ,
114 const com::sun::star::uno::Any& __Value,
115 const com::sun::star::beans::PropertyState& __State,
116 const sal_Int16& __Attributes );
118 ~MyProperty();
119 inline const sal_Bool& SAL_CALL IsNative() const;
120 inline const rtl::OUString& SAL_CALL getPropertyName() const { return PropertyName; }
121 inline const sal_Int32& SAL_CALL getHandle() const;
122 inline const com::sun::star::uno::Type& SAL_CALL getType() const;
123 inline const com::sun::star::uno::Any& SAL_CALL getValue() const;
124 inline const com::sun::star::beans::PropertyState& SAL_CALL getState() const;
125 inline const sal_Int16& SAL_CALL getAttributes() const;
127 // The set* functions are declared const, because the key of "this" stays intact
128 inline void SAL_CALL setHandle( const sal_Int32& __Handle ) const;
129 inline void SAL_CALL setType( const com::sun::star::uno::Type& __Type ) const;
130 inline void SAL_CALL setValue( const com::sun::star::uno::Any& __Value ) const;
131 inline void SAL_CALL setState( const com::sun::star::beans::PropertyState& __State ) const;
132 inline void SAL_CALL setAttributes( const sal_Int16& __Attributes ) const;
135 struct eMyProperty
137 bool operator()( const MyProperty& rKey1, const MyProperty& rKey2 ) const
139 return !!( rKey1.getPropertyName() == rKey2.getPropertyName() );
143 struct hMyProperty
145 size_t operator()( const MyProperty& rName ) const
147 return rName.getPropertyName().hashCode();
151 typedef std::hash_set< MyProperty,hMyProperty,eMyProperty > PropertySet;
152 typedef std::list< Notifier* > NotifierList;
155 class UnqPathData
157 public:
158 UnqPathData();
159 ~UnqPathData();
160 UnqPathData( const UnqPathData& );
161 UnqPathData& operator=( UnqPathData& );
163 PropertySet* properties;
164 NotifierList* notifier;
166 // Three views on the PersistentPropertySet
167 com::sun::star::uno::Reference< com::sun::star::ucb::XPersistentPropertySet > xS;
168 com::sun::star::uno::Reference< com::sun::star::beans::XPropertyContainer > xC;
169 com::sun::star::uno::Reference< com::sun::star::beans::XPropertyAccess > xA;
172 typedef std::hash_map< UniquePath,UnqPathData,hUniquePath,eUniquePath > ContentMap;
174 public:
176 // MethodenDefinitionen
177 shell( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& xMultiServiceFactory,
178 FileProvider* pProvider,sal_Bool bWithConfig );
180 virtual ~shell();
185 * This two methods register and deregister a change listener for the content belonging
186 * to URL aUnqPath
189 void SAL_CALL registerNotifier( const rtl::OUString& aUnqPath,Notifier* pNotifier );
191 void SAL_CALL deregisterNotifier( const rtl::OUString& aUnqPath,Notifier* pNotifier );
196 * Used to associate and deassociate a new property with
197 * the content belonging to URL UnqPath.
198 * The default value and the the attributes are input
201 void SAL_CALL associate( const rtl::OUString& UnqPath,
202 const rtl::OUString& PropertyName,
203 const com::sun::star::uno::Any& DefaultValue,
204 const sal_Int16 Attributes )
205 throw( com::sun::star::beans::PropertyExistException,
206 com::sun::star::beans::IllegalTypeException,
207 com::sun::star::uno::RuntimeException);
210 void SAL_CALL deassociate( const rtl::OUString& UnqPath,
211 const rtl::OUString& PropertyName )
212 throw( com::sun::star::beans::UnknownPropertyException,
213 com::sun::star::beans::NotRemoveableException,
214 com::sun::star::uno::RuntimeException);
219 // Every method having a command id is not allowed to throw anything,
220 // but instead must install every error code in the task handler
225 * Given an xOutputStream, this method writes the content of the file belonging to
226 * URL aUnqPath into the XOutputStream
229 void SAL_CALL page( sal_Int32 CommandId,
230 const rtl::OUString& aUnqPath,
231 const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xOutputStream )
232 throw();
236 * Given a file URL aUnqPath, this methods returns a XInputStream which reads from the open file.
239 com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL
240 open( sal_Int32 CommandId,
241 const rtl::OUString& aUnqPath,
242 sal_Bool bLock )
243 throw();
247 * Given a file URL aUnqPath, this methods returns a XStream which can be used
248 * to read and write from/to the file.
251 com::sun::star::uno::Reference< com::sun::star::io::XStream > SAL_CALL
252 open_rw( sal_Int32 CommandId,
253 const rtl::OUString& aUnqPath,
254 sal_Bool bLock )
255 throw();
259 * This method returns the result set containing the the children of the directory belonging
260 * to file URL aUnqPath
263 com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet > SAL_CALL
264 ls( sal_Int32 CommandId,
265 const rtl::OUString& aUnqPath,
266 const sal_Int32 OpenMode,
267 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& sProperty,
268 const com::sun::star::uno::Sequence< com::sun::star::ucb::NumberedSortingInfo > & sSortingInfo )
269 throw();
273 * Info methods
276 // Info for commands
277 com::sun::star::uno::Reference< com::sun::star::ucb::XCommandInfo > SAL_CALL
278 info_c()
279 throw();
281 // Info for the properties
282 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL
283 info_p( const rtl::OUString& aUnqPath )
284 throw();
288 * Sets the values of the properties belonging to fileURL aUnqPath
291 com::sun::star::uno::Sequence< com::sun::star::uno::Any > SAL_CALL
292 setv( const rtl::OUString& aUnqPath,
293 const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& values )
294 throw();
298 * Reads the values of the properties belonging to fileURL aUnqPath;
299 * Returns an XRow object containing the values in the requested order.
302 com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > SAL_CALL
303 getv( sal_Int32 CommandId,
304 const rtl::OUString& aUnqPath,
305 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& properties )
306 throw();
309 /********************************************************************************/
310 /* transfer-commandos */
311 /********************************************************************************/
314 * Moves the content belonging to fileURL srcUnqPath to fileURL dstUnqPath( files and directories )
317 void SAL_CALL
318 move( sal_Int32 CommandId,
319 const rtl::OUString srcUnqPath, // Full file(folder)-path
320 const rtl::OUString dstUnqPath, // Path to the destination-directory
321 const sal_Int32 NameClash )
322 throw();
325 * Copies the content belonging to fileURL srcUnqPath to fileURL dstUnqPath ( files and directories )
328 void SAL_CALL
329 copy( sal_Int32 CommandId, // See "move"
330 const rtl::OUString srcUnqPath,
331 const rtl::OUString dstUnqPath,
332 sal_Int32 NameClash )
333 throw();
335 #define RemoveFolder 1
336 #define RemoveFile -1
337 #define RemoveUnknown 0
340 * Deletes the content belonging to fileURL aUnqPath( recursively in case of directory )
343 sal_Bool SAL_CALL
344 remove( sal_Int32 CommandId,
345 const rtl::OUString& aUnqPath,
346 sal_Int32 TypeToMove = RemoveUnknown,
347 sal_Bool MustExist = sal_True )
348 throw();
350 #undef RemoveUnknown
351 #undef RemoveFile
352 #undef RemoveFolder
355 /********************************************************************************/
356 /* write and create - commandos */
357 /********************************************************************************/
360 * Creates new directory with given URL, recursively if necessary
361 * Return:: success of operation
364 sal_Bool SAL_CALL
365 mkdir( sal_Int32 CommandId,
366 const rtl::OUString& aDirectoryName,
367 sal_Bool OverWrite )
368 throw();
372 * Creates new file with given URL.
373 * The content of aInputStream becomes the content of the file
374 * Return:: success of operation
377 sal_Bool SAL_CALL
378 mkfil( sal_Int32 CommandId,
379 const rtl::OUString& aFileName,
380 sal_Bool OverWrite,
381 const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream )
382 throw();
386 * writes to the file with given URL.
387 * The content of aInputStream becomes the content of the file
388 * Return:: success of operation
390 sal_Bool SAL_CALL
391 write( sal_Int32 CommandId,
392 const rtl::OUString& aUnqPath,
393 sal_Bool OverWrite,
394 const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream )
395 throw();
399 void SAL_CALL insertDefaultProperties( const rtl::OUString& aUnqPath );
402 /******************************************************************************/
403 /* */
404 /* mapping of file urls */
405 /* to uncpath and vice versa */
406 /* */
407 /******************************************************************************/
409 sal_Bool SAL_CALL getUnqFromUrl( const rtl::OUString& Url, rtl::OUString& Unq );
411 sal_Bool SAL_CALL getUrlFromUnq( const rtl::OUString& Unq, rtl::OUString& Url );
414 sal_Bool m_bWithConfig;
415 FileProvider* m_pProvider;
416 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xMultiServiceFactory;
417 com::sun::star::uno::Reference< com::sun::star::ucb::XPropertySetRegistry > m_xFileRegistry;
420 private:
422 /********************************************************************************/
423 /* get eventListeners */
424 /********************************************************************************/
426 std::list< ContentEventNotifier* >* SAL_CALL
427 getContentEventListeners( const rtl::OUString& aName );
429 std::list< ContentEventNotifier* >* SAL_CALL
430 getContentDeletedEventListeners( const rtl::OUString& aName );
432 std::vector< std::list< ContentEventNotifier* >* >* SAL_CALL
433 getContentExchangedEventListeners( const rtl::OUString aOldPrefix,
434 const rtl::OUString aNewPrefix,
435 sal_Bool withChilds );
437 std::list< PropertyChangeNotifier* >* SAL_CALL
438 getPropertyChangeNotifier( const rtl::OUString& aName );
440 std::list< PropertySetInfoChangeNotifier* >* SAL_CALL
441 getPropertySetListeners( const rtl::OUString& aName );
444 /********************************************************************************/
445 /* notify eventListeners */
446 /********************************************************************************/
448 void SAL_CALL notifyPropertyChanges(
449 std::list< PropertyChangeNotifier* >* listeners,
450 const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyChangeEvent >& seqChanged );
452 void SAL_CALL notifyContentExchanged(
453 std::vector< std::list< ContentEventNotifier* >* >* listeners_vec );
455 void SAL_CALL notifyInsert(
456 std::list< ContentEventNotifier* >* listeners,const rtl::OUString& aChildName );
458 void SAL_CALL notifyContentDeleted(
459 std::list< ContentEventNotifier* >* listeners );
461 void SAL_CALL notifyContentRemoved(
462 std::list< ContentEventNotifier* >* listeners,
463 const rtl::OUString& aChildName );
465 void SAL_CALL notifyPropertyAdded(
466 std::list< PropertySetInfoChangeNotifier* >* listeners,
467 const rtl::OUString& aPropertyName );
469 void SAL_CALL notifyPropertyRemoved(
470 std::list< PropertySetInfoChangeNotifier* >* listeners,
471 const rtl::OUString& aPropertyName );
474 /********************************************************************************/
475 /* remove persistent propertyset */
476 /********************************************************************************/
478 void SAL_CALL erasePersistentSet( const rtl::OUString& aUnqPath,
479 sal_Bool withChilds = false );
481 /********************************************************************************/
482 /* copy persistent propertyset */
483 /* from srcUnqPath to dstUnqPath */
484 /********************************************************************************/
486 void SAL_CALL copyPersistentSet( const rtl::OUString& srcUnqPath,
487 const rtl::OUString& dstUnqPath,
488 sal_Bool withChilds = false );
491 // Special optimized method for getting the properties of a directoryitem, which
492 // is returned by osl::DirectoryItem::getNextItem()
494 com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > SAL_CALL
495 getv( Notifier* pNotifier,
496 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& properties,
497 osl::DirectoryItem& DirItem,
498 rtl::OUString& aUnqPath,
499 sal_Bool& bIsRegular );
503 * Load the properties from configuration, if create == true create them.
504 * The Properties are stored under the url belonging to it->first.
507 void SAL_CALL load( const shell::ContentMap::iterator& it,
508 sal_Bool create );
511 * Commit inserts the determined properties in the filestatus object into
512 * the internal map, so that is possible to determine on a subsequent
513 * setting of file properties which properties have changed without filestat
516 void SAL_CALL
517 commit(
518 const shell::ContentMap::iterator& it,
519 const osl::FileStatus& aFileStatus );
522 * Given a Sequence of properties seq, this method determines the mask
523 * used to instantiate a osl::FileStatus, so that a call to
524 * osl::DirectoryItem::getFileStatus fills the required fields.
527 void SAL_CALL
528 getMaskFromProperties(
529 sal_Int32& n_Mask,
530 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& seq );
533 void SAL_CALL
534 setFileProperties(
535 const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& values,
536 sal_Int32 numberOfValues )
537 throw();
540 // Helper function for public copy
542 osl::FileBase::RC SAL_CALL
543 copy_recursive(
544 const rtl::OUString& srcUnqPath,
545 const rtl::OUString& dstUnqPath,
546 sal_Int32 TypeToCopy,
547 sal_Bool testExistence )
548 throw();
551 // Helper function for mkfil,mkdir and write
552 // Creates whole path
553 // returns success of the operation
554 // The calle determines the errorCode, which should be used to install
555 // any error
557 sal_Bool SAL_CALL
558 ensuredir( sal_Int32 CommandId,
559 const rtl::OUString& aDirectoryName,
560 sal_Int32 errorCode )
561 throw();
563 // General
564 osl::Mutex m_aMutex;
565 ContentMap m_aContent;
567 // Default properties
569 const rtl::OUString Title;
570 const rtl::OUString CasePreservingURL;
571 const rtl::OUString IsDocument;
572 const rtl::OUString IsFolder;
573 const rtl::OUString DateModified;
574 const rtl::OUString Size;
575 const rtl::OUString IsVolume;
576 const rtl::OUString IsRemoveable;
577 const rtl::OUString IsRemote;
578 const rtl::OUString IsCompactDisc;
579 const rtl::OUString IsFloppy;
580 const rtl::OUString IsHidden;
581 const rtl::OUString ContentType;
582 const rtl::OUString IsReadOnly;
584 public:
586 const rtl::OUString FolderContentType;
587 const rtl::OUString FileContentType;
590 private:
592 PropertySet m_aDefaultProperties;
593 com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo > m_sCommandInfo;
595 public:
596 // Misceancellous:
597 // Methods for "writeComponentInfo" and "createComponentFactory"
599 static void SAL_CALL getScheme( rtl::OUString& Scheme );
601 static rtl::OUString SAL_CALL getImplementationName_static( void );
603 static com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames_static( void );
605 }; // end class shell
607 } // end namespace fileaccess
609 #endif