1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef INCLUDED_TDOC_STGELEMS_HXX
30 #define INCLUDED_TDOC_STGELEMS_HXX
34 #include "osl/mutex.hxx"
35 #include "rtl/ref.hxx"
37 #include "cppuhelper/implbase2.hxx"
38 #include "cppuhelper/implbase5.hxx"
40 #include "com/sun/star/embed/XStorage.hpp"
41 #include "com/sun/star/embed/XTransactedObject.hpp"
42 #include "com/sun/star/io/XOutputStream.hpp"
43 #include "com/sun/star/io/XStream.hpp"
44 #include "com/sun/star/io/XTruncate.hpp"
45 #include "com/sun/star/lang/XComponent.hpp"
47 #include "tdoc_storage.hxx"
56 //=======================================================================
58 class ParentStorageHolder
: public MutexHolder
62 const com::sun::star::uno::Reference
<
63 com::sun::star::embed::XStorage
> & xParentStorage
,
64 const rtl::OUString
& rUri
);
66 bool isParentARootStorage() const
67 { return m_bParentIsRootStorage
; }
68 com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>
69 getParentStorage() const
70 { return m_xParentStorage
; }
71 void setParentStorage( const com::sun::star::uno::Reference
<
72 com::sun::star::embed::XStorage
> & xStg
)
73 { osl::MutexGuard
aGuard( m_aMutex
); m_xParentStorage
= xStg
; }
76 com::sun::star::uno::Reference
<
77 com::sun::star::embed::XStorage
> m_xParentStorage
;
78 bool m_bParentIsRootStorage
;
81 //=======================================================================
84 cppu::WeakImplHelper2
<
85 com::sun::star::embed::XStorage
,
86 com::sun::star::embed::XTransactedObject
> StorageUNOBase
;
88 class Storage
: public StorageUNOBase
, public ParentStorageHolder
92 const com::sun::star::uno::Reference
<
93 com::sun::star::lang::XMultiServiceFactory
> & xSMgr
,
94 const rtl::Reference
< StorageElementFactory
> & xFactory
,
95 const rtl::OUString
& rUri
,
96 const com::sun::star::uno::Reference
<
97 com::sun::star::embed::XStorage
> & xParentStorage
,
98 const com::sun::star::uno::Reference
<
99 com::sun::star::embed::XStorage
> & xStorageToWrap
);
102 bool isDocumentStorage() const { return m_bIsDocumentStorage
; }
105 virtual com::sun::star::uno::Any SAL_CALL
queryInterface(
106 const com::sun::star::uno::Type
& aType
)
107 throw ( com::sun::star::uno::RuntimeException
);
108 virtual void SAL_CALL
acquire()
110 virtual void SAL_CALL
release()
113 // XTypeProvider (implemnented by base, but needs to be overridden for
114 // delegating to aggregate)
115 virtual com::sun::star::uno::Sequence
< com::sun::star::uno::Type
> SAL_CALL
117 throw ( com::sun::star::uno::RuntimeException
);
118 virtual com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
119 getImplementationId()
120 throw ( com::sun::star::uno::RuntimeException
);
122 // XComponent ( one of XStorage bases )
123 virtual void SAL_CALL
125 throw ( com::sun::star::uno::RuntimeException
);
126 virtual void SAL_CALL
127 addEventListener( const com::sun::star::uno::Reference
<
128 com::sun::star::lang::XEventListener
> & xListener
)
129 throw ( com::sun::star::uno::RuntimeException
);
130 virtual void SAL_CALL
131 removeEventListener( const com::sun::star::uno::Reference
<
132 com::sun::star::lang::XEventListener
>& aListener
)
133 throw ( com::sun::star::uno::RuntimeException
);
135 // XNameAccess ( one of XStorage bases )
136 virtual com::sun::star::uno::Any SAL_CALL
137 getByName( const rtl::OUString
& aName
)
138 throw ( com::sun::star::container::NoSuchElementException
,
139 com::sun::star::lang::WrappedTargetException
,
140 com::sun::star::uno::RuntimeException
);
141 virtual com::sun::star::uno::Sequence
< rtl::OUString
> SAL_CALL
143 throw ( com::sun::star::uno::RuntimeException
);
144 virtual sal_Bool SAL_CALL
145 hasByName( const rtl::OUString
& aName
)
146 throw ( com::sun::star::uno::RuntimeException
);
148 // XElementAccess (base of XNameAccess)
149 virtual com::sun::star::uno::Type SAL_CALL
151 throw ( com::sun::star::uno::RuntimeException
);
152 virtual sal_Bool SAL_CALL
154 throw ( com::sun::star::uno::RuntimeException
);
157 virtual void SAL_CALL
158 copyToStorage( const com::sun::star::uno::Reference
<
159 com::sun::star::embed::XStorage
>& xDest
)
160 throw ( com::sun::star::embed::InvalidStorageException
,
161 com::sun::star::lang::IllegalArgumentException
,
162 com::sun::star::io::IOException
,
163 com::sun::star::embed::StorageWrappedTargetException
,
164 com::sun::star::uno::RuntimeException
);
165 virtual com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
166 openStreamElement( const ::rtl::OUString
& aStreamName
,
167 sal_Int32 nOpenMode
)
168 throw ( com::sun::star::embed::InvalidStorageException
,
169 com::sun::star::lang::IllegalArgumentException
,
170 com::sun::star::packages::WrongPasswordException
,
171 com::sun::star::io::IOException
,
172 com::sun::star::embed::StorageWrappedTargetException
,
173 com::sun::star::uno::RuntimeException
);
174 virtual com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
175 openEncryptedStreamElement( const ::rtl::OUString
& aStreamName
,
177 const ::rtl::OUString
& aPassword
)
178 throw ( com::sun::star::embed::InvalidStorageException
,
179 com::sun::star::lang::IllegalArgumentException
,
180 com::sun::star::packages::NoEncryptionException
,
181 com::sun::star::packages::WrongPasswordException
,
182 com::sun::star::io::IOException
,
183 com::sun::star::embed::StorageWrappedTargetException
,
184 com::sun::star::uno::RuntimeException
);
185 virtual com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
> SAL_CALL
186 openStorageElement( const ::rtl::OUString
& aStorName
,
187 sal_Int32 nOpenMode
)
188 throw ( com::sun::star::embed::InvalidStorageException
,
189 com::sun::star::lang::IllegalArgumentException
,
190 com::sun::star::io::IOException
,
191 com::sun::star::embed::StorageWrappedTargetException
,
192 com::sun::star::uno::RuntimeException
);
193 virtual com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
194 cloneStreamElement( const ::rtl::OUString
& aStreamName
)
195 throw ( com::sun::star::embed::InvalidStorageException
,
196 com::sun::star::lang::IllegalArgumentException
,
197 com::sun::star::packages::WrongPasswordException
,
198 com::sun::star::io::IOException
,
199 com::sun::star::embed::StorageWrappedTargetException
,
200 com::sun::star::uno::RuntimeException
);
201 virtual com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
202 cloneEncryptedStreamElement( const ::rtl::OUString
& aStreamName
,
203 const ::rtl::OUString
& aPassword
)
204 throw ( com::sun::star::embed::InvalidStorageException
,
205 com::sun::star::lang::IllegalArgumentException
,
206 com::sun::star::packages::NoEncryptionException
,
207 com::sun::star::packages::WrongPasswordException
,
208 com::sun::star::io::IOException
,
209 com::sun::star::embed::StorageWrappedTargetException
,
210 com::sun::star::uno::RuntimeException
);
211 virtual void SAL_CALL
212 copyLastCommitTo( const com::sun::star::uno::Reference
<
213 com::sun::star::embed::XStorage
>& xTargetStorage
)
214 throw ( com::sun::star::embed::InvalidStorageException
,
215 com::sun::star::lang::IllegalArgumentException
,
216 com::sun::star::io::IOException
,
217 com::sun::star::embed::StorageWrappedTargetException
,
218 com::sun::star::uno::RuntimeException
);
219 virtual void SAL_CALL
220 copyStorageElementLastCommitTo( const ::rtl::OUString
& aStorName
,
221 const com::sun::star::uno::Reference
<
222 com::sun::star::embed::XStorage
> &
224 throw ( com::sun::star::embed::InvalidStorageException
,
225 com::sun::star::lang::IllegalArgumentException
,
226 com::sun::star::io::IOException
,
227 com::sun::star::embed::StorageWrappedTargetException
,
228 com::sun::star::uno::RuntimeException
);
229 virtual sal_Bool SAL_CALL
230 isStreamElement( const ::rtl::OUString
& aElementName
)
231 throw ( com::sun::star::container::NoSuchElementException
,
232 com::sun::star::lang::IllegalArgumentException
,
233 com::sun::star::embed::InvalidStorageException
,
234 com::sun::star::uno::RuntimeException
);
235 virtual sal_Bool SAL_CALL
236 isStorageElement( const ::rtl::OUString
& aElementName
)
237 throw ( com::sun::star::container::NoSuchElementException
,
238 com::sun::star::lang::IllegalArgumentException
,
239 com::sun::star::embed::InvalidStorageException
,
240 com::sun::star::uno::RuntimeException
);
241 virtual void SAL_CALL
242 removeElement( const ::rtl::OUString
& aElementName
)
243 throw ( com::sun::star::embed::InvalidStorageException
,
244 com::sun::star::lang::IllegalArgumentException
,
245 com::sun::star::container::NoSuchElementException
,
246 com::sun::star::io::IOException
,
247 com::sun::star::embed::StorageWrappedTargetException
,
248 com::sun::star::uno::RuntimeException
);
249 virtual void SAL_CALL
250 renameElement( const ::rtl::OUString
& aEleName
,
251 const ::rtl::OUString
& aNewName
)
252 throw ( com::sun::star::embed::InvalidStorageException
,
253 com::sun::star::lang::IllegalArgumentException
,
254 com::sun::star::container::NoSuchElementException
,
255 com::sun::star::container::ElementExistException
,
256 com::sun::star::io::IOException
,
257 com::sun::star::embed::StorageWrappedTargetException
,
258 com::sun::star::uno::RuntimeException
);
259 virtual void SAL_CALL
260 copyElementTo( const ::rtl::OUString
& aElementName
,
261 const com::sun::star::uno::Reference
<
262 com::sun::star::embed::XStorage
>& xDest
,
263 const ::rtl::OUString
& aNewName
)
264 throw ( com::sun::star::embed::InvalidStorageException
,
265 com::sun::star::lang::IllegalArgumentException
,
266 com::sun::star::container::NoSuchElementException
,
267 com::sun::star::container::ElementExistException
,
268 com::sun::star::io::IOException
,
269 com::sun::star::embed::StorageWrappedTargetException
,
270 com::sun::star::uno::RuntimeException
);
271 virtual void SAL_CALL
272 moveElementTo( const ::rtl::OUString
& aElementName
,
273 const com::sun::star::uno::Reference
<
274 com::sun::star::embed::XStorage
>& xDest
,
275 const ::rtl::OUString
& rNewName
)
276 throw ( com::sun::star::embed::InvalidStorageException
,
277 com::sun::star::lang::IllegalArgumentException
,
278 com::sun::star::container::NoSuchElementException
,
279 com::sun::star::container::ElementExistException
,
280 com::sun::star::io::IOException
,
281 com::sun::star::embed::StorageWrappedTargetException
,
282 com::sun::star::uno::RuntimeException
);
285 virtual void SAL_CALL
commit()
286 throw ( com::sun::star::io::IOException
,
287 com::sun::star::lang::WrappedTargetException
,
288 com::sun::star::uno::RuntimeException
);
289 virtual void SAL_CALL
revert()
290 throw ( com::sun::star::io::IOException
,
291 com::sun::star::lang::WrappedTargetException
,
292 com::sun::star::uno::RuntimeException
);
295 Storage( const rtl::Reference
< Storage
> & rFactory
); // n.i.
297 rtl::Reference
< StorageElementFactory
> m_xFactory
;
298 com::sun::star::uno::Reference
<
299 com::sun::star::uno::XAggregation
> m_xAggProxy
;
300 com::sun::star::uno::Reference
<
301 com::sun::star::embed::XStorage
> m_xWrappedStorage
;
302 com::sun::star::uno::Reference
<
303 com::sun::star::embed::XTransactedObject
> m_xWrappedTransObj
;
304 com::sun::star::uno::Reference
<
305 com::sun::star::lang::XComponent
> m_xWrappedComponent
;
306 com::sun::star::uno::Reference
<
307 com::sun::star::lang::XTypeProvider
> m_xWrappedTypeProv
;
308 bool m_bIsDocumentStorage
;
310 StorageElementFactory::StorageMap::iterator m_aContainerIt
;
312 friend class StorageElementFactory
;
313 friend class std::auto_ptr
< Storage
>;
316 //=======================================================================
319 cppu::WeakImplHelper2
<
320 com::sun::star::io::XOutputStream
,
321 com::sun::star::lang::XComponent
> OutputStreamUNOBase
;
323 class OutputStream
: public OutputStreamUNOBase
, public ParentStorageHolder
327 const com::sun::star::uno::Reference
<
328 com::sun::star::lang::XMultiServiceFactory
> & xSMgr
,
329 const rtl::OUString
& rUri
,
330 const com::sun::star::uno::Reference
<
331 com::sun::star::embed::XStorage
> & xParentStorage
,
332 const com::sun::star::uno::Reference
<
333 com::sun::star::io::XOutputStream
> & xStreamToWrap
);
334 virtual ~OutputStream();
337 virtual com::sun::star::uno::Any SAL_CALL
338 queryInterface( const com::sun::star::uno::Type
& aType
)
339 throw ( com::sun::star::uno::RuntimeException
);
341 // XTypeProvider (implemnented by base, but needs to be overridden for
342 // delegating to aggregate)
343 virtual com::sun::star::uno::Sequence
< com::sun::star::uno::Type
> SAL_CALL
345 throw ( com::sun::star::uno::RuntimeException
);
346 virtual com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
347 getImplementationId()
348 throw ( com::sun::star::uno::RuntimeException
);
351 virtual void SAL_CALL
352 writeBytes( const com::sun::star::uno::Sequence
< sal_Int8
>& aData
)
353 throw ( com::sun::star::io::NotConnectedException
,
354 com::sun::star::io::BufferSizeExceededException
,
355 com::sun::star::io::IOException
,
356 com::sun::star::uno::RuntimeException
);
357 virtual void SAL_CALL
359 throw ( com::sun::star::io::NotConnectedException
,
360 com::sun::star::io::BufferSizeExceededException
,
361 com::sun::star::io::IOException
,
362 com::sun::star::uno::RuntimeException
);
363 // Note: We need to intercept this one.
364 virtual void SAL_CALL
366 throw ( com::sun::star::io::NotConnectedException
,
367 com::sun::star::io::BufferSizeExceededException
,
368 com::sun::star::io::IOException
,
369 com::sun::star::uno::RuntimeException
);
372 // Note: We need to intercept this one.
373 virtual void SAL_CALL
375 throw ( com::sun::star::uno::RuntimeException
);
376 virtual void SAL_CALL
377 addEventListener( const com::sun::star::uno::Reference
<
378 com::sun::star::lang::XEventListener
>& xListener
)
379 throw ( com::sun::star::uno::RuntimeException
);
380 virtual void SAL_CALL
381 removeEventListener( const com::sun::star::uno::Reference
<
382 com::sun::star::lang::XEventListener
>& aListener
)
383 throw ( com::sun::star::uno::RuntimeException
);
386 com::sun::star::uno::Reference
<
387 com::sun::star::uno::XAggregation
> m_xAggProxy
;
388 com::sun::star::uno::Reference
<
389 com::sun::star::io::XOutputStream
> m_xWrappedStream
;
390 com::sun::star::uno::Reference
<
391 com::sun::star::lang::XComponent
> m_xWrappedComponent
;
392 com::sun::star::uno::Reference
<
393 com::sun::star::lang::XTypeProvider
> m_xWrappedTypeProv
;
396 //=======================================================================
398 typedef cppu::WeakImplHelper5
< com::sun::star::io::XStream
,
399 com::sun::star::io::XOutputStream
,
400 com::sun::star::io::XTruncate
,
401 com::sun::star::io::XInputStream
,
402 com::sun::star::lang::XComponent
>
405 class Stream
: public StreamUNOBase
, public ParentStorageHolder
409 const com::sun::star::uno::Reference
<
410 com::sun::star::lang::XMultiServiceFactory
> & xSMgr
,
411 const rtl::OUString
& rUri
,
412 const com::sun::star::uno::Reference
<
413 com::sun::star::embed::XStorage
> & xParentStorage
,
414 const com::sun::star::uno::Reference
<
415 com::sun::star::io::XStream
> & xStreamToWrap
);
420 virtual com::sun::star::uno::Any SAL_CALL
421 queryInterface( const com::sun::star::uno::Type
& aType
)
422 throw ( com::sun::star::uno::RuntimeException
);
424 // XTypeProvider (implemnented by base, but needs to be overridden for
425 // delegating to aggregate)
426 virtual com::sun::star::uno::Sequence
< com::sun::star::uno::Type
> SAL_CALL
428 throw ( com::sun::star::uno::RuntimeException
);
429 virtual com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
430 getImplementationId()
431 throw ( com::sun::star::uno::RuntimeException
);
434 virtual com::sun::star::uno::Reference
<
435 com::sun::star::io::XInputStream
> SAL_CALL
437 throw( com::sun::star::uno::RuntimeException
);
439 virtual com::sun::star::uno::Reference
<
440 com::sun::star::io::XOutputStream
> SAL_CALL
442 throw( com::sun::star::uno::RuntimeException
);
445 virtual void SAL_CALL
446 writeBytes( const com::sun::star::uno::Sequence
< sal_Int8
>& aData
)
447 throw( com::sun::star::io::NotConnectedException
,
448 com::sun::star::io::BufferSizeExceededException
,
449 com::sun::star::io::IOException
,
450 com::sun::star::uno::RuntimeException
);
452 virtual void SAL_CALL
454 throw( com::sun::star::io::NotConnectedException
,
455 com::sun::star::io::BufferSizeExceededException
,
456 com::sun::star::io::IOException
,
457 com::sun::star::uno::RuntimeException
);
459 virtual void SAL_CALL
461 throw( com::sun::star::io::NotConnectedException
,
462 com::sun::star::io::IOException
,
463 com::sun::star::uno::RuntimeException
);
466 virtual void SAL_CALL
468 throw( com::sun::star::io::IOException
,
469 com::sun::star::uno::RuntimeException
);
472 virtual sal_Int32 SAL_CALL
473 readBytes( com::sun::star::uno::Sequence
< sal_Int8
>& aData
,
474 sal_Int32 nBytesToRead
)
475 throw( com::sun::star::io::NotConnectedException
,
476 com::sun::star::io::BufferSizeExceededException
,
477 com::sun::star::io::IOException
,
478 com::sun::star::uno::RuntimeException
);
480 virtual sal_Int32 SAL_CALL
481 readSomeBytes( com::sun::star::uno::Sequence
< sal_Int8
>& aData
,
482 sal_Int32 nMaxBytesToRead
)
483 throw( com::sun::star::io::NotConnectedException
,
484 com::sun::star::io::BufferSizeExceededException
,
485 com::sun::star::io::IOException
,
486 com::sun::star::uno::RuntimeException
);
488 virtual void SAL_CALL
489 skipBytes( sal_Int32 nBytesToSkip
)
490 throw( com::sun::star::io::NotConnectedException
,
491 com::sun::star::io::BufferSizeExceededException
,
492 com::sun::star::io::IOException
,
493 com::sun::star::uno::RuntimeException
);
495 virtual sal_Int32 SAL_CALL
497 throw( com::sun::star::io::NotConnectedException
,
498 com::sun::star::io::IOException
,
499 com::sun::star::uno::RuntimeException
);
501 virtual void SAL_CALL
503 throw( com::sun::star::io::NotConnectedException
,
504 com::sun::star::io::IOException
,
505 com::sun::star::uno::RuntimeException
);
508 // Note: We need to intercept this one.
509 virtual void SAL_CALL
511 throw ( com::sun::star::uno::RuntimeException
);
512 virtual void SAL_CALL
513 addEventListener( const com::sun::star::uno::Reference
<
514 com::sun::star::lang::XEventListener
>& xListener
)
515 throw ( com::sun::star::uno::RuntimeException
);
516 virtual void SAL_CALL
517 removeEventListener( const com::sun::star::uno::Reference
<
518 com::sun::star::lang::XEventListener
>& aListener
)
519 throw ( com::sun::star::uno::RuntimeException
);
523 throw( com::sun::star::io::IOException
);
525 com::sun::star::uno::Reference
<
526 com::sun::star::uno::XAggregation
> m_xAggProxy
;
527 com::sun::star::uno::Reference
<
528 com::sun::star::io::XStream
> m_xWrappedStream
;
529 com::sun::star::uno::Reference
<
530 com::sun::star::io::XOutputStream
> m_xWrappedOutputStream
;
531 com::sun::star::uno::Reference
<
532 com::sun::star::io::XTruncate
> m_xWrappedTruncate
;
533 com::sun::star::uno::Reference
<
534 com::sun::star::io::XInputStream
> m_xWrappedInputStream
;
535 com::sun::star::uno::Reference
<
536 com::sun::star::lang::XComponent
> m_xWrappedComponent
;
537 com::sun::star::uno::Reference
<
538 com::sun::star::lang::XTypeProvider
> m_xWrappedTypeProv
;
541 } // namespace tdoc_ucp
543 #endif /* !INCLUDED_TDOC_STGELEMS_HXX */
545 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */