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