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 #ifndef INCLUDED_TDOC_STORAGE_HXX 25 #define INCLUDED_TDOC_STORAGE_HXX 26 27 #include <map> 28 29 #include "osl/mutex.hxx" 30 #include "rtl/ref.hxx" 31 #include "salhelper/simplereferenceobject.hxx" 32 33 #include "com/sun/star/embed/XStorage.hpp" 34 35 namespace tdoc_ucp { 36 37 enum StorageAccessMode 38 { 39 READ, // Note: might be writable as well 40 READ_WRITE_NOCREATE, 41 READ_WRITE_CREATE 42 }; 43 44 class Storage; 45 class OfficeDocumentsManager; 46 47 class StorageElementFactory : public salhelper::SimpleReferenceObject 48 { 49 public: 50 StorageElementFactory( 51 const com::sun::star::uno::Reference< 52 com::sun::star::lang::XMultiServiceFactory > & xSMgr, 53 const rtl::Reference< OfficeDocumentsManager > & xDocsMgr ); 54 ~StorageElementFactory(); 55 56 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > 57 createTemporaryStorage(); 58 59 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > 60 createStorage( const rtl::OUString & rUri, StorageAccessMode eMode ); 61 62 com::sun::star::uno::Reference< com::sun::star::io::XInputStream > 63 createInputStream( const rtl::OUString & rUri, 64 const rtl::OUString & rPassword ); 65 66 com::sun::star::uno::Reference< com::sun::star::io::XOutputStream > 67 createOutputStream( const rtl::OUString & rUri, 68 const rtl::OUString & rPassword, 69 bool bTruncate ); 70 71 com::sun::star::uno::Reference< com::sun::star::io::XStream > 72 createStream( const rtl::OUString & rUri, 73 const rtl::OUString & rPassword, 74 bool bTruncate ); 75 76 private: 77 friend class Storage; 78 79 void releaseElement( Storage * pElement ) SAL_THROW(()); 80 81 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > 82 queryParentStorage( const rtl::OUString & rUri, 83 StorageAccessMode eMode ); 84 85 com::sun::star::uno::Reference< com::sun::star::embed::XStorage > 86 queryStorage( const com::sun::star::uno::Reference< 87 com::sun::star::embed::XStorage > & xParentStorage, 88 const rtl::OUString & rUri, 89 StorageAccessMode eMode ); 90 91 com::sun::star::uno::Reference< com::sun::star::io::XStream > 92 queryStream( const com::sun::star::uno::Reference< 93 com::sun::star::embed::XStorage > & xParentStorage, 94 const rtl::OUString & rPassword, 95 const rtl::OUString & rUri, 96 StorageAccessMode eMode, 97 bool bTruncate /* ignored for read-only streams */ ); 98 99 struct ltstrbool 100 { operator ()tdoc_ucp::StorageElementFactory::ltstrbool101 bool operator()( 102 const std::pair< rtl::OUString, bool > & s1, 103 const std::pair< rtl::OUString, bool > & s2 ) const 104 { 105 if ( s1.first < s2.first ) 106 return true; 107 else if ( s1.first == s2.first ) 108 return ( !s1.second && s2.second ); 109 else 110 return false; 111 } 112 }; 113 114 // key: pair< storageuri, iswritable > 115 typedef std::map< 116 std::pair< rtl::OUString, bool >, Storage *, ltstrbool > StorageMap; 117 118 StorageMap m_aMap; 119 osl::Mutex m_aMutex; 120 rtl::Reference< OfficeDocumentsManager > m_xDocsMgr; 121 com::sun::star::uno::Reference< 122 com::sun::star::lang::XMultiServiceFactory > m_xSMgr; 123 }; 124 125 } // namespace tdoc_ucp 126 127 #endif /* !INCLUDED_TDOC_STORAGE_HXX */ 128