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