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 .
20 #ifndef INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STGELEMS_HXX
21 #define INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STGELEMS_HXX
25 #include <osl/mutex.hxx>
26 #include <rtl/ref.hxx>
28 #include <cppuhelper/implbase.hxx>
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>
38 #include "tdoc_storage.hxx"
48 class ParentStorageHolder
: public MutexHolder
52 const css::uno::Reference
< css::embed::XStorage
> & xParentStorage
,
53 const OUString
& rUri
);
55 bool isParentARootStorage() const
56 { return m_bParentIsRootStorage
; }
57 const css::uno::Reference
< css::embed::XStorage
>&
58 getParentStorage() const
59 { return m_xParentStorage
; }
60 void setParentStorage( const css::uno::Reference
< css::embed::XStorage
> & xStg
)
61 { osl::MutexGuard
aGuard( m_aMutex
); m_xParentStorage
= xStg
; }
64 css::uno::Reference
< css::embed::XStorage
> m_xParentStorage
;
65 bool m_bParentIsRootStorage
;
72 css::embed::XTransactedObject
> StorageUNOBase
;
74 class Storage
: public StorageUNOBase
, public ParentStorageHolder
78 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
79 const rtl::Reference
< StorageElementFactory
> & xFactory
,
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
;
86 virtual css::uno::Any SAL_CALL
queryInterface(
87 const css::uno::Type
& aType
) override
;
88 virtual void SAL_CALL
acquire()
90 virtual void SAL_CALL
release()
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
97 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
98 getImplementationId() override
;
100 // XComponent ( one of XStorage bases )
101 virtual void SAL_CALL
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
;
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
;
116 // XElementAccess (base of XNameAccess)
117 virtual css::uno::Type SAL_CALL
118 getElementType() override
;
119 virtual sal_Bool SAL_CALL
120 hasElements() override
;
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
,
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
;
167 virtual void SAL_CALL
commit() override
;
168 virtual void SAL_CALL
revert() override
;
171 rtl::Reference
< StorageElementFactory
> m_xFactory
;
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
;
177 bool const m_bIsDocumentStorage
;
179 StorageElementFactory::StorageMap::iterator m_aContainerIt
;
181 friend class StorageElementFactory
;
182 friend class std::unique_ptr
< Storage
>;
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 (implemnented 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 const OUString
& rUri
,
255 const css::uno::Reference
< css::embed::XStorage
> & xParentStorage
,
256 const css::uno::Reference
< css::io::XStream
> & xStreamToWrap
);
258 virtual ~Stream() override
;
261 virtual css::uno::Any SAL_CALL
262 queryInterface( const css::uno::Type
& aType
) override
;
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
268 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
269 getImplementationId() override
;
272 virtual css::uno::Reference
< css::io::XInputStream
> SAL_CALL
273 getInputStream() override
;
275 virtual css::uno::Reference
< css::io::XOutputStream
> SAL_CALL
276 getOutputStream() override
;
279 virtual void SAL_CALL
280 writeBytes( const css::uno::Sequence
< sal_Int8
>& aData
) override
;
282 virtual void SAL_CALL
285 virtual void SAL_CALL
286 closeOutput() override
;
289 virtual void SAL_CALL
293 virtual sal_Int32 SAL_CALL
294 readBytes( css::uno::Sequence
< sal_Int8
>& aData
,
295 sal_Int32 nBytesToRead
) override
;
297 virtual sal_Int32 SAL_CALL
298 readSomeBytes( css::uno::Sequence
< sal_Int8
>& aData
,
299 sal_Int32 nMaxBytesToRead
) override
;
301 virtual void SAL_CALL
302 skipBytes( sal_Int32 nBytesToSkip
) override
;
304 virtual sal_Int32 SAL_CALL
305 available() override
;
307 virtual void SAL_CALL
308 closeInput() override
;
311 // Note: We need to intercept this one.
312 virtual void SAL_CALL
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
;
320 /// @throws css::io::IOException
321 void commitChanges();
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 #endif // INCLUDED_UCB_SOURCE_UCP_TDOC_TDOC_STGELEMS_HXX
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */