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