bump product version to 4.1.6.2
[LibreOffice.git] / svl / source / fsstor / fsstorage.cxx
blob41bf495b419515ab768672d2365a284ccae2c122
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/beans/PropertyValue.hpp>
21 #include <com/sun/star/embed/ElementModes.hpp>
22 #include <com/sun/star/embed/XTransactedObject.hpp>
23 #include <com/sun/star/ucb/NameClash.hpp>
24 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
25 #include <com/sun/star/ucb/XProgressHandler.hpp>
26 #include <com/sun/star/ucb/XContentAccess.hpp>
27 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
29 #include <com/sun/star/ucb/InteractiveIOException.hpp>
30 #include <com/sun/star/ucb/IOErrorCode.hpp>
31 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
32 #include <com/sun/star/container/XEnumerationAccess.hpp>
33 #include <com/sun/star/container/XNamed.hpp>
34 #include <com/sun/star/util/XChangesBatch.hpp>
35 #include <com/sun/star/util/XCloneable.hpp>
36 #include <com/sun/star/lang/XUnoTunnel.hpp>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <com/sun/star/lang/DisposedException.hpp>
39 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
40 #include <com/sun/star/io/IOException.hpp>
41 #include <com/sun/star/io/XTruncate.hpp>
42 #include <com/sun/star/io/TempFile.hpp>
43 #include <com/sun/star/sdbc/XResultSet.hpp>
44 #include <com/sun/star/sdbc/XRow.hpp>
47 #include <comphelper/processfactory.hxx>
48 #include <comphelper/storagehelper.hxx>
49 #include <cppuhelper/typeprovider.hxx>
50 #include <cppuhelper/exc_hlp.hxx>
52 #include <tools/urlobj.hxx>
53 #include <unotools/ucbhelper.hxx>
54 #include <unotools/ucbstreamhelper.hxx>
55 #include <unotools/streamwrap.hxx>
56 #include <ucbhelper/fileidentifierconverter.hxx>
57 #include <ucbhelper/content.hxx>
59 #include "fsstorage.hxx"
60 #include "oinputstreamcontainer.hxx"
61 #include "ostreamcontainer.hxx"
63 using namespace ::com::sun::star;
65 //=========================================================
67 // TODO: move to a standard helper
68 sal_Bool isLocalFile_Impl( OUString aURL )
70 OUString aSystemPath;
72 try
74 aSystemPath = ::ucbhelper::getSystemPathFromFileURL(
75 ucb::UniversalContentBroker::create(
76 comphelper::getProcessComponentContext() ),
77 aURL );
79 catch ( uno::Exception& )
83 return ( !aSystemPath.isEmpty() );
87 //=========================================================
89 struct FSStorage_Impl
91 OUString m_aURL;
93 ::ucbhelper::Content* m_pContent;
94 sal_Int32 m_nMode;
96 ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners
97 ::cppu::OTypeCollection* m_pTypeCollection;
99 uno::Reference< lang::XMultiServiceFactory > m_xFactory;
102 FSStorage_Impl( const OUString& aURL, sal_Int32 nMode, uno::Reference< lang::XMultiServiceFactory > xFactory )
103 : m_aURL( aURL )
104 , m_pContent( NULL )
105 , m_nMode( nMode )
106 , m_pListenersContainer( NULL )
107 , m_pTypeCollection( NULL )
108 , m_xFactory( xFactory )
110 OSL_ENSURE( !m_aURL.isEmpty(), "The URL must not be empty" );
113 FSStorage_Impl( const ::ucbhelper::Content& aContent, sal_Int32 nMode, uno::Reference< lang::XMultiServiceFactory > xFactory )
114 : m_aURL( aContent.getURL() )
115 , m_pContent( new ::ucbhelper::Content( aContent ) )
116 , m_nMode( nMode )
117 , m_pListenersContainer( NULL )
118 , m_pTypeCollection( NULL )
119 , m_xFactory( xFactory )
121 OSL_ENSURE( !m_aURL.isEmpty(), "The URL must not be empty" );
124 ~FSStorage_Impl();
127 //=========================================================
129 FSStorage_Impl::~FSStorage_Impl()
131 if ( m_pListenersContainer )
132 delete m_pListenersContainer;
133 if ( m_pTypeCollection )
134 delete m_pTypeCollection;
135 if ( m_pContent )
136 delete m_pContent;
139 //=====================================================
140 // FSStorage implementation
141 //=====================================================
143 //-----------------------------------------------
144 FSStorage::FSStorage( const ::ucbhelper::Content& aContent,
145 sal_Int32 nMode,
146 uno::Reference< lang::XMultiServiceFactory > xFactory )
147 : m_pImpl( new FSStorage_Impl( aContent, nMode, xFactory ) )
149 // TODO: use properties
150 if ( !xFactory.is() )
151 throw uno::RuntimeException();
153 GetContent();
156 //-----------------------------------------------
157 FSStorage::~FSStorage()
160 ::osl::MutexGuard aGuard( m_aMutex );
161 m_refCount++; // to call dispose
162 try {
163 dispose();
165 catch( uno::RuntimeException& )
170 //-----------------------------------------------
171 sal_Bool FSStorage::MakeFolderNoUI( const OUString& rFolder )
173 INetURLObject aURL( rFolder );
174 OUString aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
175 aURL.removeSegment();
176 ::ucbhelper::Content aParent;
177 ::ucbhelper::Content aResultContent;
179 if ( ::ucbhelper::Content::create( aURL.GetMainURL( INetURLObject::NO_DECODE ),
180 uno::Reference< ucb::XCommandEnvironment >(),
181 comphelper::getProcessComponentContext(),
182 aParent ) )
183 return ::utl::UCBContentHelper::MakeFolder( aParent, aTitle, aResultContent, sal_False );
185 return sal_False;
188 //-----------------------------------------------
189 ::ucbhelper::Content* FSStorage::GetContent()
191 ::osl::MutexGuard aGuard( m_aMutex );
192 if ( !m_pImpl->m_pContent )
194 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
198 m_pImpl->m_pContent = new ::ucbhelper::Content( m_pImpl->m_aURL, xDummyEnv, comphelper::getProcessComponentContext() );
200 catch( uno::Exception& )
205 return m_pImpl->m_pContent;
208 //-----------------------------------------------
209 void FSStorage::CopyStreamToSubStream( const OUString& aSourceURL,
210 const uno::Reference< embed::XStorage >& xDest,
211 const OUString& aNewEntryName )
213 if ( !xDest.is() )
214 throw uno::RuntimeException();
216 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
217 ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv, comphelper::getProcessComponentContext() );
218 uno::Reference< io::XInputStream > xSourceInput = aSourceContent.openStream();
220 if ( !xSourceInput.is() )
221 throw io::IOException(); // TODO: error handling
223 uno::Reference< io::XStream > xSubStream = xDest->openStreamElement(
224 aNewEntryName,
225 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
226 if ( !xSubStream.is() )
227 throw uno::RuntimeException();
229 uno::Reference< io::XOutputStream > xDestOutput = xSubStream->getOutputStream();
230 if ( !xDestOutput.is() )
231 throw uno::RuntimeException();
233 ::comphelper::OStorageHelper::CopyInputToOutput( xSourceInput, xDestOutput );
234 xDestOutput->closeOutput();
237 //-----------------------------------------------
238 void FSStorage::CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, const uno::Reference< embed::XStorage >& xDest )
240 if ( !pContent )
241 throw uno::RuntimeException();
243 // get list of contents of the Content
244 // create cursor for access to children
245 uno::Sequence< OUString > aProps( 2 );
246 OUString* pProps = aProps.getArray();
247 pProps[0] = OUString("TargetURL");
248 pProps[1] = OUString("IsFolder");
249 ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
253 uno::Reference< sdbc::XResultSet > xResultSet = pContent->createCursor( aProps, eInclude );
254 uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
255 uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
256 if ( xResultSet.is() )
258 // go through the list: insert files as streams, insert folders as substorages using recursion
259 while ( xResultSet->next() )
261 OUString aSourceURL( xRow->getString( 1 ) );
262 sal_Bool bIsFolder( xRow->getBoolean(2) );
264 // TODO/LATER: not sure whether the entry name must be encoded
265 OUString aNewEntryName( INetURLObject( aSourceURL ).getName( INetURLObject::LAST_SEGMENT,
266 true,
267 INetURLObject::NO_DECODE ) );
268 if ( bIsFolder )
270 uno::Reference< embed::XStorage > xSubStorage = xDest->openStorageElement( aNewEntryName,
271 embed::ElementModes::READWRITE );
272 if ( !xSubStorage.is() )
273 throw uno::RuntimeException();
275 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
276 ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv, comphelper::getProcessComponentContext() );
277 CopyContentToStorage_Impl( &aSourceContent, xSubStorage );
279 else
281 CopyStreamToSubStream( aSourceURL, xDest, aNewEntryName );
286 uno::Reference< embed::XTransactedObject > xTransact( xDest, uno::UNO_QUERY );
287 if ( xTransact.is() )
288 xTransact->commit();
290 catch( ucb::InteractiveIOException& r )
292 if ( r.Code == ucb::IOErrorCode_NOT_EXISTING )
293 OSL_FAIL( "The folder does not exist!\n" );
294 else
295 throw;
299 //____________________________________________________________________________________________________
300 // XInterface
301 //____________________________________________________________________________________________________
303 //-----------------------------------------------
304 uno::Any SAL_CALL FSStorage::queryInterface( const uno::Type& rType )
305 throw( uno::RuntimeException )
307 uno::Any aReturn;
308 aReturn <<= ::cppu::queryInterface
309 ( rType
310 , static_cast<lang::XTypeProvider*> ( this )
311 , static_cast<embed::XStorage*> ( this )
312 , static_cast<embed::XHierarchicalStorageAccess*> ( this )
313 , static_cast<container::XNameAccess*> ( this )
314 , static_cast<container::XElementAccess*> ( this )
315 , static_cast<lang::XComponent*> ( this )
316 , static_cast<beans::XPropertySet*> ( this ) );
318 if ( aReturn.hasValue() == sal_True )
319 return aReturn ;
321 return OWeakObject::queryInterface( rType );
324 //-----------------------------------------------
325 void SAL_CALL FSStorage::acquire() throw()
327 OWeakObject::acquire();
330 //-----------------------------------------------
331 void SAL_CALL FSStorage::release() throw()
333 OWeakObject::release();
336 //____________________________________________________________________________________________________
337 // XTypeProvider
338 //____________________________________________________________________________________________________
340 //-----------------------------------------------
341 uno::Sequence< uno::Type > SAL_CALL FSStorage::getTypes()
342 throw( uno::RuntimeException )
344 if ( m_pImpl->m_pTypeCollection == NULL )
346 ::osl::MutexGuard aGuard( m_aMutex );
348 if ( m_pImpl->m_pTypeCollection == NULL )
350 m_pImpl->m_pTypeCollection = new ::cppu::OTypeCollection
351 ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
352 , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
353 , ::getCppuType( ( const uno::Reference< embed::XHierarchicalStorageAccess >* )NULL )
354 , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
358 return m_pImpl->m_pTypeCollection->getTypes() ;
361 //-----------------------------------------------
362 uno::Sequence< sal_Int8 > SAL_CALL FSStorage::getImplementationId()
363 throw( uno::RuntimeException )
365 static ::cppu::OImplementationId* pID = NULL ;
367 if ( pID == NULL )
369 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;
371 if ( pID == NULL )
373 static ::cppu::OImplementationId aID( sal_False ) ;
374 pID = &aID ;
378 return pID->getImplementationId() ;
382 //____________________________________________________________________________________________________
383 // XStorage
384 //____________________________________________________________________________________________________
386 //-----------------------------------------------
387 void SAL_CALL FSStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest )
388 throw ( embed::InvalidStorageException,
389 io::IOException,
390 lang::IllegalArgumentException,
391 embed::StorageWrappedTargetException,
392 uno::RuntimeException )
394 ::osl::MutexGuard aGuard( m_aMutex );
396 if ( !m_pImpl )
397 throw lang::DisposedException();
399 if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) )
400 throw lang::IllegalArgumentException(); // TODO:
402 if ( !GetContent() )
403 throw io::IOException(); // TODO: error handling
407 CopyContentToStorage_Impl( GetContent(), xDest );
409 catch( embed::InvalidStorageException& )
411 throw;
413 catch( lang::IllegalArgumentException& )
415 throw;
417 catch( embed::StorageWrappedTargetException& )
419 throw;
421 catch( io::IOException& )
423 throw;
425 catch( uno::RuntimeException& )
427 throw;
429 catch( uno::Exception& )
431 uno::Any aCaught( ::cppu::getCaughtException() );
432 throw embed::StorageWrappedTargetException( OUString("Can't copy raw stream"),
433 uno::Reference< io::XInputStream >(),
434 aCaught );
438 //-----------------------------------------------
439 uno::Reference< io::XStream > SAL_CALL FSStorage::openStreamElement(
440 const OUString& aStreamName, sal_Int32 nOpenMode )
441 throw ( embed::InvalidStorageException,
442 lang::IllegalArgumentException,
443 packages::WrongPasswordException,
444 io::IOException,
445 embed::StorageWrappedTargetException,
446 uno::RuntimeException )
448 ::osl::MutexGuard aGuard( m_aMutex );
450 if ( !m_pImpl )
451 throw lang::DisposedException();
453 if ( !GetContent() )
454 throw io::IOException(); // TODO: error handling
456 // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
457 INetURLObject aFileURL( m_pImpl->m_aURL );
458 aFileURL.Append( aStreamName );
460 if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
461 throw io::IOException();
463 if ( ( nOpenMode & embed::ElementModes::NOCREATE )
464 && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
465 throw io::IOException(); // TODO:
467 uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
468 uno::Reference< io::XStream > xResult;
471 if ( nOpenMode & embed::ElementModes::WRITE )
473 if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
475 uno::Reference<ucb::XSimpleFileAccess3> xSimpleFileAccess(
476 ucb::SimpleFileAccess::create(
477 comphelper::getComponentContext(m_pImpl->m_xFactory) ) );
478 xResult = xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) );
480 else
482 // TODO: test whether it really works for http and fwp
483 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ),
484 STREAM_STD_WRITE );
485 if ( pStream )
487 if ( !pStream->GetError() )
488 xResult = uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) );
489 else
490 delete pStream;
494 if ( !xResult.is() )
495 throw io::IOException();
497 if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) )
499 uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW );
500 xTrunc->truncate();
503 else
505 if ( ( nOpenMode & embed::ElementModes::TRUNCATE )
506 || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
507 throw io::IOException(); // TODO: access denied
509 ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
510 uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
511 xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) );
514 catch( embed::InvalidStorageException& )
516 throw;
518 catch( lang::IllegalArgumentException& )
520 throw;
522 catch( packages::WrongPasswordException& )
524 throw;
526 catch( embed::StorageWrappedTargetException& )
528 throw;
530 catch( io::IOException& )
532 throw;
534 catch( uno::RuntimeException& )
536 throw;
538 catch( uno::Exception& )
540 uno::Any aCaught( ::cppu::getCaughtException() );
541 throw embed::StorageWrappedTargetException( OUString("Can't copy raw stream"),
542 uno::Reference< io::XInputStream >(),
543 aCaught );
546 return xResult;
549 //-----------------------------------------------
550 uno::Reference< io::XStream > SAL_CALL FSStorage::openEncryptedStreamElement(
551 const OUString&, sal_Int32, const OUString& )
552 throw ( embed::InvalidStorageException,
553 lang::IllegalArgumentException,
554 packages::NoEncryptionException,
555 packages::WrongPasswordException,
556 io::IOException,
557 embed::StorageWrappedTargetException,
558 uno::RuntimeException )
560 throw packages::NoEncryptionException();
563 //-----------------------------------------------
564 uno::Reference< embed::XStorage > SAL_CALL FSStorage::openStorageElement(
565 const OUString& aStorName, sal_Int32 nStorageMode )
566 throw ( embed::InvalidStorageException,
567 lang::IllegalArgumentException,
568 io::IOException,
569 embed::StorageWrappedTargetException,
570 uno::RuntimeException )
572 ::osl::MutexGuard aGuard( m_aMutex );
574 if ( !m_pImpl )
575 throw lang::DisposedException();
577 if ( !GetContent() )
578 throw io::IOException(); // TODO: error handling
580 if ( ( nStorageMode & embed::ElementModes::WRITE )
581 && !( m_pImpl->m_nMode & embed::ElementModes::WRITE ) )
582 throw io::IOException(); // TODO: error handling
584 // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
585 INetURLObject aFolderURL( m_pImpl->m_aURL );
586 aFolderURL.Append( aStorName );
588 sal_Bool bFolderExists = ::utl::UCBContentHelper::IsFolder( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) );
589 if ( !bFolderExists && ::utl::UCBContentHelper::IsDocument( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
590 throw io::IOException(); // TODO:
592 if ( ( nStorageMode & embed::ElementModes::NOCREATE ) && !bFolderExists )
593 throw io::IOException(); // TODO:
595 uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
596 uno::Reference< embed::XStorage > xResult;
599 if ( nStorageMode & embed::ElementModes::WRITE )
601 if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) && bFolderExists )
603 ::utl::UCBContentHelper::Kill( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) );
604 bFolderExists =
605 MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ); // TODO: not atomic :(
607 else if ( !bFolderExists )
609 bFolderExists =
610 MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ); // TODO: not atomic :(
613 else if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) )
614 throw io::IOException(); // TODO: access denied
616 if ( !bFolderExists )
617 throw io::IOException(); // there is no such folder
619 ::ucbhelper::Content aResultContent( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
620 xResult = uno::Reference< embed::XStorage >(
621 static_cast< OWeakObject* >( new FSStorage( aResultContent,
622 nStorageMode,
623 m_pImpl->m_xFactory ) ),
624 uno::UNO_QUERY );
626 catch( embed::InvalidStorageException& )
628 throw;
630 catch( lang::IllegalArgumentException& )
632 throw;
634 catch( embed::StorageWrappedTargetException& )
636 throw;
638 catch( io::IOException& )
640 throw;
642 catch( uno::RuntimeException& )
644 throw;
646 catch( uno::Exception& )
648 uno::Any aCaught( ::cppu::getCaughtException() );
649 throw embed::StorageWrappedTargetException( OUString("Can't copy raw stream"),
650 uno::Reference< io::XInputStream >(),
651 aCaught );
654 return xResult;
657 //-----------------------------------------------
658 uno::Reference< io::XStream > SAL_CALL FSStorage::cloneStreamElement( const OUString& aStreamName )
659 throw ( embed::InvalidStorageException,
660 lang::IllegalArgumentException,
661 packages::WrongPasswordException,
662 io::IOException,
663 embed::StorageWrappedTargetException,
664 uno::RuntimeException )
666 ::osl::MutexGuard aGuard( m_aMutex );
668 if ( !m_pImpl )
669 throw lang::DisposedException();
671 if ( !GetContent() )
672 throw io::IOException(); // TODO: error handling
674 // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
675 INetURLObject aFileURL( m_pImpl->m_aURL );
676 aFileURL.Append( aStreamName );
678 uno::Reference < io::XStream > xTempResult;
681 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
682 ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
683 uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
685 xTempResult = uno::Reference < io::XStream >(
686 io::TempFile::create(comphelper::getComponentContext(m_pImpl->m_xFactory)),
687 uno::UNO_QUERY_THROW );
688 uno::Reference < io::XOutputStream > xTempOut = xTempResult->getOutputStream();
689 uno::Reference < io::XInputStream > xTempIn = xTempResult->getInputStream();
691 if ( !xTempOut.is() || !xTempIn.is() )
692 throw io::IOException();
694 ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut );
695 xTempOut->closeOutput();
697 catch( embed::InvalidStorageException& )
699 throw;
701 catch( lang::IllegalArgumentException& )
703 throw;
705 catch( packages::WrongPasswordException& )
707 throw;
709 catch( io::IOException& )
711 throw;
713 catch( embed::StorageWrappedTargetException& )
715 throw;
717 catch( uno::RuntimeException& )
719 throw;
721 catch( uno::Exception& )
723 uno::Any aCaught( ::cppu::getCaughtException() );
724 throw embed::StorageWrappedTargetException( OUString("Can't copy raw stream"),
725 uno::Reference< io::XInputStream >(),
726 aCaught );
729 return xTempResult;
732 //-----------------------------------------------
733 uno::Reference< io::XStream > SAL_CALL FSStorage::cloneEncryptedStreamElement(
734 const OUString&,
735 const OUString& )
736 throw ( embed::InvalidStorageException,
737 lang::IllegalArgumentException,
738 packages::NoEncryptionException,
739 packages::WrongPasswordException,
740 io::IOException,
741 embed::StorageWrappedTargetException,
742 uno::RuntimeException )
744 throw packages::NoEncryptionException();
747 //-----------------------------------------------
748 void SAL_CALL FSStorage::copyLastCommitTo(
749 const uno::Reference< embed::XStorage >& xTargetStorage )
750 throw ( embed::InvalidStorageException,
751 lang::IllegalArgumentException,
752 io::IOException,
753 embed::StorageWrappedTargetException,
754 uno::RuntimeException )
756 copyToStorage( xTargetStorage );
759 //-----------------------------------------------
760 void SAL_CALL FSStorage::copyStorageElementLastCommitTo(
761 const OUString& aStorName,
762 const uno::Reference< embed::XStorage >& xTargetStorage )
763 throw ( embed::InvalidStorageException,
764 lang::IllegalArgumentException,
765 io::IOException,
766 embed::StorageWrappedTargetException,
767 uno::RuntimeException )
769 ::osl::MutexGuard aGuard( m_aMutex );
771 if ( !m_pImpl )
772 throw lang::DisposedException();
774 uno::Reference< embed::XStorage > xSourceStor( openStorageElement( aStorName, embed::ElementModes::READ ),
775 uno::UNO_QUERY_THROW );
776 xSourceStor->copyToStorage( xTargetStorage );
779 //-----------------------------------------------
780 sal_Bool SAL_CALL FSStorage::isStreamElement( const OUString& aElementName )
781 throw ( embed::InvalidStorageException,
782 lang::IllegalArgumentException,
783 container::NoSuchElementException,
784 uno::RuntimeException )
786 ::osl::MutexGuard aGuard( m_aMutex );
788 if ( !m_pImpl )
789 throw lang::DisposedException();
791 if ( !GetContent() )
792 throw embed::InvalidStorageException(); // TODO: error handling
794 INetURLObject aURL( m_pImpl->m_aURL );
795 aURL.Append( aElementName );
797 return !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
800 //-----------------------------------------------
801 sal_Bool SAL_CALL FSStorage::isStorageElement( const OUString& aElementName )
802 throw ( embed::InvalidStorageException,
803 lang::IllegalArgumentException,
804 container::NoSuchElementException,
805 uno::RuntimeException )
807 ::osl::MutexGuard aGuard( m_aMutex );
809 if ( !m_pImpl )
810 throw lang::DisposedException();
812 if ( !GetContent() )
813 throw embed::InvalidStorageException(); // TODO: error handling
815 INetURLObject aURL( m_pImpl->m_aURL );
816 aURL.Append( aElementName );
818 return ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
821 //-----------------------------------------------
822 void SAL_CALL FSStorage::removeElement( const OUString& aElementName )
823 throw ( embed::InvalidStorageException,
824 lang::IllegalArgumentException,
825 container::NoSuchElementException,
826 io::IOException,
827 embed::StorageWrappedTargetException,
828 uno::RuntimeException )
830 ::osl::MutexGuard aGuard( m_aMutex );
832 if ( !m_pImpl )
833 throw lang::DisposedException();
835 if ( !GetContent() )
836 throw io::IOException(); // TODO: error handling
838 INetURLObject aURL( m_pImpl->m_aURL );
839 aURL.Append( aElementName );
841 if ( !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) )
842 && !::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
843 throw container::NoSuchElementException(); // TODO:
845 ::utl::UCBContentHelper::Kill( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
848 //-----------------------------------------------
849 void SAL_CALL FSStorage::renameElement( const OUString& aElementName, const OUString& aNewName )
850 throw ( embed::InvalidStorageException,
851 lang::IllegalArgumentException,
852 container::NoSuchElementException,
853 container::ElementExistException,
854 io::IOException,
855 embed::StorageWrappedTargetException,
856 uno::RuntimeException )
858 ::osl::MutexGuard aGuard( m_aMutex );
860 if ( !m_pImpl )
861 throw lang::DisposedException();
863 if ( !GetContent() )
864 throw io::IOException(); // TODO: error handling
866 INetURLObject aOldURL( m_pImpl->m_aURL );
867 aOldURL.Append( aElementName );
869 INetURLObject aNewURL( m_pImpl->m_aURL );
870 aNewURL.Append( aNewName );
872 if ( !::utl::UCBContentHelper::IsFolder( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) )
873 && !::utl::UCBContentHelper::IsDocument( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
874 throw container::NoSuchElementException(); // TODO:
876 if ( ::utl::UCBContentHelper::IsFolder( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) )
877 || ::utl::UCBContentHelper::IsDocument( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
878 throw container::ElementExistException(); // TODO:
882 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
883 ::ucbhelper::Content aSourceContent( aOldURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
885 if ( !GetContent()->transferContent( aSourceContent,
886 ::ucbhelper::InsertOperation_MOVE,
887 aNewName,
888 ucb::NameClash::ERROR ) )
889 throw io::IOException(); // TODO: error handling
891 catch( embed::InvalidStorageException& )
893 throw;
895 catch( lang::IllegalArgumentException& )
897 throw;
899 catch( container::NoSuchElementException& )
901 throw;
903 catch( container::ElementExistException& )
905 throw;
907 catch( io::IOException& )
909 throw;
911 catch( embed::StorageWrappedTargetException& )
913 throw;
915 catch( uno::RuntimeException& )
917 throw;
919 catch( uno::Exception& )
921 uno::Any aCaught( ::cppu::getCaughtException() );
922 throw embed::StorageWrappedTargetException( OUString("Can't copy raw stream"),
923 uno::Reference< io::XInputStream >(),
924 aCaught );
928 //-----------------------------------------------
929 void SAL_CALL FSStorage::copyElementTo( const OUString& aElementName,
930 const uno::Reference< embed::XStorage >& xDest,
931 const OUString& aNewName )
932 throw ( embed::InvalidStorageException,
933 lang::IllegalArgumentException,
934 container::NoSuchElementException,
935 container::ElementExistException,
936 io::IOException,
937 embed::StorageWrappedTargetException,
938 uno::RuntimeException )
940 ::osl::MutexGuard aGuard( m_aMutex );
942 if ( !m_pImpl )
943 throw lang::DisposedException();
945 if ( !xDest.is() )
946 throw uno::RuntimeException();
948 if ( !GetContent() )
949 throw io::IOException(); // TODO: error handling
951 INetURLObject aOwnURL( m_pImpl->m_aURL );
952 aOwnURL.Append( aElementName );
954 if ( xDest->hasByName( aNewName ) )
955 throw container::ElementExistException(); // TODO:
959 uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
960 if ( ::utl::UCBContentHelper::IsFolder( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
962 ::ucbhelper::Content aSourceContent( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
963 uno::Reference< embed::XStorage > xDestSubStor(
964 xDest->openStorageElement( aNewName, embed::ElementModes::READWRITE ),
965 uno::UNO_QUERY_THROW );
967 CopyContentToStorage_Impl( &aSourceContent, xDestSubStor );
969 else if ( ::utl::UCBContentHelper::IsDocument( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
971 CopyStreamToSubStream( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDest, aNewName );
973 else
974 throw container::NoSuchElementException(); // TODO:
976 catch( embed::InvalidStorageException& )
978 throw;
980 catch( lang::IllegalArgumentException& )
982 throw;
984 catch( container::NoSuchElementException& )
986 throw;
988 catch( container::ElementExistException& )
990 throw;
992 catch( embed::StorageWrappedTargetException& )
994 throw;
996 catch( io::IOException& )
998 throw;
1000 catch( uno::RuntimeException& )
1002 throw;
1004 catch( uno::Exception& )
1006 uno::Any aCaught( ::cppu::getCaughtException() );
1007 throw embed::StorageWrappedTargetException( OUString("Can't copy raw stream"),
1008 uno::Reference< io::XInputStream >(),
1009 aCaught );
1013 //-----------------------------------------------
1014 void SAL_CALL FSStorage::moveElementTo( const OUString& aElementName,
1015 const uno::Reference< embed::XStorage >& xDest,
1016 const OUString& aNewName )
1017 throw ( embed::InvalidStorageException,
1018 lang::IllegalArgumentException,
1019 container::NoSuchElementException,
1020 container::ElementExistException,
1021 io::IOException,
1022 embed::StorageWrappedTargetException,
1023 uno::RuntimeException )
1025 ::osl::MutexGuard aGuard( m_aMutex );
1026 copyElementTo( aElementName, xDest, aNewName );
1028 INetURLObject aOwnURL( m_pImpl->m_aURL );
1029 aOwnURL.Append( aElementName );
1030 if ( !::utl::UCBContentHelper::Kill( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1031 throw io::IOException(); // TODO: error handling
1034 //____________________________________________________________________________________________________
1035 // XNameAccess
1036 //____________________________________________________________________________________________________
1038 //-----------------------------------------------
1039 uno::Any SAL_CALL FSStorage::getByName( const OUString& aName )
1040 throw ( container::NoSuchElementException,
1041 lang::WrappedTargetException,
1042 uno::RuntimeException )
1044 ::osl::MutexGuard aGuard( m_aMutex );
1046 if ( !m_pImpl )
1047 throw lang::DisposedException();
1049 if ( !GetContent() )
1050 throw io::IOException(); // TODO: error handling
1052 if ( aName.isEmpty() )
1053 throw lang::IllegalArgumentException();
1055 INetURLObject aURL( m_pImpl->m_aURL );
1056 aURL.Append( aName );
1058 uno::Any aResult;
1061 if ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1063 aResult <<= openStorageElement( aName, embed::ElementModes::READ );
1065 else if ( ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1067 aResult <<= openStreamElement( aName, embed::ElementModes::READ );
1069 else
1070 throw container::NoSuchElementException(); // TODO:
1072 catch( container::NoSuchElementException& )
1074 throw;
1076 catch( lang::WrappedTargetException& )
1078 throw;
1080 catch( uno::RuntimeException& )
1082 throw;
1084 catch ( uno::Exception& )
1086 uno::Any aCaught( ::cppu::getCaughtException() );
1087 throw lang::WrappedTargetException( OUString("Can not open element!\n"),
1088 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1089 uno::UNO_QUERY ),
1090 aCaught );
1093 return aResult;
1097 //-----------------------------------------------
1098 uno::Sequence< OUString > SAL_CALL FSStorage::getElementNames()
1099 throw ( uno::RuntimeException )
1101 ::osl::MutexGuard aGuard( m_aMutex );
1103 if ( !m_pImpl )
1104 throw lang::DisposedException();
1106 if ( !GetContent() )
1107 throw io::IOException(); // TODO: error handling
1109 uno::Sequence< OUString > aProps( 1 );
1110 OUString* pProps = aProps.getArray();
1111 pProps[0] = OUString("Title");
1112 ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
1114 uno::Sequence< OUString > aResult;
1115 sal_Int32 nSize = 0;
1119 uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude );
1120 uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
1121 uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
1122 if ( xResultSet.is() )
1124 // go through the list
1125 while ( xResultSet->next() )
1127 OUString aName( xRow->getString( 1 ) );
1128 aResult.realloc( ++nSize );
1129 aResult[nSize-1] = aName;
1133 catch( const ucb::InteractiveIOException& r )
1135 if ( r.Code == ucb::IOErrorCode_NOT_EXISTING )
1136 OSL_FAIL( "The folder does not exist!\n" );
1137 else
1139 uno::Any aCaught( ::cppu::getCaughtException() );
1140 throw lang::WrappedTargetRuntimeException( OUString("Can not open storage!\n"),
1141 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1142 uno::UNO_QUERY ),
1143 aCaught );
1146 catch( uno::RuntimeException& )
1148 throw;
1150 catch ( uno::Exception& )
1152 uno::Any aCaught( ::cppu::getCaughtException() );
1153 throw lang::WrappedTargetRuntimeException( OUString("Can not open storage!\n"),
1154 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1155 uno::UNO_QUERY ),
1156 aCaught );
1159 return aResult;
1163 //-----------------------------------------------
1164 sal_Bool SAL_CALL FSStorage::hasByName( const OUString& aName )
1165 throw ( uno::RuntimeException )
1167 ::osl::MutexGuard aGuard( m_aMutex );
1169 if ( !m_pImpl )
1170 throw lang::DisposedException();
1174 if ( !GetContent() )
1175 throw io::IOException(); // TODO: error handling
1177 if ( aName.isEmpty() )
1178 throw lang::IllegalArgumentException();
1180 catch( uno::RuntimeException& )
1182 throw;
1184 catch ( uno::Exception& )
1186 uno::Any aCaught( ::cppu::getCaughtException() );
1187 throw lang::WrappedTargetRuntimeException( OUString("Can not open storage!\n"),
1188 uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1189 uno::UNO_QUERY ),
1190 aCaught );
1193 INetURLObject aURL( m_pImpl->m_aURL );
1194 aURL.Append( aName );
1196 return ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) )
1197 || ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) );
1200 //-----------------------------------------------
1201 uno::Type SAL_CALL FSStorage::getElementType()
1202 throw ( uno::RuntimeException )
1204 ::osl::MutexGuard aGuard( m_aMutex );
1206 if ( !m_pImpl )
1207 throw lang::DisposedException();
1209 // it is a multitype container
1210 return uno::Type();
1213 //-----------------------------------------------
1214 sal_Bool SAL_CALL FSStorage::hasElements()
1215 throw ( uno::RuntimeException )
1217 ::osl::MutexGuard aGuard( m_aMutex );
1219 if ( !m_pImpl )
1220 throw lang::DisposedException();
1222 if ( !GetContent() )
1223 throw io::IOException(); // TODO: error handling
1225 uno::Sequence< OUString > aProps( 1 );
1226 aProps[0] = OUString("TargetURL");
1227 ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
1231 uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude );
1232 return ( xResultSet.is() && xResultSet->next() );
1234 catch( uno::Exception& )
1236 throw uno::RuntimeException();
1241 //____________________________________________________________________________________________________
1242 // XDisposable
1243 //____________________________________________________________________________________________________
1245 //-----------------------------------------------
1246 void SAL_CALL FSStorage::dispose()
1247 throw ( uno::RuntimeException )
1249 ::osl::MutexGuard aGuard( m_aMutex );
1251 if ( !m_pImpl )
1252 throw lang::DisposedException();
1254 if ( m_pImpl->m_pListenersContainer )
1256 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
1257 m_pImpl->m_pListenersContainer->disposeAndClear( aSource );
1260 delete m_pImpl;
1261 m_pImpl = NULL;
1264 //-----------------------------------------------
1265 void SAL_CALL FSStorage::addEventListener(
1266 const uno::Reference< lang::XEventListener >& xListener )
1267 throw ( uno::RuntimeException )
1269 ::osl::MutexGuard aGuard( m_aMutex );
1271 if ( !m_pImpl )
1272 throw lang::DisposedException();
1274 if ( !m_pImpl->m_pListenersContainer )
1275 m_pImpl->m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
1277 m_pImpl->m_pListenersContainer->addInterface( xListener );
1280 //-----------------------------------------------
1281 void SAL_CALL FSStorage::removeEventListener(
1282 const uno::Reference< lang::XEventListener >& xListener )
1283 throw ( uno::RuntimeException )
1285 ::osl::MutexGuard aGuard( m_aMutex );
1287 if ( !m_pImpl )
1288 throw lang::DisposedException();
1290 if ( m_pImpl->m_pListenersContainer )
1291 m_pImpl->m_pListenersContainer->removeInterface( xListener );
1294 //____________________________________________________________________________________________________
1295 // XPropertySet
1296 //____________________________________________________________________________________________________
1298 //-----------------------------------------------
1299 uno::Reference< beans::XPropertySetInfo > SAL_CALL FSStorage::getPropertySetInfo()
1300 throw ( uno::RuntimeException )
1302 ::osl::MutexGuard aGuard( m_aMutex );
1304 if ( !m_pImpl )
1305 throw lang::DisposedException();
1307 //TODO:
1308 return uno::Reference< beans::XPropertySetInfo >();
1312 //-----------------------------------------------
1313 void SAL_CALL FSStorage::setPropertyValue( const OUString& aPropertyName, const uno::Any& )
1314 throw ( beans::UnknownPropertyException,
1315 beans::PropertyVetoException,
1316 lang::IllegalArgumentException,
1317 lang::WrappedTargetException,
1318 uno::RuntimeException )
1320 ::osl::MutexGuard aGuard( m_aMutex );
1322 if ( !m_pImpl )
1323 throw lang::DisposedException();
1325 if ( aPropertyName == "URL" || aPropertyName == "OpenMode" )
1326 throw beans::PropertyVetoException(); // TODO
1327 else
1328 throw beans::UnknownPropertyException(); // TODO
1332 //-----------------------------------------------
1333 uno::Any SAL_CALL FSStorage::getPropertyValue( const OUString& aPropertyName )
1334 throw ( beans::UnknownPropertyException,
1335 lang::WrappedTargetException,
1336 uno::RuntimeException )
1338 ::osl::MutexGuard aGuard( m_aMutex );
1340 if ( !m_pImpl )
1341 throw lang::DisposedException();
1343 if ( aPropertyName == "URL" )
1344 return uno::makeAny( m_pImpl->m_aURL );
1345 else if ( aPropertyName == "OpenMode" )
1346 return uno::makeAny( m_pImpl->m_nMode );
1348 throw beans::UnknownPropertyException(); // TODO
1352 //-----------------------------------------------
1353 void SAL_CALL FSStorage::addPropertyChangeListener(
1354 const OUString& /*aPropertyName*/,
1355 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
1356 throw ( beans::UnknownPropertyException,
1357 lang::WrappedTargetException,
1358 uno::RuntimeException )
1360 ::osl::MutexGuard aGuard( m_aMutex );
1362 if ( !m_pImpl )
1363 throw lang::DisposedException();
1365 //TODO:
1369 //-----------------------------------------------
1370 void SAL_CALL FSStorage::removePropertyChangeListener(
1371 const OUString& /*aPropertyName*/,
1372 const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
1373 throw ( beans::UnknownPropertyException,
1374 lang::WrappedTargetException,
1375 uno::RuntimeException )
1377 ::osl::MutexGuard aGuard( m_aMutex );
1379 if ( !m_pImpl )
1380 throw lang::DisposedException();
1382 //TODO:
1386 //-----------------------------------------------
1387 void SAL_CALL FSStorage::addVetoableChangeListener(
1388 const OUString& /*PropertyName*/,
1389 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
1390 throw ( beans::UnknownPropertyException,
1391 lang::WrappedTargetException,
1392 uno::RuntimeException )
1394 ::osl::MutexGuard aGuard( m_aMutex );
1396 if ( !m_pImpl )
1397 throw lang::DisposedException();
1399 //TODO:
1403 //-----------------------------------------------
1404 void SAL_CALL FSStorage::removeVetoableChangeListener(
1405 const OUString& /*PropertyName*/,
1406 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
1407 throw ( beans::UnknownPropertyException,
1408 lang::WrappedTargetException,
1409 uno::RuntimeException )
1411 ::osl::MutexGuard aGuard( m_aMutex );
1413 if ( !m_pImpl )
1414 throw lang::DisposedException();
1416 //TODO:
1419 //____________________________________________________________________________________________________
1420 // XHierarchicalStorageAccess
1421 //____________________________________________________________________________________________________
1422 //-----------------------------------------------
1423 uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openStreamElementByHierarchicalName( const OUString& sStreamPath, ::sal_Int32 nOpenMode )
1424 throw ( embed::InvalidStorageException,
1425 lang::IllegalArgumentException,
1426 packages::WrongPasswordException,
1427 io::IOException,
1428 embed::StorageWrappedTargetException,
1429 uno::RuntimeException )
1431 ::osl::MutexGuard aGuard( m_aMutex );
1433 if ( !m_pImpl )
1434 throw lang::DisposedException();
1436 if ( sStreamPath.toChar() == '/' )
1437 throw lang::IllegalArgumentException();
1439 if ( !GetContent() )
1440 throw io::IOException(); // TODO: error handling
1442 INetURLObject aBaseURL( m_pImpl->m_aURL );
1443 if ( !aBaseURL.setFinalSlash() )
1444 throw uno::RuntimeException();
1446 INetURLObject aFileURL = INetURLObject::GetAbsURL(
1447 aBaseURL.GetMainURL( INetURLObject::NO_DECODE ),
1448 sStreamPath );
1450 if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1451 throw io::IOException();
1453 if ( ( nOpenMode & embed::ElementModes::NOCREATE )
1454 && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1455 throw io::IOException(); // TODO:
1457 uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
1458 uno::Reference< io::XStream > xResult;
1461 if ( nOpenMode & embed::ElementModes::WRITE )
1463 if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1465 uno::Reference<ucb::XSimpleFileAccess3> xSimpleFileAccess(
1466 ucb::SimpleFileAccess::create(
1467 comphelper::getComponentContext(m_pImpl->m_xFactory) ) );
1468 uno::Reference< io::XStream > xStream =
1469 xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) );
1471 xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) );
1473 else
1475 // TODO: test whether it really works for http and fwp
1476 SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ),
1477 STREAM_STD_WRITE );
1478 if ( pStream )
1480 if ( !pStream->GetError() )
1482 uno::Reference< io::XStream > xStream =
1483 uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) );
1484 xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) );
1486 else
1487 delete pStream;
1491 if ( !xResult.is() )
1492 throw io::IOException();
1494 if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) )
1496 uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW );
1497 xTrunc->truncate();
1500 else
1502 if ( ( nOpenMode & embed::ElementModes::TRUNCATE )
1503 || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1504 throw io::IOException(); // TODO: access denied
1506 ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, comphelper::getProcessComponentContext() );
1507 uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
1508 xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) );
1511 catch( embed::InvalidStorageException& )
1513 throw;
1515 catch( lang::IllegalArgumentException& )
1517 throw;
1519 catch( packages::WrongPasswordException& )
1521 throw;
1523 catch( embed::StorageWrappedTargetException& )
1525 throw;
1527 catch( io::IOException& )
1529 throw;
1531 catch( uno::RuntimeException& )
1533 throw;
1535 catch( uno::Exception& )
1537 uno::Any aCaught( ::cppu::getCaughtException() );
1538 throw embed::StorageWrappedTargetException( OUString("Can't copy raw stream"),
1539 uno::Reference< io::XInputStream >(),
1540 aCaught );
1543 return uno::Reference< embed::XExtendedStorageStream >( xResult, uno::UNO_QUERY_THROW );
1546 //-----------------------------------------------
1547 uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openEncryptedStreamElementByHierarchicalName( const OUString& /*sStreamName*/, ::sal_Int32 /*nOpenMode*/, const OUString& /*sPassword*/ )
1548 throw ( embed::InvalidStorageException,
1549 lang::IllegalArgumentException,
1550 packages::NoEncryptionException,
1551 packages::WrongPasswordException,
1552 io::IOException,
1553 embed::StorageWrappedTargetException,
1554 uno::RuntimeException )
1556 throw packages::NoEncryptionException();
1559 //-----------------------------------------------
1560 void SAL_CALL FSStorage::removeStreamElementByHierarchicalName( const OUString& sStreamPath )
1561 throw ( embed::InvalidStorageException,
1562 lang::IllegalArgumentException,
1563 container::NoSuchElementException,
1564 io::IOException,
1565 embed::StorageWrappedTargetException,
1566 uno::RuntimeException )
1568 ::osl::MutexGuard aGuard( m_aMutex );
1570 if ( !m_pImpl )
1571 throw lang::DisposedException();
1573 if ( !GetContent() )
1574 throw io::IOException(); // TODO: error handling
1576 // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
1577 INetURLObject aBaseURL( m_pImpl->m_aURL );
1578 if ( !aBaseURL.setFinalSlash() )
1579 throw uno::RuntimeException();
1581 INetURLObject aFileURL = INetURLObject::GetAbsURL(
1582 aBaseURL.GetMainURL( INetURLObject::NO_DECODE ),
1583 sStreamPath );
1585 if ( !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1587 if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1588 throw lang::IllegalArgumentException();
1589 else
1590 throw container::NoSuchElementException(); // TODO:
1593 if ( !::utl::UCBContentHelper::Kill( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1594 throw io::IOException(); // TODO: error handling
1598 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */