xref: /aoo42x/main/ucb/source/ucp/tdoc/tdoc_storage.hxx (revision 6df1ea1f)
1*6df1ea1fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6df1ea1fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6df1ea1fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6df1ea1fSAndrew Rist  * distributed with this work for additional information
6*6df1ea1fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6df1ea1fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6df1ea1fSAndrew Rist  * "License"); you may not use this file except in compliance
9*6df1ea1fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6df1ea1fSAndrew Rist  *
11*6df1ea1fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6df1ea1fSAndrew Rist  *
13*6df1ea1fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6df1ea1fSAndrew Rist  * software distributed under the License is distributed on an
15*6df1ea1fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6df1ea1fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*6df1ea1fSAndrew Rist  * specific language governing permissions and limitations
18*6df1ea1fSAndrew Rist  * under the License.
19*6df1ea1fSAndrew Rist  *
20*6df1ea1fSAndrew Rist  *************************************************************/
21*6df1ea1fSAndrew Rist 
22*6df1ea1fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_TDOC_STORAGE_HXX
25cdf0e10cSrcweir #define INCLUDED_TDOC_STORAGE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <map>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "osl/mutex.hxx"
30cdf0e10cSrcweir #include "rtl/ref.hxx"
31cdf0e10cSrcweir #include "salhelper/simplereferenceobject.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "com/sun/star/embed/XStorage.hpp"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace tdoc_ucp {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir     enum StorageAccessMode
38cdf0e10cSrcweir     {
39cdf0e10cSrcweir         READ, // Note: might be writable as well
40cdf0e10cSrcweir         READ_WRITE_NOCREATE,
41cdf0e10cSrcweir         READ_WRITE_CREATE
42cdf0e10cSrcweir     };
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     class Storage;
45cdf0e10cSrcweir     class OfficeDocumentsManager;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     class StorageElementFactory : public salhelper::SimpleReferenceObject
48cdf0e10cSrcweir     {
49cdf0e10cSrcweir     public:
50cdf0e10cSrcweir         StorageElementFactory(
51cdf0e10cSrcweir             const com::sun::star::uno::Reference<
52cdf0e10cSrcweir                 com::sun::star::lang::XMultiServiceFactory > & xSMgr,
53cdf0e10cSrcweir             const rtl::Reference< OfficeDocumentsManager > & xDocsMgr );
54cdf0e10cSrcweir         ~StorageElementFactory();
55cdf0e10cSrcweir 
56cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
57cdf0e10cSrcweir 		createTemporaryStorage()
58cdf0e10cSrcweir             throw ( com::sun::star::uno::Exception,
59cdf0e10cSrcweir             		com::sun::star::uno::RuntimeException );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
62cdf0e10cSrcweir         createStorage( const rtl::OUString & rUri, StorageAccessMode eMode )
63cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
64cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
65cdf0e10cSrcweir                     com::sun::star::io::IOException,
66cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
67cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::io::XInputStream >
70cdf0e10cSrcweir         createInputStream( const rtl::OUString & rUri,
71cdf0e10cSrcweir                            const rtl::OUString & rPassword )
72cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
73cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
74cdf0e10cSrcweir                     com::sun::star::io::IOException,
75cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
76cdf0e10cSrcweir                     com::sun::star::packages::WrongPasswordException,
77cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >
80cdf0e10cSrcweir         createOutputStream( const rtl::OUString & rUri,
81cdf0e10cSrcweir                             const rtl::OUString & rPassword,
82cdf0e10cSrcweir                             bool bTruncate )
83cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
84cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
85cdf0e10cSrcweir                     com::sun::star::io::IOException,
86cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
87cdf0e10cSrcweir                     com::sun::star::packages::WrongPasswordException,
88cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::io::XStream >
91cdf0e10cSrcweir         createStream( const rtl::OUString & rUri,
92cdf0e10cSrcweir                       const rtl::OUString & rPassword,
93cdf0e10cSrcweir                       bool bTruncate )
94cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
95cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
96cdf0e10cSrcweir                     com::sun::star::io::IOException,
97cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
98cdf0e10cSrcweir                     com::sun::star::packages::WrongPasswordException,
99cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     private:
102cdf0e10cSrcweir         friend class Storage;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         void releaseElement( Storage * pElement ) SAL_THROW(());
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
107cdf0e10cSrcweir         queryParentStorage( const rtl::OUString & rUri,
108cdf0e10cSrcweir                             StorageAccessMode eMode )
109cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
110cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
111cdf0e10cSrcweir                     com::sun::star::io::IOException,
112cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
113cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
116cdf0e10cSrcweir         queryStorage( const com::sun::star::uno::Reference<
117cdf0e10cSrcweir                         com::sun::star::embed::XStorage > & xParentStorage,
118cdf0e10cSrcweir                       const rtl::OUString & rUri,
119cdf0e10cSrcweir                       StorageAccessMode eMode )
120cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
121cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
122cdf0e10cSrcweir                     com::sun::star::io::IOException,
123cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
124cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::io::XStream >
127cdf0e10cSrcweir         queryStream( const com::sun::star::uno::Reference<
128cdf0e10cSrcweir                         com::sun::star::embed::XStorage > & xParentStorage,
129cdf0e10cSrcweir                      const rtl::OUString & rPassword,
130cdf0e10cSrcweir                      const rtl::OUString & rUri,
131cdf0e10cSrcweir                      StorageAccessMode eMode,
132cdf0e10cSrcweir                      bool bTruncate /* ignored for read-only streams */ )
133cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
134cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
135cdf0e10cSrcweir                     com::sun::star::io::IOException,
136cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
137cdf0e10cSrcweir                     com::sun::star::packages::WrongPasswordException,
138cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         struct ltstrbool
141cdf0e10cSrcweir         {
operator ()tdoc_ucp::StorageElementFactory::ltstrbool142cdf0e10cSrcweir             bool operator()(
143cdf0e10cSrcweir                 const std::pair< rtl::OUString, bool > & s1,
144cdf0e10cSrcweir                 const std::pair< rtl::OUString, bool > & s2 ) const
145cdf0e10cSrcweir             {
146cdf0e10cSrcweir                 if ( s1.first < s2.first )
147cdf0e10cSrcweir                     return true;
148cdf0e10cSrcweir                 else if ( s1.first == s2.first )
149cdf0e10cSrcweir                     return ( !s1.second && s2.second );
150cdf0e10cSrcweir                 else
151cdf0e10cSrcweir                     return false;
152cdf0e10cSrcweir             }
153cdf0e10cSrcweir         };
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         // key: pair< storageuri, iswritable >
156cdf0e10cSrcweir         typedef std::map<
157cdf0e10cSrcweir 			std::pair< rtl::OUString, bool >, Storage *, ltstrbool > StorageMap;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         StorageMap m_aMap;
160cdf0e10cSrcweir         osl::Mutex m_aMutex;
161cdf0e10cSrcweir         rtl::Reference< OfficeDocumentsManager > m_xDocsMgr;
162cdf0e10cSrcweir         com::sun::star::uno::Reference<
163cdf0e10cSrcweir             com::sun::star::lang::XMultiServiceFactory > m_xSMgr;
164cdf0e10cSrcweir     };
165cdf0e10cSrcweir 
166cdf0e10cSrcweir } // namespace tdoc_ucp
167cdf0e10cSrcweir 
168cdf0e10cSrcweir #endif /* !INCLUDED_TDOC_STORAGE_HXX */
169