1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: storageholder.hxx,v $
10 * $Revision: 1.5.82.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_
32 #define __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_
34 //===============================================
37 #include <accelerators/istoragelistener.hxx>
38 #include <threadhelp/threadhelpbase.hxx>
42 //===============================================
45 #ifndef __COM_SUN_STAR_EMBED_XSTORAGE_HPP_
46 #include <com/sun/star/embed/XStorage.hpp>
49 #ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53 //===============================================
57 //===============================================
64 #error "Who defines css? I will use it as namespace alias inside header."
66 #define css ::com::sun::star
69 //===============================================
72 //-----------------------------------------------
76 class StorageHolder
: private ThreadHelpBase
// attention! Must be the first base class to guarentee right initialize lock ...
78 //-------------------------------------------
83 typedef ::std::vector
< css::uno::Reference
< css::embed::XStorage
> > TStorageList
;
85 typedef ::std::vector
< IStorageListener
* > TStorageListenerList
;
90 css::uno::Reference
< css::embed::XStorage
> Storage
;
92 TStorageListenerList Listener
;
100 typedef ::std::hash_map
< ::rtl::OUString
,
102 ::rtl::OUStringHash
,
103 ::std::equal_to
< ::rtl::OUString
> > TPath2StorageInfo
;
105 //-------------------------------------------
110 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
113 css::uno::Reference
< css::embed::XStorage
> m_xRoot
;
116 TPath2StorageInfo m_lStorages
;
118 //-------------------------------------------
122 //---------------------------------------
127 //---------------------------------------
130 StorageHolder(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
);
132 //---------------------------------------
135 virtual ~StorageHolder();
137 //---------------------------------------
140 virtual void forgetCachedStorages();
142 //---------------------------------------
145 virtual void setRootStorage(const css::uno::Reference
< css::embed::XStorage
>& xRoot
);
147 //---------------------------------------
150 virtual css::uno::Reference
< css::embed::XStorage
> getRootStorage() const;
152 //---------------------------------------
156 virtual css::uno::Reference
< css::embed::XStorage
> openPath(const ::rtl::OUString
& sPath
,
157 sal_Int32 nOpenMode
);
159 //---------------------------------------
162 virtual StorageHolder::TStorageList
getAllPathStorages(const ::rtl::OUString
& sPath
);
164 //---------------------------------------
167 virtual void commitPath(const ::rtl::OUString
& sPath
);
169 //---------------------------------------
172 virtual void closePath(const ::rtl::OUString
& sPath
);
174 //---------------------------------------
177 virtual void notifyPath(const ::rtl::OUString
& sPath
);
179 //---------------------------------------
182 virtual void addStorageListener( IStorageListener
* pListener
,
183 const ::rtl::OUString
& sPath
);
185 //---------------------------------------
188 virtual void removeStorageListener( IStorageListener
* pListener
,
189 const ::rtl::OUString
& sPath
);
191 //---------------------------------------
194 virtual ::rtl::OUString
getPathOfStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
196 //---------------------------------------
199 virtual css::uno::Reference
< css::embed::XStorage
> getParentStorage(const css::uno::Reference
< css::embed::XStorage
>& xChild
);
201 //---------------------------------------
204 virtual css::uno::Reference
< css::embed::XStorage
> getParentStorage(const ::rtl::OUString
& sChildPath
);
206 //---------------------------------------
209 virtual void operator=(const StorageHolder
& rCopy
);
211 //---------------------------------------
212 /** @short opens a sub element of the specified base storage.
214 @descr First this method try to open the requested sub element
215 using the given open mode. If it failed there is second step,
216 which tries to do the same again ... but removing a might existing
217 WRITE flag from the open mode. The user can supress this fallback
218 handling by setting the parameter bAllowFallback to FALSE.
221 the storage, where the sub element should be searched.
224 the full name of the sub element.
228 a flag field, which set the open mode for this operation.
230 @param bAllowFallback
231 if eOpenMode contains an ELEMENT_WRITE flag this parameter
232 allow to remove it and try it with the rest of eOpenMode flags
235 static css::uno::Reference
< css::embed::XStorage
> openSubStorageWithFallback(const css::uno::Reference
< css::embed::XStorage
>& xBaseStorage
,
236 const ::rtl::OUString
& sSubStorage
,
237 sal_Int32 eOpenMode
,
238 sal_Bool bAllowFallback
);
240 static css::uno::Reference
< css::io::XStream
> openSubStreamWithFallback(const css::uno::Reference
< css::embed::XStorage
>& xBaseStorage
,
241 const ::rtl::OUString
& sSubStream
,
242 sal_Int32 eOpenMode
,
243 sal_Bool bAllowFallback
);
245 //---------------------------------------
249 //-----------------------------------
252 static ::rtl::OUString
impl_st_normPath(const ::rtl::OUString
& sPath
);
254 //-----------------------------------
257 static OUStringList
impl_st_parsePath(const ::rtl::OUString
& sPath
);
260 #undef css // dont let it out!
262 } // namespace framework
264 #endif // __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_