1*40df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*40df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*40df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*40df464eSAndrew Rist * distributed with this work for additional information
6*40df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*40df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*40df464eSAndrew Rist * "License"); you may not use this file except in compliance
9*40df464eSAndrew Rist * with the License. You may obtain a copy of the License at
10*40df464eSAndrew Rist *
11*40df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*40df464eSAndrew Rist *
13*40df464eSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*40df464eSAndrew Rist * software distributed under the License is distributed on an
15*40df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*40df464eSAndrew Rist * KIND, either express or implied. See the License for the
17*40df464eSAndrew Rist * specific language governing permissions and limitations
18*40df464eSAndrew Rist * under the License.
19*40df464eSAndrew Rist *
20*40df464eSAndrew Rist *************************************************************/
21*40df464eSAndrew Rist
22*40df464eSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
27cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
28cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
29cdf0e10cSrcweir #include <com/sun/star/ucb/XProgressHandler.hpp>
30cdf0e10cSrcweir #include <com/sun/star/ucb/XContentAccess.hpp>
31cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UCB_INTERACTIVEIODEXCEPTION_HPP_
34cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveIOException.hpp>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include <com/sun/star/ucb/IOErrorCode.hpp>
37cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
38cdf0e10cSrcweir #include <com/sun/star/container/XEnumerationAccess.hpp>
39cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
40cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp>
41cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
42cdf0e10cSrcweir #include <com/sun/star/lang/XUnoTunnel.hpp>
43cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
44cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
45cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
46cdf0e10cSrcweir #include <com/sun/star/io/IOException.hpp>
47cdf0e10cSrcweir #include <com/sun/star/io/XTruncate.hpp>
48cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
49cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
50cdf0e10cSrcweir
51cdf0e10cSrcweir
52cdf0e10cSrcweir #ifndef _COMPHELPER_PROCESSFACTORY_HXX
53cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
54cdf0e10cSrcweir #endif
55cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
56cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
57cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
58cdf0e10cSrcweir
59cdf0e10cSrcweir #include <tools/urlobj.hxx>
60cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
61cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
62cdf0e10cSrcweir #include <unotools/streamwrap.hxx>
63cdf0e10cSrcweir #include <ucbhelper/fileidentifierconverter.hxx>
64cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
65cdf0e10cSrcweir #include <ucbhelper/content.hxx>
66cdf0e10cSrcweir
67cdf0e10cSrcweir #include "fsstorage.hxx"
68cdf0e10cSrcweir #include "oinputstreamcontainer.hxx"
69cdf0e10cSrcweir #include "ostreamcontainer.hxx"
70cdf0e10cSrcweir
71cdf0e10cSrcweir using namespace ::com::sun::star;
72cdf0e10cSrcweir
73cdf0e10cSrcweir //=========================================================
74cdf0e10cSrcweir
75cdf0e10cSrcweir // TODO: move to a standard helper
isLocalFile_Impl(::rtl::OUString aURL)76cdf0e10cSrcweir sal_Bool isLocalFile_Impl( ::rtl::OUString aURL )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir ::rtl::OUString aSystemPath;
79cdf0e10cSrcweir ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
80cdf0e10cSrcweir if ( !pBroker )
81cdf0e10cSrcweir throw uno::RuntimeException();
82cdf0e10cSrcweir
83cdf0e10cSrcweir uno::Reference< ucb::XContentProviderManager > xManager =
84cdf0e10cSrcweir pBroker->getContentProviderManagerInterface();
85cdf0e10cSrcweir try
86cdf0e10cSrcweir {
87cdf0e10cSrcweir aSystemPath = ::ucbhelper::getSystemPathFromFileURL( xManager, aURL );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir catch ( uno::Exception& )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
93cdf0e10cSrcweir return ( aSystemPath.getLength() != 0 );
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir
97cdf0e10cSrcweir //=========================================================
98cdf0e10cSrcweir
99cdf0e10cSrcweir struct FSStorage_Impl
100cdf0e10cSrcweir {
101cdf0e10cSrcweir ::rtl::OUString m_aURL;
102cdf0e10cSrcweir
103cdf0e10cSrcweir ::ucbhelper::Content* m_pContent;
104cdf0e10cSrcweir sal_Int32 m_nMode;
105cdf0e10cSrcweir
106cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners
107cdf0e10cSrcweir ::cppu::OTypeCollection* m_pTypeCollection;
108cdf0e10cSrcweir
109cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > m_xFactory;
110cdf0e10cSrcweir
111cdf0e10cSrcweir
FSStorage_ImplFSStorage_Impl112cdf0e10cSrcweir FSStorage_Impl( const ::rtl::OUString& aURL, sal_Int32 nMode, uno::Reference< lang::XMultiServiceFactory > xFactory )
113cdf0e10cSrcweir : m_aURL( aURL )
114cdf0e10cSrcweir , m_pContent( NULL )
115cdf0e10cSrcweir , m_nMode( nMode )
116cdf0e10cSrcweir , m_pListenersContainer( NULL )
117cdf0e10cSrcweir , m_pTypeCollection( NULL )
118cdf0e10cSrcweir , m_xFactory( xFactory )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir OSL_ENSURE( m_aURL.getLength(), "The URL must not be empty" );
121cdf0e10cSrcweir }
122cdf0e10cSrcweir
FSStorage_ImplFSStorage_Impl123cdf0e10cSrcweir FSStorage_Impl( const ::ucbhelper::Content& aContent, sal_Int32 nMode, uno::Reference< lang::XMultiServiceFactory > xFactory )
124cdf0e10cSrcweir : m_aURL( aContent.getURL() )
125cdf0e10cSrcweir , m_pContent( new ::ucbhelper::Content( aContent ) )
126cdf0e10cSrcweir , m_nMode( nMode )
127cdf0e10cSrcweir , m_pListenersContainer( NULL )
128cdf0e10cSrcweir , m_pTypeCollection( NULL )
129cdf0e10cSrcweir , m_xFactory( xFactory )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir OSL_ENSURE( m_aURL.getLength(), "The URL must not be empty" );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir ~FSStorage_Impl();
135cdf0e10cSrcweir };
136cdf0e10cSrcweir
137cdf0e10cSrcweir //=========================================================
138cdf0e10cSrcweir
~FSStorage_Impl()139cdf0e10cSrcweir FSStorage_Impl::~FSStorage_Impl()
140cdf0e10cSrcweir {
141cdf0e10cSrcweir if ( m_pListenersContainer )
142cdf0e10cSrcweir delete m_pListenersContainer;
143cdf0e10cSrcweir if ( m_pTypeCollection )
144cdf0e10cSrcweir delete m_pTypeCollection;
145cdf0e10cSrcweir if ( m_pContent )
146cdf0e10cSrcweir delete m_pContent;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir //=====================================================
150cdf0e10cSrcweir // FSStorage implementation
151cdf0e10cSrcweir //=====================================================
152cdf0e10cSrcweir
153cdf0e10cSrcweir //-----------------------------------------------
FSStorage(const::ucbhelper::Content & aContent,sal_Int32 nMode,uno::Sequence<beans::PropertyValue>,uno::Reference<lang::XMultiServiceFactory> xFactory)154cdf0e10cSrcweir FSStorage::FSStorage( const ::ucbhelper::Content& aContent,
155cdf0e10cSrcweir sal_Int32 nMode,
156cdf0e10cSrcweir uno::Sequence< beans::PropertyValue >,
157cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory )
158cdf0e10cSrcweir : m_pImpl( new FSStorage_Impl( aContent, nMode, xFactory ) )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir // TODO: use properties
161cdf0e10cSrcweir if ( !xFactory.is() )
162cdf0e10cSrcweir throw uno::RuntimeException();
163cdf0e10cSrcweir
164cdf0e10cSrcweir GetContent();
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir //-----------------------------------------------
~FSStorage()168cdf0e10cSrcweir FSStorage::~FSStorage()
169cdf0e10cSrcweir {
170cdf0e10cSrcweir {
171cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
172cdf0e10cSrcweir m_refCount++; // to call dispose
173cdf0e10cSrcweir try {
174cdf0e10cSrcweir dispose();
175cdf0e10cSrcweir }
176cdf0e10cSrcweir catch( uno::RuntimeException& )
177cdf0e10cSrcweir {}
178cdf0e10cSrcweir }
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
181cdf0e10cSrcweir //-----------------------------------------------
MakeFolderNoUI(const String & rFolder,sal_Bool)182cdf0e10cSrcweir sal_Bool FSStorage::MakeFolderNoUI( const String& rFolder, sal_Bool )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir INetURLObject aURL( rFolder );
185cdf0e10cSrcweir ::rtl::OUString aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
186cdf0e10cSrcweir aURL.removeSegment();
187cdf0e10cSrcweir ::ucbhelper::Content aParent;
188cdf0e10cSrcweir ::ucbhelper::Content aResultContent;
189cdf0e10cSrcweir
190cdf0e10cSrcweir if ( ::ucbhelper::Content::create( aURL.GetMainURL( INetURLObject::NO_DECODE ),
191cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment >(),
192cdf0e10cSrcweir aParent ) )
193cdf0e10cSrcweir return ::utl::UCBContentHelper::MakeFolder( aParent, aTitle, aResultContent, sal_False );
194cdf0e10cSrcweir
195cdf0e10cSrcweir return sal_False;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir
198cdf0e10cSrcweir //-----------------------------------------------
GetContent()199cdf0e10cSrcweir ::ucbhelper::Content* FSStorage::GetContent()
200cdf0e10cSrcweir {
201cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
202cdf0e10cSrcweir if ( !m_pImpl->m_pContent )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
205cdf0e10cSrcweir
206cdf0e10cSrcweir try
207cdf0e10cSrcweir {
208cdf0e10cSrcweir m_pImpl->m_pContent = new ::ucbhelper::Content( m_pImpl->m_aURL, xDummyEnv );
209cdf0e10cSrcweir }
210cdf0e10cSrcweir catch( uno::Exception& )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir }
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir return m_pImpl->m_pContent;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir //-----------------------------------------------
CopyStreamToSubStream(const::rtl::OUString & aSourceURL,const uno::Reference<embed::XStorage> & xDest,const::rtl::OUString & aNewEntryName)219cdf0e10cSrcweir void FSStorage::CopyStreamToSubStream( const ::rtl::OUString& aSourceURL,
220cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xDest,
221cdf0e10cSrcweir const ::rtl::OUString& aNewEntryName )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir if ( !xDest.is() )
224cdf0e10cSrcweir throw uno::RuntimeException();
225cdf0e10cSrcweir
226cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
227cdf0e10cSrcweir ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv );
228cdf0e10cSrcweir uno::Reference< io::XInputStream > xSourceInput = aSourceContent.openStream();
229cdf0e10cSrcweir
230cdf0e10cSrcweir if ( !xSourceInput.is() )
231cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
232cdf0e10cSrcweir
233cdf0e10cSrcweir uno::Reference< io::XStream > xSubStream = xDest->openStreamElement(
234cdf0e10cSrcweir aNewEntryName,
235cdf0e10cSrcweir embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
236cdf0e10cSrcweir if ( !xSubStream.is() )
237cdf0e10cSrcweir throw uno::RuntimeException();
238cdf0e10cSrcweir
239cdf0e10cSrcweir uno::Reference< io::XOutputStream > xDestOutput = xSubStream->getOutputStream();
240cdf0e10cSrcweir if ( !xDestOutput.is() )
241cdf0e10cSrcweir throw uno::RuntimeException();
242cdf0e10cSrcweir
243cdf0e10cSrcweir ::comphelper::OStorageHelper::CopyInputToOutput( xSourceInput, xDestOutput );
244cdf0e10cSrcweir xDestOutput->closeOutput();
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
247cdf0e10cSrcweir //-----------------------------------------------
CopyContentToStorage_Impl(::ucbhelper::Content * pContent,const uno::Reference<embed::XStorage> & xDest)248cdf0e10cSrcweir void FSStorage::CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, const uno::Reference< embed::XStorage >& xDest )
249cdf0e10cSrcweir {
250cdf0e10cSrcweir if ( !pContent )
251cdf0e10cSrcweir throw uno::RuntimeException();
252cdf0e10cSrcweir
253cdf0e10cSrcweir // get list of contents of the Content
254cdf0e10cSrcweir // create cursor for access to children
255cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aProps( 2 );
256cdf0e10cSrcweir ::rtl::OUString* pProps = aProps.getArray();
257cdf0e10cSrcweir pProps[0] = ::rtl::OUString::createFromAscii( "TargetURL" );
258cdf0e10cSrcweir pProps[1] = ::rtl::OUString::createFromAscii( "IsFolder" );
259cdf0e10cSrcweir ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
260cdf0e10cSrcweir
261cdf0e10cSrcweir try
262cdf0e10cSrcweir {
263cdf0e10cSrcweir uno::Reference< sdbc::XResultSet > xResultSet = pContent->createCursor( aProps, eInclude );
264cdf0e10cSrcweir uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
265cdf0e10cSrcweir uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
266cdf0e10cSrcweir if ( xResultSet.is() )
267cdf0e10cSrcweir {
268cdf0e10cSrcweir // go through the list: insert files as streams, insert folders as substorages using recursion
269cdf0e10cSrcweir while ( xResultSet->next() )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir ::rtl::OUString aSourceURL( xRow->getString( 1 ) );
272cdf0e10cSrcweir sal_Bool bIsFolder( xRow->getBoolean(2) );
273cdf0e10cSrcweir
274cdf0e10cSrcweir // TODO/LATER: not sure whether the entry name must be encoded
275cdf0e10cSrcweir ::rtl::OUString aNewEntryName( INetURLObject( aSourceURL ).getName( INetURLObject::LAST_SEGMENT,
276cdf0e10cSrcweir true,
277cdf0e10cSrcweir INetURLObject::NO_DECODE ) );
278cdf0e10cSrcweir if ( bIsFolder )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir uno::Reference< embed::XStorage > xSubStorage = xDest->openStorageElement( aNewEntryName,
281cdf0e10cSrcweir embed::ElementModes::READWRITE );
282cdf0e10cSrcweir if ( !xSubStorage.is() )
283cdf0e10cSrcweir throw uno::RuntimeException();
284cdf0e10cSrcweir
285cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
286cdf0e10cSrcweir ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv );
287cdf0e10cSrcweir CopyContentToStorage_Impl( &aSourceContent, xSubStorage );
288cdf0e10cSrcweir }
289cdf0e10cSrcweir else
290cdf0e10cSrcweir {
291cdf0e10cSrcweir CopyStreamToSubStream( aSourceURL, xDest, aNewEntryName );
292cdf0e10cSrcweir }
293cdf0e10cSrcweir }
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransact( xDest, uno::UNO_QUERY );
297cdf0e10cSrcweir if ( xTransact.is() )
298cdf0e10cSrcweir xTransact->commit();
299cdf0e10cSrcweir }
300cdf0e10cSrcweir catch( ucb::InteractiveIOException& r )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir if ( r.Code == ucb::IOErrorCode_NOT_EXISTING )
303cdf0e10cSrcweir OSL_ENSURE( sal_False, "The folder does not exist!\n" );
304cdf0e10cSrcweir else
305cdf0e10cSrcweir throw;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir }
308cdf0e10cSrcweir
309cdf0e10cSrcweir //____________________________________________________________________________________________________
310cdf0e10cSrcweir // XInterface
311cdf0e10cSrcweir //____________________________________________________________________________________________________
312cdf0e10cSrcweir
313cdf0e10cSrcweir //-----------------------------------------------
queryInterface(const uno::Type & rType)314cdf0e10cSrcweir uno::Any SAL_CALL FSStorage::queryInterface( const uno::Type& rType )
315cdf0e10cSrcweir throw( uno::RuntimeException )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir uno::Any aReturn;
318cdf0e10cSrcweir aReturn <<= ::cppu::queryInterface
319cdf0e10cSrcweir ( rType
320cdf0e10cSrcweir , static_cast<lang::XTypeProvider*> ( this )
321cdf0e10cSrcweir , static_cast<embed::XStorage*> ( this )
322cdf0e10cSrcweir , static_cast<embed::XHierarchicalStorageAccess*> ( this )
323cdf0e10cSrcweir , static_cast<container::XNameAccess*> ( this )
324cdf0e10cSrcweir , static_cast<container::XElementAccess*> ( this )
325cdf0e10cSrcweir , static_cast<lang::XComponent*> ( this )
326cdf0e10cSrcweir , static_cast<beans::XPropertySet*> ( this ) );
327cdf0e10cSrcweir
328cdf0e10cSrcweir if ( aReturn.hasValue() == sal_True )
329cdf0e10cSrcweir return aReturn ;
330cdf0e10cSrcweir
331cdf0e10cSrcweir return OWeakObject::queryInterface( rType );
332cdf0e10cSrcweir }
333cdf0e10cSrcweir
334cdf0e10cSrcweir //-----------------------------------------------
acquire()335cdf0e10cSrcweir void SAL_CALL FSStorage::acquire() throw()
336cdf0e10cSrcweir {
337cdf0e10cSrcweir OWeakObject::acquire();
338cdf0e10cSrcweir }
339cdf0e10cSrcweir
340cdf0e10cSrcweir //-----------------------------------------------
release()341cdf0e10cSrcweir void SAL_CALL FSStorage::release() throw()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir OWeakObject::release();
344cdf0e10cSrcweir }
345cdf0e10cSrcweir
346cdf0e10cSrcweir //____________________________________________________________________________________________________
347cdf0e10cSrcweir // XTypeProvider
348cdf0e10cSrcweir //____________________________________________________________________________________________________
349cdf0e10cSrcweir
350cdf0e10cSrcweir //-----------------------------------------------
getTypes()351cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL FSStorage::getTypes()
352cdf0e10cSrcweir throw( uno::RuntimeException )
353cdf0e10cSrcweir {
354cdf0e10cSrcweir if ( m_pImpl->m_pTypeCollection == NULL )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
357cdf0e10cSrcweir
358cdf0e10cSrcweir if ( m_pImpl->m_pTypeCollection == NULL )
359cdf0e10cSrcweir {
360cdf0e10cSrcweir m_pImpl->m_pTypeCollection = new ::cppu::OTypeCollection
361cdf0e10cSrcweir ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL )
362cdf0e10cSrcweir , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL )
363cdf0e10cSrcweir , ::getCppuType( ( const uno::Reference< embed::XHierarchicalStorageAccess >* )NULL )
364cdf0e10cSrcweir , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) );
365cdf0e10cSrcweir }
366cdf0e10cSrcweir }
367cdf0e10cSrcweir
368cdf0e10cSrcweir return m_pImpl->m_pTypeCollection->getTypes() ;
369cdf0e10cSrcweir }
370cdf0e10cSrcweir
371cdf0e10cSrcweir //-----------------------------------------------
getImplementationId()372cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL FSStorage::getImplementationId()
373cdf0e10cSrcweir throw( uno::RuntimeException )
374cdf0e10cSrcweir {
375cdf0e10cSrcweir static ::cppu::OImplementationId* pID = NULL ;
376cdf0e10cSrcweir
377cdf0e10cSrcweir if ( pID == NULL )
378cdf0e10cSrcweir {
379cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;
380cdf0e10cSrcweir
381cdf0e10cSrcweir if ( pID == NULL )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir static ::cppu::OImplementationId aID( sal_False ) ;
384cdf0e10cSrcweir pID = &aID ;
385cdf0e10cSrcweir }
386cdf0e10cSrcweir }
387cdf0e10cSrcweir
388cdf0e10cSrcweir return pID->getImplementationId() ;
389cdf0e10cSrcweir
390cdf0e10cSrcweir }
391cdf0e10cSrcweir
392cdf0e10cSrcweir //____________________________________________________________________________________________________
393cdf0e10cSrcweir // XStorage
394cdf0e10cSrcweir //____________________________________________________________________________________________________
395cdf0e10cSrcweir
396cdf0e10cSrcweir //-----------------------------------------------
copyToStorage(const uno::Reference<embed::XStorage> & xDest)397cdf0e10cSrcweir void SAL_CALL FSStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest )
398cdf0e10cSrcweir throw ( embed::InvalidStorageException,
399cdf0e10cSrcweir io::IOException,
400cdf0e10cSrcweir lang::IllegalArgumentException,
401cdf0e10cSrcweir embed::StorageWrappedTargetException,
402cdf0e10cSrcweir uno::RuntimeException )
403cdf0e10cSrcweir {
404cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
405cdf0e10cSrcweir
406cdf0e10cSrcweir if ( !m_pImpl )
407cdf0e10cSrcweir throw lang::DisposedException();
408cdf0e10cSrcweir
409cdf0e10cSrcweir if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) )
410cdf0e10cSrcweir throw lang::IllegalArgumentException(); // TODO:
411cdf0e10cSrcweir
412cdf0e10cSrcweir if ( !GetContent() )
413cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
414cdf0e10cSrcweir
415cdf0e10cSrcweir try
416cdf0e10cSrcweir {
417cdf0e10cSrcweir CopyContentToStorage_Impl( GetContent(), xDest );
418cdf0e10cSrcweir }
419cdf0e10cSrcweir catch( embed::InvalidStorageException& )
420cdf0e10cSrcweir {
421cdf0e10cSrcweir throw;
422cdf0e10cSrcweir }
423cdf0e10cSrcweir catch( lang::IllegalArgumentException& )
424cdf0e10cSrcweir {
425cdf0e10cSrcweir throw;
426cdf0e10cSrcweir }
427cdf0e10cSrcweir catch( embed::StorageWrappedTargetException& )
428cdf0e10cSrcweir {
429cdf0e10cSrcweir throw;
430cdf0e10cSrcweir }
431cdf0e10cSrcweir catch( io::IOException& )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir throw;
434cdf0e10cSrcweir }
435cdf0e10cSrcweir catch( uno::RuntimeException& )
436cdf0e10cSrcweir {
437cdf0e10cSrcweir throw;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir catch( uno::Exception& )
440cdf0e10cSrcweir {
441cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
442cdf0e10cSrcweir throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
443cdf0e10cSrcweir uno::Reference< io::XInputStream >(),
444cdf0e10cSrcweir aCaught );
445cdf0e10cSrcweir }
446cdf0e10cSrcweir }
447cdf0e10cSrcweir
448cdf0e10cSrcweir //-----------------------------------------------
openStreamElement(const::rtl::OUString & aStreamName,sal_Int32 nOpenMode)449cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL FSStorage::openStreamElement(
450cdf0e10cSrcweir const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode )
451cdf0e10cSrcweir throw ( embed::InvalidStorageException,
452cdf0e10cSrcweir lang::IllegalArgumentException,
453cdf0e10cSrcweir packages::WrongPasswordException,
454cdf0e10cSrcweir io::IOException,
455cdf0e10cSrcweir embed::StorageWrappedTargetException,
456cdf0e10cSrcweir uno::RuntimeException )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
459cdf0e10cSrcweir
460cdf0e10cSrcweir if ( !m_pImpl )
461cdf0e10cSrcweir throw lang::DisposedException();
462cdf0e10cSrcweir
463cdf0e10cSrcweir if ( !GetContent() )
464cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
465cdf0e10cSrcweir
466cdf0e10cSrcweir // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
467cdf0e10cSrcweir INetURLObject aFileURL( m_pImpl->m_aURL );
468cdf0e10cSrcweir aFileURL.Append( aStreamName );
469cdf0e10cSrcweir
470cdf0e10cSrcweir if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
471cdf0e10cSrcweir throw io::IOException();
472cdf0e10cSrcweir
473cdf0e10cSrcweir if ( ( nOpenMode & embed::ElementModes::NOCREATE )
474cdf0e10cSrcweir && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
475cdf0e10cSrcweir throw io::IOException(); // TODO:
476cdf0e10cSrcweir
477cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
478cdf0e10cSrcweir uno::Reference< io::XStream > xResult;
479cdf0e10cSrcweir try
480cdf0e10cSrcweir {
481cdf0e10cSrcweir if ( nOpenMode & embed::ElementModes::WRITE )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess(
486cdf0e10cSrcweir m_pImpl->m_xFactory->createInstance(
487cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ),
488cdf0e10cSrcweir uno::UNO_QUERY_THROW );
489cdf0e10cSrcweir xResult = xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) );
490cdf0e10cSrcweir }
491cdf0e10cSrcweir else
492cdf0e10cSrcweir {
493cdf0e10cSrcweir // TODO: test whether it really works for http and fwp
494cdf0e10cSrcweir SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ),
495cdf0e10cSrcweir STREAM_STD_WRITE );
496cdf0e10cSrcweir if ( pStream )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir if ( !pStream->GetError() )
499cdf0e10cSrcweir xResult = uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) );
500cdf0e10cSrcweir else
501cdf0e10cSrcweir delete pStream;
502cdf0e10cSrcweir }
503cdf0e10cSrcweir }
504cdf0e10cSrcweir
505cdf0e10cSrcweir if ( !xResult.is() )
506cdf0e10cSrcweir throw io::IOException();
507cdf0e10cSrcweir
508cdf0e10cSrcweir if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) )
509cdf0e10cSrcweir {
510cdf0e10cSrcweir uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW );
511cdf0e10cSrcweir xTrunc->truncate();
512cdf0e10cSrcweir }
513cdf0e10cSrcweir }
514cdf0e10cSrcweir else
515cdf0e10cSrcweir {
516cdf0e10cSrcweir if ( ( nOpenMode & embed::ElementModes::TRUNCATE )
517cdf0e10cSrcweir || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
518cdf0e10cSrcweir throw io::IOException(); // TODO: access denied
519cdf0e10cSrcweir
520cdf0e10cSrcweir ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
521cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
522cdf0e10cSrcweir xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) );
523cdf0e10cSrcweir }
524cdf0e10cSrcweir }
525cdf0e10cSrcweir catch( embed::InvalidStorageException& )
526cdf0e10cSrcweir {
527cdf0e10cSrcweir throw;
528cdf0e10cSrcweir }
529cdf0e10cSrcweir catch( lang::IllegalArgumentException& )
530cdf0e10cSrcweir {
531cdf0e10cSrcweir throw;
532cdf0e10cSrcweir }
533cdf0e10cSrcweir catch( packages::WrongPasswordException& )
534cdf0e10cSrcweir {
535cdf0e10cSrcweir throw;
536cdf0e10cSrcweir }
537cdf0e10cSrcweir catch( embed::StorageWrappedTargetException& )
538cdf0e10cSrcweir {
539cdf0e10cSrcweir throw;
540cdf0e10cSrcweir }
541cdf0e10cSrcweir catch( io::IOException& )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir throw;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir catch( uno::RuntimeException& )
546cdf0e10cSrcweir {
547cdf0e10cSrcweir throw;
548cdf0e10cSrcweir }
549cdf0e10cSrcweir catch( uno::Exception& )
550cdf0e10cSrcweir {
551cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
552cdf0e10cSrcweir throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
553cdf0e10cSrcweir uno::Reference< io::XInputStream >(),
554cdf0e10cSrcweir aCaught );
555cdf0e10cSrcweir }
556cdf0e10cSrcweir
557cdf0e10cSrcweir return xResult;
558cdf0e10cSrcweir }
559cdf0e10cSrcweir
560cdf0e10cSrcweir //-----------------------------------------------
openEncryptedStreamElement(const::rtl::OUString &,sal_Int32,const::rtl::OUString &)561cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL FSStorage::openEncryptedStreamElement(
562cdf0e10cSrcweir const ::rtl::OUString&, sal_Int32, const ::rtl::OUString& )
563cdf0e10cSrcweir throw ( embed::InvalidStorageException,
564cdf0e10cSrcweir lang::IllegalArgumentException,
565cdf0e10cSrcweir packages::NoEncryptionException,
566cdf0e10cSrcweir packages::WrongPasswordException,
567cdf0e10cSrcweir io::IOException,
568cdf0e10cSrcweir embed::StorageWrappedTargetException,
569cdf0e10cSrcweir uno::RuntimeException )
570cdf0e10cSrcweir {
571cdf0e10cSrcweir throw packages::NoEncryptionException();
572cdf0e10cSrcweir }
573cdf0e10cSrcweir
574cdf0e10cSrcweir //-----------------------------------------------
openStorageElement(const::rtl::OUString & aStorName,sal_Int32 nStorageMode)575cdf0e10cSrcweir uno::Reference< embed::XStorage > SAL_CALL FSStorage::openStorageElement(
576cdf0e10cSrcweir const ::rtl::OUString& aStorName, sal_Int32 nStorageMode )
577cdf0e10cSrcweir throw ( embed::InvalidStorageException,
578cdf0e10cSrcweir lang::IllegalArgumentException,
579cdf0e10cSrcweir io::IOException,
580cdf0e10cSrcweir embed::StorageWrappedTargetException,
581cdf0e10cSrcweir uno::RuntimeException )
582cdf0e10cSrcweir {
583cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
584cdf0e10cSrcweir
585cdf0e10cSrcweir if ( !m_pImpl )
586cdf0e10cSrcweir throw lang::DisposedException();
587cdf0e10cSrcweir
588cdf0e10cSrcweir if ( !GetContent() )
589cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
590cdf0e10cSrcweir
591cdf0e10cSrcweir if ( ( nStorageMode & embed::ElementModes::WRITE )
592cdf0e10cSrcweir && !( m_pImpl->m_nMode & embed::ElementModes::WRITE ) )
593cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
594cdf0e10cSrcweir
595cdf0e10cSrcweir // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
596cdf0e10cSrcweir INetURLObject aFolderURL( m_pImpl->m_aURL );
597cdf0e10cSrcweir aFolderURL.Append( aStorName );
598cdf0e10cSrcweir
599cdf0e10cSrcweir sal_Bool bFolderExists = ::utl::UCBContentHelper::IsFolder( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) );
600cdf0e10cSrcweir if ( !bFolderExists && ::utl::UCBContentHelper::IsDocument( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
601cdf0e10cSrcweir throw io::IOException(); // TODO:
602cdf0e10cSrcweir
603cdf0e10cSrcweir if ( ( nStorageMode & embed::ElementModes::NOCREATE ) && !bFolderExists )
604cdf0e10cSrcweir throw io::IOException(); // TODO:
605cdf0e10cSrcweir
606cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
607cdf0e10cSrcweir uno::Reference< embed::XStorage > xResult;
608cdf0e10cSrcweir try
609cdf0e10cSrcweir {
610cdf0e10cSrcweir if ( nStorageMode & embed::ElementModes::WRITE )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) && bFolderExists )
613cdf0e10cSrcweir {
614cdf0e10cSrcweir ::utl::UCBContentHelper::Kill( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) );
615cdf0e10cSrcweir bFolderExists =
616cdf0e10cSrcweir MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), sal_True ); // TODO: not atomar :(
617cdf0e10cSrcweir }
618cdf0e10cSrcweir else if ( !bFolderExists )
619cdf0e10cSrcweir {
620cdf0e10cSrcweir bFolderExists =
621cdf0e10cSrcweir MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), sal_True ); // TODO: not atomar :(
622cdf0e10cSrcweir }
623cdf0e10cSrcweir }
624cdf0e10cSrcweir else if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) )
625cdf0e10cSrcweir throw io::IOException(); // TODO: access denied
626cdf0e10cSrcweir
627cdf0e10cSrcweir if ( !bFolderExists )
628cdf0e10cSrcweir throw io::IOException(); // there is no such folder
629cdf0e10cSrcweir
630cdf0e10cSrcweir ::ucbhelper::Content aResultContent( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
631cdf0e10cSrcweir xResult = uno::Reference< embed::XStorage >(
632cdf0e10cSrcweir static_cast< OWeakObject* >( new FSStorage( aResultContent,
633cdf0e10cSrcweir nStorageMode,
634cdf0e10cSrcweir uno::Sequence< beans::PropertyValue >(),
635cdf0e10cSrcweir m_pImpl->m_xFactory ) ),
636cdf0e10cSrcweir uno::UNO_QUERY );
637cdf0e10cSrcweir }
638cdf0e10cSrcweir catch( embed::InvalidStorageException& )
639cdf0e10cSrcweir {
640cdf0e10cSrcweir throw;
641cdf0e10cSrcweir }
642cdf0e10cSrcweir catch( lang::IllegalArgumentException& )
643cdf0e10cSrcweir {
644cdf0e10cSrcweir throw;
645cdf0e10cSrcweir }
646cdf0e10cSrcweir catch( embed::StorageWrappedTargetException& )
647cdf0e10cSrcweir {
648cdf0e10cSrcweir throw;
649cdf0e10cSrcweir }
650cdf0e10cSrcweir catch( io::IOException& )
651cdf0e10cSrcweir {
652cdf0e10cSrcweir throw;
653cdf0e10cSrcweir }
654cdf0e10cSrcweir catch( uno::RuntimeException& )
655cdf0e10cSrcweir {
656cdf0e10cSrcweir throw;
657cdf0e10cSrcweir }
658cdf0e10cSrcweir catch( uno::Exception& )
659cdf0e10cSrcweir {
660cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
661cdf0e10cSrcweir throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
662cdf0e10cSrcweir uno::Reference< io::XInputStream >(),
663cdf0e10cSrcweir aCaught );
664cdf0e10cSrcweir }
665cdf0e10cSrcweir
666cdf0e10cSrcweir return xResult;
667cdf0e10cSrcweir }
668cdf0e10cSrcweir
669cdf0e10cSrcweir //-----------------------------------------------
cloneStreamElement(const::rtl::OUString & aStreamName)670cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL FSStorage::cloneStreamElement( const ::rtl::OUString& aStreamName )
671cdf0e10cSrcweir throw ( embed::InvalidStorageException,
672cdf0e10cSrcweir lang::IllegalArgumentException,
673cdf0e10cSrcweir packages::WrongPasswordException,
674cdf0e10cSrcweir io::IOException,
675cdf0e10cSrcweir embed::StorageWrappedTargetException,
676cdf0e10cSrcweir uno::RuntimeException )
677cdf0e10cSrcweir {
678cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
679cdf0e10cSrcweir
680cdf0e10cSrcweir if ( !m_pImpl )
681cdf0e10cSrcweir throw lang::DisposedException();
682cdf0e10cSrcweir
683cdf0e10cSrcweir if ( !GetContent() )
684cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
685cdf0e10cSrcweir
686cdf0e10cSrcweir // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
687cdf0e10cSrcweir INetURLObject aFileURL( m_pImpl->m_aURL );
688cdf0e10cSrcweir aFileURL.Append( aStreamName );
689cdf0e10cSrcweir
690cdf0e10cSrcweir uno::Reference < io::XStream > xTempResult;
691cdf0e10cSrcweir try
692cdf0e10cSrcweir {
693cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
694cdf0e10cSrcweir ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
695cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
696cdf0e10cSrcweir
697cdf0e10cSrcweir xTempResult = uno::Reference < io::XStream >(
698cdf0e10cSrcweir m_pImpl->m_xFactory->createInstance ( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ),
699cdf0e10cSrcweir uno::UNO_QUERY_THROW );
700cdf0e10cSrcweir uno::Reference < io::XOutputStream > xTempOut = xTempResult->getOutputStream();
701cdf0e10cSrcweir uno::Reference < io::XInputStream > xTempIn = xTempResult->getInputStream();
702cdf0e10cSrcweir
703cdf0e10cSrcweir if ( !xTempOut.is() || !xTempIn.is() )
704cdf0e10cSrcweir throw io::IOException();
705cdf0e10cSrcweir
706cdf0e10cSrcweir ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut );
707cdf0e10cSrcweir xTempOut->closeOutput();
708cdf0e10cSrcweir }
709cdf0e10cSrcweir catch( embed::InvalidStorageException& )
710cdf0e10cSrcweir {
711cdf0e10cSrcweir throw;
712cdf0e10cSrcweir }
713cdf0e10cSrcweir catch( lang::IllegalArgumentException& )
714cdf0e10cSrcweir {
715cdf0e10cSrcweir throw;
716cdf0e10cSrcweir }
717cdf0e10cSrcweir catch( packages::WrongPasswordException& )
718cdf0e10cSrcweir {
719cdf0e10cSrcweir throw;
720cdf0e10cSrcweir }
721cdf0e10cSrcweir catch( io::IOException& )
722cdf0e10cSrcweir {
723cdf0e10cSrcweir throw;
724cdf0e10cSrcweir }
725cdf0e10cSrcweir catch( embed::StorageWrappedTargetException& )
726cdf0e10cSrcweir {
727cdf0e10cSrcweir throw;
728cdf0e10cSrcweir }
729cdf0e10cSrcweir catch( uno::RuntimeException& )
730cdf0e10cSrcweir {
731cdf0e10cSrcweir throw;
732cdf0e10cSrcweir }
733cdf0e10cSrcweir catch( uno::Exception& )
734cdf0e10cSrcweir {
735cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
736cdf0e10cSrcweir throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
737cdf0e10cSrcweir uno::Reference< io::XInputStream >(),
738cdf0e10cSrcweir aCaught );
739cdf0e10cSrcweir }
740cdf0e10cSrcweir
741cdf0e10cSrcweir return xTempResult;
742cdf0e10cSrcweir }
743cdf0e10cSrcweir
744cdf0e10cSrcweir //-----------------------------------------------
cloneEncryptedStreamElement(const::rtl::OUString &,const::rtl::OUString &)745cdf0e10cSrcweir uno::Reference< io::XStream > SAL_CALL FSStorage::cloneEncryptedStreamElement(
746cdf0e10cSrcweir const ::rtl::OUString&,
747cdf0e10cSrcweir const ::rtl::OUString& )
748cdf0e10cSrcweir throw ( embed::InvalidStorageException,
749cdf0e10cSrcweir lang::IllegalArgumentException,
750cdf0e10cSrcweir packages::NoEncryptionException,
751cdf0e10cSrcweir packages::WrongPasswordException,
752cdf0e10cSrcweir io::IOException,
753cdf0e10cSrcweir embed::StorageWrappedTargetException,
754cdf0e10cSrcweir uno::RuntimeException )
755cdf0e10cSrcweir {
756cdf0e10cSrcweir throw packages::NoEncryptionException();
757cdf0e10cSrcweir }
758cdf0e10cSrcweir
759cdf0e10cSrcweir //-----------------------------------------------
copyLastCommitTo(const uno::Reference<embed::XStorage> & xTargetStorage)760cdf0e10cSrcweir void SAL_CALL FSStorage::copyLastCommitTo(
761cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xTargetStorage )
762cdf0e10cSrcweir throw ( embed::InvalidStorageException,
763cdf0e10cSrcweir lang::IllegalArgumentException,
764cdf0e10cSrcweir io::IOException,
765cdf0e10cSrcweir embed::StorageWrappedTargetException,
766cdf0e10cSrcweir uno::RuntimeException )
767cdf0e10cSrcweir {
768cdf0e10cSrcweir copyToStorage( xTargetStorage );
769cdf0e10cSrcweir }
770cdf0e10cSrcweir
771cdf0e10cSrcweir //-----------------------------------------------
copyStorageElementLastCommitTo(const::rtl::OUString & aStorName,const uno::Reference<embed::XStorage> & xTargetStorage)772cdf0e10cSrcweir void SAL_CALL FSStorage::copyStorageElementLastCommitTo(
773cdf0e10cSrcweir const ::rtl::OUString& aStorName,
774cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xTargetStorage )
775cdf0e10cSrcweir throw ( embed::InvalidStorageException,
776cdf0e10cSrcweir lang::IllegalArgumentException,
777cdf0e10cSrcweir io::IOException,
778cdf0e10cSrcweir embed::StorageWrappedTargetException,
779cdf0e10cSrcweir uno::RuntimeException )
780cdf0e10cSrcweir {
781cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
782cdf0e10cSrcweir
783cdf0e10cSrcweir if ( !m_pImpl )
784cdf0e10cSrcweir throw lang::DisposedException();
785cdf0e10cSrcweir
786cdf0e10cSrcweir uno::Reference< embed::XStorage > xSourceStor( openStorageElement( aStorName, embed::ElementModes::READ ),
787cdf0e10cSrcweir uno::UNO_QUERY_THROW );
788cdf0e10cSrcweir xSourceStor->copyToStorage( xTargetStorage );
789cdf0e10cSrcweir }
790cdf0e10cSrcweir
791cdf0e10cSrcweir //-----------------------------------------------
isStreamElement(const::rtl::OUString & aElementName)792cdf0e10cSrcweir sal_Bool SAL_CALL FSStorage::isStreamElement( const ::rtl::OUString& aElementName )
793cdf0e10cSrcweir throw ( embed::InvalidStorageException,
794cdf0e10cSrcweir lang::IllegalArgumentException,
795cdf0e10cSrcweir container::NoSuchElementException,
796cdf0e10cSrcweir uno::RuntimeException )
797cdf0e10cSrcweir {
798cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
799cdf0e10cSrcweir
800cdf0e10cSrcweir if ( !m_pImpl )
801cdf0e10cSrcweir throw lang::DisposedException();
802cdf0e10cSrcweir
803cdf0e10cSrcweir if ( !GetContent() )
804cdf0e10cSrcweir throw embed::InvalidStorageException(); // TODO: error handling
805cdf0e10cSrcweir
806cdf0e10cSrcweir INetURLObject aURL( m_pImpl->m_aURL );
807cdf0e10cSrcweir aURL.Append( aElementName );
808cdf0e10cSrcweir
809cdf0e10cSrcweir return !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
810cdf0e10cSrcweir }
811cdf0e10cSrcweir
812cdf0e10cSrcweir //-----------------------------------------------
isStorageElement(const::rtl::OUString & aElementName)813cdf0e10cSrcweir sal_Bool SAL_CALL FSStorage::isStorageElement( const ::rtl::OUString& aElementName )
814cdf0e10cSrcweir throw ( embed::InvalidStorageException,
815cdf0e10cSrcweir lang::IllegalArgumentException,
816cdf0e10cSrcweir container::NoSuchElementException,
817cdf0e10cSrcweir uno::RuntimeException )
818cdf0e10cSrcweir {
819cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
820cdf0e10cSrcweir
821cdf0e10cSrcweir if ( !m_pImpl )
822cdf0e10cSrcweir throw lang::DisposedException();
823cdf0e10cSrcweir
824cdf0e10cSrcweir if ( !GetContent() )
825cdf0e10cSrcweir throw embed::InvalidStorageException(); // TODO: error handling
826cdf0e10cSrcweir
827cdf0e10cSrcweir INetURLObject aURL( m_pImpl->m_aURL );
828cdf0e10cSrcweir aURL.Append( aElementName );
829cdf0e10cSrcweir
830cdf0e10cSrcweir return ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
831cdf0e10cSrcweir }
832cdf0e10cSrcweir
833cdf0e10cSrcweir //-----------------------------------------------
removeElement(const::rtl::OUString & aElementName)834cdf0e10cSrcweir void SAL_CALL FSStorage::removeElement( const ::rtl::OUString& aElementName )
835cdf0e10cSrcweir throw ( embed::InvalidStorageException,
836cdf0e10cSrcweir lang::IllegalArgumentException,
837cdf0e10cSrcweir container::NoSuchElementException,
838cdf0e10cSrcweir io::IOException,
839cdf0e10cSrcweir embed::StorageWrappedTargetException,
840cdf0e10cSrcweir uno::RuntimeException )
841cdf0e10cSrcweir {
842cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
843cdf0e10cSrcweir
844cdf0e10cSrcweir if ( !m_pImpl )
845cdf0e10cSrcweir throw lang::DisposedException();
846cdf0e10cSrcweir
847cdf0e10cSrcweir if ( !GetContent() )
848cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
849cdf0e10cSrcweir
850cdf0e10cSrcweir INetURLObject aURL( m_pImpl->m_aURL );
851cdf0e10cSrcweir aURL.Append( aElementName );
852cdf0e10cSrcweir
853cdf0e10cSrcweir if ( !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) )
854cdf0e10cSrcweir && !::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
855cdf0e10cSrcweir throw container::NoSuchElementException(); // TODO:
856cdf0e10cSrcweir
857cdf0e10cSrcweir ::utl::UCBContentHelper::Kill( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
858cdf0e10cSrcweir }
859cdf0e10cSrcweir
860cdf0e10cSrcweir //-----------------------------------------------
renameElement(const::rtl::OUString & aElementName,const::rtl::OUString & aNewName)861cdf0e10cSrcweir void SAL_CALL FSStorage::renameElement( const ::rtl::OUString& aElementName, const ::rtl::OUString& aNewName )
862cdf0e10cSrcweir throw ( embed::InvalidStorageException,
863cdf0e10cSrcweir lang::IllegalArgumentException,
864cdf0e10cSrcweir container::NoSuchElementException,
865cdf0e10cSrcweir container::ElementExistException,
866cdf0e10cSrcweir io::IOException,
867cdf0e10cSrcweir embed::StorageWrappedTargetException,
868cdf0e10cSrcweir uno::RuntimeException )
869cdf0e10cSrcweir {
870cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
871cdf0e10cSrcweir
872cdf0e10cSrcweir if ( !m_pImpl )
873cdf0e10cSrcweir throw lang::DisposedException();
874cdf0e10cSrcweir
875cdf0e10cSrcweir if ( !GetContent() )
876cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
877cdf0e10cSrcweir
878cdf0e10cSrcweir INetURLObject aOldURL( m_pImpl->m_aURL );
879cdf0e10cSrcweir aOldURL.Append( aElementName );
880cdf0e10cSrcweir
881cdf0e10cSrcweir INetURLObject aNewURL( m_pImpl->m_aURL );
882cdf0e10cSrcweir aNewURL.Append( aNewName );
883cdf0e10cSrcweir
884cdf0e10cSrcweir if ( !::utl::UCBContentHelper::IsFolder( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) )
885cdf0e10cSrcweir && !::utl::UCBContentHelper::IsDocument( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
886cdf0e10cSrcweir throw container::NoSuchElementException(); // TODO:
887cdf0e10cSrcweir
888cdf0e10cSrcweir if ( ::utl::UCBContentHelper::IsFolder( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) )
889cdf0e10cSrcweir || ::utl::UCBContentHelper::IsDocument( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
890cdf0e10cSrcweir throw container::ElementExistException(); // TODO:
891cdf0e10cSrcweir
892cdf0e10cSrcweir try
893cdf0e10cSrcweir {
894cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
895cdf0e10cSrcweir ::ucbhelper::Content aSourceContent( aOldURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
896cdf0e10cSrcweir
897cdf0e10cSrcweir if ( !GetContent()->transferContent( aSourceContent,
898cdf0e10cSrcweir ::ucbhelper::InsertOperation_MOVE,
899cdf0e10cSrcweir aNewName,
900cdf0e10cSrcweir ucb::NameClash::ERROR ) )
901cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
902cdf0e10cSrcweir }
903cdf0e10cSrcweir catch( embed::InvalidStorageException& )
904cdf0e10cSrcweir {
905cdf0e10cSrcweir throw;
906cdf0e10cSrcweir }
907cdf0e10cSrcweir catch( lang::IllegalArgumentException& )
908cdf0e10cSrcweir {
909cdf0e10cSrcweir throw;
910cdf0e10cSrcweir }
911cdf0e10cSrcweir catch( container::NoSuchElementException& )
912cdf0e10cSrcweir {
913cdf0e10cSrcweir throw;
914cdf0e10cSrcweir }
915cdf0e10cSrcweir catch( container::ElementExistException& )
916cdf0e10cSrcweir {
917cdf0e10cSrcweir throw;
918cdf0e10cSrcweir }
919cdf0e10cSrcweir catch( io::IOException& )
920cdf0e10cSrcweir {
921cdf0e10cSrcweir throw;
922cdf0e10cSrcweir }
923cdf0e10cSrcweir catch( embed::StorageWrappedTargetException& )
924cdf0e10cSrcweir {
925cdf0e10cSrcweir throw;
926cdf0e10cSrcweir }
927cdf0e10cSrcweir catch( uno::RuntimeException& )
928cdf0e10cSrcweir {
929cdf0e10cSrcweir throw;
930cdf0e10cSrcweir }
931cdf0e10cSrcweir catch( uno::Exception& )
932cdf0e10cSrcweir {
933cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
934cdf0e10cSrcweir throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
935cdf0e10cSrcweir uno::Reference< io::XInputStream >(),
936cdf0e10cSrcweir aCaught );
937cdf0e10cSrcweir }
938cdf0e10cSrcweir }
939cdf0e10cSrcweir
940cdf0e10cSrcweir //-----------------------------------------------
copyElementTo(const::rtl::OUString & aElementName,const uno::Reference<embed::XStorage> & xDest,const::rtl::OUString & aNewName)941cdf0e10cSrcweir void SAL_CALL FSStorage::copyElementTo( const ::rtl::OUString& aElementName,
942cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xDest,
943cdf0e10cSrcweir const ::rtl::OUString& aNewName )
944cdf0e10cSrcweir throw ( embed::InvalidStorageException,
945cdf0e10cSrcweir lang::IllegalArgumentException,
946cdf0e10cSrcweir container::NoSuchElementException,
947cdf0e10cSrcweir container::ElementExistException,
948cdf0e10cSrcweir io::IOException,
949cdf0e10cSrcweir embed::StorageWrappedTargetException,
950cdf0e10cSrcweir uno::RuntimeException )
951cdf0e10cSrcweir {
952cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
953cdf0e10cSrcweir
954cdf0e10cSrcweir if ( !m_pImpl )
955cdf0e10cSrcweir throw lang::DisposedException();
956cdf0e10cSrcweir
957cdf0e10cSrcweir if ( !xDest.is() )
958cdf0e10cSrcweir throw uno::RuntimeException();
959cdf0e10cSrcweir
960cdf0e10cSrcweir if ( !GetContent() )
961cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
962cdf0e10cSrcweir
963cdf0e10cSrcweir INetURLObject aOwnURL( m_pImpl->m_aURL );
964cdf0e10cSrcweir aOwnURL.Append( aElementName );
965cdf0e10cSrcweir
966cdf0e10cSrcweir if ( xDest->hasByName( aNewName ) )
967cdf0e10cSrcweir throw container::ElementExistException(); // TODO:
968cdf0e10cSrcweir
969cdf0e10cSrcweir try
970cdf0e10cSrcweir {
971cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xDummyEnv;
972cdf0e10cSrcweir if ( ::utl::UCBContentHelper::IsFolder( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
973cdf0e10cSrcweir {
974cdf0e10cSrcweir ::ucbhelper::Content aSourceContent( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
975cdf0e10cSrcweir uno::Reference< embed::XStorage > xDestSubStor(
976cdf0e10cSrcweir xDest->openStorageElement( aNewName, embed::ElementModes::READWRITE ),
977cdf0e10cSrcweir uno::UNO_QUERY_THROW );
978cdf0e10cSrcweir
979cdf0e10cSrcweir CopyContentToStorage_Impl( &aSourceContent, xDestSubStor );
980cdf0e10cSrcweir }
981cdf0e10cSrcweir else if ( ::utl::UCBContentHelper::IsDocument( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
982cdf0e10cSrcweir {
983cdf0e10cSrcweir CopyStreamToSubStream( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDest, aNewName );
984cdf0e10cSrcweir }
985cdf0e10cSrcweir else
986cdf0e10cSrcweir throw container::NoSuchElementException(); // TODO:
987cdf0e10cSrcweir }
988cdf0e10cSrcweir catch( embed::InvalidStorageException& )
989cdf0e10cSrcweir {
990cdf0e10cSrcweir throw;
991cdf0e10cSrcweir }
992cdf0e10cSrcweir catch( lang::IllegalArgumentException& )
993cdf0e10cSrcweir {
994cdf0e10cSrcweir throw;
995cdf0e10cSrcweir }
996cdf0e10cSrcweir catch( container::NoSuchElementException& )
997cdf0e10cSrcweir {
998cdf0e10cSrcweir throw;
999cdf0e10cSrcweir }
1000cdf0e10cSrcweir catch( container::ElementExistException& )
1001cdf0e10cSrcweir {
1002cdf0e10cSrcweir throw;
1003cdf0e10cSrcweir }
1004cdf0e10cSrcweir catch( embed::StorageWrappedTargetException& )
1005cdf0e10cSrcweir {
1006cdf0e10cSrcweir throw;
1007cdf0e10cSrcweir }
1008cdf0e10cSrcweir catch( io::IOException& )
1009cdf0e10cSrcweir {
1010cdf0e10cSrcweir throw;
1011cdf0e10cSrcweir }
1012cdf0e10cSrcweir catch( uno::RuntimeException& )
1013cdf0e10cSrcweir {
1014cdf0e10cSrcweir throw;
1015cdf0e10cSrcweir }
1016cdf0e10cSrcweir catch( uno::Exception& )
1017cdf0e10cSrcweir {
1018cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
1019cdf0e10cSrcweir throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
1020cdf0e10cSrcweir uno::Reference< io::XInputStream >(),
1021cdf0e10cSrcweir aCaught );
1022cdf0e10cSrcweir }
1023cdf0e10cSrcweir }
1024cdf0e10cSrcweir
1025cdf0e10cSrcweir //-----------------------------------------------
moveElementTo(const::rtl::OUString & aElementName,const uno::Reference<embed::XStorage> & xDest,const::rtl::OUString & aNewName)1026cdf0e10cSrcweir void SAL_CALL FSStorage::moveElementTo( const ::rtl::OUString& aElementName,
1027cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xDest,
1028cdf0e10cSrcweir const ::rtl::OUString& aNewName )
1029cdf0e10cSrcweir throw ( embed::InvalidStorageException,
1030cdf0e10cSrcweir lang::IllegalArgumentException,
1031cdf0e10cSrcweir container::NoSuchElementException,
1032cdf0e10cSrcweir container::ElementExistException,
1033cdf0e10cSrcweir io::IOException,
1034cdf0e10cSrcweir embed::StorageWrappedTargetException,
1035cdf0e10cSrcweir uno::RuntimeException )
1036cdf0e10cSrcweir {
1037cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1038cdf0e10cSrcweir copyElementTo( aElementName, xDest, aNewName );
1039cdf0e10cSrcweir
1040cdf0e10cSrcweir INetURLObject aOwnURL( m_pImpl->m_aURL );
1041cdf0e10cSrcweir aOwnURL.Append( aElementName );
1042cdf0e10cSrcweir if ( !::utl::UCBContentHelper::Kill( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1043cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
1044cdf0e10cSrcweir }
1045cdf0e10cSrcweir
1046cdf0e10cSrcweir //____________________________________________________________________________________________________
1047cdf0e10cSrcweir // XNameAccess
1048cdf0e10cSrcweir //____________________________________________________________________________________________________
1049cdf0e10cSrcweir
1050cdf0e10cSrcweir //-----------------------------------------------
getByName(const::rtl::OUString & aName)1051cdf0e10cSrcweir uno::Any SAL_CALL FSStorage::getByName( const ::rtl::OUString& aName )
1052cdf0e10cSrcweir throw ( container::NoSuchElementException,
1053cdf0e10cSrcweir lang::WrappedTargetException,
1054cdf0e10cSrcweir uno::RuntimeException )
1055cdf0e10cSrcweir {
1056cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1057cdf0e10cSrcweir
1058cdf0e10cSrcweir if ( !m_pImpl )
1059cdf0e10cSrcweir throw lang::DisposedException();
1060cdf0e10cSrcweir
1061cdf0e10cSrcweir if ( !GetContent() )
1062cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
1063cdf0e10cSrcweir
1064cdf0e10cSrcweir if ( !aName.getLength() )
1065cdf0e10cSrcweir throw lang::IllegalArgumentException();
1066cdf0e10cSrcweir
1067cdf0e10cSrcweir INetURLObject aURL( m_pImpl->m_aURL );
1068cdf0e10cSrcweir aURL.Append( aName );
1069cdf0e10cSrcweir
1070cdf0e10cSrcweir uno::Any aResult;
1071cdf0e10cSrcweir try
1072cdf0e10cSrcweir {
1073cdf0e10cSrcweir if ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1074cdf0e10cSrcweir {
1075cdf0e10cSrcweir aResult <<= openStorageElement( aName, embed::ElementModes::READ );
1076cdf0e10cSrcweir }
1077cdf0e10cSrcweir else if ( ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1078cdf0e10cSrcweir {
1079cdf0e10cSrcweir aResult <<= openStreamElement( aName, embed::ElementModes::READ );
1080cdf0e10cSrcweir }
1081cdf0e10cSrcweir else
1082cdf0e10cSrcweir throw container::NoSuchElementException(); // TODO:
1083cdf0e10cSrcweir }
1084cdf0e10cSrcweir catch( container::NoSuchElementException& )
1085cdf0e10cSrcweir {
1086cdf0e10cSrcweir throw;
1087cdf0e10cSrcweir }
1088cdf0e10cSrcweir catch( lang::WrappedTargetException& )
1089cdf0e10cSrcweir {
1090cdf0e10cSrcweir throw;
1091cdf0e10cSrcweir }
1092cdf0e10cSrcweir catch( uno::RuntimeException& )
1093cdf0e10cSrcweir {
1094cdf0e10cSrcweir throw;
1095cdf0e10cSrcweir }
1096cdf0e10cSrcweir catch ( uno::Exception& )
1097cdf0e10cSrcweir {
1098cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
1099cdf0e10cSrcweir throw lang::WrappedTargetException( ::rtl::OUString::createFromAscii( "Can not open element!\n" ),
1100cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1101cdf0e10cSrcweir uno::UNO_QUERY ),
1102cdf0e10cSrcweir aCaught );
1103cdf0e10cSrcweir }
1104cdf0e10cSrcweir
1105cdf0e10cSrcweir return aResult;
1106cdf0e10cSrcweir }
1107cdf0e10cSrcweir
1108cdf0e10cSrcweir
1109cdf0e10cSrcweir //-----------------------------------------------
getElementNames()1110cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL FSStorage::getElementNames()
1111cdf0e10cSrcweir throw ( uno::RuntimeException )
1112cdf0e10cSrcweir {
1113cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1114cdf0e10cSrcweir
1115cdf0e10cSrcweir if ( !m_pImpl )
1116cdf0e10cSrcweir throw lang::DisposedException();
1117cdf0e10cSrcweir
1118cdf0e10cSrcweir if ( !GetContent() )
1119cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
1120cdf0e10cSrcweir
1121cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aProps( 1 );
1122cdf0e10cSrcweir ::rtl::OUString* pProps = aProps.getArray();
1123cdf0e10cSrcweir pProps[0] = ::rtl::OUString::createFromAscii( "Title" );
1124cdf0e10cSrcweir ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
1125cdf0e10cSrcweir
1126cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aResult;
1127cdf0e10cSrcweir sal_Int32 nSize = 0;
1128cdf0e10cSrcweir
1129cdf0e10cSrcweir try
1130cdf0e10cSrcweir {
1131cdf0e10cSrcweir uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude );
1132cdf0e10cSrcweir uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
1133cdf0e10cSrcweir uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY );
1134cdf0e10cSrcweir if ( xResultSet.is() )
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir // go through the list
1137cdf0e10cSrcweir while ( xResultSet->next() )
1138cdf0e10cSrcweir {
1139cdf0e10cSrcweir ::rtl::OUString aName( xRow->getString( 1 ) );
1140cdf0e10cSrcweir aResult.realloc( ++nSize );
1141cdf0e10cSrcweir aResult[nSize-1] = aName;
1142cdf0e10cSrcweir }
1143cdf0e10cSrcweir }
1144cdf0e10cSrcweir }
1145cdf0e10cSrcweir catch( ucb::InteractiveIOException& r )
1146cdf0e10cSrcweir {
1147cdf0e10cSrcweir if ( r.Code == ucb::IOErrorCode_NOT_EXISTING )
1148cdf0e10cSrcweir OSL_ENSURE( sal_False, "The folder does not exist!\n" );
1149cdf0e10cSrcweir else
1150cdf0e10cSrcweir {
1151cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
1152cdf0e10cSrcweir throw lang::WrappedTargetRuntimeException( ::rtl::OUString::createFromAscii( "Can not open storage!\n" ),
1153cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1154cdf0e10cSrcweir uno::UNO_QUERY ),
1155cdf0e10cSrcweir aCaught );
1156cdf0e10cSrcweir }
1157cdf0e10cSrcweir }
1158cdf0e10cSrcweir catch( uno::RuntimeException& )
1159cdf0e10cSrcweir {
1160cdf0e10cSrcweir throw;
1161cdf0e10cSrcweir }
1162cdf0e10cSrcweir catch ( uno::Exception& )
1163cdf0e10cSrcweir {
1164cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
1165cdf0e10cSrcweir throw lang::WrappedTargetRuntimeException( ::rtl::OUString::createFromAscii( "Can not open storage!\n" ),
1166cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1167cdf0e10cSrcweir uno::UNO_QUERY ),
1168cdf0e10cSrcweir aCaught );
1169cdf0e10cSrcweir }
1170cdf0e10cSrcweir
1171cdf0e10cSrcweir return aResult;
1172cdf0e10cSrcweir }
1173cdf0e10cSrcweir
1174cdf0e10cSrcweir
1175cdf0e10cSrcweir //-----------------------------------------------
hasByName(const::rtl::OUString & aName)1176cdf0e10cSrcweir sal_Bool SAL_CALL FSStorage::hasByName( const ::rtl::OUString& aName )
1177cdf0e10cSrcweir throw ( uno::RuntimeException )
1178cdf0e10cSrcweir {
1179cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1180cdf0e10cSrcweir
1181cdf0e10cSrcweir if ( !m_pImpl )
1182cdf0e10cSrcweir throw lang::DisposedException();
1183cdf0e10cSrcweir
1184cdf0e10cSrcweir try
1185cdf0e10cSrcweir {
1186cdf0e10cSrcweir if ( !GetContent() )
1187cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
1188cdf0e10cSrcweir
1189cdf0e10cSrcweir if ( !aName.getLength() )
1190cdf0e10cSrcweir throw lang::IllegalArgumentException();
1191cdf0e10cSrcweir }
1192cdf0e10cSrcweir catch( uno::RuntimeException& )
1193cdf0e10cSrcweir {
1194cdf0e10cSrcweir throw;
1195cdf0e10cSrcweir }
1196cdf0e10cSrcweir catch ( uno::Exception& )
1197cdf0e10cSrcweir {
1198cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
1199cdf0e10cSrcweir throw lang::WrappedTargetRuntimeException( ::rtl::OUString::createFromAscii( "Can not open storage!\n" ),
1200cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ),
1201cdf0e10cSrcweir uno::UNO_QUERY ),
1202cdf0e10cSrcweir aCaught );
1203cdf0e10cSrcweir }
1204cdf0e10cSrcweir
1205cdf0e10cSrcweir INetURLObject aURL( m_pImpl->m_aURL );
1206cdf0e10cSrcweir aURL.Append( aName );
1207cdf0e10cSrcweir
1208cdf0e10cSrcweir return ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) )
1209cdf0e10cSrcweir || ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) );
1210cdf0e10cSrcweir }
1211cdf0e10cSrcweir
1212cdf0e10cSrcweir //-----------------------------------------------
getElementType()1213cdf0e10cSrcweir uno::Type SAL_CALL FSStorage::getElementType()
1214cdf0e10cSrcweir throw ( uno::RuntimeException )
1215cdf0e10cSrcweir {
1216cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1217cdf0e10cSrcweir
1218cdf0e10cSrcweir if ( !m_pImpl )
1219cdf0e10cSrcweir throw lang::DisposedException();
1220cdf0e10cSrcweir
1221cdf0e10cSrcweir // it is a multitype container
1222cdf0e10cSrcweir return uno::Type();
1223cdf0e10cSrcweir }
1224cdf0e10cSrcweir
1225cdf0e10cSrcweir //-----------------------------------------------
hasElements()1226cdf0e10cSrcweir sal_Bool SAL_CALL FSStorage::hasElements()
1227cdf0e10cSrcweir throw ( uno::RuntimeException )
1228cdf0e10cSrcweir {
1229cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1230cdf0e10cSrcweir
1231cdf0e10cSrcweir if ( !m_pImpl )
1232cdf0e10cSrcweir throw lang::DisposedException();
1233cdf0e10cSrcweir
1234cdf0e10cSrcweir if ( !GetContent() )
1235cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
1236cdf0e10cSrcweir
1237cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aProps( 1 );
1238cdf0e10cSrcweir aProps[0] = ::rtl::OUString::createFromAscii( "TargetURL" );
1239cdf0e10cSrcweir ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS;
1240cdf0e10cSrcweir
1241cdf0e10cSrcweir try
1242cdf0e10cSrcweir {
1243cdf0e10cSrcweir uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude );
1244cdf0e10cSrcweir return ( xResultSet.is() && xResultSet->next() );
1245cdf0e10cSrcweir }
1246cdf0e10cSrcweir catch( uno::Exception& )
1247cdf0e10cSrcweir {
1248cdf0e10cSrcweir throw uno::RuntimeException();
1249cdf0e10cSrcweir }
1250cdf0e10cSrcweir }
1251cdf0e10cSrcweir
1252cdf0e10cSrcweir
1253cdf0e10cSrcweir //____________________________________________________________________________________________________
1254cdf0e10cSrcweir // XDisposable
1255cdf0e10cSrcweir //____________________________________________________________________________________________________
1256cdf0e10cSrcweir
1257cdf0e10cSrcweir //-----------------------------------------------
dispose()1258cdf0e10cSrcweir void SAL_CALL FSStorage::dispose()
1259cdf0e10cSrcweir throw ( uno::RuntimeException )
1260cdf0e10cSrcweir {
1261cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1262cdf0e10cSrcweir
1263cdf0e10cSrcweir if ( !m_pImpl )
1264cdf0e10cSrcweir throw lang::DisposedException();
1265cdf0e10cSrcweir
1266cdf0e10cSrcweir if ( m_pImpl->m_pListenersContainer )
1267cdf0e10cSrcweir {
1268cdf0e10cSrcweir lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
1269cdf0e10cSrcweir m_pImpl->m_pListenersContainer->disposeAndClear( aSource );
1270cdf0e10cSrcweir }
1271cdf0e10cSrcweir
1272cdf0e10cSrcweir delete m_pImpl;
1273cdf0e10cSrcweir m_pImpl = NULL;
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir
1276cdf0e10cSrcweir //-----------------------------------------------
addEventListener(const uno::Reference<lang::XEventListener> & xListener)1277cdf0e10cSrcweir void SAL_CALL FSStorage::addEventListener(
1278cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& xListener )
1279cdf0e10cSrcweir throw ( uno::RuntimeException )
1280cdf0e10cSrcweir {
1281cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1282cdf0e10cSrcweir
1283cdf0e10cSrcweir if ( !m_pImpl )
1284cdf0e10cSrcweir throw lang::DisposedException();
1285cdf0e10cSrcweir
1286cdf0e10cSrcweir if ( !m_pImpl->m_pListenersContainer )
1287cdf0e10cSrcweir m_pImpl->m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex );
1288cdf0e10cSrcweir
1289cdf0e10cSrcweir m_pImpl->m_pListenersContainer->addInterface( xListener );
1290cdf0e10cSrcweir }
1291cdf0e10cSrcweir
1292cdf0e10cSrcweir //-----------------------------------------------
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)1293cdf0e10cSrcweir void SAL_CALL FSStorage::removeEventListener(
1294cdf0e10cSrcweir const uno::Reference< lang::XEventListener >& xListener )
1295cdf0e10cSrcweir throw ( uno::RuntimeException )
1296cdf0e10cSrcweir {
1297cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1298cdf0e10cSrcweir
1299cdf0e10cSrcweir if ( !m_pImpl )
1300cdf0e10cSrcweir throw lang::DisposedException();
1301cdf0e10cSrcweir
1302cdf0e10cSrcweir if ( m_pImpl->m_pListenersContainer )
1303cdf0e10cSrcweir m_pImpl->m_pListenersContainer->removeInterface( xListener );
1304cdf0e10cSrcweir }
1305cdf0e10cSrcweir
1306cdf0e10cSrcweir //____________________________________________________________________________________________________
1307cdf0e10cSrcweir // XPropertySet
1308cdf0e10cSrcweir //____________________________________________________________________________________________________
1309cdf0e10cSrcweir
1310cdf0e10cSrcweir //-----------------------------------------------
getPropertySetInfo()1311cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL FSStorage::getPropertySetInfo()
1312cdf0e10cSrcweir throw ( uno::RuntimeException )
1313cdf0e10cSrcweir {
1314cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1315cdf0e10cSrcweir
1316cdf0e10cSrcweir if ( !m_pImpl )
1317cdf0e10cSrcweir throw lang::DisposedException();
1318cdf0e10cSrcweir
1319cdf0e10cSrcweir //TODO:
1320cdf0e10cSrcweir return uno::Reference< beans::XPropertySetInfo >();
1321cdf0e10cSrcweir }
1322cdf0e10cSrcweir
1323cdf0e10cSrcweir
1324cdf0e10cSrcweir //-----------------------------------------------
setPropertyValue(const::rtl::OUString & aPropertyName,const uno::Any &)1325cdf0e10cSrcweir void SAL_CALL FSStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& )
1326cdf0e10cSrcweir throw ( beans::UnknownPropertyException,
1327cdf0e10cSrcweir beans::PropertyVetoException,
1328cdf0e10cSrcweir lang::IllegalArgumentException,
1329cdf0e10cSrcweir lang::WrappedTargetException,
1330cdf0e10cSrcweir uno::RuntimeException )
1331cdf0e10cSrcweir {
1332cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1333cdf0e10cSrcweir
1334cdf0e10cSrcweir if ( !m_pImpl )
1335cdf0e10cSrcweir throw lang::DisposedException();
1336cdf0e10cSrcweir
1337cdf0e10cSrcweir if ( aPropertyName.equalsAscii( "URL" ) || aPropertyName.equalsAscii( "OpenMode" ) )
1338cdf0e10cSrcweir throw beans::PropertyVetoException(); // TODO
1339cdf0e10cSrcweir else
1340cdf0e10cSrcweir throw beans::UnknownPropertyException(); // TODO
1341cdf0e10cSrcweir }
1342cdf0e10cSrcweir
1343cdf0e10cSrcweir
1344cdf0e10cSrcweir //-----------------------------------------------
getPropertyValue(const::rtl::OUString & aPropertyName)1345cdf0e10cSrcweir uno::Any SAL_CALL FSStorage::getPropertyValue( const ::rtl::OUString& aPropertyName )
1346cdf0e10cSrcweir throw ( beans::UnknownPropertyException,
1347cdf0e10cSrcweir lang::WrappedTargetException,
1348cdf0e10cSrcweir uno::RuntimeException )
1349cdf0e10cSrcweir {
1350cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1351cdf0e10cSrcweir
1352cdf0e10cSrcweir if ( !m_pImpl )
1353cdf0e10cSrcweir throw lang::DisposedException();
1354cdf0e10cSrcweir
1355cdf0e10cSrcweir if ( aPropertyName.equalsAscii( "URL" ) )
1356cdf0e10cSrcweir return uno::makeAny( m_pImpl->m_aURL );
1357cdf0e10cSrcweir else if ( aPropertyName.equalsAscii( "OpenMode" ) )
1358cdf0e10cSrcweir return uno::makeAny( m_pImpl->m_nMode );
1359cdf0e10cSrcweir
1360cdf0e10cSrcweir throw beans::UnknownPropertyException(); // TODO
1361cdf0e10cSrcweir }
1362cdf0e10cSrcweir
1363cdf0e10cSrcweir
1364cdf0e10cSrcweir //-----------------------------------------------
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1365cdf0e10cSrcweir void SAL_CALL FSStorage::addPropertyChangeListener(
1366cdf0e10cSrcweir const ::rtl::OUString& /*aPropertyName*/,
1367cdf0e10cSrcweir const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
1368cdf0e10cSrcweir throw ( beans::UnknownPropertyException,
1369cdf0e10cSrcweir lang::WrappedTargetException,
1370cdf0e10cSrcweir uno::RuntimeException )
1371cdf0e10cSrcweir {
1372cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1373cdf0e10cSrcweir
1374cdf0e10cSrcweir if ( !m_pImpl )
1375cdf0e10cSrcweir throw lang::DisposedException();
1376cdf0e10cSrcweir
1377cdf0e10cSrcweir //TODO:
1378cdf0e10cSrcweir }
1379cdf0e10cSrcweir
1380cdf0e10cSrcweir
1381cdf0e10cSrcweir //-----------------------------------------------
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1382cdf0e10cSrcweir void SAL_CALL FSStorage::removePropertyChangeListener(
1383cdf0e10cSrcweir const ::rtl::OUString& /*aPropertyName*/,
1384cdf0e10cSrcweir const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
1385cdf0e10cSrcweir throw ( beans::UnknownPropertyException,
1386cdf0e10cSrcweir lang::WrappedTargetException,
1387cdf0e10cSrcweir uno::RuntimeException )
1388cdf0e10cSrcweir {
1389cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1390cdf0e10cSrcweir
1391cdf0e10cSrcweir if ( !m_pImpl )
1392cdf0e10cSrcweir throw lang::DisposedException();
1393cdf0e10cSrcweir
1394cdf0e10cSrcweir //TODO:
1395cdf0e10cSrcweir }
1396cdf0e10cSrcweir
1397cdf0e10cSrcweir
1398cdf0e10cSrcweir //-----------------------------------------------
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1399cdf0e10cSrcweir void SAL_CALL FSStorage::addVetoableChangeListener(
1400cdf0e10cSrcweir const ::rtl::OUString& /*PropertyName*/,
1401cdf0e10cSrcweir const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
1402cdf0e10cSrcweir throw ( beans::UnknownPropertyException,
1403cdf0e10cSrcweir lang::WrappedTargetException,
1404cdf0e10cSrcweir uno::RuntimeException )
1405cdf0e10cSrcweir {
1406cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1407cdf0e10cSrcweir
1408cdf0e10cSrcweir if ( !m_pImpl )
1409cdf0e10cSrcweir throw lang::DisposedException();
1410cdf0e10cSrcweir
1411cdf0e10cSrcweir //TODO:
1412cdf0e10cSrcweir }
1413cdf0e10cSrcweir
1414cdf0e10cSrcweir
1415cdf0e10cSrcweir //-----------------------------------------------
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1416cdf0e10cSrcweir void SAL_CALL FSStorage::removeVetoableChangeListener(
1417cdf0e10cSrcweir const ::rtl::OUString& /*PropertyName*/,
1418cdf0e10cSrcweir const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
1419cdf0e10cSrcweir throw ( beans::UnknownPropertyException,
1420cdf0e10cSrcweir lang::WrappedTargetException,
1421cdf0e10cSrcweir uno::RuntimeException )
1422cdf0e10cSrcweir {
1423cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1424cdf0e10cSrcweir
1425cdf0e10cSrcweir if ( !m_pImpl )
1426cdf0e10cSrcweir throw lang::DisposedException();
1427cdf0e10cSrcweir
1428cdf0e10cSrcweir //TODO:
1429cdf0e10cSrcweir }
1430cdf0e10cSrcweir
1431cdf0e10cSrcweir //____________________________________________________________________________________________________
1432cdf0e10cSrcweir // XHierarchicalStorageAccess
1433cdf0e10cSrcweir //____________________________________________________________________________________________________
1434cdf0e10cSrcweir //-----------------------------------------------
openStreamElementByHierarchicalName(const::rtl::OUString & sStreamPath,::sal_Int32 nOpenMode)1435cdf0e10cSrcweir uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath, ::sal_Int32 nOpenMode )
1436cdf0e10cSrcweir throw ( embed::InvalidStorageException,
1437cdf0e10cSrcweir lang::IllegalArgumentException,
1438cdf0e10cSrcweir packages::WrongPasswordException,
1439cdf0e10cSrcweir io::IOException,
1440cdf0e10cSrcweir embed::StorageWrappedTargetException,
1441cdf0e10cSrcweir uno::RuntimeException )
1442cdf0e10cSrcweir {
1443cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1444cdf0e10cSrcweir
1445cdf0e10cSrcweir if ( !m_pImpl )
1446cdf0e10cSrcweir throw lang::DisposedException();
1447cdf0e10cSrcweir
1448cdf0e10cSrcweir if ( sStreamPath.toChar() == '/' )
1449cdf0e10cSrcweir throw lang::IllegalArgumentException();
1450cdf0e10cSrcweir
1451cdf0e10cSrcweir if ( !GetContent() )
1452cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
1453cdf0e10cSrcweir
1454cdf0e10cSrcweir INetURLObject aBaseURL( m_pImpl->m_aURL );
1455cdf0e10cSrcweir if ( !aBaseURL.setFinalSlash() )
1456cdf0e10cSrcweir throw uno::RuntimeException();
1457cdf0e10cSrcweir
1458cdf0e10cSrcweir INetURLObject aFileURL = INetURLObject::GetAbsURL(
1459cdf0e10cSrcweir aBaseURL.GetMainURL( INetURLObject::NO_DECODE ),
1460cdf0e10cSrcweir sStreamPath );
1461cdf0e10cSrcweir
1462cdf0e10cSrcweir if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1463cdf0e10cSrcweir throw io::IOException();
1464cdf0e10cSrcweir
1465cdf0e10cSrcweir if ( ( nOpenMode & embed::ElementModes::NOCREATE )
1466cdf0e10cSrcweir && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1467cdf0e10cSrcweir throw io::IOException(); // TODO:
1468cdf0e10cSrcweir
1469cdf0e10cSrcweir uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any
1470cdf0e10cSrcweir uno::Reference< io::XStream > xResult;
1471cdf0e10cSrcweir try
1472cdf0e10cSrcweir {
1473cdf0e10cSrcweir if ( nOpenMode & embed::ElementModes::WRITE )
1474cdf0e10cSrcweir {
1475cdf0e10cSrcweir if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1476cdf0e10cSrcweir {
1477cdf0e10cSrcweir uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess(
1478cdf0e10cSrcweir m_pImpl->m_xFactory->createInstance(
1479cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ),
1480cdf0e10cSrcweir uno::UNO_QUERY_THROW );
1481cdf0e10cSrcweir uno::Reference< io::XStream > xStream =
1482cdf0e10cSrcweir xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) );
1483cdf0e10cSrcweir
1484cdf0e10cSrcweir xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) );
1485cdf0e10cSrcweir }
1486cdf0e10cSrcweir else
1487cdf0e10cSrcweir {
1488cdf0e10cSrcweir // TODO: test whether it really works for http and fwp
1489cdf0e10cSrcweir SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ),
1490cdf0e10cSrcweir STREAM_STD_WRITE );
1491cdf0e10cSrcweir if ( pStream )
1492cdf0e10cSrcweir {
1493cdf0e10cSrcweir if ( !pStream->GetError() )
1494cdf0e10cSrcweir {
1495cdf0e10cSrcweir uno::Reference< io::XStream > xStream =
1496cdf0e10cSrcweir uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) );
1497cdf0e10cSrcweir xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) );
1498cdf0e10cSrcweir }
1499cdf0e10cSrcweir else
1500cdf0e10cSrcweir delete pStream;
1501cdf0e10cSrcweir }
1502cdf0e10cSrcweir }
1503cdf0e10cSrcweir
1504cdf0e10cSrcweir if ( !xResult.is() )
1505cdf0e10cSrcweir throw io::IOException();
1506cdf0e10cSrcweir
1507cdf0e10cSrcweir if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) )
1508cdf0e10cSrcweir {
1509cdf0e10cSrcweir uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW );
1510cdf0e10cSrcweir xTrunc->truncate();
1511cdf0e10cSrcweir }
1512cdf0e10cSrcweir }
1513cdf0e10cSrcweir else
1514cdf0e10cSrcweir {
1515cdf0e10cSrcweir if ( ( nOpenMode & embed::ElementModes::TRUNCATE )
1516cdf0e10cSrcweir || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1517cdf0e10cSrcweir throw io::IOException(); // TODO: access denied
1518cdf0e10cSrcweir
1519cdf0e10cSrcweir ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv );
1520cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = aResultContent.openStream();
1521cdf0e10cSrcweir xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) );
1522cdf0e10cSrcweir }
1523cdf0e10cSrcweir }
1524cdf0e10cSrcweir catch( embed::InvalidStorageException& )
1525cdf0e10cSrcweir {
1526cdf0e10cSrcweir throw;
1527cdf0e10cSrcweir }
1528cdf0e10cSrcweir catch( lang::IllegalArgumentException& )
1529cdf0e10cSrcweir {
1530cdf0e10cSrcweir throw;
1531cdf0e10cSrcweir }
1532cdf0e10cSrcweir catch( packages::WrongPasswordException& )
1533cdf0e10cSrcweir {
1534cdf0e10cSrcweir throw;
1535cdf0e10cSrcweir }
1536cdf0e10cSrcweir catch( embed::StorageWrappedTargetException& )
1537cdf0e10cSrcweir {
1538cdf0e10cSrcweir throw;
1539cdf0e10cSrcweir }
1540cdf0e10cSrcweir catch( io::IOException& )
1541cdf0e10cSrcweir {
1542cdf0e10cSrcweir throw;
1543cdf0e10cSrcweir }
1544cdf0e10cSrcweir catch( uno::RuntimeException& )
1545cdf0e10cSrcweir {
1546cdf0e10cSrcweir throw;
1547cdf0e10cSrcweir }
1548cdf0e10cSrcweir catch( uno::Exception& )
1549cdf0e10cSrcweir {
1550cdf0e10cSrcweir uno::Any aCaught( ::cppu::getCaughtException() );
1551cdf0e10cSrcweir throw embed::StorageWrappedTargetException( ::rtl::OUString::createFromAscii( "Can't copy raw stream" ),
1552cdf0e10cSrcweir uno::Reference< io::XInputStream >(),
1553cdf0e10cSrcweir aCaught );
1554cdf0e10cSrcweir }
1555cdf0e10cSrcweir
1556cdf0e10cSrcweir return uno::Reference< embed::XExtendedStorageStream >( xResult, uno::UNO_QUERY_THROW );
1557cdf0e10cSrcweir }
1558cdf0e10cSrcweir
1559cdf0e10cSrcweir //-----------------------------------------------
openEncryptedStreamElementByHierarchicalName(const::rtl::OUString &,::sal_Int32,const::rtl::OUString &)1560cdf0e10cSrcweir uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& /*sStreamName*/, ::sal_Int32 /*nOpenMode*/, const ::rtl::OUString& /*sPassword*/ )
1561cdf0e10cSrcweir throw ( embed::InvalidStorageException,
1562cdf0e10cSrcweir lang::IllegalArgumentException,
1563cdf0e10cSrcweir packages::NoEncryptionException,
1564cdf0e10cSrcweir packages::WrongPasswordException,
1565cdf0e10cSrcweir io::IOException,
1566cdf0e10cSrcweir embed::StorageWrappedTargetException,
1567cdf0e10cSrcweir uno::RuntimeException )
1568cdf0e10cSrcweir {
1569cdf0e10cSrcweir throw packages::NoEncryptionException();
1570cdf0e10cSrcweir }
1571cdf0e10cSrcweir
1572cdf0e10cSrcweir //-----------------------------------------------
removeStreamElementByHierarchicalName(const::rtl::OUString & sStreamPath)1573cdf0e10cSrcweir void SAL_CALL FSStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath )
1574cdf0e10cSrcweir throw ( embed::InvalidStorageException,
1575cdf0e10cSrcweir lang::IllegalArgumentException,
1576cdf0e10cSrcweir container::NoSuchElementException,
1577cdf0e10cSrcweir io::IOException,
1578cdf0e10cSrcweir embed::StorageWrappedTargetException,
1579cdf0e10cSrcweir uno::RuntimeException )
1580cdf0e10cSrcweir {
1581cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
1582cdf0e10cSrcweir
1583cdf0e10cSrcweir if ( !m_pImpl )
1584cdf0e10cSrcweir throw lang::DisposedException();
1585cdf0e10cSrcweir
1586cdf0e10cSrcweir if ( !GetContent() )
1587cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
1588cdf0e10cSrcweir
1589cdf0e10cSrcweir // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked
1590cdf0e10cSrcweir INetURLObject aBaseURL( m_pImpl->m_aURL );
1591cdf0e10cSrcweir if ( !aBaseURL.setFinalSlash() )
1592cdf0e10cSrcweir throw uno::RuntimeException();
1593cdf0e10cSrcweir
1594cdf0e10cSrcweir INetURLObject aFileURL = INetURLObject::GetAbsURL(
1595cdf0e10cSrcweir aBaseURL.GetMainURL( INetURLObject::NO_DECODE ),
1596cdf0e10cSrcweir sStreamPath );
1597cdf0e10cSrcweir
1598cdf0e10cSrcweir if ( !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1599cdf0e10cSrcweir {
1600cdf0e10cSrcweir if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1601cdf0e10cSrcweir throw lang::IllegalArgumentException();
1602cdf0e10cSrcweir else
1603cdf0e10cSrcweir throw container::NoSuchElementException(); // TODO:
1604cdf0e10cSrcweir }
1605cdf0e10cSrcweir
1606cdf0e10cSrcweir if ( !::utl::UCBContentHelper::Kill( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) )
1607cdf0e10cSrcweir throw io::IOException(); // TODO: error handling
1608cdf0e10cSrcweir }
1609cdf0e10cSrcweir
1610cdf0e10cSrcweir
1611