diff options
author | Ivo Hinkelmann <ihi@openoffice.org> | 2009-09-17 13:53:54 +0000 |
---|---|---|
committer | Ivo Hinkelmann <ihi@openoffice.org> | 2009-09-17 13:53:54 +0000 |
commit | ca929afbdb49345507f6d3eb122a521dbb05ebdd (patch) | |
tree | 03fe827cd61b36b44dde8dc4e78fc7aff5ec0c6e /sfx2/source/doc/docfile.cxx | |
parent | e6c689f43a50e1dbda83f88ae1e0e43689cbe0c7 (diff) |
CWS-TOOLING: integrate CWS encsig09
2009-09-14 15:11:29 +0200 oc r276125 : #i105049# MacroSignatur needs Macro
2009-09-09 17:09:46 +0200 jl r276005 : #i103989# could not signe encrypted doc containing a formular object
2009-09-09 13:11:24 +0200 jl r275985 : #i103989# could not signe encrypted doc containing a formular object
2009-09-08 15:54:02 +0200 mav r275934 : #i103906# fix the automation test scenario ( tempfile should be writable for the user )
2009-09-07 14:01:39 +0200 mav r275895 : #i103906# fix the problem with reload
2009-09-07 09:34:48 +0200 mav r275871 : #i104786# do the ODF version check only for ODF documents
2009-09-07 08:19:06 +0200 mav r275870 : #i104389# fix text
2009-09-06 22:24:21 +0200 mav r275867 : #i104786# check the consistency of ODF version
2009-09-06 22:23:24 +0200 mav r275866 : #i104786# check the consistency of ODF version
2009-09-06 22:23:00 +0200 mav r275865 : #i104786# check the consistency of ODF version
2009-09-06 22:22:36 +0200 mav r275864 : #i104786# check the consistency of ODF version
2009-09-06 22:22:03 +0200 mav r275863 : #i104786# check the consistency of ODF version
2009-09-02 17:09:30 +0200 mav r275722 : #i104715# let repairing mechanics use the streams correctly
2009-09-01 16:52:49 +0200 mav r275670 : #i104389# notify user not to trust the corrupted document
2009-09-01 16:31:37 +0200 mav r275668 : #i104389# use vnd.sun.star.zip: protocol to access zip files
2009-09-01 16:30:32 +0200 mav r275667 : #i104389# use vnd.sun.star.zip: protocol to access zip files
2009-09-01 16:22:13 +0200 jl r275666 : #i104339# small content change
2009-09-01 14:20:42 +0200 jl r275660 : #i103519# remove some debug output
2009-09-01 13:51:52 +0200 jl r275659 : #i103519# NSS uses '\' for escaping in distinguished names
2009-09-01 12:49:47 +0200 mav r275655 : #i104389# use zip-mode to read from jar files
2009-09-01 12:40:22 +0200 mav r275653 : #i104389# use zip-mode to read from jar files
2009-09-01 12:32:29 +0200 mav r275652 : #i104389# use constants
2009-08-31 21:58:00 +0200 mav r275637 : #i10000# fix warning
2009-08-31 21:11:17 +0200 mav r275636 : #i104227# adding of scripting signature removes the document signature
2009-08-31 20:55:05 +0200 mav r275635 : #i103905# ZipStorage supports Compressed property
2009-08-31 20:53:55 +0200 mav r275634 : #i103905# adjust macro signature transfer to usage of ZipStorage
2009-08-31 15:30:49 +0200 jl r275609 : #i103989# warning is shown as long the user does not click 'OK'
2009-08-31 14:36:10 +0200 jl r275608 : #i103989# changed warning text when signing macro and there is a document signature. This warning is only displayed once
2009-08-31 13:34:41 +0200 mav r275603 : #i104452# disable macros in repaired documents
2009-08-31 13:33:42 +0200 mav r275602 : #i104452# disable macros in repaired documents
2009-08-31 13:03:56 +0200 jl r275600 : #i45212# signature dialog could not be started when using read-only documents
2009-08-31 09:26:13 +0200 mav r275583 : #i104578# store the additional entry as the last one to workaround parsing problem in OOo3.1 and later
2009-08-30 20:54:25 +0200 mav r275562 : #i10000# adopt for unix
2009-08-30 10:56:00 +0200 mav r275561 : CWS-TOOLING: rebase CWS encsig09 to trunk@275331 (milestone: DEV300:m56)
2009-08-28 16:34:00 +0200 mav r275539 : #i104578# write necessary info in manifest.xml for ODF1.2 encrypted document
2009-08-28 14:04:22 +0200 mav r275533 : #104587# fix handling of readonly streams
2009-08-28 13:58:10 +0200 mav r275531 : #i104389# fix the broken document handling
2009-08-28 11:40:39 +0200 mav r275522 : #i104389# fix the signature streams check
2009-08-27 21:48:12 +0200 mav r275509 : #i103927# show the warning
2009-08-27 21:47:48 +0200 mav r275508 : #i103927# show the warning
2009-08-27 16:45:59 +0200 jl r275495 : #i45212# remove unused variable
2009-08-27 16:34:00 +0200 jl r275494 : #i103989#
2009-08-27 13:54:28 +0200 jl r275482 : #i103519# fixed replacement of 'S' by 'ST'
2009-08-27 12:32:21 +0200 mav r275472 : #i10000# fix warning
2009-08-27 11:58:11 +0200 mav r275467 : #i104389# handle the entry path correctly
2009-08-26 17:18:35 +0200 jl r275438 : #i103519# subject and issuer distinguished names were not properly displayed. The strings were obtained by system functions (Windows, NSS), which use quotes to escape the values, when they contain special characters
2009-08-26 11:00:20 +0200 mav r275403 : #i10000# fix warnings
2009-08-26 08:25:45 +0200 mav r275392 : #i10000# fix warning
2009-08-26 08:02:22 +0200 mav r275391 : #i10000# adopt for linux
2009-08-26 07:40:30 +0200 mav r275390 : #i10000# fix warning
2009-08-26 07:35:28 +0200 mav r275389 : #i10000# use correct include file name
2009-08-25 15:01:41 +0200 jl r275356 : #i103989# better check for mimetype of streams
2009-08-25 09:07:09 +0200 mav r275335 : CWS-TOOLING: rebase CWS encsig09 to trunk@274622 (milestone: DEV300:m54)
2009-08-24 18:17:02 +0200 mav r275329 : #i103927# check the nonencrypted streams
2009-08-24 18:14:14 +0200 mav r275328 : #i103927# check the nonencrypted streams
2009-08-24 17:59:34 +0200 mav r275327 : #i103927#,#i104389# check the package consistency and nonencrypted streams
2009-08-24 16:18:28 +0200 jl r275323 : #i103989# added comment
2009-08-24 13:08:47 +0200 jl r275305 : #i45212# #i66276# only write the X509Certificate element once and allow to add remove several certificates at a time
2009-08-21 12:57:28 +0200 ufi r275239 : 104339
2009-08-21 08:39:05 +0200 jl r275213 : #i10398# comparing URIs of signed files with the 'element list'
2009-08-20 13:39:47 +0200 jl r275178 : #i10398# displaying 'new partially signed' status in the status bar
2009-08-20 13:35:39 +0200 jl r275177 : #i10398# displaying 'new partially signed' status in the status bar
2009-08-20 13:29:06 +0200 jl r275176 : #i10398# displaying 'new partially signed' status in the status bar
2009-08-20 13:26:21 +0200 jl r275175 : #i10398# displaying 'new partially signed' status in the status bar
2009-08-20 12:05:09 +0200 ufi r275170 : i104339
2009-08-19 12:24:54 +0200 jl r275146 : #i10398# displaying 'old signature' icon and status in signature dialog
2009-08-18 15:18:48 +0200 jl r275111 : #i103989# document signatures containing manifest.xml are now validated according to the final ODF1.2 spec
2009-08-18 11:41:06 +0200 mav r275087 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams
2009-08-18 11:35:13 +0200 mav r275085 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams
2009-08-14 17:32:41 +0200 jl r274999 : #i103989# using c14n tranformation for XML streams
2009-08-14 15:27:43 +0200 jl r274987 : #i103989# remove special handling for encrypted document streams in UriBindingHelper::OpenInputStream, since we use zip storage this is not necessary anymore
2009-08-14 15:08:10 +0200 jl r274983 : #i103989# Showing a message when adding or removing a macro signature, that the document signature will be removed
2009-08-14 14:57:27 +0200 jl r274982 : #i103989# accesing Sequence at invalid index
2009-08-11 08:55:02 +0200 mav r274846 : #i103905# let signing service know if there is already a valid document signature
2009-08-10 11:33:37 +0200 jl r274799 : #i103905# do not truncate the stream
2009-08-10 10:43:47 +0200 mav r274797 : #i103905# provide the storage version
2009-08-07 16:58:46 +0200 jl r274780 : #i103989#
2009-08-07 16:56:19 +0200 jl r274779 : #i103989# using odf version string etc.
2009-08-07 15:20:53 +0200 mav r274771 : #i103905# provide the storage version
2009-08-07 15:19:12 +0200 mav r274770 : #i103905# provide the storage version
2009-08-07 12:41:45 +0200 mav r274758 : #103930# do not store thumbnail in case of encrypted document
2009-08-07 12:36:52 +0200 mav r274757 : #i103905# provide the storage version
2009-08-07 12:15:54 +0200 mav r274754 : #i103760# the signed state is not lost on saving
2009-08-07 12:06:19 +0200 mav r274753 : #i103760# avoid warning regarding signature removal on export
2009-08-07 12:06:01 +0200 mav r274752 : #i103760# avoid warning regarding signature removal on export
2009-08-06 08:47:34 +0200 mav r274703 : #i103905# allow to transport ODF version to the signing component
2009-08-05 21:34:42 +0200 mav r274701 : #i103905# allow to transport ODF version to the signing component
2009-08-05 15:48:17 +0200 mav r274683 : #i103905# allow to transport ODF version to the signing component
2009-08-05 14:58:12 +0200 jl r274673 : #i103989# documentsignature now signes all streams except documentsignatures.xml, all streams are processed as binary files
2009-08-05 12:00:32 +0200 mav r274648 : #i103905# allow to transport ODF version to the signing component
2009-08-04 10:57:04 +0200 jl r274612 : #i103989# added XInitialization
2009-07-31 10:32:27 +0200 mav r274516 : #i103905# use zip storage to sign documents
2009-07-30 14:01:33 +0200 mav r274489 : #i103906# optimize the usage of temporary medium
2009-07-30 14:00:28 +0200 mav r274488 : #i103906# optimize the usage of temporary medium
2009-07-30 13:59:09 +0200 mav r274487 : #i103906# optimize the usage of temporary medium
2009-07-30 13:50:44 +0200 mav r274485 : #i103906# optimize the usage of temporary medium
2009-07-30 13:49:53 +0200 mav r274484 : #i103906# optimize the usage of temporary medium
2009-07-30 13:49:13 +0200 mav r274483 : #i103906# optimize the usage of temporary medium
2009-07-30 13:47:09 +0200 mav r274482 : #i103905#,#i103906# let the signing process use zip-storage; optimize the usage of temporary medium
2009-07-21 09:10:31 +0200 mav r274159 : CWS-TOOLING: rebase CWS encsig09 to trunk@273468 (milestone: DEV300:m51)
2009-05-05 08:39:01 +0200 mav r271496 : #i100832# allow to sign macros only when there are any
Diffstat (limited to 'sfx2/source/doc/docfile.cxx')
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 963 |
1 files changed, 311 insertions, 652 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 0683eaa415..f44ac7c3ec 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -84,6 +84,7 @@ #include <unotools/tempfile.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/componentcontext.hxx> +#include <framework/interaction.hxx> #include <unotools/streamhelper.hxx> #include <unotools/localedatawrapper.hxx> #ifndef _MSGBOX_HXX //autogen @@ -106,6 +107,7 @@ #include <unotools/streamwrap.hxx> #include <rtl/logfile.hxx> +#include <osl/file.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -373,10 +375,9 @@ public: uno::Sequence < util::RevisionTag > aVersions; - ::utl::TempFile* pTempDir; ::utl::TempFile* pTempFile; - uno::Reference < embed::XStorage > m_xReadStorage; + uno::Reference < embed::XStorage > m_xZipStorage; Reference < XInputStream > xInputStream; Reference < XStream > xStream; @@ -452,7 +453,6 @@ SfxMedium_Impl::SfxMedium_Impl( SfxMedium* pAntiImplP ) nFileVersion( 0 ), pOrigFilter( 0 ), aExpireTime( Date() + 10, Time() ), - pTempDir( NULL ), pTempFile( NULL ), nLastStorageError( 0 ), m_bRemoveBackup( sal_False ), @@ -470,9 +470,6 @@ SfxMedium_Impl::~SfxMedium_Impl() if ( pTempFile ) delete pTempFile; - - if ( pTempDir ) - delete pTempDir; } //================================================================ @@ -491,18 +488,6 @@ SfxMedium_Impl::~SfxMedium_Impl() pOutStream( 0 ) //------------------------------------------------------------------ -/* -const SvGlobalName& SfxMedium::GetClassFilter() -{ - GetMedium_Impl(); - if( GetError() ) - return aFilterClass; - if( !bSetFilter && GetStorage() ) - SetClassFilter( GetStorage()->GetClassName() ); - return aFilterClass; -}*/ - -//------------------------------------------------------------------ void SfxMedium::ResetError() { eError = SVSTREAM_OK; @@ -557,15 +542,6 @@ sal_uInt32 SfxMedium::GetErrorCode() const } //------------------------------------------------------------------ -long SfxMedium::GetFileVersion() const -{ - if ( !pImp->nFileVersion && pFilter ) - return pFilter->GetVersion(); - else - return pImp->nFileVersion; -} - -//------------------------------------------------------------------ void SfxMedium::CheckFileDate( const util::DateTime& aInitDate ) { GetInitFileDate( sal_True ); @@ -665,6 +641,7 @@ Reference < XContent > SfxMedium::GetContent() const return pImp->aContent.get(); } +//------------------------------------------------------------------ ::rtl::OUString SfxMedium::GetBaseURL( bool bForSaving ) { ::rtl::OUString aBaseURL; @@ -703,7 +680,7 @@ SvStream* SfxMedium::GetInStream() if ( pInStream ) return pInStream; - if ( pImp->pTempFile || pImp->pTempDir ) + if ( pImp->pTempFile ) { pInStream = new SvFileStream( aName, nStorOpenMode ); @@ -747,7 +724,7 @@ void SfxMedium::CloseInStream_Impl() if ( pInStream && !GetContent().is() ) { - CreateTempFile(); + CreateTempFile( sal_True ); return; } @@ -755,7 +732,7 @@ void SfxMedium::CloseInStream_Impl() if ( pSet ) pSet->ClearItem( SID_INPUTSTREAM ); - CloseReadStorage_Impl(); + CloseZipStorage_Impl(); pImp->xInputStream = uno::Reference< io::XInputStream >(); if ( !pOutStream ) @@ -775,8 +752,7 @@ SvStream* SfxMedium::GetOutStream() { // Create a temp. file if there is none because we always // need one. - if ( !pImp->pTempFile ) - CreateTempFile(); + CreateTempFile( sal_False ); if ( pImp->pTempFile ) { @@ -844,8 +820,7 @@ void SfxMedium::CreateFileStream() GetInStream(); if( pInStream ) { - if ( !pImp->pTempFile ) - CreateTempFile(); + CreateTempFile( sal_False ); pImp->bIsTemp = sal_True; CloseInStream_Impl(); } @@ -942,82 +917,17 @@ sal_Bool SfxMedium::IsPreview_Impl() } //------------------------------------------------------------------ -sal_Bool SfxMedium::TryStorage() -{ - GetStorage(); - - if ( pImp->xStorage.is() ) - return sal_True; - - // this code will be removed when binary filter components are available! - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr( ::comphelper::getProcessServiceFactory() ); - ::com::sun::star::uno::Reference< ::com::sun::star::util::XArchiver > - xPacker( xSMgr->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.util.Archiver" ) ), ::com::sun::star::uno::UNO_QUERY ); - - if( !xPacker.is() ) - return sal_False; - - // extract extra data - ::rtl::OUString aPath = GetURLObject().PathToFileName(); - ::rtl::OUString aExtraData = xPacker->getExtraData( aPath ); - const ::rtl::OUString aSig1( DEFINE_CONST_UNICODE( "private:" ) ); - String aTmp( '?' ); - aTmp += String::CreateFromAscii("simpress");//pFilter->GetFilterContainer()->GetName(); - const ::rtl::OUString aSig2( aTmp ); - sal_Int32 nIndex1 = aExtraData.indexOf( aSig1 ); - sal_Int32 nIndex2 = aExtraData.indexOf( aSig2 ); - - if( nIndex1 != 0 || nIndex2 == -1 ) - return sal_False; - - nIndex1 += aSig1.getLength(); - ::rtl::OUString aTempDoku = aExtraData.copy( nIndex1, nIndex2 - nIndex1 ); - - // create a temp dir to unpack to - pImp->pTempDir = new ::utl::TempFile( NULL, sal_True ); - pImp->pTempDir->EnableKillingFile( sal_True ); - - // unpack all files to temp dir - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs; - com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > xInteractionHandler = GetInteractionHandler(); - if (xInteractionHandler.is()) - { - aArgs.realloc(1); - aArgs.getArray()[0].Name = DEFINE_CONST_UNICODE( "InteractionHandler" ); - aArgs.getArray()[0].Value <<= xInteractionHandler ; - } - ::com::sun::star::uno::Sequence< ::rtl::OUString > files(0); - - if( !xPacker->unpack( pImp->pTempDir->GetURL(), aPath, files, aArgs ) ) - return sal_False; - - String aNewName = pImp->pTempDir->GetURL(); - aNewName += '/'; - aNewName += String( aTempDoku ); - CloseInStream_Impl(); - String aTemp; - ::utl::LocalFileHelper::ConvertURLToPhysicalName( aNewName, aTemp ); - SetPhysicalName_Impl( aTemp ); - GetStorage(); - - return pImp->xStorage.is(); -} - -//------------------------------------------------------------------ -sal_Bool SfxMedium::BasedOnOriginalFile_Impl() -{ - return ( !pImp->pTempFile && !( aLogicName.Len() && pImp->m_bSalvageMode ) - && GetURLObject().GetMainURL( INetURLObject::NO_DECODE ).getLength() - && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) - && ::utl::UCBContentHelper::IsDocument( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ); -} - -//------------------------------------------------------------------ void SfxMedium::StorageBackup_Impl() { ::ucbhelper::Content aOriginalContent; Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; - if ( BasedOnOriginalFile_Impl() && !pImp->m_aBackupURL.getLength() + + sal_Bool bBasedOnOriginalFile = ( !pImp->pTempFile && !( aLogicName.Len() && pImp->m_bSalvageMode ) + && GetURLObject().GetMainURL( INetURLObject::NO_DECODE ).getLength() + && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) + && ::utl::UCBContentHelper::IsDocument( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ); + + if ( bBasedOnOriginalFile && !pImp->m_aBackupURL.getLength() && ::ucbhelper::Content::create( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, aOriginalContent ) ) { DoInternalBackup_Impl( aOriginalContent ); @@ -1036,26 +946,6 @@ void SfxMedium::StorageBackup_Impl() } //------------------------------------------------------------------ -::rtl::OUString SfxMedium::GetOutputStorageURL_Impl() -{ - String aStorageName; - - if ( aName.Len() ) - { - if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aStorageName ) ) - { - DBG_ERROR("Physical name not convertable!"); - } - } - else - { - aStorageName = GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); - } - - return aStorageName; -} - -//------------------------------------------------------------------ uno::Reference < embed::XStorage > SfxMedium::GetOutputStorage() { if ( GetError() ) @@ -1249,7 +1139,9 @@ sal_Bool SfxMedium::LockOrigFileOnDemand( sal_Bool bLoading, sal_Bool bNoUI ) try { // MediaDescriptor does this check also, the duplication should be avoided in future - pImp->aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bContentReadonly; + Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; + ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); + aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bContentReadonly; } catch( uno::Exception ) {} @@ -1420,222 +1312,82 @@ sal_Bool SfxMedium::LockOrigFileOnDemand( sal_Bool bLoading, sal_Bool bNoUI ) } //------------------------------------------------------------------ -uno::Reference < embed::XStorage > SfxMedium::GetStorage() +uno::Reference < embed::XStorage > SfxMedium::GetStorage( sal_Bool bCreateTempIfNo ) { if ( pImp->xStorage.is() || bTriedStorage ) return pImp->xStorage; uno::Sequence< uno::Any > aArgs( 2 ); - String aStorageName; - if ( pImp->pTempFile || pImp->pTempDir ) - { - // open storage from the temporary file - if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aStorageName ) ) - { - DBG_ERROR("Physical name not convertable!"); - } + // the medium should be retrieved before temporary file creation + // to let the MediaDescriptor be filled with the streams + GetMedium_Impl(); - CloseOutStream(); - // create the set of the streams based on the temporary file - GetMedium_Impl(); + if ( bCreateTempIfNo ) + CreateTempFile( sal_False ); - OSL_ENSURE( pImp->xStream.is(), "It must be possible to create read write stream access!" ); - if ( pImp->xStream.is() ) - { - aArgs[0] <<= pImp->xStream; - pImp->bStorageBasedOnInStream = sal_True; - } - else - { - CloseStreams_Impl(); - aArgs[0] <<= ::rtl::OUString( aName ); - pImp->bStorageBasedOnInStream = sal_False; - } + GetMedium_Impl(); - aArgs[1] <<= ( nStorOpenMode&STREAM_WRITE ? embed::ElementModes::READWRITE : embed::ElementModes::READ ); + if ( GetError() ) + return pImp->xStorage; - try - { - pImp->xStorage = uno::Reference< embed::XStorage >( - ::comphelper::OStorageHelper::GetStorageFactory()->createInstanceWithArguments( aArgs ), - uno::UNO_QUERY ); - } - catch( uno::Exception& ) - { - //TODO/LATER: error handling; Error and LastStorageError - } - } - else + SFX_ITEMSET_ARG( GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False); + if ( pRepairItem && pRepairItem->GetValue() ) { - // open the storage from original location - { - GetMedium_Impl(); - if ( GetError() ) - return pImp->xStorage; - - try - { - if ( IsReadOnly() && ::utl::LocalFileHelper::IsLocalFile( aLogicName ) ) - { - //TODO/LATER: performance problem if not controlled by special Mode in SfxMedium - //(should be done only for permanently open storages) - // create a copy, the following method will close all existing streams - CreateTempFile(); - - // create the set of the streams based on the temporary file - GetMedium_Impl(); - - OSL_ENSURE( pImp->xStream.is(), "It must be possible to create read write stream access!" ); - if ( pImp->xStream.is() ) - { - aArgs[0] <<= pImp->xStream; - pImp->bStorageBasedOnInStream = sal_True; - } - else - { - CloseStreams_Impl(); - aArgs[0] <<= ::rtl::OUString( aName ); - pImp->bStorageBasedOnInStream = sal_False; - } - - aArgs[1] <<= embed::ElementModes::READWRITE; - - } - else - { - // there is no explicit request to open the document readonly - - // create a storage on the stream - if ( pImp->xStream.is() ) - { - aArgs[0] <<= pImp->xStream; - aArgs[1] <<= ( ( nStorOpenMode & STREAM_WRITE ) ? - embed::ElementModes::READWRITE : embed::ElementModes::READ ); - - pImp->bStorageBasedOnInStream = sal_True; - } - else - { - // no readwrite stream, but it can be a case of http protocol - sal_Bool bReadOnly = sal_False; - - if ( aLogicName.CompareToAscii( "private:stream", 14 ) != COMPARE_EQUAL - && GetContent().is() ) - { - // unfortunately the content can not always have the interaction handler - // so in some cases it has to be set for some time - Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; - Reference < ::com::sun::star::ucb::XCommandEnvironment > xOldEnv; - Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler = ((SfxMedium*)this)->GetInteractionHandler(); - if ( xInteractionHandler.is() ) - xEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, - Reference< ::com::sun::star::ucb::XProgressHandler >() ); - - if ( xEnv.is() ) - { - xOldEnv = pImp->aContent.getCommandEnvironment(); - pImp->aContent.setCommandEnvironment( xEnv ); - } - - try - { - Any aAny = pImp->aContent.getPropertyValue( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsReadOnly" )) ); - - if ( ( aAny >>= bReadOnly ) && bReadOnly ) - { - GetItemSet()->Put( SfxBoolItem(SID_DOC_READONLY, sal_True)); - SetOpenMode( SFX_STREAM_READONLY, sal_False, sal_True ); - } - } - catch( uno::Exception& ) - {} - - if ( xEnv.is() ) - pImp->aContent.setCommandEnvironment( xOldEnv ); - } - - // if the document is opened as readonly the copy should be done according to selected approach - // if the document is opened for editing the copy should be done to use it as a temporary location for changes before the final transfer - // the following method will close all existing streams - CreateTempFile(); - - // create the set of the streams based on the temporary file - GetMedium_Impl(); - - OSL_ENSURE( pImp->xStream.is(), "It must be possible to create read write stream access!" ); - if ( pImp->xStream.is() ) - { - aArgs[0] <<= pImp->xStream; - pImp->bStorageBasedOnInStream = sal_True; - } - else - { - CloseStreams_Impl(); - aArgs[0] <<= ::rtl::OUString( aName ); - pImp->bStorageBasedOnInStream = sal_False; - } + // the storage should be created for repairing mode + CreateTempFile( sal_False ); + GetMedium_Impl(); - if ( bReadOnly ) - aArgs[1] <<= embed::ElementModes::READ; - else - aArgs[1] <<= embed::ElementModes::READWRITE; - } - } + Reference< ::com::sun::star::ucb::XProgressHandler > xProgressHandler; + Reference< ::com::sun::star::task::XStatusIndicator > xStatusIndicator; - SFX_ITEMSET_ARG( GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False); - if ( pRepairItem && pRepairItem->GetValue() ) - { - // the storage should be created for repairing mode - CreateTempFile(); - Reference< ::com::sun::star::ucb::XProgressHandler > xProgressHandler; - Reference< ::com::sun::star::task::XStatusIndicator > xStatusIndicator; - - SFX_ITEMSET_ARG( GetItemSet(), pxProgressItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, sal_False ); - if( pxProgressItem && ( pxProgressItem->GetValue() >>= xStatusIndicator ) ) - xProgressHandler = Reference< ::com::sun::star::ucb::XProgressHandler >( - new utl::ProgressHandlerWrap( xStatusIndicator ) ); - - uno::Sequence< beans::PropertyValue > aAddProps( 2 ); - aAddProps[0].Name = ::rtl::OUString::createFromAscii( "RepairPackage" ); - aAddProps[0].Value <<= (sal_Bool)sal_True; - aAddProps[1].Name = ::rtl::OUString::createFromAscii( "StatusIndicator" ); - aAddProps[1].Value <<= xProgressHandler; - - aArgs.realloc( 3 ); - aArgs[0] <<= ::rtl::OUString( aName ); - aArgs[1] <<= embed::ElementModes::READWRITE; - aArgs[2] <<= aAddProps; + SFX_ITEMSET_ARG( GetItemSet(), pxProgressItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, sal_False ); + if( pxProgressItem && ( pxProgressItem->GetValue() >>= xStatusIndicator ) ) + xProgressHandler = Reference< ::com::sun::star::ucb::XProgressHandler >( + new utl::ProgressHandlerWrap( xStatusIndicator ) ); - pImp->bStorageBasedOnInStream = sal_False; - } + uno::Sequence< beans::PropertyValue > aAddProps( 2 ); + aAddProps[0].Name = ::rtl::OUString::createFromAscii( "RepairPackage" ); + aAddProps[0].Value <<= (sal_Bool)sal_True; + aAddProps[1].Name = ::rtl::OUString::createFromAscii( "StatusIndicator" ); + aAddProps[1].Value <<= xProgressHandler; - pImp->xStorage = uno::Reference< embed::XStorage >( - ::comphelper::OStorageHelper::GetStorageFactory()->createInstanceWithArguments( aArgs ), - uno::UNO_QUERY ); + // the first arguments will be filled later + aArgs.realloc( 3 ); + aArgs[2] <<= aAddProps; + } - if ( !pImp->xStorage.is() ) - throw uno::RuntimeException(); + if ( pImp->xStream.is() ) + { + // since the storage is based on temporary stream we open it always read-write + aArgs[0] <<= pImp->xStream; + aArgs[1] <<= embed::ElementModes::READWRITE; + pImp->bStorageBasedOnInStream = sal_True; + } + else if ( pImp->xInputStream.is() ) + { + // since the storage is based on temporary stream we open it always read-write + aArgs[0] <<= pImp->xInputStream; + aArgs[1] <<= embed::ElementModes::READ; + pImp->bStorageBasedOnInStream = sal_True; + } + else + { + CloseStreams_Impl(); + aArgs[0] <<= ::rtl::OUString( aName ); + aArgs[1] <<= embed::ElementModes::READ; + pImp->bStorageBasedOnInStream = sal_False; + } - if ( pRepairItem && pRepairItem->GetValue() ) - { - // in repairing mode the mediatype required by filter should be used - ::rtl::OUString aMediaType; - ::rtl::OUString aMediaTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - uno::Reference < beans::XPropertySet > xPropSet( pImp->xStorage, uno::UNO_QUERY_THROW ); - xPropSet->getPropertyValue( aMediaTypePropName ) >>= aMediaType; - if ( !aMediaType.getLength() && pFilter ) - xPropSet->setPropertyValue( aMediaTypePropName, - uno::makeAny( ::rtl::OUString( pFilter->GetMimeType() ) ) ); - } - } - catch ( uno::Exception& ) - { - //TODO/MBA: error handling; Error and LastStorageError - pImp->bStorageBasedOnInStream = sal_False; - } - } + try + { + pImp->xStorage = uno::Reference< embed::XStorage >( + ::comphelper::OStorageHelper::GetStorageFactory()->createInstanceWithArguments( aArgs ), + uno::UNO_QUERY ); + } + catch( uno::Exception& ) + { + // impossibility to create the storage is no error } if( ( pImp->nLastStorageError = GetError() ) != SVSTREAM_OK ) @@ -1643,13 +1395,12 @@ uno::Reference < embed::XStorage > SfxMedium::GetStorage() pImp->xStorage = 0; if ( pInStream ) pInStream->Seek(0); - return NULL; + return uno::Reference< embed::XStorage >(); } bTriedStorage = sal_True; - //TODO/MBA: error handling; Error and LastStorageError - //if ( aStorage->GetError() == SVSTREAM_OK ) + // TODO/LATER: Get versionlist on demand if ( pImp->xStorage.is() ) { SetPasswordToStorage_Impl(); @@ -1716,15 +1467,6 @@ uno::Reference < embed::XStorage > SfxMedium::GetStorage() bResetStorage = TRUE; } - //TODO/MBA: error handling; Error and LastStorageError - if ( pImp->xStorage.is() ) - { /* - if( ( pImp->nLastStorageError = aStorage->GetError() ) != SVSTREAM_OK ) - bResetStorage = TRUE; - else if ( GetFilter() ) - aStorage->SetVersion( GetFilter()->GetVersion() );*/ - } - if ( bResetStorage ) { pImp->xStorage = 0; @@ -1737,28 +1479,25 @@ uno::Reference < embed::XStorage > SfxMedium::GetStorage() } //------------------------------------------------------------------ -uno::Reference< embed::XStorage > SfxMedium::GetLastCommitReadStorage_Impl() +uno::Reference< embed::XStorage > SfxMedium::GetZipStorageToSign_Impl( sal_Bool bReadOnly ) { - if ( !GetError() && !pImp->m_xReadStorage.is() ) + if ( !GetError() && !pImp->m_xZipStorage.is() ) { + // very careful!!! + // if bReadOnly == sal_False and there is no temporary file the original file might be used GetMedium_Impl(); try { - if ( pImp->xInputStream.is() ) + // we can not sign document if there is no stream + // should it be possible at all? + if ( !bReadOnly && pImp->xStream.is() ) { - uno::Sequence< uno::Any > aArgs( 2 ); - aArgs[0] <<= pImp->xInputStream; - aArgs[1] <<= embed::ElementModes::READ; - pImp->m_xReadStorage = uno::Reference< embed::XStorage >( - ::comphelper::OStorageHelper::GetStorageFactory()->createInstanceWithArguments( aArgs ), - uno::UNO_QUERY ); + pImp->m_xZipStorage = ::comphelper::OStorageHelper::GetStorageOfFormatFromStream( ZIP_STORAGE_FORMAT_STRING, pImp->xStream, embed::ElementModes::READWRITE ); } - else if ( GetStorage().is() ) + else if ( pImp->xInputStream.is() ) { - uno::Reference< embed::XStorage > xTempStor = ::comphelper::OStorageHelper::GetTemporaryStorage(); - GetStorage()->copyLastCommitTo( xTempStor ); - pImp->m_xReadStorage = xTempStor; + pImp->m_xZipStorage = ::comphelper::OStorageHelper::GetStorageOfFormatFromInputStream( ZIP_STORAGE_FORMAT_STRING, pImp->xInputStream ); } } catch( uno::Exception& ) @@ -1770,20 +1509,20 @@ uno::Reference< embed::XStorage > SfxMedium::GetLastCommitReadStorage_Impl() ResetError(); } - return pImp->m_xReadStorage; + return pImp->m_xZipStorage; } //------------------------------------------------------------------ -void SfxMedium::CloseReadStorage_Impl() +void SfxMedium::CloseZipStorage_Impl() { - if ( pImp->m_xReadStorage.is() ) + if ( pImp->m_xZipStorage.is() ) { try { - pImp->m_xReadStorage->dispose(); + pImp->m_xZipStorage->dispose(); } catch( uno::Exception& ) {} - pImp->m_xReadStorage = uno::Reference< embed::XStorage >(); + pImp->m_xZipStorage = uno::Reference< embed::XStorage >(); } } @@ -1885,11 +1624,12 @@ sal_Bool SfxMedium::StorageCommit_Impl() try { xTrans->commit(); - CloseReadStorage_Impl(); + CloseZipStorage_Impl(); bResult = sal_True; } catch ( embed::UseBackupException& aBackupExc ) { + // since the temporary file is created always now, the scenario is close to be impossible if ( !pImp->pTempFile ) { OSL_ENSURE( pImp->m_aBackupURL.getLength(), "No backup on storage commit!\n" ); @@ -1936,9 +1676,6 @@ sal_Bool SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource, Reference< XOutputStream > aDestStream; ::ucbhelper::Content aOriginalContent; -// actualy it should work even for contents different from file content -// DBG_ASSERT( ::utl::LocalFileHelper::IsLocalFile( aDest.GetMainURL( INetURLObject::NO_DECODE ) ), -// "SfxMedium::TransactedTransferForFS() should be used only for local contents!" ); try { aOriginalContent = ::ucbhelper::Content( aDest.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); @@ -2241,57 +1978,10 @@ void SfxMedium::Transfer_Impl() catch ( uno::Exception& ) { //TODO/MBA: error handling - //if ( !GetError() ) - // SetError( xStor->GetError(, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) )) ); } return; } - if ( pFilter && SOFFICE_FILEFORMAT_60 <= pFilter->GetVersion() ) - { - //TODO/LATER: how?! - /* - SFX_ITEMSET_ARG( GetItemSet(), pItem, SfxBoolItem, SID_UNPACK, sal_False); - if ( pItem && pItem->GetValue() ) - { - // this file must be stored without packing into a JAR file - // check for an existing unpacked storage - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( GetName(), STREAM_STD_READ ); - if ( !pStream->GetError() ) - { - String aURL = UCBStorage::GetLinkedFile( *pStream ); - if ( aURL.Len() ) - // remove a possibly existing old folder - ::utl::UCBContentHelper::Kill( aURL ); - - DELETEZ( pStream ); - } - - // create a new folder based storage - SvStorageRef xStor = new SvStorage( TRUE, GetName(), STREAM_STD_READWRITE, STORAGE_CREATE_UNPACKED ); - - // copy package into unpacked storage - if ( xStor->GetError() == ERRCODE_NONE && GetStorage()->copyToStorage( xStor ) ) - { - // commit changes, writing will happen now - xStor->Commit(); - - // take new unpacked storage as own storage - if ( pImp->xStorage.is() ) - CloseStorage(); - - CloseStreams_Impl(); - - DELETEZ( pImp->pTempFile ); - ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), aName ); - SetStorage_Impl( xStor ); - } - else if ( !GetError() ) - SetError( xStor->GetError(, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) )) ); - return; - }*/ - } - INetURLObject aDest( GetURLObject() ); // source is the temp file written so far @@ -2606,7 +2296,7 @@ void SfxMedium::GetMedium_Impl() // in case the temporary file exists the streams should be initialized from it, // but the original MediaDescriptor should not be changed - sal_Bool bFromTempFile = ( pImp->pTempFile || pImp->pTempDir ); + sal_Bool bFromTempFile = ( pImp->pTempFile != NULL ); if ( !bFromTempFile ) { @@ -2703,54 +2393,6 @@ void SfxMedium::CancelTransfers() pImp->xCancelManager->Cancel(); } -//---------------------------------------------------------------- -/* -String SfxMedium::GetStatusString( const SvProgressArg* pArg ) -{ - String aString; - StringList_Impl aSL( SfxResId( RID_DLSTATUS2 ), (USHORT)pArg->eStatus ); - USHORT nTotal = 0; - - if ( pArg->eStatus == SVBINDSTATUS_ENDDOWNLOADDATA && nTotal <= 1 ) - return aString; - - if( aSL ) - { - INetURLObject aObj( pArg->rStatus ); - aString = aSL.GetString(); - aString.SearchAndReplaceAscii( "$(HOST)", aObj.GetHost() ); - String aTarget = aObj.GetFull(); - if( aTarget.Len() <= 1 && pArg->eStatus != SVBINDSTATUS_CONNECTING ) - aTarget = aObj.GetHost(); - if( pArg->nMax ) - { - aTarget += DEFINE_CONST_UNICODE( " (" ); - AddNumber_Impl( aTarget, pArg->nMax ); - aTarget += ')'; - } - - aString.SearchAndReplaceAscii( "$(TARGET)",aTarget ); - String aNumber; - AddNumber_Impl( aNumber, pArg->nProgress ); - if( pArg->nRate ) - { - aNumber+= DEFINE_CONST_UNICODE( " (" ); - AddNumber_Impl( aNumber, (ULONG)pArg->nRate ); - aNumber+= DEFINE_CONST_UNICODE( "/s)" ); - } - if( pArg->nMax && pArg->nProgress && pArg->nMax != pArg->nProgress ) - { - aNumber += DEFINE_CONST_UNICODE( " [" ); - float aPerc = pArg->nProgress / (float)pArg->nMax; - aNumber += String::CreateFromInt32( (USHORT)(aPerc * 100) ); - aNumber += DEFINE_CONST_UNICODE( "%]" ); - } - aString.SearchAndReplaceAscii( "$(BYTE)", aNumber ); - } - return aString; -} -*/ - sal_Bool SfxMedium::IsRemote() { return bRemote; @@ -2910,7 +2552,7 @@ SfxMedium::SfxMedium( const SfxMedium& rMedium, sal_Bool bTemporary ) pFilter = rMedium.pFilter; Init_Impl(); if( bTemporary ) - CreateTempFile(); + CreateTempFile( sal_True ); } //------------------------------------------------------------------ @@ -2989,7 +2631,7 @@ void SfxMedium::Close() const SvStream *pStream = aStorage->GetSvStream(); if ( pStream && pStream == pInStream ) { - CloseReadStorage_Impl(); + CloseZipStorage_Impl(); pInStream = NULL; pImp->xInputStream = Reference < XInputStream >(); pImp->xLockBytes.Clear(); @@ -3022,7 +2664,7 @@ void SfxMedium::CloseAndRelease() const SvStream *pStream = aStorage->GetSvStream(); if ( pStream && pStream == pInStream ) { - CloseReadStorage_Impl(); + CloseZipStorage_Impl(); pInStream = NULL; pImp->xInputStream = Reference < XInputStream >(); pImp->xLockBytes.Clear(); @@ -3062,7 +2704,7 @@ void SfxMedium::UnlockFile() void SfxMedium::CloseAndReleaseStreams_Impl() { - CloseReadStorage_Impl(); + CloseZipStorage_Impl(); uno::Reference< io::XInputStream > xInToClose = pImp->xInputStream; uno::Reference< io::XOutputStream > xOutToClose; @@ -3184,26 +2826,6 @@ void SfxMedium::SetPhysicalName_Impl( const String& rNameP ) } } -//---------------------------------------------------------------- -void SfxMedium::MoveTempTo_Impl( SfxMedium* pMedium ) -{ - if ( pMedium && pMedium != this && pImp->pTempFile ) - { - if( pMedium->pImp->pTempFile ) - delete pMedium->pImp->pTempFile; - pMedium->pImp->pTempFile = pImp->pTempFile; - - pImp->pTempFile->EnableKillingFile( sal_True ); - pImp->pTempFile = NULL; - - pMedium->aName = pMedium->pImp->pTempFile->GetFileName(); - - pMedium->CloseInStream(); - pMedium->CloseStorage(); - pMedium->pImp->aContent = ::ucbhelper::Content(); - } -} - //------------------------------------------------------------------ void SfxMedium::SetTemporary( sal_Bool bTemp ) { @@ -3407,22 +3029,15 @@ SfxMedium::~SfxMedium() delete pURLObj; delete pImp; } -//------------------------------------------------------------------ +//------------------------------------------------------------------ void SfxMedium::SetItemSet(SfxItemSet *pNewSet) { delete pSet; pSet = pNewSet; } -//------------------------------------------------------------------ -void SfxMedium::SetClassFilter( const SvGlobalName & rFilterClass ) -{ - bSetFilter = sal_True; - aFilterClass = rFilterClass; -} //---------------------------------------------------------------- - const INetURLObject& SfxMedium::GetURLObject() const { if( !pURLObj ) @@ -3755,131 +3370,122 @@ sal_Bool SfxMedium::IsReadOnly() } //---------------------------------------------------------------- -void SfxMedium::TryToSwitchToRepairedTemp() +sal_Bool SfxMedium::SetWritableForUserOnly( const ::rtl::OUString& aURL ) { - // the medium should be opened in repair mode - SFX_ITEMSET_ARG( GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, FALSE ); - if ( pRepairItem && pRepairItem->GetValue() ) + // UCB does not allow to allow write access only for the user, + // use osl API + sal_Bool bResult = sal_False; + + ::osl::DirectoryItem aDirItem; + if ( ::osl::DirectoryItem::get( aURL, aDirItem ) == ::osl::FileBase::E_None ) { - DBG_ASSERT( pImp->xStorage.is(), "Possible performance problem" ); - if ( GetStorage().is() ) + ::osl::FileStatus aFileStatus( FileStatusMask_Attributes ); + if ( aDirItem.getFileStatus( aFileStatus ) == osl::FileBase::E_None + && aFileStatus.isValid( FileStatusMask_Attributes ) ) { - ::utl::TempFile* pTmpFile = new ::utl::TempFile(); - pTmpFile->EnableKillingFile( sal_True ); - ::rtl::OUString aNewName = pTmpFile->GetFileName(); + sal_uInt64 nAttributes = aFileStatus.getAttributes(); - if( aNewName.getLength() ) - { - try - { - uno::Reference < embed::XStorage > xNewStorage = comphelper::OStorageHelper::GetStorageFromURL( aNewName, - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); - //SvStorageRef aNewStorage = new SvStorage( sal_True, aNewName, STREAM_WRITE | STREAM_TRUNC, STORAGE_TRANSACTED ); - - pImp->xStorage->copyToStorage( xNewStorage ); - //if ( aNewStorage->GetError() == SVSTREAM_OK ) - { - CloseInStream(); - CloseStorage(); - if ( pImp->pTempFile ) - DELETEZ( pImp->pTempFile ); + nAttributes &= ~(Attribute_OwnWrite | + Attribute_GrpWrite | + Attribute_OthWrite | + Attribute_ReadOnly); + nAttributes |= Attribute_OwnWrite; - pImp->pTempFile = pTmpFile; - aName = aNewName; - } - } - catch ( uno::Exception& ) - { - //TODO/MBA: error handling - //SetError( aNewStorage->GetError(, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) )) ); - } - } - else - SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); - - if (pImp->pTempFile != pTmpFile) - delete pTmpFile; + bResult = ( osl::File::setAttributes( aURL, nAttributes ) == ::osl::FileBase::E_None ); } - else - SetError( ERRCODE_IO_CANTREAD, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); } + + return bResult; } //---------------------------------------------------------------- -void SfxMedium::CreateTempFile() +void SfxMedium::CreateTempFile( sal_Bool bReplace ) { if ( pImp->pTempFile ) { + if ( !bReplace ) + return; + DELETEZ( pImp->pTempFile ); aName = String(); } - StreamMode nOpenMode = nStorOpenMode; - BOOL bCopy = ( nStorOpenMode == nOpenMode && ! ( nOpenMode & STREAM_TRUNC ) ); - if ( bCopy && !pInStream ) - { - if ( GetContent().is() ) - { - try - { - // make sure that the desired file exists before trying to open - SvMemoryStream aStream(0,0); - ::utl::OInputStreamWrapper* pInput = new ::utl::OInputStreamWrapper( aStream ); - Reference< XInputStream > xInput( pInput ); - - InsertCommandArgument aInsertArg; - aInsertArg.Data = xInput; - - aInsertArg.ReplaceExisting = sal_False; - Any aCmdArg; - aCmdArg <<= aInsertArg; - pImp->aContent.executeCommand( ::rtl::OUString::createFromAscii( "insert" ), aCmdArg ); - } - catch ( Exception& ) - { - // it is NOT an error when the stream already exists! - GetInStream(); - } - } - } - - nStorOpenMode = nOpenMode; - ResetError(); - pImp->pTempFile = new ::utl::TempFile(); pImp->pTempFile->EnableKillingFile( sal_True ); aName = pImp->pTempFile->GetFileName(); - if ( !aName.Len() ) + ::rtl::OUString aTmpURL = pImp->pTempFile->GetURL(); + if ( !aName.Len() || !aTmpURL.getLength() ) { SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); return; } - if ( bCopy && pInStream ) + if ( !( nStorOpenMode & STREAM_TRUNC ) ) { - GetOutStream(); - if ( pOutStream ) + if ( GetContent().is() + && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) + && ::utl::UCBContentHelper::IsDocument( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) { - char *pBuf = new char [8192]; - sal_uInt32 nErr = ERRCODE_NONE; - - pInStream->Seek(0); - pOutStream->Seek(0); + // if there is already such a document, we should copy it + // if it is a file system use OS copy process + sal_Bool bTransferSuccess = sal_False; + try + { + uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv; + INetURLObject aTmpURLObj( aTmpURL ); + ::rtl::OUString aFileName = aTmpURLObj.getName( INetURLObject::LAST_SEGMENT, + true, + INetURLObject::DECODE_WITH_CHARSET ); + if ( aFileName.getLength() && aTmpURLObj.removeSegment() ) + { + ::ucbhelper::Content aTargetContent( aTmpURLObj.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); + if ( aTargetContent.transferContent( pImp->aContent, ::ucbhelper::InsertOperation_COPY, aFileName, NameClash::OVERWRITE ) ) + { + SetWritableForUserOnly( aTmpURL ); + bTransferSuccess = sal_True; + } + } + } + catch( uno::Exception& ) + {} - while( !pInStream->IsEof() && nErr == ERRCODE_NONE ) + if ( !bTransferSuccess ) { - sal_uInt32 nRead = pInStream->Read( pBuf, 8192 ); - nErr = pInStream->GetError(); - pOutStream->Write( pBuf, nRead ); + SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); + return; } - delete[] pBuf; + CloseOutStream(); CloseInStream(); } - CloseOutStream_Impl(); + else if ( pInStream ) + { + // the case when there is no URL-access available or this is a remote protocoll + // but there is an input stream + GetOutStream(); + if ( pOutStream ) + { + char *pBuf = new char [8192]; + sal_uInt32 nErr = ERRCODE_NONE; + + pInStream->Seek(0); + pOutStream->Seek(0); + + while( !pInStream->IsEof() && nErr == ERRCODE_NONE ) + { + sal_uInt32 nRead = pInStream->Read( pBuf, 8192 ); + nErr = pInStream->GetError(); + pOutStream->Write( pBuf, nRead ); + } + + delete[] pBuf; + CloseInStream(); + } + CloseOutStream_Impl(); + } + else + CloseInStream(); } - else - CloseInStream(); CloseStorage(); } @@ -3887,6 +3493,7 @@ void SfxMedium::CreateTempFile() //---------------------------------------------------------------- void SfxMedium::CreateTempFileNoCopy() { + // this call always replaces the existing temporary file if ( pImp->pTempFile ) delete pImp->pTempFile; @@ -3944,100 +3551,120 @@ void SfxMedium::SetCharset( ::rtl::OUString aChs ) pImp->aCharset = aChs; } -sal_Bool SfxMedium::SignContents_Impl( sal_Bool bScriptingContent ) +sal_Bool SfxMedium::SignContents_Impl( sal_Bool bScriptingContent, const ::rtl::OUString& aODFVersion, sal_Bool bHasValidDocumentSignature ) { - DBG_ASSERT( GetStorage().is(), "SfxMedium::SignContents_Impl - Storage doesn't exist!" ); - sal_Bool bChanges = FALSE; - ::com::sun::star::uno::Reference< ::com::sun::star::security::XDocumentDigitalSignatures > xD( - comphelper::getProcessServiceFactory()->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ) ), ::com::sun::star::uno::UNO_QUERY ); - - // TODO/LATER: error handling - if ( xD.is() && GetStorage().is() ) + // the medium should be closed to be able to sign, the caller is responsible to close it + if ( !IsOpen() && !GetError() ) { - sal_Int32 nEncrMode = IsReadOnly() ? embed::ElementModes::READ - : embed::ElementModes::READWRITE; + // The component should know if there was a valid document signature, since + // it should show a warning in this case + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[0] <<= aODFVersion; + aArgs[1] <<= bHasValidDocumentSignature; + ::com::sun::star::uno::Reference< ::com::sun::star::security::XDocumentDigitalSignatures > xSigner( + comphelper::getProcessServiceFactory()->createInstanceWithArguments( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), + aArgs ), + ::com::sun::star::uno::UNO_QUERY ); - try + if ( xSigner.is() ) { - uno::Reference< embed::XStorage > xMetaInf = GetStorage()->openStorageElement( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ), - nEncrMode ); - if ( !xMetaInf.is() ) - throw uno::RuntimeException(); - - if ( bScriptingContent ) + uno::Reference< embed::XStorage > xWriteableZipStor; + if ( !IsReadOnly() ) { - if ( !IsReadOnly() ) + // we can reuse the temporary file if there is one already + CreateTempFile( sal_False ); + GetMedium_Impl(); + + try { - uno::Reference< io::XStream > xStream = xMetaInf->openStreamElement( - xD->getScriptingContentSignatureDefaultStreamName(), - nEncrMode ); - if ( !xStream.is() ) + if ( !pImp->xStream.is() ) throw uno::RuntimeException(); - try + xWriteableZipStor = ::comphelper::OStorageHelper::GetStorageOfFormatFromStream( ZIP_STORAGE_FORMAT_STRING, pImp->xStream ); + if ( !xWriteableZipStor.is() ) + throw uno::RuntimeException(); + + uno::Reference< embed::XStorage > xMetaInf = xWriteableZipStor->openStorageElement( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ), + embed::ElementModes::READWRITE ); + if ( !xMetaInf.is() ) + throw uno::RuntimeException(); + + if ( bScriptingContent ) { - // to leave the stream unencrypted as before - uno::Reference< beans::XPropertySet > xStrmProps( xStream, uno::UNO_QUERY_THROW ); - xStrmProps->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ), - uno::makeAny( (sal_Bool)sal_False ) ); + // If the signature has already the document signature it will be removed + // after the scripting signature is inserted. + uno::Reference< io::XStream > xStream( + xMetaInf->openStreamElement( xSigner->getScriptingContentSignatureDefaultStreamName(), + embed::ElementModes::READWRITE ), + uno::UNO_SET_THROW ); + + if ( xSigner->signScriptingContent( GetZipStorageToSign_Impl(), xStream ) ) + { + // remove the document signature if any + ::rtl::OUString aDocSigName = xSigner->getDocumentContentSignatureDefaultStreamName(); + if ( aDocSigName.getLength() && xMetaInf->hasByName( aDocSigName ) ) + xMetaInf->removeElement( aDocSigName ); + + uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW ); + xTransact->commit(); + xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW ); + xTransact->commit(); + + // the temporary file has been written, commit it to the original file + Commit(); + bChanges = TRUE; + } } - catch ( uno::Exception& ) - {} - - if ( xD->signScriptingContent( GetLastCommitReadStorage_Impl(), xStream ) ) + else { - uno::Reference< embed::XTransactedObject > xTrans( xMetaInf, uno::UNO_QUERY ); - xTrans->commit(); - Commit(); - bChanges = TRUE; + uno::Reference< io::XStream > xStream( + xMetaInf->openStreamElement( xSigner->getDocumentContentSignatureDefaultStreamName(), + embed::ElementModes::READWRITE ), + uno::UNO_SET_THROW ); + + if ( xSigner->signDocumentContent( GetZipStorageToSign_Impl(), xStream ) ) + { + uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW ); + xTransact->commit(); + xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW ); + xTransact->commit(); + + // the temporary file has been written, commit it to the original file + Commit(); + bChanges = TRUE; + } } } - else - xD->showScriptingContentSignatures( GetLastCommitReadStorage_Impl(), uno::Reference< io::XInputStream >() ); + catch ( uno::Exception& ) + { + OSL_ENSURE( sal_False, "Couldn't use signing functionality!\n" ); + } + + CloseAndRelease(); } else { - if ( !IsReadOnly() ) + try { - uno::Reference< io::XStream > xStream = xMetaInf->openStreamElement( - xD->getDocumentContentSignatureDefaultStreamName(), - nEncrMode ); - if ( !xStream.is() ) - throw uno::RuntimeException(); - - try - { - // to leave the stream unencrypted as before - uno::Reference< beans::XPropertySet > xStrmProps( xStream, uno::UNO_QUERY_THROW ); - xStrmProps->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ), - uno::makeAny( (sal_Bool)sal_False ) ); - } - catch ( uno::Exception& ) - {} - - if ( xD->signDocumentContent( GetLastCommitReadStorage_Impl(), xStream ) ) - { - uno::Reference< embed::XTransactedObject > xTrans( xMetaInf, uno::UNO_QUERY ); - xTrans->commit(); - Commit(); - bChanges = TRUE; - } - + if ( bScriptingContent ) + xSigner->showScriptingContentSignatures( GetZipStorageToSign_Impl(), uno::Reference< io::XInputStream >() ); + else + xSigner->showDocumentContentSignatures( GetZipStorageToSign_Impl(), uno::Reference< io::XInputStream >() ); + } + catch( uno::Exception& ) + { + OSL_ENSURE( sal_False, "Couldn't use signing functionality!\n" ); } - else - xD->showDocumentContentSignatures( GetLastCommitReadStorage_Impl(), uno::Reference< io::XInputStream >() ); } } - catch( uno::Exception& ) - { - OSL_ENSURE( sal_False, "Couldn't use signing functionality!\n" ); - } + + ResetError(); } + return bChanges; } @@ -4152,6 +3779,38 @@ BOOL SfxMedium::IsOpen() const return aResult; } +sal_Bool SfxMedium::CallApproveHandler( const uno::Reference< task::XInteractionHandler >& xHandler, uno::Any aRequest, sal_Bool bAllowAbort ) +{ + sal_Bool bResult = sal_False; + + if ( xHandler.is() ) + { + try + { + uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( bAllowAbort ? 2 : 1 ); + + ::rtl::Reference< ::framework::ContinuationApprove > pApprove( new ::framework::ContinuationApprove() ); + aContinuations[ 0 ] = pApprove.get(); + + if ( bAllowAbort ) + { + ::rtl::Reference< ::framework::ContinuationAbort > pAbort( new ::framework::ContinuationAbort() ); + aContinuations[ 1 ] = pAbort.get(); + } + + uno::Reference< task::XInteractionRequest > xRequest( new ::framework::InteractionRequest( aRequest, aContinuations ) ); + xHandler->handle( xRequest ); + + bResult = pApprove->isSelected(); + } + catch( const Exception& ) + { + } + } + + return bResult; +} + ::rtl::OUString SfxMedium::SwitchDocumentToTempFile() { // the method returns empty string in case of failure @@ -4189,7 +3848,7 @@ BOOL SfxMedium::IsOpen() const GetMedium_Impl(); LockOrigFileOnDemand( sal_False, sal_False ); - CreateTempFile(); + CreateTempFile( sal_True ); GetMedium_Impl(); if ( pImp->xStream.is() ) @@ -4247,7 +3906,7 @@ sal_Bool SfxMedium::SwitchDocumentToFile( ::rtl::OUString aURL ) // open the temporary file based document GetMedium_Impl(); LockOrigFileOnDemand( sal_False, sal_False ); - CreateTempFile(); + CreateTempFile( sal_True ); GetMedium_Impl(); if ( pImp->xStream.is() ) |