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