1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_
29 #define __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_
31 //===============================================
34 #include <accelerators/istoragelistener.hxx>
35 #include <threadhelp/threadhelpbase.hxx>
39 //===============================================
42 #ifndef __COM_SUN_STAR_EMBED_XSTORAGE_HPP_
43 #include <com/sun/star/embed/XStorage.hpp>
46 #ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 //===============================================
54 //===============================================
61 #error "Who defines css? I will use it as namespace alias inside header."
63 #define css ::com::sun::star
66 //===============================================
69 //-----------------------------------------------
73 class StorageHolder
: private ThreadHelpBase
// attention! Must be the first base class to guarentee right initialize lock ...
75 //-------------------------------------------
80 typedef ::std::vector
< css::uno::Reference
< css::embed::XStorage
> > TStorageList
;
82 typedef ::std::vector
< IStorageListener
* > TStorageListenerList
;
87 css::uno::Reference
< css::embed::XStorage
> Storage
;
89 TStorageListenerList Listener
;
97 typedef ::std::hash_map
< ::rtl::OUString
,
100 ::std::equal_to
< ::rtl::OUString
> > TPath2StorageInfo
;
102 //-------------------------------------------
107 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
110 css::uno::Reference
< css::embed::XStorage
> m_xRoot
;
113 TPath2StorageInfo m_lStorages
;
115 //-------------------------------------------
119 //---------------------------------------
124 //---------------------------------------
127 StorageHolder(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
);
129 //---------------------------------------
132 virtual ~StorageHolder();
134 //---------------------------------------
137 virtual void forgetCachedStorages();
139 //---------------------------------------
142 virtual void setRootStorage(const css::uno::Reference
< css::embed::XStorage
>& xRoot
);
144 //---------------------------------------
147 virtual css::uno::Reference
< css::embed::XStorage
> getRootStorage() const;
149 //---------------------------------------
153 virtual css::uno::Reference
< css::embed::XStorage
> openPath(const ::rtl::OUString
& sPath
,
154 sal_Int32 nOpenMode
);
156 //---------------------------------------
159 virtual StorageHolder::TStorageList
getAllPathStorages(const ::rtl::OUString
& sPath
);
161 //---------------------------------------
164 virtual void commitPath(const ::rtl::OUString
& sPath
);
166 //---------------------------------------
169 virtual void closePath(const ::rtl::OUString
& sPath
);
171 //---------------------------------------
174 virtual void notifyPath(const ::rtl::OUString
& sPath
);
176 //---------------------------------------
179 virtual void addStorageListener( IStorageListener
* pListener
,
180 const ::rtl::OUString
& sPath
);
182 //---------------------------------------
185 virtual void removeStorageListener( IStorageListener
* pListener
,
186 const ::rtl::OUString
& sPath
);
188 //---------------------------------------
191 virtual ::rtl::OUString
getPathOfStorage(const css::uno::Reference
< css::embed::XStorage
>& xStorage
);
193 //---------------------------------------
196 virtual css::uno::Reference
< css::embed::XStorage
> getParentStorage(const css::uno::Reference
< css::embed::XStorage
>& xChild
);
198 //---------------------------------------
201 virtual css::uno::Reference
< css::embed::XStorage
> getParentStorage(const ::rtl::OUString
& sChildPath
);
203 //---------------------------------------
206 virtual void operator=(const StorageHolder
& rCopy
);
208 //---------------------------------------
209 /** @short opens a sub element of the specified base storage.
211 @descr First this method try to open the requested sub element
212 using the given open mode. If it failed there is second step,
213 which tries to do the same again ... but removing a might existing
214 WRITE flag from the open mode. The user can supress this fallback
215 handling by setting the parameter bAllowFallback to FALSE.
218 the storage, where the sub element should be searched.
221 the full name of the sub element.
225 a flag field, which set the open mode for this operation.
227 @param bAllowFallback
228 if eOpenMode contains an ELEMENT_WRITE flag this parameter
229 allow to remove it and try it with the rest of eOpenMode flags
232 static css::uno::Reference
< css::embed::XStorage
> openSubStorageWithFallback(const css::uno::Reference
< css::embed::XStorage
>& xBaseStorage
,
233 const ::rtl::OUString
& sSubStorage
,
234 sal_Int32 eOpenMode
,
235 sal_Bool bAllowFallback
);
237 static css::uno::Reference
< css::io::XStream
> openSubStreamWithFallback(const css::uno::Reference
< css::embed::XStorage
>& xBaseStorage
,
238 const ::rtl::OUString
& sSubStream
,
239 sal_Int32 eOpenMode
,
240 sal_Bool bAllowFallback
);
242 //---------------------------------------
246 //-----------------------------------
249 static ::rtl::OUString
impl_st_normPath(const ::rtl::OUString
& sPath
);
251 //-----------------------------------
254 static OUStringList
impl_st_parsePath(const ::rtl::OUString
& sPath
);
257 #undef css // dont let it out!
259 } // namespace framework
261 #endif // __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_