From 206c70eef30f7b6f538b88f7fb9505f397bef073 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 23 Aug 2012 17:23:26 +0200 Subject: fdo#46808, Adapt TempFile UNO service to new style Change-Id: Ia448d6d74201e2be487c6d8317f94be3745808aa --- package/source/xstor/owriteablestream.cxx | 10 ++++----- package/source/xstor/switchpersistencestream.cxx | 4 +++- package/source/xstor/xfactory.cxx | 8 +++---- package/source/xstor/xstorage.cxx | 9 ++++---- package/source/zippackage/ZipPackage.cxx | 3 ++- package/source/zippackage/ZipPackageStream.cxx | 28 ++++++++++-------------- 6 files changed, 28 insertions(+), 34 deletions(-) (limited to 'package') diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index 25e66390754d..ce8b36e2382b 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -236,11 +237,8 @@ const sal_Int32 n_ConstBufferSize = 32000; ::rtl::OUString aTempURL; uno::Reference < beans::XPropertySet > xTempFile( - xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), - uno::UNO_QUERY ); - - if ( !xTempFile.is() ) - throw uno::RuntimeException(); // TODO + io::TempFile::create(comphelper::ComponentContext(xFactory).getUNOContext()), + uno::UNO_QUERY_THROW ); try { xTempFile->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RemoveFile") ), uno::makeAny( sal_False ) ); @@ -1513,7 +1511,7 @@ void OWriteStream_Impl::CreateReadonlyCopyBasedOnData( const uno::Reference< io: uno::Reference < io::XStream > xTempFile; if ( !xTargetStream.is() ) xTempFile = uno::Reference < io::XStream >( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), + io::TempFile::create(comphelper::ComponentContext(m_xFactory).getUNOContext()), uno::UNO_QUERY ); else xTempFile = xTargetStream; diff --git a/package/source/xstor/switchpersistencestream.cxx b/package/source/xstor/switchpersistencestream.cxx index 41f43f51ec56..359a65a0ac40 100644 --- a/package/source/xstor/switchpersistencestream.cxx +++ b/package/source/xstor/switchpersistencestream.cxx @@ -19,6 +19,8 @@ #include +#include +#include #include #include @@ -174,7 +176,7 @@ void SwitchablePersistenceStream::CopyAndSwitchPersistenceTo( const uno::Referen if ( !xTargetStream.is() ) { xTargetStream = uno::Reference < io::XStream >( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), + io::TempFile::create(comphelper::ComponentContext(m_xFactory).getUNOContext()), uno::UNO_QUERY_THROW ); xTargetSeek = uno::Reference< io::XSeekable >( xTargetStream, uno::UNO_QUERY_THROW ); diff --git a/package/source/xstor/xfactory.cxx b/package/source/xstor/xfactory.cxx index 8012c82072d5..302334646d25 100644 --- a/package/source/xstor/xfactory.cxx +++ b/package/source/xstor/xfactory.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -84,11 +85,8 @@ uno::Reference< uno::XInterface > SAL_CALL OStorageFactory::createInstance() { // TODO: reimplement TempStream service to support XStream interface uno::Reference < io::XStream > xTempStream( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), - uno::UNO_QUERY ); - - if ( !xTempStream.is() ) - throw uno::RuntimeException(); // TODO: + io::TempFile::create(comphelper::ComponentContext(m_xFactory).getUNOContext()), + uno::UNO_QUERY_THROW ); return uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( new OStorage( xTempStream, diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx index d8fade3b2912..9900cbc4dcad 100644 --- a/package/source/xstor/xstorage.cxx +++ b/package/source/xstor/xstorage.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -144,7 +145,7 @@ uno::Reference< io::XInputStream > GetSeekableTempCopy( uno::Reference< io::XInp uno::Reference< lang::XMultiServiceFactory > xFactory ) { uno::Reference < io::XOutputStream > xTempOut( - xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), + io::TempFile::create(comphelper::ComponentContext(xFactory).getUNOContext()), uno::UNO_QUERY ); uno::Reference < io::XInputStream > xTempIn( xTempOut, uno::UNO_QUERY ); @@ -3800,8 +3801,7 @@ uno::Reference< io::XInputStream > SAL_CALL OStorage::getPlainRawStreamElement( throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); uno::Reference < io::XOutputStream > xTempOut( - m_pImpl->GetServiceFactory()->createInstance ( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), + io::TempFile::create(comphelper::ComponentContext(m_pImpl->GetServiceFactory()).getUNOContext()), uno::UNO_QUERY ); xTempIn = uno::Reference < io::XInputStream >( xTempOut, uno::UNO_QUERY ); uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY ); @@ -3913,8 +3913,7 @@ uno::Reference< io::XInputStream > SAL_CALL OStorage::getRawEncrStreamElement( throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); uno::Reference < io::XOutputStream > xTempOut( - m_pImpl->GetServiceFactory()->createInstance ( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), + io::TempFile::create(comphelper::ComponentContext(m_pImpl->GetServiceFactory()).getUNOContext()), uno::UNO_QUERY ); xTempIn = uno::Reference < io::XInputStream >( xTempOut, uno::UNO_QUERY ); uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY ); diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index e6abbea5b4ee..bc941a61b7f3 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1177,7 +1178,7 @@ uno::Reference< io::XInputStream > ZipPackage::writeTempFile() if( bUseTemp ) { // create temporary file - uno::Reference < io::XStream > xTempFile( m_xFactory->createInstance ("com.sun.star.io.TempFile"), UNO_QUERY_THROW ); + uno::Reference < io::XStream > xTempFile( io::TempFile::create(comphelper::ComponentContext(m_xFactory).getUNOContext()), UNO_QUERY_THROW ); xTempOut.set( xTempFile->getOutputStream(), UNO_SET_THROW ); xTempIn.set( xTempFile->getInputStream(), UNO_SET_THROW ); } diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index a8029ff9ec72..5c7feb7645ca 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,7 @@ #include #include "wrapstreamforshare.hxx" +#include #include #include @@ -175,12 +177,10 @@ uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCop // create temporary stream uno::Reference < io::XOutputStream > xTempOut( - m_xFactory->createInstance("com.sun.star.io.TempFile"), - uno::UNO_QUERY ); - uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY ); - uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY ); - if ( !xTempOut.is() || !xTempIn.is() || !xTempSeek.is() ) - throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() ); + io::TempFile::create(comphelper::ComponentContext(m_xFactory).getUNOContext()), + uno::UNO_QUERY_THROW ); + uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY_THROW ); + uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY_THROW ); // copy the raw stream to the temporary file starting from the current position ::comphelper::OStorageHelper::CopyInputToOutput( GetOwnSeekStream(), xTempOut ); @@ -282,10 +282,8 @@ uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( { // create temporary file uno::Reference < io::XStream > xTempStream( - m_xFactory->createInstance ("com.sun.star.io.TempFile"), - uno::UNO_QUERY ); - if ( !xTempStream.is() ) - throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() ); + io::TempFile::create(comphelper::ComponentContext(m_xFactory).getUNOContext()), + uno::UNO_QUERY_THROW ); // create a package based on it ZipPackage* pPackage = new ZipPackage( m_xFactory ); @@ -341,12 +339,10 @@ uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( // create another temporary file uno::Reference < io::XOutputStream > xTempOut( - m_xFactory->createInstance ("com.sun.star.io.TempFile"), - uno::UNO_QUERY ); - uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY ); - uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY ); - if ( !xTempOut.is() || !xTempIn.is() || !xTempSeek.is() ) - throw io::IOException(OSL_LOG_PREFIX, uno::Reference< uno::XInterface >() ); + io::TempFile::create(comphelper::ComponentContext(m_xFactory).getUNOContext()), + uno::UNO_QUERY_THROW ); + uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY_THROW ); + uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY_THROW ); // copy the raw stream to the temporary file ::comphelper::OStorageHelper::CopyInputToOutput( xInRaw, xTempOut ); -- cgit