bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_stgelems.hxx
blobeda5390f07b6edcba4bdf811af1eaacc16357f75
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 <memory>
24 #include <osl/mutex.hxx>
25 #include <rtl/ref.hxx>
27 #include <cppuhelper/implbase.hxx>
29 #include <com/sun/star/embed/XStorage.hpp>
30 #include <com/sun/star/embed/XTransactedObject.hpp>
31 #include <com/sun/star/io/XOutputStream.hpp>
32 #include <com/sun/star/io/XStream.hpp>
33 #include <com/sun/star/io/XTruncate.hpp>
34 #include <com/sun/star/lang/XComponent.hpp>
35 #include <com/sun/star/uno/XAggregation.hpp>
37 #include "tdoc_storage.hxx"
39 namespace tdoc_ucp {
41 struct MutexHolder
43 osl::Mutex m_aMutex;
47 class ParentStorageHolder : public MutexHolder
49 public:
50 ParentStorageHolder(
51 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
52 const OUString & rUri );
54 bool isParentARootStorage() const
55 { return m_bParentIsRootStorage; }
56 const css::uno::Reference< css::embed::XStorage >&
57 getParentStorage() const
58 { return m_xParentStorage; }
59 void setParentStorage( const css::uno::Reference< css::embed::XStorage > & xStg )
60 { osl::MutexGuard aGuard( m_aMutex ); m_xParentStorage = xStg; }
62 private:
63 css::uno::Reference< css::embed::XStorage > m_xParentStorage;
64 bool m_bParentIsRootStorage;
68 typedef
69 cppu::WeakImplHelper<
70 css::embed::XStorage,
71 css::embed::XTransactedObject > StorageUNOBase;
73 class Storage : public StorageUNOBase, public ParentStorageHolder
75 public:
76 Storage(
77 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
78 const rtl::Reference< StorageElementFactory > & xFactory,
79 const OUString & rUri,
80 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
81 const css::uno::Reference< css::embed::XStorage > & xStorageToWrap );
82 virtual ~Storage() override;
84 // XInterface
85 virtual css::uno::Any SAL_CALL queryInterface(
86 const css::uno::Type& aType ) override;
87 virtual void SAL_CALL acquire()
88 noexcept override;
89 virtual void SAL_CALL release()
90 noexcept override;
92 // XTypeProvider (implemnented by base, but needs to be overridden for
93 // delegating to aggregate)
94 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
95 getTypes() override;
96 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
97 getImplementationId() override;
99 // XComponent ( one of XStorage bases )
100 virtual void SAL_CALL
101 dispose() override;
102 virtual void SAL_CALL
103 addEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
104 virtual void SAL_CALL
105 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
107 // XNameAccess ( one of XStorage bases )
108 virtual css::uno::Any SAL_CALL
109 getByName( const OUString& aName ) override;
110 virtual css::uno::Sequence< OUString > SAL_CALL
111 getElementNames() override;
112 virtual sal_Bool SAL_CALL
113 hasByName( const OUString& aName ) override;
115 // XElementAccess (base of XNameAccess)
116 virtual css::uno::Type SAL_CALL
117 getElementType() override;
118 virtual sal_Bool SAL_CALL
119 hasElements() override;
121 // XStorage
122 virtual void SAL_CALL
123 copyToStorage( const css::uno::Reference< css::embed::XStorage >& xDest ) override;
124 virtual css::uno::Reference< css::io::XStream > SAL_CALL
125 openStreamElement( const OUString& aStreamName,
126 sal_Int32 nOpenMode ) override;
127 virtual css::uno::Reference< css::io::XStream > SAL_CALL
128 openEncryptedStreamElement( const OUString& aStreamName,
129 sal_Int32 nOpenMode,
130 const OUString& aPassword ) override;
131 virtual css::uno::Reference< css::embed::XStorage > SAL_CALL
132 openStorageElement( const OUString& aStorName,
133 sal_Int32 nOpenMode ) override;
134 virtual css::uno::Reference< css::io::XStream > SAL_CALL
135 cloneStreamElement( const OUString& aStreamName ) override;
136 virtual css::uno::Reference< css::io::XStream > SAL_CALL
137 cloneEncryptedStreamElement( const OUString& aStreamName,
138 const OUString& aPassword ) override;
139 virtual void SAL_CALL
140 copyLastCommitTo( const css::uno::Reference<
141 css::embed::XStorage >& xTargetStorage ) override;
142 virtual void SAL_CALL
143 copyStorageElementLastCommitTo( const OUString& aStorName,
144 const css::uno::Reference<
145 css::embed::XStorage > &
146 xTargetStorage ) override;
147 virtual sal_Bool SAL_CALL
148 isStreamElement( const OUString& aElementName ) override;
149 virtual sal_Bool SAL_CALL
150 isStorageElement( const OUString& aElementName ) override;
151 virtual void SAL_CALL
152 removeElement( const OUString& aElementName ) override;
153 virtual void SAL_CALL
154 renameElement( const OUString& aEleName,
155 const OUString& aNewName ) override;
156 virtual void SAL_CALL
157 copyElementTo( const OUString& aElementName,
158 const css::uno::Reference< css::embed::XStorage >& xDest,
159 const OUString& aNewName ) override;
160 virtual void SAL_CALL
161 moveElementTo( const OUString& aElementName,
162 const css::uno::Reference< css::embed::XStorage >& xDest,
163 const OUString& rNewName ) override;
165 // XTransactedObject
166 virtual void SAL_CALL commit() override;
167 virtual void SAL_CALL revert() override;
169 private:
170 rtl::Reference< StorageElementFactory > m_xFactory;
171 css::uno::Reference< css::uno::XAggregation > m_xAggProxy;
172 css::uno::Reference< css::embed::XStorage > m_xWrappedStorage;
173 css::uno::Reference< css::embed::XTransactedObject > m_xWrappedTransObj;
174 css::uno::Reference< css::lang::XComponent > m_xWrappedComponent;
175 css::uno::Reference< css::lang::XTypeProvider > m_xWrappedTypeProv;
176 bool m_bIsDocumentStorage;
178 StorageElementFactory::StorageMap::iterator m_aContainerIt;
180 friend class StorageElementFactory;
184 typedef
185 cppu::WeakImplHelper<
186 css::io::XOutputStream,
187 css::lang::XComponent > OutputStreamUNOBase;
189 class OutputStream : public OutputStreamUNOBase, public ParentStorageHolder
191 public:
192 OutputStream(
193 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
194 const OUString & rUri,
195 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
196 const css::uno::Reference< css::io::XOutputStream > & xStreamToWrap );
197 virtual ~OutputStream() override;
199 // XInterface
200 virtual css::uno::Any SAL_CALL
201 queryInterface( const css::uno::Type& aType ) override;
203 // XTypeProvider (implemnented by base, but needs to be overridden for
204 // delegating to aggregate)
205 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
206 getTypes() override;
207 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
208 getImplementationId() override;
210 // XOutputStream
211 virtual void SAL_CALL
212 writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
213 virtual void SAL_CALL
214 flush( ) override;
215 // Note: We need to intercept this one.
216 virtual void SAL_CALL
217 closeOutput( ) override;
219 // XComponent
220 // Note: We need to intercept this one.
221 virtual void SAL_CALL
222 dispose() override;
223 virtual void SAL_CALL
224 addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
225 virtual void SAL_CALL
226 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
228 private:
229 css::uno::Reference<
230 css::uno::XAggregation > m_xAggProxy;
231 css::uno::Reference<
232 css::io::XOutputStream > m_xWrappedStream;
233 css::uno::Reference<
234 css::lang::XComponent > m_xWrappedComponent;
235 css::uno::Reference<
236 css::lang::XTypeProvider > m_xWrappedTypeProv;
240 typedef cppu::WeakImplHelper< css::io::XStream,
241 css::io::XOutputStream,
242 css::io::XTruncate,
243 css::io::XInputStream,
244 css::lang::XComponent >
245 StreamUNOBase;
247 class Stream : public StreamUNOBase, public ParentStorageHolder
249 public:
250 Stream(
251 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
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 (implemnented 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 css::uno::Reference<
322 css::uno::XAggregation > m_xAggProxy;
323 css::uno::Reference<
324 css::io::XStream > m_xWrappedStream;
325 css::uno::Reference<
326 css::io::XOutputStream > m_xWrappedOutputStream;
327 css::uno::Reference<
328 css::io::XTruncate > m_xWrappedTruncate;
329 css::uno::Reference<
330 css::io::XInputStream > m_xWrappedInputStream;
331 css::uno::Reference<
332 css::lang::XComponent > m_xWrappedComponent;
333 css::uno::Reference<
334 css::lang::XTypeProvider > m_xWrappedTypeProv;
337 } // namespace tdoc_ucp
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */