1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
30*cdf0e10cSrcweir #include <osl/diagnose.h>
31*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/io/XAsyncOutputMonitor.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/embed/UseBackupException.hpp>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <comphelper/otransactedfilestream.hxx>
36*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
37*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir using namespace ::com::sun::star;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir namespace comphelper
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir // ========================================================================
45*cdf0e10cSrcweir class OTransactionHelper : public ::cppu::WeakImplHelper1 < embed::XTransactedObject >
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir 	OTruncatedTransactedFileStream* m_pFileStream;
48*cdf0e10cSrcweir 	uno::Reference< io::XStream > m_xStreamHolder;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir public:
51*cdf0e10cSrcweir 	OTransactionHelper( OTruncatedTransactedFileStream* pStream )
52*cdf0e10cSrcweir 	: m_pFileStream( pStream )
53*cdf0e10cSrcweir 	{
54*cdf0e10cSrcweir 		m_xStreamHolder = static_cast< io::XStream* >( pStream );
55*cdf0e10cSrcweir 		if ( !m_xStreamHolder.is() )
56*cdf0e10cSrcweir 			throw uno::RuntimeException();
57*cdf0e10cSrcweir 	}
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     virtual void SAL_CALL commit(  ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException);
60*cdf0e10cSrcweir     virtual void SAL_CALL revert(  ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException);
61*cdf0e10cSrcweir };
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir // ------------------------------------------------------------------------
64*cdf0e10cSrcweir void SAL_CALL OTransactionHelper::commit(  ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException)
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir 	m_pFileStream->Commit_Impl();
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir // ------------------------------------------------------------------------
70*cdf0e10cSrcweir void SAL_CALL OTransactionHelper::revert(  ) throw (io::IOException, lang::WrappedTargetException, uno::RuntimeException)
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir 	m_pFileStream->Revert_Impl();
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir // ========================================================================
76*cdf0e10cSrcweir struct TTFileStreamData_Impl
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir 	uno::Reference< ucb::XSimpleFileAccess > m_xFileAccess;
79*cdf0e10cSrcweir 	sal_Bool m_bDelete;
80*cdf0e10cSrcweir 	::rtl::OUString m_aURL;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	// the streams below are not visible from outside so there is no need to remember position
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	// original stream related members
85*cdf0e10cSrcweir 	uno::Reference< io::XStream > m_xOrigStream;
86*cdf0e10cSrcweir 	uno::Reference< io::XTruncate > m_xOrigTruncate;
87*cdf0e10cSrcweir 	uno::Reference< io::XSeekable > m_xOrigSeekable;
88*cdf0e10cSrcweir 	uno::Reference< io::XInputStream > m_xOrigInStream;
89*cdf0e10cSrcweir 	uno::Reference< io::XOutputStream > m_xOrigOutStream;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 	// temporary stream related members
92*cdf0e10cSrcweir 	uno::Reference< io::XStream > m_xTempStream;
93*cdf0e10cSrcweir 	uno::Reference< io::XTruncate > m_xTempTruncate;
94*cdf0e10cSrcweir 	uno::Reference< io::XSeekable > m_xTempSeekable;
95*cdf0e10cSrcweir 	uno::Reference< io::XInputStream > m_xTempInStream;
96*cdf0e10cSrcweir 	uno::Reference< io::XOutputStream > m_xTempOutStream;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	sal_Bool m_bInOpen;
99*cdf0e10cSrcweir 	sal_Bool m_bOutOpen;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	sal_Bool m_bTransacted;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 	TTFileStreamData_Impl(
105*cdf0e10cSrcweir 			const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
106*cdf0e10cSrcweir 			sal_Bool bDelete,
107*cdf0e10cSrcweir 			const ::rtl::OUString& aURL,
108*cdf0e10cSrcweir 			const uno::Reference< io::XStream >& xOrigStream,
109*cdf0e10cSrcweir 			const uno::Reference< io::XTruncate >& xOrigTruncate,
110*cdf0e10cSrcweir 			const uno::Reference< io::XSeekable >& xOrigSeekable,
111*cdf0e10cSrcweir 			const uno::Reference< io::XInputStream >& xOrigInStream,
112*cdf0e10cSrcweir 			const uno::Reference< io::XOutputStream >& xOrigOutStream,
113*cdf0e10cSrcweir 			const uno::Reference< io::XStream >& xTempStream,
114*cdf0e10cSrcweir 			const uno::Reference< io::XTruncate >& xTempTruncate,
115*cdf0e10cSrcweir 			const uno::Reference< io::XSeekable >& xTempSeekable,
116*cdf0e10cSrcweir 			const uno::Reference< io::XInputStream >& xTempInStream,
117*cdf0e10cSrcweir 			const uno::Reference< io::XOutputStream >& xTempOutStream )
118*cdf0e10cSrcweir 	: m_xFileAccess( xFileAccess )
119*cdf0e10cSrcweir 	, m_bDelete( bDelete )
120*cdf0e10cSrcweir 	, m_aURL( aURL )
121*cdf0e10cSrcweir 	, m_xOrigStream( xOrigStream )
122*cdf0e10cSrcweir 	, m_xOrigTruncate( xOrigTruncate )
123*cdf0e10cSrcweir 	, m_xOrigSeekable( xOrigSeekable )
124*cdf0e10cSrcweir 	, m_xOrigInStream( xOrigInStream )
125*cdf0e10cSrcweir 	, m_xOrigOutStream( xOrigOutStream )
126*cdf0e10cSrcweir 	, m_xTempStream( xTempStream )
127*cdf0e10cSrcweir 	, m_xTempTruncate( xTempTruncate )
128*cdf0e10cSrcweir 	, m_xTempSeekable( xTempSeekable )
129*cdf0e10cSrcweir 	, m_xTempInStream( xTempInStream )
130*cdf0e10cSrcweir 	, m_xTempOutStream( xTempOutStream )
131*cdf0e10cSrcweir 	, m_bInOpen( sal_False )
132*cdf0e10cSrcweir 	, m_bOutOpen( sal_False )
133*cdf0e10cSrcweir 	, m_bTransacted( sal_True )
134*cdf0e10cSrcweir 	{}
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 	void NoTransaction()
137*cdf0e10cSrcweir 	{
138*cdf0e10cSrcweir 		m_bDelete = sal_False;
139*cdf0e10cSrcweir 		m_bTransacted = sal_False;
140*cdf0e10cSrcweir 		m_xTempStream = uno::Reference< io::XStream >();
141*cdf0e10cSrcweir 		m_xTempTruncate = uno::Reference< io::XTruncate >();
142*cdf0e10cSrcweir 		m_xTempSeekable = uno::Reference< io::XSeekable >();
143*cdf0e10cSrcweir 		m_xTempInStream = uno::Reference< io::XInputStream >();
144*cdf0e10cSrcweir 		m_xTempOutStream = uno::Reference< io::XOutputStream >();
145*cdf0e10cSrcweir 	}
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 	void FreeOriginal()
148*cdf0e10cSrcweir 	{
149*cdf0e10cSrcweir 		m_bDelete = sal_False;
150*cdf0e10cSrcweir 		m_bTransacted = sal_False;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 		m_xOrigStream = m_xTempStream;
153*cdf0e10cSrcweir 		m_xTempStream = uno::Reference< io::XStream >();
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 		m_xOrigTruncate = m_xTempTruncate;
156*cdf0e10cSrcweir 		m_xTempTruncate = uno::Reference< io::XTruncate >();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 		m_xOrigSeekable = m_xTempSeekable;
159*cdf0e10cSrcweir 		m_xTempSeekable = uno::Reference< io::XSeekable >();
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 		m_xOrigInStream = m_xTempInStream;
162*cdf0e10cSrcweir 		m_xTempInStream = uno::Reference< io::XInputStream >();
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 		m_xOrigOutStream = m_xTempOutStream;
165*cdf0e10cSrcweir 		m_xTempOutStream = uno::Reference< io::XOutputStream >();
166*cdf0e10cSrcweir 	}
167*cdf0e10cSrcweir };
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir // ========================================================================
170*cdf0e10cSrcweir // ------------------------------------------------------------------------
171*cdf0e10cSrcweir OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
172*cdf0e10cSrcweir 		const ::rtl::OUString& aURL,
173*cdf0e10cSrcweir 		const uno::Reference< lang::XMultiServiceFactory >& xFactory )
174*cdf0e10cSrcweir : m_pStreamData( NULL )
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir 	uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess(
177*cdf0e10cSrcweir 		xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ),
178*cdf0e10cSrcweir 		uno::UNO_QUERY_THROW );
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	CommonInit_Impl( aURL, xSimpleFileAccess, xFactory, sal_False );
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir // ------------------------------------------------------------------------
184*cdf0e10cSrcweir OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
185*cdf0e10cSrcweir 		const ::rtl::OUString& aURL,
186*cdf0e10cSrcweir 		const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
187*cdf0e10cSrcweir 		const uno::Reference< lang::XMultiServiceFactory >& xFactory )
188*cdf0e10cSrcweir : m_pStreamData( NULL )
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir 	CommonInit_Impl( aURL, xFileAccess, xFactory, sal_False );
191*cdf0e10cSrcweir }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir // ------------------------------------------------------------------------
194*cdf0e10cSrcweir OTruncatedTransactedFileStream::OTruncatedTransactedFileStream(
195*cdf0e10cSrcweir 		const ::rtl::OUString& aURL,
196*cdf0e10cSrcweir 		const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
197*cdf0e10cSrcweir 		const uno::Reference< lang::XMultiServiceFactory >& xFactory,
198*cdf0e10cSrcweir 		sal_Bool bDeleteIfNotCommited )
199*cdf0e10cSrcweir : m_pStreamData( NULL )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir 	CommonInit_Impl( aURL, xFileAccess, xFactory, sal_True );
202*cdf0e10cSrcweir 	if ( m_pStreamData )
203*cdf0e10cSrcweir 		m_pStreamData->m_bDelete = bDeleteIfNotCommited;
204*cdf0e10cSrcweir }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir // ------------------------------------------------------------------------
207*cdf0e10cSrcweir OTruncatedTransactedFileStream::~OTruncatedTransactedFileStream()
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir 	CloseAll_Impl();
210*cdf0e10cSrcweir }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir // ------------------------------------------------------------------------
213*cdf0e10cSrcweir void OTruncatedTransactedFileStream::CloseAll_Impl()
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 	if ( m_pStreamData )
218*cdf0e10cSrcweir 	{
219*cdf0e10cSrcweir 		sal_Bool bDelete = m_pStreamData->m_bDelete;
220*cdf0e10cSrcweir 		::rtl::OUString aURL = m_pStreamData->m_aURL;
221*cdf0e10cSrcweir 		uno::Reference< ucb::XSimpleFileAccess > xFileAccess = m_pStreamData->m_xFileAccess;
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 		delete m_pStreamData;
224*cdf0e10cSrcweir 		m_pStreamData = NULL;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 		if ( bDelete && xFileAccess.is() && aURL.getLength() )
227*cdf0e10cSrcweir 		{
228*cdf0e10cSrcweir 			// delete the file
229*cdf0e10cSrcweir 			try
230*cdf0e10cSrcweir 			{
231*cdf0e10cSrcweir 				xFileAccess->kill( aURL );
232*cdf0e10cSrcweir 			} catch( uno::Exception& )
233*cdf0e10cSrcweir 			{
234*cdf0e10cSrcweir 				OSL_ENSURE( sal_False, "Could not remove the file!" );
235*cdf0e10cSrcweir 			}
236*cdf0e10cSrcweir 		}
237*cdf0e10cSrcweir 	}
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir // ------------------------------------------------------------------------
241*cdf0e10cSrcweir void OTruncatedTransactedFileStream::CommonInit_Impl(
242*cdf0e10cSrcweir 		const ::rtl::OUString& aURL,
243*cdf0e10cSrcweir 		const uno::Reference< ucb::XSimpleFileAccess >& xFileAccess,
244*cdf0e10cSrcweir 		const uno::Reference< lang::XMultiServiceFactory >& xFactory,
245*cdf0e10cSrcweir 		sal_Bool bDeleteOptionIsProvided )
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir 	sal_Bool bDelete = sal_False;
248*cdf0e10cSrcweir 	if ( !bDeleteOptionIsProvided )
249*cdf0e10cSrcweir 		bDelete = !xFileAccess->exists( aURL );
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	uno::Reference< io::XStream > xOrigStream = xFileAccess->openFileReadWrite( aURL );
252*cdf0e10cSrcweir 	uno::Reference< io::XTruncate > xOrigTruncate( xOrigStream, uno::UNO_QUERY_THROW );
253*cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xOrigSeekable( xOrigStream, uno::UNO_QUERY_THROW );
254*cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xOrigInStream = xOrigStream->getInputStream();
255*cdf0e10cSrcweir 	uno::Reference< io::XOutputStream > xOrigOutStream = xOrigStream->getOutputStream();
256*cdf0e10cSrcweir 	if ( !xOrigInStream.is() || !xOrigOutStream.is() )
257*cdf0e10cSrcweir 		throw uno::RuntimeException();
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 	// temporary stream related members
260*cdf0e10cSrcweir 	uno::Reference< io::XStream > xTempStream( xFactory->createInstance(
261*cdf0e10cSrcweir 		::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ),
262*cdf0e10cSrcweir 		uno::UNO_QUERY_THROW );
263*cdf0e10cSrcweir 	uno::Reference< io::XTruncate > xTempTruncate( xTempStream, uno::UNO_QUERY_THROW );
264*cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xTempSeekable( xTempStream, uno::UNO_QUERY_THROW );
265*cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xTempInStream = xTempStream->getInputStream();
266*cdf0e10cSrcweir 	uno::Reference< io::XOutputStream > xTempOutStream = xTempStream->getOutputStream();
267*cdf0e10cSrcweir 	if ( !xTempInStream.is() || !xTempOutStream.is() )
268*cdf0e10cSrcweir 		throw uno::RuntimeException();
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 	m_pStreamData = new TTFileStreamData_Impl( xFileAccess, bDelete, aURL,
271*cdf0e10cSrcweir 											xOrigStream, xOrigTruncate, xOrigSeekable, xOrigInStream, xOrigOutStream,
272*cdf0e10cSrcweir 											xTempStream, xTempTruncate, xTempSeekable, xTempInStream, xTempOutStream );
273*cdf0e10cSrcweir }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir // ------------------------------------------------------------------------
276*cdf0e10cSrcweir void OTruncatedTransactedFileStream::Commit_Impl()
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 	if ( !m_pStreamData )
281*cdf0e10cSrcweir 		throw io::NotConnectedException();
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
284*cdf0e10cSrcweir 	{
285*cdf0e10cSrcweir 		sal_Int64 nPos = m_pStreamData->m_xTempSeekable->getPosition();
286*cdf0e10cSrcweir 		m_pStreamData->m_xTempSeekable->seek( 0 );
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 		// after the following step fails the information might be lost, throw an exception with URL of temporary file
289*cdf0e10cSrcweir 		try
290*cdf0e10cSrcweir 		{
291*cdf0e10cSrcweir 			m_pStreamData->m_xOrigTruncate->truncate();
292*cdf0e10cSrcweir 			OStorageHelper::CopyInputToOutput( m_pStreamData->m_xTempInStream, m_pStreamData->m_xOrigOutStream );
293*cdf0e10cSrcweir 			m_pStreamData->m_xOrigOutStream->flush();
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 			// in case the stream is based on a file it will implement the following interface
296*cdf0e10cSrcweir 			// the call should be used to be sure that the contents are written to the file system
297*cdf0e10cSrcweir 			uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( m_pStreamData->m_xOrigOutStream, uno::UNO_QUERY );
298*cdf0e10cSrcweir 			if ( asyncOutputMonitor.is() )
299*cdf0e10cSrcweir 				asyncOutputMonitor->waitForCompletion();
300*cdf0e10cSrcweir 		}
301*cdf0e10cSrcweir 		catch( uno::Exception& )
302*cdf0e10cSrcweir 		{
303*cdf0e10cSrcweir 			::rtl::OUString aTempURL;
304*cdf0e10cSrcweir 			try {
305*cdf0e10cSrcweir 				uno::Reference< beans::XPropertySet > xTempFile( m_pStreamData->m_xTempStream, uno::UNO_QUERY_THROW );
306*cdf0e10cSrcweir 				uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) );
307*cdf0e10cSrcweir 				aUrl >>= aTempURL;
308*cdf0e10cSrcweir 				xTempFile->setPropertyValue( ::rtl::OUString::createFromAscii( "RemoveFile" ),
309*cdf0e10cSrcweir 									 		uno::makeAny( sal_False ) );
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 				m_pStreamData->m_xTempSeekable->seek( nPos );
312*cdf0e10cSrcweir 			}
313*cdf0e10cSrcweir 			catch( uno::Exception& )
314*cdf0e10cSrcweir 			{
315*cdf0e10cSrcweir 				OSL_ENSURE( sal_False, "These calls are pretty simple, they should not fail!\n" );
316*cdf0e10cSrcweir 			}
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 			m_pStreamData->FreeOriginal();
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 			::rtl::OUString aErrTxt( RTL_CONSTASCII_USTRINGPARAM ( "Writing file failed!" ) );
321*cdf0e10cSrcweir 			embed::UseBackupException aException( aErrTxt, uno::Reference< uno::XInterface >(), aTempURL );
322*cdf0e10cSrcweir 			throw lang::WrappedTargetException( aErrTxt,
323*cdf0e10cSrcweir 												static_cast < OWeakObject * > ( this ),
324*cdf0e10cSrcweir 												uno::makeAny ( aException ) );
325*cdf0e10cSrcweir 		}
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 		m_pStreamData->m_xOrigSeekable->seek( nPos );
328*cdf0e10cSrcweir 		m_pStreamData->NoTransaction();
329*cdf0e10cSrcweir 	}
330*cdf0e10cSrcweir 	else
331*cdf0e10cSrcweir 		throw io::NotConnectedException();
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir // ------------------------------------------------------------------------
335*cdf0e10cSrcweir void OTruncatedTransactedFileStream::Revert_Impl()
336*cdf0e10cSrcweir {
337*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 	if ( !m_pStreamData )
340*cdf0e10cSrcweir 		throw io::NotConnectedException();
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
343*cdf0e10cSrcweir 		m_pStreamData->m_xTempTruncate->truncate();
344*cdf0e10cSrcweir 	else
345*cdf0e10cSrcweir 		throw io::NotConnectedException();
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir // com::sun::star::io::XStream
349*cdf0e10cSrcweir // ------------------------------------------------------------------------
350*cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL OTruncatedTransactedFileStream::getInputStream(  )
351*cdf0e10cSrcweir 	throw (uno::RuntimeException)
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir     if ( m_pStreamData )
356*cdf0e10cSrcweir         m_pStreamData->m_bInOpen = sal_True;
357*cdf0e10cSrcweir 	return static_cast< io::XInputStream* >( this );
358*cdf0e10cSrcweir }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir // ------------------------------------------------------------------------
362*cdf0e10cSrcweir uno::Reference< io::XOutputStream > SAL_CALL OTruncatedTransactedFileStream::getOutputStream(  )
363*cdf0e10cSrcweir 	throw (uno::RuntimeException)
364*cdf0e10cSrcweir {
365*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir     if ( m_pStreamData )
368*cdf0e10cSrcweir         m_pStreamData->m_bOutOpen = sal_True;
369*cdf0e10cSrcweir 	return static_cast< io::XOutputStream* >( this );
370*cdf0e10cSrcweir }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir // com::sun::star::io::XInputStream
375*cdf0e10cSrcweir // ------------------------------------------------------------------------
376*cdf0e10cSrcweir ::sal_Int32 SAL_CALL OTruncatedTransactedFileStream::readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead )
377*cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
378*cdf0e10cSrcweir {
379*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 	if ( !m_pStreamData )
382*cdf0e10cSrcweir 		throw io::NotConnectedException();
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
385*cdf0e10cSrcweir 	{
386*cdf0e10cSrcweir 		// temporary stream data should be provided
387*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempInStream.is() )
388*cdf0e10cSrcweir 			throw uno::RuntimeException();
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir 		return m_pStreamData->m_xTempInStream->readBytes( aData, nBytesToRead );
391*cdf0e10cSrcweir 	}
392*cdf0e10cSrcweir 	else
393*cdf0e10cSrcweir 	{
394*cdf0e10cSrcweir 		// the original stream data should be provided
395*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigInStream.is() )
396*cdf0e10cSrcweir 			throw uno::RuntimeException();
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir 		return m_pStreamData->m_xOrigInStream->readBytes( aData, nBytesToRead );
399*cdf0e10cSrcweir 	}
400*cdf0e10cSrcweir }
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir // ------------------------------------------------------------------------
404*cdf0e10cSrcweir ::sal_Int32 SAL_CALL OTruncatedTransactedFileStream::readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead )
405*cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
406*cdf0e10cSrcweir {
407*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 	if ( !m_pStreamData )
410*cdf0e10cSrcweir 		throw io::NotConnectedException();
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
413*cdf0e10cSrcweir 	{
414*cdf0e10cSrcweir 		// temporary stream data should be provided
415*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempInStream.is() )
416*cdf0e10cSrcweir 			throw uno::RuntimeException();
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 		return m_pStreamData->m_xTempInStream->readSomeBytes( aData, nMaxBytesToRead );
419*cdf0e10cSrcweir 	}
420*cdf0e10cSrcweir 	else
421*cdf0e10cSrcweir 	{
422*cdf0e10cSrcweir 		// the original stream data should be provided
423*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigInStream.is() )
424*cdf0e10cSrcweir 			throw uno::RuntimeException();
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir 		return m_pStreamData->m_xOrigInStream->readSomeBytes( aData, nMaxBytesToRead );
427*cdf0e10cSrcweir 	}
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir // ------------------------------------------------------------------------
431*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::skipBytes( ::sal_Int32 nBytesToSkip )
432*cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 	if ( !m_pStreamData )
437*cdf0e10cSrcweir 		throw io::NotConnectedException();
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
440*cdf0e10cSrcweir 	{
441*cdf0e10cSrcweir 		// temporary stream data should be provided
442*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempInStream.is() )
443*cdf0e10cSrcweir 			throw uno::RuntimeException();
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 		m_pStreamData->m_xTempInStream->skipBytes( nBytesToSkip );
446*cdf0e10cSrcweir 	}
447*cdf0e10cSrcweir 	else
448*cdf0e10cSrcweir 	{
449*cdf0e10cSrcweir 		// the original stream data should be provided
450*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigInStream.is() )
451*cdf0e10cSrcweir 			throw uno::RuntimeException();
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir 		m_pStreamData->m_xOrigInStream->skipBytes( nBytesToSkip );
454*cdf0e10cSrcweir 	}
455*cdf0e10cSrcweir }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir // ------------------------------------------------------------------------
459*cdf0e10cSrcweir ::sal_Int32 SAL_CALL OTruncatedTransactedFileStream::available(  )
460*cdf0e10cSrcweir 	throw (io::NotConnectedException, io::IOException, uno::RuntimeException)
461*cdf0e10cSrcweir {
462*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir 	if ( !m_pStreamData )
465*cdf0e10cSrcweir 		throw io::NotConnectedException();
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
468*cdf0e10cSrcweir 	{
469*cdf0e10cSrcweir 		// temporary stream data should be provided
470*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempInStream.is() )
471*cdf0e10cSrcweir 			throw uno::RuntimeException();
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir 		return m_pStreamData->m_xTempInStream->available();
474*cdf0e10cSrcweir 	}
475*cdf0e10cSrcweir 	else
476*cdf0e10cSrcweir 	{
477*cdf0e10cSrcweir 		// the original stream data should be provided
478*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigInStream.is() )
479*cdf0e10cSrcweir 			throw uno::RuntimeException();
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 		return m_pStreamData->m_xOrigInStream->available();
482*cdf0e10cSrcweir 	}
483*cdf0e10cSrcweir }
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir // ------------------------------------------------------------------------
487*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::closeInput()
488*cdf0e10cSrcweir 	throw (io::NotConnectedException, io::IOException, uno::RuntimeException)
489*cdf0e10cSrcweir {
490*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 	if ( !m_pStreamData )
493*cdf0e10cSrcweir 		throw io::NotConnectedException();
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 	m_pStreamData->m_bInOpen = sal_False;
496*cdf0e10cSrcweir 	if ( !m_pStreamData->m_bOutOpen )
497*cdf0e10cSrcweir 		CloseAll_Impl();
498*cdf0e10cSrcweir }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir // com::sun::star::io::XOutputStream
503*cdf0e10cSrcweir // ------------------------------------------------------------------------
504*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::writeBytes( const uno::Sequence< ::sal_Int8 >& aData )
505*cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
506*cdf0e10cSrcweir {
507*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir 	if ( !m_pStreamData )
510*cdf0e10cSrcweir 		throw io::NotConnectedException();
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
513*cdf0e10cSrcweir 	{
514*cdf0e10cSrcweir 		// temporary stream data should be provided
515*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempOutStream.is() )
516*cdf0e10cSrcweir 			throw uno::RuntimeException();
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir 		m_pStreamData->m_xTempOutStream->writeBytes( aData );
519*cdf0e10cSrcweir 	}
520*cdf0e10cSrcweir 	else
521*cdf0e10cSrcweir 	{
522*cdf0e10cSrcweir 		// the original stream data should be provided
523*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigOutStream.is() )
524*cdf0e10cSrcweir 			throw uno::RuntimeException();
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir 		m_pStreamData->m_xOrigOutStream->writeBytes( aData );
527*cdf0e10cSrcweir 	}
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir // ------------------------------------------------------------------------
532*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::flush(  )
533*cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
534*cdf0e10cSrcweir {
535*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir 	if ( !m_pStreamData )
538*cdf0e10cSrcweir 	{
539*cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "flush() call on closed stream!\n" );
540*cdf0e10cSrcweir 		return;
541*cdf0e10cSrcweir 		// in future throw exception, for now some code might call flush() on closed stream
542*cdf0e10cSrcweir 		// since file ucp implementation allows it
543*cdf0e10cSrcweir 		// throw io::NotConnectedException();
544*cdf0e10cSrcweir 	}
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
547*cdf0e10cSrcweir 	{
548*cdf0e10cSrcweir 		// temporary stream data should be provided
549*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempOutStream.is() )
550*cdf0e10cSrcweir 			throw uno::RuntimeException();
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir 		m_pStreamData->m_xTempOutStream->flush();
553*cdf0e10cSrcweir 	}
554*cdf0e10cSrcweir 	else
555*cdf0e10cSrcweir 	{
556*cdf0e10cSrcweir 		// the original stream data should be provided
557*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigOutStream.is() )
558*cdf0e10cSrcweir 			throw uno::RuntimeException();
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 		m_pStreamData->m_xOrigOutStream->flush();
561*cdf0e10cSrcweir 	}
562*cdf0e10cSrcweir }
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir // ------------------------------------------------------------------------
566*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::closeOutput(  )
567*cdf0e10cSrcweir 	throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException)
568*cdf0e10cSrcweir {
569*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 	if ( !m_pStreamData )
572*cdf0e10cSrcweir 		throw io::NotConnectedException();
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 	m_pStreamData->m_bOutOpen = sal_False;
575*cdf0e10cSrcweir 	if ( !m_pStreamData->m_bInOpen )
576*cdf0e10cSrcweir 		CloseAll_Impl();
577*cdf0e10cSrcweir }
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir // com::sun::star::io::XTruncate
582*cdf0e10cSrcweir // ------------------------------------------------------------------------
583*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::truncate(  )
584*cdf0e10cSrcweir 	throw (io::IOException, uno::RuntimeException)
585*cdf0e10cSrcweir {
586*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir 	if ( !m_pStreamData )
589*cdf0e10cSrcweir 		throw io::NotConnectedException();
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
592*cdf0e10cSrcweir 	{
593*cdf0e10cSrcweir 		// temporary stream data should be provided
594*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempTruncate.is() )
595*cdf0e10cSrcweir 			throw uno::RuntimeException();
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir 		m_pStreamData->m_xTempTruncate->truncate();
598*cdf0e10cSrcweir 	}
599*cdf0e10cSrcweir 	else
600*cdf0e10cSrcweir 	{
601*cdf0e10cSrcweir 		// the original stream data should be provided
602*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigTruncate.is() )
603*cdf0e10cSrcweir 			throw uno::RuntimeException();
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir 		m_pStreamData->m_xOrigTruncate->truncate();
606*cdf0e10cSrcweir 	}
607*cdf0e10cSrcweir }
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir // com::sun::star::io::XSeekable
612*cdf0e10cSrcweir // ------------------------------------------------------------------------
613*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::seek( ::sal_Int64 location )
614*cdf0e10cSrcweir 	throw (lang::IllegalArgumentException, io::IOException, uno::RuntimeException)
615*cdf0e10cSrcweir {
616*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir 	if ( !m_pStreamData )
619*cdf0e10cSrcweir 		throw io::NotConnectedException();
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
622*cdf0e10cSrcweir 	{
623*cdf0e10cSrcweir 		// temporary stream data should be provided
624*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempSeekable.is() )
625*cdf0e10cSrcweir 			throw uno::RuntimeException();
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir 		m_pStreamData->m_xTempSeekable->seek( location );
628*cdf0e10cSrcweir 	}
629*cdf0e10cSrcweir 	else
630*cdf0e10cSrcweir 	{
631*cdf0e10cSrcweir 		// the original stream data should be provided
632*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigSeekable.is() )
633*cdf0e10cSrcweir 			throw uno::RuntimeException();
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir 		m_pStreamData->m_xOrigSeekable->seek( location );
636*cdf0e10cSrcweir 	}
637*cdf0e10cSrcweir }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir // ------------------------------------------------------------------------
641*cdf0e10cSrcweir ::sal_Int64 SAL_CALL OTruncatedTransactedFileStream::getPosition(  )
642*cdf0e10cSrcweir 	throw (io::IOException, uno::RuntimeException)
643*cdf0e10cSrcweir {
644*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir 	if ( !m_pStreamData )
647*cdf0e10cSrcweir 		throw io::NotConnectedException();
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
650*cdf0e10cSrcweir 	{
651*cdf0e10cSrcweir 		// temporary stream data should be provided
652*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempSeekable.is() )
653*cdf0e10cSrcweir 			throw uno::RuntimeException();
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir 		return m_pStreamData->m_xTempSeekable->getPosition();
656*cdf0e10cSrcweir 	}
657*cdf0e10cSrcweir 	else
658*cdf0e10cSrcweir 	{
659*cdf0e10cSrcweir 		// the original stream data should be provided
660*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigSeekable.is() )
661*cdf0e10cSrcweir 			throw uno::RuntimeException();
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 		return m_pStreamData->m_xOrigSeekable->getPosition();
664*cdf0e10cSrcweir 	}
665*cdf0e10cSrcweir }
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir // ------------------------------------------------------------------------
669*cdf0e10cSrcweir ::sal_Int64 SAL_CALL OTruncatedTransactedFileStream::getLength(  )
670*cdf0e10cSrcweir 	throw (io::IOException, uno::RuntimeException)
671*cdf0e10cSrcweir {
672*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir 	if ( !m_pStreamData )
675*cdf0e10cSrcweir 		throw io::NotConnectedException();
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir 	if ( m_pStreamData->m_bTransacted )
678*cdf0e10cSrcweir 	{
679*cdf0e10cSrcweir 		// temporary stream data should be provided
680*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xTempSeekable.is() )
681*cdf0e10cSrcweir 			throw uno::RuntimeException();
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir 		return m_pStreamData->m_xTempSeekable->getLength();
684*cdf0e10cSrcweir 	}
685*cdf0e10cSrcweir 	else
686*cdf0e10cSrcweir 	{
687*cdf0e10cSrcweir 		// the original stream data should be provided
688*cdf0e10cSrcweir 		if ( !m_pStreamData->m_xOrigSeekable.is() )
689*cdf0e10cSrcweir 			throw uno::RuntimeException();
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir 		return m_pStreamData->m_xOrigSeekable->getLength();
692*cdf0e10cSrcweir 	}
693*cdf0e10cSrcweir }
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir // com::sun::star::beans::XPropertySetInfo
696*cdf0e10cSrcweir // ------------------------------------------------------------------------
697*cdf0e10cSrcweir uno::Sequence< beans::Property > SAL_CALL OTruncatedTransactedFileStream::getProperties()
698*cdf0e10cSrcweir 	throw (uno::RuntimeException)
699*cdf0e10cSrcweir {
700*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 	uno::Sequence< beans::Property > aProps( 1 );
703*cdf0e10cSrcweir 	aProps[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
704*cdf0e10cSrcweir 	aProps[0].Type = getCppuType( static_cast< uno::Reference< beans::XPropertySet >* >( NULL ) );
705*cdf0e10cSrcweir 	aProps[0].Attributes = beans::PropertyAttribute::TRANSIENT | beans::PropertyAttribute::READONLY;
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 	return aProps;
708*cdf0e10cSrcweir }
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir // ------------------------------------------------------------------------
712*cdf0e10cSrcweir beans::Property SAL_CALL OTruncatedTransactedFileStream::getPropertyByName( const ::rtl::OUString& aName )
713*cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, uno::RuntimeException)
714*cdf0e10cSrcweir {
715*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir 	::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir 	if ( !aName.equals( aTransactionPropName ) )
720*cdf0e10cSrcweir 		throw beans::UnknownPropertyException();
721*cdf0e10cSrcweir 
722*cdf0e10cSrcweir 	beans::Property aProp;
723*cdf0e10cSrcweir 	aProp.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
724*cdf0e10cSrcweir 	aProp.Type = getCppuType( static_cast< uno::Reference< beans::XPropertySet >* >( NULL ) );
725*cdf0e10cSrcweir 	aProp.Attributes = beans::PropertyAttribute::TRANSIENT | beans::PropertyAttribute::READONLY;
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir 	return aProp;
728*cdf0e10cSrcweir }
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir // ------------------------------------------------------------------------
732*cdf0e10cSrcweir ::sal_Bool SAL_CALL OTruncatedTransactedFileStream::hasPropertyByName( const ::rtl::OUString& Name )
733*cdf0e10cSrcweir 	throw (uno::RuntimeException)
734*cdf0e10cSrcweir {
735*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir 	::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
738*cdf0e10cSrcweir 	return ( Name.equals( aTransactionPropName ) );
739*cdf0e10cSrcweir }
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir // com::sun::star::beans::XPropertySet
744*cdf0e10cSrcweir // ------------------------------------------------------------------------
745*cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL OTruncatedTransactedFileStream::getPropertySetInfo()
746*cdf0e10cSrcweir 	throw (uno::RuntimeException)
747*cdf0e10cSrcweir {
748*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir 	return static_cast< beans::XPropertySetInfo* >( this );
751*cdf0e10cSrcweir }
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir // ------------------------------------------------------------------------
755*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& )
756*cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
757*cdf0e10cSrcweir {
758*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir 	::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
761*cdf0e10cSrcweir 	if ( aPropertyName.equals( aTransactionPropName ) )
762*cdf0e10cSrcweir 		throw beans::PropertyVetoException();
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir 	throw beans::UnknownPropertyException();
765*cdf0e10cSrcweir }
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir // ------------------------------------------------------------------------
769*cdf0e10cSrcweir uno::Any SAL_CALL OTruncatedTransactedFileStream::getPropertyValue( const ::rtl::OUString& PropertyName )
770*cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
771*cdf0e10cSrcweir {
772*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir 	if ( !m_pStreamData )
775*cdf0e10cSrcweir 		throw io::NotConnectedException();
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir 	::rtl::OUString aTransactionPropName( RTL_CONSTASCII_USTRINGPARAM( "TransactionSupport" ) );
778*cdf0e10cSrcweir 	if ( PropertyName.equals( aTransactionPropName ) )
779*cdf0e10cSrcweir 	{
780*cdf0e10cSrcweir 		uno::Reference< embed::XTransactedObject > xObj;
781*cdf0e10cSrcweir 		if ( m_pStreamData->m_bTransacted )
782*cdf0e10cSrcweir 			xObj = static_cast< embed::XTransactedObject* >( new OTransactionHelper( this ) );
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir 		return uno::makeAny( xObj );
785*cdf0e10cSrcweir 	}
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir 	throw beans::UnknownPropertyException();
788*cdf0e10cSrcweir }
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir // ------------------------------------------------------------------------
792*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::addPropertyChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
793*cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
794*cdf0e10cSrcweir {
795*cdf0e10cSrcweir 	// not implemented
796*cdf0e10cSrcweir }
797*cdf0e10cSrcweir 
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir // ------------------------------------------------------------------------
800*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::removePropertyChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
801*cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
802*cdf0e10cSrcweir {
803*cdf0e10cSrcweir 	// not implemented
804*cdf0e10cSrcweir }
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir 
807*cdf0e10cSrcweir // ------------------------------------------------------------------------
808*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::addVetoableChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
809*cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
810*cdf0e10cSrcweir {
811*cdf0e10cSrcweir 	// not implemented
812*cdf0e10cSrcweir }
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir // ------------------------------------------------------------------------
816*cdf0e10cSrcweir void SAL_CALL OTruncatedTransactedFileStream::removeVetoableChangeListener( const ::rtl::OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
817*cdf0e10cSrcweir 	throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
818*cdf0e10cSrcweir {
819*cdf0e10cSrcweir 	// not implemented
820*cdf0e10cSrcweir }
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir } // namespace comphelper
824*cdf0e10cSrcweir 
825