xref: /aoo42x/main/ucb/source/ucp/tdoc/tdoc_storage.hxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef INCLUDED_TDOC_STORAGE_HXX
29*cdf0e10cSrcweir #define INCLUDED_TDOC_STORAGE_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <map>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "osl/mutex.hxx"
34*cdf0e10cSrcweir #include "rtl/ref.hxx"
35*cdf0e10cSrcweir #include "salhelper/simplereferenceobject.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "com/sun/star/embed/XStorage.hpp"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir namespace tdoc_ucp {
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir     enum StorageAccessMode
42*cdf0e10cSrcweir     {
43*cdf0e10cSrcweir         READ, // Note: might be writable as well
44*cdf0e10cSrcweir         READ_WRITE_NOCREATE,
45*cdf0e10cSrcweir         READ_WRITE_CREATE
46*cdf0e10cSrcweir     };
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir     class Storage;
49*cdf0e10cSrcweir     class OfficeDocumentsManager;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir     class StorageElementFactory : public salhelper::SimpleReferenceObject
52*cdf0e10cSrcweir     {
53*cdf0e10cSrcweir     public:
54*cdf0e10cSrcweir         StorageElementFactory(
55*cdf0e10cSrcweir             const com::sun::star::uno::Reference<
56*cdf0e10cSrcweir                 com::sun::star::lang::XMultiServiceFactory > & xSMgr,
57*cdf0e10cSrcweir             const rtl::Reference< OfficeDocumentsManager > & xDocsMgr );
58*cdf0e10cSrcweir         ~StorageElementFactory();
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
61*cdf0e10cSrcweir 		createTemporaryStorage()
62*cdf0e10cSrcweir             throw ( com::sun::star::uno::Exception,
63*cdf0e10cSrcweir             		com::sun::star::uno::RuntimeException );
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
66*cdf0e10cSrcweir         createStorage( const rtl::OUString & rUri, StorageAccessMode eMode )
67*cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
68*cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
69*cdf0e10cSrcweir                     com::sun::star::io::IOException,
70*cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
71*cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::io::XInputStream >
74*cdf0e10cSrcweir         createInputStream( const rtl::OUString & rUri,
75*cdf0e10cSrcweir                            const rtl::OUString & rPassword )
76*cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
77*cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
78*cdf0e10cSrcweir                     com::sun::star::io::IOException,
79*cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
80*cdf0e10cSrcweir                     com::sun::star::packages::WrongPasswordException,
81*cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::io::XOutputStream >
84*cdf0e10cSrcweir         createOutputStream( const rtl::OUString & rUri,
85*cdf0e10cSrcweir                             const rtl::OUString & rPassword,
86*cdf0e10cSrcweir                             bool bTruncate )
87*cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
88*cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
89*cdf0e10cSrcweir                     com::sun::star::io::IOException,
90*cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
91*cdf0e10cSrcweir                     com::sun::star::packages::WrongPasswordException,
92*cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::io::XStream >
95*cdf0e10cSrcweir         createStream( const rtl::OUString & rUri,
96*cdf0e10cSrcweir                       const rtl::OUString & rPassword,
97*cdf0e10cSrcweir                       bool bTruncate )
98*cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
99*cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
100*cdf0e10cSrcweir                     com::sun::star::io::IOException,
101*cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
102*cdf0e10cSrcweir                     com::sun::star::packages::WrongPasswordException,
103*cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     private:
106*cdf0e10cSrcweir         friend class Storage;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir         void releaseElement( Storage * pElement ) SAL_THROW(());
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
111*cdf0e10cSrcweir         queryParentStorage( const rtl::OUString & rUri,
112*cdf0e10cSrcweir                             StorageAccessMode eMode )
113*cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
114*cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
115*cdf0e10cSrcweir                     com::sun::star::io::IOException,
116*cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
117*cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::embed::XStorage >
120*cdf0e10cSrcweir         queryStorage( const com::sun::star::uno::Reference<
121*cdf0e10cSrcweir                         com::sun::star::embed::XStorage > & xParentStorage,
122*cdf0e10cSrcweir                       const rtl::OUString & rUri,
123*cdf0e10cSrcweir                       StorageAccessMode eMode )
124*cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
125*cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
126*cdf0e10cSrcweir                     com::sun::star::io::IOException,
127*cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
128*cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir         com::sun::star::uno::Reference< com::sun::star::io::XStream >
131*cdf0e10cSrcweir         queryStream( const com::sun::star::uno::Reference<
132*cdf0e10cSrcweir                         com::sun::star::embed::XStorage > & xParentStorage,
133*cdf0e10cSrcweir                      const rtl::OUString & rPassword,
134*cdf0e10cSrcweir                      const rtl::OUString & rUri,
135*cdf0e10cSrcweir                      StorageAccessMode eMode,
136*cdf0e10cSrcweir                      bool bTruncate /* ignored for read-only streams */ )
137*cdf0e10cSrcweir             throw ( com::sun::star::embed::InvalidStorageException,
138*cdf0e10cSrcweir                     com::sun::star::lang::IllegalArgumentException,
139*cdf0e10cSrcweir                     com::sun::star::io::IOException,
140*cdf0e10cSrcweir                     com::sun::star::embed::StorageWrappedTargetException,
141*cdf0e10cSrcweir                     com::sun::star::packages::WrongPasswordException,
142*cdf0e10cSrcweir                     com::sun::star::uno::RuntimeException );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir         struct ltstrbool
145*cdf0e10cSrcweir         {
146*cdf0e10cSrcweir             bool operator()(
147*cdf0e10cSrcweir                 const std::pair< rtl::OUString, bool > & s1,
148*cdf0e10cSrcweir                 const std::pair< rtl::OUString, bool > & s2 ) const
149*cdf0e10cSrcweir             {
150*cdf0e10cSrcweir                 if ( s1.first < s2.first )
151*cdf0e10cSrcweir                     return true;
152*cdf0e10cSrcweir                 else if ( s1.first == s2.first )
153*cdf0e10cSrcweir                     return ( !s1.second && s2.second );
154*cdf0e10cSrcweir                 else
155*cdf0e10cSrcweir                     return false;
156*cdf0e10cSrcweir             }
157*cdf0e10cSrcweir         };
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir         // key: pair< storageuri, iswritable >
160*cdf0e10cSrcweir         typedef std::map<
161*cdf0e10cSrcweir 			std::pair< rtl::OUString, bool >, Storage *, ltstrbool > StorageMap;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir         StorageMap m_aMap;
164*cdf0e10cSrcweir         osl::Mutex m_aMutex;
165*cdf0e10cSrcweir         rtl::Reference< OfficeDocumentsManager > m_xDocsMgr;
166*cdf0e10cSrcweir         com::sun::star::uno::Reference<
167*cdf0e10cSrcweir             com::sun::star::lang::XMultiServiceFactory > m_xSMgr;
168*cdf0e10cSrcweir     };
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir } // namespace tdoc_ucp
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir #endif /* !INCLUDED_TDOC_STORAGE_HXX */
173