Update ooo320-m1
[ooovba.git] / svtools / source / fsstor / fsstorage.cxx
blobdfcd5c9c1730566fc66de6e03763248223c1228e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fsstorage.cxx,v $
10 * $Revision: 1.11 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <com/sun/star/beans/PropertyValue.hpp>
34 #include <com/sun/star/embed/ElementModes.hpp>
35 #include <com/sun/star/embed/XTransactedObject.hpp>
36 #include <com/sun/star/ucb/XProgressHandler.hpp>
37 #include <com/sun/star/ucb/XContentAccess.hpp>
38 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
40 #ifndef _COM_SUN_STAR_UCB_INTERACTIVEIODEXCEPTION_HPP_
41 #include <com/sun/star/ucb/InteractiveIOException.hpp>
42 #endif
43 #include <com/sun/star/ucb/IOErrorCode.hpp>
44 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
45 #include <com/sun/star/container/XEnumerationAccess.hpp>
46 #include <com/sun/star/container/XNamed.hpp>
47 #include <com/sun/star/util/XChangesBatch.hpp>
48 #include <com/sun/star/util/XCloneable.hpp>
49 #include <com/sun/star/lang/XUnoTunnel.hpp>
50 #include <com/sun/star/lang/XComponent.hpp>
51 #include <com/sun/star/lang/DisposedException.hpp>
52 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
53 #include <com/sun/star/io/IOException.hpp>
54 #include <com/sun/star/io/XTruncate.hpp>
55 #include <com/sun/star/sdbc/XResultSet.hpp>
56 #include <com/sun/star/sdbc/XRow.hpp>
59 #ifndef _COMPHELPER_PROCESSFACTORY_HXX
60 #include <comphelper/processfactory.hxx>
61 #endif
62 #include <comphelper/storagehelper.hxx>
63 #include <cppuhelper/typeprovider.hxx>
64 #include <cppuhelper/exc_hlp.hxx>
66 #include <tools/urlobj.hxx>
67 #include <unotools/ucbhelper.hxx>
68 #include <unotools/ucbstreamhelper.hxx>
69 #include <unotools/streamwrap.hxx>
70 #include <ucbhelper/fileidentifierconverter.hxx>
71 #include <ucbhelper/contentbroker.hxx>
72 #include <ucbhelper/content.hxx>
74 #include "fsstorage.hxx"
75 #include "oinputstreamcontainer.hxx"
76 #include "ostreamcontainer.hxx"
78 using namespace ::com::sun::star;
80 //=========================================================
82 // TODO: move to a standard helper
83 sal_Bool isLocalFile_Impl( ::rtl::OUString aURL )
85 ::rtl::OUString aSystemPath;
86 ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
87 if ( !pBroker )
88 throw uno::RuntimeException();
90 uno::Reference< ucb::XContentProviderManager > xManager =
91 pBroker->getContentProviderManagerInterface();
92 try
94 aSystemPath = ::ucbhelper::getSystemPathFromFileURL( xManager, aURL );
96 catch ( uno::Exception& )
100 return ( aSystemPath.getLength() != 0 );
104 //=========================================================
106 struct FSStorage_Impl
108 ::rtl::OUString m_aURL;
110 ::ucbhelper::Content* m_pContent;
111 sal_Int32 m_nMode;
113 ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners
114 ::cppu::OTypeCollection* m_pTypeCollection;
116 uno::Reference< lang::XMultiServiceFactory > m_xFactory;
119 FSStorage_Impl( const ::rtl::OUString& aURL, sal_Int32 nMode, uno::Reference< lang::XMultiServiceFactory > xFactory )
120 : m_aURL( aURL )
121 , m_pContent( NULL )
122 , m_nMode( nMode )
123 , m_pListenersContainer( NULL )
124 , m_pTypeCollection( NULL )
125 , m_xFactory( xFactory )
127 OSL_ENSURE( m_aURL.getLength(), "The URL must not be empty" );
130 FSStorage_Impl( const ::ucbhelper::Content& aContent, sal_Int32 nMode, uno::Reference< lang::XMultiServiceFactory > xFactory )
131 : m_aURL( aContent.getURL() )
132 , m_pContent( new ::ucbhelper::Content( aContent ) )
133 , m_nMode( nMode )
134 , m_pListenersContainer( NULL )
135 , m_pTypeCollection( NULL )
136 , m_xFactory( xFactory )
138 OSL_ENSURE( m_aURL.getLength(), "The URL must not be empty" );
141 ~FSStorage_Impl();
144 //=========================================================
146 FSStorage_Impl::~FSStorage_Impl()
148 if ( m_pListenersContainer )
149 delete m_pListenersContainer;
150 if ( m_pTypeCollection )
151 delete m_pTypeCollection;
152 if ( m_pContent )
153 delete m_pContent;
156 //=====================================================
157 // FSStorage implementation
158 //=====================================================
160 //-----------------------------------------------
161 FSStorage::FSStorage( const ::ucbhelper::Content& aContent,
162 sal_Int32 nMode,
163 uno::Sequence< beans::PropertyValue >,
164 uno::Reference< lang::XMultiServiceFactory > xFactory )
165 : m_pImpl( new FSStorage_Impl( aContent, nMode, xFactory ) )
167 // TODO: use properties
168 if ( !xFactory.is() )
169 throw uno::RuntimeException();
171 GetContent();
174 //-----------------------------------------------
175 FSStorage::~FSStorage()
178 ::osl::MutexGuard aGuard( m_aMutex );
179 m_refCount++; // to call dispose
180 try {
181 dispose();
183 catch( uno::RuntimeException& )
188 //-----------------------------------------------
189 sal_Bool FSStorage::MakeFolderNoUI( const String& rFolder, sal_Bool )
191 INetURLObject aURL( rFolder );
192 ::rtl::OUString aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
193 aURL.removeSegment();
194 ::ucbhelper::Content aParent;
195 ::ucbhelper::Content aResultContent;
197 if ( ::ucbhelper::Content::create( aURL.GetMainURL( INetURLObject::NO_DECODE ),
198 uno::Reference< ucb::XCommandEnvironment >(),
199 aParent ) )
200 return ::utl::UCBContentHelper::MakeFolder( aParent, aTitle, aResultContent, sal_False );
202 return sal_False;
205 //-----------------------------------------------
206 ::ucbhelper::Content* FSStorage::GetContent()
208 ::osl::MutexGuard aGuard( m_aMutex );
209 if ( !m_pImpl->m_pContent )
211 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
215 m_pImpl->m_pContent = new ::ucbhelper::Content( m_pImpl->m_aURL, xDummyEnv );
217 catch( uno::Exception& )
222 return m_pImpl->m_pContent;
225 //-----------------------------------------------
226 void FSStorage::CopyStreamToSubStream( const ::rtl::OUString& aSourceURL,
227 const uno::Reference< embed::XStorage >& xDest,
228 const ::rtl::OUString& aNewEntryName )
230 if ( !xDest.is() )
231 throw uno::RuntimeException();
233 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
234 ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv );
235 uno::Reference< io::XInputStream > xSourceInput = aSourceContent.openStream();
237 if ( !xSourceInput.is() )
238 throw io::IOException(); // TODO: error handling
240 uno::Reference< io::XStream > xSubStream = xDest->openStreamElement(
241 aNewEntryName,
242 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
243 if ( !xSubStream.is() )
244 throw uno::RuntimeException();
246 uno::Reference< io::XOutputStream > xDestOutput = xSubStream->getOutputStream();
247 if ( !xDestOutput.is() )
248 throw uno::RuntimeException();
250 ::comphelper::OStorageHelper::CopyInputToOutput( xSourceInput, xDestOutput );
251 xDestOutput->closeOutput();
254 //-----------------------------------------------
255 void FSStorage::CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, const uno::Reference< embed::XStorage >& xDest )
257 if ( !pContent )
258 throw uno::RuntimeException();
260 // get list of contents of the Content
261 // create cursor for access to children
262 uno::Sequence< ::rtl::OUString > aProps( 2 );
263 ::rtl::OUString* pProps = aProps.getArray();
264 pProps[0] = ::rtl::OUString::createFromAscii( "TargetURL" );
265 pProps[1] = ::rtl::OUString::createFromAscii( "IsFolder" );
266 ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
270 uno::Reference< sdbc::XResultSet > xResultSet = pContent->createCursor( aProps, eInclude );
271 uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
272 uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
273 if ( xResultSet.is() )
275 // go through the list: insert files as streams, insert folders as substorages using recursion
276 while ( xResultSet->next() )
278 ::rtl::OUString aSourceURL( xRow->getString( 1 ) );
279 sal_Bool bIsFolder( xRow->getBoolean(2) );
281 // TODO/LATER: not sure whether the entry name must be encoded
282 ::rtl::OUString aNewEntryName( INetURLObject( aSourceURL ).getName( INetURLObject::LAST_SEGMENT,
283 true,
284 INetURLObject::NO_DECODE ) );
285 if ( bIsFolder )
287 uno::Reference< embed::XStorage > xSubStorage = xDest->openStorageElement( aNewEntryName,
288 embed::ElementModes::READWRITE );
289 if ( !xSubStorage.is() )
290 throw uno::RuntimeException();
292 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
293 ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv );
294 CopyContentToStorage_Impl( &aSourceContent, xSubStorage );
296 else
298 CopyStreamToSubStream( aSourceURL, xDest, aNewEntryName );
303 uno::Reference< embed::XTransactedObject > xTransact( xDest, uno::UNO_QUERY );
304 if ( xTransact.is() )
305 xTransact->commit();
307 catch( ucb::InteractiveIOException& r )
309 if ( r.Code == ucb::IOErrorCode_NOT_EXISTING )
310 OSL_ENSURE( sal_False, "The folder does not exist!\n" );
311 else
312 throw;
316 //____________________________________________________________________________________________________
317 // XInterface
318 //____________________________________________________________________________________________________
320 //-----------------------------------------------
321 uno::Any SAL_CALL FSStorage::queryInterface( const uno::Type& rType )
322 throw( uno::RuntimeException )
324 uno::Any aReturn;
325 aReturn <<= ::cppu::queryInterface
326 ( rType
327 , static_cast<lang::XTypeProvider*> ( this )
328 , static_cast<embed::XStorage*> ( this )
329 , static_cast<embed::XHierarchicalStorageAccess*> ( this )
330 , static_cast<container::XNameAccess*> ( this )
331 , static_cast<container::XElementAccess*> ( this )
332 , static_cast<lang::XComponent*> ( this )
333 , static_cast<beans::XPropertySet*> ( this ) );
335 if ( aReturn.hasValue() == sal_True )
336 return aReturn ;
338 return OWeakObject::queryInterface( rType );
341 //-----------------------------------------------
342 void SAL_CALL FSStorage::acquire() throw()
344 OWeakObject::acquire();
347 //-----------------------------------------------
348 void SAL_CALL FSStorage::release() throw()
350 OWeakObject::release();
353 //____________________________________________________________________________________________________
354 // XTypeProvider
355 //____________________________________________________________________________________________________
357 //-----------------------------------------------
358 uno::Sequence< uno::Type > SAL_CALL FSStorage::getTypes()
359 throw( uno::RuntimeException )
361 if ( m_pImpl->m_pTypeCollection == NULL )
363 ::osl::MutexGuard aGuard( m_aMutex );
365 if ( m_pImpl->m_pTypeCollection == NULL )
367 m_pImpl->m_pTypeCollection = new ::cppu::OTypeCollection
368 ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
369 , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
370 , ::getCppuType( ( const uno::Reference< embed::XHierarchicalStorageAccess >* )NULL )
371 , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
375 return m_pImpl->m_pTypeCollection->getTypes() ;
378 //-----------------------------------------------
379 uno::Sequence< sal_Int8 > SAL_CALL FSStorage::getImplementationId()
380 throw( uno::RuntimeException )
382 static ::cppu::OImplementationId* pID = NULL ;
384 if ( pID == NULL )
386 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;
388 if ( pID == NULL )
390 static ::cppu::OImplementationId aID( sal_False ) ;
391 pID = &aID ;
395 return pID->getImplementationId() ;
399 //____________________________________________________________________________________________________
400 // XStorage
401 //____________________________________________________________________________________________________
403 //-----------------------------------------------
404 void SAL_CALL FSStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest )
405 throw ( embed::InvalidStorageException,
406 io::IOException,
407 lang::IllegalArgumentException,
408 embed::StorageWrappedTargetException,
409 uno::RuntimeException )
411 ::osl::MutexGuard aGuard( m_aMutex );
413 if ( !m_pImpl )
414 throw lang::DisposedException();
416 if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) )
417 throw lang::IllegalArgumentException(); // TODO:
419 if ( !GetContent() )
420 throw io::IOException(); // TODO: error handling
424 CopyContentToStorage_Impl( GetContent(), xDest );
426 catch( embed::InvalidStorageException& )
428 throw;
430 catch( lang::IllegalArgumentException& )
432 throw;
434 catch( embed::StorageWrappedTargetException& )
436 throw;
438 catch( io::IOException& )
440 throw;
442 catch( uno::RuntimeException& )
444 throw;
446 catch( uno::Exception& )
448 uno::Any aCaught( ::cppu::getCaughtException() );
449 throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
450 uno::Reference< io::XInputStream >(),
451 aCaught );
455 //-----------------------------------------------
456 uno::Reference< io::XStream > SAL_CALL FSStorage::openStreamElement(
457 const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode )
458 throw ( embed::InvalidStorageException,
459 lang::IllegalArgumentException,
460 packages::WrongPasswordException,
461 io::IOException,
462 embed::StorageWrappedTargetException,
463 uno::RuntimeException )
465 ::osl::MutexGuard aGuard( m_aMutex );
467 if ( !m_pImpl )
468 throw lang::DisposedException();
470 if ( !GetContent() )
471 throw io::IOException(); // TODO: error handling
473 // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
474 INetURLObject aFileURL( m_pImpl->m_aURL );
475 aFileURL.Append( aStreamName );
477 if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
478 throw io::IOException();
480 if ( ( nOpenMode & embed::ElementModes::NOCREATE )
481 && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
482 throw io::IOException(); // TODO:
484 uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
485 uno::Reference< io::XStream > xResult;
488 if ( nOpenMode & embed::ElementModes::WRITE )
490 if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
492 uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess(
493 m_pImpl->m_xFactory->createInstance(
494 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ),
495 uno::UNO_QUERY_THROW );
496 xResult = xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) );
498 else
500 // TODO: test whether it really works for http and fwp
501 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ),
502 STREAM_STD_WRITE );
503 if ( pStream )
505 if ( !pStream->GetError() )
506 xResult = uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) );
507 else
508 delete pStream;
512 if ( !xResult.is() )
513 throw io::IOException();
515 if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) )
517 uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW );
518 xTrunc->truncate();
521 else
523 if ( ( nOpenMode & embed::ElementModes::TRUNCATE )
524 || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
525 throw io::IOException(); // TODO: access denied
527 ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
528 uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
529 xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) );
532 catch( embed::InvalidStorageException& )
534 throw;
536 catch( lang::IllegalArgumentException& )
538 throw;
540 catch( packages::WrongPasswordException& )
542 throw;
544 catch( embed::StorageWrappedTargetException& )
546 throw;
548 catch( io::IOException& )
550 throw;
552 catch( uno::RuntimeException& )
554 throw;
556 catch( uno::Exception& )
558 uno::Any aCaught( ::cppu::getCaughtException() );
559 throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
560 uno::Reference< io::XInputStream >(),
561 aCaught );
564 return xResult;
567 //-----------------------------------------------
568 uno::Reference< io::XStream > SAL_CALL FSStorage::openEncryptedStreamElement(
569 const ::rtl::OUString&, sal_Int32, const ::rtl::OUString& )
570 throw ( embed::InvalidStorageException,
571 lang::IllegalArgumentException,
572 packages::NoEncryptionException,
573 packages::WrongPasswordException,
574 io::IOException,
575 embed::StorageWrappedTargetException,
576 uno::RuntimeException )
578 throw packages::NoEncryptionException();
581 //-----------------------------------------------
582 uno::Reference< embed::XStorage > SAL_CALL FSStorage::openStorageElement(
583 const ::rtl::OUString& aStorName, sal_Int32 nStorageMode )
584 throw ( embed::InvalidStorageException,
585 lang::IllegalArgumentException,
586 io::IOException,
587 embed::StorageWrappedTargetException,
588 uno::RuntimeException )
590 ::osl::MutexGuard aGuard( m_aMutex );
592 if ( !m_pImpl )
593 throw lang::DisposedException();
595 if ( !GetContent() )
596 throw io::IOException(); // TODO: error handling
598 if ( ( nStorageMode & embed::ElementModes::WRITE )
599 && !( m_pImpl->m_nMode & embed::ElementModes::WRITE ) )
600 throw io::IOException(); // TODO: error handling
602 // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
603 INetURLObject aFolderURL( m_pImpl->m_aURL );
604 aFolderURL.Append( aStorName );
606 sal_Bool bFolderExists = ::utl::UCBContentHelper::IsFolder( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) );
607 if ( !bFolderExists && ::utl::UCBContentHelper::IsDocument( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
608 throw io::IOException(); // TODO:
610 if ( ( nStorageMode & embed::ElementModes::NOCREATE ) && !bFolderExists )
611 throw io::IOException(); // TODO:
613 uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
614 uno::Reference< embed::XStorage > xResult;
617 if ( nStorageMode & embed::ElementModes::WRITE )
619 if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) && bFolderExists )
621 ::utl::UCBContentHelper::Kill( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) );
622 bFolderExists =
623 MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), sal_True ); // TODO: not atomar :(
625 else if ( !bFolderExists )
627 bFolderExists =
628 MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), sal_True ); // TODO: not atomar :(
631 else if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) )
632 throw io::IOException(); // TODO: access denied
634 if ( !bFolderExists )
635 throw io::IOException(); // there is no such folder
637 ::ucbhelper::Content aResultContent( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
638 xResult = uno::Reference< embed::XStorage >(
639 static_cast< OWeakObject* >( new FSStorage( aResultContent,
640 nStorageMode,
641 uno::Sequence< beans::PropertyValue >(),
642 m_pImpl->m_xFactory ) ),
643 uno::UNO_QUERY );
645 catch( embed::InvalidStorageException& )
647 throw;
649 catch( lang::IllegalArgumentException& )
651 throw;
653 catch( embed::StorageWrappedTargetException& )
655 throw;
657 catch( io::IOException& )
659 throw;
661 catch( uno::RuntimeException& )
663 throw;
665 catch( uno::Exception& )
667 uno::Any aCaught( ::cppu::getCaughtException() );
668 throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
669 uno::Reference< io::XInputStream >(),
670 aCaught );
673 return xResult;
676 //-----------------------------------------------
677 uno::Reference< io::XStream > SAL_CALL FSStorage::cloneStreamElement( const ::rtl::OUString& aStreamName )
678 throw ( embed::InvalidStorageException,
679 lang::IllegalArgumentException,
680 packages::WrongPasswordException,
681 io::IOException,
682 embed::StorageWrappedTargetException,
683 uno::RuntimeException )
685 ::osl::MutexGuard aGuard( m_aMutex );
687 if ( !m_pImpl )
688 throw lang::DisposedException();
690 if ( !GetContent() )
691 throw io::IOException(); // TODO: error handling
693 // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
694 INetURLObject aFileURL( m_pImpl->m_aURL );
695 aFileURL.Append( aStreamName );
697 uno::Reference < io::XStream > xTempResult;
700 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
701 ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
702 uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
704 xTempResult = uno::Reference < io::XStream >(
705 m_pImpl->m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ),
706 uno::UNO_QUERY_THROW );
707 uno::Reference < io::XOutputStream > xTempOut = xTempResult->getOutputStream();
708 uno::Reference < io::XInputStream > xTempIn = xTempResult->getInputStream();
710 if ( !xTempOut.is() || !xTempIn.is() )
711 throw io::IOException();
713 ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut );
714 xTempOut->closeOutput();
716 catch( embed::InvalidStorageException& )
718 throw;
720 catch( lang::IllegalArgumentException& )
722 throw;
724 catch( packages::WrongPasswordException& )
726 throw;
728 catch( io::IOException& )
730 throw;
732 catch( embed::StorageWrappedTargetException& )
734 throw;
736 catch( uno::RuntimeException& )
738 throw;
740 catch( uno::Exception& )
742 uno::Any aCaught( ::cppu::getCaughtException() );
743 throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
744 uno::Reference< io::XInputStream >(),
745 aCaught );
748 return xTempResult;
751 //-----------------------------------------------
752 uno::Reference< io::XStream > SAL_CALL FSStorage::cloneEncryptedStreamElement(
753 const ::rtl::OUString&,
754 const ::rtl::OUString& )
755 throw ( embed::InvalidStorageException,
756 lang::IllegalArgumentException,
757 packages::NoEncryptionException,
758 packages::WrongPasswordException,
759 io::IOException,
760 embed::StorageWrappedTargetException,
761 uno::RuntimeException )
763 throw packages::NoEncryptionException();
766 //-----------------------------------------------
767 void SAL_CALL FSStorage::copyLastCommitTo(
768 const uno::Reference< embed::XStorage >& xTargetStorage )
769 throw ( embed::InvalidStorageException,
770 lang::IllegalArgumentException,
771 io::IOException,
772 embed::StorageWrappedTargetException,
773 uno::RuntimeException )
775 copyToStorage( xTargetStorage );
778 //-----------------------------------------------
779 void SAL_CALL FSStorage::copyStorageElementLastCommitTo(
780 const ::rtl::OUString& aStorName,
781 const uno::Reference< embed::XStorage >& xTargetStorage )
782 throw ( embed::InvalidStorageException,
783 lang::IllegalArgumentException,
784 io::IOException,
785 embed::StorageWrappedTargetException,
786 uno::RuntimeException )
788 ::osl::MutexGuard aGuard( m_aMutex );
790 if ( !m_pImpl )
791 throw lang::DisposedException();
793 uno::Reference< embed::XStorage > xSourceStor( openStorageElement( aStorName, embed::ElementModes::READ ),
794 uno::UNO_QUERY_THROW );
795 xSourceStor->copyToStorage( xTargetStorage );
798 //-----------------------------------------------
799 sal_Bool SAL_CALL FSStorage::isStreamElement( const ::rtl::OUString& aElementName )
800 throw ( embed::InvalidStorageException,
801 lang::IllegalArgumentException,
802 container::NoSuchElementException,
803 uno::RuntimeException )
805 ::osl::MutexGuard aGuard( m_aMutex );
807 if ( !m_pImpl )
808 throw lang::DisposedException();
810 if ( !GetContent() )
811 throw embed::InvalidStorageException(); // TODO: error handling
813 INetURLObject aURL( m_pImpl->m_aURL );
814 aURL.Append( aElementName );
816 return !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
819 //-----------------------------------------------
820 sal_Bool SAL_CALL FSStorage::isStorageElement( const ::rtl::OUString& aElementName )
821 throw ( embed::InvalidStorageException,
822 lang::IllegalArgumentException,
823 container::NoSuchElementException,
824 uno::RuntimeException )
826 ::osl::MutexGuard aGuard( m_aMutex );
828 if ( !m_pImpl )
829 throw lang::DisposedException();
831 if ( !GetContent() )
832 throw embed::InvalidStorageException(); // TODO: error handling
834 INetURLObject aURL( m_pImpl->m_aURL );
835 aURL.Append( aElementName );
837 return ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
840 //-----------------------------------------------
841 void SAL_CALL FSStorage::removeElement( const ::rtl::OUString& aElementName )
842 throw ( embed::InvalidStorageException,
843 lang::IllegalArgumentException,
844 container::NoSuchElementException,
845 io::IOException,
846 embed::StorageWrappedTargetException,
847 uno::RuntimeException )
849 ::osl::MutexGuard aGuard( m_aMutex );
851 if ( !m_pImpl )
852 throw lang::DisposedException();
854 if ( !GetContent() )
855 throw io::IOException(); // TODO: error handling
857 INetURLObject aURL( m_pImpl->m_aURL );
858 aURL.Append( aElementName );
860 if ( !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) )
861 && !::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
862 throw container::NoSuchElementException(); // TODO:
864 ::utl::UCBContentHelper::Kill( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
867 //-----------------------------------------------
868 void SAL_CALL FSStorage::renameElement( const ::rtl::OUString& aElementName, const ::rtl::OUString& aNewName )
869 throw ( embed::InvalidStorageException,
870 lang::IllegalArgumentException,
871 container::NoSuchElementException,
872 container::ElementExistException,
873 io::IOException,
874 embed::StorageWrappedTargetException,
875 uno::RuntimeException )
877 ::osl::MutexGuard aGuard( m_aMutex );
879 if ( !m_pImpl )
880 throw lang::DisposedException();
882 if ( !GetContent() )
883 throw io::IOException(); // TODO: error handling
885 INetURLObject aOldURL( m_pImpl->m_aURL );
886 aOldURL.Append( aElementName );
888 INetURLObject aNewURL( m_pImpl->m_aURL );
889 aNewURL.Append( aNewName );
891 if ( !::utl::UCBContentHelper::IsFolder( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) )
892 && !::utl::UCBContentHelper::IsDocument( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
893 throw container::NoSuchElementException(); // TODO:
895 if ( ::utl::UCBContentHelper::IsFolder( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) )
896 || ::utl::UCBContentHelper::IsDocument( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
897 throw container::ElementExistException(); // TODO:
901 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
902 ::ucbhelper::Content aSourceContent( aOldURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
904 if ( !GetContent()->transferContent( aSourceContent,
905 ::ucbhelper::InsertOperation_MOVE,
906 aNewName,
907 ucb::NameClash::ERROR ) )
908 throw io::IOException(); // TODO: error handling
910 catch( embed::InvalidStorageException& )
912 throw;
914 catch( lang::IllegalArgumentException& )
916 throw;
918 catch( container::NoSuchElementException& )
920 throw;
922 catch( container::ElementExistException& )
924 throw;
926 catch( io::IOException& )
928 throw;
930 catch( embed::StorageWrappedTargetException& )
932 throw;
934 catch( uno::RuntimeException& )
936 throw;
938 catch( uno::Exception& )
940 uno::Any aCaught( ::cppu::getCaughtException() );
941 throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
942 uno::Reference< io::XInputStream >(),
943 aCaught );
947 //-----------------------------------------------
948 void SAL_CALL FSStorage::copyElementTo( const ::rtl::OUString& aElementName,
949 const uno::Reference< embed::XStorage >& xDest,
950 const ::rtl::OUString& aNewName )
951 throw ( embed::InvalidStorageException,
952 lang::IllegalArgumentException,
953 container::NoSuchElementException,
954 container::ElementExistException,
955 io::IOException,
956 embed::StorageWrappedTargetException,
957 uno::RuntimeException )
959 ::osl::MutexGuard aGuard( m_aMutex );
961 if ( !m_pImpl )
962 throw lang::DisposedException();
964 if ( !xDest.is() )
965 throw uno::RuntimeException();
967 if ( !GetContent() )
968 throw io::IOException(); // TODO: error handling
970 INetURLObject aOwnURL( m_pImpl->m_aURL );
971 aOwnURL.Append( aElementName );
973 if ( xDest->hasByName( aNewName ) )
974 throw container::ElementExistException(); // TODO:
978 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
979 if ( ::utl::UCBContentHelper::IsFolder( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
981 ::ucbhelper::Content aSourceContent( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
982 uno::Reference< embed::XStorage > xDestSubStor(
983 xDest->openStorageElement( aNewName, embed::ElementModes::READWRITE ),
984 uno::UNO_QUERY_THROW );
986 CopyContentToStorage_Impl( &aSourceContent, xDestSubStor );
988 else if ( ::utl::UCBContentHelper::IsDocument( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
990 CopyStreamToSubStream( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDest, aNewName );
992 else
993 throw container::NoSuchElementException(); // TODO:
995 catch( embed::InvalidStorageException& )
997 throw;
999 catch( lang::IllegalArgumentException& )
1001 throw;
1003 catch( container::NoSuchElementException& )
1005 throw;
1007 catch( container::ElementExistException& )
1009 throw;
1011 catch( embed::StorageWrappedTargetException& )
1013 throw;
1015 catch( io::IOException& )
1017 throw;
1019 catch( uno::RuntimeException& )
1021 throw;
1023 catch( uno::Exception& )
1025 uno::Any aCaught( ::cppu::getCaughtException() );
1026 throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
1027 uno::Reference< io::XInputStream >(),
1028 aCaught );
1032 //-----------------------------------------------
1033 void SAL_CALL FSStorage::moveElementTo( const ::rtl::OUString& aElementName,
1034 const uno::Reference< embed::XStorage >& xDest,
1035 const ::rtl::OUString& aNewName )
1036 throw ( embed::InvalidStorageException,
1037 lang::IllegalArgumentException,
1038 container::NoSuchElementException,
1039 container::ElementExistException,
1040 io::IOException,
1041 embed::StorageWrappedTargetException,
1042 uno::RuntimeException )
1044 ::osl::MutexGuard aGuard( m_aMutex );
1045 copyElementTo( aElementName, xDest, aNewName );
1047 INetURLObject aOwnURL( m_pImpl->m_aURL );
1048 aOwnURL.Append( aElementName );
1049 if ( !::utl::UCBContentHelper::Kill( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1050 throw io::IOException(); // TODO: error handling
1053 //____________________________________________________________________________________________________
1054 // XNameAccess
1055 //____________________________________________________________________________________________________
1057 //-----------------------------------------------
1058 uno::Any SAL_CALL FSStorage::getByName( const ::rtl::OUString& aName )
1059 throw ( container::NoSuchElementException,
1060 lang::WrappedTargetException,
1061 uno::RuntimeException )
1063 ::osl::MutexGuard aGuard( m_aMutex );
1065 if ( !m_pImpl )
1066 throw lang::DisposedException();
1068 if ( !GetContent() )
1069 throw io::IOException(); // TODO: error handling
1071 if ( !aName.getLength() )
1072 throw lang::IllegalArgumentException();
1074 INetURLObject aURL( m_pImpl->m_aURL );
1075 aURL.Append( aName );
1077 uno::Any aResult;
1080 if ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1082 aResult <<= openStorageElement( aName, embed::ElementModes::READ );
1084 else if ( ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1086 aResult <<= openStreamElement( aName, embed::ElementModes::READ );
1088 else
1089 throw container::NoSuchElementException(); // TODO:
1091 catch( container::NoSuchElementException& )
1093 throw;
1095 catch( lang::WrappedTargetException& )
1097 throw;
1099 catch( uno::RuntimeException& )
1101 throw;
1103 catch ( uno::Exception& )
1105 uno::Any aCaught( ::cppu::getCaughtException() );
1106 throw lang::WrappedTargetException( ::rtl::OUString::createFromAscii( "Can not open element!\n" ),
1107 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1108 uno::UNO_QUERY ),
1109 aCaught );
1112 return aResult;
1116 //-----------------------------------------------
1117 uno::Sequence< ::rtl::OUString > SAL_CALL FSStorage::getElementNames()
1118 throw ( uno::RuntimeException )
1120 ::osl::MutexGuard aGuard( m_aMutex );
1122 if ( !m_pImpl )
1123 throw lang::DisposedException();
1125 if ( !GetContent() )
1126 throw io::IOException(); // TODO: error handling
1128 uno::Sequence< ::rtl::OUString > aProps( 1 );
1129 ::rtl::OUString* pProps = aProps.getArray();
1130 pProps[0] = ::rtl::OUString::createFromAscii( "Title" );
1131 ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
1133 uno::Sequence< ::rtl::OUString > aResult;
1134 sal_Int32 nSize = 0;
1138 uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude );
1139 uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
1140 uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
1141 if ( xResultSet.is() )
1143 // go through the list
1144 while ( xResultSet->next() )
1146 ::rtl::OUString aName( xRow->getString( 1 ) );
1147 aResult.realloc( ++nSize );
1148 aResult[nSize-1] = aName;
1152 catch( ucb::InteractiveIOException& r )
1154 if ( r.Code == ucb::IOErrorCode_NOT_EXISTING )
1155 OSL_ENSURE( sal_False, "The folder does not exist!\n" );
1156 else
1158 uno::Any aCaught( ::cppu::getCaughtException() );
1159 throw lang::WrappedTargetRuntimeException( ::rtl::OUString::createFromAscii( "Can not open storage!\n" ),
1160 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1161 uno::UNO_QUERY ),
1162 aCaught );
1165 catch( uno::RuntimeException& )
1167 throw;
1169 catch ( uno::Exception& )
1171 uno::Any aCaught( ::cppu::getCaughtException() );
1172 throw lang::WrappedTargetRuntimeException( ::rtl::OUString::createFromAscii( "Can not open storage!\n" ),
1173 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1174 uno::UNO_QUERY ),
1175 aCaught );
1178 return aResult;
1182 //-----------------------------------------------
1183 sal_Bool SAL_CALL FSStorage::hasByName( const ::rtl::OUString& aName )
1184 throw ( uno::RuntimeException )
1186 ::osl::MutexGuard aGuard( m_aMutex );
1188 if ( !m_pImpl )
1189 throw lang::DisposedException();
1193 if ( !GetContent() )
1194 throw io::IOException(); // TODO: error handling
1196 if ( !aName.getLength() )
1197 throw lang::IllegalArgumentException();
1199 catch( uno::RuntimeException& )
1201 throw;
1203 catch ( uno::Exception& )
1205 uno::Any aCaught( ::cppu::getCaughtException() );
1206 throw lang::WrappedTargetRuntimeException( ::rtl::OUString::createFromAscii( "Can not open storage!\n" ),
1207 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1208 uno::UNO_QUERY ),
1209 aCaught );
1212 INetURLObject aURL( m_pImpl->m_aURL );
1213 aURL.Append( aName );
1215 return ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) )
1216 || ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) );
1219 //-----------------------------------------------
1220 uno::Type SAL_CALL FSStorage::getElementType()
1221 throw ( uno::RuntimeException )
1223 ::osl::MutexGuard aGuard( m_aMutex );
1225 if ( !m_pImpl )
1226 throw lang::DisposedException();
1228 // it is a multitype container
1229 return uno::Type();
1232 //-----------------------------------------------
1233 sal_Bool SAL_CALL FSStorage::hasElements()
1234 throw ( uno::RuntimeException )
1236 ::osl::MutexGuard aGuard( m_aMutex );
1238 if ( !m_pImpl )
1239 throw lang::DisposedException();
1241 if ( !GetContent() )
1242 throw io::IOException(); // TODO: error handling
1244 uno::Sequence< ::rtl::OUString > aProps( 1 );
1245 aProps[0] = ::rtl::OUString::createFromAscii( "TargetURL" );
1246 ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
1250 uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude );
1251 return ( xResultSet.is() && xResultSet->next() );
1253 catch( uno::Exception& )
1255 throw uno::RuntimeException();
1260 //____________________________________________________________________________________________________
1261 // XDisposable
1262 //____________________________________________________________________________________________________
1264 //-----------------------------------------------
1265 void SAL_CALL FSStorage::dispose()
1266 throw ( uno::RuntimeException )
1268 ::osl::MutexGuard aGuard( m_aMutex );
1270 if ( !m_pImpl )
1271 throw lang::DisposedException();
1273 if ( m_pImpl->m_pListenersContainer )
1275 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
1276 m_pImpl->m_pListenersContainer->disposeAndClear( aSource );
1279 delete m_pImpl;
1280 m_pImpl = NULL;
1283 //-----------------------------------------------
1284 void SAL_CALL FSStorage::addEventListener(
1285 const uno::Reference< lang::XEventListener >& xListener )
1286 throw ( uno::RuntimeException )
1288 ::osl::MutexGuard aGuard( m_aMutex );
1290 if ( !m_pImpl )
1291 throw lang::DisposedException();
1293 if ( !m_pImpl->m_pListenersContainer )
1294 m_pImpl->m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
1296 m_pImpl->m_pListenersContainer->addInterface( xListener );
1299 //-----------------------------------------------
1300 void SAL_CALL FSStorage::removeEventListener(
1301 const uno::Reference< lang::XEventListener >& xListener )
1302 throw ( uno::RuntimeException )
1304 ::osl::MutexGuard aGuard( m_aMutex );
1306 if ( !m_pImpl )
1307 throw lang::DisposedException();
1309 if ( m_pImpl->m_pListenersContainer )
1310 m_pImpl->m_pListenersContainer->removeInterface( xListener );
1313 //____________________________________________________________________________________________________
1314 // XPropertySet
1315 //____________________________________________________________________________________________________
1317 //-----------------------------------------------
1318 uno::Reference< beans::XPropertySetInfo > SAL_CALL FSStorage::getPropertySetInfo()
1319 throw ( uno::RuntimeException )
1321 ::osl::MutexGuard aGuard( m_aMutex );
1323 if ( !m_pImpl )
1324 throw lang::DisposedException();
1326 //TODO:
1327 return uno::Reference< beans::XPropertySetInfo >();
1331 //-----------------------------------------------
1332 void SAL_CALL FSStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& )
1333 throw ( beans::UnknownPropertyException,
1334 beans::PropertyVetoException,
1335 lang::IllegalArgumentException,
1336 lang::WrappedTargetException,
1337 uno::RuntimeException )
1339 ::osl::MutexGuard aGuard( m_aMutex );
1341 if ( !m_pImpl )
1342 throw lang::DisposedException();
1344 if ( aPropertyName.equalsAscii( "URL" ) || aPropertyName.equalsAscii( "OpenMode" ) )
1345 throw beans::PropertyVetoException(); // TODO
1346 else
1347 throw beans::UnknownPropertyException(); // TODO
1351 //-----------------------------------------------
1352 uno::Any SAL_CALL FSStorage::getPropertyValue( const ::rtl::OUString& aPropertyName )
1353 throw ( beans::UnknownPropertyException,
1354 lang::WrappedTargetException,
1355 uno::RuntimeException )
1357 ::osl::MutexGuard aGuard( m_aMutex );
1359 if ( !m_pImpl )
1360 throw lang::DisposedException();
1362 if ( aPropertyName.equalsAscii( "URL" ) )
1363 return uno::makeAny( m_pImpl->m_aURL );
1364 else if ( aPropertyName.equalsAscii( "OpenMode" ) )
1365 return uno::makeAny( m_pImpl->m_nMode );
1367 throw beans::UnknownPropertyException(); // TODO
1371 //-----------------------------------------------
1372 void SAL_CALL FSStorage::addPropertyChangeListener(
1373 const ::rtl::OUString& /*aPropertyName*/,
1374 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
1375 throw ( beans::UnknownPropertyException,
1376 lang::WrappedTargetException,
1377 uno::RuntimeException )
1379 ::osl::MutexGuard aGuard( m_aMutex );
1381 if ( !m_pImpl )
1382 throw lang::DisposedException();
1384 //TODO:
1388 //-----------------------------------------------
1389 void SAL_CALL FSStorage::removePropertyChangeListener(
1390 const ::rtl::OUString& /*aPropertyName*/,
1391 const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
1392 throw ( beans::UnknownPropertyException,
1393 lang::WrappedTargetException,
1394 uno::RuntimeException )
1396 ::osl::MutexGuard aGuard( m_aMutex );
1398 if ( !m_pImpl )
1399 throw lang::DisposedException();
1401 //TODO:
1405 //-----------------------------------------------
1406 void SAL_CALL FSStorage::addVetoableChangeListener(
1407 const ::rtl::OUString& /*PropertyName*/,
1408 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
1409 throw ( beans::UnknownPropertyException,
1410 lang::WrappedTargetException,
1411 uno::RuntimeException )
1413 ::osl::MutexGuard aGuard( m_aMutex );
1415 if ( !m_pImpl )
1416 throw lang::DisposedException();
1418 //TODO:
1422 //-----------------------------------------------
1423 void SAL_CALL FSStorage::removeVetoableChangeListener(
1424 const ::rtl::OUString& /*PropertyName*/,
1425 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
1426 throw ( beans::UnknownPropertyException,
1427 lang::WrappedTargetException,
1428 uno::RuntimeException )
1430 ::osl::MutexGuard aGuard( m_aMutex );
1432 if ( !m_pImpl )
1433 throw lang::DisposedException();
1435 //TODO:
1438 //____________________________________________________________________________________________________
1439 // XHierarchicalStorageAccess
1440 //____________________________________________________________________________________________________
1441 //-----------------------------------------------
1442 uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath, ::sal_Int32 nOpenMode )
1443 throw ( embed::InvalidStorageException,
1444 lang::IllegalArgumentException,
1445 packages::WrongPasswordException,
1446 io::IOException,
1447 embed::StorageWrappedTargetException,
1448 uno::RuntimeException )
1450 ::osl::MutexGuard aGuard( m_aMutex );
1452 if ( !m_pImpl )
1453 throw lang::DisposedException();
1455 if ( sStreamPath.toChar() == '/' )
1456 throw lang::IllegalArgumentException();
1458 if ( !GetContent() )
1459 throw io::IOException(); // TODO: error handling
1461 INetURLObject aBaseURL( m_pImpl->m_aURL );
1462 if ( !aBaseURL.setFinalSlash() )
1463 throw uno::RuntimeException();
1465 INetURLObject aFileURL = INetURLObject::GetAbsURL(
1466 aBaseURL.GetMainURL( INetURLObject::NO_DECODE ),
1467 sStreamPath );
1469 if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1470 throw io::IOException();
1472 if ( ( nOpenMode & embed::ElementModes::NOCREATE )
1473 && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1474 throw io::IOException(); // TODO:
1476 uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
1477 uno::Reference< io::XStream > xResult;
1480 if ( nOpenMode & embed::ElementModes::WRITE )
1482 if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1484 uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess(
1485 m_pImpl->m_xFactory->createInstance(
1486 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ),
1487 uno::UNO_QUERY_THROW );
1488 uno::Reference< io::XStream > xStream =
1489 xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) );
1491 xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) );
1493 else
1495 // TODO: test whether it really works for http and fwp
1496 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ),
1497 STREAM_STD_WRITE );
1498 if ( pStream )
1500 if ( !pStream->GetError() )
1502 uno::Reference< io::XStream > xStream =
1503 uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) );
1504 xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) );
1506 else
1507 delete pStream;
1511 if ( !xResult.is() )
1512 throw io::IOException();
1514 if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) )
1516 uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW );
1517 xTrunc->truncate();
1520 else
1522 if ( ( nOpenMode & embed::ElementModes::TRUNCATE )
1523 || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1524 throw io::IOException(); // TODO: access denied
1526 ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
1527 uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
1528 xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) );
1531 catch( embed::InvalidStorageException& )
1533 throw;
1535 catch( lang::IllegalArgumentException& )
1537 throw;
1539 catch( packages::WrongPasswordException& )
1541 throw;
1543 catch( embed::StorageWrappedTargetException& )
1545 throw;
1547 catch( io::IOException& )
1549 throw;
1551 catch( uno::RuntimeException& )
1553 throw;
1555 catch( uno::Exception& )
1557 uno::Any aCaught( ::cppu::getCaughtException() );
1558 throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
1559 uno::Reference< io::XInputStream >(),
1560 aCaught );
1563 return uno::Reference< embed::XExtendedStorageStream >( xResult, uno::UNO_QUERY_THROW );
1566 //-----------------------------------------------
1567 uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& /*sStreamName*/, ::sal_Int32 /*nOpenMode*/, const ::rtl::OUString& /*sPassword*/ )
1568 throw ( embed::InvalidStorageException,
1569 lang::IllegalArgumentException,
1570 packages::NoEncryptionException,
1571 packages::WrongPasswordException,
1572 io::IOException,
1573 embed::StorageWrappedTargetException,
1574 uno::RuntimeException )
1576 throw packages::NoEncryptionException();
1579 //-----------------------------------------------
1580 void SAL_CALL FSStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath )
1581 throw ( embed::InvalidStorageException,
1582 lang::IllegalArgumentException,
1583 container::NoSuchElementException,
1584 io::IOException,
1585 embed::StorageWrappedTargetException,
1586 uno::RuntimeException )
1588 ::osl::MutexGuard aGuard( m_aMutex );
1590 if ( !m_pImpl )
1591 throw lang::DisposedException();
1593 if ( !GetContent() )
1594 throw io::IOException(); // TODO: error handling
1596 // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
1597 INetURLObject aBaseURL( m_pImpl->m_aURL );
1598 if ( !aBaseURL.setFinalSlash() )
1599 throw uno::RuntimeException();
1601 INetURLObject aFileURL = INetURLObject::GetAbsURL(
1602 aBaseURL.GetMainURL( INetURLObject::NO_DECODE ),
1603 sStreamPath );
1605 if ( !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1607 if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1608 throw lang::IllegalArgumentException();
1609 else
1610 throw container::NoSuchElementException(); // TODO:
1613 if ( !::utl::UCBContentHelper::Kill( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1614 throw io::IOException(); // TODO: error handling