bump product version to 7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_stgelems.hxx
blob6229923f226c0ac4ab0aa6886cae37ce0c6b92e2
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 #pragma once
22 #include <rtl/ref.hxx>
24 #include <cppuhelper/implbase.hxx>
26 #include <com/sun/star/embed/XStorage.hpp>
27 #include <com/sun/star/embed/XTransactedObject.hpp>
28 #include <com/sun/star/io/XOutputStream.hpp>
29 #include <com/sun/star/io/XStream.hpp>
30 #include <com/sun/star/io/XTruncate.hpp>
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/uno/XAggregation.hpp>
34 #include "tdoc_storage.hxx"
36 #include <mutex>
38 namespace tdoc_ucp {
40 class OfficeDocumentsManager;
42 class ParentStorageHolder
44 public:
45 ParentStorageHolder(
46 css::uno::Reference< css::embed::XStorage > xParentStorage,
47 const OUString & rUri );
49 bool isParentARootStorage() const
50 { return m_bParentIsRootStorage; }
51 const css::uno::Reference< css::embed::XStorage >&
52 getParentStorage() const
53 { return m_xParentStorage; }
54 void setParentStorage( const css::uno::Reference< css::embed::XStorage > & xStg )
56 std::scoped_lock aGuard( m_aMutex );
57 m_xParentStorage = xStg;
60 private:
61 std::mutex m_aMutex;
62 css::uno::Reference< css::embed::XStorage > m_xParentStorage;
63 bool m_bParentIsRootStorage;
67 typedef
68 cppu::WeakImplHelper<
69 css::embed::XStorage,
70 css::embed::XTransactedObject > StorageUNOBase;
72 class Storage : public StorageUNOBase, public ParentStorageHolder
74 public:
75 Storage(
76 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
77 rtl::Reference< StorageElementFactory > xFactory,
78 const OUString & rUri,
79 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
80 const css::uno::Reference< css::embed::XStorage > & xStorageToWrap );
81 virtual ~Storage() override;
83 // XInterface
84 virtual css::uno::Any SAL_CALL queryInterface(
85 const css::uno::Type& aType ) override;
86 virtual void SAL_CALL acquire()
87 noexcept override;
88 virtual void SAL_CALL release()
89 noexcept override;
91 // XTypeProvider (implemented by base, but needs to be overridden for
92 // delegating to aggregate)
93 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
94 getTypes() override;
95 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
96 getImplementationId() override;
98 // XComponent ( one of XStorage bases )
99 virtual void SAL_CALL
100 dispose() override;
101 virtual void SAL_CALL
102 addEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
103 virtual void SAL_CALL
104 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
106 // XNameAccess ( one of XStorage bases )
107 virtual css::uno::Any SAL_CALL
108 getByName( const OUString& aName ) override;
109 virtual css::uno::Sequence< OUString > SAL_CALL
110 getElementNames() override;
111 virtual sal_Bool SAL_CALL
112 hasByName( const OUString& aName ) override;
114 // XElementAccess (base of XNameAccess)
115 virtual css::uno::Type SAL_CALL
116 getElementType() override;
117 virtual sal_Bool SAL_CALL
118 hasElements() override;
120 // XStorage
121 virtual void SAL_CALL
122 copyToStorage( const css::uno::Reference< css::embed::XStorage >& xDest ) override;
123 virtual css::uno::Reference< css::io::XStream > SAL_CALL
124 openStreamElement( const OUString& aStreamName,
125 sal_Int32 nOpenMode ) override;
126 virtual css::uno::Reference< css::io::XStream > SAL_CALL
127 openEncryptedStreamElement( const OUString& aStreamName,
128 sal_Int32 nOpenMode,
129 const OUString& aPassword ) override;
130 virtual css::uno::Reference< css::embed::XStorage > SAL_CALL
131 openStorageElement( const OUString& aStorName,
132 sal_Int32 nOpenMode ) override;
133 virtual css::uno::Reference< css::io::XStream > SAL_CALL
134 cloneStreamElement( const OUString& aStreamName ) override;
135 virtual css::uno::Reference< css::io::XStream > SAL_CALL
136 cloneEncryptedStreamElement( const OUString& aStreamName,
137 const OUString& aPassword ) override;
138 virtual void SAL_CALL
139 copyLastCommitTo( const css::uno::Reference<
140 css::embed::XStorage >& xTargetStorage ) override;
141 virtual void SAL_CALL
142 copyStorageElementLastCommitTo( const OUString& aStorName,
143 const css::uno::Reference<
144 css::embed::XStorage > &
145 xTargetStorage ) override;
146 virtual sal_Bool SAL_CALL
147 isStreamElement( const OUString& aElementName ) override;
148 virtual sal_Bool SAL_CALL
149 isStorageElement( const OUString& aElementName ) override;
150 virtual void SAL_CALL
151 removeElement( const OUString& aElementName ) override;
152 virtual void SAL_CALL
153 renameElement( const OUString& aEleName,
154 const OUString& aNewName ) override;
155 virtual void SAL_CALL
156 copyElementTo( const OUString& aElementName,
157 const css::uno::Reference< css::embed::XStorage >& xDest,
158 const OUString& aNewName ) override;
159 virtual void SAL_CALL
160 moveElementTo( const OUString& aElementName,
161 const css::uno::Reference< css::embed::XStorage >& xDest,
162 const OUString& rNewName ) override;
164 // XTransactedObject
165 virtual void SAL_CALL commit() override;
166 virtual void SAL_CALL revert() override;
168 private:
169 rtl::Reference< StorageElementFactory > m_xFactory;
170 css::uno::Reference< css::uno::XAggregation > m_xAggProxy;
171 css::uno::Reference< css::embed::XStorage > m_xWrappedStorage;
172 css::uno::Reference< css::embed::XTransactedObject > m_xWrappedTransObj;
173 css::uno::Reference< css::lang::XComponent > m_xWrappedComponent;
174 css::uno::Reference< css::lang::XTypeProvider > m_xWrappedTypeProv;
175 bool m_bIsDocumentStorage;
177 StorageElementFactory::StorageMap::iterator m_aContainerIt;
179 friend class StorageElementFactory;
183 typedef
184 cppu::WeakImplHelper<
185 css::io::XOutputStream,
186 css::lang::XComponent > OutputStreamUNOBase;
188 class OutputStream : public OutputStreamUNOBase, public ParentStorageHolder
190 public:
191 OutputStream(
192 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
193 const OUString & rUri,
194 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
195 const css::uno::Reference< css::io::XOutputStream > & xStreamToWrap );
196 virtual ~OutputStream() override;
198 // XInterface
199 virtual css::uno::Any SAL_CALL
200 queryInterface( const css::uno::Type& aType ) override;
202 // XTypeProvider (implemented by base, but needs to be overridden for
203 // delegating to aggregate)
204 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
205 getTypes() override;
206 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
207 getImplementationId() override;
209 // XOutputStream
210 virtual void SAL_CALL
211 writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
212 virtual void SAL_CALL
213 flush( ) override;
214 // Note: We need to intercept this one.
215 virtual void SAL_CALL
216 closeOutput( ) override;
218 // XComponent
219 // Note: We need to intercept this one.
220 virtual void SAL_CALL
221 dispose() override;
222 virtual void SAL_CALL
223 addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
224 virtual void SAL_CALL
225 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
227 private:
228 css::uno::Reference<
229 css::uno::XAggregation > m_xAggProxy;
230 css::uno::Reference<
231 css::io::XOutputStream > m_xWrappedStream;
232 css::uno::Reference<
233 css::lang::XComponent > m_xWrappedComponent;
234 css::uno::Reference<
235 css::lang::XTypeProvider > m_xWrappedTypeProv;
239 typedef cppu::WeakImplHelper< css::io::XStream,
240 css::io::XOutputStream,
241 css::io::XTruncate,
242 css::io::XInputStream,
243 css::lang::XComponent >
244 StreamUNOBase;
246 class Stream : public StreamUNOBase, public ParentStorageHolder
248 public:
249 Stream(
250 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
251 rtl::Reference<OfficeDocumentsManager> const & docsMgr,
252 const OUString & rUri,
253 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
254 const css::uno::Reference< css::io::XStream > & xStreamToWrap );
256 virtual ~Stream() override;
258 // XInterface
259 virtual css::uno::Any SAL_CALL
260 queryInterface( const css::uno::Type& aType ) override;
262 // XTypeProvider (implemented by base, but needs to be overridden for
263 // delegating to aggregate)
264 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
265 getTypes() override;
266 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
267 getImplementationId() override;
269 // XStream
270 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
271 getInputStream() override;
273 virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL
274 getOutputStream() override;
276 // XOutputStream
277 virtual void SAL_CALL
278 writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
280 virtual void SAL_CALL
281 flush() override;
283 virtual void SAL_CALL
284 closeOutput() override;
286 // XTruncate
287 virtual void SAL_CALL
288 truncate() override;
290 // XInputStream
291 virtual sal_Int32 SAL_CALL
292 readBytes( css::uno::Sequence< sal_Int8 >& aData,
293 sal_Int32 nBytesToRead ) override;
295 virtual sal_Int32 SAL_CALL
296 readSomeBytes( css::uno::Sequence< sal_Int8 >& aData,
297 sal_Int32 nMaxBytesToRead ) override;
299 virtual void SAL_CALL
300 skipBytes( sal_Int32 nBytesToSkip ) override;
302 virtual sal_Int32 SAL_CALL
303 available() override;
305 virtual void SAL_CALL
306 closeInput() override;
308 // XComponent
309 // Note: We need to intercept this one.
310 virtual void SAL_CALL
311 dispose() override;
312 virtual void SAL_CALL
313 addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
314 virtual void SAL_CALL
315 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
317 private:
318 /// @throws css::io::IOException
319 void commitChanges();
321 rtl::Reference<OfficeDocumentsManager> m_docsMgr;
322 OUString m_uri;
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 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */