1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_
29 #define __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_
30 
31 //===============================================
32 // own includes
33 
34 #include <accelerators/istoragelistener.hxx>
35 #include <threadhelp/threadhelpbase.hxx>
36 #include <general.h>
37 #include <stdtypes.h>
38 
39 //===============================================
40 // interface includes
41 
42 #ifndef __COM_SUN_STAR_EMBED_XSTORAGE_HPP_
43 #include <com/sun/star/embed/XStorage.hpp>
44 #endif
45 
46 #ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #endif
49 
50 //===============================================
51 // other includes
52 
53 
54 //===============================================
55 // namespace
56 
57 namespace framework
58 {
59 
60 #ifdef css
61     #error "Who defines css? I will use it as namespace alias inside header."
62 #else
63     #define css ::com::sun::star
64 #endif
65 
66 //===============================================
67 // definitions
68 
69 //-----------------------------------------------
70 /**
71     TODO document me
72  */
73 class StorageHolder : private ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ...
74 {
75     //-------------------------------------------
76     // types
77     public:
78 
79         /** @short  TODO */
80         typedef ::std::vector< css::uno::Reference< css::embed::XStorage > > TStorageList;
81 
82         typedef ::std::vector< IStorageListener* > TStorageListenerList;
83 
84         struct TStorageInfo
85         {
86             public:
87                 css::uno::Reference< css::embed::XStorage > Storage;
88                 sal_Int32 UseCount;
89                 TStorageListenerList Listener;
90 
91                 TStorageInfo()
92                     : UseCount(0)
93                 {}
94         };
95 
96         /** @short  TODO */
97         typedef ::std::hash_map< ::rtl::OUString                    ,
98                                  TStorageInfo                       ,
99                                  ::rtl::OUStringHash                ,
100                                  ::std::equal_to< ::rtl::OUString > > TPath2StorageInfo;
101 
102     //-------------------------------------------
103     // member
104     private:
105 
106         /** @short  TODO */
107         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
108 
109         /** @short  TODO */
110         css::uno::Reference< css::embed::XStorage > m_xRoot;
111 
112         /** @short  TODO */
113         TPath2StorageInfo m_lStorages;
114 
115     //-------------------------------------------
116     // interface
117     public:
118 
119         //---------------------------------------
120         /** @short  TODO
121          */
122         StorageHolder();
123 
124         //---------------------------------------
125         /** @short  TODO
126          */
127         StorageHolder(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
128 
129         //---------------------------------------
130         /** @short  TODO
131          */
132         virtual ~StorageHolder();
133 
134         //---------------------------------------
135         /** @short  TODO
136          */
137         virtual void forgetCachedStorages();
138 
139         //---------------------------------------
140         /** @short  TODO
141          */
142         virtual void setRootStorage(const css::uno::Reference< css::embed::XStorage >& xRoot);
143 
144         //---------------------------------------
145         /** @short  TODO
146          */
147         virtual css::uno::Reference< css::embed::XStorage > getRootStorage() const;
148 
149         //---------------------------------------
150         /** @short  TODO
151                     open or get!
152          */
153         virtual css::uno::Reference< css::embed::XStorage > openPath(const ::rtl::OUString& sPath    ,
154                                                                            sal_Int32        nOpenMode);
155 
156         //---------------------------------------
157         /** @short  TODO
158          */
159         virtual StorageHolder::TStorageList getAllPathStorages(const ::rtl::OUString& sPath);
160 
161         //---------------------------------------
162         /** @short  TODO
163          */
164         virtual void commitPath(const ::rtl::OUString& sPath);
165 
166         //---------------------------------------
167         /** @short  TODO
168          */
169         virtual void closePath(const ::rtl::OUString& sPath);
170 
171         //---------------------------------------
172         /** @short  TODO
173          */
174         virtual void notifyPath(const ::rtl::OUString& sPath);
175 
176         //---------------------------------------
177         /** @short  TODO
178          */
179         virtual void addStorageListener(      IStorageListener* pListener,
180                                         const ::rtl::OUString&  sPath    );
181 
182         //---------------------------------------
183         /** @short  TODO
184          */
185         virtual void removeStorageListener(      IStorageListener* pListener,
186                                            const ::rtl::OUString&  sPath    );
187 
188         //---------------------------------------
189         /** @short  TODO
190          */
191         virtual ::rtl::OUString getPathOfStorage(const css::uno::Reference< css::embed::XStorage >& xStorage);
192 
193         //---------------------------------------
194         /** @short  TODO
195          */
196         virtual css::uno::Reference< css::embed::XStorage > getParentStorage(const css::uno::Reference< css::embed::XStorage >& xChild);
197 
198         //---------------------------------------
199         /** @short  TODO
200          */
201         virtual css::uno::Reference< css::embed::XStorage > getParentStorage(const ::rtl::OUString& sChildPath);
202 
203         //---------------------------------------
204         /** @short  TODO
205          */
206         virtual void operator=(const StorageHolder& rCopy);
207 
208         //---------------------------------------
209         /** @short  opens a sub element of the specified base storage.
210 
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 sal_False.
216 
217             @param  xBaseStorage
218                     the storage, where the sub element should be searched.
219 
220             @param  sSubElement
221                     the full name of the sub element.
222                     e.g. "default.xml"
223 
224             @param  eOpenMode
225                     a flag field, which set the open mode for this operation.
226 
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
230                     again.
231          */
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);
236 
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);
241 
242         //---------------------------------------
243         // helper
244         private:
245 
246             //-----------------------------------
247             /** @short  TODO
248              */
249             static ::rtl::OUString impl_st_normPath(const ::rtl::OUString& sPath);
250 
251             //-----------------------------------
252             /** @short  TODO
253              */
254             static OUStringList impl_st_parsePath(const ::rtl::OUString& sPath);
255 };
256 
257 #undef css // dont let it out!
258 
259 } // namespace framework
260 
261 #endif // __FRAMEWORK_ACCELERATORS_STORAGEHOLDER_HXX_
262