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 const css::uno::Reference
< css::embed::XStorage
>&
52 getParentStorage() const
53 { return m_xParentStorage
; }
54 void setParentStorage( const css::uno::Reference
< css::embed::XStorage
> & xStg
)
56 std::scoped_lock
aGuard( m_aMutex
);
57 m_xParentStorage
= xStg
;
62 css::uno::Reference
< css::embed::XStorage
> m_xParentStorage
;
63 bool m_bParentIsRootStorage
;
70 css::embed::XTransactedObject
> StorageUNOBase
;
72 class Storage
: public StorageUNOBase
, public ParentStorageHolder
76 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
77 rtl::Reference
< StorageElementFactory
> xFactory
,
78 const OUString
& rUri
,
79 const css::uno::Reference
< css::embed::XStorage
> & xParentStorage
,
80 const css::uno::Reference
< css::embed::XStorage
> & xStorageToWrap
);
81 virtual ~Storage() override
;
84 virtual css::uno::Any SAL_CALL
queryInterface(
85 const css::uno::Type
& aType
) override
;
86 virtual void SAL_CALL
acquire()
88 virtual void SAL_CALL
release()
91 // XTypeProvider (implemented by base, but needs to be overridden for
92 // delegating to aggregate)
93 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
95 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
96 getImplementationId() override
;
98 // XComponent ( one of XStorage bases )
101 virtual void SAL_CALL
102 addEventListener( const css::uno::Reference
< css::lang::XEventListener
> & xListener
) override
;
103 virtual void SAL_CALL
104 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
106 // XNameAccess ( one of XStorage bases )
107 virtual css::uno::Any SAL_CALL
108 getByName( const OUString
& aName
) override
;
109 virtual css::uno::Sequence
< OUString
> SAL_CALL
110 getElementNames() override
;
111 virtual sal_Bool SAL_CALL
112 hasByName( const OUString
& aName
) override
;
114 // XElementAccess (base of XNameAccess)
115 virtual css::uno::Type SAL_CALL
116 getElementType() override
;
117 virtual sal_Bool SAL_CALL
118 hasElements() override
;
121 virtual void SAL_CALL
122 copyToStorage( const css::uno::Reference
< css::embed::XStorage
>& xDest
) override
;
123 virtual css::uno::Reference
< css::io::XStream
> SAL_CALL
124 openStreamElement( const OUString
& aStreamName
,
125 sal_Int32 nOpenMode
) override
;
126 virtual css::uno::Reference
< css::io::XStream
> SAL_CALL
127 openEncryptedStreamElement( const OUString
& aStreamName
,
129 const OUString
& aPassword
) override
;
130 virtual css::uno::Reference
< css::embed::XStorage
> SAL_CALL
131 openStorageElement( const OUString
& aStorName
,
132 sal_Int32 nOpenMode
) override
;
133 virtual css::uno::Reference
< css::io::XStream
> SAL_CALL
134 cloneStreamElement( const OUString
& aStreamName
) override
;
135 virtual css::uno::Reference
< css::io::XStream
> SAL_CALL
136 cloneEncryptedStreamElement( const OUString
& aStreamName
,
137 const OUString
& aPassword
) override
;
138 virtual void SAL_CALL
139 copyLastCommitTo( const css::uno::Reference
<
140 css::embed::XStorage
>& xTargetStorage
) override
;
141 virtual void SAL_CALL
142 copyStorageElementLastCommitTo( const OUString
& aStorName
,
143 const css::uno::Reference
<
144 css::embed::XStorage
> &
145 xTargetStorage
) override
;
146 virtual sal_Bool SAL_CALL
147 isStreamElement( const OUString
& aElementName
) override
;
148 virtual sal_Bool SAL_CALL
149 isStorageElement( const OUString
& aElementName
) override
;
150 virtual void SAL_CALL
151 removeElement( const OUString
& aElementName
) override
;
152 virtual void SAL_CALL
153 renameElement( const OUString
& aEleName
,
154 const OUString
& aNewName
) override
;
155 virtual void SAL_CALL
156 copyElementTo( const OUString
& aElementName
,
157 const css::uno::Reference
< css::embed::XStorage
>& xDest
,
158 const OUString
& aNewName
) override
;
159 virtual void SAL_CALL
160 moveElementTo( const OUString
& aElementName
,
161 const css::uno::Reference
< css::embed::XStorage
>& xDest
,
162 const OUString
& rNewName
) override
;
165 virtual void SAL_CALL
commit() override
;
166 virtual void SAL_CALL
revert() override
;
169 rtl::Reference
< StorageElementFactory
> m_xFactory
;
170 css::uno::Reference
< css::uno::XAggregation
> m_xAggProxy
;
171 css::uno::Reference
< css::embed::XStorage
> m_xWrappedStorage
;
172 css::uno::Reference
< css::embed::XTransactedObject
> m_xWrappedTransObj
;
173 css::uno::Reference
< css::lang::XComponent
> m_xWrappedComponent
;
174 css::uno::Reference
< css::lang::XTypeProvider
> m_xWrappedTypeProv
;
175 bool m_bIsDocumentStorage
;
177 StorageElementFactory::StorageMap::iterator m_aContainerIt
;
179 friend class StorageElementFactory
;
184 cppu::WeakImplHelper
<
185 css::io::XOutputStream
,
186 css::lang::XComponent
> OutputStreamUNOBase
;
188 class OutputStream
: public OutputStreamUNOBase
, public ParentStorageHolder
192 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
193 const OUString
& rUri
,
194 const css::uno::Reference
< css::embed::XStorage
> & xParentStorage
,
195 const css::uno::Reference
< css::io::XOutputStream
> & xStreamToWrap
);
196 virtual ~OutputStream() override
;
199 virtual css::uno::Any SAL_CALL
200 queryInterface( const css::uno::Type
& aType
) override
;
202 // XTypeProvider (implemented by base, but needs to be overridden for
203 // delegating to aggregate)
204 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
206 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
207 getImplementationId() override
;
210 virtual void SAL_CALL
211 writeBytes( const css::uno::Sequence
< sal_Int8
>& aData
) override
;
212 virtual void SAL_CALL
214 // Note: We need to intercept this one.
215 virtual void SAL_CALL
216 closeOutput( ) override
;
219 // Note: We need to intercept this one.
220 virtual void SAL_CALL
222 virtual void SAL_CALL
223 addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
224 virtual void SAL_CALL
225 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
229 css::uno::XAggregation
> m_xAggProxy
;
231 css::io::XOutputStream
> m_xWrappedStream
;
233 css::lang::XComponent
> m_xWrappedComponent
;
235 css::lang::XTypeProvider
> m_xWrappedTypeProv
;
239 typedef cppu::WeakImplHelper
< css::io::XStream
,
240 css::io::XOutputStream
,
242 css::io::XInputStream
,
243 css::lang::XComponent
>
246 class Stream
: public StreamUNOBase
, public ParentStorageHolder
250 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
251 rtl::Reference
<OfficeDocumentsManager
> const & docsMgr
,
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
;
259 virtual css::uno::Any SAL_CALL
260 queryInterface( const css::uno::Type
& aType
) override
;
262 // XTypeProvider (implemented by base, but needs to be overridden for
263 // delegating to aggregate)
264 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
266 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
267 getImplementationId() override
;
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
;
277 virtual void SAL_CALL
278 writeBytes( const css::uno::Sequence
< sal_Int8
>& aData
) override
;
280 virtual void SAL_CALL
283 virtual void SAL_CALL
284 closeOutput() override
;
287 virtual void SAL_CALL
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
;
309 // Note: We need to intercept this one.
310 virtual void SAL_CALL
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
;
318 /// @throws css::io::IOException
319 void commitChanges();
321 rtl::Reference
<OfficeDocumentsManager
> m_docsMgr
;
324 css::uno::XAggregation
> m_xAggProxy
;
326 css::io::XStream
> m_xWrappedStream
;
328 css::io::XOutputStream
> m_xWrappedOutputStream
;
330 css::io::XTruncate
> m_xWrappedTruncate
;
332 css::io::XInputStream
> m_xWrappedInputStream
;
334 css::lang::XComponent
> m_xWrappedComponent
;
336 css::lang::XTypeProvider
> m_xWrappedTypeProv
;
339 } // namespace tdoc_ucp
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */