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 
37 #include "tdoc_storage.hxx"
38 
39 namespace tdoc_ucp {
40 
42 {
43  osl::Mutex m_aMutex;
44 };
45 
46 
48 {
49 public:
51  const css::uno::Reference< css::embed::XStorage > & xParentStorage,
52  const OUString & rUri );
53 
54  bool isParentARootStorage() const
55  { return m_bParentIsRootStorage; }
56  const css::uno::Reference< css::embed::XStorage >&
58  { return m_xParentStorage; }
59  void setParentStorage( const css::uno::Reference< css::embed::XStorage > & xStg )
60  { osl::MutexGuard aGuard( m_aMutex ); m_xParentStorage = xStg; }
61 
62 private:
63  css::uno::Reference< css::embed::XStorage > m_xParentStorage;
65 };
66 
67 
68 typedef
69  cppu::WeakImplHelper<
70  css::embed::XStorage,
71  css::embed::XTransactedObject > StorageUNOBase;
72 
73 class Storage : public StorageUNOBase, public ParentStorageHolder
74 {
75 public:
76  Storage(
77  const css::uno::Reference< css::uno::XComponentContext > & rxContext,
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;
83 
84  // XInterface
85  virtual css::uno::Any SAL_CALL queryInterface(
86  const css::uno::Type& aType ) override;
87  virtual void SAL_CALL acquire()
88  throw () override;
89  virtual void SAL_CALL release()
90  throw () override;
91 
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;
98 
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;
106 
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;
114 
115  // XElementAccess (base of XNameAccess)
116  virtual css::uno::Type SAL_CALL
117  getElementType() override;
118  virtual sal_Bool SAL_CALL
119  hasElements() override;
120 
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;
164 
165  // XTransactedObject
166  virtual void SAL_CALL commit() override;
167  virtual void SAL_CALL revert() override;
168 
169 private:
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;
177 
178  StorageElementFactory::StorageMap::iterator m_aContainerIt;
179 
180  friend class StorageElementFactory;
181  friend class std::unique_ptr< Storage >;
182 };
183 
184 
185 typedef
186  cppu::WeakImplHelper<
187  css::io::XOutputStream,
188  css::lang::XComponent > OutputStreamUNOBase;
189 
190 class OutputStream : public OutputStreamUNOBase, public ParentStorageHolder
191 {
192 public:
193  OutputStream(
194  const css::uno::Reference< css::uno::XComponentContext > & rxContext,
195  const OUString & rUri,
196  const css::uno::Reference< css::embed::XStorage > & xParentStorage,
197  const css::uno::Reference< css::io::XOutputStream > & xStreamToWrap );
198  virtual ~OutputStream() override;
199 
200  // XInterface
201  virtual css::uno::Any SAL_CALL
202  queryInterface( const css::uno::Type& aType ) override;
203 
204  // XTypeProvider (implemnented by base, but needs to be overridden for
205  // delegating to aggregate)
206  virtual css::uno::Sequence< css::uno::Type > SAL_CALL
207  getTypes() override;
208  virtual css::uno::Sequence< sal_Int8 > SAL_CALL
209  getImplementationId() override;
210 
211  // XOutputStream
212  virtual void SAL_CALL
213  writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
214  virtual void SAL_CALL
215  flush( ) override;
216  // Note: We need to intercept this one.
217  virtual void SAL_CALL
218  closeOutput( ) override;
219 
220  // XComponent
221  // Note: We need to intercept this one.
222  virtual void SAL_CALL
223  dispose() override;
224  virtual void SAL_CALL
225  addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
226  virtual void SAL_CALL
227  removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
228 
229 private:
230  css::uno::Reference<
231  css::uno::XAggregation > m_xAggProxy;
232  css::uno::Reference<
233  css::io::XOutputStream > m_xWrappedStream;
234  css::uno::Reference<
235  css::lang::XComponent > m_xWrappedComponent;
236  css::uno::Reference<
237  css::lang::XTypeProvider > m_xWrappedTypeProv;
238 };
239 
240 
241 typedef cppu::WeakImplHelper< css::io::XStream,
242  css::io::XOutputStream,
243  css::io::XTruncate,
244  css::io::XInputStream,
245  css::lang::XComponent >
247 
249 {
250 public:
251  Stream(
252  const css::uno::Reference< css::uno::XComponentContext > & rxContext,
253  const OUString & rUri,
254  const css::uno::Reference< css::embed::XStorage > & xParentStorage,
255  const css::uno::Reference< css::io::XStream > & xStreamToWrap );
256 
257  virtual ~Stream() override;
258 
259  // XInterface
260  virtual css::uno::Any SAL_CALL
261  queryInterface( const css::uno::Type& aType ) override;
262 
263  // XTypeProvider (implemnented by base, but needs to be overridden for
264  // delegating to aggregate)
265  virtual css::uno::Sequence< css::uno::Type > SAL_CALL
266  getTypes() override;
267  virtual css::uno::Sequence< sal_Int8 > SAL_CALL
268  getImplementationId() override;
269 
270  // XStream
271  virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
272  getInputStream() override;
273 
274  virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL
275  getOutputStream() override;
276 
277  // XOutputStream
278  virtual void SAL_CALL
279  writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
280 
281  virtual void SAL_CALL
282  flush() override;
283 
284  virtual void SAL_CALL
285  closeOutput() override;
286 
287  // XTruncate
288  virtual void SAL_CALL
289  truncate() override;
290 
291  // XInputStream
292  virtual sal_Int32 SAL_CALL
293  readBytes( css::uno::Sequence< sal_Int8 >& aData,
294  sal_Int32 nBytesToRead ) override;
295 
296  virtual sal_Int32 SAL_CALL
297  readSomeBytes( css::uno::Sequence< sal_Int8 >& aData,
298  sal_Int32 nMaxBytesToRead ) override;
299 
300  virtual void SAL_CALL
301  skipBytes( sal_Int32 nBytesToSkip ) override;
302 
303  virtual sal_Int32 SAL_CALL
304  available() override;
305 
306  virtual void SAL_CALL
307  closeInput() override;
308 
309  // XComponent
310  // Note: We need to intercept this one.
311  virtual void SAL_CALL
312  dispose() override;
313  virtual void SAL_CALL
314  addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
315  virtual void SAL_CALL
316  removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
317 
318 private:
320  void commitChanges();
321 
322  css::uno::Reference<
323  css::uno::XAggregation > m_xAggProxy;
324  css::uno::Reference<
325  css::io::XStream > m_xWrappedStream;
326  css::uno::Reference<
327  css::io::XOutputStream > m_xWrappedOutputStream;
328  css::uno::Reference<
329  css::io::XTruncate > m_xWrappedTruncate;
330  css::uno::Reference<
331  css::io::XInputStream > m_xWrappedInputStream;
332  css::uno::Reference<
333  css::lang::XComponent > m_xWrappedComponent;
334  css::uno::Reference<
335  css::lang::XTypeProvider > m_xWrappedTypeProv;
336 };
337 
338 } // namespace tdoc_ucp
339 
340 #endif // INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STGELEMS_HXX
341 
342 /* 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