1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tdoc_stgelems.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_TDOC_STGELEMS_HXX
32 #define INCLUDED_TDOC_STGELEMS_HXX
36 #include "osl/mutex.hxx"
37 #include "rtl/ref.hxx"
39 #include "cppuhelper/implbase2.hxx"
40 #include "cppuhelper/implbase5.hxx"
42 #include "com/sun/star/embed/XStorage.hpp"
43 #include "com/sun/star/embed/XTransactedObject.hpp"
44 #include "com/sun/star/io/XOutputStream.hpp"
45 #include "com/sun/star/io/XStream.hpp"
46 #include "com/sun/star/io/XTruncate.hpp"
47 #include "com/sun/star/lang/XComponent.hpp"
49 #include "tdoc_storage.hxx"
58 //=======================================================================
60 class ParentStorageHolder
: public MutexHolder
64 const com::sun::star::uno::Reference
<
65 com::sun::star::embed::XStorage
> & xParentStorage
,
66 const rtl::OUString
& rUri
);
68 bool isParentARootStorage() const
69 { return m_bParentIsRootStorage
; }
70 com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>
71 getParentStorage() const
72 { return m_xParentStorage
; }
73 void setParentStorage( const com::sun::star::uno::Reference
<
74 com::sun::star::embed::XStorage
> & xStg
)
75 { osl::MutexGuard
aGuard( m_aMutex
); m_xParentStorage
= xStg
; }
78 com::sun::star::uno::Reference
<
79 com::sun::star::embed::XStorage
> m_xParentStorage
;
80 bool m_bParentIsRootStorage
;
83 //=======================================================================
86 cppu::WeakImplHelper2
<
87 com::sun::star::embed::XStorage
,
88 com::sun::star::embed::XTransactedObject
> StorageUNOBase
;
90 class Storage
: public StorageUNOBase
, public ParentStorageHolder
94 const com::sun::star::uno::Reference
<
95 com::sun::star::lang::XMultiServiceFactory
> & xSMgr
,
96 const rtl::Reference
< StorageElementFactory
> & xFactory
,
97 const rtl::OUString
& rUri
,
98 const com::sun::star::uno::Reference
<
99 com::sun::star::embed::XStorage
> & xParentStorage
,
100 const com::sun::star::uno::Reference
<
101 com::sun::star::embed::XStorage
> & xStorageToWrap
);
104 bool isDocumentStorage() const { return m_bIsDocumentStorage
; }
107 virtual com::sun::star::uno::Any SAL_CALL
queryInterface(
108 const com::sun::star::uno::Type
& aType
)
109 throw ( com::sun::star::uno::RuntimeException
);
110 virtual void SAL_CALL
acquire()
112 virtual void SAL_CALL
release()
115 // XTypeProvider (implemnented by base, but needs to be overridden for
116 // delegating to aggregate)
117 virtual com::sun::star::uno::Sequence
< com::sun::star::uno::Type
> SAL_CALL
119 throw ( com::sun::star::uno::RuntimeException
);
120 virtual com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
121 getImplementationId()
122 throw ( com::sun::star::uno::RuntimeException
);
124 // XComponent ( one of XStorage bases )
125 virtual void SAL_CALL
127 throw ( com::sun::star::uno::RuntimeException
);
128 virtual void SAL_CALL
129 addEventListener( const com::sun::star::uno::Reference
<
130 com::sun::star::lang::XEventListener
> & xListener
)
131 throw ( com::sun::star::uno::RuntimeException
);
132 virtual void SAL_CALL
133 removeEventListener( const com::sun::star::uno::Reference
<
134 com::sun::star::lang::XEventListener
>& aListener
)
135 throw ( com::sun::star::uno::RuntimeException
);
137 // XNameAccess ( one of XStorage bases )
138 virtual com::sun::star::uno::Any SAL_CALL
139 getByName( const rtl::OUString
& aName
)
140 throw ( com::sun::star::container::NoSuchElementException
,
141 com::sun::star::lang::WrappedTargetException
,
142 com::sun::star::uno::RuntimeException
);
143 virtual com::sun::star::uno::Sequence
< rtl::OUString
> SAL_CALL
145 throw ( com::sun::star::uno::RuntimeException
);
146 virtual sal_Bool SAL_CALL
147 hasByName( const rtl::OUString
& aName
)
148 throw ( com::sun::star::uno::RuntimeException
);
150 // XElementAccess (base of XNameAccess)
151 virtual com::sun::star::uno::Type SAL_CALL
153 throw ( com::sun::star::uno::RuntimeException
);
154 virtual sal_Bool SAL_CALL
156 throw ( com::sun::star::uno::RuntimeException
);
159 virtual void SAL_CALL
160 copyToStorage( const com::sun::star::uno::Reference
<
161 com::sun::star::embed::XStorage
>& xDest
)
162 throw ( com::sun::star::embed::InvalidStorageException
,
163 com::sun::star::lang::IllegalArgumentException
,
164 com::sun::star::io::IOException
,
165 com::sun::star::embed::StorageWrappedTargetException
,
166 com::sun::star::uno::RuntimeException
);
167 virtual com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
168 openStreamElement( const ::rtl::OUString
& aStreamName
,
169 sal_Int32 nOpenMode
)
170 throw ( com::sun::star::embed::InvalidStorageException
,
171 com::sun::star::lang::IllegalArgumentException
,
172 com::sun::star::packages::WrongPasswordException
,
173 com::sun::star::io::IOException
,
174 com::sun::star::embed::StorageWrappedTargetException
,
175 com::sun::star::uno::RuntimeException
);
176 virtual com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
177 openEncryptedStreamElement( const ::rtl::OUString
& aStreamName
,
179 const ::rtl::OUString
& aPassword
)
180 throw ( com::sun::star::embed::InvalidStorageException
,
181 com::sun::star::lang::IllegalArgumentException
,
182 com::sun::star::packages::NoEncryptionException
,
183 com::sun::star::packages::WrongPasswordException
,
184 com::sun::star::io::IOException
,
185 com::sun::star::embed::StorageWrappedTargetException
,
186 com::sun::star::uno::RuntimeException
);
187 virtual com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
> SAL_CALL
188 openStorageElement( const ::rtl::OUString
& aStorName
,
189 sal_Int32 nOpenMode
)
190 throw ( com::sun::star::embed::InvalidStorageException
,
191 com::sun::star::lang::IllegalArgumentException
,
192 com::sun::star::io::IOException
,
193 com::sun::star::embed::StorageWrappedTargetException
,
194 com::sun::star::uno::RuntimeException
);
195 virtual com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
196 cloneStreamElement( const ::rtl::OUString
& aStreamName
)
197 throw ( com::sun::star::embed::InvalidStorageException
,
198 com::sun::star::lang::IllegalArgumentException
,
199 com::sun::star::packages::WrongPasswordException
,
200 com::sun::star::io::IOException
,
201 com::sun::star::embed::StorageWrappedTargetException
,
202 com::sun::star::uno::RuntimeException
);
203 virtual com::sun::star::uno::Reference
< com::sun::star::io::XStream
> SAL_CALL
204 cloneEncryptedStreamElement( const ::rtl::OUString
& aStreamName
,
205 const ::rtl::OUString
& aPassword
)
206 throw ( com::sun::star::embed::InvalidStorageException
,
207 com::sun::star::lang::IllegalArgumentException
,
208 com::sun::star::packages::NoEncryptionException
,
209 com::sun::star::packages::WrongPasswordException
,
210 com::sun::star::io::IOException
,
211 com::sun::star::embed::StorageWrappedTargetException
,
212 com::sun::star::uno::RuntimeException
);
213 virtual void SAL_CALL
214 copyLastCommitTo( const com::sun::star::uno::Reference
<
215 com::sun::star::embed::XStorage
>& xTargetStorage
)
216 throw ( com::sun::star::embed::InvalidStorageException
,
217 com::sun::star::lang::IllegalArgumentException
,
218 com::sun::star::io::IOException
,
219 com::sun::star::embed::StorageWrappedTargetException
,
220 com::sun::star::uno::RuntimeException
);
221 virtual void SAL_CALL
222 copyStorageElementLastCommitTo( const ::rtl::OUString
& aStorName
,
223 const com::sun::star::uno::Reference
<
224 com::sun::star::embed::XStorage
> &
226 throw ( com::sun::star::embed::InvalidStorageException
,
227 com::sun::star::lang::IllegalArgumentException
,
228 com::sun::star::io::IOException
,
229 com::sun::star::embed::StorageWrappedTargetException
,
230 com::sun::star::uno::RuntimeException
);
231 virtual sal_Bool SAL_CALL
232 isStreamElement( const ::rtl::OUString
& aElementName
)
233 throw ( com::sun::star::container::NoSuchElementException
,
234 com::sun::star::lang::IllegalArgumentException
,
235 com::sun::star::embed::InvalidStorageException
,
236 com::sun::star::uno::RuntimeException
);
237 virtual sal_Bool SAL_CALL
238 isStorageElement( const ::rtl::OUString
& aElementName
)
239 throw ( com::sun::star::container::NoSuchElementException
,
240 com::sun::star::lang::IllegalArgumentException
,
241 com::sun::star::embed::InvalidStorageException
,
242 com::sun::star::uno::RuntimeException
);
243 virtual void SAL_CALL
244 removeElement( const ::rtl::OUString
& aElementName
)
245 throw ( com::sun::star::embed::InvalidStorageException
,
246 com::sun::star::lang::IllegalArgumentException
,
247 com::sun::star::container::NoSuchElementException
,
248 com::sun::star::io::IOException
,
249 com::sun::star::embed::StorageWrappedTargetException
,
250 com::sun::star::uno::RuntimeException
);
251 virtual void SAL_CALL
252 renameElement( const ::rtl::OUString
& aEleName
,
253 const ::rtl::OUString
& aNewName
)
254 throw ( com::sun::star::embed::InvalidStorageException
,
255 com::sun::star::lang::IllegalArgumentException
,
256 com::sun::star::container::NoSuchElementException
,
257 com::sun::star::container::ElementExistException
,
258 com::sun::star::io::IOException
,
259 com::sun::star::embed::StorageWrappedTargetException
,
260 com::sun::star::uno::RuntimeException
);
261 virtual void SAL_CALL
262 copyElementTo( const ::rtl::OUString
& aElementName
,
263 const com::sun::star::uno::Reference
<
264 com::sun::star::embed::XStorage
>& xDest
,
265 const ::rtl::OUString
& aNewName
)
266 throw ( com::sun::star::embed::InvalidStorageException
,
267 com::sun::star::lang::IllegalArgumentException
,
268 com::sun::star::container::NoSuchElementException
,
269 com::sun::star::container::ElementExistException
,
270 com::sun::star::io::IOException
,
271 com::sun::star::embed::StorageWrappedTargetException
,
272 com::sun::star::uno::RuntimeException
);
273 virtual void SAL_CALL
274 moveElementTo( const ::rtl::OUString
& aElementName
,
275 const com::sun::star::uno::Reference
<
276 com::sun::star::embed::XStorage
>& xDest
,
277 const ::rtl::OUString
& rNewName
)
278 throw ( com::sun::star::embed::InvalidStorageException
,
279 com::sun::star::lang::IllegalArgumentException
,
280 com::sun::star::container::NoSuchElementException
,
281 com::sun::star::container::ElementExistException
,
282 com::sun::star::io::IOException
,
283 com::sun::star::embed::StorageWrappedTargetException
,
284 com::sun::star::uno::RuntimeException
);
287 virtual void SAL_CALL
commit()
288 throw ( com::sun::star::io::IOException
,
289 com::sun::star::lang::WrappedTargetException
,
290 com::sun::star::uno::RuntimeException
);
291 virtual void SAL_CALL
revert()
292 throw ( com::sun::star::io::IOException
,
293 com::sun::star::lang::WrappedTargetException
,
294 com::sun::star::uno::RuntimeException
);
297 Storage( const rtl::Reference
< Storage
> & rFactory
); // n.i.
299 rtl::Reference
< StorageElementFactory
> m_xFactory
;
300 com::sun::star::uno::Reference
<
301 com::sun::star::uno::XAggregation
> m_xAggProxy
;
302 com::sun::star::uno::Reference
<
303 com::sun::star::embed::XStorage
> m_xWrappedStorage
;
304 com::sun::star::uno::Reference
<
305 com::sun::star::embed::XTransactedObject
> m_xWrappedTransObj
;
306 com::sun::star::uno::Reference
<
307 com::sun::star::lang::XComponent
> m_xWrappedComponent
;
308 com::sun::star::uno::Reference
<
309 com::sun::star::lang::XTypeProvider
> m_xWrappedTypeProv
;
310 bool m_bIsDocumentStorage
;
312 StorageElementFactory::StorageMap::iterator m_aContainerIt
;
314 friend class StorageElementFactory
;
315 friend class std::auto_ptr
< Storage
>;
318 //=======================================================================
321 cppu::WeakImplHelper2
<
322 com::sun::star::io::XOutputStream
,
323 com::sun::star::lang::XComponent
> OutputStreamUNOBase
;
325 class OutputStream
: public OutputStreamUNOBase
, public ParentStorageHolder
329 const com::sun::star::uno::Reference
<
330 com::sun::star::lang::XMultiServiceFactory
> & xSMgr
,
331 const rtl::OUString
& rUri
,
332 const com::sun::star::uno::Reference
<
333 com::sun::star::embed::XStorage
> & xParentStorage
,
334 const com::sun::star::uno::Reference
<
335 com::sun::star::io::XOutputStream
> & xStreamToWrap
);
336 virtual ~OutputStream();
339 virtual com::sun::star::uno::Any SAL_CALL
340 queryInterface( const com::sun::star::uno::Type
& aType
)
341 throw ( com::sun::star::uno::RuntimeException
);
343 // XTypeProvider (implemnented by base, but needs to be overridden for
344 // delegating to aggregate)
345 virtual com::sun::star::uno::Sequence
< com::sun::star::uno::Type
> SAL_CALL
347 throw ( com::sun::star::uno::RuntimeException
);
348 virtual com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
349 getImplementationId()
350 throw ( com::sun::star::uno::RuntimeException
);
353 virtual void SAL_CALL
354 writeBytes( const com::sun::star::uno::Sequence
< sal_Int8
>& aData
)
355 throw ( com::sun::star::io::NotConnectedException
,
356 com::sun::star::io::BufferSizeExceededException
,
357 com::sun::star::io::IOException
,
358 com::sun::star::uno::RuntimeException
);
359 virtual void SAL_CALL
361 throw ( com::sun::star::io::NotConnectedException
,
362 com::sun::star::io::BufferSizeExceededException
,
363 com::sun::star::io::IOException
,
364 com::sun::star::uno::RuntimeException
);
365 // Note: We need to intercept this one.
366 virtual void SAL_CALL
368 throw ( com::sun::star::io::NotConnectedException
,
369 com::sun::star::io::BufferSizeExceededException
,
370 com::sun::star::io::IOException
,
371 com::sun::star::uno::RuntimeException
);
374 // Note: We need to intercept this one.
375 virtual void SAL_CALL
377 throw ( com::sun::star::uno::RuntimeException
);
378 virtual void SAL_CALL
379 addEventListener( const com::sun::star::uno::Reference
<
380 com::sun::star::lang::XEventListener
>& xListener
)
381 throw ( com::sun::star::uno::RuntimeException
);
382 virtual void SAL_CALL
383 removeEventListener( const com::sun::star::uno::Reference
<
384 com::sun::star::lang::XEventListener
>& aListener
)
385 throw ( com::sun::star::uno::RuntimeException
);
388 com::sun::star::uno::Reference
<
389 com::sun::star::uno::XAggregation
> m_xAggProxy
;
390 com::sun::star::uno::Reference
<
391 com::sun::star::io::XOutputStream
> m_xWrappedStream
;
392 com::sun::star::uno::Reference
<
393 com::sun::star::lang::XComponent
> m_xWrappedComponent
;
394 com::sun::star::uno::Reference
<
395 com::sun::star::lang::XTypeProvider
> m_xWrappedTypeProv
;
398 //=======================================================================
400 typedef cppu::WeakImplHelper5
< com::sun::star::io::XStream
,
401 com::sun::star::io::XOutputStream
,
402 com::sun::star::io::XTruncate
,
403 com::sun::star::io::XInputStream
,
404 com::sun::star::lang::XComponent
>
407 class Stream
: public StreamUNOBase
, public ParentStorageHolder
411 const com::sun::star::uno::Reference
<
412 com::sun::star::lang::XMultiServiceFactory
> & xSMgr
,
413 const rtl::OUString
& rUri
,
414 const com::sun::star::uno::Reference
<
415 com::sun::star::embed::XStorage
> & xParentStorage
,
416 const com::sun::star::uno::Reference
<
417 com::sun::star::io::XStream
> & xStreamToWrap
);
422 virtual com::sun::star::uno::Any SAL_CALL
423 queryInterface( const com::sun::star::uno::Type
& aType
)
424 throw ( com::sun::star::uno::RuntimeException
);
426 // XTypeProvider (implemnented by base, but needs to be overridden for
427 // delegating to aggregate)
428 virtual com::sun::star::uno::Sequence
< com::sun::star::uno::Type
> SAL_CALL
430 throw ( com::sun::star::uno::RuntimeException
);
431 virtual com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
432 getImplementationId()
433 throw ( com::sun::star::uno::RuntimeException
);
436 virtual com::sun::star::uno::Reference
<
437 com::sun::star::io::XInputStream
> SAL_CALL
439 throw( com::sun::star::uno::RuntimeException
);
441 virtual com::sun::star::uno::Reference
<
442 com::sun::star::io::XOutputStream
> SAL_CALL
444 throw( com::sun::star::uno::RuntimeException
);
447 virtual void SAL_CALL
448 writeBytes( const com::sun::star::uno::Sequence
< sal_Int8
>& aData
)
449 throw( com::sun::star::io::NotConnectedException
,
450 com::sun::star::io::BufferSizeExceededException
,
451 com::sun::star::io::IOException
,
452 com::sun::star::uno::RuntimeException
);
454 virtual void SAL_CALL
456 throw( com::sun::star::io::NotConnectedException
,
457 com::sun::star::io::BufferSizeExceededException
,
458 com::sun::star::io::IOException
,
459 com::sun::star::uno::RuntimeException
);
461 virtual void SAL_CALL
463 throw( com::sun::star::io::NotConnectedException
,
464 com::sun::star::io::IOException
,
465 com::sun::star::uno::RuntimeException
);
468 virtual void SAL_CALL
470 throw( com::sun::star::io::IOException
,
471 com::sun::star::uno::RuntimeException
);
474 virtual sal_Int32 SAL_CALL
475 readBytes( com::sun::star::uno::Sequence
< sal_Int8
>& aData
,
476 sal_Int32 nBytesToRead
)
477 throw( com::sun::star::io::NotConnectedException
,
478 com::sun::star::io::BufferSizeExceededException
,
479 com::sun::star::io::IOException
,
480 com::sun::star::uno::RuntimeException
);
482 virtual sal_Int32 SAL_CALL
483 readSomeBytes( com::sun::star::uno::Sequence
< sal_Int8
>& aData
,
484 sal_Int32 nMaxBytesToRead
)
485 throw( com::sun::star::io::NotConnectedException
,
486 com::sun::star::io::BufferSizeExceededException
,
487 com::sun::star::io::IOException
,
488 com::sun::star::uno::RuntimeException
);
490 virtual void SAL_CALL
491 skipBytes( sal_Int32 nBytesToSkip
)
492 throw( com::sun::star::io::NotConnectedException
,
493 com::sun::star::io::BufferSizeExceededException
,
494 com::sun::star::io::IOException
,
495 com::sun::star::uno::RuntimeException
);
497 virtual sal_Int32 SAL_CALL
499 throw( com::sun::star::io::NotConnectedException
,
500 com::sun::star::io::IOException
,
501 com::sun::star::uno::RuntimeException
);
503 virtual void SAL_CALL
505 throw( com::sun::star::io::NotConnectedException
,
506 com::sun::star::io::IOException
,
507 com::sun::star::uno::RuntimeException
);
510 // Note: We need to intercept this one.
511 virtual void SAL_CALL
513 throw ( com::sun::star::uno::RuntimeException
);
514 virtual void SAL_CALL
515 addEventListener( const com::sun::star::uno::Reference
<
516 com::sun::star::lang::XEventListener
>& xListener
)
517 throw ( com::sun::star::uno::RuntimeException
);
518 virtual void SAL_CALL
519 removeEventListener( const com::sun::star::uno::Reference
<
520 com::sun::star::lang::XEventListener
>& aListener
)
521 throw ( com::sun::star::uno::RuntimeException
);
525 throw( com::sun::star::io::IOException
);
527 com::sun::star::uno::Reference
<
528 com::sun::star::uno::XAggregation
> m_xAggProxy
;
529 com::sun::star::uno::Reference
<
530 com::sun::star::io::XStream
> m_xWrappedStream
;
531 com::sun::star::uno::Reference
<
532 com::sun::star::io::XOutputStream
> m_xWrappedOutputStream
;
533 com::sun::star::uno::Reference
<
534 com::sun::star::io::XTruncate
> m_xWrappedTruncate
;
535 com::sun::star::uno::Reference
<
536 com::sun::star::io::XInputStream
> m_xWrappedInputStream
;
537 com::sun::star::uno::Reference
<
538 com::sun::star::lang::XComponent
> m_xWrappedComponent
;
539 com::sun::star::uno::Reference
<
540 com::sun::star::lang::XTypeProvider
> m_xWrappedTypeProv
;
543 } // namespace tdoc_ucp
545 #endif /* !INCLUDED_TDOC_STGELEMS_HXX */