LibreOffice Module ucb (master)  1
tdoc_stgelems.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
22 #include <rtl/ref.hxx>
23 
24 #include <cppuhelper/implbase.hxx>
25 
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>
33 
34 #include "tdoc_storage.hxx"
35 
36 #include <mutex>
37 
38 namespace tdoc_ucp {
39 
41 {
42 public:
44  const css::uno::Reference< css::embed::XStorage > & xParentStorage,
45  const OUString & rUri );
46 
47  bool isParentARootStorage() const
48  { return m_bParentIsRootStorage; }
49  const css::uno::Reference< css::embed::XStorage >&
51  { return m_xParentStorage; }
52  void setParentStorage( const css::uno::Reference< css::embed::XStorage > & xStg )
53  {
54  std::scoped_lock aGuard( m_aMutex );
55  m_xParentStorage = xStg;
56  }
57 
58 private:
59  std::mutex m_aMutex;
60  css::uno::Reference< css::embed::XStorage > m_xParentStorage;
62 };
63 
64 
65 typedef
66  cppu::WeakImplHelper<
67  css::embed::XStorage,
68  css::embed::XTransactedObject > StorageUNOBase;
69 
70 class Storage : public StorageUNOBase, public ParentStorageHolder
71 {
72 public:
73  Storage(
74  const css::uno::Reference< css::uno::XComponentContext > & rxContext,
76  const OUString & rUri,
77  const css::uno::Reference< css::embed::XStorage > & xParentStorage,
78  const css::uno::Reference< css::embed::XStorage > & xStorageToWrap );
79  virtual ~Storage() override;
80 
81  // XInterface
82  virtual css::uno::Any SAL_CALL queryInterface(
83  const css::uno::Type& aType ) override;
84  virtual void SAL_CALL acquire()
85  noexcept override;
86  virtual void SAL_CALL release()
87  noexcept override;
88 
89  // XTypeProvider (implemented by base, but needs to be overridden for
90  // delegating to aggregate)
91  virtual css::uno::Sequence< css::uno::Type > SAL_CALL
92  getTypes() override;
93  virtual css::uno::Sequence< sal_Int8 > SAL_CALL
94  getImplementationId() override;
95 
96  // XComponent ( one of XStorage bases )
97  virtual void SAL_CALL
98  dispose() override;
99  virtual void SAL_CALL
100  addEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
101  virtual void SAL_CALL
102  removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
103 
104  // XNameAccess ( one of XStorage bases )
105  virtual css::uno::Any SAL_CALL
106  getByName( const OUString& aName ) override;
107  virtual css::uno::Sequence< OUString > SAL_CALL
108  getElementNames() override;
109  virtual sal_Bool SAL_CALL
110  hasByName( const OUString& aName ) override;
111 
112  // XElementAccess (base of XNameAccess)
113  virtual css::uno::Type SAL_CALL
114  getElementType() override;
115  virtual sal_Bool SAL_CALL
116  hasElements() override;
117 
118  // XStorage
119  virtual void SAL_CALL
120  copyToStorage( const css::uno::Reference< css::embed::XStorage >& xDest ) override;
121  virtual css::uno::Reference< css::io::XStream > SAL_CALL
122  openStreamElement( const OUString& aStreamName,
123  sal_Int32 nOpenMode ) override;
124  virtual css::uno::Reference< css::io::XStream > SAL_CALL
125  openEncryptedStreamElement( const OUString& aStreamName,
126  sal_Int32 nOpenMode,
127  const OUString& aPassword ) override;
128  virtual css::uno::Reference< css::embed::XStorage > SAL_CALL
129  openStorageElement( const OUString& aStorName,
130  sal_Int32 nOpenMode ) override;
131  virtual css::uno::Reference< css::io::XStream > SAL_CALL
132  cloneStreamElement( const OUString& aStreamName ) override;
133  virtual css::uno::Reference< css::io::XStream > SAL_CALL
134  cloneEncryptedStreamElement( const OUString& aStreamName,
135  const OUString& aPassword ) override;
136  virtual void SAL_CALL
137  copyLastCommitTo( const css::uno::Reference<
138  css::embed::XStorage >& xTargetStorage ) override;
139  virtual void SAL_CALL
140  copyStorageElementLastCommitTo( const OUString& aStorName,
141  const css::uno::Reference<
142  css::embed::XStorage > &
143  xTargetStorage ) override;
144  virtual sal_Bool SAL_CALL
145  isStreamElement( const OUString& aElementName ) override;
146  virtual sal_Bool SAL_CALL
147  isStorageElement( const OUString& aElementName ) override;
148  virtual void SAL_CALL
149  removeElement( const OUString& aElementName ) override;
150  virtual void SAL_CALL
151  renameElement( const OUString& aEleName,
152  const OUString& aNewName ) override;
153  virtual void SAL_CALL
154  copyElementTo( const OUString& aElementName,
155  const css::uno::Reference< css::embed::XStorage >& xDest,
156  const OUString& aNewName ) override;
157  virtual void SAL_CALL
158  moveElementTo( const OUString& aElementName,
159  const css::uno::Reference< css::embed::XStorage >& xDest,
160  const OUString& rNewName ) override;
161 
162  // XTransactedObject
163  virtual void SAL_CALL commit() override;
164  virtual void SAL_CALL revert() override;
165 
166 private:
168  css::uno::Reference< css::uno::XAggregation > m_xAggProxy;
169  css::uno::Reference< css::embed::XStorage > m_xWrappedStorage;
170  css::uno::Reference< css::embed::XTransactedObject > m_xWrappedTransObj;
171  css::uno::Reference< css::lang::XComponent > m_xWrappedComponent;
172  css::uno::Reference< css::lang::XTypeProvider > m_xWrappedTypeProv;
174 
175  StorageElementFactory::StorageMap::iterator m_aContainerIt;
176 
177  friend class StorageElementFactory;
178 };
179 
180 
181 typedef
182  cppu::WeakImplHelper<
183  css::io::XOutputStream,
184  css::lang::XComponent > OutputStreamUNOBase;
185 
186 class OutputStream : public OutputStreamUNOBase, public ParentStorageHolder
187 {
188 public:
189  OutputStream(
190  const css::uno::Reference< css::uno::XComponentContext > & rxContext,
191  const OUString & rUri,
192  const css::uno::Reference< css::embed::XStorage > & xParentStorage,
193  const css::uno::Reference< css::io::XOutputStream > & xStreamToWrap );
194  virtual ~OutputStream() override;
195 
196  // XInterface
197  virtual css::uno::Any SAL_CALL
198  queryInterface( const css::uno::Type& aType ) override;
199 
200  // XTypeProvider (implemented by base, but needs to be overridden for
201  // delegating to aggregate)
202  virtual css::uno::Sequence< css::uno::Type > SAL_CALL
203  getTypes() override;
204  virtual css::uno::Sequence< sal_Int8 > SAL_CALL
205  getImplementationId() override;
206 
207  // XOutputStream
208  virtual void SAL_CALL
209  writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
210  virtual void SAL_CALL
211  flush( ) override;
212  // Note: We need to intercept this one.
213  virtual void SAL_CALL
214  closeOutput( ) override;
215 
216  // XComponent
217  // Note: We need to intercept this one.
218  virtual void SAL_CALL
219  dispose() override;
220  virtual void SAL_CALL
221  addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
222  virtual void SAL_CALL
223  removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
224 
225 private:
226  css::uno::Reference<
227  css::uno::XAggregation > m_xAggProxy;
228  css::uno::Reference<
229  css::io::XOutputStream > m_xWrappedStream;
230  css::uno::Reference<
231  css::lang::XComponent > m_xWrappedComponent;
232  css::uno::Reference<
233  css::lang::XTypeProvider > m_xWrappedTypeProv;
234 };
235 
236 
237 typedef cppu::WeakImplHelper< css::io::XStream,
238  css::io::XOutputStream,
239  css::io::XTruncate,
240  css::io::XInputStream,
241  css::lang::XComponent >
243 
245 {
246 public:
247  Stream(
248  const css::uno::Reference< css::uno::XComponentContext > & rxContext,
249  const OUString & rUri,
250  const css::uno::Reference< css::embed::XStorage > & xParentStorage,
251  const css::uno::Reference< css::io::XStream > & xStreamToWrap );
252 
253  virtual ~Stream() override;
254 
255  // XInterface
256  virtual css::uno::Any SAL_CALL
257  queryInterface( const css::uno::Type& aType ) override;
258 
259  // XTypeProvider (implemented by base, but needs to be overridden for
260  // delegating to aggregate)
261  virtual css::uno::Sequence< css::uno::Type > SAL_CALL
262  getTypes() override;
263  virtual css::uno::Sequence< sal_Int8 > SAL_CALL
264  getImplementationId() override;
265 
266  // XStream
267  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
268  getInputStream() override;
269 
270  virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL
271  getOutputStream() override;
272 
273  // XOutputStream
274  virtual void SAL_CALL
275  writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
276 
277  virtual void SAL_CALL
278  flush() override;
279 
280  virtual void SAL_CALL
281  closeOutput() override;
282 
283  // XTruncate
284  virtual void SAL_CALL
285  truncate() override;
286 
287  // XInputStream
288  virtual sal_Int32 SAL_CALL
289  readBytes( css::uno::Sequence< sal_Int8 >& aData,
290  sal_Int32 nBytesToRead ) override;
291 
292  virtual sal_Int32 SAL_CALL
293  readSomeBytes( css::uno::Sequence< sal_Int8 >& aData,
294  sal_Int32 nMaxBytesToRead ) override;
295 
296  virtual void SAL_CALL
297  skipBytes( sal_Int32 nBytesToSkip ) override;
298 
299  virtual sal_Int32 SAL_CALL
300  available() override;
301 
302  virtual void SAL_CALL
303  closeInput() override;
304 
305  // XComponent
306  // Note: We need to intercept this one.
307  virtual void SAL_CALL
308  dispose() override;
309  virtual void SAL_CALL
310  addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
311  virtual void SAL_CALL
312  removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
313 
314 private:
316  void commitChanges();
317 
318  css::uno::Reference<
319  css::uno::XAggregation > m_xAggProxy;
320  css::uno::Reference<
321  css::io::XStream > m_xWrappedStream;
322  css::uno::Reference<
323  css::io::XOutputStream > m_xWrappedOutputStream;
324  css::uno::Reference<
325  css::io::XTruncate > m_xWrappedTruncate;
326  css::uno::Reference<
327  css::io::XInputStream > m_xWrappedInputStream;
328  css::uno::Reference<
329  css::lang::XComponent > m_xWrappedComponent;
330  css::uno::Reference<
331  css::lang::XTypeProvider > m_xWrappedTypeProv;
332 };
333 
334 } // namespace tdoc_ucp
335 
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void SAL_CALL removeElement(const OUString &aElementName) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual void SAL_CALL copyLastCommitTo(const css::uno::Reference< css::embed::XStorage > &xTargetStorage) override
virtual void SAL_CALL flush() override
virtual void SAL_CALL dispose() override
cppu::WeakImplHelper< css::embed::XStorage, css::embed::XTransactedObject > StorageUNOBase
css::uno::Reference< css::io::XOutputStream > m_xWrappedStream
cppu::WeakImplHelper< css::io::XOutputStream, css::lang::XComponent > OutputStreamUNOBase
const css::uno::Reference< css::embed::XStorage > & getParentStorage() const
virtual void SAL_CALL dispose() override
virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) override
Storage(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const rtl::Reference< StorageElementFactory > &xFactory, const OUString &rUri, const css::uno::Reference< css::embed::XStorage > &xParentStorage, const css::uno::Reference< css::embed::XStorage > &xStorageToWrap)
OutputStream(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &rUri, const css::uno::Reference< css::embed::XStorage > &xParentStorage, const css::uno::Reference< css::io::XOutputStream > &xStreamToWrap)
virtual void SAL_CALL flush() override
css::uno::Reference< css::uno::XAggregation > m_xAggProxy
virtual sal_Int32 SAL_CALL available() override
virtual void SAL_CALL acquire() noexcept override
virtual void SAL_CALL moveElementTo(const OUString &aElementName, const css::uno::Reference< css::embed::XStorage > &xDest, const OUString &rNewName) override
virtual css::uno::Reference< css::io::XStream > SAL_CALL openEncryptedStreamElement(const OUString &aStreamName, sal_Int32 nOpenMode, const OUString &aPassword) override
css::uno::Reference< css::io::XStream > m_xWrappedStream
cppu::WeakImplHelper< css::io::XStream, css::io::XOutputStream, css::io::XTruncate, css::io::XInputStream, css::lang::XComponent > StreamUNOBase
virtual css::uno::Reference< css::io::XStream > SAL_CALL cloneStreamElement(const OUString &aStreamName) override
virtual sal_Bool SAL_CALL hasElements() override
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream() override
css::uno::Reference< css::uno::XAggregation > m_xAggProxy
virtual css::uno::Reference< css::io::XStream > SAL_CALL cloneEncryptedStreamElement(const OUString &aStreamName, const OUString &aPassword) override
virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 > &aData) override
virtual ~Stream() override
virtual void SAL_CALL dispose() override
virtual void SAL_CALL closeOutput() override
rtl::Reference< StorageElementFactory > m_xFactory
constexpr OUStringLiteral aData
virtual css::uno::Type SAL_CALL getElementType() override
virtual void SAL_CALL copyStorageElementLastCommitTo(const OUString &aStorName, const css::uno::Reference< css::embed::XStorage > &xTargetStorage) override
virtual css::uno::Reference< css::embed::XStorage > SAL_CALL openStorageElement(const OUString &aStorName, sal_Int32 nOpenMode) override
virtual ~Storage() override
virtual css::uno::Reference< css::io::XStream > SAL_CALL openStreamElement(const OUString &aStreamName, sal_Int32 nOpenMode) override
virtual sal_Bool SAL_CALL isStorageElement(const OUString &aElementName) override
virtual void SAL_CALL writeBytes(const css::uno::Sequence< sal_Int8 > &aData) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual sal_Int32 SAL_CALL readSomeBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nMaxBytesToRead) override
virtual sal_Bool SAL_CALL isStreamElement(const OUString &aElementName) override
StorageElementFactory::StorageMap::iterator m_aContainerIt
css::uno::Reference< css::embed::XStorage > m_xParentStorage
virtual sal_Int32 SAL_CALL readBytes(css::uno::Sequence< sal_Int8 > &aData, sal_Int32 nBytesToRead) override
unsigned char sal_Bool
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
css::uno::Reference< css::io::XOutputStream > m_xWrappedOutputStream
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
ParentStorageHolder(const css::uno::Reference< css::embed::XStorage > &xParentStorage, const OUString &rUri)
virtual void SAL_CALL copyElementTo(const OUString &aElementName, const css::uno::Reference< css::embed::XStorage > &xDest, const OUString &aNewName) override
css::uno::Reference< css::lang::XTypeProvider > m_xWrappedTypeProv
virtual void SAL_CALL truncate() override
virtual void SAL_CALL commit() override
virtual void SAL_CALL revert() override
css::uno::Reference< css::embed::XTransactedObject > m_xWrappedTransObj
css::uno::Reference< css::lang::XComponent > m_xWrappedComponent
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
css::uno::Reference< css::lang::XComponent > m_xWrappedComponent
virtual void SAL_CALL closeOutput() override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
Stream(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &rUri, const css::uno::Reference< css::embed::XStorage > &xParentStorage, const css::uno::Reference< css::io::XStream > &xStreamToWrap)
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL getOutputStream() override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void SAL_CALL closeInput() override
css::uno::Reference< css::io::XInputStream > m_xWrappedInputStream
virtual void SAL_CALL release() noexcept override
css::uno::Reference< css::lang::XTypeProvider > m_xWrappedTypeProv
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
void setParentStorage(const css::uno::Reference< css::embed::XStorage > &xStg)
OUString aName
virtual void SAL_CALL renameElement(const OUString &aEleName, const OUString &aNewName) override
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual void SAL_CALL copyToStorage(const css::uno::Reference< css::embed::XStorage > &xDest) override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
css::uno::Reference< css::lang::XTypeProvider > m_xWrappedTypeProv
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
virtual ~OutputStream() override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Reference< XSingleServiceFactory > xFactory
css::uno::Reference< css::io::XTruncate > m_xWrappedTruncate
css::uno::Reference< css::lang::XComponent > m_xWrappedComponent
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
css::uno::Reference< css::uno::XAggregation > m_xAggProxy
css::uno::Reference< css::embed::XStorage > m_xWrappedStorage