1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fsstorage.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // 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>
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>
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();
88 throw uno::RuntimeException();
90 uno::Reference
< ucb::XContentProviderManager
> xManager
=
91 pBroker
->getContentProviderManagerInterface();
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
;
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
)
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
) )
134 , m_pListenersContainer( NULL
)
135 , m_pTypeCollection( NULL
)
136 , m_xFactory( xFactory
)
138 OSL_ENSURE( m_aURL
.getLength(), "The URL must not be empty" );
144 //=========================================================
146 FSStorage_Impl::~FSStorage_Impl()
148 if ( m_pListenersContainer
)
149 delete m_pListenersContainer
;
150 if ( m_pTypeCollection
)
151 delete m_pTypeCollection
;
156 //=====================================================
157 // FSStorage implementation
158 //=====================================================
160 //-----------------------------------------------
161 FSStorage::FSStorage( const ::ucbhelper::Content
& aContent
,
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();
174 //-----------------------------------------------
175 FSStorage::~FSStorage()
178 ::osl::MutexGuard
aGuard( m_aMutex
);
179 m_refCount
++; // to call 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
>(),
200 return ::utl::UCBContentHelper::MakeFolder( aParent
, aTitle
, aResultContent
, 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
)
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(
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
)
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
,
284 INetURLObject::NO_DECODE
) );
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
);
298 CopyStreamToSubStream( aSourceURL
, xDest
, aNewEntryName
);
303 uno::Reference
< embed::XTransactedObject
> xTransact( xDest
, uno::UNO_QUERY
);
304 if ( xTransact
.is() )
307 catch( ucb::InteractiveIOException
& r
)
309 if ( r
.Code
== ucb::IOErrorCode_NOT_EXISTING
)
310 OSL_ENSURE( sal_False
, "The folder does not exist!\n" );
316 //____________________________________________________________________________________________________
318 //____________________________________________________________________________________________________
320 //-----------------------------------------------
321 uno::Any SAL_CALL
FSStorage::queryInterface( const uno::Type
& rType
)
322 throw( uno::RuntimeException
)
325 aReturn
<<= ::cppu::queryInterface
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
)
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 //____________________________________________________________________________________________________
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
;
386 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() ) ;
390 static ::cppu::OImplementationId
aID( sal_False
) ;
395 return pID
->getImplementationId() ;
399 //____________________________________________________________________________________________________
401 //____________________________________________________________________________________________________
403 //-----------------------------------------------
404 void SAL_CALL
FSStorage::copyToStorage( const uno::Reference
< embed::XStorage
>& xDest
)
405 throw ( embed::InvalidStorageException
,
407 lang::IllegalArgumentException
,
408 embed::StorageWrappedTargetException
,
409 uno::RuntimeException
)
411 ::osl::MutexGuard
aGuard( m_aMutex
);
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:
420 throw io::IOException(); // TODO: error handling
424 CopyContentToStorage_Impl( GetContent(), xDest
);
426 catch( embed::InvalidStorageException
& )
430 catch( lang::IllegalArgumentException
& )
434 catch( embed::StorageWrappedTargetException
& )
438 catch( io::IOException
& )
442 catch( uno::RuntimeException
& )
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
>(),
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
,
462 embed::StorageWrappedTargetException
,
463 uno::RuntimeException
)
465 ::osl::MutexGuard
aGuard( m_aMutex
);
468 throw lang::DisposedException();
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
) );
500 // TODO: test whether it really works for http and fwp
501 SvStream
* pStream
= ::utl::UcbStreamHelper::CreateStream( aFileURL
.GetMainURL( INetURLObject::NO_DECODE
),
505 if ( !pStream
->GetError() )
506 xResult
= uno::Reference
< io::XStream
>( new ::utl::OStreamWrapper( *pStream
) );
513 throw io::IOException();
515 if ( ( nOpenMode
& embed::ElementModes::TRUNCATE
) )
517 uno::Reference
< io::XTruncate
> xTrunc( xResult
->getOutputStream(), uno::UNO_QUERY_THROW
);
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
& )
536 catch( lang::IllegalArgumentException
& )
540 catch( packages::WrongPasswordException
& )
544 catch( embed::StorageWrappedTargetException
& )
548 catch( io::IOException
& )
552 catch( uno::RuntimeException
& )
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
>(),
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
,
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
,
587 embed::StorageWrappedTargetException
,
588 uno::RuntimeException
)
590 ::osl::MutexGuard
aGuard( m_aMutex
);
593 throw lang::DisposedException();
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
) );
623 MakeFolderNoUI( aFolderURL
.GetMainURL( INetURLObject::NO_DECODE
), sal_True
); // TODO: not atomar :(
625 else if ( !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
,
641 uno::Sequence
< beans::PropertyValue
>(),
642 m_pImpl
->m_xFactory
) ),
645 catch( embed::InvalidStorageException
& )
649 catch( lang::IllegalArgumentException
& )
653 catch( embed::StorageWrappedTargetException
& )
657 catch( io::IOException
& )
661 catch( uno::RuntimeException
& )
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
>(),
676 //-----------------------------------------------
677 uno::Reference
< io::XStream
> SAL_CALL
FSStorage::cloneStreamElement( const ::rtl::OUString
& aStreamName
)
678 throw ( embed::InvalidStorageException
,
679 lang::IllegalArgumentException
,
680 packages::WrongPasswordException
,
682 embed::StorageWrappedTargetException
,
683 uno::RuntimeException
)
685 ::osl::MutexGuard
aGuard( m_aMutex
);
688 throw lang::DisposedException();
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
& )
720 catch( lang::IllegalArgumentException
& )
724 catch( packages::WrongPasswordException
& )
728 catch( io::IOException
& )
732 catch( embed::StorageWrappedTargetException
& )
736 catch( uno::RuntimeException
& )
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
>(),
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
,
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
,
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
,
785 embed::StorageWrappedTargetException
,
786 uno::RuntimeException
)
788 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
808 throw lang::DisposedException();
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
);
829 throw lang::DisposedException();
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
,
846 embed::StorageWrappedTargetException
,
847 uno::RuntimeException
)
849 ::osl::MutexGuard
aGuard( m_aMutex
);
852 throw lang::DisposedException();
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
,
874 embed::StorageWrappedTargetException
,
875 uno::RuntimeException
)
877 ::osl::MutexGuard
aGuard( m_aMutex
);
880 throw lang::DisposedException();
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
,
907 ucb::NameClash::ERROR
) )
908 throw io::IOException(); // TODO: error handling
910 catch( embed::InvalidStorageException
& )
914 catch( lang::IllegalArgumentException
& )
918 catch( container::NoSuchElementException
& )
922 catch( container::ElementExistException
& )
926 catch( io::IOException
& )
930 catch( embed::StorageWrappedTargetException
& )
934 catch( uno::RuntimeException
& )
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
>(),
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
,
956 embed::StorageWrappedTargetException
,
957 uno::RuntimeException
)
959 ::osl::MutexGuard
aGuard( m_aMutex
);
962 throw lang::DisposedException();
965 throw uno::RuntimeException();
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
);
993 throw container::NoSuchElementException(); // TODO:
995 catch( embed::InvalidStorageException
& )
999 catch( lang::IllegalArgumentException
& )
1003 catch( container::NoSuchElementException
& )
1007 catch( container::ElementExistException
& )
1011 catch( embed::StorageWrappedTargetException
& )
1015 catch( io::IOException
& )
1019 catch( uno::RuntimeException
& )
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
>(),
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
,
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 //____________________________________________________________________________________________________
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
);
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
);
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
);
1089 throw container::NoSuchElementException(); // TODO:
1091 catch( container::NoSuchElementException
& )
1095 catch( lang::WrappedTargetException
& )
1099 catch( uno::RuntimeException
& )
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 ),
1116 //-----------------------------------------------
1117 uno::Sequence
< ::rtl::OUString
> SAL_CALL
FSStorage::getElementNames()
1118 throw ( uno::RuntimeException
)
1120 ::osl::MutexGuard
aGuard( m_aMutex
);
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" );
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 ),
1165 catch( uno::RuntimeException
& )
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 ),
1182 //-----------------------------------------------
1183 sal_Bool SAL_CALL
FSStorage::hasByName( const ::rtl::OUString
& aName
)
1184 throw ( uno::RuntimeException
)
1186 ::osl::MutexGuard
aGuard( m_aMutex
);
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
& )
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 ),
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
);
1226 throw lang::DisposedException();
1228 // it is a multitype container
1232 //-----------------------------------------------
1233 sal_Bool SAL_CALL
FSStorage::hasElements()
1234 throw ( uno::RuntimeException
)
1236 ::osl::MutexGuard
aGuard( m_aMutex
);
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 //____________________________________________________________________________________________________
1262 //____________________________________________________________________________________________________
1264 //-----------------------------------------------
1265 void SAL_CALL
FSStorage::dispose()
1266 throw ( uno::RuntimeException
)
1268 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
1283 //-----------------------------------------------
1284 void SAL_CALL
FSStorage::addEventListener(
1285 const uno::Reference
< lang::XEventListener
>& xListener
)
1286 throw ( uno::RuntimeException
)
1288 ::osl::MutexGuard
aGuard( m_aMutex
);
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
);
1307 throw lang::DisposedException();
1309 if ( m_pImpl
->m_pListenersContainer
)
1310 m_pImpl
->m_pListenersContainer
->removeInterface( xListener
);
1313 //____________________________________________________________________________________________________
1315 //____________________________________________________________________________________________________
1317 //-----------------------------------------------
1318 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
FSStorage::getPropertySetInfo()
1319 throw ( uno::RuntimeException
)
1321 ::osl::MutexGuard
aGuard( m_aMutex
);
1324 throw lang::DisposedException();
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
);
1342 throw lang::DisposedException();
1344 if ( aPropertyName
.equalsAscii( "URL" ) || aPropertyName
.equalsAscii( "OpenMode" ) )
1345 throw beans::PropertyVetoException(); // TODO
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
);
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
);
1382 throw lang::DisposedException();
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
);
1399 throw lang::DisposedException();
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
);
1416 throw lang::DisposedException();
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
);
1433 throw lang::DisposedException();
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
,
1447 embed::StorageWrappedTargetException
,
1448 uno::RuntimeException
)
1450 ::osl::MutexGuard
aGuard( m_aMutex
);
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
),
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
) );
1495 // TODO: test whether it really works for http and fwp
1496 SvStream
* pStream
= ::utl::UcbStreamHelper::CreateStream( aFileURL
.GetMainURL( INetURLObject::NO_DECODE
),
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
) );
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
);
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
& )
1535 catch( lang::IllegalArgumentException
& )
1539 catch( packages::WrongPasswordException
& )
1543 catch( embed::StorageWrappedTargetException
& )
1547 catch( io::IOException
& )
1551 catch( uno::RuntimeException
& )
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
>(),
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
,
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
,
1585 embed::StorageWrappedTargetException
,
1586 uno::RuntimeException
)
1588 ::osl::MutexGuard
aGuard( m_aMutex
);
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
),
1605 if ( !::utl::UCBContentHelper::IsDocument( aFileURL
.GetMainURL( INetURLObject::NO_DECODE
) ) )
1607 if ( ::utl::UCBContentHelper::IsFolder( aFileURL
.GetMainURL( INetURLObject::NO_DECODE
) ) )
1608 throw lang::IllegalArgumentException();
1610 throw container::NoSuchElementException(); // TODO:
1613 if ( !::utl::UCBContentHelper::Kill( aFileURL
.GetMainURL( INetURLObject::NO_DECODE
) ) )
1614 throw io::IOException(); // TODO: error handling