From 93f166da84a53ffe3ae4a83d7800425bfa8e5126 Mon Sep 17 00:00:00 2001 From: Mikhail Voitenko Date: Thu, 20 Nov 2003 16:02:23 +0000 Subject: [PATCH] #112923# do not close stream untill it is needed --- .../source/commonembedding/miscobj.cxx | 21 +++++++++- embeddedobj/source/inc/oleembobj.hxx | 7 +++- embeddedobj/source/msole/olemisc.cxx | 29 +++++++++++--- embeddedobj/source/msole/olepersist.cxx | 39 +++++++++++++------ 4 files changed, 75 insertions(+), 21 deletions(-) diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx index 15f9b0edad48..254174936b8f 100644 --- a/embeddedobj/source/commonembedding/miscobj.cxx +++ b/embeddedobj/source/commonembedding/miscobj.cxx @@ -2,9 +2,9 @@ * * $RCSfile: miscobj.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: mav $ $Date: 2003-11-18 12:47:06 $ + * last change: $Author: mav $ $Date: 2003-11-20 17:02:21 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -467,6 +467,23 @@ void SAL_CALL OCommonEmbeddedObject::close( sal_Bool bDeliverOwnership ) m_pDocHolder = NULL; } + // TODO: for now the storage will be disposed by the object, but after the document + // will use the storage, the storage will be disposed by the document and recreated by the object + if ( m_xObjectStorage.is() ) + { + uno::Reference< lang::XComponent > xComp( m_xObjectStorage, uno::UNO_QUERY ); + OSL_ENSURE( xComp.is(), "Storage does not support XComponent!\n" ); + + if ( xComp.is() ) + { + try { + xComp->dispose(); + } catch ( uno::Exception& ) {} + } + + m_xObjectStorage = uno::Reference< embed::XStorage >(); + } + m_bClosed = sal_True; // the closing succeeded } diff --git a/embeddedobj/source/inc/oleembobj.hxx b/embeddedobj/source/inc/oleembobj.hxx index bedbab8e2df2..c38e7fbc7d78 100644 --- a/embeddedobj/source/inc/oleembobj.hxx +++ b/embeddedobj/source/inc/oleembobj.hxx @@ -2,9 +2,9 @@ * * $RCSfile: oleembobj.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: mav $ $Date: 2003-11-18 09:03:54 $ + * last change: $Author: mav $ $Date: 2003-11-20 17:02:21 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -165,6 +165,9 @@ class OleEmbeddedObject : public ::cppu::WeakImplHelper8 ::rtl::OUString m_aLinkURL; // ??? protected: + + ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > GetStreamForSaving(); + ::com::sun::star::uno::Sequence< sal_Int32 > GetIntermediateVerbsSequence_Impl( sal_Int32 nNewState ); ::com::sun::star::uno::Sequence< sal_Int32 > GetReachableStatesList_Impl( diff --git a/embeddedobj/source/msole/olemisc.cxx b/embeddedobj/source/msole/olemisc.cxx index a2fe27bc1901..3cf36d8b5b72 100644 --- a/embeddedobj/source/msole/olemisc.cxx +++ b/embeddedobj/source/msole/olemisc.cxx @@ -2,9 +2,9 @@ * * $RCSfile: olemisc.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: mav $ $Date: 2003-11-18 09:03:55 $ + * last change: $Author: mav $ $Date: 2003-11-20 17:02:23 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -66,7 +66,9 @@ #include #endif - +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include +#endif #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_ #include #endif @@ -118,9 +120,10 @@ OleEmbeddedObject::OleEmbeddedObject( const uno::Reference< lang::XMultiServiceF //------------------------------------------------------ OleEmbeddedObject::~OleEmbeddedObject() { - OSL_ENSURE( !m_pInterfaceContainer && !m_pOleComponent, "The object is not closed! DISASTER is possible!" ); + OSL_ENSURE( !m_pInterfaceContainer && !m_pOleComponent && !m_xObjectStream.is(), + "The object is not closed! DISASTER is possible!" ); - if ( m_pOleComponent || m_pInterfaceContainer ) + if ( m_pOleComponent || m_pInterfaceContainer || m_xObjectStream.is() ) { // the component must be cleaned during closing m_refCount++; // to avoid crash @@ -155,6 +158,22 @@ void OleEmbeddedObject::Dispose() m_pOleComponent = NULL; } + if ( m_xObjectStream.is() ) + { + uno::Reference< lang::XComponent > xComp( m_xObjectStream, uno::UNO_QUERY ); + OSL_ENSURE( xComp.is(), "Storage stream doesn't support XComponent!\n" ); + + if ( xComp.is() ) + { + try { + xComp->dispose(); + } catch( uno::Exception& ) {} + } + m_xObjectStream = uno::Reference< io::XStream >(); + } + + m_xParentStorage = uno::Reference< embed::XStorage >(); + m_bDisposed = true; } diff --git a/embeddedobj/source/msole/olepersist.cxx b/embeddedobj/source/msole/olepersist.cxx index 01fa2ea7943a..0ffc954a06a8 100644 --- a/embeddedobj/source/msole/olepersist.cxx +++ b/embeddedobj/source/msole/olepersist.cxx @@ -2,9 +2,9 @@ * * $RCSfile: olepersist.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: mav $ $Date: 2003-11-18 09:03:56 $ + * last change: $Author: mav $ $Date: 2003-11-20 17:02:23 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -94,6 +94,10 @@ #include #endif +#ifndef _COM_SUN_STAR_IO_XTRUNCATE_HPP_ +#include +#endif + #include #include @@ -167,6 +171,25 @@ void OleEmbeddedObject::CreateOleComponent_Impl() OSL_ENSURE( sal_False, "Trying to recreate OLE component!\n" ); } +//------------------------------------------------------ +uno::Reference< io::XOutputStream > OleEmbeddedObject::GetStreamForSaving() +{ + if ( !m_xObjectStream.is() ) + throw uno::RuntimeException(); //TODO: + + uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream(); + if ( !xOutStream.is() ) + throw io::IOException(); //TODO: access denied + + uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY ); + if ( !xTruncate.is() ) + throw uno::RuntimeException(); //TODO: + + xTruncate->truncate(); + + return xOutStream; +} + //------------------------------------------------------ void SAL_CALL OleEmbeddedObject::setPersistentEntry( const uno::Reference< embed::XStorage >& xStorage, @@ -367,21 +390,15 @@ void SAL_CALL OleEmbeddedObject::storeOwn() // in case visual repersentation must be stored also // the procedure should be the same as for embedded objects - uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream(); - if ( !xOutStream.is() ) - throw io::IOException(); //TODO: access denied + uno::Reference< io::XOutputStream > xOutStream = GetStreamForSaving(); // should the component detect that it is a link??? m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl ); - xOutStream->closeOutput(); //TODO: allow to reopen the stream object ??? } else { - uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream(); - if ( !xOutStream.is() ) - throw io::IOException(); //TODO: access denied + uno::Reference< io::XOutputStream > xOutStream = GetStreamForSaving(); m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl ); - xOutStream->closeOutput(); //TODO: allow to reopen the stream object ??? } // TODO: @@ -431,7 +448,6 @@ void SAL_CALL OleEmbeddedObject::storeToEntry( const uno::Reference< embed::XSto throw io::IOException(); //TODO: access denied m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl ); - xOutStream->closeOutput(); uno::Reference< lang::XComponent > xComp( xTargetStream, uno::UNO_QUERY ); if ( xComp.is() ) @@ -485,7 +501,6 @@ void SAL_CALL OleEmbeddedObject::storeAsEntry( const uno::Reference< embed::XSto throw io::IOException(); //TODO: access denied m_pOleComponent->StoreObjectToStream( xOutStream, m_bStoreVisRepl ); - xOutStream->closeOutput(); // TODO: allow to reuse the stream try { uno::Reference< lang::XComponent > xComp( xTargetStream, uno::UNO_QUERY );