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 __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_ 25 #define __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_ 26 27 //=============================================== 28 // own includes 29 30 #include <accelerators/istoragelistener.hxx> 31 #include <threadhelp/threadhelpbase.hxx> 32 #include <general.h> 33 #include <stdtypes.h> 34 35 //=============================================== 36 // interface includes 37 38 #ifndef __COM_SUN_STAR_EMBED_XSTORAGE_HPP_ 39 #include <com/sun/star/embed/XStorage.hpp> 40 #endif 41 42 #ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ 43 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 44 #endif 45 46 //=============================================== 47 // other includes 48 49 50 //=============================================== 51 // namespace 52 53 namespace framework 54 { 55 56 #ifdef css 57 #error "Who defines css? I will use it as namespace alias inside header." 58 #else 59 #define css ::com::sun::star 60 #endif 61 62 //=============================================== 63 // definitions 64 65 //----------------------------------------------- 66 /** 67 TODO document me 68 */ 69 class StorageHolder : private ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ... 70 { 71 //------------------------------------------- 72 // types 73 public: 74 75 /** @short TODO */ 76 typedef ::std::vector< css::uno::Reference< css::embed::XStorage > > TStorageList; 77 78 typedef ::std::vector< IStorageListener* > TStorageListenerList; 79 80 struct TStorageInfo 81 { 82 public: 83 css::uno::Reference< css::embed::XStorage > Storage; 84 sal_Int32 UseCount; 85 TStorageListenerList Listener; 86 TStorageInfoframework::StorageHolder::TStorageInfo87 TStorageInfo() 88 : UseCount(0) 89 {} 90 }; 91 92 /** @short TODO */ 93 typedef ::std::hash_map< ::rtl::OUString , 94 TStorageInfo , 95 ::rtl::OUStringHash , 96 ::std::equal_to< ::rtl::OUString > > TPath2StorageInfo; 97 98 //------------------------------------------- 99 // member 100 private: 101 102 /** @short TODO */ 103 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 104 105 /** @short TODO */ 106 css::uno::Reference< css::embed::XStorage > m_xRoot; 107 108 /** @short TODO */ 109 TPath2StorageInfo m_lStorages; 110 111 //------------------------------------------- 112 // interface 113 public: 114 115 //--------------------------------------- 116 /** @short TODO 117 */ 118 StorageHolder(); 119 120 //--------------------------------------- 121 /** @short TODO 122 */ 123 StorageHolder(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); 124 125 //--------------------------------------- 126 /** @short TODO 127 */ 128 virtual ~StorageHolder(); 129 130 //--------------------------------------- 131 /** @short TODO 132 */ 133 virtual void forgetCachedStorages(); 134 135 //--------------------------------------- 136 /** @short TODO 137 */ 138 virtual void setRootStorage(const css::uno::Reference< css::embed::XStorage >& xRoot); 139 140 //--------------------------------------- 141 /** @short TODO 142 */ 143 virtual css::uno::Reference< css::embed::XStorage > getRootStorage() const; 144 145 //--------------------------------------- 146 /** @short TODO 147 open or get! 148 */ 149 virtual css::uno::Reference< css::embed::XStorage > openPath(const ::rtl::OUString& sPath , 150 sal_Int32 nOpenMode); 151 152 //--------------------------------------- 153 /** @short TODO 154 */ 155 virtual StorageHolder::TStorageList getAllPathStorages(const ::rtl::OUString& sPath); 156 157 //--------------------------------------- 158 /** @short TODO 159 */ 160 virtual void commitPath(const ::rtl::OUString& sPath); 161 162 //--------------------------------------- 163 /** @short TODO 164 */ 165 virtual void closePath(const ::rtl::OUString& sPath); 166 167 //--------------------------------------- 168 /** @short TODO 169 */ 170 virtual void notifyPath(const ::rtl::OUString& sPath); 171 172 //--------------------------------------- 173 /** @short TODO 174 */ 175 virtual void addStorageListener( IStorageListener* pListener, 176 const ::rtl::OUString& sPath ); 177 178 //--------------------------------------- 179 /** @short TODO 180 */ 181 virtual void removeStorageListener( IStorageListener* pListener, 182 const ::rtl::OUString& sPath ); 183 184 //--------------------------------------- 185 /** @short TODO 186 */ 187 virtual ::rtl::OUString getPathOfStorage(const css::uno::Reference< css::embed::XStorage >& xStorage); 188 189 //--------------------------------------- 190 /** @short TODO 191 */ 192 virtual css::uno::Reference< css::embed::XStorage > getParentStorage(const css::uno::Reference< css::embed::XStorage >& xChild); 193 194 //--------------------------------------- 195 /** @short TODO 196 */ 197 virtual css::uno::Reference< css::embed::XStorage > getParentStorage(const ::rtl::OUString& sChildPath); 198 199 //--------------------------------------- 200 /** @short TODO 201 */ 202 virtual void operator=(const StorageHolder& rCopy); 203 204 //--------------------------------------- 205 /** @short opens a sub element of the specified base storage. 206 207 @descr First this method try to open the requested sub element 208 using the given open mode. If it failed there is second step, 209 which tries to do the same again ... but removing a might existing 210 WRITE flag from the open mode. The user can supress this fallback 211 handling by setting the parameter bAllowFallback to sal_False. 212 213 @param xBaseStorage 214 the storage, where the sub element should be searched. 215 216 @param sSubElement 217 the full name of the sub element. 218 e.g. "default.xml" 219 220 @param eOpenMode 221 a flag field, which set the open mode for this operation. 222 223 @param bAllowFallback 224 if eOpenMode contains an ELEMENT_WRITE flag this parameter 225 allow to remove it and try it with the rest of eOpenMode flags 226 again. 227 */ 228 static css::uno::Reference< css::embed::XStorage > openSubStorageWithFallback(const css::uno::Reference< css::embed::XStorage >& xBaseStorage , 229 const ::rtl::OUString& sSubStorage , 230 sal_Int32 eOpenMode , 231 sal_Bool bAllowFallback); 232 233 static css::uno::Reference< css::io::XStream > openSubStreamWithFallback(const css::uno::Reference< css::embed::XStorage >& xBaseStorage , 234 const ::rtl::OUString& sSubStream , 235 sal_Int32 eOpenMode , 236 sal_Bool bAllowFallback); 237 238 //--------------------------------------- 239 // helper 240 private: 241 242 //----------------------------------- 243 /** @short TODO 244 */ 245 static ::rtl::OUString impl_st_normPath(const ::rtl::OUString& sPath); 246 247 //----------------------------------- 248 /** @short TODO 249 */ 250 static OUStringList impl_st_parsePath(const ::rtl::OUString& sPath); 251 }; 252 253 #undef css // dont let it out! 254 255 } // namespace framework 256 257 #endif // __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_ 258