1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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"
40 class OfficeDocumentsManager
;
42 class ParentStorageHolder
46 css::uno::Reference
< css::embed::XStorage
> xParentStorage
,
47 const OUString
& rUri
);
49 bool isParentARootStorage() const
50 { return m_bParentIsRootStorage
; }
51 css::uno::Reference
< css::embed::XStorage
>
52 getParentStorage() const
54 std::scoped_lock
aGuard( m_aMutex
);
55 return m_xParentStorage
;
57 void clearParentStorage()
59 std::scoped_lock
aGuard( m_aMutex
);
60 m_xParentStorage
= nullptr;
64 mutable std::mutex m_aMutex
;
65 css::uno::Reference
< css::embed::XStorage
> m_xParentStorage
;
66 bool m_bParentIsRootStorage
;
73 css::embed::XTransactedObject
> StorageUNOBase
;
75 class Storage
: public StorageUNOBase
, public ParentStorageHolder
79 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
80 rtl::Reference
< StorageElementFactory
> xFactory
,
81 const OUString
& rUri
,
82 const css::uno::Reference
< css::embed::XStorage
> & xParentStorage
,
83 const css::uno::Reference
< css::embed::XStorage
> & xStorageToWrap
);
84 virtual ~Storage() override
;
87 virtual css::uno::Any SAL_CALL
queryInterface(
88 const css::uno::Type
& aType
) override
;
89 virtual void SAL_CALL
acquire()
91 virtual void SAL_CALL
release()
94 // XTypeProvider (implemented by base, but needs to be overridden for
95 // delegating to aggregate)
96 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
98 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
99 getImplementationId() override
;
101 // XComponent ( one of XStorage bases )
102 virtual void SAL_CALL
104 virtual void SAL_CALL
105 addEventListener( const css::uno::Reference
< css::lang::XEventListener
> & xListener
) override
;
106 virtual void SAL_CALL
107 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
109 // XNameAccess ( one of XStorage bases )
110 virtual css::uno::Any SAL_CALL
111 getByName( const OUString
& aName
) override
;
112 virtual css::uno::Sequence
< OUString
> SAL_CALL
113 getElementNames() override
;
114 virtual sal_Bool SAL_CALL
115 hasByName( const OUString
& aName
) override
;
117 // XElementAccess (base of XNameAccess)
118 virtual css::uno::Type SAL_CALL
119 getElementType() override
;
120 virtual sal_Bool SAL_CALL
121 hasElements() override
;
124 virtual void SAL_CALL
125 copyToStorage( const css::uno::Reference
< css::embed::XStorage
>& xDest
) override
;
126 virtual css::uno::Reference
< css::io::XStream
> SAL_CALL
127 openStreamElement( const OUString
& aStreamName
,
128 sal_Int32 nOpenMode
) override
;
129 virtual css::uno::Reference
< css::io::XStream
> SAL_CALL
130 openEncryptedStreamElement( const OUString
& aStreamName
,
132 const OUString
& aPassword
) override
;
133 virtual css::uno::Reference
< css::embed::XStorage
> SAL_CALL
134 openStorageElement( const OUString
& aStorName
,
135 sal_Int32 nOpenMode
) override
;
136 virtual css::uno::Reference
< css::io::XStream
> SAL_CALL
137 cloneStreamElement( const OUString
& aStreamName
) override
;
138 virtual css::uno::Reference
< css::io::XStream
> SAL_CALL
139 cloneEncryptedStreamElement( const OUString
& aStreamName
,
140 const OUString
& aPassword
) override
;
141 virtual void SAL_CALL
142 copyLastCommitTo( const css::uno::Reference
<
143 css::embed::XStorage
>& xTargetStorage
) override
;
144 virtual void SAL_CALL
145 copyStorageElementLastCommitTo( const OUString
& aStorName
,
146 const css::uno::Reference
<
147 css::embed::XStorage
> &
148 xTargetStorage
) override
;
149 virtual sal_Bool SAL_CALL
150 isStreamElement( const OUString
& aElementName
) override
;
151 virtual sal_Bool SAL_CALL
152 isStorageElement( const OUString
& aElementName
) override
;
153 virtual void SAL_CALL
154 removeElement( const OUString
& aElementName
) override
;
155 virtual void SAL_CALL
156 renameElement( const OUString
& aEleName
,
157 const OUString
& aNewName
) override
;
158 virtual void SAL_CALL
159 copyElementTo( const OUString
& aElementName
,
160 const css::uno::Reference
< css::embed::XStorage
>& xDest
,
161 const OUString
& aNewName
) override
;
162 virtual void SAL_CALL
163 moveElementTo( const OUString
& aElementName
,
164 const css::uno::Reference
< css::embed::XStorage
>& xDest
,
165 const OUString
& rNewName
) override
;
168 virtual void SAL_CALL
commit() override
;
169 virtual void SAL_CALL
revert() override
;
172 rtl::Reference
< StorageElementFactory
> m_xFactory
;
173 css::uno::Reference
< css::uno::XAggregation
> m_xAggProxy
;
174 css::uno::Reference
< css::embed::XStorage
> m_xWrappedStorage
;
175 css::uno::Reference
< css::embed::XTransactedObject
> m_xWrappedTransObj
;
176 css::uno::Reference
< css::lang::XComponent
> m_xWrappedComponent
;
177 css::uno::Reference
< css::lang::XTypeProvider
> m_xWrappedTypeProv
;
178 bool m_bIsDocumentStorage
;
180 StorageElementFactory::StorageMap::iterator m_aContainerIt
;
182 friend class StorageElementFactory
;
187 cppu::WeakImplHelper
<
188 css::io::XOutputStream
,
189 css::lang::XComponent
> OutputStreamUNOBase
;
191 class OutputStream
: public OutputStreamUNOBase
, public ParentStorageHolder
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
;
202 virtual css::uno::Any SAL_CALL
203 queryInterface( const css::uno::Type
& aType
) override
;
205 // XTypeProvider (implemented by base, but needs to be overridden for
206 // delegating to aggregate)
207 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
209 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
210 getImplementationId() override
;
213 virtual void SAL_CALL
214 writeBytes( const css::uno::Sequence
< sal_Int8
>& aData
) override
;
215 virtual void SAL_CALL
217 // Note: We need to intercept this one.
218 virtual void SAL_CALL
219 closeOutput( ) override
;
222 // Note: We need to intercept this one.
223 virtual void SAL_CALL
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
;
232 css::uno::XAggregation
> m_xAggProxy
;
234 css::io::XOutputStream
> m_xWrappedStream
;
236 css::lang::XComponent
> m_xWrappedComponent
;
238 css::lang::XTypeProvider
> m_xWrappedTypeProv
;
242 typedef cppu::WeakImplHelper
< css::io::XStream
,
243 css::io::XOutputStream
,
245 css::io::XInputStream
,
246 css::lang::XComponent
>
249 class Stream
: public StreamUNOBase
, public ParentStorageHolder
253 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
254 rtl::Reference
<OfficeDocumentsManager
> const & docsMgr
,
255 const OUString
& rUri
,
256 const css::uno::Reference
< css::embed::XStorage
> & xParentStorage
,
257 const css::uno::Reference
< css::io::XStream
> & xStreamToWrap
);
259 virtual ~Stream() override
;
262 virtual css::uno::Any SAL_CALL
263 queryInterface( const css::uno::Type
& aType
) override
;
265 // XTypeProvider (implemented by base, but needs to be overridden for
266 // delegating to aggregate)
267 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
269 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
270 getImplementationId() override
;
273 virtual css::uno::Reference
< css::io::XInputStream
> SAL_CALL
274 getInputStream() override
;
276 virtual css::uno::Reference
< css::io::XOutputStream
> SAL_CALL
277 getOutputStream() override
;
280 virtual void SAL_CALL
281 writeBytes( const css::uno::Sequence
< sal_Int8
>& aData
) override
;
283 virtual void SAL_CALL
286 virtual void SAL_CALL
287 closeOutput() override
;
290 virtual void SAL_CALL
294 virtual sal_Int32 SAL_CALL
295 readBytes( css::uno::Sequence
< sal_Int8
>& aData
,
296 sal_Int32 nBytesToRead
) override
;
298 virtual sal_Int32 SAL_CALL
299 readSomeBytes( css::uno::Sequence
< sal_Int8
>& aData
,
300 sal_Int32 nMaxBytesToRead
) override
;
302 virtual void SAL_CALL
303 skipBytes( sal_Int32 nBytesToSkip
) override
;
305 virtual sal_Int32 SAL_CALL
306 available() override
;
308 virtual void SAL_CALL
309 closeInput() override
;
312 // Note: We need to intercept this one.
313 virtual void SAL_CALL
315 virtual void SAL_CALL
316 addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
317 virtual void SAL_CALL
318 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
321 /// @throws css::io::IOException
322 void commitChanges();
324 rtl::Reference
<OfficeDocumentsManager
> m_docsMgr
;
327 css::uno::XAggregation
> m_xAggProxy
;
329 css::io::XStream
> m_xWrappedStream
;
331 css::io::XOutputStream
> m_xWrappedOutputStream
;
333 css::io::XTruncate
> m_xWrappedTruncate
;
335 css::io::XInputStream
> m_xWrappedInputStream
;
337 css::lang::XComponent
> m_xWrappedComponent
;
339 css::lang::XTypeProvider
> m_xWrappedTypeProv
;
342 } // namespace tdoc_ucp
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */