Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_stgelems.hxx
bloba8df298e012d86452684780a7214c16a2635a1df
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STGELEMS_HXX
21 #define INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STGELEMS_HXX
23 #include <memory>
25 #include <osl/mutex.hxx>
26 #include <rtl/ref.hxx>
28 #include <cppuhelper/implbase.hxx>
30 #include <com/sun/star/embed/XStorage.hpp>
31 #include <com/sun/star/embed/XTransactedObject.hpp>
32 #include <com/sun/star/io/XOutputStream.hpp>
33 #include <com/sun/star/io/XStream.hpp>
34 #include <com/sun/star/io/XTruncate.hpp>
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/uno/XAggregation.hpp>
38 #include "tdoc_storage.hxx"
40 namespace tdoc_ucp {
42 struct MutexHolder
44 osl::Mutex m_aMutex;
48 class ParentStorageHolder : public MutexHolder
50 public:
51 ParentStorageHolder(
52 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
53 const OUString & rUri );
55 bool isParentARootStorage() const
56 { return m_bParentIsRootStorage; }
57 const css::uno::Reference< css::embed::XStorage >&
58 getParentStorage() const
59 { return m_xParentStorage; }
60 void setParentStorage( const css::uno::Reference< css::embed::XStorage > & xStg )
61 { osl::MutexGuard aGuard( m_aMutex ); m_xParentStorage = xStg; }
63 private:
64 css::uno::Reference< css::embed::XStorage > m_xParentStorage;
65 bool m_bParentIsRootStorage;
69 typedef
70 cppu::WeakImplHelper<
71 css::embed::XStorage,
72 css::embed::XTransactedObject > StorageUNOBase;
74 class Storage : public StorageUNOBase, public ParentStorageHolder
76 public:
77 Storage(
78 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
79 const rtl::Reference< StorageElementFactory > & xFactory,
80 const OUString & rUri,
81 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
82 const css::uno::Reference< css::embed::XStorage > & xStorageToWrap );
83 virtual ~Storage() override;
85 // XInterface
86 virtual css::uno::Any SAL_CALL queryInterface(
87 const css::uno::Type& aType ) override;
88 virtual void SAL_CALL acquire()
89 throw () override;
90 virtual void SAL_CALL release()
91 throw () override;
93 // XTypeProvider (implemnented by base, but needs to be overridden for
94 // delegating to aggregate)
95 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
96 getTypes() override;
97 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
98 getImplementationId() override;
100 // XComponent ( one of XStorage bases )
101 virtual void SAL_CALL
102 dispose() override;
103 virtual void SAL_CALL
104 addEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
105 virtual void SAL_CALL
106 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
108 // XNameAccess ( one of XStorage bases )
109 virtual css::uno::Any SAL_CALL
110 getByName( const OUString& aName ) override;
111 virtual css::uno::Sequence< OUString > SAL_CALL
112 getElementNames() override;
113 virtual sal_Bool SAL_CALL
114 hasByName( const OUString& aName ) override;
116 // XElementAccess (base of XNameAccess)
117 virtual css::uno::Type SAL_CALL
118 getElementType() override;
119 virtual sal_Bool SAL_CALL
120 hasElements() override;
122 // XStorage
123 virtual void SAL_CALL
124 copyToStorage( const css::uno::Reference< css::embed::XStorage >& xDest ) override;
125 virtual css::uno::Reference< css::io::XStream > SAL_CALL
126 openStreamElement( const OUString& aStreamName,
127 sal_Int32 nOpenMode ) override;
128 virtual css::uno::Reference< css::io::XStream > SAL_CALL
129 openEncryptedStreamElement( const OUString& aStreamName,
130 sal_Int32 nOpenMode,
131 const OUString& aPassword ) override;
132 virtual css::uno::Reference< css::embed::XStorage > SAL_CALL
133 openStorageElement( const OUString& aStorName,
134 sal_Int32 nOpenMode ) override;
135 virtual css::uno::Reference< css::io::XStream > SAL_CALL
136 cloneStreamElement( const OUString& aStreamName ) override;
137 virtual css::uno::Reference< css::io::XStream > SAL_CALL
138 cloneEncryptedStreamElement( const OUString& aStreamName,
139 const OUString& aPassword ) override;
140 virtual void SAL_CALL
141 copyLastCommitTo( const css::uno::Reference<
142 css::embed::XStorage >& xTargetStorage ) override;
143 virtual void SAL_CALL
144 copyStorageElementLastCommitTo( const OUString& aStorName,
145 const css::uno::Reference<
146 css::embed::XStorage > &
147 xTargetStorage ) override;
148 virtual sal_Bool SAL_CALL
149 isStreamElement( const OUString& aElementName ) override;
150 virtual sal_Bool SAL_CALL
151 isStorageElement( const OUString& aElementName ) override;
152 virtual void SAL_CALL
153 removeElement( const OUString& aElementName ) override;
154 virtual void SAL_CALL
155 renameElement( const OUString& aEleName,
156 const OUString& aNewName ) override;
157 virtual void SAL_CALL
158 copyElementTo( const OUString& aElementName,
159 const css::uno::Reference< css::embed::XStorage >& xDest,
160 const OUString& aNewName ) override;
161 virtual void SAL_CALL
162 moveElementTo( const OUString& aElementName,
163 const css::uno::Reference< css::embed::XStorage >& xDest,
164 const OUString& rNewName ) override;
166 // XTransactedObject
167 virtual void SAL_CALL commit() override;
168 virtual void SAL_CALL revert() override;
170 private:
171 rtl::Reference< StorageElementFactory > m_xFactory;
172 css::uno::Reference< css::uno::XAggregation > m_xAggProxy;
173 css::uno::Reference< css::embed::XStorage > m_xWrappedStorage;
174 css::uno::Reference< css::embed::XTransactedObject > m_xWrappedTransObj;
175 css::uno::Reference< css::lang::XComponent > m_xWrappedComponent;
176 css::uno::Reference< css::lang::XTypeProvider > m_xWrappedTypeProv;
177 bool const m_bIsDocumentStorage;
179 StorageElementFactory::StorageMap::iterator m_aContainerIt;
181 friend class StorageElementFactory;
182 friend class std::unique_ptr< Storage >;
186 typedef
187 cppu::WeakImplHelper<
188 css::io::XOutputStream,
189 css::lang::XComponent > OutputStreamUNOBase;
191 class OutputStream : public OutputStreamUNOBase, public ParentStorageHolder
193 public:
194 OutputStream(
195 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
196 const OUString & rUri,
197 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
198 const css::uno::Reference< css::io::XOutputStream > & xStreamToWrap );
199 virtual ~OutputStream() override;
201 // XInterface
202 virtual css::uno::Any SAL_CALL
203 queryInterface( const css::uno::Type& aType ) override;
205 // XTypeProvider (implemnented by base, but needs to be overridden for
206 // delegating to aggregate)
207 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
208 getTypes() override;
209 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
210 getImplementationId() override;
212 // XOutputStream
213 virtual void SAL_CALL
214 writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
215 virtual void SAL_CALL
216 flush( ) override;
217 // Note: We need to intercept this one.
218 virtual void SAL_CALL
219 closeOutput( ) override;
221 // XComponent
222 // Note: We need to intercept this one.
223 virtual void SAL_CALL
224 dispose() override;
225 virtual void SAL_CALL
226 addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
227 virtual void SAL_CALL
228 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
230 private:
231 css::uno::Reference<
232 css::uno::XAggregation > m_xAggProxy;
233 css::uno::Reference<
234 css::io::XOutputStream > m_xWrappedStream;
235 css::uno::Reference<
236 css::lang::XComponent > m_xWrappedComponent;
237 css::uno::Reference<
238 css::lang::XTypeProvider > m_xWrappedTypeProv;
242 typedef cppu::WeakImplHelper< css::io::XStream,
243 css::io::XOutputStream,
244 css::io::XTruncate,
245 css::io::XInputStream,
246 css::lang::XComponent >
247 StreamUNOBase;
249 class Stream : public StreamUNOBase, public ParentStorageHolder
251 public:
252 Stream(
253 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
254 const OUString & rUri,
255 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
256 const css::uno::Reference< css::io::XStream > & xStreamToWrap );
258 virtual ~Stream() override;
260 // XInterface
261 virtual css::uno::Any SAL_CALL
262 queryInterface( const css::uno::Type& aType ) override;
264 // XTypeProvider (implemnented by base, but needs to be overridden for
265 // delegating to aggregate)
266 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
267 getTypes() override;
268 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
269 getImplementationId() override;
271 // XStream
272 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
273 getInputStream() override;
275 virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL
276 getOutputStream() override;
278 // XOutputStream
279 virtual void SAL_CALL
280 writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
282 virtual void SAL_CALL
283 flush() override;
285 virtual void SAL_CALL
286 closeOutput() override;
288 // XTruncate
289 virtual void SAL_CALL
290 truncate() override;
292 // XInputStream
293 virtual sal_Int32 SAL_CALL
294 readBytes( css::uno::Sequence< sal_Int8 >& aData,
295 sal_Int32 nBytesToRead ) override;
297 virtual sal_Int32 SAL_CALL
298 readSomeBytes( css::uno::Sequence< sal_Int8 >& aData,
299 sal_Int32 nMaxBytesToRead ) override;
301 virtual void SAL_CALL
302 skipBytes( sal_Int32 nBytesToSkip ) override;
304 virtual sal_Int32 SAL_CALL
305 available() override;
307 virtual void SAL_CALL
308 closeInput() override;
310 // XComponent
311 // Note: We need to intercept this one.
312 virtual void SAL_CALL
313 dispose() override;
314 virtual void SAL_CALL
315 addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
316 virtual void SAL_CALL
317 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
319 private:
320 /// @throws css::io::IOException
321 void commitChanges();
323 css::uno::Reference<
324 css::uno::XAggregation > m_xAggProxy;
325 css::uno::Reference<
326 css::io::XStream > m_xWrappedStream;
327 css::uno::Reference<
328 css::io::XOutputStream > m_xWrappedOutputStream;
329 css::uno::Reference<
330 css::io::XTruncate > m_xWrappedTruncate;
331 css::uno::Reference<
332 css::io::XInputStream > m_xWrappedInputStream;
333 css::uno::Reference<
334 css::lang::XComponent > m_xWrappedComponent;
335 css::uno::Reference<
336 css::lang::XTypeProvider > m_xWrappedTypeProv;
339 } // namespace tdoc_ucp
341 #endif // INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STGELEMS_HXX
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */