1cdf0e10cSrcweir /************************************************************************* 2cdf0e10cSrcweir * 3cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4cdf0e10cSrcweir * 5cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6cdf0e10cSrcweir * 7cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8cdf0e10cSrcweir * 9cdf0e10cSrcweir * This file is part of OpenOffice.org. 10cdf0e10cSrcweir * 11cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14cdf0e10cSrcweir * 15cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20cdf0e10cSrcweir * 21cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25cdf0e10cSrcweir * 26cdf0e10cSrcweir ************************************************************************/ 27cdf0e10cSrcweir 28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30cdf0e10cSrcweir #include <sfx2/docfile.hxx> 31cdf0e10cSrcweir #include "sfx2/signaturestate.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <uno/mapping.hxx> 34cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 35cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h> 36cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 37cdf0e10cSrcweir #include <com/sun/star/document/XDocumentRevisionListPersistence.hpp> 38cdf0e10cSrcweir #include <com/sun/star/document/LockedDocumentRequest.hpp> 39cdf0e10cSrcweir #include <com/sun/star/document/OwnLockOnDocumentRequest.hpp> 40cdf0e10cSrcweir #include <com/sun/star/document/LockedOnSavingRequest.hpp> 41cdf0e10cSrcweir #include <com/sun/star/document/LockFileIgnoreRequest.hpp> 42cdf0e10cSrcweir #include <com/sun/star/document/ChangedByOthersRequest.hpp> 43cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 44cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp> 45cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 46cdf0e10cSrcweir #include <com/sun/star/embed/UseBackupException.hpp> 47cdf0e10cSrcweir #include <com/sun/star/embed/XOptimizedStorage.hpp> 48cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveIOException.hpp> 49cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp> 50cdf0e10cSrcweir #include <com/sun/star/ucb/CommandFailedException.hpp> 51cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp> 52cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp> 53cdf0e10cSrcweir #include <com/sun/star/ucb/XContentIdentifierFactory.hpp> 54cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp> 55cdf0e10cSrcweir #include <com/sun/star/ucb/XProgressHandler.hpp> 56cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp> 57cdf0e10cSrcweir #include <com/sun/star/util/XArchiver.hpp> 58cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 59cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 60cdf0e10cSrcweir #include <com/sun/star/io/XTruncate.hpp> 61cdf0e10cSrcweir #include <com/sun/star/io/XStreamListener.hpp> 62cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 63cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 64cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 65cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp> 66cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp> 67cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp> 68cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp> 69cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp> 70cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp> 71cdf0e10cSrcweir #include <com/sun/star/logging/XSimpleLogRing.hpp> 72cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 73cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 74cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SECURITY_DOCUMENTSIGNATURESINFORMATION_HPP_ 75cdf0e10cSrcweir #include <com/sun/star/security/DocumentSignatureInformation.hpp> 76cdf0e10cSrcweir #endif 77cdf0e10cSrcweir #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> 78cdf0e10cSrcweir #include <tools/zcodec.hxx> 79cdf0e10cSrcweir #include <tools/cachestr.hxx> 80cdf0e10cSrcweir #include <tools/urlobj.hxx> 81cdf0e10cSrcweir #include <unotools/tempfile.hxx> 82cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 83cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 84cdf0e10cSrcweir #include <comphelper/interaction.hxx> 85cdf0e10cSrcweir #include <framework/interaction.hxx> 86cdf0e10cSrcweir #include <unotools/streamhelper.hxx> 87cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx> 88cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen 89cdf0e10cSrcweir #include <vcl/msgbox.hxx> 90cdf0e10cSrcweir #endif 91cdf0e10cSrcweir #include <svl/stritem.hxx> 92cdf0e10cSrcweir #include <svl/eitem.hxx> 93cdf0e10cSrcweir #include <svl/lckbitem.hxx> 94cdf0e10cSrcweir #include <svtools/sfxecode.hxx> 95cdf0e10cSrcweir #include <svl/itemset.hxx> 96cdf0e10cSrcweir #include <svl/intitem.hxx> 97cdf0e10cSrcweir #include <svtools/svparser.hxx> // SvKeyValue 98cdf0e10cSrcweir #include <cppuhelper/weakref.hxx> 99cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 100cdf0e10cSrcweir 101cdf0e10cSrcweir #define _SVSTDARR_ULONGS 102cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR 103cdf0e10cSrcweir #include <svl/svstdarr.hxx> 104cdf0e10cSrcweir 105cdf0e10cSrcweir #include <unotools/streamwrap.hxx> 106cdf0e10cSrcweir 107cdf0e10cSrcweir #include <rtl/logfile.hxx> 108cdf0e10cSrcweir #include <osl/file.hxx> 109cdf0e10cSrcweir 110cdf0e10cSrcweir using namespace ::com::sun::star; 111cdf0e10cSrcweir using namespace ::com::sun::star::uno; 112cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 113cdf0e10cSrcweir using namespace ::com::sun::star::beans; 114cdf0e10cSrcweir using namespace ::com::sun::star::io; 115cdf0e10cSrcweir 116cdf0e10cSrcweir #include <comphelper/storagehelper.hxx> 117cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx> 118cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx> 119cdf0e10cSrcweir #include <comphelper/docpasswordhelper.hxx> 120cdf0e10cSrcweir #include <tools/urlobj.hxx> 121cdf0e10cSrcweir #include <tools/inetmime.hxx> 122cdf0e10cSrcweir #include <unotools/ucblockbytes.hxx> 123cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 124cdf0e10cSrcweir #include <svtools/asynclink.hxx> 125cdf0e10cSrcweir #include <svl/inettype.hxx> 126cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx> 127cdf0e10cSrcweir #include <ucbhelper/commandenvironment.hxx> 128cdf0e10cSrcweir #include <unotools/localfilehelper.hxx> 129cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 130cdf0e10cSrcweir #include <unotools/ucbhelper.hxx> 131cdf0e10cSrcweir #include <unotools/progresshandlerwrap.hxx> 132cdf0e10cSrcweir #include <ucbhelper/content.hxx> 133cdf0e10cSrcweir #include <ucbhelper/interactionrequest.hxx> 134cdf0e10cSrcweir #include <sot/stg.hxx> 135cdf0e10cSrcweir #include <unotools/saveopt.hxx> 136cdf0e10cSrcweir #include <svl/documentlockfile.hxx> 137cdf0e10cSrcweir 138cdf0e10cSrcweir #include "helper.hxx" 139cdf0e10cSrcweir #include <sfx2/request.hxx> // SFX_ITEMSET_SET 140cdf0e10cSrcweir #include <sfx2/app.hxx> // GetFilterMatcher 141cdf0e10cSrcweir #include <sfx2/frame.hxx> // LoadTargetFrame 142cdf0e10cSrcweir #include "fltfnc.hxx" // SfxFilterMatcher 143cdf0e10cSrcweir #include <sfx2/docfilt.hxx> // SfxFilter 144cdf0e10cSrcweir #include <sfx2/objsh.hxx> // CheckOpenMode 145cdf0e10cSrcweir #include <sfx2/docfac.hxx> // GetFilterContainer 146cdf0e10cSrcweir #include "doc.hrc" 147cdf0e10cSrcweir #include "openflag.hxx" // SFX_STREAM_READONLY etc. 148cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 149cdf0e10cSrcweir #include <sfx2/appuno.hxx> 150cdf0e10cSrcweir 151cdf0e10cSrcweir //#include "xmlversion.hxx" 152cdf0e10cSrcweir 153cdf0e10cSrcweir #define MAX_REDIRECT 5 154cdf0e10cSrcweir 155cdf0e10cSrcweir 156cdf0e10cSrcweir sal_Bool IsReadonlyAccordingACL( const sal_Unicode* pFilePath ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir //========================================================== 159cdf0e10cSrcweir namespace { 160cdf0e10cSrcweir 161cdf0e10cSrcweir static const sal_Int8 LOCK_UI_NOLOCK = 0; 162cdf0e10cSrcweir static const sal_Int8 LOCK_UI_SUCCEEDED = 1; 163cdf0e10cSrcweir static const sal_Int8 LOCK_UI_TRY = 2; 164cdf0e10cSrcweir 165cdf0e10cSrcweir //---------------------------------------------------------------- 166cdf0e10cSrcweir sal_Bool IsSystemFileLockingUsed() 167cdf0e10cSrcweir { 168cdf0e10cSrcweir // check whether system file locking has been used, the default value is false 169cdf0e10cSrcweir sal_Bool bUseSystemLock = sal_False; 170cdf0e10cSrcweir try 171cdf0e10cSrcweir { 172cdf0e10cSrcweir 173cdf0e10cSrcweir uno::Reference< uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig( 174cdf0e10cSrcweir ::comphelper::getProcessServiceFactory(), 175cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ), 176cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_STANDARD ); 177cdf0e10cSrcweir if ( !xCommonConfig.is() ) 178cdf0e10cSrcweir throw uno::RuntimeException(); 179cdf0e10cSrcweir 180cdf0e10cSrcweir ::comphelper::ConfigurationHelper::readRelativeKey( 181cdf0e10cSrcweir xCommonConfig, 182cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ), 183cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentSystemFileLocking" ) ) ) >>= bUseSystemLock; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir catch( const uno::Exception& ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir return bUseSystemLock; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir //---------------------------------------------------------------- 193cdf0e10cSrcweir sal_Bool IsOOoLockFileUsed() 194cdf0e10cSrcweir { 195cdf0e10cSrcweir // check whether system file locking has been used, the default value is false 196cdf0e10cSrcweir sal_Bool bOOoLockFileUsed = sal_False; 197cdf0e10cSrcweir try 198cdf0e10cSrcweir { 199cdf0e10cSrcweir 200cdf0e10cSrcweir uno::Reference< uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig( 201cdf0e10cSrcweir ::comphelper::getProcessServiceFactory(), 202cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ), 203cdf0e10cSrcweir ::comphelper::ConfigurationHelper::E_STANDARD ); 204cdf0e10cSrcweir if ( !xCommonConfig.is() ) 205cdf0e10cSrcweir throw uno::RuntimeException(); 206cdf0e10cSrcweir 207cdf0e10cSrcweir ::comphelper::ConfigurationHelper::readRelativeKey( 208cdf0e10cSrcweir xCommonConfig, 209cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ), 210cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentOOoLockFile" ) ) ) >>= bOOoLockFileUsed; 211cdf0e10cSrcweir } 212cdf0e10cSrcweir catch( const uno::Exception& ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir return bOOoLockFileUsed; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir } // anonymous namespace 220cdf0e10cSrcweir //========================================================== 221cdf0e10cSrcweir 222cdf0e10cSrcweir 223cdf0e10cSrcweir //---------------------------------------------------------------- 224cdf0e10cSrcweir class SfxMediumHandler_Impl : public ::cppu::WeakImplHelper1< com::sun::star::task::XInteractionHandler > 225cdf0e10cSrcweir { 226cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInter; 227cdf0e10cSrcweir 228cdf0e10cSrcweir public: 229cdf0e10cSrcweir virtual void SAL_CALL handle( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& xRequest ) 230cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 231cdf0e10cSrcweir 232cdf0e10cSrcweir SfxMediumHandler_Impl( com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > xInteraction ) 233cdf0e10cSrcweir : m_xInter( xInteraction ) 234cdf0e10cSrcweir {} 235cdf0e10cSrcweir 236cdf0e10cSrcweir ~SfxMediumHandler_Impl(); 237cdf0e10cSrcweir }; 238cdf0e10cSrcweir 239cdf0e10cSrcweir //---------------------------------------------------------------- 240cdf0e10cSrcweir SfxMediumHandler_Impl::~SfxMediumHandler_Impl() 241cdf0e10cSrcweir { 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir //---------------------------------------------------------------- 245cdf0e10cSrcweir void SAL_CALL SfxMediumHandler_Impl::handle( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& xRequest ) 246cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir if( !m_xInter.is() ) 249cdf0e10cSrcweir return; 250cdf0e10cSrcweir 251cdf0e10cSrcweir com::sun::star::uno::Any aRequest = xRequest->getRequest(); 252cdf0e10cSrcweir com::sun::star::ucb::InteractiveIOException aIoException; 253cdf0e10cSrcweir com::sun::star::ucb::UnsupportedDataSinkException aSinkException; 254cdf0e10cSrcweir if ( (aRequest >>= aIoException) && ( aIoException.Code == IOErrorCode_ACCESS_DENIED || aIoException.Code == IOErrorCode_LOCKING_VIOLATION ) ) 255cdf0e10cSrcweir return; 256cdf0e10cSrcweir else 257cdf0e10cSrcweir if ( aRequest >>= aSinkException ) 258cdf0e10cSrcweir return; 259cdf0e10cSrcweir else 260cdf0e10cSrcweir m_xInter->handle( xRequest ); 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir //---------------------------------------------------------------- 264cdf0e10cSrcweir class SfxMedium_Impl : public SvCompatWeakBase 265cdf0e10cSrcweir { 266cdf0e10cSrcweir public: 267cdf0e10cSrcweir ::ucbhelper::Content aContent; 268cdf0e10cSrcweir sal_Bool bUpdatePickList : 1; 269cdf0e10cSrcweir sal_Bool bIsTemp : 1; 270cdf0e10cSrcweir sal_Bool bForceSynchron : 1; 271cdf0e10cSrcweir sal_Bool bDownloadDone : 1; 272cdf0e10cSrcweir sal_Bool bDontCallDoneLinkOnSharingError : 1; 273cdf0e10cSrcweir sal_Bool bIsStorage: 1; 274cdf0e10cSrcweir sal_Bool bUseInteractionHandler: 1; 275cdf0e10cSrcweir sal_Bool bAllowDefaultIntHdl: 1; 276cdf0e10cSrcweir sal_Bool bIsCharsetInitialized: 1; 277cdf0e10cSrcweir sal_Bool bDisposeStorage: 1; 278cdf0e10cSrcweir sal_Bool bStorageBasedOnInStream: 1; 279cdf0e10cSrcweir sal_Bool m_bSalvageMode: 1; 280cdf0e10cSrcweir sal_Bool m_bVersionsAlreadyLoaded: 1; 281cdf0e10cSrcweir sal_Bool m_bLocked: 1; 282cdf0e10cSrcweir sal_Bool m_bGotDateTime: 1; 283cdf0e10cSrcweir 284cdf0e10cSrcweir uno::Reference < embed::XStorage > xStorage; 285cdf0e10cSrcweir 286cdf0e10cSrcweir SfxMedium* pAntiImpl; 287cdf0e10cSrcweir 288cdf0e10cSrcweir long nFileVersion; 289cdf0e10cSrcweir 290cdf0e10cSrcweir const SfxFilter* pOrigFilter; 291cdf0e10cSrcweir String aOrigURL; 292cdf0e10cSrcweir String aPreRedirectionURL; 293cdf0e10cSrcweir String aReferer; 294cdf0e10cSrcweir DateTime aExpireTime; 295cdf0e10cSrcweir SfxFrameWeak wLoadTargetFrame; 296cdf0e10cSrcweir SvKeyValueIteratorRef xAttributes; 297cdf0e10cSrcweir 298cdf0e10cSrcweir svtools::AsynchronLink aDoneLink; 299cdf0e10cSrcweir svtools::AsynchronLink aAvailableLink; 300cdf0e10cSrcweir 301cdf0e10cSrcweir uno::Sequence < util::RevisionTag > aVersions; 302cdf0e10cSrcweir 303cdf0e10cSrcweir ::utl::TempFile* pTempFile; 304cdf0e10cSrcweir 305cdf0e10cSrcweir uno::Reference < embed::XStorage > m_xZipStorage; 306cdf0e10cSrcweir Reference < XInputStream > xInputStream; 307cdf0e10cSrcweir Reference < XStream > xStream; 308cdf0e10cSrcweir 309cdf0e10cSrcweir uno::Reference< io::XStream > m_xLockingStream; 310cdf0e10cSrcweir 311cdf0e10cSrcweir sal_uInt32 nLastStorageError; 312cdf0e10cSrcweir ::rtl::OUString aCharset; 313cdf0e10cSrcweir 314cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xInteraction; 315cdf0e10cSrcweir 316cdf0e10cSrcweir sal_Bool m_bRemoveBackup; 317cdf0e10cSrcweir ::rtl::OUString m_aBackupURL; 318cdf0e10cSrcweir 319cdf0e10cSrcweir // the following member is changed and makes sence only during saving 320cdf0e10cSrcweir // TODO/LATER: in future the signature state should be controlled by the medium not by the document 321cdf0e10cSrcweir // in this case the member will hold this information 322cdf0e10cSrcweir sal_uInt16 m_nSignatureState; 323cdf0e10cSrcweir 324cdf0e10cSrcweir util::DateTime m_aDateTime; 325cdf0e10cSrcweir 326cdf0e10cSrcweir uno::Reference< logging::XSimpleLogRing > m_xLogRing; 327cdf0e10cSrcweir 328cdf0e10cSrcweir SfxMedium_Impl( SfxMedium* pAntiImplP ); 329cdf0e10cSrcweir ~SfxMedium_Impl(); 330cdf0e10cSrcweir }; 331cdf0e10cSrcweir 332cdf0e10cSrcweir void SfxMedium::DataAvailable_Impl() 333cdf0e10cSrcweir { 334cdf0e10cSrcweir pImp->aAvailableLink.ClearPendingCall(); 335cdf0e10cSrcweir pImp->aAvailableLink.Call( NULL ); 336cdf0e10cSrcweir } 337cdf0e10cSrcweir 338cdf0e10cSrcweir void SfxMedium::Cancel_Impl() 339cdf0e10cSrcweir { 340cdf0e10cSrcweir SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir //------------------------------------------------------------------ 344cdf0e10cSrcweir SfxMedium_Impl::SfxMedium_Impl( SfxMedium* pAntiImplP ) 345cdf0e10cSrcweir : SvCompatWeakBase( pAntiImplP ), 346cdf0e10cSrcweir bUpdatePickList(sal_True), 347cdf0e10cSrcweir bIsTemp( sal_False ), 348cdf0e10cSrcweir bForceSynchron( sal_False ), 349cdf0e10cSrcweir bDownloadDone( sal_True ), 350cdf0e10cSrcweir bDontCallDoneLinkOnSharingError( sal_False ), 351cdf0e10cSrcweir bIsStorage( sal_False ), 352cdf0e10cSrcweir bUseInteractionHandler( sal_True ), 353cdf0e10cSrcweir bAllowDefaultIntHdl( sal_False ), 354cdf0e10cSrcweir bIsCharsetInitialized( sal_False ), 355cdf0e10cSrcweir bStorageBasedOnInStream( sal_False ), 356cdf0e10cSrcweir m_bSalvageMode( sal_False ), 357cdf0e10cSrcweir m_bVersionsAlreadyLoaded( sal_False ), 358cdf0e10cSrcweir m_bLocked( sal_False ), 359cdf0e10cSrcweir m_bGotDateTime( sal_False ), 360cdf0e10cSrcweir pAntiImpl( pAntiImplP ), 361cdf0e10cSrcweir nFileVersion( 0 ), 362cdf0e10cSrcweir pOrigFilter( 0 ), 363cdf0e10cSrcweir aExpireTime( Date() + 10, Time() ), 364cdf0e10cSrcweir pTempFile( NULL ), 365cdf0e10cSrcweir nLastStorageError( 0 ), 366cdf0e10cSrcweir m_bRemoveBackup( sal_False ), 367cdf0e10cSrcweir m_nSignatureState( SIGNATURESTATE_NOSIGNATURES ) 368cdf0e10cSrcweir { 369cdf0e10cSrcweir aDoneLink.CreateMutex(); 370cdf0e10cSrcweir } 371cdf0e10cSrcweir 372cdf0e10cSrcweir //------------------------------------------------------------------ 373cdf0e10cSrcweir SfxMedium_Impl::~SfxMedium_Impl() 374cdf0e10cSrcweir { 375cdf0e10cSrcweir 376cdf0e10cSrcweir aDoneLink.ClearPendingCall(); 377cdf0e10cSrcweir aAvailableLink.ClearPendingCall(); 378cdf0e10cSrcweir 379cdf0e10cSrcweir if ( pTempFile ) 380cdf0e10cSrcweir delete pTempFile; 381cdf0e10cSrcweir } 382cdf0e10cSrcweir 383cdf0e10cSrcweir //================================================================ 384cdf0e10cSrcweir 385cdf0e10cSrcweir #define IMPL_CTOR(rootVal,URLVal) \ 386cdf0e10cSrcweir eError( SVSTREAM_OK ), \ 387cdf0e10cSrcweir \ 388cdf0e10cSrcweir bDirect( sal_False ), \ 389cdf0e10cSrcweir bRoot( rootVal ), \ 390cdf0e10cSrcweir bSetFilter( sal_False ), \ 391cdf0e10cSrcweir bTriedStorage( sal_False ), \ 392cdf0e10cSrcweir \ 393cdf0e10cSrcweir nStorOpenMode( SFX_STREAM_READWRITE ), \ 394cdf0e10cSrcweir pURLObj( URLVal ), \ 395cdf0e10cSrcweir pInStream(0), \ 396cdf0e10cSrcweir pOutStream( 0 ) 397cdf0e10cSrcweir 398cdf0e10cSrcweir //------------------------------------------------------------------ 399cdf0e10cSrcweir void SfxMedium::ResetError() 400cdf0e10cSrcweir { 401cdf0e10cSrcweir eError = SVSTREAM_OK; 402cdf0e10cSrcweir if( pInStream ) 403cdf0e10cSrcweir pInStream->ResetError(); 404cdf0e10cSrcweir if( pOutStream ) 405cdf0e10cSrcweir pOutStream->ResetError(); 406cdf0e10cSrcweir } 407cdf0e10cSrcweir 408cdf0e10cSrcweir //------------------------------------------------------------------ 409cdf0e10cSrcweir sal_uInt32 SfxMedium::GetLastStorageCreationState() 410cdf0e10cSrcweir { 411cdf0e10cSrcweir return pImp->nLastStorageError; 412cdf0e10cSrcweir } 413cdf0e10cSrcweir 414cdf0e10cSrcweir //------------------------------------------------------------------ 415cdf0e10cSrcweir void SfxMedium::AddLog( const ::rtl::OUString& aMessage ) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir if ( !pImp->m_xLogRing.is() ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir try 420cdf0e10cSrcweir { 421cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 422cdf0e10cSrcweir if ( aContext.is() ) 423cdf0e10cSrcweir pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW ); 424cdf0e10cSrcweir } 425cdf0e10cSrcweir catch( uno::Exception& ) 426cdf0e10cSrcweir {} 427cdf0e10cSrcweir } 428cdf0e10cSrcweir 429cdf0e10cSrcweir if ( pImp->m_xLogRing.is() ) 430cdf0e10cSrcweir pImp->m_xLogRing->logString( aMessage ); 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir //------------------------------------------------------------------ 434cdf0e10cSrcweir void SfxMedium::SetError( sal_uInt32 nError, const ::rtl::OUString& aLogMessage ) 435cdf0e10cSrcweir { 436cdf0e10cSrcweir eError = nError; 437cdf0e10cSrcweir if ( eError != ERRCODE_NONE && aLogMessage.getLength() ) 438cdf0e10cSrcweir AddLog( aLogMessage ); 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir //------------------------------------------------------------------ 442cdf0e10cSrcweir sal_uInt32 SfxMedium::GetErrorCode() const 443cdf0e10cSrcweir { 444cdf0e10cSrcweir sal_uInt32 lError=eError; 445cdf0e10cSrcweir if(!lError && pInStream) 446cdf0e10cSrcweir lError=pInStream->GetErrorCode(); 447cdf0e10cSrcweir if(!lError && pOutStream) 448cdf0e10cSrcweir lError=pOutStream->GetErrorCode(); 449cdf0e10cSrcweir return lError; 450cdf0e10cSrcweir } 451cdf0e10cSrcweir 452cdf0e10cSrcweir //------------------------------------------------------------------ 453cdf0e10cSrcweir void SfxMedium::CheckFileDate( const util::DateTime& aInitDate ) 454cdf0e10cSrcweir { 455cdf0e10cSrcweir GetInitFileDate( sal_True ); 456cdf0e10cSrcweir if ( pImp->m_aDateTime.Seconds != aInitDate.Seconds 457cdf0e10cSrcweir || pImp->m_aDateTime.Minutes != aInitDate.Minutes 458cdf0e10cSrcweir || pImp->m_aDateTime.Hours != aInitDate.Hours 459cdf0e10cSrcweir || pImp->m_aDateTime.Day != aInitDate.Day 460cdf0e10cSrcweir || pImp->m_aDateTime.Month != aInitDate.Month 461cdf0e10cSrcweir || pImp->m_aDateTime.Year != aInitDate.Year ) 462cdf0e10cSrcweir { 463cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler(); 464cdf0e10cSrcweir 465cdf0e10cSrcweir if ( xHandler.is() ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir try 468cdf0e10cSrcweir { 469cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionRequest > xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( 470cdf0e10cSrcweir document::ChangedByOthersRequest() ) ); 471cdf0e10cSrcweir uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 3 ); 472cdf0e10cSrcweir aContinuations[0] = new ::ucbhelper::InteractionAbort( xInteractionRequestImpl.get() ); 473cdf0e10cSrcweir aContinuations[1] = new ::ucbhelper::InteractionApprove( xInteractionRequestImpl.get() ); 474cdf0e10cSrcweir xInteractionRequestImpl->setContinuations( aContinuations ); 475cdf0e10cSrcweir 476cdf0e10cSrcweir xHandler->handle( xInteractionRequestImpl.get() ); 477cdf0e10cSrcweir 478cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xInteractionRequestImpl->getSelection(); 479cdf0e10cSrcweir if ( uno::Reference< task::XInteractionAbort >( xSelected.get(), uno::UNO_QUERY ).is() ) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 482cdf0e10cSrcweir } 483cdf0e10cSrcweir } 484cdf0e10cSrcweir catch ( uno::Exception& ) 485cdf0e10cSrcweir {} 486cdf0e10cSrcweir } 487cdf0e10cSrcweir } 488cdf0e10cSrcweir } 489cdf0e10cSrcweir 490cdf0e10cSrcweir //------------------------------------------------------------------ 491cdf0e10cSrcweir sal_Bool SfxMedium::DocNeedsFileDateCheck() 492cdf0e10cSrcweir { 493cdf0e10cSrcweir return ( !IsReadOnly() && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ); 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir //------------------------------------------------------------------ 497cdf0e10cSrcweir util::DateTime SfxMedium::GetInitFileDate( sal_Bool bIgnoreOldValue ) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir if ( ( bIgnoreOldValue || !pImp->m_bGotDateTime ) && aLogicName.Len() ) 500cdf0e10cSrcweir { 501cdf0e10cSrcweir try 502cdf0e10cSrcweir { 503cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 504cdf0e10cSrcweir ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); 505cdf0e10cSrcweir 506cdf0e10cSrcweir aContent.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "DateModified" )) ) >>= pImp->m_aDateTime; 507cdf0e10cSrcweir pImp->m_bGotDateTime = sal_True; 508cdf0e10cSrcweir } 509cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir } 512cdf0e10cSrcweir } 513cdf0e10cSrcweir 514cdf0e10cSrcweir return pImp->m_aDateTime; 515cdf0e10cSrcweir } 516cdf0e10cSrcweir 517cdf0e10cSrcweir //------------------------------------------------------------------ 518cdf0e10cSrcweir Reference < XContent > SfxMedium::GetContent() const 519cdf0e10cSrcweir { 520cdf0e10cSrcweir if ( !pImp->aContent.get().is() ) 521cdf0e10cSrcweir { 522cdf0e10cSrcweir Reference < ::com::sun::star::ucb::XContent > xContent; 523cdf0e10cSrcweir Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; 524cdf0e10cSrcweir 525cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pItem, SfxUnoAnyItem, SID_CONTENT, sal_False); 526cdf0e10cSrcweir if ( pItem ) 527cdf0e10cSrcweir pItem->GetValue() >>= xContent; 528cdf0e10cSrcweir 529cdf0e10cSrcweir if ( xContent.is() ) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir try 532cdf0e10cSrcweir { 533cdf0e10cSrcweir pImp->aContent = ::ucbhelper::Content( xContent, xEnv ); 534cdf0e10cSrcweir } 535cdf0e10cSrcweir catch ( Exception& ) 536cdf0e10cSrcweir { 537cdf0e10cSrcweir } 538cdf0e10cSrcweir } 539cdf0e10cSrcweir else 540cdf0e10cSrcweir { 541cdf0e10cSrcweir // TODO: DBG_ERROR("SfxMedium::GetContent()\nCreate Content? This code exists as fallback only. Please clarify, why its used."); 542cdf0e10cSrcweir String aURL; 543cdf0e10cSrcweir if ( aName.Len() ) 544cdf0e10cSrcweir ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aURL ); 545cdf0e10cSrcweir else if ( aLogicName.Len() ) 546cdf0e10cSrcweir aURL = GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 547cdf0e10cSrcweir if ( aURL.Len() ) 548cdf0e10cSrcweir ::ucbhelper::Content::create( aURL, xEnv, pImp->aContent ); 549cdf0e10cSrcweir } 550cdf0e10cSrcweir } 551cdf0e10cSrcweir 552cdf0e10cSrcweir return pImp->aContent.get(); 553cdf0e10cSrcweir } 554cdf0e10cSrcweir 555cdf0e10cSrcweir //------------------------------------------------------------------ 556cdf0e10cSrcweir ::rtl::OUString SfxMedium::GetBaseURL( bool bForSaving ) 557cdf0e10cSrcweir { 558cdf0e10cSrcweir ::rtl::OUString aBaseURL; 559cdf0e10cSrcweir const SfxStringItem* pBaseURLItem = static_cast<const SfxStringItem*>( GetItemSet()->GetItem(SID_DOC_BASEURL) ); 560cdf0e10cSrcweir if ( pBaseURLItem ) 561cdf0e10cSrcweir aBaseURL = pBaseURLItem->GetValue(); 562cdf0e10cSrcweir else if ( GetContent().is() ) 563cdf0e10cSrcweir { 564cdf0e10cSrcweir try 565cdf0e10cSrcweir { 566cdf0e10cSrcweir Any aAny = pImp->aContent.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI" )) ); 567cdf0e10cSrcweir aAny >>= aBaseURL; 568cdf0e10cSrcweir } 569cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 570cdf0e10cSrcweir { 571cdf0e10cSrcweir } 572cdf0e10cSrcweir 573cdf0e10cSrcweir if ( !aBaseURL.getLength() ) 574cdf0e10cSrcweir aBaseURL = GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 575cdf0e10cSrcweir } 576cdf0e10cSrcweir 577cdf0e10cSrcweir if ( bForSaving ) 578cdf0e10cSrcweir { 579cdf0e10cSrcweir SvtSaveOptions aOpt; 580cdf0e10cSrcweir sal_Bool bIsRemote = IsRemote(); 581cdf0e10cSrcweir if( (bIsRemote && !aOpt.IsSaveRelINet()) || (!bRemote && !aOpt.IsSaveRelFSys()) ) 582cdf0e10cSrcweir return ::rtl::OUString(); 583cdf0e10cSrcweir } 584cdf0e10cSrcweir 585cdf0e10cSrcweir return aBaseURL; 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir //------------------------------------------------------------------ 589cdf0e10cSrcweir SvStream* SfxMedium::GetInStream() 590cdf0e10cSrcweir { 591cdf0e10cSrcweir if ( pInStream ) 592cdf0e10cSrcweir return pInStream; 593cdf0e10cSrcweir 594cdf0e10cSrcweir if ( pImp->pTempFile ) 595cdf0e10cSrcweir { 596cdf0e10cSrcweir pInStream = new SvFileStream( aName, nStorOpenMode ); 597cdf0e10cSrcweir 598cdf0e10cSrcweir eError = pInStream->GetError(); 599cdf0e10cSrcweir 600cdf0e10cSrcweir if( !eError && (nStorOpenMode & STREAM_WRITE) 601cdf0e10cSrcweir && ! pInStream->IsWritable() ) 602cdf0e10cSrcweir { 603cdf0e10cSrcweir eError = ERRCODE_IO_ACCESSDENIED; 604cdf0e10cSrcweir delete pInStream; 605cdf0e10cSrcweir pInStream = NULL; 606cdf0e10cSrcweir } 607cdf0e10cSrcweir else 608cdf0e10cSrcweir return pInStream; 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir GetMedium_Impl(); 612cdf0e10cSrcweir 613cdf0e10cSrcweir if ( GetError() ) 614cdf0e10cSrcweir return NULL; 615cdf0e10cSrcweir 616cdf0e10cSrcweir return pInStream; 617cdf0e10cSrcweir } 618cdf0e10cSrcweir 619cdf0e10cSrcweir //------------------------------------------------------------------ 620cdf0e10cSrcweir void SfxMedium::CloseInStream() 621cdf0e10cSrcweir { 622cdf0e10cSrcweir CloseInStream_Impl(); 623cdf0e10cSrcweir } 624cdf0e10cSrcweir 625cdf0e10cSrcweir void SfxMedium::CloseInStream_Impl() 626cdf0e10cSrcweir { 627cdf0e10cSrcweir // if there is a storage based on the InStream, we have to 628cdf0e10cSrcweir // close the storage, too, because otherwise the storage 629cdf0e10cSrcweir // would use an invalid ( deleted ) stream. 630cdf0e10cSrcweir if ( pInStream && pImp->xStorage.is() ) 631cdf0e10cSrcweir { 632cdf0e10cSrcweir if ( pImp->bStorageBasedOnInStream ) 633cdf0e10cSrcweir CloseStorage(); 634cdf0e10cSrcweir } 635cdf0e10cSrcweir 636cdf0e10cSrcweir if ( pInStream && !GetContent().is() ) 637cdf0e10cSrcweir { 638cdf0e10cSrcweir CreateTempFile( sal_True ); 639cdf0e10cSrcweir return; 640cdf0e10cSrcweir } 641cdf0e10cSrcweir 642cdf0e10cSrcweir DELETEZ( pInStream ); 643cdf0e10cSrcweir if ( pSet ) 644cdf0e10cSrcweir pSet->ClearItem( SID_INPUTSTREAM ); 645cdf0e10cSrcweir 646cdf0e10cSrcweir CloseZipStorage_Impl(); 647cdf0e10cSrcweir pImp->xInputStream = uno::Reference< io::XInputStream >(); 648cdf0e10cSrcweir 649cdf0e10cSrcweir if ( !pOutStream ) 650cdf0e10cSrcweir { 651cdf0e10cSrcweir // output part of the stream is not used so the whole stream can be closed 652cdf0e10cSrcweir // TODO/LATER: is it correct? 653cdf0e10cSrcweir pImp->xStream = uno::Reference< io::XStream >(); 654cdf0e10cSrcweir if ( pSet ) 655cdf0e10cSrcweir pSet->ClearItem( SID_STREAM ); 656cdf0e10cSrcweir } 657cdf0e10cSrcweir } 658cdf0e10cSrcweir 659cdf0e10cSrcweir //------------------------------------------------------------------ 660cdf0e10cSrcweir SvStream* SfxMedium::GetOutStream() 661cdf0e10cSrcweir { 662cdf0e10cSrcweir if ( !pOutStream ) 663cdf0e10cSrcweir { 664cdf0e10cSrcweir // Create a temp. file if there is none because we always 665cdf0e10cSrcweir // need one. 666cdf0e10cSrcweir CreateTempFile( sal_False ); 667cdf0e10cSrcweir 668cdf0e10cSrcweir if ( pImp->pTempFile ) 669cdf0e10cSrcweir { 670cdf0e10cSrcweir pOutStream = new SvFileStream( aName, STREAM_STD_READWRITE ); 671cdf0e10cSrcweir CloseStorage(); 672cdf0e10cSrcweir } 673cdf0e10cSrcweir } 674cdf0e10cSrcweir 675cdf0e10cSrcweir return pOutStream; 676cdf0e10cSrcweir } 677cdf0e10cSrcweir 678cdf0e10cSrcweir //------------------------------------------------------------------ 679cdf0e10cSrcweir sal_Bool SfxMedium::CloseOutStream() 680cdf0e10cSrcweir { 681cdf0e10cSrcweir CloseOutStream_Impl(); 682cdf0e10cSrcweir return sal_True; 683cdf0e10cSrcweir } 684cdf0e10cSrcweir 685cdf0e10cSrcweir sal_Bool SfxMedium::CloseOutStream_Impl() 686cdf0e10cSrcweir { 687cdf0e10cSrcweir if ( pOutStream ) 688cdf0e10cSrcweir { 689cdf0e10cSrcweir // if there is a storage based on the OutStream, we have to 690cdf0e10cSrcweir // close the storage, too, because otherwise the storage 691cdf0e10cSrcweir // would use an invalid ( deleted ) stream. 692cdf0e10cSrcweir //TODO/MBA: how to deal with this?! 693cdf0e10cSrcweir //maybe we need a new flag when the storage was created from the outstream 694cdf0e10cSrcweir if ( pImp->xStorage.is() ) 695cdf0e10cSrcweir { 696cdf0e10cSrcweir //const SvStream *pStorage = aStorage->GetSvStream(); 697cdf0e10cSrcweir //if ( pStorage == pOutStream ) 698cdf0e10cSrcweir CloseStorage(); 699cdf0e10cSrcweir } 700cdf0e10cSrcweir 701cdf0e10cSrcweir delete pOutStream; 702cdf0e10cSrcweir pOutStream = NULL; 703cdf0e10cSrcweir } 704cdf0e10cSrcweir 705cdf0e10cSrcweir if ( !pInStream ) 706cdf0e10cSrcweir { 707cdf0e10cSrcweir // input part of the stream is not used so the whole stream can be closed 708cdf0e10cSrcweir // TODO/LATER: is it correct? 709cdf0e10cSrcweir pImp->xStream = uno::Reference< io::XStream >(); 710cdf0e10cSrcweir if ( pSet ) 711cdf0e10cSrcweir pSet->ClearItem( SID_STREAM ); 712cdf0e10cSrcweir } 713cdf0e10cSrcweir 714cdf0e10cSrcweir return sal_True; 715cdf0e10cSrcweir } 716cdf0e10cSrcweir 717cdf0e10cSrcweir //------------------------------------------------------------------ 718cdf0e10cSrcweir const String& SfxMedium::GetPhysicalName() const 719cdf0e10cSrcweir { 720cdf0e10cSrcweir if ( !aName.Len() && aLogicName.Len() ) 721cdf0e10cSrcweir (( SfxMedium*)this)->CreateFileStream(); 722cdf0e10cSrcweir 723cdf0e10cSrcweir // return the name then 724cdf0e10cSrcweir return aName; 725cdf0e10cSrcweir } 726cdf0e10cSrcweir 727cdf0e10cSrcweir //------------------------------------------------------------------ 728cdf0e10cSrcweir void SfxMedium::CreateFileStream() 729cdf0e10cSrcweir { 730cdf0e10cSrcweir ForceSynchronStream_Impl( sal_True ); 731cdf0e10cSrcweir GetInStream(); 732cdf0e10cSrcweir if( pInStream ) 733cdf0e10cSrcweir { 734cdf0e10cSrcweir CreateTempFile( sal_False ); 735cdf0e10cSrcweir pImp->bIsTemp = sal_True; 736cdf0e10cSrcweir CloseInStream_Impl(); 737cdf0e10cSrcweir } 738cdf0e10cSrcweir } 739cdf0e10cSrcweir 740cdf0e10cSrcweir //------------------------------------------------------------------ 741cdf0e10cSrcweir sal_Bool SfxMedium::Commit() 742cdf0e10cSrcweir { 743cdf0e10cSrcweir if( pImp->xStorage.is() ) 744cdf0e10cSrcweir StorageCommit_Impl(); 745cdf0e10cSrcweir else if( pOutStream ) 746cdf0e10cSrcweir pOutStream->Flush(); 747cdf0e10cSrcweir else if( pInStream ) 748cdf0e10cSrcweir pInStream->Flush(); 749cdf0e10cSrcweir 750cdf0e10cSrcweir if ( GetError() == SVSTREAM_OK ) 751cdf0e10cSrcweir { 752cdf0e10cSrcweir // does something only in case there is a temporary file ( means aName points to different location than aLogicName ) 753cdf0e10cSrcweir Transfer_Impl(); 754cdf0e10cSrcweir } 755cdf0e10cSrcweir 756cdf0e10cSrcweir sal_Bool bResult = ( GetError() == SVSTREAM_OK ); 757cdf0e10cSrcweir 758cdf0e10cSrcweir if ( bResult && DocNeedsFileDateCheck() ) 759cdf0e10cSrcweir GetInitFileDate( sal_True ); 760cdf0e10cSrcweir 761cdf0e10cSrcweir // remove truncation mode from the flags 762cdf0e10cSrcweir nStorOpenMode &= (~STREAM_TRUNC); 763cdf0e10cSrcweir return bResult; 764cdf0e10cSrcweir } 765cdf0e10cSrcweir 766cdf0e10cSrcweir //------------------------------------------------------------------ 767cdf0e10cSrcweir sal_Bool SfxMedium::IsStorage() 768cdf0e10cSrcweir { 769cdf0e10cSrcweir if ( pImp->xStorage.is() ) 770cdf0e10cSrcweir return sal_True; 771cdf0e10cSrcweir 772cdf0e10cSrcweir if ( bTriedStorage ) 773cdf0e10cSrcweir return pImp->bIsStorage; 774cdf0e10cSrcweir 775cdf0e10cSrcweir if ( pImp->pTempFile ) 776cdf0e10cSrcweir { 777cdf0e10cSrcweir String aURL; 778cdf0e10cSrcweir if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aURL ) ) 779cdf0e10cSrcweir { 780cdf0e10cSrcweir DBG_ERROR("Physical name not convertable!"); 781cdf0e10cSrcweir } 782cdf0e10cSrcweir pImp->bIsStorage = SotStorage::IsStorageFile( aURL ) && !SotStorage::IsOLEStorage( aURL); 783cdf0e10cSrcweir if ( !pImp->bIsStorage ) 784cdf0e10cSrcweir bTriedStorage = sal_True; 785cdf0e10cSrcweir } 786cdf0e10cSrcweir else if ( GetInStream() ) 787cdf0e10cSrcweir { 788cdf0e10cSrcweir pImp->bIsStorage = SotStorage::IsStorageFile( pInStream ) && !SotStorage::IsOLEStorage( pInStream ); 789cdf0e10cSrcweir if ( !pInStream->GetError() && !pImp->bIsStorage ) 790cdf0e10cSrcweir bTriedStorage = sal_True; 791cdf0e10cSrcweir } 792cdf0e10cSrcweir 793cdf0e10cSrcweir return pImp->bIsStorage; 794cdf0e10cSrcweir } 795cdf0e10cSrcweir 796cdf0e10cSrcweir //------------------------------------------------------------------ 797cdf0e10cSrcweir Link SfxMedium::GetDataAvailableLink() const 798cdf0e10cSrcweir { 799cdf0e10cSrcweir return pImp->aAvailableLink.GetLink(); 800cdf0e10cSrcweir } 801cdf0e10cSrcweir 802cdf0e10cSrcweir //------------------------------------------------------------------ 803cdf0e10cSrcweir Link SfxMedium::GetDoneLink() const 804cdf0e10cSrcweir { 805cdf0e10cSrcweir return pImp->aDoneLink.GetLink(); 806cdf0e10cSrcweir } 807cdf0e10cSrcweir 808cdf0e10cSrcweir //------------------------------------------------------------------ 809cdf0e10cSrcweir sal_Bool SfxMedium::IsPreview_Impl() 810cdf0e10cSrcweir { 811cdf0e10cSrcweir sal_Bool bPreview = sal_False; 812cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pPreview, SfxBoolItem, SID_PREVIEW, sal_False); 813cdf0e10cSrcweir if ( pPreview ) 814cdf0e10cSrcweir bPreview = pPreview->GetValue(); 815cdf0e10cSrcweir else 816cdf0e10cSrcweir { 817cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False); 818cdf0e10cSrcweir if ( pFlags ) 819cdf0e10cSrcweir { 820cdf0e10cSrcweir String aFileFlags = pFlags->GetValue(); 821cdf0e10cSrcweir aFileFlags.ToUpperAscii(); 822cdf0e10cSrcweir if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) ) 823cdf0e10cSrcweir bPreview = sal_True; 824cdf0e10cSrcweir } 825cdf0e10cSrcweir } 826cdf0e10cSrcweir 827cdf0e10cSrcweir return bPreview; 828cdf0e10cSrcweir } 829cdf0e10cSrcweir 830cdf0e10cSrcweir //------------------------------------------------------------------ 831cdf0e10cSrcweir void SfxMedium::StorageBackup_Impl() 832cdf0e10cSrcweir { 833cdf0e10cSrcweir ::ucbhelper::Content aOriginalContent; 834cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 835cdf0e10cSrcweir 836cdf0e10cSrcweir sal_Bool bBasedOnOriginalFile = ( !pImp->pTempFile && !( aLogicName.Len() && pImp->m_bSalvageMode ) 837cdf0e10cSrcweir && GetURLObject().GetMainURL( INetURLObject::NO_DECODE ).getLength() 838cdf0e10cSrcweir && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) 839cdf0e10cSrcweir && ::utl::UCBContentHelper::IsDocument( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ); 840cdf0e10cSrcweir 841cdf0e10cSrcweir if ( bBasedOnOriginalFile && !pImp->m_aBackupURL.getLength() 842cdf0e10cSrcweir && ::ucbhelper::Content::create( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, aOriginalContent ) ) 843cdf0e10cSrcweir { 844cdf0e10cSrcweir DoInternalBackup_Impl( aOriginalContent ); 845cdf0e10cSrcweir if( !pImp->m_aBackupURL.getLength() ) 846cdf0e10cSrcweir SetError( ERRCODE_SFX_CANTCREATEBACKUP, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 847cdf0e10cSrcweir } 848cdf0e10cSrcweir } 849cdf0e10cSrcweir 850cdf0e10cSrcweir //------------------------------------------------------------------ 851cdf0e10cSrcweir ::rtl::OUString SfxMedium::GetBackup_Impl() 852cdf0e10cSrcweir { 853cdf0e10cSrcweir if ( !pImp->m_aBackupURL.getLength() ) 854cdf0e10cSrcweir StorageBackup_Impl(); 855cdf0e10cSrcweir 856cdf0e10cSrcweir return pImp->m_aBackupURL; 857cdf0e10cSrcweir } 858cdf0e10cSrcweir 859cdf0e10cSrcweir //------------------------------------------------------------------ 860cdf0e10cSrcweir uno::Reference < embed::XStorage > SfxMedium::GetOutputStorage() 861cdf0e10cSrcweir { 862cdf0e10cSrcweir if ( GetError() ) 863cdf0e10cSrcweir return uno::Reference< embed::XStorage >(); 864cdf0e10cSrcweir 865cdf0e10cSrcweir // if the medium was constructed with a Storage: use this one, not a temp. storage 866cdf0e10cSrcweir // if a temporary storage already exists: use it 867cdf0e10cSrcweir if ( pImp->xStorage.is() && ( !aLogicName.Len() || pImp->pTempFile ) ) 868cdf0e10cSrcweir return pImp->xStorage; 869cdf0e10cSrcweir 870cdf0e10cSrcweir // if necessary close stream that was used for reading 871cdf0e10cSrcweir if ( pInStream && !pInStream->IsWritable() ) 872cdf0e10cSrcweir CloseInStream(); 873cdf0e10cSrcweir 874cdf0e10cSrcweir DBG_ASSERT( !pOutStream, "OutStream in a readonly Medium?!" ); 875cdf0e10cSrcweir 876cdf0e10cSrcweir // TODO/LATER: The current solution is to store the document temporary and then copy it to the target location; 877cdf0e10cSrcweir // in future it should be stored directly and then copied to the temporary location, since in this case no 878cdf0e10cSrcweir // file attributes have to be preserved and system copying mechanics could be used instead of streaming. 879cdf0e10cSrcweir CreateTempFileNoCopy(); 880cdf0e10cSrcweir 881cdf0e10cSrcweir return GetStorage(); 882cdf0e10cSrcweir } 883cdf0e10cSrcweir 884cdf0e10cSrcweir //------------------------------------------------------------------ 885cdf0e10cSrcweir void SfxMedium::SetEncryptionDataToStorage_Impl() 886cdf0e10cSrcweir { 887cdf0e10cSrcweir // in case media-descriptor contains password it should be used on opening 888cdf0e10cSrcweir if ( pImp->xStorage.is() && pSet ) 889cdf0e10cSrcweir { 890cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aEncryptionData; 891cdf0e10cSrcweir if ( GetEncryptionData_Impl( pSet, aEncryptionData ) ) 892cdf0e10cSrcweir { 893cdf0e10cSrcweir // replace the password with encryption data 894cdf0e10cSrcweir pSet->ClearItem( SID_PASSWORD ); 895cdf0e10cSrcweir pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) ) ); 896cdf0e10cSrcweir 897cdf0e10cSrcweir try 898cdf0e10cSrcweir { 899cdf0e10cSrcweir ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( pImp->xStorage, aEncryptionData ); 900cdf0e10cSrcweir } 901cdf0e10cSrcweir catch( uno::Exception& ) 902cdf0e10cSrcweir { 903cdf0e10cSrcweir OSL_ENSURE( sal_False, "It must be possible to set a common password for the storage" ); 904cdf0e10cSrcweir // TODO/LATER: set the error code in case of problem 905cdf0e10cSrcweir // SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 906cdf0e10cSrcweir } 907cdf0e10cSrcweir } 908cdf0e10cSrcweir } 909cdf0e10cSrcweir } 910cdf0e10cSrcweir 911cdf0e10cSrcweir //------------------------------------------------------------------ 912cdf0e10cSrcweir sal_Int8 SfxMedium::ShowLockedDocumentDialog( const uno::Sequence< ::rtl::OUString >& aData, sal_Bool bIsLoading, sal_Bool bOwnLock ) 913cdf0e10cSrcweir { 914cdf0e10cSrcweir sal_Int8 nResult = LOCK_UI_NOLOCK; 915cdf0e10cSrcweir 916cdf0e10cSrcweir // show the interaction regarding the document opening 917cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler(); 918cdf0e10cSrcweir 919cdf0e10cSrcweir if ( ::svt::DocumentLockFile::IsInteractionAllowed() && xHandler.is() && ( bIsLoading || bOwnLock ) ) 920cdf0e10cSrcweir { 921cdf0e10cSrcweir ::rtl::OUString aDocumentURL = GetURLObject().GetLastName(); 922cdf0e10cSrcweir ::rtl::OUString aInfo; 923cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionRequest > xInteractionRequestImpl; 924cdf0e10cSrcweir 925cdf0e10cSrcweir if ( bOwnLock ) 926cdf0e10cSrcweir { 927cdf0e10cSrcweir if ( aData.getLength() > LOCKFILE_EDITTIME_ID ) 928cdf0e10cSrcweir aInfo = aData[LOCKFILE_EDITTIME_ID]; 929cdf0e10cSrcweir 930cdf0e10cSrcweir xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( 931cdf0e10cSrcweir document::OwnLockOnDocumentRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo, !bIsLoading ) ) ); 932cdf0e10cSrcweir } 933cdf0e10cSrcweir else 934cdf0e10cSrcweir { 935cdf0e10cSrcweir if ( aData.getLength() > LOCKFILE_EDITTIME_ID ) 936cdf0e10cSrcweir { 937cdf0e10cSrcweir if ( aData[LOCKFILE_OOOUSERNAME_ID].getLength() ) 938cdf0e10cSrcweir aInfo = aData[LOCKFILE_OOOUSERNAME_ID]; 939cdf0e10cSrcweir else 940cdf0e10cSrcweir aInfo = aData[LOCKFILE_SYSUSERNAME_ID]; 941cdf0e10cSrcweir 942cdf0e10cSrcweir if ( aInfo.getLength() && aData[LOCKFILE_EDITTIME_ID].getLength() ) 943cdf0e10cSrcweir { 944cdf0e10cSrcweir aInfo += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " ( " ) ); 945cdf0e10cSrcweir aInfo += aData[LOCKFILE_EDITTIME_ID]; 946cdf0e10cSrcweir aInfo += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " )" ) ); 947cdf0e10cSrcweir } 948cdf0e10cSrcweir } 949cdf0e10cSrcweir 950cdf0e10cSrcweir if ( bIsLoading ) 951cdf0e10cSrcweir { 952cdf0e10cSrcweir xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( 953cdf0e10cSrcweir document::LockedDocumentRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) ); 954cdf0e10cSrcweir } 955cdf0e10cSrcweir else 956cdf0e10cSrcweir { 957cdf0e10cSrcweir xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( 958cdf0e10cSrcweir document::LockedOnSavingRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) ); 959cdf0e10cSrcweir 960cdf0e10cSrcweir } 961cdf0e10cSrcweir } 962cdf0e10cSrcweir 963cdf0e10cSrcweir uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 3 ); 964cdf0e10cSrcweir aContinuations[0] = new ::ucbhelper::InteractionAbort( xInteractionRequestImpl.get() ); 965cdf0e10cSrcweir aContinuations[1] = new ::ucbhelper::InteractionApprove( xInteractionRequestImpl.get() ); 966cdf0e10cSrcweir aContinuations[2] = new ::ucbhelper::InteractionDisapprove( xInteractionRequestImpl.get() ); 967cdf0e10cSrcweir xInteractionRequestImpl->setContinuations( aContinuations ); 968cdf0e10cSrcweir 969cdf0e10cSrcweir xHandler->handle( xInteractionRequestImpl.get() ); 970cdf0e10cSrcweir 971cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xInteractionRequestImpl->getSelection(); 972cdf0e10cSrcweir if ( uno::Reference< task::XInteractionAbort >( xSelected.get(), uno::UNO_QUERY ).is() ) 973cdf0e10cSrcweir { 974cdf0e10cSrcweir SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 975cdf0e10cSrcweir } 976cdf0e10cSrcweir else if ( uno::Reference< task::XInteractionDisapprove >( xSelected.get(), uno::UNO_QUERY ).is() ) 977cdf0e10cSrcweir { 978cdf0e10cSrcweir // own lock on loading, user has selected to ignore the lock 979cdf0e10cSrcweir // own lock on saving, user has selected to ignore the lock 980cdf0e10cSrcweir // alien lock on loading, user has selected to edit a copy of document 981cdf0e10cSrcweir // TODO/LATER: alien lock on saving, user has selected to do SaveAs to different location 982cdf0e10cSrcweir if ( bIsLoading && !bOwnLock ) 983cdf0e10cSrcweir { 984cdf0e10cSrcweir // means that a copy of the document should be opened 985cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); 986cdf0e10cSrcweir } 987cdf0e10cSrcweir else if ( bOwnLock ) 988cdf0e10cSrcweir nResult = LOCK_UI_SUCCEEDED; 989cdf0e10cSrcweir } 990cdf0e10cSrcweir else // if ( XSelected == aContinuations[1] ) 991cdf0e10cSrcweir { 992cdf0e10cSrcweir // own lock on loading, user has selected to open readonly 993cdf0e10cSrcweir // own lock on saving, user has selected to open readonly 994cdf0e10cSrcweir // alien lock on loading, user has selected to retry saving 995cdf0e10cSrcweir // TODO/LATER: alien lock on saving, user has selected to retry saving 996cdf0e10cSrcweir 997cdf0e10cSrcweir if ( bIsLoading ) 998cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 999cdf0e10cSrcweir else 1000cdf0e10cSrcweir nResult = LOCK_UI_TRY; 1001cdf0e10cSrcweir } 1002cdf0e10cSrcweir } 1003cdf0e10cSrcweir else 1004cdf0e10cSrcweir { 1005cdf0e10cSrcweir if ( bIsLoading ) 1006cdf0e10cSrcweir { 1007cdf0e10cSrcweir // if no interaction handler is provided the default answer is open readonly 1008cdf0e10cSrcweir // that usually happens in case the document is loaded per API 1009cdf0e10cSrcweir // so the document must be opened readonly for backward compatibility 1010cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 1011cdf0e10cSrcweir } 1012cdf0e10cSrcweir else 1013cdf0e10cSrcweir SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1014cdf0e10cSrcweir 1015cdf0e10cSrcweir } 1016cdf0e10cSrcweir 1017cdf0e10cSrcweir return nResult; 1018cdf0e10cSrcweir } 1019cdf0e10cSrcweir 1020cdf0e10cSrcweir //------------------------------------------------------------------ 1021cdf0e10cSrcweir sal_Bool SfxMedium::LockOrigFileOnDemand( sal_Bool bLoading, sal_Bool bNoUI ) 1022cdf0e10cSrcweir { 1023cdf0e10cSrcweir // returns true if the document can be opened for editing ( even if it should be a copy ) 1024cdf0e10cSrcweir // otherwise the document should be opened readonly 1025cdf0e10cSrcweir // if user cancel the loading the ERROR_ABORT is set 1026cdf0e10cSrcweir 1027cdf0e10cSrcweir if ( pImp->m_bLocked && bLoading && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) 1028cdf0e10cSrcweir { 1029cdf0e10cSrcweir // if the document is already locked the system locking might be temporarely off after storing 1030cdf0e10cSrcweir // check whether the system file locking should be taken again 1031cdf0e10cSrcweir GetLockingStream_Impl(); 1032cdf0e10cSrcweir } 1033cdf0e10cSrcweir 1034cdf0e10cSrcweir sal_Bool bResult = pImp->m_bLocked; 1035cdf0e10cSrcweir 1036cdf0e10cSrcweir if ( !bResult ) 1037cdf0e10cSrcweir { 1038cdf0e10cSrcweir // no read-write access is necessary on loading if the document is explicitly opened as copy 1039cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False); 1040cdf0e10cSrcweir bResult = ( bLoading && pTemplateItem && pTemplateItem->GetValue() ); 1041cdf0e10cSrcweir } 1042cdf0e10cSrcweir 1043cdf0e10cSrcweir if ( !bResult && !IsReadOnly() ) 1044cdf0e10cSrcweir { 1045cdf0e10cSrcweir sal_Bool bContentReadonly = sal_False; 1046cdf0e10cSrcweir if ( bLoading && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) 1047cdf0e10cSrcweir { 1048cdf0e10cSrcweir // let the original document be opened to check the possibility to open it for editing 1049cdf0e10cSrcweir // and to let the writable stream stay open to hold the lock on the document 1050cdf0e10cSrcweir GetLockingStream_Impl(); 1051cdf0e10cSrcweir } 1052cdf0e10cSrcweir 1053cdf0e10cSrcweir // "IsReadOnly" property does not allow to detect whether the file is readonly always 1054cdf0e10cSrcweir // so we try always to open the file for editing 1055cdf0e10cSrcweir // the file is readonly only in case the read-write stream can not be opened 1056cdf0e10cSrcweir if ( bLoading && !pImp->m_xLockingStream.is() ) 1057cdf0e10cSrcweir { 1058cdf0e10cSrcweir try 1059cdf0e10cSrcweir { 1060cdf0e10cSrcweir // MediaDescriptor does this check also, the duplication should be avoided in future 1061cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 1062cdf0e10cSrcweir ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); 1063cdf0e10cSrcweir aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bContentReadonly; 1064cdf0e10cSrcweir } 1065cdf0e10cSrcweir catch( uno::Exception ) 1066cdf0e10cSrcweir {} 1067cdf0e10cSrcweir 1068cdf0e10cSrcweir if ( !bContentReadonly ) 1069cdf0e10cSrcweir { 1070cdf0e10cSrcweir // the file is not readonly, check the ACL 1071cdf0e10cSrcweir 1072cdf0e10cSrcweir String aPhysPath; 1073cdf0e10cSrcweir if ( ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), aPhysPath ) ) 1074cdf0e10cSrcweir bContentReadonly = IsReadonlyAccordingACL( aPhysPath.GetBuffer() ); 1075cdf0e10cSrcweir } 1076cdf0e10cSrcweir } 1077cdf0e10cSrcweir 1078cdf0e10cSrcweir // do further checks only if the file not readonly in fs 1079cdf0e10cSrcweir if ( !bContentReadonly ) 1080cdf0e10cSrcweir { 1081cdf0e10cSrcweir // the special file locking should be used only for file URLs 1082cdf0e10cSrcweir if ( ::utl::LocalFileHelper::IsLocalFile( aLogicName ) ) 1083cdf0e10cSrcweir { 1084cdf0e10cSrcweir 1085cdf0e10cSrcweir // in case of storing the document should request the output before locking 1086cdf0e10cSrcweir if ( bLoading ) 1087cdf0e10cSrcweir { 1088cdf0e10cSrcweir // let the stream be opened to check the system file locking 1089cdf0e10cSrcweir GetMedium_Impl(); 1090cdf0e10cSrcweir } 1091cdf0e10cSrcweir 1092cdf0e10cSrcweir sal_Int8 bUIStatus = LOCK_UI_NOLOCK; 1093cdf0e10cSrcweir 1094cdf0e10cSrcweir // check whether system file locking has been used, the default value is false 1095cdf0e10cSrcweir sal_Bool bUseSystemLock = IsSystemFileLockingUsed(); 1096cdf0e10cSrcweir 1097cdf0e10cSrcweir // TODO/LATER: This implementation does not allow to detect the system lock on saving here, actually this is no big problem 1098cdf0e10cSrcweir // if system lock is used the writeable stream should be available 1099cdf0e10cSrcweir sal_Bool bHandleSysLocked = ( bLoading && bUseSystemLock && !pImp->xStream.is() && !pOutStream ); 1100cdf0e10cSrcweir 1101cdf0e10cSrcweir do 1102cdf0e10cSrcweir { 1103cdf0e10cSrcweir try 1104cdf0e10cSrcweir { 1105cdf0e10cSrcweir ::svt::DocumentLockFile aLockFile( aLogicName ); 1106cdf0e10cSrcweir if ( !bHandleSysLocked ) 1107cdf0e10cSrcweir { 1108cdf0e10cSrcweir try 1109cdf0e10cSrcweir { 1110cdf0e10cSrcweir bResult = aLockFile.CreateOwnLockFile(); 1111cdf0e10cSrcweir } 1112cdf0e10cSrcweir catch ( ucb::InteractiveIOException& e ) 1113cdf0e10cSrcweir { 1114cdf0e10cSrcweir // exception means that the lock file can not be successfuly accessed 1115cdf0e10cSrcweir // in this case it should be ignored if system file locking is anyway active 1116cdf0e10cSrcweir if ( bUseSystemLock || !IsOOoLockFileUsed() ) 1117cdf0e10cSrcweir { 1118cdf0e10cSrcweir bResult = sal_True; 1119cdf0e10cSrcweir // take the ownership over the lock file 1120cdf0e10cSrcweir aLockFile.OverwriteOwnLockFile(); 1121cdf0e10cSrcweir } 1122cdf0e10cSrcweir else if ( e.Code == IOErrorCode_INVALID_PARAMETER ) 1123cdf0e10cSrcweir { 1124cdf0e10cSrcweir // system file locking is not active, ask user whether he wants to open the document without any locking 1125cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler(); 1126cdf0e10cSrcweir 1127cdf0e10cSrcweir if ( xHandler.is() ) 1128cdf0e10cSrcweir { 1129cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionRequest > xIgnoreRequestImpl 1130cdf0e10cSrcweir = new ::ucbhelper::InteractionRequest( uno::makeAny( document::LockFileIgnoreRequest() ) ); 1131cdf0e10cSrcweir 1132cdf0e10cSrcweir uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 2 ); 1133cdf0e10cSrcweir aContinuations[0] = new ::ucbhelper::InteractionAbort( xIgnoreRequestImpl.get() ); 1134cdf0e10cSrcweir aContinuations[1] = new ::ucbhelper::InteractionApprove( xIgnoreRequestImpl.get() ); 1135cdf0e10cSrcweir xIgnoreRequestImpl->setContinuations( aContinuations ); 1136cdf0e10cSrcweir 1137cdf0e10cSrcweir xHandler->handle( xIgnoreRequestImpl.get() ); 1138cdf0e10cSrcweir 1139cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xIgnoreRequestImpl->getSelection(); 1140cdf0e10cSrcweir bResult = ( uno::Reference< task::XInteractionApprove >( xSelected.get(), uno::UNO_QUERY ).is() ); 1141cdf0e10cSrcweir } 1142cdf0e10cSrcweir } 1143cdf0e10cSrcweir } 1144cdf0e10cSrcweir catch ( uno::Exception& ) 1145cdf0e10cSrcweir { 1146cdf0e10cSrcweir // exception means that the lock file can not be successfuly accessed 1147cdf0e10cSrcweir // in this case it should be ignored if system file locking is anyway active 1148cdf0e10cSrcweir if ( bUseSystemLock || !IsOOoLockFileUsed() ) 1149cdf0e10cSrcweir { 1150cdf0e10cSrcweir bResult = sal_True; 1151cdf0e10cSrcweir // take the ownership over the lock file 1152cdf0e10cSrcweir aLockFile.OverwriteOwnLockFile(); 1153cdf0e10cSrcweir } 1154cdf0e10cSrcweir } 1155cdf0e10cSrcweir 1156cdf0e10cSrcweir // in case OOo locking is turned off the lock file is still written if possible 1157cdf0e10cSrcweir // but it is ignored while deciding whether the document should be opened for editing or not 1158cdf0e10cSrcweir if ( !bResult && !IsOOoLockFileUsed() ) 1159cdf0e10cSrcweir { 1160cdf0e10cSrcweir bResult = sal_True; 1161cdf0e10cSrcweir // take the ownership over the lock file 1162cdf0e10cSrcweir aLockFile.OverwriteOwnLockFile(); 1163cdf0e10cSrcweir } 1164cdf0e10cSrcweir } 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir 1167cdf0e10cSrcweir if ( !bResult ) 1168cdf0e10cSrcweir { 1169cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aData; 1170cdf0e10cSrcweir try 1171cdf0e10cSrcweir { 1172cdf0e10cSrcweir // impossibility to get data is no real problem 1173cdf0e10cSrcweir aData = aLockFile.GetLockData(); 1174cdf0e10cSrcweir } 1175cdf0e10cSrcweir catch( uno::Exception ) {} 1176cdf0e10cSrcweir 1177cdf0e10cSrcweir sal_Bool bOwnLock = sal_False; 1178cdf0e10cSrcweir 1179cdf0e10cSrcweir if ( !bHandleSysLocked ) 1180cdf0e10cSrcweir { 1181cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aOwnData = aLockFile.GenerateOwnEntry(); 1182cdf0e10cSrcweir bOwnLock = ( aData.getLength() > LOCKFILE_USERURL_ID 1183cdf0e10cSrcweir && aOwnData.getLength() > LOCKFILE_USERURL_ID 1184cdf0e10cSrcweir && aOwnData[LOCKFILE_SYSUSERNAME_ID].equals( aData[LOCKFILE_SYSUSERNAME_ID] ) ); 1185cdf0e10cSrcweir 1186cdf0e10cSrcweir if ( bOwnLock 1187cdf0e10cSrcweir && aOwnData[LOCKFILE_LOCALHOST_ID].equals( aData[LOCKFILE_LOCALHOST_ID] ) 1188cdf0e10cSrcweir && aOwnData[LOCKFILE_USERURL_ID].equals( aData[LOCKFILE_USERURL_ID] ) ) 1189cdf0e10cSrcweir { 1190cdf0e10cSrcweir // this is own lock from the same installation, it could remain because of crash 1191cdf0e10cSrcweir bResult = sal_True; 1192cdf0e10cSrcweir } 1193cdf0e10cSrcweir } 1194cdf0e10cSrcweir 1195cdf0e10cSrcweir if ( !bResult && !bNoUI ) 1196cdf0e10cSrcweir { 1197cdf0e10cSrcweir bUIStatus = ShowLockedDocumentDialog( aData, bLoading, bOwnLock ); 1198cdf0e10cSrcweir if ( bUIStatus == LOCK_UI_SUCCEEDED ) 1199cdf0e10cSrcweir { 1200cdf0e10cSrcweir // take the ownership over the lock file 1201cdf0e10cSrcweir bResult = aLockFile.OverwriteOwnLockFile(); 1202cdf0e10cSrcweir } 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir bHandleSysLocked = sal_False; 1206cdf0e10cSrcweir } 1207cdf0e10cSrcweir } 1208cdf0e10cSrcweir catch( uno::Exception& ) 1209cdf0e10cSrcweir { 1210cdf0e10cSrcweir } 1211cdf0e10cSrcweir } while( !bResult && bUIStatus == LOCK_UI_TRY ); 1212cdf0e10cSrcweir 1213cdf0e10cSrcweir pImp->m_bLocked = bResult; 1214cdf0e10cSrcweir } 1215cdf0e10cSrcweir else 1216cdf0e10cSrcweir { 1217cdf0e10cSrcweir // this is no file URL, check whether the file is readonly 1218cdf0e10cSrcweir bResult = !bContentReadonly; 1219cdf0e10cSrcweir } 1220cdf0e10cSrcweir } 1221cdf0e10cSrcweir } 1222cdf0e10cSrcweir 1223cdf0e10cSrcweir if ( !bResult && GetError() == ERRCODE_NONE ) 1224cdf0e10cSrcweir { 1225cdf0e10cSrcweir // the error should be set in case it is storing process 1226cdf0e10cSrcweir // or the document has been opened for editing explicitly 1227cdf0e10cSrcweir 1228cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, sal_False ); 1229cdf0e10cSrcweir if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->GetValue()) ) 1230cdf0e10cSrcweir SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1231cdf0e10cSrcweir else 1232cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 1233cdf0e10cSrcweir } 1234cdf0e10cSrcweir 1235cdf0e10cSrcweir // when the file is locked, get the current file date 1236cdf0e10cSrcweir if ( bResult && DocNeedsFileDateCheck() ) 1237cdf0e10cSrcweir GetInitFileDate( sal_True ); 1238cdf0e10cSrcweir 1239cdf0e10cSrcweir return bResult; 1240cdf0e10cSrcweir } 1241cdf0e10cSrcweir 1242cdf0e10cSrcweir //------------------------------------------------------------------ 1243cdf0e10cSrcweir uno::Reference < embed::XStorage > SfxMedium::GetStorage( sal_Bool bCreateTempIfNo ) 1244cdf0e10cSrcweir { 1245cdf0e10cSrcweir if ( pImp->xStorage.is() || bTriedStorage ) 1246cdf0e10cSrcweir return pImp->xStorage; 1247cdf0e10cSrcweir 1248cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 1249cdf0e10cSrcweir 1250cdf0e10cSrcweir // the medium should be retrieved before temporary file creation 1251cdf0e10cSrcweir // to let the MediaDescriptor be filled with the streams 1252cdf0e10cSrcweir GetMedium_Impl(); 1253cdf0e10cSrcweir 1254cdf0e10cSrcweir if ( bCreateTempIfNo ) 1255cdf0e10cSrcweir CreateTempFile( sal_False ); 1256cdf0e10cSrcweir 1257cdf0e10cSrcweir GetMedium_Impl(); 1258cdf0e10cSrcweir 1259cdf0e10cSrcweir if ( GetError() ) 1260cdf0e10cSrcweir return pImp->xStorage; 1261cdf0e10cSrcweir 1262cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False); 1263cdf0e10cSrcweir if ( pRepairItem && pRepairItem->GetValue() ) 1264cdf0e10cSrcweir { 1265cdf0e10cSrcweir // the storage should be created for repairing mode 1266cdf0e10cSrcweir CreateTempFile( sal_False ); 1267cdf0e10cSrcweir GetMedium_Impl(); 1268cdf0e10cSrcweir 1269cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XProgressHandler > xProgressHandler; 1270cdf0e10cSrcweir Reference< ::com::sun::star::task::XStatusIndicator > xStatusIndicator; 1271cdf0e10cSrcweir 1272cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pxProgressItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, sal_False ); 1273cdf0e10cSrcweir if( pxProgressItem && ( pxProgressItem->GetValue() >>= xStatusIndicator ) ) 1274cdf0e10cSrcweir xProgressHandler = Reference< ::com::sun::star::ucb::XProgressHandler >( 1275cdf0e10cSrcweir new utl::ProgressHandlerWrap( xStatusIndicator ) ); 1276cdf0e10cSrcweir 1277cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aAddProps( 2 ); 1278cdf0e10cSrcweir aAddProps[0].Name = ::rtl::OUString::createFromAscii( "RepairPackage" ); 1279cdf0e10cSrcweir aAddProps[0].Value <<= (sal_Bool)sal_True; 1280cdf0e10cSrcweir aAddProps[1].Name = ::rtl::OUString::createFromAscii( "StatusIndicator" ); 1281cdf0e10cSrcweir aAddProps[1].Value <<= xProgressHandler; 1282cdf0e10cSrcweir 1283cdf0e10cSrcweir // the first arguments will be filled later 1284cdf0e10cSrcweir aArgs.realloc( 3 ); 1285cdf0e10cSrcweir aArgs[2] <<= aAddProps; 1286cdf0e10cSrcweir } 1287cdf0e10cSrcweir 1288cdf0e10cSrcweir if ( pImp->xStream.is() ) 1289cdf0e10cSrcweir { 1290cdf0e10cSrcweir // since the storage is based on temporary stream we open it always read-write 1291cdf0e10cSrcweir aArgs[0] <<= pImp->xStream; 1292cdf0e10cSrcweir aArgs[1] <<= embed::ElementModes::READWRITE; 1293cdf0e10cSrcweir pImp->bStorageBasedOnInStream = sal_True; 1294cdf0e10cSrcweir } 1295cdf0e10cSrcweir else if ( pImp->xInputStream.is() ) 1296cdf0e10cSrcweir { 1297cdf0e10cSrcweir // since the storage is based on temporary stream we open it always read-write 1298cdf0e10cSrcweir aArgs[0] <<= pImp->xInputStream; 1299cdf0e10cSrcweir aArgs[1] <<= embed::ElementModes::READ; 1300cdf0e10cSrcweir pImp->bStorageBasedOnInStream = sal_True; 1301cdf0e10cSrcweir } 1302cdf0e10cSrcweir else 1303cdf0e10cSrcweir { 1304cdf0e10cSrcweir CloseStreams_Impl(); 1305cdf0e10cSrcweir aArgs[0] <<= ::rtl::OUString( aName ); 1306cdf0e10cSrcweir aArgs[1] <<= embed::ElementModes::READ; 1307cdf0e10cSrcweir pImp->bStorageBasedOnInStream = sal_False; 1308cdf0e10cSrcweir } 1309cdf0e10cSrcweir 1310cdf0e10cSrcweir try 1311cdf0e10cSrcweir { 1312cdf0e10cSrcweir pImp->xStorage = uno::Reference< embed::XStorage >( 1313cdf0e10cSrcweir ::comphelper::OStorageHelper::GetStorageFactory()->createInstanceWithArguments( aArgs ), 1314cdf0e10cSrcweir uno::UNO_QUERY ); 1315cdf0e10cSrcweir } 1316cdf0e10cSrcweir catch( uno::Exception& ) 1317cdf0e10cSrcweir { 1318cdf0e10cSrcweir // impossibility to create the storage is no error 1319cdf0e10cSrcweir } 1320cdf0e10cSrcweir 1321cdf0e10cSrcweir if( ( pImp->nLastStorageError = GetError() ) != SVSTREAM_OK ) 1322cdf0e10cSrcweir { 1323cdf0e10cSrcweir pImp->xStorage = 0; 1324cdf0e10cSrcweir if ( pInStream ) 1325cdf0e10cSrcweir pInStream->Seek(0); 1326cdf0e10cSrcweir return uno::Reference< embed::XStorage >(); 1327cdf0e10cSrcweir } 1328cdf0e10cSrcweir 1329cdf0e10cSrcweir bTriedStorage = sal_True; 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir // TODO/LATER: Get versionlist on demand 1332cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1333cdf0e10cSrcweir { 1334cdf0e10cSrcweir SetEncryptionDataToStorage_Impl(); 1335cdf0e10cSrcweir GetVersionList(); 1336cdf0e10cSrcweir } 1337cdf0e10cSrcweir 1338cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pVersion, SfxInt16Item, SID_VERSION, sal_False); 1339cdf0e10cSrcweir 1340cdf0e10cSrcweir sal_Bool bResetStorage = sal_False; 1341cdf0e10cSrcweir if ( pVersion && pVersion->GetValue() ) 1342cdf0e10cSrcweir { 1343cdf0e10cSrcweir // Alle verf"ugbaren Versionen einlesen 1344cdf0e10cSrcweir if ( pImp->aVersions.getLength() ) 1345cdf0e10cSrcweir { 1346cdf0e10cSrcweir // Die zum Kommentar passende Version suchen 1347cdf0e10cSrcweir // Die Versionen sind von 1 an durchnumeriert, mit negativen 1348cdf0e10cSrcweir // Versionsnummern werden die Versionen von der aktuellen aus 1349cdf0e10cSrcweir // r"uckw"arts gez"ahlt 1350cdf0e10cSrcweir short nVersion = pVersion ? pVersion->GetValue() : 0; 1351cdf0e10cSrcweir if ( nVersion<0 ) 1352cdf0e10cSrcweir nVersion = ( (short) pImp->aVersions.getLength() ) + nVersion; 1353cdf0e10cSrcweir else if ( nVersion ) 1354cdf0e10cSrcweir nVersion--; 1355cdf0e10cSrcweir 1356cdf0e10cSrcweir util::RevisionTag& rTag = pImp->aVersions[nVersion]; 1357cdf0e10cSrcweir { 1358cdf0e10cSrcweir // SubStorage f"ur alle Versionen "offnen 1359cdf0e10cSrcweir uno::Reference < embed::XStorage > xSub = pImp->xStorage->openStorageElement( DEFINE_CONST_UNICODE( "Versions" ), 1360cdf0e10cSrcweir embed::ElementModes::READ ); 1361cdf0e10cSrcweir 1362cdf0e10cSrcweir DBG_ASSERT( xSub.is(), "Versionsliste, aber keine Versionen!" ); 1363cdf0e10cSrcweir 1364cdf0e10cSrcweir // Dort ist die Version als gepackter Stream gespeichert 1365cdf0e10cSrcweir uno::Reference < io::XStream > xStr = xSub->openStreamElement( rTag.Identifier, embed::ElementModes::READ ); 1366cdf0e10cSrcweir SvStream* pStream = utl::UcbStreamHelper::CreateStream( xStr ); 1367cdf0e10cSrcweir if ( pStream && pStream->GetError() == SVSTREAM_OK ) 1368cdf0e10cSrcweir { 1369cdf0e10cSrcweir // Stream ins TempDir auspacken 1370cdf0e10cSrcweir ::utl::TempFile aTempFile; 1371cdf0e10cSrcweir String aTmpName = aTempFile.GetURL(); 1372cdf0e10cSrcweir SvFileStream aTmpStream( aTmpName, SFX_STREAM_READWRITE ); 1373cdf0e10cSrcweir 1374cdf0e10cSrcweir *pStream >> aTmpStream; 1375cdf0e10cSrcweir aTmpStream.Close(); 1376cdf0e10cSrcweir 1377cdf0e10cSrcweir // Datei als Storage "offnen 1378cdf0e10cSrcweir nStorOpenMode = SFX_STREAM_READONLY; 1379cdf0e10cSrcweir pImp->xStorage = comphelper::OStorageHelper::GetStorageFromURL( aTmpName, embed::ElementModes::READ ); 1380cdf0e10cSrcweir pImp->bStorageBasedOnInStream = sal_False; 1381cdf0e10cSrcweir String aTemp; 1382cdf0e10cSrcweir ::utl::LocalFileHelper::ConvertURLToPhysicalName( aTmpName, aTemp ); 1383cdf0e10cSrcweir SetPhysicalName_Impl( aTemp ); 1384cdf0e10cSrcweir 1385cdf0e10cSrcweir pImp->bIsTemp = sal_True; 1386cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 1387cdf0e10cSrcweir // TODO/MBA 1388cdf0e10cSrcweir pImp->aVersions.realloc(0); 1389cdf0e10cSrcweir } 1390cdf0e10cSrcweir else 1391cdf0e10cSrcweir bResetStorage = sal_True; 1392cdf0e10cSrcweir } 1393cdf0e10cSrcweir } 1394cdf0e10cSrcweir else 1395cdf0e10cSrcweir bResetStorage = sal_True; 1396cdf0e10cSrcweir } 1397cdf0e10cSrcweir 1398cdf0e10cSrcweir if ( bResetStorage ) 1399cdf0e10cSrcweir { 1400cdf0e10cSrcweir pImp->xStorage = 0; 1401cdf0e10cSrcweir if ( pInStream ) 1402cdf0e10cSrcweir pInStream->Seek( 0L ); 1403cdf0e10cSrcweir } 1404cdf0e10cSrcweir 1405cdf0e10cSrcweir pImp->bIsStorage = pImp->xStorage.is(); 1406cdf0e10cSrcweir return pImp->xStorage; 1407cdf0e10cSrcweir } 1408cdf0e10cSrcweir 1409cdf0e10cSrcweir //------------------------------------------------------------------ 1410cdf0e10cSrcweir uno::Reference< embed::XStorage > SfxMedium::GetZipStorageToSign_Impl( sal_Bool bReadOnly ) 1411cdf0e10cSrcweir { 1412cdf0e10cSrcweir if ( !GetError() && !pImp->m_xZipStorage.is() ) 1413cdf0e10cSrcweir { 1414cdf0e10cSrcweir // very careful!!! 1415cdf0e10cSrcweir // if bReadOnly == sal_False and there is no temporary file the original file might be used 1416cdf0e10cSrcweir GetMedium_Impl(); 1417cdf0e10cSrcweir 1418cdf0e10cSrcweir try 1419cdf0e10cSrcweir { 1420cdf0e10cSrcweir // we can not sign document if there is no stream 1421cdf0e10cSrcweir // should it be possible at all? 1422cdf0e10cSrcweir if ( !bReadOnly && pImp->xStream.is() ) 1423cdf0e10cSrcweir { 1424cdf0e10cSrcweir pImp->m_xZipStorage = ::comphelper::OStorageHelper::GetStorageOfFormatFromStream( ZIP_STORAGE_FORMAT_STRING, pImp->xStream, embed::ElementModes::READWRITE ); 1425cdf0e10cSrcweir } 1426cdf0e10cSrcweir else if ( pImp->xInputStream.is() ) 1427cdf0e10cSrcweir { 1428cdf0e10cSrcweir pImp->m_xZipStorage = ::comphelper::OStorageHelper::GetStorageOfFormatFromInputStream( ZIP_STORAGE_FORMAT_STRING, pImp->xInputStream ); 1429cdf0e10cSrcweir } 1430cdf0e10cSrcweir } 1431cdf0e10cSrcweir catch( uno::Exception& ) 1432cdf0e10cSrcweir { 1433cdf0e10cSrcweir OSL_ENSURE( sal_False, "No possibility to get readonly version of storage from medium!\n" ); 1434cdf0e10cSrcweir } 1435cdf0e10cSrcweir 1436cdf0e10cSrcweir if ( GetError() ) // do not remove warnings 1437cdf0e10cSrcweir ResetError(); 1438cdf0e10cSrcweir } 1439cdf0e10cSrcweir 1440cdf0e10cSrcweir return pImp->m_xZipStorage; 1441cdf0e10cSrcweir } 1442cdf0e10cSrcweir 1443cdf0e10cSrcweir //------------------------------------------------------------------ 1444cdf0e10cSrcweir void SfxMedium::CloseZipStorage_Impl() 1445cdf0e10cSrcweir { 1446cdf0e10cSrcweir if ( pImp->m_xZipStorage.is() ) 1447cdf0e10cSrcweir { 1448cdf0e10cSrcweir try { 1449cdf0e10cSrcweir pImp->m_xZipStorage->dispose(); 1450cdf0e10cSrcweir } catch( uno::Exception& ) 1451cdf0e10cSrcweir {} 1452cdf0e10cSrcweir 1453cdf0e10cSrcweir pImp->m_xZipStorage = uno::Reference< embed::XStorage >(); 1454cdf0e10cSrcweir } 1455cdf0e10cSrcweir } 1456cdf0e10cSrcweir 1457cdf0e10cSrcweir //------------------------------------------------------------------ 1458cdf0e10cSrcweir void SfxMedium::CloseStorage() 1459cdf0e10cSrcweir { 1460cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1461cdf0e10cSrcweir { 1462cdf0e10cSrcweir uno::Reference < lang::XComponent > xComp( pImp->xStorage, uno::UNO_QUERY ); 1463cdf0e10cSrcweir // in the salvage mode the medium does not own the storage 1464cdf0e10cSrcweir if ( pImp->bDisposeStorage && !pImp->m_bSalvageMode ) 1465cdf0e10cSrcweir { 1466cdf0e10cSrcweir try { 1467cdf0e10cSrcweir xComp->dispose(); 1468cdf0e10cSrcweir } catch( uno::Exception& ) 1469cdf0e10cSrcweir { 1470cdf0e10cSrcweir OSL_ENSURE( sal_False, "Medium's storage is already disposed!\n" ); 1471cdf0e10cSrcweir } 1472cdf0e10cSrcweir } 1473cdf0e10cSrcweir 1474cdf0e10cSrcweir pImp->xStorage = 0; 1475cdf0e10cSrcweir pImp->bStorageBasedOnInStream = sal_False; 1476cdf0e10cSrcweir } 1477cdf0e10cSrcweir 1478cdf0e10cSrcweir bTriedStorage = sal_False; 1479cdf0e10cSrcweir pImp->bIsStorage = sal_False; 1480cdf0e10cSrcweir } 1481cdf0e10cSrcweir 1482cdf0e10cSrcweir void SfxMedium::CanDisposeStorage_Impl( sal_Bool bDisposeStorage ) 1483cdf0e10cSrcweir { 1484cdf0e10cSrcweir pImp->bDisposeStorage = bDisposeStorage; 1485cdf0e10cSrcweir } 1486cdf0e10cSrcweir 1487cdf0e10cSrcweir sal_Bool SfxMedium::WillDisposeStorageOnClose_Impl() 1488cdf0e10cSrcweir { 1489cdf0e10cSrcweir return pImp->bDisposeStorage; 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir 1492cdf0e10cSrcweir //------------------------------------------------------------------ 1493cdf0e10cSrcweir void SfxMedium::SetOpenMode( StreamMode nStorOpen, 1494cdf0e10cSrcweir sal_Bool bDirectP, 1495cdf0e10cSrcweir sal_Bool bDontClose ) 1496cdf0e10cSrcweir { 1497cdf0e10cSrcweir if ( nStorOpenMode != nStorOpen ) 1498cdf0e10cSrcweir { 1499cdf0e10cSrcweir nStorOpenMode = nStorOpen; 1500cdf0e10cSrcweir 1501cdf0e10cSrcweir if( !bDontClose ) 1502cdf0e10cSrcweir { 1503cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1504cdf0e10cSrcweir CloseStorage(); 1505cdf0e10cSrcweir 1506cdf0e10cSrcweir CloseStreams_Impl(); 1507cdf0e10cSrcweir } 1508cdf0e10cSrcweir } 1509cdf0e10cSrcweir 1510cdf0e10cSrcweir bDirect = bDirectP; 1511cdf0e10cSrcweir bSetFilter = sal_False; 1512cdf0e10cSrcweir } 1513cdf0e10cSrcweir 1514cdf0e10cSrcweir //------------------------------------------------------------------ 1515cdf0e10cSrcweir sal_Bool SfxMedium::UseBackupToRestore_Impl( ::ucbhelper::Content& aOriginalContent, 1516cdf0e10cSrcweir const Reference< ::com::sun::star::ucb::XCommandEnvironment >& xComEnv ) 1517cdf0e10cSrcweir { 1518cdf0e10cSrcweir try 1519cdf0e10cSrcweir { 1520cdf0e10cSrcweir ::ucbhelper::Content aTransactCont( pImp->m_aBackupURL, xComEnv ); 1521cdf0e10cSrcweir 1522cdf0e10cSrcweir Reference< XInputStream > aOrigInput = aTransactCont.openStream(); 1523cdf0e10cSrcweir aOriginalContent.writeStream( aOrigInput, sal_True ); 1524cdf0e10cSrcweir return sal_True; 1525cdf0e10cSrcweir } 1526cdf0e10cSrcweir catch( Exception& ) 1527cdf0e10cSrcweir { 1528cdf0e10cSrcweir // in case of failure here the backup file should not be removed 1529cdf0e10cSrcweir // TODO/LATER: a message should be used to let user know about the backup 1530cdf0e10cSrcweir pImp->m_bRemoveBackup = sal_False; 1531cdf0e10cSrcweir // TODO/LATER: needs a specific error code 1532cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1533cdf0e10cSrcweir } 1534cdf0e10cSrcweir 1535cdf0e10cSrcweir return sal_False; 1536cdf0e10cSrcweir } 1537cdf0e10cSrcweir 1538cdf0e10cSrcweir //------------------------------------------------------------------ 1539cdf0e10cSrcweir sal_Bool SfxMedium::StorageCommit_Impl() 1540cdf0e10cSrcweir { 1541cdf0e10cSrcweir sal_Bool bResult = sal_False; 1542cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 1543cdf0e10cSrcweir ::ucbhelper::Content aOriginalContent; 1544cdf0e10cSrcweir 1545cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1546cdf0e10cSrcweir { 1547cdf0e10cSrcweir if ( !GetError() ) 1548cdf0e10cSrcweir { 1549cdf0e10cSrcweir uno::Reference < embed::XTransactedObject > xTrans( pImp->xStorage, uno::UNO_QUERY ); 1550cdf0e10cSrcweir if ( xTrans.is() ) 1551cdf0e10cSrcweir { 1552cdf0e10cSrcweir try 1553cdf0e10cSrcweir { 1554cdf0e10cSrcweir xTrans->commit(); 1555cdf0e10cSrcweir CloseZipStorage_Impl(); 1556cdf0e10cSrcweir bResult = sal_True; 1557cdf0e10cSrcweir } 1558cdf0e10cSrcweir catch ( embed::UseBackupException& aBackupExc ) 1559cdf0e10cSrcweir { 1560cdf0e10cSrcweir // since the temporary file is created always now, the scenario is close to be impossible 1561cdf0e10cSrcweir if ( !pImp->pTempFile ) 1562cdf0e10cSrcweir { 1563cdf0e10cSrcweir OSL_ENSURE( pImp->m_aBackupURL.getLength(), "No backup on storage commit!\n" ); 1564cdf0e10cSrcweir if ( pImp->m_aBackupURL.getLength() 1565cdf0e10cSrcweir && ::ucbhelper::Content::create( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), 1566cdf0e10cSrcweir xDummyEnv, 1567cdf0e10cSrcweir aOriginalContent ) ) 1568cdf0e10cSrcweir { 1569cdf0e10cSrcweir // use backup to restore the file 1570cdf0e10cSrcweir // the storage has already disconnected from original location 1571cdf0e10cSrcweir CloseAndReleaseStreams_Impl(); 1572cdf0e10cSrcweir if ( !UseBackupToRestore_Impl( aOriginalContent, xDummyEnv ) ) 1573cdf0e10cSrcweir { 1574cdf0e10cSrcweir // connect the medium to the temporary file of the storage 1575cdf0e10cSrcweir pImp->aContent = ::ucbhelper::Content(); 1576cdf0e10cSrcweir aName = aBackupExc.TemporaryFileURL; 1577cdf0e10cSrcweir OSL_ENSURE( aName.Len(), "The exception _must_ contain the temporary URL!\n" ); 1578cdf0e10cSrcweir } 1579cdf0e10cSrcweir } 1580cdf0e10cSrcweir 1581cdf0e10cSrcweir if ( !GetError() ) 1582cdf0e10cSrcweir SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1583cdf0e10cSrcweir } 1584cdf0e10cSrcweir } 1585cdf0e10cSrcweir catch ( uno::Exception& ) 1586cdf0e10cSrcweir { 1587cdf0e10cSrcweir //TODO/LATER: improve error handling 1588cdf0e10cSrcweir SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1589cdf0e10cSrcweir } 1590cdf0e10cSrcweir } 1591cdf0e10cSrcweir } 1592cdf0e10cSrcweir } 1593cdf0e10cSrcweir 1594cdf0e10cSrcweir return bResult; 1595cdf0e10cSrcweir } 1596cdf0e10cSrcweir 1597cdf0e10cSrcweir //------------------------------------------------------------------ 1598cdf0e10cSrcweir sal_Bool SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource, 1599cdf0e10cSrcweir const INetURLObject& aDest, 1600cdf0e10cSrcweir const Reference< ::com::sun::star::ucb::XCommandEnvironment >& xComEnv ) 1601cdf0e10cSrcweir { 1602cdf0e10cSrcweir sal_Bool bResult = sal_False; 1603cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 1604cdf0e10cSrcweir Reference< XOutputStream > aDestStream; 1605cdf0e10cSrcweir ::ucbhelper::Content aOriginalContent; 1606cdf0e10cSrcweir 1607cdf0e10cSrcweir try 1608cdf0e10cSrcweir { 1609cdf0e10cSrcweir aOriginalContent = ::ucbhelper::Content( aDest.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); 1610cdf0e10cSrcweir } 1611cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandAbortedException& ) 1612cdf0e10cSrcweir { 1613cdf0e10cSrcweir eError = ERRCODE_ABORT; 1614cdf0e10cSrcweir } 1615cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException& ) 1616cdf0e10cSrcweir { 1617cdf0e10cSrcweir eError = ERRCODE_ABORT; 1618cdf0e10cSrcweir } 1619cdf0e10cSrcweir catch (const ::com::sun::star::ucb::ContentCreationException& ex) 1620cdf0e10cSrcweir { 1621cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1622cdf0e10cSrcweir if ( 1623cdf0e10cSrcweir (ex.eError == ::com::sun::star::ucb::ContentCreationError_NO_CONTENT_PROVIDER ) || 1624cdf0e10cSrcweir (ex.eError == ::com::sun::star::ucb::ContentCreationError_CONTENT_CREATION_FAILED) 1625cdf0e10cSrcweir ) 1626cdf0e10cSrcweir { 1627cdf0e10cSrcweir eError = ERRCODE_IO_NOTEXISTSPATH; 1628cdf0e10cSrcweir } 1629cdf0e10cSrcweir } 1630cdf0e10cSrcweir catch (const ::com::sun::star::uno::Exception&) 1631cdf0e10cSrcweir { 1632cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1633cdf0e10cSrcweir } 1634cdf0e10cSrcweir 1635cdf0e10cSrcweir if( !eError || (eError & ERRCODE_WARNING_MASK) ) 1636cdf0e10cSrcweir { 1637cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1638cdf0e10cSrcweir CloseStorage(); 1639cdf0e10cSrcweir 1640cdf0e10cSrcweir CloseStreams_Impl(); 1641cdf0e10cSrcweir 1642cdf0e10cSrcweir ::ucbhelper::Content aTempCont; 1643cdf0e10cSrcweir if( ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, aTempCont ) ) 1644cdf0e10cSrcweir { 1645cdf0e10cSrcweir sal_Bool bTransactStarted = sal_False; 1646cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pOverWrite, SfxBoolItem, SID_OVERWRITE, sal_False ); 1647cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pRename, SfxBoolItem, SID_RENAME, sal_False ); 1648cdf0e10cSrcweir sal_Bool bRename = pRename ? pRename->GetValue() : sal_False; 1649cdf0e10cSrcweir sal_Bool bOverWrite = pOverWrite ? pOverWrite->GetValue() : !bRename; 1650cdf0e10cSrcweir 1651cdf0e10cSrcweir try 1652cdf0e10cSrcweir { 1653cdf0e10cSrcweir if( bOverWrite && ::utl::UCBContentHelper::IsDocument( aDest.GetMainURL( INetURLObject::NO_DECODE ) ) ) 1654cdf0e10cSrcweir { 1655cdf0e10cSrcweir if( ! pImp->m_aBackupURL.getLength() ) 1656cdf0e10cSrcweir DoInternalBackup_Impl( aOriginalContent ); 1657cdf0e10cSrcweir 1658cdf0e10cSrcweir if( pImp->m_aBackupURL.getLength() ) 1659cdf0e10cSrcweir { 1660cdf0e10cSrcweir Reference< XInputStream > aTempInput = aTempCont.openStream(); 1661cdf0e10cSrcweir bTransactStarted = sal_True; 1662cdf0e10cSrcweir aOriginalContent.setPropertyValue( ::rtl::OUString::createFromAscii( "Size" ), 1663cdf0e10cSrcweir uno::makeAny( (sal_Int64)0 ) ); 1664cdf0e10cSrcweir aOriginalContent.writeStream( aTempInput, bOverWrite ); 1665cdf0e10cSrcweir bResult = sal_True; 1666cdf0e10cSrcweir } 1667cdf0e10cSrcweir else 1668cdf0e10cSrcweir { 1669cdf0e10cSrcweir eError = ERRCODE_SFX_CANTCREATEBACKUP; 1670cdf0e10cSrcweir } 1671cdf0e10cSrcweir } 1672cdf0e10cSrcweir else 1673cdf0e10cSrcweir { 1674cdf0e10cSrcweir Reference< XInputStream > aTempInput = aTempCont.openStream(); 1675cdf0e10cSrcweir aOriginalContent.writeStream( aTempInput, bOverWrite ); 1676cdf0e10cSrcweir bResult = sal_True; 1677cdf0e10cSrcweir } 1678cdf0e10cSrcweir } 1679cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandAbortedException& ) 1680cdf0e10cSrcweir { 1681cdf0e10cSrcweir eError = ERRCODE_ABORT; 1682cdf0e10cSrcweir } 1683cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException& ) 1684cdf0e10cSrcweir { 1685cdf0e10cSrcweir eError = ERRCODE_ABORT; 1686cdf0e10cSrcweir } 1687cdf0e10cSrcweir catch ( ::com::sun::star::ucb::InteractiveIOException& r ) 1688cdf0e10cSrcweir { 1689cdf0e10cSrcweir if ( r.Code == IOErrorCode_ACCESS_DENIED ) 1690cdf0e10cSrcweir eError = ERRCODE_IO_ACCESSDENIED; 1691cdf0e10cSrcweir else if ( r.Code == IOErrorCode_NOT_EXISTING ) 1692cdf0e10cSrcweir eError = ERRCODE_IO_NOTEXISTS; 1693cdf0e10cSrcweir else if ( r.Code == IOErrorCode_CANT_READ ) 1694cdf0e10cSrcweir eError = ERRCODE_IO_CANTREAD; 1695cdf0e10cSrcweir else 1696cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1697cdf0e10cSrcweir } 1698cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 1699cdf0e10cSrcweir { 1700cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1701cdf0e10cSrcweir } 1702cdf0e10cSrcweir 1703cdf0e10cSrcweir if ( bResult ) 1704cdf0e10cSrcweir { 1705cdf0e10cSrcweir if ( pImp->pTempFile ) 1706cdf0e10cSrcweir { 1707cdf0e10cSrcweir pImp->pTempFile->EnableKillingFile( sal_True ); 1708cdf0e10cSrcweir delete pImp->pTempFile; 1709cdf0e10cSrcweir pImp->pTempFile = NULL; 1710cdf0e10cSrcweir } 1711cdf0e10cSrcweir } 1712cdf0e10cSrcweir else if ( bTransactStarted ) 1713cdf0e10cSrcweir { 1714cdf0e10cSrcweir UseBackupToRestore_Impl( aOriginalContent, xDummyEnv ); 1715cdf0e10cSrcweir } 1716cdf0e10cSrcweir } 1717cdf0e10cSrcweir else 1718cdf0e10cSrcweir eError = ERRCODE_IO_CANTREAD; 1719cdf0e10cSrcweir } 1720cdf0e10cSrcweir 1721cdf0e10cSrcweir return bResult; 1722cdf0e10cSrcweir } 1723cdf0e10cSrcweir 1724cdf0e10cSrcweir //------------------------------------------------------------------ 1725cdf0e10cSrcweir sal_Bool SfxMedium::TryDirectTransfer( const ::rtl::OUString& aURL, SfxItemSet& aTargetSet ) 1726cdf0e10cSrcweir { 1727cdf0e10cSrcweir if ( GetError() ) 1728cdf0e10cSrcweir return sal_False; 1729cdf0e10cSrcweir 1730cdf0e10cSrcweir // if the document had no password it should be stored without password 1731cdf0e10cSrcweir // if the document had password it should be stored with the same password 1732cdf0e10cSrcweir // otherwise the stream copying can not be done 1733cdf0e10cSrcweir SFX_ITEMSET_ARG( &aTargetSet, pNewPassItem, SfxStringItem, SID_PASSWORD, sal_False ); 1734cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pOldPassItem, SfxStringItem, SID_PASSWORD, sal_False ); 1735cdf0e10cSrcweir if ( ( !pNewPassItem && !pOldPassItem ) 1736cdf0e10cSrcweir || ( pNewPassItem && pOldPassItem && pNewPassItem->GetValue().Equals( pOldPassItem->GetValue() ) ) ) 1737cdf0e10cSrcweir { 1738cdf0e10cSrcweir // the filter must be the same 1739cdf0e10cSrcweir SFX_ITEMSET_ARG( &aTargetSet, pNewFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 1740cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pOldFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 1741cdf0e10cSrcweir if ( pNewFilterItem && pOldFilterItem && pNewFilterItem->GetValue().Equals( pOldFilterItem->GetValue() ) ) 1742cdf0e10cSrcweir { 1743cdf0e10cSrcweir // get the input stream and copy it 1744cdf0e10cSrcweir // in case of success return true 1745cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = GetInputStream(); 1746cdf0e10cSrcweir 1747cdf0e10cSrcweir ResetError(); 1748cdf0e10cSrcweir if ( xInStream.is() ) 1749cdf0e10cSrcweir { 1750cdf0e10cSrcweir try 1751cdf0e10cSrcweir { 1752cdf0e10cSrcweir uno::Reference< io::XSeekable > xSeek( xInStream, uno::UNO_QUERY ); 1753cdf0e10cSrcweir sal_Int64 nPos = 0; 1754cdf0e10cSrcweir if ( xSeek.is() ) 1755cdf0e10cSrcweir { 1756cdf0e10cSrcweir nPos = xSeek->getPosition(); 1757cdf0e10cSrcweir xSeek->seek( 0 ); 1758cdf0e10cSrcweir } 1759cdf0e10cSrcweir 1760cdf0e10cSrcweir uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; 1761cdf0e10cSrcweir ::ucbhelper::Content aTargetContent( aURL, xEnv ); 1762cdf0e10cSrcweir 1763cdf0e10cSrcweir InsertCommandArgument aInsertArg; 1764cdf0e10cSrcweir aInsertArg.Data = xInStream; 1765cdf0e10cSrcweir SFX_ITEMSET_ARG( &aTargetSet, pRename, SfxBoolItem, SID_RENAME, sal_False ); 1766cdf0e10cSrcweir SFX_ITEMSET_ARG( &aTargetSet, pOverWrite, SfxBoolItem, SID_OVERWRITE, sal_False ); 1767cdf0e10cSrcweir if ( (pOverWrite && !pOverWrite->GetValue()) // argument says: never overwrite 1768cdf0e10cSrcweir || (pRename && pRename->GetValue()) ) // argument says: rename file 1769cdf0e10cSrcweir aInsertArg.ReplaceExisting = sal_False; 1770cdf0e10cSrcweir else 1771cdf0e10cSrcweir aInsertArg.ReplaceExisting = sal_True; // default is overwrite existing files 1772cdf0e10cSrcweir 1773cdf0e10cSrcweir Any aCmdArg; 1774cdf0e10cSrcweir aCmdArg <<= aInsertArg; 1775cdf0e10cSrcweir aTargetContent.executeCommand( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ), 1776cdf0e10cSrcweir aCmdArg ); 1777cdf0e10cSrcweir 1778cdf0e10cSrcweir if ( xSeek.is() ) 1779cdf0e10cSrcweir xSeek->seek( nPos ); 1780cdf0e10cSrcweir 1781cdf0e10cSrcweir return sal_True; 1782cdf0e10cSrcweir } 1783cdf0e10cSrcweir catch( uno::Exception& ) 1784cdf0e10cSrcweir {} 1785cdf0e10cSrcweir } 1786cdf0e10cSrcweir } 1787cdf0e10cSrcweir } 1788cdf0e10cSrcweir 1789cdf0e10cSrcweir return sal_False; 1790cdf0e10cSrcweir } 1791cdf0e10cSrcweir 1792cdf0e10cSrcweir //------------------------------------------------------------------ 1793cdf0e10cSrcweir void SfxMedium::Transfer_Impl() 1794cdf0e10cSrcweir { 1795cdf0e10cSrcweir // The transfer is required only in two cases: either if there is a temporary file or if there is a salvage item 1796cdf0e10cSrcweir String aNameURL; 1797cdf0e10cSrcweir if ( pImp->pTempFile ) 1798cdf0e10cSrcweir aNameURL = pImp->pTempFile->GetURL(); 1799cdf0e10cSrcweir else if ( aLogicName.Len() && pImp->m_bSalvageMode ) 1800cdf0e10cSrcweir { 1801cdf0e10cSrcweir // makes sence only in case logic name is set 1802cdf0e10cSrcweir if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aNameURL ) ) 1803cdf0e10cSrcweir OSL_ENSURE( sal_False, "The medium name is not convertable!\n" ); 1804cdf0e10cSrcweir } 1805cdf0e10cSrcweir 1806cdf0e10cSrcweir if ( aNameURL.Len() && ( !eError || (eError & ERRCODE_WARNING_MASK) ) ) 1807cdf0e10cSrcweir { 1808cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxMedium::Transfer_Impl, copying to target" ); 1809cdf0e10cSrcweir 1810cdf0e10cSrcweir Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; 1811cdf0e10cSrcweir Reference< XOutputStream > rOutStream; 1812cdf0e10cSrcweir 1813cdf0e10cSrcweir // in case an output stream is provided from outside and the URL is correct 1814cdf0e10cSrcweir // commit to the stream 1815cdf0e10cSrcweir if( aLogicName.CompareToAscii( "private:stream", 14 ) == COMPARE_EQUAL ) 1816cdf0e10cSrcweir { 1817cdf0e10cSrcweir // TODO/LATER: support storing to SID_STREAM 1818cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pOutStreamItem, SfxUnoAnyItem, SID_OUTPUTSTREAM, sal_False); 1819cdf0e10cSrcweir if( pOutStreamItem && ( pOutStreamItem->GetValue() >>= rOutStream ) ) 1820cdf0e10cSrcweir { 1821cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1822cdf0e10cSrcweir CloseStorage(); 1823cdf0e10cSrcweir 1824cdf0e10cSrcweir CloseStreams_Impl(); 1825cdf0e10cSrcweir 1826cdf0e10cSrcweir INetURLObject aSource( aNameURL ); 1827cdf0e10cSrcweir ::ucbhelper::Content aTempCont; 1828cdf0e10cSrcweir if( ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aTempCont ) ) 1829cdf0e10cSrcweir { 1830cdf0e10cSrcweir try 1831cdf0e10cSrcweir { 1832cdf0e10cSrcweir sal_Int32 nRead; 1833cdf0e10cSrcweir sal_Int32 nBufferSize = 32767; 1834cdf0e10cSrcweir Sequence < sal_Int8 > aSequence ( nBufferSize ); 1835cdf0e10cSrcweir Reference< XInputStream > aTempInput = aTempCont.openStream(); 1836cdf0e10cSrcweir 1837cdf0e10cSrcweir do 1838cdf0e10cSrcweir { 1839cdf0e10cSrcweir nRead = aTempInput->readBytes ( aSequence, nBufferSize ); 1840cdf0e10cSrcweir if ( nRead < nBufferSize ) 1841cdf0e10cSrcweir { 1842cdf0e10cSrcweir Sequence < sal_Int8 > aTempBuf ( aSequence.getConstArray(), nRead ); 1843cdf0e10cSrcweir rOutStream->writeBytes ( aTempBuf ); 1844cdf0e10cSrcweir } 1845cdf0e10cSrcweir else 1846cdf0e10cSrcweir rOutStream->writeBytes ( aSequence ); 1847cdf0e10cSrcweir } 1848cdf0e10cSrcweir while ( nRead == nBufferSize ); 1849cdf0e10cSrcweir 1850cdf0e10cSrcweir // remove temporary file 1851cdf0e10cSrcweir if ( pImp->pTempFile ) 1852cdf0e10cSrcweir { 1853cdf0e10cSrcweir pImp->pTempFile->EnableKillingFile( sal_True ); 1854cdf0e10cSrcweir delete pImp->pTempFile; 1855cdf0e10cSrcweir pImp->pTempFile = NULL; 1856cdf0e10cSrcweir } 1857cdf0e10cSrcweir } 1858cdf0e10cSrcweir catch( Exception& ) 1859cdf0e10cSrcweir {} 1860cdf0e10cSrcweir } 1861cdf0e10cSrcweir } 1862cdf0e10cSrcweir else 1863cdf0e10cSrcweir { 1864cdf0e10cSrcweir DBG_ERROR( "Illegal Output stream parameter!\n" ); 1865cdf0e10cSrcweir SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1866cdf0e10cSrcweir } 1867cdf0e10cSrcweir 1868cdf0e10cSrcweir // free the reference 1869cdf0e10cSrcweir if ( pSet ) 1870cdf0e10cSrcweir pSet->ClearItem( SID_OUTPUTSTREAM ); 1871cdf0e10cSrcweir 1872cdf0e10cSrcweir return; 1873cdf0e10cSrcweir } 1874cdf0e10cSrcweir 1875cdf0e10cSrcweir GetContent(); 1876cdf0e10cSrcweir if ( !pImp->aContent.get().is() ) 1877cdf0e10cSrcweir { 1878cdf0e10cSrcweir eError = ERRCODE_IO_NOTEXISTS; 1879cdf0e10cSrcweir return; 1880cdf0e10cSrcweir } 1881cdf0e10cSrcweir 1882cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pSegmentSize, SfxInt32Item, SID_SEGMENTSIZE, sal_False); 1883cdf0e10cSrcweir if ( pSegmentSize ) 1884cdf0e10cSrcweir { 1885cdf0e10cSrcweir // this file must be stored into a disk spanned package 1886cdf0e10cSrcweir try 1887cdf0e10cSrcweir { 1888cdf0e10cSrcweir uno::Reference < embed::XStorage > xStor = comphelper::OStorageHelper::GetStorageFromURL( GetName(), 1889cdf0e10cSrcweir embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); 1890cdf0e10cSrcweir 1891cdf0e10cSrcweir // set segment size property; package will automatically be divided in pieces fitting 1892cdf0e10cSrcweir // into this size 1893cdf0e10cSrcweir ::com::sun::star::uno::Any aAny; 1894cdf0e10cSrcweir aAny <<= pSegmentSize->GetValue(); 1895cdf0e10cSrcweir 1896cdf0e10cSrcweir uno::Reference < beans::XPropertySet > xSet( pImp->xStorage, uno::UNO_QUERY ); 1897cdf0e10cSrcweir xSet->setPropertyValue( String::CreateFromAscii("SegmentSize"), aAny ); 1898cdf0e10cSrcweir 1899cdf0e10cSrcweir // copy the temporary storage into the disk spanned package 1900cdf0e10cSrcweir GetStorage()->copyToStorage( xStor ); 1901cdf0e10cSrcweir uno::Reference < embed::XTransactedObject > xTrans( pImp->xStorage, uno::UNO_QUERY ); 1902cdf0e10cSrcweir if ( xTrans.is() ) 1903cdf0e10cSrcweir xTrans->commit(); 1904cdf0e10cSrcweir 1905cdf0e10cSrcweir } 1906cdf0e10cSrcweir catch ( uno::Exception& ) 1907cdf0e10cSrcweir { 1908cdf0e10cSrcweir //TODO/MBA: error handling 1909cdf0e10cSrcweir } 1910cdf0e10cSrcweir return; 1911cdf0e10cSrcweir } 1912cdf0e10cSrcweir 1913cdf0e10cSrcweir INetURLObject aDest( GetURLObject() ); 1914cdf0e10cSrcweir 1915cdf0e10cSrcweir // source is the temp file written so far 1916cdf0e10cSrcweir INetURLObject aSource( aNameURL ); 1917cdf0e10cSrcweir 1918cdf0e10cSrcweir // a special case, an interaction handler should be used for 1919cdf0e10cSrcweir // authentication in case it is available 1920cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv; 1921cdf0e10cSrcweir Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = GetInteractionHandler(); 1922cdf0e10cSrcweir if (xInteractionHandler.is()) 1923cdf0e10cSrcweir xComEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, 1924cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XProgressHandler >() ); 1925cdf0e10cSrcweir 1926cdf0e10cSrcweir if ( ::utl::LocalFileHelper::IsLocalFile( aDest.GetMainURL( INetURLObject::NO_DECODE ) ) || !aDest.removeSegment() ) 1927cdf0e10cSrcweir { 1928cdf0e10cSrcweir TransactedTransferForFS_Impl( aSource, aDest, xComEnv ); 1929cdf0e10cSrcweir } 1930cdf0e10cSrcweir else 1931cdf0e10cSrcweir { 1932cdf0e10cSrcweir // create content for the parent folder and call transfer on that content with the source content 1933cdf0e10cSrcweir // and the destination file name as parameters 1934cdf0e10cSrcweir ::ucbhelper::Content aSourceContent; 1935cdf0e10cSrcweir ::ucbhelper::Content aTransferContent; 1936cdf0e10cSrcweir 1937cdf0e10cSrcweir String aFileName = GetLongName(); 1938cdf0e10cSrcweir if ( !aFileName.Len() ) 1939cdf0e10cSrcweir aFileName = GetURLObject().getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 1940cdf0e10cSrcweir 1941cdf0e10cSrcweir try 1942cdf0e10cSrcweir { 1943cdf0e10cSrcweir aTransferContent = ::ucbhelper::Content( aDest.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); 1944cdf0e10cSrcweir } 1945cdf0e10cSrcweir catch (const ::com::sun::star::ucb::ContentCreationException& ex) 1946cdf0e10cSrcweir { 1947cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1948cdf0e10cSrcweir if ( 1949cdf0e10cSrcweir (ex.eError == ::com::sun::star::ucb::ContentCreationError_NO_CONTENT_PROVIDER ) || 1950cdf0e10cSrcweir (ex.eError == ::com::sun::star::ucb::ContentCreationError_CONTENT_CREATION_FAILED) 1951cdf0e10cSrcweir ) 1952cdf0e10cSrcweir { 1953cdf0e10cSrcweir eError = ERRCODE_IO_NOTEXISTSPATH; 1954cdf0e10cSrcweir } 1955cdf0e10cSrcweir } 1956cdf0e10cSrcweir catch (const ::com::sun::star::uno::Exception&) 1957cdf0e10cSrcweir { 1958cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1959cdf0e10cSrcweir } 1960cdf0e10cSrcweir 1961cdf0e10cSrcweir if ( !eError || (eError & ERRCODE_WARNING_MASK) ) 1962cdf0e10cSrcweir { 1963cdf0e10cSrcweir // free resources, otherwise the transfer may fail 1964cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1965cdf0e10cSrcweir CloseStorage(); 1966cdf0e10cSrcweir 1967cdf0e10cSrcweir CloseStreams_Impl(); 1968cdf0e10cSrcweir 1969cdf0e10cSrcweir ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aSourceContent ); 1970cdf0e10cSrcweir 1971cdf0e10cSrcweir // check for external parameters that may customize the handling of NameClash situations 1972cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pRename, SfxBoolItem, SID_RENAME, sal_False ); 1973cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pOverWrite, SfxBoolItem, SID_OVERWRITE, sal_False ); 1974cdf0e10cSrcweir sal_Int32 nNameClash; 1975cdf0e10cSrcweir if ( pOverWrite && !pOverWrite->GetValue() ) 1976cdf0e10cSrcweir // argument says: never overwrite 1977cdf0e10cSrcweir nNameClash = NameClash::ERROR; 1978cdf0e10cSrcweir else if ( pRename && pRename->GetValue() ) 1979cdf0e10cSrcweir // argument says: rename file 1980cdf0e10cSrcweir nNameClash = NameClash::RENAME; 1981cdf0e10cSrcweir else 1982cdf0e10cSrcweir // default is overwrite existing files 1983cdf0e10cSrcweir nNameClash = NameClash::OVERWRITE; 1984cdf0e10cSrcweir 1985cdf0e10cSrcweir try 1986cdf0e10cSrcweir { 1987cdf0e10cSrcweir if (!aTransferContent.transferContent( aSourceContent, ::ucbhelper::InsertOperation_COPY, aFileName, nNameClash )) 1988cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1989cdf0e10cSrcweir } 1990cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandAbortedException& ) 1991cdf0e10cSrcweir { 1992cdf0e10cSrcweir eError = ERRCODE_ABORT; 1993cdf0e10cSrcweir } 1994cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException& ) 1995cdf0e10cSrcweir { 1996cdf0e10cSrcweir eError = ERRCODE_ABORT; 1997cdf0e10cSrcweir } 1998cdf0e10cSrcweir catch ( ::com::sun::star::ucb::InteractiveIOException& r ) 1999cdf0e10cSrcweir { 2000cdf0e10cSrcweir if ( r.Code == IOErrorCode_ACCESS_DENIED ) 2001cdf0e10cSrcweir eError = ERRCODE_IO_ACCESSDENIED; 2002cdf0e10cSrcweir else if ( r.Code == IOErrorCode_NOT_EXISTING ) 2003cdf0e10cSrcweir eError = ERRCODE_IO_NOTEXISTS; 2004cdf0e10cSrcweir else if ( r.Code == IOErrorCode_CANT_READ ) 2005cdf0e10cSrcweir eError = ERRCODE_IO_CANTREAD; 2006cdf0e10cSrcweir else 2007cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 2008cdf0e10cSrcweir } 2009cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 2010cdf0e10cSrcweir { 2011cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 2012cdf0e10cSrcweir } 2013cdf0e10cSrcweir 2014cdf0e10cSrcweir // do not switch from temporary file in case of nonfile protocol 2015cdf0e10cSrcweir } 2016cdf0e10cSrcweir } 2017cdf0e10cSrcweir 2018cdf0e10cSrcweir if ( ( !eError || (eError & ERRCODE_WARNING_MASK) ) && !pImp->pTempFile ) 2019cdf0e10cSrcweir { 2020cdf0e10cSrcweir // without a TempFile the physical and logical name should be the same after successful transfer 2021cdf0e10cSrcweir ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), 2022cdf0e10cSrcweir aName ); 2023cdf0e10cSrcweir pImp->m_bSalvageMode = sal_False; 2024cdf0e10cSrcweir } 2025cdf0e10cSrcweir } 2026cdf0e10cSrcweir } 2027cdf0e10cSrcweir 2028cdf0e10cSrcweir //------------------------------------------------------------------ 2029cdf0e10cSrcweir void SfxMedium::DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent, 2030cdf0e10cSrcweir const String& aPrefix, 2031cdf0e10cSrcweir const String& aExtension, 2032cdf0e10cSrcweir const String& aDestDir ) 2033cdf0e10cSrcweir { 2034cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxMedium::DoInternalBackup_Impl( with destdir )" ); 2035cdf0e10cSrcweir 2036cdf0e10cSrcweir if ( pImp->m_aBackupURL.getLength() ) 2037cdf0e10cSrcweir return; // the backup was done already 2038cdf0e10cSrcweir 2039cdf0e10cSrcweir ::utl::TempFile aTransactTemp( aPrefix, &aExtension, &aDestDir ); 2040cdf0e10cSrcweir aTransactTemp.EnableKillingFile( sal_False ); 2041cdf0e10cSrcweir 2042cdf0e10cSrcweir INetURLObject aBackObj( aTransactTemp.GetURL() ); 2043cdf0e10cSrcweir ::rtl::OUString aBackupName = aBackObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 2044cdf0e10cSrcweir 2045cdf0e10cSrcweir Reference < ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 2046cdf0e10cSrcweir ::ucbhelper::Content aBackupCont; 2047cdf0e10cSrcweir if( ::ucbhelper::Content::create( aDestDir, xDummyEnv, aBackupCont ) ) 2048cdf0e10cSrcweir { 2049cdf0e10cSrcweir try 2050cdf0e10cSrcweir { 2051cdf0e10cSrcweir if( aBackupCont.transferContent( aOriginalContent, 2052cdf0e10cSrcweir ::ucbhelper::InsertOperation_COPY, 2053cdf0e10cSrcweir aBackupName, 2054cdf0e10cSrcweir NameClash::OVERWRITE ) ) 2055cdf0e10cSrcweir { 2056cdf0e10cSrcweir pImp->m_aBackupURL = aBackObj.GetMainURL( INetURLObject::NO_DECODE ); 2057cdf0e10cSrcweir pImp->m_bRemoveBackup = sal_True; 2058cdf0e10cSrcweir } 2059cdf0e10cSrcweir } 2060cdf0e10cSrcweir catch( Exception& ) 2061cdf0e10cSrcweir {} 2062cdf0e10cSrcweir } 2063cdf0e10cSrcweir 2064cdf0e10cSrcweir if ( !pImp->m_aBackupURL.getLength() ) 2065cdf0e10cSrcweir aTransactTemp.EnableKillingFile( sal_True ); 2066cdf0e10cSrcweir } 2067cdf0e10cSrcweir 2068cdf0e10cSrcweir //------------------------------------------------------------------ 2069cdf0e10cSrcweir void SfxMedium::DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent ) 2070cdf0e10cSrcweir { 2071cdf0e10cSrcweir if ( pImp->m_aBackupURL.getLength() ) 2072cdf0e10cSrcweir return; // the backup was done already 2073cdf0e10cSrcweir 2074cdf0e10cSrcweir ::rtl::OUString aFileName = GetURLObject().getName( INetURLObject::LAST_SEGMENT, 2075cdf0e10cSrcweir true, 2076cdf0e10cSrcweir INetURLObject::NO_DECODE ); 2077cdf0e10cSrcweir 2078cdf0e10cSrcweir sal_Int32 nPrefixLen = aFileName.lastIndexOf( '.' ); 2079cdf0e10cSrcweir String aPrefix = ( nPrefixLen == -1 ) ? aFileName : aFileName.copy( 0, nPrefixLen ); 2080cdf0e10cSrcweir String aExtension = ( nPrefixLen == -1 ) ? String() : String(aFileName.copy( nPrefixLen )); 2081cdf0e10cSrcweir String aBakDir = SvtPathOptions().GetBackupPath(); 2082cdf0e10cSrcweir 2083cdf0e10cSrcweir DoInternalBackup_Impl( aOriginalContent, aPrefix, aExtension, aBakDir ); 2084cdf0e10cSrcweir 2085cdf0e10cSrcweir if ( !pImp->m_aBackupURL.getLength() ) 2086cdf0e10cSrcweir { 2087cdf0e10cSrcweir // the copiing to the backup catalog failed ( for example because 2088cdf0e10cSrcweir // of using an encrypted partition as target catalog ) 2089cdf0e10cSrcweir // since the user did not specify to make backup explicitly 2090cdf0e10cSrcweir // office should try to make backup in another place, 2091cdf0e10cSrcweir // target catalog does not look bad for this case ( and looks 2092cdf0e10cSrcweir // to be the only way for encrypted partitions ) 2093cdf0e10cSrcweir 2094cdf0e10cSrcweir INetURLObject aDest = GetURLObject(); 2095cdf0e10cSrcweir if ( aDest.removeSegment() ) 2096cdf0e10cSrcweir DoInternalBackup_Impl( aOriginalContent, aPrefix, aExtension, aDest.GetMainURL( INetURLObject::NO_DECODE ) ); 2097cdf0e10cSrcweir } 2098cdf0e10cSrcweir } 2099cdf0e10cSrcweir 2100cdf0e10cSrcweir 2101cdf0e10cSrcweir //------------------------------------------------------------------ 2102cdf0e10cSrcweir void SfxMedium::DoBackup_Impl() 2103cdf0e10cSrcweir { 2104cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxMedium::DoBackup_Impl" ); 2105cdf0e10cSrcweir 2106cdf0e10cSrcweir // source file name is the logical name of this medium 2107cdf0e10cSrcweir INetURLObject aSource( GetURLObject() ); 2108cdf0e10cSrcweir 2109cdf0e10cSrcweir // there is nothing to backup in case source file does not exist 2110cdf0e10cSrcweir if ( !::utl::UCBContentHelper::IsDocument( aSource.GetMainURL( INetURLObject::NO_DECODE ) ) ) 2111cdf0e10cSrcweir return; 2112cdf0e10cSrcweir 2113cdf0e10cSrcweir sal_Bool bSuccess = sal_False; 2114cdf0e10cSrcweir 2115cdf0e10cSrcweir // get path for backups 2116cdf0e10cSrcweir String aBakDir = SvtPathOptions().GetBackupPath(); 2117cdf0e10cSrcweir if( aBakDir.Len() ) 2118cdf0e10cSrcweir { 2119cdf0e10cSrcweir // create content for the parent folder ( = backup folder ) 2120cdf0e10cSrcweir ::ucbhelper::Content aContent; 2121cdf0e10cSrcweir Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; 2122cdf0e10cSrcweir if( ::ucbhelper::Content::create( aBakDir, xEnv, aContent ) ) 2123cdf0e10cSrcweir { 2124cdf0e10cSrcweir // save as ".bak" file 2125cdf0e10cSrcweir INetURLObject aDest( aBakDir ); 2126cdf0e10cSrcweir aDest.insertName( aSource.getName() ); 2127cdf0e10cSrcweir aDest.setExtension( DEFINE_CONST_UNICODE( "bak" ) ); 2128cdf0e10cSrcweir String aFileName = aDest.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 2129cdf0e10cSrcweir 2130cdf0e10cSrcweir // create a content for the source file 2131cdf0e10cSrcweir ::ucbhelper::Content aSourceContent; 2132cdf0e10cSrcweir if ( ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aSourceContent ) ) 2133cdf0e10cSrcweir { 2134cdf0e10cSrcweir try 2135cdf0e10cSrcweir { 2136cdf0e10cSrcweir // do the transfer ( copy source file to backup dir ) 2137cdf0e10cSrcweir bSuccess = aContent.transferContent( aSourceContent, 2138cdf0e10cSrcweir ::ucbhelper::InsertOperation_COPY, 2139cdf0e10cSrcweir aFileName, 2140cdf0e10cSrcweir NameClash::OVERWRITE ); 2141cdf0e10cSrcweir if( bSuccess ) 2142cdf0e10cSrcweir { 2143cdf0e10cSrcweir pImp->m_aBackupURL = aDest.GetMainURL( INetURLObject::NO_DECODE ); 2144cdf0e10cSrcweir pImp->m_bRemoveBackup = sal_False; 2145cdf0e10cSrcweir } 2146cdf0e10cSrcweir } 2147cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 2148cdf0e10cSrcweir { 2149cdf0e10cSrcweir } 2150cdf0e10cSrcweir } 2151cdf0e10cSrcweir } 2152cdf0e10cSrcweir } 2153cdf0e10cSrcweir 2154cdf0e10cSrcweir if ( !bSuccess ) 2155cdf0e10cSrcweir { 2156cdf0e10cSrcweir eError = ERRCODE_SFX_CANTCREATEBACKUP; 2157cdf0e10cSrcweir } 2158cdf0e10cSrcweir } 2159cdf0e10cSrcweir 2160cdf0e10cSrcweir //------------------------------------------------------------------ 2161cdf0e10cSrcweir void SfxMedium::ClearBackup_Impl() 2162cdf0e10cSrcweir { 2163cdf0e10cSrcweir if( pImp->m_bRemoveBackup ) 2164cdf0e10cSrcweir { 2165cdf0e10cSrcweir // currently a document is always stored in a new medium, 2166cdf0e10cSrcweir // thus if a backup can not be removed the backup URL should not be cleaned 2167cdf0e10cSrcweir if ( pImp->m_aBackupURL.getLength() ) 2168cdf0e10cSrcweir { 2169cdf0e10cSrcweir if ( ::utl::UCBContentHelper::Kill( pImp->m_aBackupURL ) ) 2170cdf0e10cSrcweir // || !::utl::UCBContentHelper::IsDocument( pImp->m_aBackupURL ) ); 2171cdf0e10cSrcweir { 2172cdf0e10cSrcweir pImp->m_bRemoveBackup = sal_False; 2173cdf0e10cSrcweir pImp->m_aBackupURL = ::rtl::OUString(); 2174cdf0e10cSrcweir } 2175cdf0e10cSrcweir else 2176cdf0e10cSrcweir { 2177cdf0e10cSrcweir 2178cdf0e10cSrcweir DBG_ERROR("Couldn't remove backup file!"); 2179cdf0e10cSrcweir } 2180cdf0e10cSrcweir } 2181cdf0e10cSrcweir } 2182cdf0e10cSrcweir else 2183cdf0e10cSrcweir pImp->m_aBackupURL = ::rtl::OUString(); 2184cdf0e10cSrcweir } 2185cdf0e10cSrcweir 2186cdf0e10cSrcweir //---------------------------------------------------------------- 2187cdf0e10cSrcweir void SfxMedium::GetLockingStream_Impl() 2188cdf0e10cSrcweir { 2189cdf0e10cSrcweir if ( ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) 2190cdf0e10cSrcweir && !pImp->m_xLockingStream.is() ) 2191cdf0e10cSrcweir { 2192cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pWriteStreamItem, SfxUnoAnyItem, SID_STREAM, sal_False); 2193cdf0e10cSrcweir if ( pWriteStreamItem ) 2194cdf0e10cSrcweir pWriteStreamItem->GetValue() >>= pImp->m_xLockingStream; 2195cdf0e10cSrcweir 2196cdf0e10cSrcweir if ( !pImp->m_xLockingStream.is() ) 2197cdf0e10cSrcweir { 2198cdf0e10cSrcweir // open the original document 2199cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > xProps; 2200cdf0e10cSrcweir TransformItems( SID_OPENDOC, *GetItemSet(), xProps ); 2201cdf0e10cSrcweir comphelper::MediaDescriptor aMedium( xProps ); 2202cdf0e10cSrcweir 2203cdf0e10cSrcweir aMedium.addInputStreamOwnLock(); 2204cdf0e10cSrcweir 2205cdf0e10cSrcweir uno::Reference< io::XInputStream > xInputStream; 2206cdf0e10cSrcweir aMedium[comphelper::MediaDescriptor::PROP_STREAM()] >>= pImp->m_xLockingStream; 2207cdf0e10cSrcweir aMedium[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream; 2208cdf0e10cSrcweir 2209cdf0e10cSrcweir if ( !pImp->pTempFile && !aName.Len() ) 2210cdf0e10cSrcweir { 2211cdf0e10cSrcweir // the medium is still based on the original file, it makes sence to initialize the streams 2212cdf0e10cSrcweir if ( pImp->m_xLockingStream.is() ) 2213cdf0e10cSrcweir pImp->xStream = pImp->m_xLockingStream; 2214cdf0e10cSrcweir 2215cdf0e10cSrcweir if ( xInputStream.is() ) 2216cdf0e10cSrcweir pImp->xInputStream = xInputStream; 2217cdf0e10cSrcweir 2218cdf0e10cSrcweir if ( !pImp->xInputStream.is() && pImp->xStream.is() ) 2219cdf0e10cSrcweir pImp->xInputStream = pImp->xStream->getInputStream(); 2220cdf0e10cSrcweir } 2221cdf0e10cSrcweir } 2222cdf0e10cSrcweir } 2223cdf0e10cSrcweir } 2224cdf0e10cSrcweir 2225cdf0e10cSrcweir //---------------------------------------------------------------- 2226cdf0e10cSrcweir void SfxMedium::GetMedium_Impl() 2227cdf0e10cSrcweir { 2228cdf0e10cSrcweir if ( !pInStream ) 2229cdf0e10cSrcweir { 2230cdf0e10cSrcweir pImp->bDownloadDone = sal_False; 2231cdf0e10cSrcweir Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = GetInteractionHandler(); 2232cdf0e10cSrcweir 2233cdf0e10cSrcweir //TODO/MBA: need support for SID_STREAM 2234cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pWriteStreamItem, SfxUnoAnyItem, SID_STREAM, sal_False); 2235cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pInStreamItem, SfxUnoAnyItem, SID_INPUTSTREAM, sal_False); 2236cdf0e10cSrcweir if ( pWriteStreamItem ) 2237cdf0e10cSrcweir { 2238cdf0e10cSrcweir pWriteStreamItem->GetValue() >>= pImp->xStream; 2239cdf0e10cSrcweir 2240cdf0e10cSrcweir if ( pInStreamItem ) 2241cdf0e10cSrcweir pInStreamItem->GetValue() >>= pImp->xInputStream; 2242cdf0e10cSrcweir 2243cdf0e10cSrcweir if ( !pImp->xInputStream.is() && pImp->xStream.is() ) 2244cdf0e10cSrcweir pImp->xInputStream = pImp->xStream->getInputStream(); 2245cdf0e10cSrcweir } 2246cdf0e10cSrcweir else if ( pInStreamItem ) 2247cdf0e10cSrcweir { 2248cdf0e10cSrcweir pInStreamItem->GetValue() >>= pImp->xInputStream; 2249cdf0e10cSrcweir } 2250cdf0e10cSrcweir else 2251cdf0e10cSrcweir { 2252cdf0e10cSrcweir uno::Sequence < beans::PropertyValue > xProps; 2253cdf0e10cSrcweir String aFileName; 2254cdf0e10cSrcweir if ( aName.Len() ) 2255cdf0e10cSrcweir { 2256cdf0e10cSrcweir if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aFileName ) ) 2257cdf0e10cSrcweir { 2258cdf0e10cSrcweir DBG_ERROR("Physical name not convertable!"); 2259cdf0e10cSrcweir } 2260cdf0e10cSrcweir } 2261cdf0e10cSrcweir else 2262cdf0e10cSrcweir aFileName = GetName(); 2263cdf0e10cSrcweir 2264cdf0e10cSrcweir // in case the temporary file exists the streams should be initialized from it, 2265cdf0e10cSrcweir // but the original MediaDescriptor should not be changed 2266cdf0e10cSrcweir sal_Bool bFromTempFile = ( pImp->pTempFile != NULL ); 2267cdf0e10cSrcweir 2268cdf0e10cSrcweir if ( !bFromTempFile ) 2269cdf0e10cSrcweir { 2270cdf0e10cSrcweir GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, aFileName ) ); 2271cdf0e10cSrcweir if( !(nStorOpenMode & STREAM_WRITE ) ) 2272cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 2273cdf0e10cSrcweir if (xInteractionHandler.is()) 2274cdf0e10cSrcweir GetItemSet()->Put( SfxUnoAnyItem( SID_INTERACTIONHANDLER, makeAny(xInteractionHandler) ) ); 2275cdf0e10cSrcweir } 2276cdf0e10cSrcweir 2277cdf0e10cSrcweir if ( m_xInputStreamToLoadFrom.is() ) 2278cdf0e10cSrcweir { 2279cdf0e10cSrcweir pImp->xInputStream = m_xInputStreamToLoadFrom; 2280cdf0e10cSrcweir pImp->xInputStream->skipBytes(0); 2281cdf0e10cSrcweir if(m_bIsReadOnly) 2282cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 2283cdf0e10cSrcweir 2284cdf0e10cSrcweir // m_xInputStreamToLoadFrom = 0; 2285cdf0e10cSrcweir } 2286cdf0e10cSrcweir else 2287cdf0e10cSrcweir { 2288cdf0e10cSrcweir TransformItems( SID_OPENDOC, *GetItemSet(), xProps ); 2289cdf0e10cSrcweir comphelper::MediaDescriptor aMedium( xProps ); 2290cdf0e10cSrcweir 2291cdf0e10cSrcweir if ( pImp->m_xLockingStream.is() && !bFromTempFile ) 2292cdf0e10cSrcweir { 2293cdf0e10cSrcweir // the medium is not based on the temporary file, so the original stream can be used 2294cdf0e10cSrcweir pImp->xStream = pImp->m_xLockingStream; 2295cdf0e10cSrcweir } 2296cdf0e10cSrcweir else 2297cdf0e10cSrcweir { 2298cdf0e10cSrcweir if ( bFromTempFile ) 2299cdf0e10cSrcweir { 2300cdf0e10cSrcweir aMedium[comphelper::MediaDescriptor::PROP_URL()] <<= ::rtl::OUString( aFileName ); 2301cdf0e10cSrcweir aMedium.erase( comphelper::MediaDescriptor::PROP_READONLY() ); 2302cdf0e10cSrcweir aMedium.addInputStream(); 2303cdf0e10cSrcweir } 2304cdf0e10cSrcweir else if ( ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) 2305cdf0e10cSrcweir { 2306cdf0e10cSrcweir // use the special locking approach only for file URLs 2307cdf0e10cSrcweir aMedium.addInputStreamOwnLock(); 2308cdf0e10cSrcweir } 2309cdf0e10cSrcweir else 2310cdf0e10cSrcweir aMedium.addInputStream(); 2311cdf0e10cSrcweir 2312cdf0e10cSrcweir // the ReadOnly property set in aMedium is ignored 2313cdf0e10cSrcweir // the check is done in LockOrigFileOnDemand() for file and non-file URLs 2314cdf0e10cSrcweir 2315cdf0e10cSrcweir //TODO/MBA: what happens if property is not there?! 2316cdf0e10cSrcweir aMedium[comphelper::MediaDescriptor::PROP_STREAM()] >>= pImp->xStream; 2317cdf0e10cSrcweir aMedium[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= pImp->xInputStream; 2318cdf0e10cSrcweir } 2319cdf0e10cSrcweir 2320cdf0e10cSrcweir GetContent(); 2321cdf0e10cSrcweir if ( !pImp->xInputStream.is() && pImp->xStream.is() ) 2322cdf0e10cSrcweir pImp->xInputStream = pImp->xStream->getInputStream(); 2323cdf0e10cSrcweir } 2324cdf0e10cSrcweir 2325cdf0e10cSrcweir if ( !bFromTempFile ) 2326cdf0e10cSrcweir { 2327cdf0e10cSrcweir //TODO/MBA: need support for SID_STREAM 2328cdf0e10cSrcweir if ( pImp->xStream.is() ) 2329cdf0e10cSrcweir GetItemSet()->Put( SfxUsrAnyItem( SID_STREAM, makeAny( pImp->xStream ) ) ); 2330cdf0e10cSrcweir 2331cdf0e10cSrcweir GetItemSet()->Put( SfxUsrAnyItem( SID_INPUTSTREAM, makeAny( pImp->xInputStream ) ) ); 2332cdf0e10cSrcweir } 2333cdf0e10cSrcweir } 2334cdf0e10cSrcweir 2335cdf0e10cSrcweir //TODO/MBA: ErrorHandling - how to transport error from MediaDescriptor 2336cdf0e10cSrcweir if ( !GetError() && !pImp->xStream.is() && !pImp->xInputStream.is() ) 2337cdf0e10cSrcweir SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 2338cdf0e10cSrcweir 2339cdf0e10cSrcweir if ( !GetError() ) 2340cdf0e10cSrcweir { 2341cdf0e10cSrcweir if ( pImp->xStream.is() ) 2342cdf0e10cSrcweir pInStream = utl::UcbStreamHelper::CreateStream( pImp->xStream ); 2343cdf0e10cSrcweir else if ( pImp->xInputStream.is() ) 2344cdf0e10cSrcweir pInStream = utl::UcbStreamHelper::CreateStream( pImp->xInputStream ); 2345cdf0e10cSrcweir } 2346cdf0e10cSrcweir 2347cdf0e10cSrcweir pImp->bDownloadDone = sal_True; 2348cdf0e10cSrcweir pImp->aDoneLink.ClearPendingCall(); 2349cdf0e10cSrcweir pImp->aDoneLink.Call( (void*) GetError() ); 2350cdf0e10cSrcweir } 2351cdf0e10cSrcweir } 2352cdf0e10cSrcweir 2353cdf0e10cSrcweir //---------------------------------------------------------------- 2354cdf0e10cSrcweir sal_Bool SfxMedium::IsRemote() 2355cdf0e10cSrcweir { 2356cdf0e10cSrcweir return bRemote; 2357cdf0e10cSrcweir } 2358cdf0e10cSrcweir 2359cdf0e10cSrcweir //------------------------------------------------------------------ 2360cdf0e10cSrcweir 2361cdf0e10cSrcweir void SfxMedium::SetUpdatePickList(sal_Bool bVal) 2362cdf0e10cSrcweir { 2363cdf0e10cSrcweir if(!pImp) 2364cdf0e10cSrcweir pImp = new SfxMedium_Impl( this ); 2365cdf0e10cSrcweir pImp->bUpdatePickList = bVal; 2366cdf0e10cSrcweir } 2367cdf0e10cSrcweir //------------------------------------------------------------------ 2368cdf0e10cSrcweir 2369cdf0e10cSrcweir sal_Bool SfxMedium::IsUpdatePickList() const 2370cdf0e10cSrcweir { 2371cdf0e10cSrcweir return pImp? pImp->bUpdatePickList: sal_True; 2372cdf0e10cSrcweir } 2373cdf0e10cSrcweir //---------------------------------------------------------------- 2374cdf0e10cSrcweir 2375cdf0e10cSrcweir void SfxMedium::SetDoneLink( const Link& rLink ) 2376cdf0e10cSrcweir { 2377cdf0e10cSrcweir pImp->aDoneLink = rLink; 2378cdf0e10cSrcweir } 2379cdf0e10cSrcweir 2380cdf0e10cSrcweir //---------------------------------------------------------------- 2381cdf0e10cSrcweir 2382cdf0e10cSrcweir void SfxMedium::SetDataAvailableLink( const Link& rLink ) 2383cdf0e10cSrcweir { 2384cdf0e10cSrcweir pImp->aAvailableLink = rLink; 2385cdf0e10cSrcweir } 2386cdf0e10cSrcweir 2387cdf0e10cSrcweir //---------------------------------------------------------------- 2388cdf0e10cSrcweir void SfxMedium::StartDownload() 2389cdf0e10cSrcweir { 2390cdf0e10cSrcweir GetInStream(); 2391cdf0e10cSrcweir } 2392cdf0e10cSrcweir 2393cdf0e10cSrcweir void SfxMedium::DownLoad( const Link& aLink ) 2394cdf0e10cSrcweir { 2395cdf0e10cSrcweir SetDoneLink( aLink ); 2396cdf0e10cSrcweir GetInStream(); 2397cdf0e10cSrcweir if ( pInStream && !aLink.IsSet() ) 2398cdf0e10cSrcweir { 2399cdf0e10cSrcweir while( !pImp->bDownloadDone ) 2400cdf0e10cSrcweir Application::Yield(); 2401cdf0e10cSrcweir } 2402cdf0e10cSrcweir } 2403cdf0e10cSrcweir 2404cdf0e10cSrcweir //------------------------------------------------------------------ 2405cdf0e10cSrcweir void SfxMedium::Init_Impl() 2406cdf0e10cSrcweir /* [Beschreibung] 2407cdf0e10cSrcweir Setzt in den Logischen Namen eine gueltige ::com::sun::star::util::URL (Falls zuvor ein Filename 2408cdf0e10cSrcweir drin war) und setzt den physikalschen Namen auf den Filenamen, falls 2409cdf0e10cSrcweir vorhanden. 2410cdf0e10cSrcweir */ 2411cdf0e10cSrcweir 2412cdf0e10cSrcweir { 2413cdf0e10cSrcweir Reference< XOutputStream > rOutStream; 2414cdf0e10cSrcweir 2415cdf0e10cSrcweir // TODO/LATER: handle lifetime of storages 2416cdf0e10cSrcweir pImp->bDisposeStorage = sal_False; 2417cdf0e10cSrcweir 2418cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False); 2419cdf0e10cSrcweir if ( pSalvageItem && !pSalvageItem->GetValue().Len() ) 2420cdf0e10cSrcweir { 2421cdf0e10cSrcweir pSalvageItem = NULL; 2422cdf0e10cSrcweir pSet->ClearItem( SID_DOC_SALVAGE ); 2423cdf0e10cSrcweir } 2424cdf0e10cSrcweir 2425cdf0e10cSrcweir if( aLogicName.Len() ) 2426cdf0e10cSrcweir { 2427cdf0e10cSrcweir INetURLObject aUrl( aLogicName ); 2428cdf0e10cSrcweir INetProtocol eProt = aUrl.GetProtocol(); 2429cdf0e10cSrcweir if ( eProt == INET_PROT_NOT_VALID ) 2430cdf0e10cSrcweir { 2431cdf0e10cSrcweir DBG_ERROR ( "Unknown protocol!" ); 2432cdf0e10cSrcweir } 2433cdf0e10cSrcweir else 2434cdf0e10cSrcweir { 2435cdf0e10cSrcweir if ( aUrl.HasMark() ) 2436cdf0e10cSrcweir { 2437cdf0e10cSrcweir aLogicName = aUrl.GetURLNoMark( INetURLObject::NO_DECODE ); 2438cdf0e10cSrcweir GetItemSet()->Put( SfxStringItem( SID_JUMPMARK, aUrl.GetMark() ) ); 2439cdf0e10cSrcweir } 2440cdf0e10cSrcweir 2441cdf0e10cSrcweir // try to convert the URL into a physical name - but never change a physical name 2442cdf0e10cSrcweir // physical name may be set if the logical name is changed after construction 2443cdf0e10cSrcweir if ( !aName.Len() ) 2444cdf0e10cSrcweir ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), aName ); 2445cdf0e10cSrcweir else { 2446cdf0e10cSrcweir DBG_ASSERT( pSalvageItem, "Suspicious change of logical name!" ); 2447cdf0e10cSrcweir } 2448cdf0e10cSrcweir } 2449cdf0e10cSrcweir } 2450cdf0e10cSrcweir 2451cdf0e10cSrcweir if ( pSalvageItem && pSalvageItem->GetValue().Len() ) 2452cdf0e10cSrcweir { 2453cdf0e10cSrcweir aLogicName = pSalvageItem->GetValue(); 2454cdf0e10cSrcweir DELETEZ( pURLObj ); 2455cdf0e10cSrcweir pImp->m_bSalvageMode = sal_True; 2456cdf0e10cSrcweir } 2457cdf0e10cSrcweir 2458cdf0e10cSrcweir // in case output stream is by mistake here 2459cdf0e10cSrcweir // clear the reference 2460cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pOutStreamItem, SfxUnoAnyItem, SID_OUTPUTSTREAM, sal_False); 2461cdf0e10cSrcweir if( pOutStreamItem 2462cdf0e10cSrcweir && ( !( pOutStreamItem->GetValue() >>= rOutStream ) 2463cdf0e10cSrcweir || !aLogicName.CompareToAscii( "private:stream", 14 ) == COMPARE_EQUAL ) ) 2464cdf0e10cSrcweir { 2465cdf0e10cSrcweir pSet->ClearItem( SID_OUTPUTSTREAM ); 2466cdf0e10cSrcweir DBG_ERROR( "Unexpected Output stream parameter!\n" ); 2467cdf0e10cSrcweir } 2468cdf0e10cSrcweir 2469cdf0e10cSrcweir if ( aLogicName.Len() ) 2470cdf0e10cSrcweir { 2471cdf0e10cSrcweir // if the logic name is set it should be set in MediaDescriptor as well 2472cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False ); 2473cdf0e10cSrcweir if ( !pFileNameItem ) 2474cdf0e10cSrcweir { 2475cdf0e10cSrcweir // let the ItemSet be created if necessary 2476cdf0e10cSrcweir GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, INetURLObject( aLogicName ).GetMainURL( INetURLObject::NO_DECODE ) ) ); 2477cdf0e10cSrcweir } 2478cdf0e10cSrcweir } 2479cdf0e10cSrcweir 2480cdf0e10cSrcweir SetIsRemote_Impl(); 2481cdf0e10cSrcweir } 2482cdf0e10cSrcweir 2483cdf0e10cSrcweir //------------------------------------------------------------------ 2484cdf0e10cSrcweir SfxMedium::SfxMedium() 2485cdf0e10cSrcweir : IMPL_CTOR( sal_False, 0 ), // bRoot, pURLObj 2486cdf0e10cSrcweir 2487cdf0e10cSrcweir pFilter(0), 2488cdf0e10cSrcweir pSet(0), 2489cdf0e10cSrcweir pImp(new SfxMedium_Impl( this )) 2490cdf0e10cSrcweir { 2491cdf0e10cSrcweir Init_Impl(); 2492cdf0e10cSrcweir } 2493cdf0e10cSrcweir //------------------------------------------------------------------ 2494cdf0e10cSrcweir 2495cdf0e10cSrcweir SfxMedium::SfxMedium( const SfxMedium& rMedium, sal_Bool bTemporary ) 2496cdf0e10cSrcweir : SvRefBase(), 2497cdf0e10cSrcweir IMPL_CTOR( sal_True, // bRoot, pURLObj 2498cdf0e10cSrcweir rMedium.pURLObj ? new INetURLObject(*rMedium.pURLObj) : 0 ), 2499cdf0e10cSrcweir pImp(new SfxMedium_Impl( this )) 2500cdf0e10cSrcweir { 2501cdf0e10cSrcweir bDirect = rMedium.IsDirect(); 2502cdf0e10cSrcweir nStorOpenMode = rMedium.GetOpenMode(); 2503cdf0e10cSrcweir if ( !bTemporary ) 2504cdf0e10cSrcweir aName = rMedium.aName; 2505cdf0e10cSrcweir 2506cdf0e10cSrcweir pImp->bIsTemp = bTemporary; 2507cdf0e10cSrcweir DBG_ASSERT( ! rMedium.pImp->bIsTemp, "Temporaeres Medium darf nicht kopiert werden" ); 2508cdf0e10cSrcweir aLogicName = rMedium.aLogicName; 2509cdf0e10cSrcweir pSet = rMedium.GetItemSet() ? new SfxItemSet(*rMedium.GetItemSet()) : 0; 2510cdf0e10cSrcweir pFilter = rMedium.pFilter; 2511cdf0e10cSrcweir Init_Impl(); 2512cdf0e10cSrcweir if( bTemporary ) 2513cdf0e10cSrcweir CreateTempFile( sal_True ); 2514cdf0e10cSrcweir } 2515cdf0e10cSrcweir 2516cdf0e10cSrcweir //------------------------------------------------------------------ 2517cdf0e10cSrcweir 2518cdf0e10cSrcweir void SfxMedium::UseInteractionHandler( sal_Bool bUse ) 2519cdf0e10cSrcweir { 2520cdf0e10cSrcweir pImp->bAllowDefaultIntHdl = bUse; 2521cdf0e10cSrcweir } 2522cdf0e10cSrcweir 2523cdf0e10cSrcweir //------------------------------------------------------------------ 2524cdf0e10cSrcweir 2525cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > 2526cdf0e10cSrcweir SfxMedium::GetInteractionHandler() 2527cdf0e10cSrcweir { 2528cdf0e10cSrcweir // if interaction isnt allowed explicitly ... return empty reference! 2529cdf0e10cSrcweir if ( !pImp->bUseInteractionHandler ) 2530cdf0e10cSrcweir return ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >(); 2531cdf0e10cSrcweir 2532cdf0e10cSrcweir // search a possible existing handler inside cached item set 2533cdf0e10cSrcweir if ( pSet ) 2534cdf0e10cSrcweir { 2535cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xHandler; 2536cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pHandler, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False); 2537cdf0e10cSrcweir if ( pHandler && (pHandler->GetValue() >>= xHandler) && xHandler.is() ) 2538cdf0e10cSrcweir return xHandler; 2539cdf0e10cSrcweir } 2540cdf0e10cSrcweir 2541cdf0e10cSrcweir // if default interaction isnt allowed explicitly ... return empty reference! 2542cdf0e10cSrcweir if ( !pImp->bAllowDefaultIntHdl ) 2543cdf0e10cSrcweir return ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >(); 2544cdf0e10cSrcweir 2545cdf0e10cSrcweir // otherwhise return cached default handler ... if it exist. 2546cdf0e10cSrcweir if ( pImp->xInteraction.is() ) 2547cdf0e10cSrcweir return pImp->xInteraction; 2548cdf0e10cSrcweir 2549cdf0e10cSrcweir // create default handler and cache it! 2550cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); 2551cdf0e10cSrcweir if ( xFactory.is() ) 2552cdf0e10cSrcweir { 2553cdf0e10cSrcweir pImp->xInteraction = ::com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler >( xFactory->createInstance( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ), ::com::sun::star::uno::UNO_QUERY ); 2554cdf0e10cSrcweir return pImp->xInteraction; 2555cdf0e10cSrcweir } 2556cdf0e10cSrcweir 2557cdf0e10cSrcweir return ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >(); 2558cdf0e10cSrcweir } 2559cdf0e10cSrcweir 2560cdf0e10cSrcweir //---------------------------------------------------------------- 2561cdf0e10cSrcweir 2562cdf0e10cSrcweir void SfxMedium::SetFilter( const SfxFilter* pFilterP, sal_Bool /*bResetOrig*/ ) 2563cdf0e10cSrcweir { 2564cdf0e10cSrcweir pFilter = pFilterP; 2565cdf0e10cSrcweir pImp->nFileVersion = 0; 2566cdf0e10cSrcweir } 2567cdf0e10cSrcweir 2568cdf0e10cSrcweir //---------------------------------------------------------------- 2569cdf0e10cSrcweir 2570cdf0e10cSrcweir const SfxFilter* SfxMedium::GetOrigFilter( sal_Bool bNotCurrent ) const 2571cdf0e10cSrcweir { 2572cdf0e10cSrcweir return ( pImp->pOrigFilter || bNotCurrent ) ? pImp->pOrigFilter : pFilter; 2573cdf0e10cSrcweir } 2574cdf0e10cSrcweir 2575cdf0e10cSrcweir //---------------------------------------------------------------- 2576cdf0e10cSrcweir 2577cdf0e10cSrcweir void SfxMedium::SetOrigFilter_Impl( const SfxFilter* pOrigFilter ) 2578cdf0e10cSrcweir { 2579cdf0e10cSrcweir pImp->pOrigFilter = pOrigFilter; 2580cdf0e10cSrcweir } 2581cdf0e10cSrcweir 2582cdf0e10cSrcweir //------------------------------------------------------------------ 2583cdf0e10cSrcweir 2584cdf0e10cSrcweir sal_uInt32 SfxMedium::CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bWriter ) 2585cdf0e10cSrcweir { 2586cdf0e10cSrcweir sal_uInt32 nHash = 0; 2587cdf0e10cSrcweir 2588cdf0e10cSrcweir if ( aPasswd.getLength() ) 2589cdf0e10cSrcweir { 2590cdf0e10cSrcweir if ( bWriter ) 2591cdf0e10cSrcweir { 2592cdf0e10cSrcweir nHash = ::comphelper::DocPasswordHelper::GetWordHashAsUINT32( aPasswd ); 2593cdf0e10cSrcweir } 2594cdf0e10cSrcweir else 2595cdf0e10cSrcweir { 2596cdf0e10cSrcweir rtl_TextEncoding nEncoding = RTL_TEXTENCODING_UTF8; 2597cdf0e10cSrcweir 2598cdf0e10cSrcweir // if the MS-filter should be used 2599cdf0e10cSrcweir // use the inconsistent algorithm to find the encoding specified by MS 2600cdf0e10cSrcweir nEncoding = osl_getThreadTextEncoding(); 2601cdf0e10cSrcweir switch( nEncoding ) 2602cdf0e10cSrcweir { 2603cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_15: 2604cdf0e10cSrcweir case RTL_TEXTENCODING_MS_874: 2605cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1250: 2606cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1251: 2607cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1252: 2608cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1253: 2609cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1254: 2610cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1255: 2611cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1256: 2612cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1257: 2613cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1258: 2614cdf0e10cSrcweir case RTL_TEXTENCODING_SHIFT_JIS: 2615cdf0e10cSrcweir case RTL_TEXTENCODING_GB_2312: 2616cdf0e10cSrcweir case RTL_TEXTENCODING_BIG5: 2617cdf0e10cSrcweir // in case the system uses an encoding from the list above, it should be used 2618cdf0e10cSrcweir break; 2619cdf0e10cSrcweir 2620cdf0e10cSrcweir default: 2621cdf0e10cSrcweir // in case other encoding is used, use one of the encodings from the list 2622cdf0e10cSrcweir nEncoding = RTL_TEXTENCODING_MS_1250; 2623cdf0e10cSrcweir break; 2624cdf0e10cSrcweir } 2625cdf0e10cSrcweir 2626cdf0e10cSrcweir nHash = ::comphelper::DocPasswordHelper::GetXLHashAsUINT16( aPasswd, nEncoding ); 2627cdf0e10cSrcweir } 2628cdf0e10cSrcweir } 2629cdf0e10cSrcweir 2630cdf0e10cSrcweir return nHash; 2631cdf0e10cSrcweir } 2632cdf0e10cSrcweir 2633cdf0e10cSrcweir //------------------------------------------------------------------ 2634cdf0e10cSrcweir 2635cdf0e10cSrcweir void SfxMedium::Close() 2636cdf0e10cSrcweir { 2637cdf0e10cSrcweir if ( pImp->xStorage.is() ) 2638cdf0e10cSrcweir { 2639cdf0e10cSrcweir // don't close the streams if they belong to the 2640cdf0e10cSrcweir // storage 2641cdf0e10cSrcweir //TODO/MBA: how to?! Do we need the flag?! 2642cdf0e10cSrcweir /* 2643cdf0e10cSrcweir const SvStream *pStream = aStorage->GetSvStream(); 2644cdf0e10cSrcweir if ( pStream && pStream == pInStream ) 2645cdf0e10cSrcweir { 2646cdf0e10cSrcweir CloseZipStorage_Impl(); 2647cdf0e10cSrcweir pInStream = NULL; 2648cdf0e10cSrcweir pImp->xInputStream = Reference < XInputStream >(); 2649cdf0e10cSrcweir pImp->xLockBytes.Clear(); 2650cdf0e10cSrcweir if ( pSet ) 2651cdf0e10cSrcweir pSet->ClearItem( SID_INPUTSTREAM ); 2652cdf0e10cSrcweir aStorage->SetDeleteStream( sal_True ); 2653cdf0e10cSrcweir } 2654cdf0e10cSrcweir else if ( pStream && pStream == pOutStream ) 2655cdf0e10cSrcweir { 2656cdf0e10cSrcweir pOutStream = NULL; 2657cdf0e10cSrcweir aStorage->SetDeleteStream( sal_True ); 2658cdf0e10cSrcweir } */ 2659cdf0e10cSrcweir 2660cdf0e10cSrcweir CloseStorage(); 2661cdf0e10cSrcweir } 2662cdf0e10cSrcweir 2663cdf0e10cSrcweir CloseStreams_Impl(); 2664cdf0e10cSrcweir 2665cdf0e10cSrcweir UnlockFile( sal_False ); 2666cdf0e10cSrcweir } 2667cdf0e10cSrcweir 2668cdf0e10cSrcweir void SfxMedium::CloseAndRelease() 2669cdf0e10cSrcweir { 2670cdf0e10cSrcweir if ( pImp->xStorage.is() ) 2671cdf0e10cSrcweir { 2672cdf0e10cSrcweir // don't close the streams if they belong to the 2673cdf0e10cSrcweir // storage 2674cdf0e10cSrcweir //TODO/MBA: how to?! Do we need the flag?! 2675cdf0e10cSrcweir /* 2676cdf0e10cSrcweir const SvStream *pStream = aStorage->GetSvStream(); 2677cdf0e10cSrcweir if ( pStream && pStream == pInStream ) 2678cdf0e10cSrcweir { 2679cdf0e10cSrcweir CloseZipStorage_Impl(); 2680cdf0e10cSrcweir pInStream = NULL; 2681cdf0e10cSrcweir pImp->xInputStream = Reference < XInputStream >(); 2682cdf0e10cSrcweir pImp->xLockBytes.Clear(); 2683cdf0e10cSrcweir if ( pSet ) 2684cdf0e10cSrcweir pSet->ClearItem( SID_INPUTSTREAM ); 2685cdf0e10cSrcweir aStorage->SetDeleteStream( sal_True ); 2686cdf0e10cSrcweir } 2687cdf0e10cSrcweir else if ( pStream && pStream == pOutStream ) 2688cdf0e10cSrcweir { 2689cdf0e10cSrcweir pOutStream = NULL; 2690cdf0e10cSrcweir aStorage->SetDeleteStream( sal_True ); 2691cdf0e10cSrcweir } */ 2692cdf0e10cSrcweir 2693cdf0e10cSrcweir CloseStorage(); 2694cdf0e10cSrcweir } 2695cdf0e10cSrcweir 2696cdf0e10cSrcweir CloseAndReleaseStreams_Impl(); 2697cdf0e10cSrcweir 2698cdf0e10cSrcweir UnlockFile( sal_True ); 2699cdf0e10cSrcweir } 2700cdf0e10cSrcweir 2701cdf0e10cSrcweir void SfxMedium::UnlockFile( sal_Bool bReleaseLockStream ) 2702cdf0e10cSrcweir { 2703cdf0e10cSrcweir if ( pImp->m_xLockingStream.is() ) 2704cdf0e10cSrcweir { 2705cdf0e10cSrcweir if ( bReleaseLockStream ) 2706cdf0e10cSrcweir { 2707cdf0e10cSrcweir try 2708cdf0e10cSrcweir { 2709cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = pImp->m_xLockingStream->getInputStream(); 2710cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutStream = pImp->m_xLockingStream->getOutputStream(); 2711cdf0e10cSrcweir if ( xInStream.is() ) 2712cdf0e10cSrcweir xInStream->closeInput(); 2713cdf0e10cSrcweir if ( xOutStream.is() ) 2714cdf0e10cSrcweir xOutStream->closeOutput(); 2715cdf0e10cSrcweir } 2716cdf0e10cSrcweir catch( uno::Exception& ) 2717cdf0e10cSrcweir {} 2718cdf0e10cSrcweir } 2719cdf0e10cSrcweir 2720cdf0e10cSrcweir pImp->m_xLockingStream = uno::Reference< io::XStream >(); 2721cdf0e10cSrcweir } 2722cdf0e10cSrcweir 2723cdf0e10cSrcweir if ( pImp->m_bLocked ) 2724cdf0e10cSrcweir { 2725cdf0e10cSrcweir try 2726cdf0e10cSrcweir { 2727cdf0e10cSrcweir pImp->m_bLocked = sal_False; 2728cdf0e10cSrcweir ::svt::DocumentLockFile aLockFile( aLogicName ); 2729cdf0e10cSrcweir // TODO/LATER: A warning could be shown in case the file is not the own one 2730cdf0e10cSrcweir aLockFile.RemoveFile(); 2731cdf0e10cSrcweir } 2732cdf0e10cSrcweir catch( uno::Exception& ) 2733cdf0e10cSrcweir {} 2734cdf0e10cSrcweir } 2735cdf0e10cSrcweir } 2736cdf0e10cSrcweir 2737cdf0e10cSrcweir void SfxMedium::CloseAndReleaseStreams_Impl() 2738cdf0e10cSrcweir { 2739cdf0e10cSrcweir CloseZipStorage_Impl(); 2740cdf0e10cSrcweir 2741cdf0e10cSrcweir uno::Reference< io::XInputStream > xInToClose = pImp->xInputStream; 2742cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutToClose; 2743cdf0e10cSrcweir if ( pImp->xStream.is() ) 2744cdf0e10cSrcweir { 2745cdf0e10cSrcweir xOutToClose = pImp->xStream->getOutputStream(); 2746cdf0e10cSrcweir 2747cdf0e10cSrcweir // if the locking stream is closed here the related member should be cleaned 2748cdf0e10cSrcweir if ( pImp->xStream == pImp->m_xLockingStream ) 2749cdf0e10cSrcweir pImp->m_xLockingStream = uno::Reference< io::XStream >(); 2750cdf0e10cSrcweir } 2751cdf0e10cSrcweir 2752cdf0e10cSrcweir // The probably exsisting SvStream wrappers should be closed first 2753cdf0e10cSrcweir CloseStreams_Impl(); 2754cdf0e10cSrcweir 2755cdf0e10cSrcweir // in case of salvage mode the storage is based on the streams 2756cdf0e10cSrcweir if ( !pImp->m_bSalvageMode ) 2757cdf0e10cSrcweir { 2758cdf0e10cSrcweir try 2759cdf0e10cSrcweir { 2760cdf0e10cSrcweir if ( xInToClose.is() ) 2761cdf0e10cSrcweir xInToClose->closeInput(); 2762cdf0e10cSrcweir if ( xOutToClose.is() ) 2763cdf0e10cSrcweir xOutToClose->closeOutput(); 2764cdf0e10cSrcweir } 2765cdf0e10cSrcweir catch ( uno::Exception& ) 2766cdf0e10cSrcweir { 2767cdf0e10cSrcweir } 2768cdf0e10cSrcweir } 2769cdf0e10cSrcweir } 2770cdf0e10cSrcweir 2771cdf0e10cSrcweir //------------------------------------------------------------------ 2772cdf0e10cSrcweir void SfxMedium::CloseStreams_Impl() 2773cdf0e10cSrcweir { 2774cdf0e10cSrcweir CloseInStream_Impl(); 2775cdf0e10cSrcweir CloseOutStream_Impl(); 2776cdf0e10cSrcweir 2777cdf0e10cSrcweir if ( pSet ) 2778cdf0e10cSrcweir pSet->ClearItem( SID_CONTENT ); 2779cdf0e10cSrcweir 2780cdf0e10cSrcweir pImp->aContent = ::ucbhelper::Content(); 2781cdf0e10cSrcweir } 2782cdf0e10cSrcweir 2783cdf0e10cSrcweir //------------------------------------------------------------------ 2784cdf0e10cSrcweir 2785cdf0e10cSrcweir void SfxMedium::RefreshName_Impl() 2786cdf0e10cSrcweir { 2787cdf0e10cSrcweir #if 0 //(dv) 2788cdf0e10cSrcweir if ( pImp->aContent.get().is() ) 2789cdf0e10cSrcweir { 2790cdf0e10cSrcweir String aNameP = pImp->xAnchor->GetViewURL(); 2791cdf0e10cSrcweir pImp->aOrigURL = aNameP; 2792cdf0e10cSrcweir aLogicName = aNameP; 2793cdf0e10cSrcweir DELETEZ( pURLObj ); 2794cdf0e10cSrcweir if (aLogicName.Len()) 2795cdf0e10cSrcweir aLogicName = GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 2796cdf0e10cSrcweir SetIsRemote_Impl(); 2797cdf0e10cSrcweir } 2798cdf0e10cSrcweir #endif //(dv) 2799cdf0e10cSrcweir } 2800cdf0e10cSrcweir 2801cdf0e10cSrcweir void SfxMedium::SetIsRemote_Impl() 2802cdf0e10cSrcweir { 2803cdf0e10cSrcweir INetURLObject aObj( GetName() ); 2804cdf0e10cSrcweir switch( aObj.GetProtocol() ) 2805cdf0e10cSrcweir { 2806cdf0e10cSrcweir case INET_PROT_FTP: 2807cdf0e10cSrcweir case INET_PROT_HTTP: 2808cdf0e10cSrcweir case INET_PROT_HTTPS: 2809cdf0e10cSrcweir case INET_PROT_POP3: 2810cdf0e10cSrcweir case INET_PROT_NEWS: 2811cdf0e10cSrcweir case INET_PROT_IMAP: 2812cdf0e10cSrcweir // case INET_PROT_OUT: 2813cdf0e10cSrcweir case INET_PROT_VIM: 2814cdf0e10cSrcweir bRemote = sal_True; break; 2815cdf0e10cSrcweir default: 2816cdf0e10cSrcweir bRemote = ( GetName().CompareToAscii( "private:msgid", 13 ) == COMPARE_EQUAL ); 2817cdf0e10cSrcweir break; 2818cdf0e10cSrcweir } 2819cdf0e10cSrcweir 2820cdf0e10cSrcweir // Da Dateien, die Remote geschrieben werden zur Uebertragung auch 2821cdf0e10cSrcweir // gelesen werden koennen muessen 2822cdf0e10cSrcweir if( bRemote ) 2823cdf0e10cSrcweir nStorOpenMode |= STREAM_READ; 2824cdf0e10cSrcweir } 2825cdf0e10cSrcweir 2826cdf0e10cSrcweir 2827cdf0e10cSrcweir 2828cdf0e10cSrcweir void SfxMedium::SetName( const String& aNameP, sal_Bool bSetOrigURL ) 2829cdf0e10cSrcweir { 2830cdf0e10cSrcweir if( !pImp->aOrigURL.Len() ) 2831cdf0e10cSrcweir pImp->aOrigURL = aLogicName; 2832cdf0e10cSrcweir if( bSetOrigURL ) 2833cdf0e10cSrcweir pImp->aOrigURL = aNameP; 2834cdf0e10cSrcweir aLogicName = aNameP; 2835cdf0e10cSrcweir DELETEZ( pURLObj ); 2836cdf0e10cSrcweir pImp->aContent = ::ucbhelper::Content(); 2837cdf0e10cSrcweir Init_Impl(); 2838cdf0e10cSrcweir } 2839cdf0e10cSrcweir 2840cdf0e10cSrcweir //---------------------------------------------------------------- 2841cdf0e10cSrcweir const String& SfxMedium::GetOrigURL() const 2842cdf0e10cSrcweir { 2843cdf0e10cSrcweir return !pImp->aOrigURL.Len() ? (String &)aLogicName : pImp->aOrigURL; 2844cdf0e10cSrcweir } 2845cdf0e10cSrcweir 2846cdf0e10cSrcweir //---------------------------------------------------------------- 2847cdf0e10cSrcweir 2848cdf0e10cSrcweir void SfxMedium::SetPhysicalName_Impl( const String& rNameP ) 2849cdf0e10cSrcweir { 2850cdf0e10cSrcweir if ( rNameP != aName ) 2851cdf0e10cSrcweir { 2852cdf0e10cSrcweir if( pImp->pTempFile ) 2853cdf0e10cSrcweir { 2854cdf0e10cSrcweir delete pImp->pTempFile; 2855cdf0e10cSrcweir pImp->pTempFile = NULL; 2856cdf0e10cSrcweir } 2857cdf0e10cSrcweir 2858cdf0e10cSrcweir if ( aName.Len() || rNameP.Len() ) 2859cdf0e10cSrcweir pImp->aContent = ::ucbhelper::Content(); 2860cdf0e10cSrcweir 2861cdf0e10cSrcweir aName = rNameP; 2862cdf0e10cSrcweir bTriedStorage = sal_False; 2863cdf0e10cSrcweir pImp->bIsStorage = sal_False; 2864cdf0e10cSrcweir } 2865cdf0e10cSrcweir } 2866cdf0e10cSrcweir 2867cdf0e10cSrcweir //------------------------------------------------------------------ 2868cdf0e10cSrcweir void SfxMedium::SetTemporary( sal_Bool bTemp ) 2869cdf0e10cSrcweir { 2870cdf0e10cSrcweir pImp->bIsTemp = bTemp; 2871cdf0e10cSrcweir } 2872cdf0e10cSrcweir 2873cdf0e10cSrcweir //------------------------------------------------------------------ 2874cdf0e10cSrcweir sal_Bool SfxMedium::IsTemporary() const 2875cdf0e10cSrcweir { 2876cdf0e10cSrcweir return pImp->bIsTemp; 2877cdf0e10cSrcweir } 2878cdf0e10cSrcweir 2879cdf0e10cSrcweir //------------------------------------------------------------------ 2880cdf0e10cSrcweir 2881cdf0e10cSrcweir sal_Bool SfxMedium::Exists( sal_Bool /*bForceSession*/ ) 2882cdf0e10cSrcweir { 2883cdf0e10cSrcweir DBG_ERROR( "Not implemented!" ); 2884cdf0e10cSrcweir return sal_True; 2885cdf0e10cSrcweir } 2886cdf0e10cSrcweir 2887cdf0e10cSrcweir //------------------------------------------------------------------ 2888cdf0e10cSrcweir 2889cdf0e10cSrcweir void SfxMedium::ReOpen() 2890cdf0e10cSrcweir { 2891cdf0e10cSrcweir sal_Bool bUseInteractionHandler = pImp->bUseInteractionHandler; 2892cdf0e10cSrcweir pImp->bUseInteractionHandler = sal_False; 2893cdf0e10cSrcweir GetMedium_Impl(); 2894cdf0e10cSrcweir pImp->bUseInteractionHandler = bUseInteractionHandler; 2895cdf0e10cSrcweir } 2896cdf0e10cSrcweir 2897cdf0e10cSrcweir //------------------------------------------------------------------ 2898cdf0e10cSrcweir 2899cdf0e10cSrcweir void SfxMedium::CompleteReOpen() 2900cdf0e10cSrcweir { 2901cdf0e10cSrcweir // do not use temporary file for reopen and in case of success throw the temporary file away 2902cdf0e10cSrcweir sal_Bool bUseInteractionHandler = pImp->bUseInteractionHandler; 2903cdf0e10cSrcweir pImp->bUseInteractionHandler = sal_False; 2904cdf0e10cSrcweir 2905cdf0e10cSrcweir ::utl::TempFile* pTmpFile = NULL; 2906cdf0e10cSrcweir if ( pImp->pTempFile ) 2907cdf0e10cSrcweir { 2908cdf0e10cSrcweir pTmpFile = pImp->pTempFile; 2909cdf0e10cSrcweir pImp->pTempFile = NULL; 2910cdf0e10cSrcweir aName = String(); 2911cdf0e10cSrcweir } 2912cdf0e10cSrcweir 2913cdf0e10cSrcweir GetMedium_Impl(); 2914cdf0e10cSrcweir 2915cdf0e10cSrcweir if ( GetError() ) 2916cdf0e10cSrcweir { 2917cdf0e10cSrcweir if ( pImp->pTempFile ) 2918cdf0e10cSrcweir { 2919cdf0e10cSrcweir pImp->pTempFile->EnableKillingFile( sal_True ); 2920cdf0e10cSrcweir delete pImp->pTempFile; 2921cdf0e10cSrcweir } 2922cdf0e10cSrcweir pImp->pTempFile = pTmpFile; 2923cdf0e10cSrcweir if ( pImp->pTempFile ) 2924cdf0e10cSrcweir aName = pImp->pTempFile->GetFileName(); 2925cdf0e10cSrcweir } 2926cdf0e10cSrcweir else 2927cdf0e10cSrcweir { 2928cdf0e10cSrcweir pTmpFile->EnableKillingFile( sal_True ); 2929cdf0e10cSrcweir delete pTmpFile; 2930cdf0e10cSrcweir 2931cdf0e10cSrcweir } 2932cdf0e10cSrcweir 2933cdf0e10cSrcweir pImp->bUseInteractionHandler = bUseInteractionHandler; 2934cdf0e10cSrcweir } 2935cdf0e10cSrcweir 2936cdf0e10cSrcweir //------------------------------------------------------------------ 2937cdf0e10cSrcweir SfxMedium::SfxMedium 2938cdf0e10cSrcweir ( 2939cdf0e10cSrcweir const String &rName, StreamMode nOpenMode, sal_Bool bDirectP, 2940cdf0e10cSrcweir const SfxFilter *pFlt, SfxItemSet *pInSet 2941cdf0e10cSrcweir ) 2942cdf0e10cSrcweir : IMPL_CTOR( sal_False, 0 ), // bRoot, pURLObj 2943cdf0e10cSrcweir pFilter(pFlt), 2944cdf0e10cSrcweir pSet( pInSet ), 2945cdf0e10cSrcweir pImp(new SfxMedium_Impl( this )) 2946cdf0e10cSrcweir { 2947cdf0e10cSrcweir aLogicName = rName; 2948cdf0e10cSrcweir nStorOpenMode = nOpenMode; 2949cdf0e10cSrcweir bDirect = bDirectP; 2950cdf0e10cSrcweir Init_Impl(); 2951cdf0e10cSrcweir } 2952cdf0e10cSrcweir 2953cdf0e10cSrcweir 2954cdf0e10cSrcweir SfxMedium::SfxMedium( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) 2955cdf0e10cSrcweir : IMPL_CTOR( sal_False, 0 ), // bRoot, pURLObj 2956cdf0e10cSrcweir pFilter(0), 2957cdf0e10cSrcweir pSet(0), 2958cdf0e10cSrcweir pImp(new SfxMedium_Impl( this )) 2959cdf0e10cSrcweir { 2960cdf0e10cSrcweir SfxAllItemSet *pParams = new SfxAllItemSet( SFX_APP()->GetPool() ); 2961cdf0e10cSrcweir pSet = pParams; 2962cdf0e10cSrcweir TransformParameters( SID_OPENDOC, aArgs, *pParams ); 2963cdf0e10cSrcweir 2964cdf0e10cSrcweir String aFilterName; 2965cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 2966cdf0e10cSrcweir if( pFilterNameItem ) 2967cdf0e10cSrcweir aFilterName = pFilterNameItem->GetValue(); 2968cdf0e10cSrcweir pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName ); 2969cdf0e10cSrcweir 2970cdf0e10cSrcweir sal_Bool bSalvage = sal_False; 2971cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False ); 2972cdf0e10cSrcweir if( pSalvageItem ) 2973cdf0e10cSrcweir { 2974cdf0e10cSrcweir // QUESTION: there is some treatment of Salvage in Init_Impl; align! 2975cdf0e10cSrcweir bSalvage = sal_True; 2976cdf0e10cSrcweir if ( pSalvageItem->GetValue().Len() ) 2977cdf0e10cSrcweir { 2978cdf0e10cSrcweir // if an URL is provided in SalvageItem that means that the FileName refers to a temporary file 2979cdf0e10cSrcweir // that must be copied here 2980cdf0e10cSrcweir 2981cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False ); 2982cdf0e10cSrcweir if (!pFileNameItem) throw uno::RuntimeException(); 2983cdf0e10cSrcweir ::rtl::OUString aNewTempFileURL = SfxMedium::CreateTempCopyWithExt( pFileNameItem->GetValue() ); 2984cdf0e10cSrcweir if ( aNewTempFileURL.getLength() ) 2985cdf0e10cSrcweir { 2986cdf0e10cSrcweir pSet->Put( SfxStringItem( SID_FILE_NAME, aNewTempFileURL ) ); 2987cdf0e10cSrcweir pSet->ClearItem( SID_INPUTSTREAM ); 2988cdf0e10cSrcweir pSet->ClearItem( SID_STREAM ); 2989cdf0e10cSrcweir pSet->ClearItem( SID_CONTENT ); 2990cdf0e10cSrcweir } 2991cdf0e10cSrcweir else 2992cdf0e10cSrcweir { 2993cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can not create a new temporary file for crash recovery!\n" ); 2994cdf0e10cSrcweir } 2995cdf0e10cSrcweir } 2996cdf0e10cSrcweir } 2997cdf0e10cSrcweir 2998cdf0e10cSrcweir sal_Bool bReadOnly = sal_False; 2999cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, sal_False ); 3000cdf0e10cSrcweir if ( pReadOnlyItem && pReadOnlyItem->GetValue() ) 3001cdf0e10cSrcweir bReadOnly = sal_True; 3002cdf0e10cSrcweir 3003cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False ); 3004cdf0e10cSrcweir if (!pFileNameItem) throw uno::RuntimeException(); 3005cdf0e10cSrcweir aLogicName = pFileNameItem->GetValue(); 3006cdf0e10cSrcweir nStorOpenMode = bReadOnly ? SFX_STREAM_READONLY : SFX_STREAM_READWRITE; 3007cdf0e10cSrcweir bDirect = sal_False; 3008cdf0e10cSrcweir Init_Impl(); 3009cdf0e10cSrcweir } 3010cdf0e10cSrcweir 3011cdf0e10cSrcweir 3012cdf0e10cSrcweir //------------------------------------------------------------------ 3013cdf0e10cSrcweir 3014cdf0e10cSrcweir SfxMedium::SfxMedium( const uno::Reference < embed::XStorage >& rStor, const String& rBaseURL, const SfxItemSet* p, sal_Bool bRootP ) 3015cdf0e10cSrcweir : IMPL_CTOR( bRootP, 0 ), // bRoot, pURLObj 3016cdf0e10cSrcweir pSet(0), 3017cdf0e10cSrcweir pImp( new SfxMedium_Impl( this )) 3018cdf0e10cSrcweir { 3019cdf0e10cSrcweir String aType = SfxFilter::GetTypeFromStorage( rStor ); 3020cdf0e10cSrcweir pFilter = SFX_APP()->GetFilterMatcher().GetFilter4EA( aType ); 3021cdf0e10cSrcweir DBG_ASSERT( pFilter, "No Filter for storage found!" ); 3022cdf0e10cSrcweir 3023cdf0e10cSrcweir Init_Impl(); 3024cdf0e10cSrcweir pImp->xStorage = rStor; 3025cdf0e10cSrcweir pImp->bDisposeStorage = sal_False; 3026cdf0e10cSrcweir 3027cdf0e10cSrcweir // always take BaseURL first, could be overwritten by ItemSet 3028cdf0e10cSrcweir GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, rBaseURL ) ); 3029cdf0e10cSrcweir if ( p ) 3030cdf0e10cSrcweir GetItemSet()->Put( *p ); 3031cdf0e10cSrcweir } 3032cdf0e10cSrcweir 3033*b45043c5SMathias Bauer SfxMedium::SfxMedium( const uno::Reference < embed::XStorage >& rStor, const String& rBaseURL, const String& rTypeName, const SfxItemSet* p, sal_Bool bRootP ) 3034*b45043c5SMathias Bauer : IMPL_CTOR( bRootP, 0 ), // bRoot, pURLObj 3035*b45043c5SMathias Bauer pSet(0), 3036*b45043c5SMathias Bauer pImp( new SfxMedium_Impl( this )) 3037*b45043c5SMathias Bauer { 3038*b45043c5SMathias Bauer pFilter = SFX_APP()->GetFilterMatcher().GetFilter4EA( rTypeName ); 3039*b45043c5SMathias Bauer DBG_ASSERT( pFilter, "No Filter for storage found!" ); 3040*b45043c5SMathias Bauer 3041*b45043c5SMathias Bauer Init_Impl(); 3042*b45043c5SMathias Bauer pImp->xStorage = rStor; 3043*b45043c5SMathias Bauer pImp->bDisposeStorage = sal_False; 3044*b45043c5SMathias Bauer 3045*b45043c5SMathias Bauer // always take BaseURL first, could be overwritten by ItemSet 3046*b45043c5SMathias Bauer GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, rBaseURL ) ); 3047*b45043c5SMathias Bauer if ( p ) 3048*b45043c5SMathias Bauer GetItemSet()->Put( *p ); 3049*b45043c5SMathias Bauer } 3050*b45043c5SMathias Bauer 3051cdf0e10cSrcweir //------------------------------------------------------------------ 3052cdf0e10cSrcweir 3053cdf0e10cSrcweir SfxMedium::~SfxMedium() 3054cdf0e10cSrcweir { 3055cdf0e10cSrcweir /* Attention 3056cdf0e10cSrcweir Don't enable CancelTransfers() till you know that the writer/web has changed his asynchronous load 3057cdf0e10cSrcweir behaviour. Otherwhise may StyleSheets inside a html file will be loaded at the right time. 3058cdf0e10cSrcweir => further the help will be empty then ... #100490# 3059cdf0e10cSrcweir */ 3060cdf0e10cSrcweir //CancelTransfers(); 3061cdf0e10cSrcweir 3062cdf0e10cSrcweir // if there is a requirement to clean the backup this is the last possibility to do it 3063cdf0e10cSrcweir ClearBackup_Impl(); 3064cdf0e10cSrcweir 3065cdf0e10cSrcweir Close(); 3066cdf0e10cSrcweir 3067cdf0e10cSrcweir delete pSet; 3068cdf0e10cSrcweir 3069cdf0e10cSrcweir if( pImp->bIsTemp && aName.Len() ) 3070cdf0e10cSrcweir { 3071cdf0e10cSrcweir String aTemp; 3072cdf0e10cSrcweir if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aTemp )) 3073cdf0e10cSrcweir { 3074cdf0e10cSrcweir DBG_ERROR("Physical name not convertable!"); 3075cdf0e10cSrcweir } 3076cdf0e10cSrcweir 3077cdf0e10cSrcweir if ( !::utl::UCBContentHelper::Kill( aTemp ) ) 3078cdf0e10cSrcweir { 3079cdf0e10cSrcweir DBG_ERROR("Couldn't remove temporary file!"); 3080cdf0e10cSrcweir } 3081cdf0e10cSrcweir } 3082cdf0e10cSrcweir 3083cdf0e10cSrcweir pFilter = 0; 3084cdf0e10cSrcweir 3085cdf0e10cSrcweir delete pURLObj; 3086cdf0e10cSrcweir delete pImp; 3087cdf0e10cSrcweir } 3088cdf0e10cSrcweir 3089cdf0e10cSrcweir //------------------------------------------------------------------ 3090cdf0e10cSrcweir void SfxMedium::SetItemSet(SfxItemSet *pNewSet) 3091cdf0e10cSrcweir { 3092cdf0e10cSrcweir delete pSet; 3093cdf0e10cSrcweir pSet = pNewSet; 3094cdf0e10cSrcweir } 3095cdf0e10cSrcweir 3096cdf0e10cSrcweir //---------------------------------------------------------------- 3097cdf0e10cSrcweir const INetURLObject& SfxMedium::GetURLObject() const 3098cdf0e10cSrcweir { 3099cdf0e10cSrcweir if( !pURLObj ) 3100cdf0e10cSrcweir { 3101cdf0e10cSrcweir SfxMedium* pThis = const_cast < SfxMedium* > (this); 3102cdf0e10cSrcweir pThis->pURLObj = new INetURLObject( aLogicName ); 3103cdf0e10cSrcweir if ( pThis->pURLObj->HasMark() ) 3104cdf0e10cSrcweir (*pThis->pURLObj) = INetURLObject( aLogicName ).GetURLNoMark(); 3105cdf0e10cSrcweir } 3106cdf0e10cSrcweir 3107cdf0e10cSrcweir return *pURLObj; 3108cdf0e10cSrcweir } 3109cdf0e10cSrcweir 3110cdf0e10cSrcweir //---------------------------------------------------------------- 3111cdf0e10cSrcweir 3112cdf0e10cSrcweir const String& SfxMedium::GetPreRedirectedURL() const 3113cdf0e10cSrcweir { 3114cdf0e10cSrcweir return pImp->aPreRedirectionURL; 3115cdf0e10cSrcweir } 3116cdf0e10cSrcweir //---------------------------------------------------------------- 3117cdf0e10cSrcweir 3118cdf0e10cSrcweir sal_uInt32 SfxMedium::GetMIMEAndRedirect( String& /*rName*/ ) 3119cdf0e10cSrcweir { 3120cdf0e10cSrcweir /* dv !!!! not needed any longer ? 3121cdf0e10cSrcweir INetProtocol eProt = GetURLObject().GetProtocol(); 3122cdf0e10cSrcweir if( eProt == INET_PROT_FTP && SvBinding::ShouldUseFtpProxy( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) 3123cdf0e10cSrcweir { 3124cdf0e10cSrcweir Any aAny( UCB_Helper::GetProperty( GetContent(), WID_FLAG_IS_FOLDER ) ); 3125cdf0e10cSrcweir sal_Bool bIsFolder = sal_False; 3126cdf0e10cSrcweir if ( ( aAny >>= bIsFolder ) && bIsFolder ) 3127cdf0e10cSrcweir return ERRCODE_NONE; 3128cdf0e10cSrcweir } 3129cdf0e10cSrcweir 3130cdf0e10cSrcweir GetMedium_Impl(); 3131cdf0e10cSrcweir if( !eError && pImp->xBinding.Is() ) 3132cdf0e10cSrcweir { 3133cdf0e10cSrcweir eError = pImp->xBinding->GetMimeType( rName ); 3134cdf0e10cSrcweir 3135cdf0e10cSrcweir // Wir koennen keine Parameter wie CharSets usw. 3136cdf0e10cSrcweir rName = rName.GetToken( 0, ';' ); 3137cdf0e10cSrcweir if( !eError ) 3138cdf0e10cSrcweir { 3139cdf0e10cSrcweir if( !pImp->aPreRedirectionURL.Len() ) 3140cdf0e10cSrcweir pImp->aPreRedirectionURL = aLogicName; 3141cdf0e10cSrcweir SetName( pImp->xBinding->GetRedirectedURL() ); 3142cdf0e10cSrcweir } 3143cdf0e10cSrcweir pImp->aExpireTime = pImp->xBinding->GetExpireDateTime(); 3144cdf0e10cSrcweir } 3145cdf0e10cSrcweir return eError; 3146cdf0e10cSrcweir */ 3147cdf0e10cSrcweir return 0; 3148cdf0e10cSrcweir } 3149cdf0e10cSrcweir 3150cdf0e10cSrcweir //---------------------------------------------------------------- 3151cdf0e10cSrcweir 3152cdf0e10cSrcweir void SfxMedium::SetReferer( const String& rRefer ) 3153cdf0e10cSrcweir { 3154cdf0e10cSrcweir pImp->aReferer = rRefer; 3155cdf0e10cSrcweir } 3156cdf0e10cSrcweir //---------------------------------------------------------------- 3157cdf0e10cSrcweir 3158cdf0e10cSrcweir const String& SfxMedium::GetReferer( ) const 3159cdf0e10cSrcweir { 3160cdf0e10cSrcweir return pImp->aReferer; 3161cdf0e10cSrcweir } 3162cdf0e10cSrcweir 3163cdf0e10cSrcweir //---------------------------------------------------------------- 3164cdf0e10cSrcweir 3165cdf0e10cSrcweir void SfxMedium::SetExpired_Impl( const DateTime& rDateTime ) 3166cdf0e10cSrcweir { 3167cdf0e10cSrcweir pImp->aExpireTime = rDateTime; 3168cdf0e10cSrcweir } 3169cdf0e10cSrcweir //---------------------------------------------------------------- 3170cdf0e10cSrcweir 3171cdf0e10cSrcweir sal_Bool SfxMedium::IsExpired() const 3172cdf0e10cSrcweir { 3173cdf0e10cSrcweir return pImp->aExpireTime.IsValid() && pImp->aExpireTime < DateTime(); 3174cdf0e10cSrcweir } 3175cdf0e10cSrcweir //---------------------------------------------------------------- 3176cdf0e10cSrcweir 3177cdf0e10cSrcweir void SfxMedium::ForceSynchronStream_Impl( sal_Bool bForce ) 3178cdf0e10cSrcweir { 3179cdf0e10cSrcweir if( pInStream ) 3180cdf0e10cSrcweir { 3181cdf0e10cSrcweir SvLockBytes* pBytes = pInStream->GetLockBytes(); 3182cdf0e10cSrcweir if( pBytes ) 3183cdf0e10cSrcweir pBytes->SetSynchronMode( bForce ); 3184cdf0e10cSrcweir } 3185cdf0e10cSrcweir pImp->bForceSynchron = bForce; 3186cdf0e10cSrcweir } 3187cdf0e10cSrcweir 3188cdf0e10cSrcweir //---------------------------------------------------------------- 3189cdf0e10cSrcweir SfxFrame* SfxMedium::GetLoadTargetFrame() const 3190cdf0e10cSrcweir { 3191cdf0e10cSrcweir return pImp->wLoadTargetFrame; 3192cdf0e10cSrcweir } 3193cdf0e10cSrcweir //---------------------------------------------------------------- 3194cdf0e10cSrcweir 3195cdf0e10cSrcweir void SfxMedium::SetLoadTargetFrame(SfxFrame* pFrame ) 3196cdf0e10cSrcweir { 3197cdf0e10cSrcweir pImp->wLoadTargetFrame = pFrame; 3198cdf0e10cSrcweir } 3199cdf0e10cSrcweir //---------------------------------------------------------------- 3200cdf0e10cSrcweir 3201cdf0e10cSrcweir void SfxMedium::SetStorage_Impl( const uno::Reference < embed::XStorage >& rStor ) 3202cdf0e10cSrcweir { 3203cdf0e10cSrcweir pImp->xStorage = rStor; 3204cdf0e10cSrcweir } 3205cdf0e10cSrcweir //---------------------------------------------------------------- 3206cdf0e10cSrcweir 3207cdf0e10cSrcweir SfxItemSet* SfxMedium::GetItemSet() const 3208cdf0e10cSrcweir { 3209cdf0e10cSrcweir // this method *must* return an ItemSet, returning NULL can cause crashes 3210cdf0e10cSrcweir if( !pSet ) 3211cdf0e10cSrcweir ((SfxMedium*)this)->pSet = new SfxAllItemSet( SFX_APP()->GetPool() ); 3212cdf0e10cSrcweir return pSet; 3213cdf0e10cSrcweir } 3214cdf0e10cSrcweir //---------------------------------------------------------------- 3215cdf0e10cSrcweir 3216cdf0e10cSrcweir SvKeyValueIterator* SfxMedium::GetHeaderAttributes_Impl() 3217cdf0e10cSrcweir { 3218cdf0e10cSrcweir if( !pImp->xAttributes.Is() ) 3219cdf0e10cSrcweir { 3220cdf0e10cSrcweir pImp->xAttributes = SvKeyValueIteratorRef( new SvKeyValueIterator ); 3221cdf0e10cSrcweir 3222cdf0e10cSrcweir if ( GetContent().is() ) 3223cdf0e10cSrcweir { 3224cdf0e10cSrcweir pImp->bIsCharsetInitialized = sal_True; 3225cdf0e10cSrcweir 3226cdf0e10cSrcweir try 3227cdf0e10cSrcweir { 3228cdf0e10cSrcweir Any aAny = pImp->aContent.getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) ); 3229cdf0e10cSrcweir ::rtl::OUString aContentType; 3230cdf0e10cSrcweir aAny >>= aContentType; 3231cdf0e10cSrcweir 3232cdf0e10cSrcweir pImp->xAttributes->Append( SvKeyValue( ::rtl::OUString::createFromAscii( "content-type" ), aContentType ) ); 3233cdf0e10cSrcweir } 3234cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 3235cdf0e10cSrcweir { 3236cdf0e10cSrcweir } 3237cdf0e10cSrcweir } 3238cdf0e10cSrcweir } 3239cdf0e10cSrcweir 3240cdf0e10cSrcweir return pImp->xAttributes; 3241cdf0e10cSrcweir } 3242cdf0e10cSrcweir //---------------------------------------------------------------- 3243cdf0e10cSrcweir 3244cdf0e10cSrcweir SvCompatWeakHdl* SfxMedium::GetHdl() 3245cdf0e10cSrcweir { 3246cdf0e10cSrcweir return pImp->GetHdl(); 3247cdf0e10cSrcweir } 3248cdf0e10cSrcweir 3249cdf0e10cSrcweir sal_Bool SfxMedium::IsDownloadDone_Impl() 3250cdf0e10cSrcweir { 3251cdf0e10cSrcweir return pImp->bDownloadDone; 3252cdf0e10cSrcweir } 3253cdf0e10cSrcweir 3254cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SfxMedium::GetInputStream() 3255cdf0e10cSrcweir { 3256cdf0e10cSrcweir if ( !pImp->xInputStream.is() ) 3257cdf0e10cSrcweir GetMedium_Impl(); 3258cdf0e10cSrcweir return pImp->xInputStream; 3259cdf0e10cSrcweir } 3260cdf0e10cSrcweir 3261cdf0e10cSrcweir const uno::Sequence < util::RevisionTag >& SfxMedium::GetVersionList( bool _bNoReload ) 3262cdf0e10cSrcweir { 3263cdf0e10cSrcweir // if the medium has no name, then this medium should represent a new document and can have no version info 3264cdf0e10cSrcweir if ( ( !_bNoReload || !pImp->m_bVersionsAlreadyLoaded ) && !pImp->aVersions.getLength() && 3265cdf0e10cSrcweir ( aName.Len() || aLogicName.Len() ) && GetStorage().is() ) 3266cdf0e10cSrcweir { 3267cdf0e10cSrcweir uno::Reference < document::XDocumentRevisionListPersistence > xReader( comphelper::getProcessServiceFactory()->createInstance( 3268cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.document.DocumentRevisionListPersistence") ), uno::UNO_QUERY ); 3269cdf0e10cSrcweir if ( xReader.is() ) 3270cdf0e10cSrcweir { 3271cdf0e10cSrcweir try 3272cdf0e10cSrcweir { 3273cdf0e10cSrcweir pImp->aVersions = xReader->load( GetStorage() ); 3274cdf0e10cSrcweir } 3275cdf0e10cSrcweir catch ( uno::Exception& ) 3276cdf0e10cSrcweir { 3277cdf0e10cSrcweir } 3278cdf0e10cSrcweir } 3279cdf0e10cSrcweir } 3280cdf0e10cSrcweir 3281cdf0e10cSrcweir if ( !pImp->m_bVersionsAlreadyLoaded ) 3282cdf0e10cSrcweir pImp->m_bVersionsAlreadyLoaded = sal_True; 3283cdf0e10cSrcweir 3284cdf0e10cSrcweir return pImp->aVersions; 3285cdf0e10cSrcweir } 3286cdf0e10cSrcweir 3287cdf0e10cSrcweir uno::Sequence < util::RevisionTag > SfxMedium::GetVersionList( const uno::Reference < embed::XStorage >& xStorage ) 3288cdf0e10cSrcweir { 3289cdf0e10cSrcweir uno::Reference < document::XDocumentRevisionListPersistence > xReader( comphelper::getProcessServiceFactory()->createInstance( 3290cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.document.DocumentRevisionListPersistence") ), uno::UNO_QUERY ); 3291cdf0e10cSrcweir if ( xReader.is() ) 3292cdf0e10cSrcweir { 3293cdf0e10cSrcweir try 3294cdf0e10cSrcweir { 3295cdf0e10cSrcweir return xReader->load( xStorage ); 3296cdf0e10cSrcweir } 3297cdf0e10cSrcweir catch ( uno::Exception& ) 3298cdf0e10cSrcweir { 3299cdf0e10cSrcweir } 3300cdf0e10cSrcweir } 3301cdf0e10cSrcweir 3302cdf0e10cSrcweir return uno::Sequence < util::RevisionTag >(); 3303cdf0e10cSrcweir } 3304cdf0e10cSrcweir 3305cdf0e10cSrcweir sal_uInt16 SfxMedium::AddVersion_Impl( util::RevisionTag& rRevision ) 3306cdf0e10cSrcweir { 3307cdf0e10cSrcweir if ( GetStorage().is() ) 3308cdf0e10cSrcweir { 3309cdf0e10cSrcweir // Einen eindeutigen Namen f"ur den Stream ermitteln 3310cdf0e10cSrcweir SvULongs aLongs; 3311cdf0e10cSrcweir sal_Int32 nLength = pImp->aVersions.getLength(); 3312cdf0e10cSrcweir for ( sal_Int32 m=0; m<nLength; m++ ) 3313cdf0e10cSrcweir { 3314cdf0e10cSrcweir sal_uInt32 nVer = (sal_uInt32) String( pImp->aVersions[m].Identifier ).Copy(7).ToInt32(); 3315cdf0e10cSrcweir sal_uInt16 n; 3316cdf0e10cSrcweir for ( n=0; n<aLongs.Count(); n++ ) 3317cdf0e10cSrcweir if ( nVer<aLongs[n] ) 3318cdf0e10cSrcweir break; 3319cdf0e10cSrcweir 3320cdf0e10cSrcweir aLongs.Insert( nVer, n ); 3321cdf0e10cSrcweir } 3322cdf0e10cSrcweir 3323cdf0e10cSrcweir sal_uInt16 nKey; 3324cdf0e10cSrcweir for ( nKey=0; nKey<aLongs.Count(); nKey++ ) 3325cdf0e10cSrcweir if ( aLongs[nKey] > ( sal_uIntPtr ) nKey+1 ) 3326cdf0e10cSrcweir break; 3327cdf0e10cSrcweir 3328cdf0e10cSrcweir String aRevName = DEFINE_CONST_UNICODE( "Version" ); 3329cdf0e10cSrcweir aRevName += String::CreateFromInt32( nKey + 1 ); 3330cdf0e10cSrcweir pImp->aVersions.realloc( nLength+1 ); 3331cdf0e10cSrcweir rRevision.Identifier = aRevName; 3332cdf0e10cSrcweir pImp->aVersions[nLength] = rRevision; 3333cdf0e10cSrcweir return nKey; 3334cdf0e10cSrcweir } 3335cdf0e10cSrcweir 3336cdf0e10cSrcweir return 0; 3337cdf0e10cSrcweir } 3338cdf0e10cSrcweir 3339cdf0e10cSrcweir sal_Bool SfxMedium::RemoveVersion_Impl( const ::rtl::OUString& rName ) 3340cdf0e10cSrcweir { 3341cdf0e10cSrcweir if ( !pImp->aVersions.getLength() ) 3342cdf0e10cSrcweir return sal_False; 3343cdf0e10cSrcweir 3344cdf0e10cSrcweir sal_Int32 nLength = pImp->aVersions.getLength(); 3345cdf0e10cSrcweir for ( sal_Int32 n=0; n<nLength; n++ ) 3346cdf0e10cSrcweir { 3347cdf0e10cSrcweir if ( pImp->aVersions[n].Identifier == rName ) 3348cdf0e10cSrcweir { 3349cdf0e10cSrcweir for ( sal_Int32 m=n; m<nLength-1; m++ ) 3350cdf0e10cSrcweir pImp->aVersions[m] = pImp->aVersions[m+1]; 3351cdf0e10cSrcweir pImp->aVersions.realloc(nLength-1); 3352cdf0e10cSrcweir return sal_True; 3353cdf0e10cSrcweir } 3354cdf0e10cSrcweir } 3355cdf0e10cSrcweir 3356cdf0e10cSrcweir return sal_False; 3357cdf0e10cSrcweir } 3358cdf0e10cSrcweir 3359cdf0e10cSrcweir sal_Bool SfxMedium::TransferVersionList_Impl( SfxMedium& rMedium ) 3360cdf0e10cSrcweir { 3361cdf0e10cSrcweir if ( rMedium.pImp->aVersions.getLength() ) 3362cdf0e10cSrcweir { 3363cdf0e10cSrcweir pImp->aVersions = rMedium.pImp->aVersions; 3364cdf0e10cSrcweir return sal_True; 3365cdf0e10cSrcweir } 3366cdf0e10cSrcweir 3367cdf0e10cSrcweir return sal_False; 3368cdf0e10cSrcweir } 3369cdf0e10cSrcweir 3370cdf0e10cSrcweir sal_Bool SfxMedium::SaveVersionList_Impl( sal_Bool /*bUseXML*/ ) 3371cdf0e10cSrcweir { 3372cdf0e10cSrcweir if ( GetStorage().is() ) 3373cdf0e10cSrcweir { 3374cdf0e10cSrcweir if ( !pImp->aVersions.getLength() ) 3375cdf0e10cSrcweir return sal_True; 3376cdf0e10cSrcweir 3377cdf0e10cSrcweir uno::Reference < document::XDocumentRevisionListPersistence > xWriter( comphelper::getProcessServiceFactory()->createInstance( 3378cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.document.DocumentRevisionListPersistence") ), uno::UNO_QUERY ); 3379cdf0e10cSrcweir if ( xWriter.is() ) 3380cdf0e10cSrcweir { 3381cdf0e10cSrcweir try 3382cdf0e10cSrcweir { 3383cdf0e10cSrcweir xWriter->store( GetStorage(), pImp->aVersions ); 3384cdf0e10cSrcweir return sal_True; 3385cdf0e10cSrcweir } 3386cdf0e10cSrcweir catch ( uno::Exception& ) 3387cdf0e10cSrcweir { 3388cdf0e10cSrcweir } 3389cdf0e10cSrcweir } 3390cdf0e10cSrcweir } 3391cdf0e10cSrcweir 3392cdf0e10cSrcweir return sal_False; 3393cdf0e10cSrcweir } 3394cdf0e10cSrcweir 3395cdf0e10cSrcweir //---------------------------------------------------------------- 3396cdf0e10cSrcweir sal_Bool SfxMedium::IsReadOnly() 3397cdf0e10cSrcweir { 3398cdf0e10cSrcweir sal_Bool bReadOnly = sal_False; 3399cdf0e10cSrcweir 3400cdf0e10cSrcweir // a) ReadOnly filter cant produce read/write contents! 3401cdf0e10cSrcweir bReadOnly = ( 3402cdf0e10cSrcweir (pFilter ) && 3403cdf0e10cSrcweir ((pFilter->GetFilterFlags() & SFX_FILTER_OPENREADONLY) == SFX_FILTER_OPENREADONLY) 3404cdf0e10cSrcweir ); 3405cdf0e10cSrcweir 3406cdf0e10cSrcweir // b) if filter allow read/write contents .. check open mode of the storage 3407cdf0e10cSrcweir if (!bReadOnly) 3408cdf0e10cSrcweir bReadOnly = !( GetOpenMode() & STREAM_WRITE ); 3409cdf0e10cSrcweir 3410cdf0e10cSrcweir // c) the API can force the readonly state! 3411cdf0e10cSrcweir if (!bReadOnly) 3412cdf0e10cSrcweir { 3413cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pItem, SfxBoolItem, SID_DOC_READONLY, sal_False); 3414cdf0e10cSrcweir if (pItem) 3415cdf0e10cSrcweir bReadOnly = pItem->GetValue(); 3416cdf0e10cSrcweir } 3417cdf0e10cSrcweir 3418cdf0e10cSrcweir return bReadOnly; 3419cdf0e10cSrcweir } 3420cdf0e10cSrcweir 3421cdf0e10cSrcweir //---------------------------------------------------------------- 3422cdf0e10cSrcweir sal_Bool SfxMedium::SetWritableForUserOnly( const ::rtl::OUString& aURL ) 3423cdf0e10cSrcweir { 3424cdf0e10cSrcweir // UCB does not allow to allow write access only for the user, 3425cdf0e10cSrcweir // use osl API 3426cdf0e10cSrcweir sal_Bool bResult = sal_False; 3427cdf0e10cSrcweir 3428cdf0e10cSrcweir ::osl::DirectoryItem aDirItem; 3429cdf0e10cSrcweir if ( ::osl::DirectoryItem::get( aURL, aDirItem ) == ::osl::FileBase::E_None ) 3430cdf0e10cSrcweir { 3431cdf0e10cSrcweir ::osl::FileStatus aFileStatus( FileStatusMask_Attributes ); 3432cdf0e10cSrcweir if ( aDirItem.getFileStatus( aFileStatus ) == osl::FileBase::E_None 3433cdf0e10cSrcweir && aFileStatus.isValid( FileStatusMask_Attributes ) ) 3434cdf0e10cSrcweir { 3435cdf0e10cSrcweir sal_uInt64 nAttributes = aFileStatus.getAttributes(); 3436cdf0e10cSrcweir 3437cdf0e10cSrcweir nAttributes &= ~(Attribute_OwnWrite | 3438cdf0e10cSrcweir Attribute_GrpWrite | 3439cdf0e10cSrcweir Attribute_OthWrite | 3440cdf0e10cSrcweir Attribute_ReadOnly); 3441cdf0e10cSrcweir nAttributes |= Attribute_OwnWrite; 3442cdf0e10cSrcweir 3443cdf0e10cSrcweir bResult = ( osl::File::setAttributes( aURL, nAttributes ) == ::osl::FileBase::E_None ); 3444cdf0e10cSrcweir } 3445cdf0e10cSrcweir } 3446cdf0e10cSrcweir 3447cdf0e10cSrcweir return bResult; 3448cdf0e10cSrcweir } 3449cdf0e10cSrcweir 3450cdf0e10cSrcweir //---------------------------------------------------------------- 3451cdf0e10cSrcweir void SfxMedium::CreateTempFile( sal_Bool bReplace ) 3452cdf0e10cSrcweir { 3453cdf0e10cSrcweir if ( pImp->pTempFile ) 3454cdf0e10cSrcweir { 3455cdf0e10cSrcweir if ( !bReplace ) 3456cdf0e10cSrcweir return; 3457cdf0e10cSrcweir 3458cdf0e10cSrcweir DELETEZ( pImp->pTempFile ); 3459cdf0e10cSrcweir aName = String(); 3460cdf0e10cSrcweir } 3461cdf0e10cSrcweir 3462cdf0e10cSrcweir pImp->pTempFile = new ::utl::TempFile(); 3463cdf0e10cSrcweir pImp->pTempFile->EnableKillingFile( sal_True ); 3464cdf0e10cSrcweir aName = pImp->pTempFile->GetFileName(); 3465cdf0e10cSrcweir ::rtl::OUString aTmpURL = pImp->pTempFile->GetURL(); 3466cdf0e10cSrcweir if ( !aName.Len() || !aTmpURL.getLength() ) 3467cdf0e10cSrcweir { 3468cdf0e10cSrcweir SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 3469cdf0e10cSrcweir return; 3470cdf0e10cSrcweir } 3471cdf0e10cSrcweir 3472cdf0e10cSrcweir if ( !( nStorOpenMode & STREAM_TRUNC ) ) 3473cdf0e10cSrcweir { 3474cdf0e10cSrcweir sal_Bool bTransferSuccess = sal_False; 3475cdf0e10cSrcweir 3476cdf0e10cSrcweir if ( GetContent().is() 3477cdf0e10cSrcweir && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) 3478cdf0e10cSrcweir && ::utl::UCBContentHelper::IsDocument( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) 3479cdf0e10cSrcweir { 3480cdf0e10cSrcweir // if there is already such a document, we should copy it 3481cdf0e10cSrcweir // if it is a file system use OS copy process 3482cdf0e10cSrcweir try 3483cdf0e10cSrcweir { 3484cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv; 3485cdf0e10cSrcweir INetURLObject aTmpURLObj( aTmpURL ); 3486cdf0e10cSrcweir ::rtl::OUString aFileName = aTmpURLObj.getName( INetURLObject::LAST_SEGMENT, 3487cdf0e10cSrcweir true, 3488cdf0e10cSrcweir INetURLObject::DECODE_WITH_CHARSET ); 3489cdf0e10cSrcweir if ( aFileName.getLength() && aTmpURLObj.removeSegment() ) 3490cdf0e10cSrcweir { 3491cdf0e10cSrcweir ::ucbhelper::Content aTargetContent( aTmpURLObj.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); 3492cdf0e10cSrcweir if ( aTargetContent.transferContent( pImp->aContent, ::ucbhelper::InsertOperation_COPY, aFileName, NameClash::OVERWRITE ) ) 3493cdf0e10cSrcweir { 3494cdf0e10cSrcweir SetWritableForUserOnly( aTmpURL ); 3495cdf0e10cSrcweir bTransferSuccess = sal_True; 3496cdf0e10cSrcweir } 3497cdf0e10cSrcweir } 3498cdf0e10cSrcweir } 3499cdf0e10cSrcweir catch( uno::Exception& ) 3500cdf0e10cSrcweir {} 3501cdf0e10cSrcweir 3502cdf0e10cSrcweir if ( bTransferSuccess ) 3503cdf0e10cSrcweir { 3504cdf0e10cSrcweir CloseOutStream(); 3505cdf0e10cSrcweir CloseInStream(); 3506cdf0e10cSrcweir } 3507cdf0e10cSrcweir } 3508cdf0e10cSrcweir 3509cdf0e10cSrcweir if ( !bTransferSuccess && pInStream ) 3510cdf0e10cSrcweir { 3511cdf0e10cSrcweir // the case when there is no URL-access available or this is a remote protocoll 3512cdf0e10cSrcweir // but there is an input stream 3513cdf0e10cSrcweir GetOutStream(); 3514cdf0e10cSrcweir if ( pOutStream ) 3515cdf0e10cSrcweir { 3516cdf0e10cSrcweir char *pBuf = new char [8192]; 3517cdf0e10cSrcweir sal_uInt32 nErr = ERRCODE_NONE; 3518cdf0e10cSrcweir 3519cdf0e10cSrcweir pInStream->Seek(0); 3520cdf0e10cSrcweir pOutStream->Seek(0); 3521cdf0e10cSrcweir 3522cdf0e10cSrcweir while( !pInStream->IsEof() && nErr == ERRCODE_NONE ) 3523cdf0e10cSrcweir { 3524cdf0e10cSrcweir sal_uInt32 nRead = pInStream->Read( pBuf, 8192 ); 3525cdf0e10cSrcweir nErr = pInStream->GetError(); 3526cdf0e10cSrcweir pOutStream->Write( pBuf, nRead ); 3527cdf0e10cSrcweir } 3528cdf0e10cSrcweir 3529cdf0e10cSrcweir bTransferSuccess = sal_True; 3530cdf0e10cSrcweir delete[] pBuf; 3531cdf0e10cSrcweir CloseInStream(); 3532cdf0e10cSrcweir } 3533cdf0e10cSrcweir CloseOutStream_Impl(); 3534cdf0e10cSrcweir } 3535cdf0e10cSrcweir else 3536cdf0e10cSrcweir { 3537cdf0e10cSrcweir // Quite strange design, but currently it is expected that in this case no transfer happens 3538cdf0e10cSrcweir // TODO/LATER: get rid of this inconsistent part of the call design 3539cdf0e10cSrcweir bTransferSuccess = sal_True; 3540cdf0e10cSrcweir CloseInStream(); 3541cdf0e10cSrcweir } 3542cdf0e10cSrcweir 3543cdf0e10cSrcweir if ( !bTransferSuccess ) 3544cdf0e10cSrcweir { 3545cdf0e10cSrcweir SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 3546cdf0e10cSrcweir return; 3547cdf0e10cSrcweir } 3548cdf0e10cSrcweir } 3549cdf0e10cSrcweir 3550cdf0e10cSrcweir CloseStorage(); 3551cdf0e10cSrcweir } 3552cdf0e10cSrcweir 3553cdf0e10cSrcweir //---------------------------------------------------------------- 3554cdf0e10cSrcweir void SfxMedium::CreateTempFileNoCopy() 3555cdf0e10cSrcweir { 3556cdf0e10cSrcweir // this call always replaces the existing temporary file 3557cdf0e10cSrcweir if ( pImp->pTempFile ) 3558cdf0e10cSrcweir delete pImp->pTempFile; 3559cdf0e10cSrcweir 3560cdf0e10cSrcweir pImp->pTempFile = new ::utl::TempFile(); 3561cdf0e10cSrcweir pImp->pTempFile->EnableKillingFile( sal_True ); 3562cdf0e10cSrcweir aName = pImp->pTempFile->GetFileName(); 3563cdf0e10cSrcweir if ( !aName.Len() ) 3564cdf0e10cSrcweir { 3565cdf0e10cSrcweir SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 3566cdf0e10cSrcweir return; 3567cdf0e10cSrcweir } 3568cdf0e10cSrcweir 3569cdf0e10cSrcweir CloseOutStream_Impl(); 3570cdf0e10cSrcweir CloseStorage(); 3571cdf0e10cSrcweir } 3572cdf0e10cSrcweir 3573cdf0e10cSrcweir ::rtl::OUString SfxMedium::GetCharset() 3574cdf0e10cSrcweir { 3575cdf0e10cSrcweir if( !pImp->bIsCharsetInitialized ) 3576cdf0e10cSrcweir { 3577cdf0e10cSrcweir // Set an error in case there is no content? 3578cdf0e10cSrcweir if ( GetContent().is() ) 3579cdf0e10cSrcweir { 3580cdf0e10cSrcweir pImp->bIsCharsetInitialized = sal_True; 3581cdf0e10cSrcweir 3582cdf0e10cSrcweir try 3583cdf0e10cSrcweir { 3584cdf0e10cSrcweir Any aAny = pImp->aContent.getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) ); 3585cdf0e10cSrcweir ::rtl::OUString aField; 3586cdf0e10cSrcweir aAny >>= aField; 3587cdf0e10cSrcweir 3588cdf0e10cSrcweir ::rtl::OString sContent = ::rtl::OUStringToOString( aField, RTL_TEXTENCODING_ASCII_US ); 3589cdf0e10cSrcweir ByteString sType, sSubType; 3590cdf0e10cSrcweir INetContentTypeParameterList aParameters; 3591cdf0e10cSrcweir 3592cdf0e10cSrcweir if( INetContentTypes::parse( sContent, sType, sSubType, &aParameters ) ) 3593cdf0e10cSrcweir { 3594cdf0e10cSrcweir const INetContentTypeParameter * pCharset = aParameters.find("charset"); 3595cdf0e10cSrcweir if (pCharset != 0) 3596cdf0e10cSrcweir pImp->aCharset = pCharset->m_sValue; 3597cdf0e10cSrcweir } 3598cdf0e10cSrcweir } 3599cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 3600cdf0e10cSrcweir { 3601cdf0e10cSrcweir } 3602cdf0e10cSrcweir } 3603cdf0e10cSrcweir } 3604cdf0e10cSrcweir 3605cdf0e10cSrcweir return pImp->aCharset; 3606cdf0e10cSrcweir } 3607cdf0e10cSrcweir 3608cdf0e10cSrcweir void SfxMedium::SetCharset( ::rtl::OUString aChs ) 3609cdf0e10cSrcweir { 3610cdf0e10cSrcweir pImp->bIsCharsetInitialized = sal_True; 3611cdf0e10cSrcweir pImp->aCharset = aChs; 3612cdf0e10cSrcweir } 3613cdf0e10cSrcweir 3614cdf0e10cSrcweir sal_Bool SfxMedium::SignContents_Impl( sal_Bool bScriptingContent, const ::rtl::OUString& aODFVersion, sal_Bool bHasValidDocumentSignature ) 3615cdf0e10cSrcweir { 3616cdf0e10cSrcweir sal_Bool bChanges = sal_False; 3617cdf0e10cSrcweir 3618cdf0e10cSrcweir // the medium should be closed to be able to sign, the caller is responsible to close it 3619cdf0e10cSrcweir if ( !IsOpen() && !GetError() ) 3620cdf0e10cSrcweir { 3621cdf0e10cSrcweir // The component should know if there was a valid document signature, since 3622cdf0e10cSrcweir // it should show a warning in this case 3623cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 3624cdf0e10cSrcweir aArgs[0] <<= aODFVersion; 3625cdf0e10cSrcweir aArgs[1] <<= bHasValidDocumentSignature; 3626cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::security::XDocumentDigitalSignatures > xSigner( 3627cdf0e10cSrcweir comphelper::getProcessServiceFactory()->createInstanceWithArguments( 3628cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), 3629cdf0e10cSrcweir aArgs ), 3630cdf0e10cSrcweir ::com::sun::star::uno::UNO_QUERY ); 3631cdf0e10cSrcweir 3632cdf0e10cSrcweir if ( xSigner.is() ) 3633cdf0e10cSrcweir { 3634cdf0e10cSrcweir uno::Reference< embed::XStorage > xWriteableZipStor; 3635cdf0e10cSrcweir if ( !IsReadOnly() ) 3636cdf0e10cSrcweir { 3637cdf0e10cSrcweir // we can reuse the temporary file if there is one already 3638cdf0e10cSrcweir CreateTempFile( sal_False ); 3639cdf0e10cSrcweir GetMedium_Impl(); 3640cdf0e10cSrcweir 3641cdf0e10cSrcweir try 3642cdf0e10cSrcweir { 3643cdf0e10cSrcweir if ( !pImp->xStream.is() ) 3644cdf0e10cSrcweir throw uno::RuntimeException(); 3645cdf0e10cSrcweir 3646cdf0e10cSrcweir xWriteableZipStor = ::comphelper::OStorageHelper::GetStorageOfFormatFromStream( ZIP_STORAGE_FORMAT_STRING, pImp->xStream ); 3647cdf0e10cSrcweir if ( !xWriteableZipStor.is() ) 3648cdf0e10cSrcweir throw uno::RuntimeException(); 3649cdf0e10cSrcweir 3650cdf0e10cSrcweir uno::Reference< embed::XStorage > xMetaInf = xWriteableZipStor->openStorageElement( 3651cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ), 3652cdf0e10cSrcweir embed::ElementModes::READWRITE ); 3653cdf0e10cSrcweir if ( !xMetaInf.is() ) 3654cdf0e10cSrcweir throw uno::RuntimeException(); 3655cdf0e10cSrcweir 3656cdf0e10cSrcweir if ( bScriptingContent ) 3657cdf0e10cSrcweir { 3658cdf0e10cSrcweir // If the signature has already the document signature it will be removed 3659cdf0e10cSrcweir // after the scripting signature is inserted. 3660cdf0e10cSrcweir uno::Reference< io::XStream > xStream( 3661cdf0e10cSrcweir xMetaInf->openStreamElement( xSigner->getScriptingContentSignatureDefaultStreamName(), 3662cdf0e10cSrcweir embed::ElementModes::READWRITE ), 3663cdf0e10cSrcweir uno::UNO_SET_THROW ); 3664cdf0e10cSrcweir 3665cdf0e10cSrcweir if ( xSigner->signScriptingContent( GetZipStorageToSign_Impl(), xStream ) ) 3666cdf0e10cSrcweir { 3667cdf0e10cSrcweir // remove the document signature if any 3668cdf0e10cSrcweir ::rtl::OUString aDocSigName = xSigner->getDocumentContentSignatureDefaultStreamName(); 3669cdf0e10cSrcweir if ( aDocSigName.getLength() && xMetaInf->hasByName( aDocSigName ) ) 3670cdf0e10cSrcweir xMetaInf->removeElement( aDocSigName ); 3671cdf0e10cSrcweir 3672cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW ); 3673cdf0e10cSrcweir xTransact->commit(); 3674cdf0e10cSrcweir xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW ); 3675cdf0e10cSrcweir xTransact->commit(); 3676cdf0e10cSrcweir 3677cdf0e10cSrcweir // the temporary file has been written, commit it to the original file 3678cdf0e10cSrcweir Commit(); 3679cdf0e10cSrcweir bChanges = sal_True; 3680cdf0e10cSrcweir } 3681cdf0e10cSrcweir } 3682cdf0e10cSrcweir else 3683cdf0e10cSrcweir { 3684cdf0e10cSrcweir uno::Reference< io::XStream > xStream( 3685cdf0e10cSrcweir xMetaInf->openStreamElement( xSigner->getDocumentContentSignatureDefaultStreamName(), 3686cdf0e10cSrcweir embed::ElementModes::READWRITE ), 3687cdf0e10cSrcweir uno::UNO_SET_THROW ); 3688cdf0e10cSrcweir 3689cdf0e10cSrcweir if ( xSigner->signDocumentContent( GetZipStorageToSign_Impl(), xStream ) ) 3690cdf0e10cSrcweir { 3691cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW ); 3692cdf0e10cSrcweir xTransact->commit(); 3693cdf0e10cSrcweir xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW ); 3694cdf0e10cSrcweir xTransact->commit(); 3695cdf0e10cSrcweir 3696cdf0e10cSrcweir // the temporary file has been written, commit it to the original file 3697cdf0e10cSrcweir Commit(); 3698cdf0e10cSrcweir bChanges = sal_True; 3699cdf0e10cSrcweir } 3700cdf0e10cSrcweir } 3701cdf0e10cSrcweir } 3702cdf0e10cSrcweir catch ( uno::Exception& ) 3703cdf0e10cSrcweir { 3704cdf0e10cSrcweir OSL_ENSURE( sal_False, "Couldn't use signing functionality!\n" ); 3705cdf0e10cSrcweir } 3706cdf0e10cSrcweir 3707cdf0e10cSrcweir CloseAndRelease(); 3708cdf0e10cSrcweir } 3709cdf0e10cSrcweir else 3710cdf0e10cSrcweir { 3711cdf0e10cSrcweir try 3712cdf0e10cSrcweir { 3713cdf0e10cSrcweir if ( bScriptingContent ) 3714cdf0e10cSrcweir xSigner->showScriptingContentSignatures( GetZipStorageToSign_Impl(), uno::Reference< io::XInputStream >() ); 3715cdf0e10cSrcweir else 3716cdf0e10cSrcweir xSigner->showDocumentContentSignatures( GetZipStorageToSign_Impl(), uno::Reference< io::XInputStream >() ); 3717cdf0e10cSrcweir } 3718cdf0e10cSrcweir catch( uno::Exception& ) 3719cdf0e10cSrcweir { 3720cdf0e10cSrcweir OSL_ENSURE( sal_False, "Couldn't use signing functionality!\n" ); 3721cdf0e10cSrcweir } 3722cdf0e10cSrcweir } 3723cdf0e10cSrcweir } 3724cdf0e10cSrcweir 3725cdf0e10cSrcweir ResetError(); 3726cdf0e10cSrcweir } 3727cdf0e10cSrcweir 3728cdf0e10cSrcweir return bChanges; 3729cdf0e10cSrcweir } 3730cdf0e10cSrcweir 3731cdf0e10cSrcweir //---------------------------------------------------------------- 3732cdf0e10cSrcweir sal_uInt16 SfxMedium::GetCachedSignatureState_Impl() 3733cdf0e10cSrcweir { 3734cdf0e10cSrcweir return pImp->m_nSignatureState; 3735cdf0e10cSrcweir } 3736cdf0e10cSrcweir 3737cdf0e10cSrcweir //---------------------------------------------------------------- 3738cdf0e10cSrcweir void SfxMedium::SetCachedSignatureState_Impl( sal_uInt16 nState ) 3739cdf0e10cSrcweir { 3740cdf0e10cSrcweir pImp->m_nSignatureState = nState; 3741cdf0e10cSrcweir } 3742cdf0e10cSrcweir 3743cdf0e10cSrcweir sal_Bool SfxMedium::HasStorage_Impl() const 3744cdf0e10cSrcweir { 3745cdf0e10cSrcweir return pImp->xStorage.is(); 3746cdf0e10cSrcweir } 3747cdf0e10cSrcweir 3748cdf0e10cSrcweir sal_Bool SfxMedium::IsOpen() const 3749cdf0e10cSrcweir { 3750cdf0e10cSrcweir return pInStream || pOutStream || pImp->xStorage.is(); 3751cdf0e10cSrcweir } 3752cdf0e10cSrcweir 3753cdf0e10cSrcweir ::rtl::OUString SfxMedium::CreateTempCopyWithExt( const ::rtl::OUString& aURL ) 3754cdf0e10cSrcweir { 3755cdf0e10cSrcweir ::rtl::OUString aResult; 3756cdf0e10cSrcweir 3757cdf0e10cSrcweir if ( aURL.getLength() ) 3758cdf0e10cSrcweir { 3759cdf0e10cSrcweir sal_Int32 nPrefixLen = aURL.lastIndexOf( '.' ); 3760cdf0e10cSrcweir String aExt = ( nPrefixLen == -1 ) ? String() : String( aURL.copy( nPrefixLen ) ); 3761cdf0e10cSrcweir 3762cdf0e10cSrcweir ::rtl::OUString aNewTempFileURL = ::utl::TempFile( String(), &aExt ).GetURL(); 3763cdf0e10cSrcweir if ( aNewTempFileURL.getLength() ) 3764cdf0e10cSrcweir { 3765cdf0e10cSrcweir INetURLObject aSource( aURL ); 3766cdf0e10cSrcweir INetURLObject aDest( aNewTempFileURL ); 3767cdf0e10cSrcweir ::rtl::OUString aFileName = aDest.getName( INetURLObject::LAST_SEGMENT, 3768cdf0e10cSrcweir true, 3769cdf0e10cSrcweir INetURLObject::DECODE_WITH_CHARSET ); 3770cdf0e10cSrcweir if ( aFileName.getLength() && aDest.removeSegment() ) 3771cdf0e10cSrcweir { 3772cdf0e10cSrcweir try 3773cdf0e10cSrcweir { 3774cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv; 3775cdf0e10cSrcweir ::ucbhelper::Content aTargetContent( aDest.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); 3776cdf0e10cSrcweir ::ucbhelper::Content aSourceContent( aSource.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); 3777cdf0e10cSrcweir if ( aTargetContent.transferContent( aSourceContent, 3778cdf0e10cSrcweir ::ucbhelper::InsertOperation_COPY, 3779cdf0e10cSrcweir aFileName, 3780cdf0e10cSrcweir NameClash::OVERWRITE ) ) 3781cdf0e10cSrcweir { 3782cdf0e10cSrcweir // Success 3783cdf0e10cSrcweir aResult = aNewTempFileURL; 3784cdf0e10cSrcweir } 3785cdf0e10cSrcweir } 3786cdf0e10cSrcweir catch( uno::Exception& ) 3787cdf0e10cSrcweir {} 3788cdf0e10cSrcweir } 3789cdf0e10cSrcweir } 3790cdf0e10cSrcweir } 3791cdf0e10cSrcweir 3792cdf0e10cSrcweir return aResult; 3793cdf0e10cSrcweir } 3794cdf0e10cSrcweir 3795cdf0e10cSrcweir sal_Bool SfxMedium::CallApproveHandler( const uno::Reference< task::XInteractionHandler >& xHandler, uno::Any aRequest, sal_Bool bAllowAbort ) 3796cdf0e10cSrcweir { 3797cdf0e10cSrcweir sal_Bool bResult = sal_False; 3798cdf0e10cSrcweir 3799cdf0e10cSrcweir if ( xHandler.is() ) 3800cdf0e10cSrcweir { 3801cdf0e10cSrcweir try 3802cdf0e10cSrcweir { 3803cdf0e10cSrcweir uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( bAllowAbort ? 2 : 1 ); 3804cdf0e10cSrcweir 3805cdf0e10cSrcweir ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove ); 3806cdf0e10cSrcweir aContinuations[ 0 ] = pApprove.get(); 3807cdf0e10cSrcweir 3808cdf0e10cSrcweir if ( bAllowAbort ) 3809cdf0e10cSrcweir { 3810cdf0e10cSrcweir ::rtl::Reference< ::comphelper::OInteractionAbort > pAbort( new ::comphelper::OInteractionAbort ); 3811cdf0e10cSrcweir aContinuations[ 1 ] = pAbort.get(); 3812cdf0e10cSrcweir } 3813cdf0e10cSrcweir 3814cdf0e10cSrcweir xHandler->handle(::framework::InteractionRequest::CreateRequest (aRequest,aContinuations)); 3815cdf0e10cSrcweir bResult = pApprove->wasSelected(); 3816cdf0e10cSrcweir } 3817cdf0e10cSrcweir catch( const Exception& ) 3818cdf0e10cSrcweir { 3819cdf0e10cSrcweir } 3820cdf0e10cSrcweir } 3821cdf0e10cSrcweir 3822cdf0e10cSrcweir return bResult; 3823cdf0e10cSrcweir } 3824cdf0e10cSrcweir 3825cdf0e10cSrcweir ::rtl::OUString SfxMedium::SwitchDocumentToTempFile() 3826cdf0e10cSrcweir { 3827cdf0e10cSrcweir // the method returns empty string in case of failure 3828cdf0e10cSrcweir ::rtl::OUString aResult; 3829cdf0e10cSrcweir ::rtl::OUString aOrigURL = aLogicName; 3830cdf0e10cSrcweir 3831cdf0e10cSrcweir if ( aOrigURL.getLength() ) 3832cdf0e10cSrcweir { 3833cdf0e10cSrcweir sal_Int32 nPrefixLen = aOrigURL.lastIndexOf( '.' ); 3834cdf0e10cSrcweir String aExt = ( nPrefixLen == -1 ) ? String() : String( aOrigURL.copy( nPrefixLen ) ); 3835cdf0e10cSrcweir ::rtl::OUString aNewURL = ::utl::TempFile( String(), &aExt ).GetURL(); 3836cdf0e10cSrcweir 3837cdf0e10cSrcweir // TODO/LATER: In future the aLogicName should be set to shared folder URL 3838cdf0e10cSrcweir // and a temporary file should be created. Transport_Impl should be impossible then. 3839cdf0e10cSrcweir if ( aNewURL.getLength() ) 3840cdf0e10cSrcweir { 3841cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage = GetStorage(); 3842cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY ); 3843cdf0e10cSrcweir 3844cdf0e10cSrcweir if ( xOptStorage.is() ) 3845cdf0e10cSrcweir { 3846cdf0e10cSrcweir // TODO/LATER: reuse the pImp->pTempFile if it already exists 3847cdf0e10cSrcweir CanDisposeStorage_Impl( sal_False ); 3848cdf0e10cSrcweir Close(); 3849cdf0e10cSrcweir SetPhysicalName_Impl( String() ); 3850cdf0e10cSrcweir SetName( aNewURL ); 3851cdf0e10cSrcweir 3852cdf0e10cSrcweir // remove the readonly state 3853cdf0e10cSrcweir sal_Bool bWasReadonly = sal_False; 3854cdf0e10cSrcweir nStorOpenMode = SFX_STREAM_READWRITE; 3855cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, sal_False ); 3856cdf0e10cSrcweir if ( pReadOnlyItem && pReadOnlyItem->GetValue() ) 3857cdf0e10cSrcweir bWasReadonly = sal_True; 3858cdf0e10cSrcweir GetItemSet()->ClearItem( SID_DOC_READONLY ); 3859cdf0e10cSrcweir 3860cdf0e10cSrcweir GetMedium_Impl(); 3861cdf0e10cSrcweir LockOrigFileOnDemand( sal_False, sal_False ); 3862cdf0e10cSrcweir CreateTempFile( sal_True ); 3863cdf0e10cSrcweir GetMedium_Impl(); 3864cdf0e10cSrcweir 3865cdf0e10cSrcweir if ( pImp->xStream.is() ) 3866cdf0e10cSrcweir { 3867cdf0e10cSrcweir try 3868cdf0e10cSrcweir { 3869cdf0e10cSrcweir xOptStorage->writeAndAttachToStream( pImp->xStream ); 3870cdf0e10cSrcweir pImp->xStorage = xStorage; 3871cdf0e10cSrcweir aResult = aNewURL; 3872cdf0e10cSrcweir } 3873cdf0e10cSrcweir catch( uno::Exception& ) 3874cdf0e10cSrcweir {} 3875cdf0e10cSrcweir } 3876cdf0e10cSrcweir 3877cdf0e10cSrcweir if ( !aResult.getLength() ) 3878cdf0e10cSrcweir { 3879cdf0e10cSrcweir Close(); 3880cdf0e10cSrcweir SetPhysicalName_Impl( String() ); 3881cdf0e10cSrcweir SetName( aOrigURL ); 3882cdf0e10cSrcweir if ( bWasReadonly ) 3883cdf0e10cSrcweir { 3884cdf0e10cSrcweir // set the readonly state back 3885cdf0e10cSrcweir nStorOpenMode = SFX_STREAM_READONLY; 3886cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem(SID_DOC_READONLY, sal_True)); 3887cdf0e10cSrcweir } 3888cdf0e10cSrcweir GetMedium_Impl(); 3889cdf0e10cSrcweir pImp->xStorage = xStorage; 3890cdf0e10cSrcweir } 3891cdf0e10cSrcweir } 3892cdf0e10cSrcweir } 3893cdf0e10cSrcweir } 3894cdf0e10cSrcweir 3895cdf0e10cSrcweir return aResult; 3896cdf0e10cSrcweir } 3897cdf0e10cSrcweir 3898cdf0e10cSrcweir sal_Bool SfxMedium::SwitchDocumentToFile( ::rtl::OUString aURL ) 3899cdf0e10cSrcweir { 3900cdf0e10cSrcweir // the method is only for storage based documents 3901cdf0e10cSrcweir sal_Bool bResult = sal_False; 3902cdf0e10cSrcweir ::rtl::OUString aOrigURL = aLogicName; 3903cdf0e10cSrcweir 3904cdf0e10cSrcweir if ( aURL.getLength() && aOrigURL.getLength() ) 3905cdf0e10cSrcweir { 3906cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage = GetStorage(); 3907cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY ); 3908cdf0e10cSrcweir 3909cdf0e10cSrcweir if ( xOptStorage.is() ) 3910cdf0e10cSrcweir { 3911cdf0e10cSrcweir // TODO/LATER: reuse the pImp->pTempFile if it already exists 3912cdf0e10cSrcweir CanDisposeStorage_Impl( sal_False ); 3913cdf0e10cSrcweir Close(); 3914cdf0e10cSrcweir SetPhysicalName_Impl( String() ); 3915cdf0e10cSrcweir SetName( aURL ); 3916cdf0e10cSrcweir 3917cdf0e10cSrcweir // open the temporary file based document 3918cdf0e10cSrcweir GetMedium_Impl(); 3919cdf0e10cSrcweir LockOrigFileOnDemand( sal_False, sal_False ); 3920cdf0e10cSrcweir CreateTempFile( sal_True ); 3921cdf0e10cSrcweir GetMedium_Impl(); 3922cdf0e10cSrcweir 3923cdf0e10cSrcweir if ( pImp->xStream.is() ) 3924cdf0e10cSrcweir { 3925cdf0e10cSrcweir try 3926cdf0e10cSrcweir { 3927cdf0e10cSrcweir uno::Reference< io::XTruncate > xTruncate( pImp->xStream, uno::UNO_QUERY_THROW ); 3928cdf0e10cSrcweir if ( xTruncate.is() ) 3929cdf0e10cSrcweir xTruncate->truncate(); 3930cdf0e10cSrcweir 3931cdf0e10cSrcweir xOptStorage->writeAndAttachToStream( pImp->xStream ); 3932cdf0e10cSrcweir pImp->xStorage = xStorage; 3933cdf0e10cSrcweir bResult = sal_True; 3934cdf0e10cSrcweir } 3935cdf0e10cSrcweir catch( uno::Exception& ) 3936cdf0e10cSrcweir {} 3937cdf0e10cSrcweir } 3938cdf0e10cSrcweir 3939cdf0e10cSrcweir if ( !bResult ) 3940cdf0e10cSrcweir { 3941cdf0e10cSrcweir Close(); 3942cdf0e10cSrcweir SetPhysicalName_Impl( String() ); 3943cdf0e10cSrcweir SetName( aOrigURL ); 3944cdf0e10cSrcweir GetMedium_Impl(); 3945cdf0e10cSrcweir pImp->xStorage = xStorage; 3946cdf0e10cSrcweir } 3947cdf0e10cSrcweir } 3948cdf0e10cSrcweir } 3949cdf0e10cSrcweir 3950cdf0e10cSrcweir return bResult; 3951cdf0e10cSrcweir } 3952cdf0e10cSrcweir 3953