xref: /aoo42x/main/ucb/source/ucp/tdoc/tdoc_storage.hxx (revision 6df1ea1f)
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 INCLUDED_TDOC_STORAGE_HXX
25 #define INCLUDED_TDOC_STORAGE_HXX
26 
27 #include <map>
28 
29 #include "osl/mutex.hxx"
30 #include "rtl/ref.hxx"
31 #include "salhelper/simplereferenceobject.hxx"
32 
33 #include "com/sun/star/embed/XStorage.hpp"
34 
35 namespace tdoc_ucp {
36 
37     enum StorageAccessMode
38     {
39         READ, // Note: might be writable as well
40         READ_WRITE_NOCREATE,
41         READ_WRITE_CREATE
42     };
43 
44     class Storage;
45     class OfficeDocumentsManager;
46 
47     class StorageElementFactory : public salhelper::SimpleReferenceObject
48     {
49     public:
50         StorageElementFactory(
51             const com::sun::star::uno::Reference<
52                 com::sun::star::lang::XMultiServiceFactory > & xSMgr,
53             const rtl::Reference< OfficeDocumentsManager > & xDocsMgr );
54         ~StorageElementFactory();
55 
56         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
57 		createTemporaryStorage()
58             throw ( com::sun::star::uno::Exception,
59             		com::sun::star::uno::RuntimeException );
60 
61         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
62         createStorage( const rtl::OUString & rUri, StorageAccessMode eMode )
63             throw ( com::sun::star::embed::InvalidStorageException,
64                     com::sun::star::lang::IllegalArgumentException,
65                     com::sun::star::io::IOException,
66                     com::sun::star::embed::StorageWrappedTargetException,
67                     com::sun::star::uno::RuntimeException );
68 
69         com::sun::star::uno::Reference< com::sun::star::io::XInputStream >
70         createInputStream( const rtl::OUString & rUri,
71                            const rtl::OUString & rPassword )
72             throw ( com::sun::star::embed::InvalidStorageException,
73                     com::sun::star::lang::IllegalArgumentException,
74                     com::sun::star::io::IOException,
75                     com::sun::star::embed::StorageWrappedTargetException,
76                     com::sun::star::packages::WrongPasswordException,
77                     com::sun::star::uno::RuntimeException );
78 
79         com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >
80         createOutputStream( const rtl::OUString & rUri,
81                             const rtl::OUString & rPassword,
82                             bool bTruncate )
83             throw ( com::sun::star::embed::InvalidStorageException,
84                     com::sun::star::lang::IllegalArgumentException,
85                     com::sun::star::io::IOException,
86                     com::sun::star::embed::StorageWrappedTargetException,
87                     com::sun::star::packages::WrongPasswordException,
88                     com::sun::star::uno::RuntimeException );
89 
90         com::sun::star::uno::Reference< com::sun::star::io::XStream >
91         createStream( const rtl::OUString & rUri,
92                       const rtl::OUString & rPassword,
93                       bool bTruncate )
94             throw ( com::sun::star::embed::InvalidStorageException,
95                     com::sun::star::lang::IllegalArgumentException,
96                     com::sun::star::io::IOException,
97                     com::sun::star::embed::StorageWrappedTargetException,
98                     com::sun::star::packages::WrongPasswordException,
99                     com::sun::star::uno::RuntimeException );
100 
101     private:
102         friend class Storage;
103 
104         void releaseElement( Storage * pElement ) SAL_THROW(());
105 
106         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
107         queryParentStorage( const rtl::OUString & rUri,
108                             StorageAccessMode eMode )
109             throw ( com::sun::star::embed::InvalidStorageException,
110                     com::sun::star::lang::IllegalArgumentException,
111                     com::sun::star::io::IOException,
112                     com::sun::star::embed::StorageWrappedTargetException,
113                     com::sun::star::uno::RuntimeException );
114 
115         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
116         queryStorage( const com::sun::star::uno::Reference<
117                         com::sun::star::embed::XStorage > & xParentStorage,
118                       const rtl::OUString & rUri,
119                       StorageAccessMode eMode )
120             throw ( com::sun::star::embed::InvalidStorageException,
121                     com::sun::star::lang::IllegalArgumentException,
122                     com::sun::star::io::IOException,
123                     com::sun::star::embed::StorageWrappedTargetException,
124                     com::sun::star::uno::RuntimeException );
125 
126         com::sun::star::uno::Reference< com::sun::star::io::XStream >
127         queryStream( const com::sun::star::uno::Reference<
128                         com::sun::star::embed::XStorage > & xParentStorage,
129                      const rtl::OUString & rPassword,
130                      const rtl::OUString & rUri,
131                      StorageAccessMode eMode,
132                      bool bTruncate /* ignored for read-only streams */ )
133             throw ( com::sun::star::embed::InvalidStorageException,
134                     com::sun::star::lang::IllegalArgumentException,
135                     com::sun::star::io::IOException,
136                     com::sun::star::embed::StorageWrappedTargetException,
137                     com::sun::star::packages::WrongPasswordException,
138                     com::sun::star::uno::RuntimeException );
139 
140         struct ltstrbool
141         {
operator ()tdoc_ucp::StorageElementFactory::ltstrbool142             bool operator()(
143                 const std::pair< rtl::OUString, bool > & s1,
144                 const std::pair< rtl::OUString, bool > & s2 ) const
145             {
146                 if ( s1.first < s2.first )
147                     return true;
148                 else if ( s1.first == s2.first )
149                     return ( !s1.second && s2.second );
150                 else
151                     return false;
152             }
153         };
154 
155         // key: pair< storageuri, iswritable >
156         typedef std::map<
157 			std::pair< rtl::OUString, bool >, Storage *, ltstrbool > StorageMap;
158 
159         StorageMap m_aMap;
160         osl::Mutex m_aMutex;
161         rtl::Reference< OfficeDocumentsManager > m_xDocsMgr;
162         com::sun::star::uno::Reference<
163             com::sun::star::lang::XMultiServiceFactory > m_xSMgr;
164     };
165 
166 } // namespace tdoc_ucp
167 
168 #endif /* !INCLUDED_TDOC_STORAGE_HXX */
169