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 196 197 void SAL_CALL deassociate( const rtl::OUString& UnqPath, 198 const rtl::OUString& PropertyName ); 199 200 201 202 // 203 // Every method having a command id is not allowed to throw anything, 204 // but instead must install every error code in the task handler 205 // 206 207 208 /** 209 * Given an xOutputStream, this method writes the content of the file belonging to 210 * URL aUnqPath into the XOutputStream 211 */ 212 213 void SAL_CALL page( sal_Int32 CommandId, 214 const rtl::OUString& aUnqPath, 215 const com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >& xOutputStream ) 216 throw(); 217 218 219 /** 220 * Given a file URL aUnqPath, this methods returns a XInputStream which reads from the open file. 221 */ 222 223 com::sun::star::uno::Reference< com::sun::star::io::XInputStream > SAL_CALL 224 open( sal_Int32 CommandId, 225 const rtl::OUString& aUnqPath, 226 sal_Bool bLock ) 227 throw(); 228 229 230 /** 231 * Given a file URL aUnqPath, this methods returns a XStream which can be used 232 * to read and write from/to the file. 233 */ 234 235 com::sun::star::uno::Reference< com::sun::star::io::XStream > SAL_CALL 236 open_rw( sal_Int32 CommandId, 237 const rtl::OUString& aUnqPath, 238 sal_Bool bLock ) 239 throw(); 240 241 242 /** 243 * This method returns the result set containing the children of the directory belonging 244 * to file URL aUnqPath 245 */ 246 247 com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet > SAL_CALL 248 ls( sal_Int32 CommandId, 249 const rtl::OUString& aUnqPath, 250 const sal_Int32 OpenMode, 251 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& sProperty, 252 const com::sun::star::uno::Sequence< com::sun::star::ucb::NumberedSortingInfo > & sSortingInfo ) 253 throw(); 254 255 256 /** 257 * Info methods 258 */ 259 260 // Info for commands 261 com::sun::star::uno::Reference< com::sun::star::ucb::XCommandInfo > SAL_CALL 262 info_c() 263 throw(); 264 265 // Info for the properties 266 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL 267 info_p( const rtl::OUString& aUnqPath ) 268 throw(); 269 270 271 /** 272 * Sets the values of the properties belonging to fileURL aUnqPath 273 */ 274 275 com::sun::star::uno::Sequence< com::sun::star::uno::Any > SAL_CALL 276 setv( const rtl::OUString& aUnqPath, 277 const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& values ) 278 throw(); 279 280 281 /** 282 * Reads the values of the properties belonging to fileURL aUnqPath; 283 * Returns an XRow object containing the values in the requested order. 284 */ 285 286 com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > SAL_CALL 287 getv( sal_Int32 CommandId, 288 const rtl::OUString& aUnqPath, 289 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& properties ) 290 throw(); 291 292 293 /********************************************************************************/ 294 /* transfer-commands */ 295 /********************************************************************************/ 296 297 /** 298 * Moves the content belonging to fileURL srcUnqPath to fileURL dstUnqPath( files and directories ) 299 */ 300 301 void SAL_CALL 302 move( sal_Int32 CommandId, 303 const rtl::OUString srcUnqPath, // Full file(folder)-path 304 const rtl::OUString dstUnqPath, // Path to the destination-directory 305 const sal_Int32 NameClash ) 306 throw(); 307 308 /** 309 * Copies the content belonging to fileURL srcUnqPath to fileURL dstUnqPath ( files and directories ) 310 */ 311 312 void SAL_CALL 313 copy( sal_Int32 CommandId, // See "move" 314 const rtl::OUString srcUnqPath, 315 const rtl::OUString dstUnqPath, 316 sal_Int32 NameClash ) 317 throw(); 318 319 #define RemoveFolder 1 320 #define RemoveFile -1 321 #define RemoveUnknown 0 322 323 /** 324 * Deletes the content belonging to fileURL aUnqPath( recursively in case of directory ) 325 */ 326 327 sal_Bool SAL_CALL 328 remove( sal_Int32 CommandId, 329 const rtl::OUString& aUnqPath, 330 sal_Int32 TypeToMove = RemoveUnknown, 331 sal_Bool MustExist = sal_True ) 332 throw(); 333 334 #undef RemoveUnknown 335 #undef RemoveFile 336 #undef RemoveFolder 337 338 339 /********************************************************************************/ 340 /* write and create - commandos */ 341 /********************************************************************************/ 342 343 /** 344 * Creates new directory with given URL, recursively if necessary 345 * Return:: success of operation 346 */ 347 348 sal_Bool SAL_CALL 349 mkdir( sal_Int32 CommandId, 350 const rtl::OUString& aDirectoryName, 351 sal_Bool OverWrite ) 352 throw(); 353 354 355 /** 356 * Creates new file with given URL. 357 * The content of aInputStream becomes the content of the file 358 * Return:: success of operation 359 */ 360 361 sal_Bool SAL_CALL 362 mkfil( sal_Int32 CommandId, 363 const rtl::OUString& aFileName, 364 sal_Bool OverWrite, 365 const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream ) 366 throw(); 367 368 369 /** 370 * writes to the file with given URL. 371 * The content of aInputStream becomes the content of the file 372 * Return:: success of operation 373 */ 374 sal_Bool SAL_CALL 375 write( sal_Int32 CommandId, 376 const rtl::OUString& aUnqPath, 377 sal_Bool OverWrite, 378 const com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream ) 379 throw(); 380 381 382 383 void SAL_CALL insertDefaultProperties( const rtl::OUString& aUnqPath ); 384 385 com::sun::star::uno::Sequence< com::sun::star::ucb::ContentInfo > 386 queryCreatableContentsInfo(); 387 388 389 /******************************************************************************/ 390 /* */ 391 /* mapping of file urls */ 392 /* to uncpath and vice versa */ 393 /* */ 394 /******************************************************************************/ 395 396 sal_Bool SAL_CALL getUnqFromUrl( const rtl::OUString& Url, rtl::OUString& Unq ); 397 398 sal_Bool SAL_CALL getUrlFromUnq( const rtl::OUString& Unq, rtl::OUString& Url ); 399 400 401 sal_Bool m_bWithConfig; 402 FileProvider* m_pProvider; 403 com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xMultiServiceFactory; 404 com::sun::star::uno::Reference< com::sun::star::ucb::XPropertySetRegistry > m_xFileRegistry; 405 406 private: 407 408 /********************************************************************************/ 409 /* get eventListeners */ 410 /********************************************************************************/ 411 412 std::list< ContentEventNotifier* >* SAL_CALL 413 getContentEventListeners( const rtl::OUString& aName ); 414 415 std::list< ContentEventNotifier* >* SAL_CALL 416 getContentDeletedEventListeners( const rtl::OUString& aName ); 417 418 std::vector< std::list< ContentEventNotifier* >* >* SAL_CALL 419 getContentExchangedEventListeners( const rtl::OUString aOldPrefix, 420 const rtl::OUString aNewPrefix, 421 sal_Bool withChilds ); 422 423 std::list< PropertyChangeNotifier* >* SAL_CALL 424 getPropertyChangeNotifier( const rtl::OUString& aName ); 425 426 std::list< PropertySetInfoChangeNotifier* >* SAL_CALL 427 getPropertySetListeners( const rtl::OUString& aName ); 428 429 430 /********************************************************************************/ 431 /* notify eventListeners */ 432 /********************************************************************************/ 433 434 void SAL_CALL notifyPropertyChanges( 435 std::list< PropertyChangeNotifier* >* listeners, 436 const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyChangeEvent >& seqChanged ); 437 438 void SAL_CALL notifyContentExchanged( 439 std::vector< std::list< ContentEventNotifier* >* >* listeners_vec ); 440 441 void SAL_CALL notifyInsert( 442 std::list< ContentEventNotifier* >* listeners,const rtl::OUString& aChildName ); 443 444 void SAL_CALL notifyContentDeleted( 445 std::list< ContentEventNotifier* >* listeners ); 446 447 void SAL_CALL notifyContentRemoved( 448 std::list< ContentEventNotifier* >* listeners, 449 const rtl::OUString& aChildName ); 450 451 void SAL_CALL notifyPropertyAdded( 452 std::list< PropertySetInfoChangeNotifier* >* listeners, 453 const rtl::OUString& aPropertyName ); 454 455 void SAL_CALL notifyPropertyRemoved( 456 std::list< PropertySetInfoChangeNotifier* >* listeners, 457 const rtl::OUString& aPropertyName ); 458 459 460 /********************************************************************************/ 461 /* remove persistent propertyset */ 462 /********************************************************************************/ 463 464 void SAL_CALL erasePersistentSet( const rtl::OUString& aUnqPath, 465 sal_Bool withChilds = false ); 466 467 /********************************************************************************/ 468 /* copy persistent propertyset */ 469 /* from srcUnqPath to dstUnqPath */ 470 /********************************************************************************/ 471 472 void SAL_CALL copyPersistentSet( const rtl::OUString& srcUnqPath, 473 const rtl::OUString& dstUnqPath, 474 sal_Bool withChilds = false ); 475 476 477 // Special optimized method for getting the properties of a directoryitem, which 478 // is returned by osl::DirectoryItem::getNextItem() 479 480 com::sun::star::uno::Reference< com::sun::star::sdbc::XRow > SAL_CALL 481 getv( Notifier* pNotifier, 482 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& properties, 483 osl::DirectoryItem& DirItem, 484 rtl::OUString& aUnqPath, 485 sal_Bool& bIsRegular ); 486 487 488 /** 489 * Load the properties from configuration, if create == true create them. 490 * The Properties are stored under the url belonging to it->first. 491 */ 492 493 void SAL_CALL load( const shell::ContentMap::iterator& it, 494 sal_Bool create ); 495 496 /** 497 * Commit inserts the determined properties in the filestatus object into 498 * the internal map, so that is possible to determine on a subsequent 499 * setting of file properties which properties have changed without filestat 500 */ 501 502 void SAL_CALL 503 commit( 504 const shell::ContentMap::iterator& it, 505 const osl::FileStatus& aFileStatus ); 506 507 /** 508 * Given a Sequence of properties seq, this method determines the mask 509 * used to instantiate a osl::FileStatus, so that a call to 510 * osl::DirectoryItem::getFileStatus fills the required fields. 511 */ 512 513 void SAL_CALL 514 getMaskFromProperties( 515 sal_Int32& n_Mask, 516 const com::sun::star::uno::Sequence< com::sun::star::beans::Property >& seq ); 517 518 519 void SAL_CALL 520 setFileProperties( 521 const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& values, 522 sal_Int32 numberOfValues ) 523 throw(); 524 525 526 // Helper function for public copy 527 528 osl::FileBase::RC SAL_CALL 529 copy_recursive( 530 const rtl::OUString& srcUnqPath, 531 const rtl::OUString& dstUnqPath, 532 sal_Int32 TypeToCopy, 533 sal_Bool testExistence ) 534 throw(); 535 536 537 // Helper function for mkfil,mkdir and write 538 // Creates whole path 539 // returns success of the operation 540 // The calle determines the errorCode, which should be used to install 541 // any error 542 543 sal_Bool SAL_CALL 544 ensuredir( sal_Int32 CommandId, 545 const rtl::OUString& aDirectoryName, 546 sal_Int32 errorCode ) 547 throw(); 548 549 // General 550 osl::Mutex m_aMutex; 551 ContentMap m_aContent; 552 553 // Default properties 554 555 const rtl::OUString Title; 556 const rtl::OUString CasePreservingURL; 557 const rtl::OUString IsDocument; 558 const rtl::OUString IsFolder; 559 const rtl::OUString DateModified; 560 const rtl::OUString Size; 561 const rtl::OUString IsVolume; 562 const rtl::OUString IsRemoveable; 563 const rtl::OUString IsRemote; 564 const rtl::OUString IsCompactDisc; 565 const rtl::OUString IsFloppy; 566 const rtl::OUString IsHidden; 567 const rtl::OUString ContentType; 568 const rtl::OUString IsReadOnly; 569 const rtl::OUString CreatableContentsInfo; 570 571 public: 572 573 const rtl::OUString FolderContentType; 574 const rtl::OUString FileContentType; 575 576 577 private: 578 579 PropertySet m_aDefaultProperties; 580 com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo > m_sCommandInfo; 581 582 public: 583 // Miscellaneous: 584 // Methods for "writeComponentInfo" and "createComponentFactory" 585 586 static void SAL_CALL getScheme( rtl::OUString& Scheme ); 587 588 static rtl::OUString SAL_CALL getImplementationName_static( void ); 589 590 static com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames_static( void ); 591 592 }; // end class shell 593 594 } // end namespace fileaccess 595 596 #endif 597