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 #ifndef INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STGELEMS_HXX
21 #define INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STGELEMS_HXX
22 
23 #include <memory>
24 
25 #include <osl/mutex.hxx>
26 #include <rtl/ref.hxx>
27 
28 #include <cppuhelper/implbase.hxx>
29 
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>
37 
38 #include "tdoc_storage.hxx"
39 
40 namespace tdoc_ucp {
41 
43 {
44  osl::Mutex m_aMutex;
45 };
46 
47 
49 {
50 public:
52  const css::uno::Reference< css::embed::XStorage > & xParentStorage,
53  const OUString & rUri );
54 
55  bool isParentARootStorage() const
56  { return m_bParentIsRootStorage; }
57  const css::uno::Reference< css::embed::XStorage >&
59  { return m_xParentStorage; }
60  void setParentStorage( const css::uno::Reference< css::embed::XStorage > & xStg )
61  { osl::MutexGuard aGuard( m_aMutex ); m_xParentStorage = xStg; }
62 
63 private:
64  css::uno::Reference< css::embed::XStorage > m_xParentStorage;
66 };
67 
68 
69 typedef
70  cppu::WeakImplHelper<
71  css::embed::XStorage,
72  css::embed::XTransactedObject > StorageUNOBase;
73 
74 class Storage : public StorageUNOBase, public ParentStorageHolder
75 {
76 public:
77  Storage(
78  const css::uno::Reference< css::uno::XComponentContext > & rxContext,
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;
84 
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;
92 
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;
99 
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;
107 
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;
115 
116  // XElementAccess (base of XNameAccess)
117  virtual css::uno::Type SAL_CALL
118  getElementType() override;
119  virtual sal_Bool SAL_CALL
120  hasElements() override;
121 
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;
165 
166  // XTransactedObject
167  virtual void SAL_CALL commit() override;
168  virtual void SAL_CALL revert() override;
169 
170 private:
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;
178 
179  StorageElementFactory::StorageMap::iterator m_aContainerIt;
180 
181  friend class StorageElementFactory;
182  friend class std::unique_ptr< Storage >;
183 };
184 
185 
186 typedef
187  cppu::WeakImplHelper<
188  css::io::XOutputStream,
189  css::lang::XComponent > OutputStreamUNOBase;
190 
191 class OutputStream : public OutputStreamUNOBase, public ParentStorageHolder
192 {
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;
200 
201  // XInterface
202  virtual css::uno::Any SAL_CALL
203  queryInterface( const css::uno::Type& aType ) override;
204 
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;
211 
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;
220 
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;
229 
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;
239 };
240 
241 
242 typedef cppu::WeakImplHelper< css::io::XStream,
243  css::io::XOutputStream,
244  css::io::XTruncate,
245  css::io::XInputStream,
246  css::lang::XComponent >
248 
250 {
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 );
257 
258  virtual ~Stream() override;
259 
260  // XInterface
261  virtual css::uno::Any SAL_CALL
262  queryInterface( const css::uno::Type& aType ) override;
263 
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;
270 
271  // XStream
272  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
273  getInputStream() override;
274 
275  virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL
276  getOutputStream() override;
277 
278  // XOutputStream
279  virtual void SAL_CALL
280  writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
281 
282  virtual void SAL_CALL
283  flush() override;
284 
285  virtual void SAL_CALL
286  closeOutput() override;
287 
288  // XTruncate
289  virtual void SAL_CALL
290  truncate() override;
291 
292  // XInputStream
293  virtual sal_Int32 SAL_CALL
294  readBytes( css::uno::Sequence< sal_Int8 >& aData,
295  sal_Int32 nBytesToRead ) override;
296 
297  virtual sal_Int32 SAL_CALL
298  readSomeBytes( css::uno::Sequence< sal_Int8 >& aData,
299  sal_Int32 nMaxBytesToRead ) override;
300 
301  virtual void SAL_CALL
302  skipBytes( sal_Int32 nBytesToSkip ) override;
303 
304  virtual sal_Int32 SAL_CALL
305  available() override;
306 
307  virtual void SAL_CALL
308  closeInput() override;
309 
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;
318 
319 private:
321  void commitChanges();
322 
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;
337 };
338 
339 } // namespace tdoc_ucp
340 
341 #endif // INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STGELEMS_HXX
342 
343 /* 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
const char aData[]
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
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
virtual void SAL_CALL release() override
css::uno::Reference< css::uno::XAggregation > m_xAggProxy
virtual sal_Int32 SAL_CALL available() 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
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 void SAL_CALL acquire() 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
bool const m_bIsDocumentStorage
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
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)
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
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)
OString const aName
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