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