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