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 .
24 #include <osl/mutex.hxx>
25 #include <rtl/ref.hxx>
27 #include <cppuhelper/implbase.hxx>
29 #include <com/sun/star/embed/XStorage.hpp>
30 #include <com/sun/star/embed/XTransactedObject.hpp>
31 #include <com/sun/star/io/XOutputStream.hpp>
32 #include <com/sun/star/io/XStream.hpp>
33 #include <com/sun/star/io/XTruncate.hpp>
34 #include <com/sun/star/lang/XComponent.hpp>
35 #include <com/sun/star/uno/XAggregation.hpp>
37 #include "tdoc_storage.hxx"
47 class ParentStorageHolder
: public MutexHolder
51 const css::uno::Reference
< css::embed::XStorage
> & xParentStorage
,
52 const OUString
& rUri
);
54 bool isParentARootStorage() const
55 { return m_bParentIsRootStorage
; }
56 const css::uno::Reference
< css::embed::XStorage
>&
57 getParentStorage() const
58 { return m_xParentStorage
; }
59 void setParentStorage( const css::uno::Reference
< css::embed::XStorage
> & xStg
)
60 { osl::MutexGuard
aGuard( m_aMutex
); m_xParentStorage
= xStg
; }
63 css::uno::Reference
< css::embed::XStorage
> m_xParentStorage
;
64 bool m_bParentIsRootStorage
;
71 css::embed::XTransactedObject
> StorageUNOBase
;
73 class Storage
: public StorageUNOBase
, public ParentStorageHolder
77 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
78 const rtl::Reference
< StorageElementFactory
> & xFactory
,
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
;
85 virtual css::uno::Any SAL_CALL
queryInterface(
86 const css::uno::Type
& aType
) override
;
87 virtual void SAL_CALL
acquire()
89 virtual void SAL_CALL
release()
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
96 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
97 getImplementationId() override
;
99 // XComponent ( one of XStorage bases )
100 virtual void SAL_CALL
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
;
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
;
115 // XElementAccess (base of XNameAccess)
116 virtual css::uno::Type SAL_CALL
117 getElementType() override
;
118 virtual sal_Bool SAL_CALL
119 hasElements() override
;
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
,
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
;
166 virtual void SAL_CALL
commit() override
;
167 virtual void SAL_CALL
revert() override
;
170 rtl::Reference
< StorageElementFactory
> m_xFactory
;
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
;
176 bool m_bIsDocumentStorage
;
178 StorageElementFactory::StorageMap::iterator m_aContainerIt
;
180 friend class StorageElementFactory
;
185 cppu::WeakImplHelper
<
186 css::io::XOutputStream
,
187 css::lang::XComponent
> OutputStreamUNOBase
;
189 class OutputStream
: public OutputStreamUNOBase
, public ParentStorageHolder
193 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
194 const OUString
& rUri
,
195 const css::uno::Reference
< css::embed::XStorage
> & xParentStorage
,
196 const css::uno::Reference
< css::io::XOutputStream
> & xStreamToWrap
);
197 virtual ~OutputStream() override
;
200 virtual css::uno::Any SAL_CALL
201 queryInterface( const css::uno::Type
& aType
) override
;
203 // XTypeProvider (implemnented by base, but needs to be overridden for
204 // delegating to aggregate)
205 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
207 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
208 getImplementationId() override
;
211 virtual void SAL_CALL
212 writeBytes( const css::uno::Sequence
< sal_Int8
>& aData
) override
;
213 virtual void SAL_CALL
215 // Note: We need to intercept this one.
216 virtual void SAL_CALL
217 closeOutput( ) override
;
220 // Note: We need to intercept this one.
221 virtual void SAL_CALL
223 virtual void SAL_CALL
224 addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
225 virtual void SAL_CALL
226 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
230 css::uno::XAggregation
> m_xAggProxy
;
232 css::io::XOutputStream
> m_xWrappedStream
;
234 css::lang::XComponent
> m_xWrappedComponent
;
236 css::lang::XTypeProvider
> m_xWrappedTypeProv
;
240 typedef cppu::WeakImplHelper
< css::io::XStream
,
241 css::io::XOutputStream
,
243 css::io::XInputStream
,
244 css::lang::XComponent
>
247 class Stream
: public StreamUNOBase
, public ParentStorageHolder
251 const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
,
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 (implemnented 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();
322 css::uno::XAggregation
> m_xAggProxy
;
324 css::io::XStream
> m_xWrappedStream
;
326 css::io::XOutputStream
> m_xWrappedOutputStream
;
328 css::io::XTruncate
> m_xWrappedTruncate
;
330 css::io::XInputStream
> m_xWrappedInputStream
;
332 css::lang::XComponent
> m_xWrappedComponent
;
334 css::lang::XTypeProvider
> m_xWrappedTypeProv
;
337 } // namespace tdoc_ucp
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */