1d119d52dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5d119d52dSAndrew Rist * distributed with this work for additional information 6d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8d119d52dSAndrew Rist * "License"); you may not use this file except in compliance 9d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14d119d52dSAndrew Rist * software distributed under the License is distributed on an 15d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16d119d52dSAndrew Rist * KIND, either express or implied. See the License for the 17d119d52dSAndrew Rist * specific language governing permissions and limitations 18d119d52dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20d119d52dSAndrew Rist *************************************************************/ 21d119d52dSAndrew Rist 22d119d52dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 26cdf0e10cSrcweir #include <sfx2/docfile.hxx> 27cdf0e10cSrcweir #include "sfx2/signaturestate.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <uno/mapping.hxx> 30cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 31cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h> 32cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 33cdf0e10cSrcweir #include <com/sun/star/document/XDocumentRevisionListPersistence.hpp> 34cdf0e10cSrcweir #include <com/sun/star/document/LockedDocumentRequest.hpp> 35cdf0e10cSrcweir #include <com/sun/star/document/OwnLockOnDocumentRequest.hpp> 36cdf0e10cSrcweir #include <com/sun/star/document/LockedOnSavingRequest.hpp> 37cdf0e10cSrcweir #include <com/sun/star/document/LockFileIgnoreRequest.hpp> 38cdf0e10cSrcweir #include <com/sun/star/document/ChangedByOthersRequest.hpp> 39cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 40cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp> 41cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 42cdf0e10cSrcweir #include <com/sun/star/embed/UseBackupException.hpp> 43cdf0e10cSrcweir #include <com/sun/star/embed/XOptimizedStorage.hpp> 44cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveIOException.hpp> 45cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp> 46cdf0e10cSrcweir #include <com/sun/star/ucb/CommandFailedException.hpp> 47cdf0e10cSrcweir #include <com/sun/star/ucb/CommandAbortedException.hpp> 48cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp> 49cdf0e10cSrcweir #include <com/sun/star/ucb/XContentIdentifierFactory.hpp> 50cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp> 51cdf0e10cSrcweir #include <com/sun/star/ucb/XProgressHandler.hpp> 52cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp> 539c0c1533SAndrea Pescetti #include <com/sun/star/ucb/Lock.hpp> 549c0c1533SAndrea Pescetti #include <com/sun/star/ucb/InteractiveLockingLockNotAvailableException.hpp> 559c0c1533SAndrea Pescetti #include <com/sun/star/ucb/InteractiveLockingLockedException.hpp> 569c0c1533SAndrea Pescetti #include <com/sun/star/ucb/InteractiveNetworkReadException.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 3169c0c1533SAndrea Pescetti ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xCredentialInteraction; 3179c0c1533SAndrea Pescetti 318cdf0e10cSrcweir sal_Bool m_bRemoveBackup; 319cdf0e10cSrcweir ::rtl::OUString m_aBackupURL; 320cdf0e10cSrcweir 321*30acf5e8Spfg // the following member is changed and makes sense only during saving 322cdf0e10cSrcweir // TODO/LATER: in future the signature state should be controlled by the medium not by the document 323cdf0e10cSrcweir // in this case the member will hold this information 324cdf0e10cSrcweir sal_uInt16 m_nSignatureState; 325cdf0e10cSrcweir 326cdf0e10cSrcweir util::DateTime m_aDateTime; 327cdf0e10cSrcweir 328cdf0e10cSrcweir uno::Reference< logging::XSimpleLogRing > m_xLogRing; 329cdf0e10cSrcweir 330cdf0e10cSrcweir SfxMedium_Impl( SfxMedium* pAntiImplP ); 331cdf0e10cSrcweir ~SfxMedium_Impl(); 332cdf0e10cSrcweir }; 333cdf0e10cSrcweir 334cdf0e10cSrcweir void SfxMedium::DataAvailable_Impl() 335cdf0e10cSrcweir { 336cdf0e10cSrcweir pImp->aAvailableLink.ClearPendingCall(); 337cdf0e10cSrcweir pImp->aAvailableLink.Call( NULL ); 338cdf0e10cSrcweir } 339cdf0e10cSrcweir 340cdf0e10cSrcweir void SfxMedium::Cancel_Impl() 341cdf0e10cSrcweir { 342cdf0e10cSrcweir SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir 345cdf0e10cSrcweir //------------------------------------------------------------------ 346cdf0e10cSrcweir SfxMedium_Impl::SfxMedium_Impl( SfxMedium* pAntiImplP ) 347cdf0e10cSrcweir : SvCompatWeakBase( pAntiImplP ), 348cdf0e10cSrcweir bUpdatePickList(sal_True), 349cdf0e10cSrcweir bIsTemp( sal_False ), 350cdf0e10cSrcweir bForceSynchron( sal_False ), 351cdf0e10cSrcweir bDownloadDone( sal_True ), 352cdf0e10cSrcweir bDontCallDoneLinkOnSharingError( sal_False ), 353cdf0e10cSrcweir bIsStorage( sal_False ), 354cdf0e10cSrcweir bUseInteractionHandler( sal_True ), 355cdf0e10cSrcweir bAllowDefaultIntHdl( sal_False ), 356cdf0e10cSrcweir bIsCharsetInitialized( sal_False ), 357cdf0e10cSrcweir bStorageBasedOnInStream( sal_False ), 358cdf0e10cSrcweir m_bSalvageMode( sal_False ), 359cdf0e10cSrcweir m_bVersionsAlreadyLoaded( sal_False ), 360cdf0e10cSrcweir m_bLocked( sal_False ), 361cdf0e10cSrcweir m_bGotDateTime( sal_False ), 362cdf0e10cSrcweir pAntiImpl( pAntiImplP ), 363cdf0e10cSrcweir nFileVersion( 0 ), 364cdf0e10cSrcweir pOrigFilter( 0 ), 365cdf0e10cSrcweir aExpireTime( Date() + 10, Time() ), 366cdf0e10cSrcweir pTempFile( NULL ), 367cdf0e10cSrcweir nLastStorageError( 0 ), 368cdf0e10cSrcweir m_bRemoveBackup( sal_False ), 369cdf0e10cSrcweir m_nSignatureState( SIGNATURESTATE_NOSIGNATURES ) 370cdf0e10cSrcweir { 371cdf0e10cSrcweir aDoneLink.CreateMutex(); 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir //------------------------------------------------------------------ 375cdf0e10cSrcweir SfxMedium_Impl::~SfxMedium_Impl() 376cdf0e10cSrcweir { 377cdf0e10cSrcweir 378cdf0e10cSrcweir aDoneLink.ClearPendingCall(); 379cdf0e10cSrcweir aAvailableLink.ClearPendingCall(); 380cdf0e10cSrcweir 381cdf0e10cSrcweir if ( pTempFile ) 382cdf0e10cSrcweir delete pTempFile; 383cdf0e10cSrcweir } 384cdf0e10cSrcweir 385cdf0e10cSrcweir //================================================================ 386cdf0e10cSrcweir 387cdf0e10cSrcweir #define IMPL_CTOR(rootVal,URLVal) \ 388cdf0e10cSrcweir eError( SVSTREAM_OK ), \ 389cdf0e10cSrcweir \ 390cdf0e10cSrcweir bDirect( sal_False ), \ 391cdf0e10cSrcweir bRoot( rootVal ), \ 392cdf0e10cSrcweir bSetFilter( sal_False ), \ 393cdf0e10cSrcweir bTriedStorage( sal_False ), \ 394cdf0e10cSrcweir \ 395cdf0e10cSrcweir nStorOpenMode( SFX_STREAM_READWRITE ), \ 396cdf0e10cSrcweir pURLObj( URLVal ), \ 397cdf0e10cSrcweir pInStream(0), \ 398cdf0e10cSrcweir pOutStream( 0 ) 399cdf0e10cSrcweir 400cdf0e10cSrcweir //------------------------------------------------------------------ 401cdf0e10cSrcweir void SfxMedium::ResetError() 402cdf0e10cSrcweir { 403cdf0e10cSrcweir eError = SVSTREAM_OK; 404cdf0e10cSrcweir if( pInStream ) 405cdf0e10cSrcweir pInStream->ResetError(); 406cdf0e10cSrcweir if( pOutStream ) 407cdf0e10cSrcweir pOutStream->ResetError(); 408cdf0e10cSrcweir } 409cdf0e10cSrcweir 410cdf0e10cSrcweir //------------------------------------------------------------------ 411cdf0e10cSrcweir sal_uInt32 SfxMedium::GetLastStorageCreationState() 412cdf0e10cSrcweir { 413cdf0e10cSrcweir return pImp->nLastStorageError; 414cdf0e10cSrcweir } 415cdf0e10cSrcweir 416cdf0e10cSrcweir //------------------------------------------------------------------ 417cdf0e10cSrcweir void SfxMedium::AddLog( const ::rtl::OUString& aMessage ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir if ( !pImp->m_xLogRing.is() ) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir try 422cdf0e10cSrcweir { 423cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 424cdf0e10cSrcweir if ( aContext.is() ) 425cdf0e10cSrcweir pImp->m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), UNO_QUERY_THROW ); 426cdf0e10cSrcweir } 427cdf0e10cSrcweir catch( uno::Exception& ) 428cdf0e10cSrcweir {} 429cdf0e10cSrcweir } 430cdf0e10cSrcweir 431cdf0e10cSrcweir if ( pImp->m_xLogRing.is() ) 432cdf0e10cSrcweir pImp->m_xLogRing->logString( aMessage ); 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir //------------------------------------------------------------------ 436cdf0e10cSrcweir void SfxMedium::SetError( sal_uInt32 nError, const ::rtl::OUString& aLogMessage ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir eError = nError; 439cdf0e10cSrcweir if ( eError != ERRCODE_NONE && aLogMessage.getLength() ) 440cdf0e10cSrcweir AddLog( aLogMessage ); 441cdf0e10cSrcweir } 442cdf0e10cSrcweir 443cdf0e10cSrcweir //------------------------------------------------------------------ 444cdf0e10cSrcweir sal_uInt32 SfxMedium::GetErrorCode() const 445cdf0e10cSrcweir { 446cdf0e10cSrcweir sal_uInt32 lError=eError; 447cdf0e10cSrcweir if(!lError && pInStream) 448cdf0e10cSrcweir lError=pInStream->GetErrorCode(); 449cdf0e10cSrcweir if(!lError && pOutStream) 450cdf0e10cSrcweir lError=pOutStream->GetErrorCode(); 451cdf0e10cSrcweir return lError; 452cdf0e10cSrcweir } 453cdf0e10cSrcweir 454cdf0e10cSrcweir //------------------------------------------------------------------ 455cdf0e10cSrcweir void SfxMedium::CheckFileDate( const util::DateTime& aInitDate ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir GetInitFileDate( sal_True ); 458cdf0e10cSrcweir if ( pImp->m_aDateTime.Seconds != aInitDate.Seconds 459cdf0e10cSrcweir || pImp->m_aDateTime.Minutes != aInitDate.Minutes 460cdf0e10cSrcweir || pImp->m_aDateTime.Hours != aInitDate.Hours 461cdf0e10cSrcweir || pImp->m_aDateTime.Day != aInitDate.Day 462cdf0e10cSrcweir || pImp->m_aDateTime.Month != aInitDate.Month 463cdf0e10cSrcweir || pImp->m_aDateTime.Year != aInitDate.Year ) 464cdf0e10cSrcweir { 465cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler(); 466cdf0e10cSrcweir 467cdf0e10cSrcweir if ( xHandler.is() ) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir try 470cdf0e10cSrcweir { 471cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionRequest > xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( 472cdf0e10cSrcweir document::ChangedByOthersRequest() ) ); 473cdf0e10cSrcweir uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 3 ); 474cdf0e10cSrcweir aContinuations[0] = new ::ucbhelper::InteractionAbort( xInteractionRequestImpl.get() ); 475cdf0e10cSrcweir aContinuations[1] = new ::ucbhelper::InteractionApprove( xInteractionRequestImpl.get() ); 476cdf0e10cSrcweir xInteractionRequestImpl->setContinuations( aContinuations ); 477cdf0e10cSrcweir 478cdf0e10cSrcweir xHandler->handle( xInteractionRequestImpl.get() ); 479cdf0e10cSrcweir 480cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xInteractionRequestImpl->getSelection(); 481cdf0e10cSrcweir if ( uno::Reference< task::XInteractionAbort >( xSelected.get(), uno::UNO_QUERY ).is() ) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 484cdf0e10cSrcweir } 485cdf0e10cSrcweir } 486cdf0e10cSrcweir catch ( uno::Exception& ) 487cdf0e10cSrcweir {} 488cdf0e10cSrcweir } 489cdf0e10cSrcweir } 490cdf0e10cSrcweir } 491cdf0e10cSrcweir 492cdf0e10cSrcweir //------------------------------------------------------------------ 493cdf0e10cSrcweir sal_Bool SfxMedium::DocNeedsFileDateCheck() 494cdf0e10cSrcweir { 4959c0c1533SAndrea Pescetti ::rtl::OUString aScheme = INetURLObject::GetScheme( GetURLObject().GetProtocol() ); 4969c0c1533SAndrea Pescetti sal_Bool bIsWebDAV = ( aScheme.equalsIgnoreAsciiCaseAscii( INET_HTTP_SCHEME ) || 4979c0c1533SAndrea Pescetti aScheme.equalsIgnoreAsciiCaseAscii( INET_HTTPS_SCHEME ) ); 4989c0c1533SAndrea Pescetti return ( !IsReadOnly() && 4999c0c1533SAndrea Pescetti ( ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) || bIsWebDAV ) ); 500cdf0e10cSrcweir } 501cdf0e10cSrcweir 502cdf0e10cSrcweir //------------------------------------------------------------------ 503cdf0e10cSrcweir util::DateTime SfxMedium::GetInitFileDate( sal_Bool bIgnoreOldValue ) 504cdf0e10cSrcweir { 505cdf0e10cSrcweir if ( ( bIgnoreOldValue || !pImp->m_bGotDateTime ) && aLogicName.Len() ) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir try 508cdf0e10cSrcweir { 509cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 510cdf0e10cSrcweir ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); 511cdf0e10cSrcweir 512cdf0e10cSrcweir aContent.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "DateModified" )) ) >>= pImp->m_aDateTime; 513cdf0e10cSrcweir pImp->m_bGotDateTime = sal_True; 514cdf0e10cSrcweir } 515cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir } 518cdf0e10cSrcweir } 519cdf0e10cSrcweir 520cdf0e10cSrcweir return pImp->m_aDateTime; 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir //------------------------------------------------------------------ 524cdf0e10cSrcweir Reference < XContent > SfxMedium::GetContent() const 525cdf0e10cSrcweir { 526cdf0e10cSrcweir if ( !pImp->aContent.get().is() ) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir Reference < ::com::sun::star::ucb::XContent > xContent; 529cdf0e10cSrcweir Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; 530cdf0e10cSrcweir 531cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pItem, SfxUnoAnyItem, SID_CONTENT, sal_False); 532cdf0e10cSrcweir if ( pItem ) 533cdf0e10cSrcweir pItem->GetValue() >>= xContent; 534cdf0e10cSrcweir 535cdf0e10cSrcweir if ( xContent.is() ) 536cdf0e10cSrcweir { 537cdf0e10cSrcweir try 538cdf0e10cSrcweir { 539cdf0e10cSrcweir pImp->aContent = ::ucbhelper::Content( xContent, xEnv ); 540cdf0e10cSrcweir } 541cdf0e10cSrcweir catch ( Exception& ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir } 544cdf0e10cSrcweir } 545cdf0e10cSrcweir else 546cdf0e10cSrcweir { 547cdf0e10cSrcweir // TODO: DBG_ERROR("SfxMedium::GetContent()\nCreate Content? This code exists as fallback only. Please clarify, why its used."); 548cdf0e10cSrcweir String aURL; 549cdf0e10cSrcweir if ( aName.Len() ) 550cdf0e10cSrcweir ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aURL ); 551cdf0e10cSrcweir else if ( aLogicName.Len() ) 552cdf0e10cSrcweir aURL = GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 553cdf0e10cSrcweir if ( aURL.Len() ) 554cdf0e10cSrcweir ::ucbhelper::Content::create( aURL, xEnv, pImp->aContent ); 555cdf0e10cSrcweir } 556cdf0e10cSrcweir } 557cdf0e10cSrcweir 558cdf0e10cSrcweir return pImp->aContent.get(); 559cdf0e10cSrcweir } 560cdf0e10cSrcweir 561cdf0e10cSrcweir //------------------------------------------------------------------ 562cdf0e10cSrcweir ::rtl::OUString SfxMedium::GetBaseURL( bool bForSaving ) 563cdf0e10cSrcweir { 564cdf0e10cSrcweir ::rtl::OUString aBaseURL; 565cdf0e10cSrcweir const SfxStringItem* pBaseURLItem = static_cast<const SfxStringItem*>( GetItemSet()->GetItem(SID_DOC_BASEURL) ); 566cdf0e10cSrcweir if ( pBaseURLItem ) 567cdf0e10cSrcweir aBaseURL = pBaseURLItem->GetValue(); 568cdf0e10cSrcweir else if ( GetContent().is() ) 569cdf0e10cSrcweir { 570cdf0e10cSrcweir try 571cdf0e10cSrcweir { 572cdf0e10cSrcweir Any aAny = pImp->aContent.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI" )) ); 573cdf0e10cSrcweir aAny >>= aBaseURL; 574cdf0e10cSrcweir } 575cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 576cdf0e10cSrcweir { 577cdf0e10cSrcweir } 578cdf0e10cSrcweir 579cdf0e10cSrcweir if ( !aBaseURL.getLength() ) 580cdf0e10cSrcweir aBaseURL = GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 581cdf0e10cSrcweir } 582cdf0e10cSrcweir 583cdf0e10cSrcweir if ( bForSaving ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir SvtSaveOptions aOpt; 586cdf0e10cSrcweir sal_Bool bIsRemote = IsRemote(); 587cdf0e10cSrcweir if( (bIsRemote && !aOpt.IsSaveRelINet()) || (!bRemote && !aOpt.IsSaveRelFSys()) ) 588cdf0e10cSrcweir return ::rtl::OUString(); 589cdf0e10cSrcweir } 590cdf0e10cSrcweir 591cdf0e10cSrcweir return aBaseURL; 592cdf0e10cSrcweir } 593cdf0e10cSrcweir 594cdf0e10cSrcweir //------------------------------------------------------------------ 595cdf0e10cSrcweir SvStream* SfxMedium::GetInStream() 596cdf0e10cSrcweir { 597cdf0e10cSrcweir if ( pInStream ) 5983b5992cdSOliver-Rainer Wittmann { 599cdf0e10cSrcweir return pInStream; 6003b5992cdSOliver-Rainer Wittmann } 601cdf0e10cSrcweir 602cdf0e10cSrcweir if ( pImp->pTempFile ) 603cdf0e10cSrcweir { 604cdf0e10cSrcweir pInStream = new SvFileStream( aName, nStorOpenMode ); 605cdf0e10cSrcweir 606cdf0e10cSrcweir eError = pInStream->GetError(); 607cdf0e10cSrcweir 608cdf0e10cSrcweir if( !eError && (nStorOpenMode & STREAM_WRITE) 609cdf0e10cSrcweir && ! pInStream->IsWritable() ) 610cdf0e10cSrcweir { 611cdf0e10cSrcweir eError = ERRCODE_IO_ACCESSDENIED; 612cdf0e10cSrcweir delete pInStream; 613cdf0e10cSrcweir pInStream = NULL; 614cdf0e10cSrcweir } 615cdf0e10cSrcweir else 6163b5992cdSOliver-Rainer Wittmann { 617cdf0e10cSrcweir return pInStream; 618cdf0e10cSrcweir } 6193b5992cdSOliver-Rainer Wittmann } 620cdf0e10cSrcweir 621cdf0e10cSrcweir GetMedium_Impl(); 622cdf0e10cSrcweir 623cdf0e10cSrcweir if ( GetError() ) 6243b5992cdSOliver-Rainer Wittmann { 625cdf0e10cSrcweir return NULL; 6263b5992cdSOliver-Rainer Wittmann } 627cdf0e10cSrcweir 628cdf0e10cSrcweir return pInStream; 629cdf0e10cSrcweir } 630cdf0e10cSrcweir 631cdf0e10cSrcweir //------------------------------------------------------------------ 632cdf0e10cSrcweir void SfxMedium::CloseInStream() 633cdf0e10cSrcweir { 634cdf0e10cSrcweir CloseInStream_Impl(); 635cdf0e10cSrcweir } 636cdf0e10cSrcweir 637cdf0e10cSrcweir void SfxMedium::CloseInStream_Impl() 638cdf0e10cSrcweir { 639cdf0e10cSrcweir // if there is a storage based on the InStream, we have to 640cdf0e10cSrcweir // close the storage, too, because otherwise the storage 641cdf0e10cSrcweir // would use an invalid ( deleted ) stream. 642cdf0e10cSrcweir if ( pInStream && pImp->xStorage.is() ) 643cdf0e10cSrcweir { 644cdf0e10cSrcweir if ( pImp->bStorageBasedOnInStream ) 645cdf0e10cSrcweir CloseStorage(); 646cdf0e10cSrcweir } 647cdf0e10cSrcweir 648cdf0e10cSrcweir if ( pInStream && !GetContent().is() ) 649cdf0e10cSrcweir { 650cdf0e10cSrcweir CreateTempFile( sal_True ); 651cdf0e10cSrcweir return; 652cdf0e10cSrcweir } 653cdf0e10cSrcweir 654cdf0e10cSrcweir DELETEZ( pInStream ); 655cdf0e10cSrcweir if ( pSet ) 656cdf0e10cSrcweir pSet->ClearItem( SID_INPUTSTREAM ); 657cdf0e10cSrcweir 658cdf0e10cSrcweir CloseZipStorage_Impl(); 659cdf0e10cSrcweir pImp->xInputStream = uno::Reference< io::XInputStream >(); 660cdf0e10cSrcweir 661cdf0e10cSrcweir if ( !pOutStream ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir // output part of the stream is not used so the whole stream can be closed 664cdf0e10cSrcweir // TODO/LATER: is it correct? 665cdf0e10cSrcweir pImp->xStream = uno::Reference< io::XStream >(); 666cdf0e10cSrcweir if ( pSet ) 667cdf0e10cSrcweir pSet->ClearItem( SID_STREAM ); 668cdf0e10cSrcweir } 669cdf0e10cSrcweir } 670cdf0e10cSrcweir 671cdf0e10cSrcweir //------------------------------------------------------------------ 672cdf0e10cSrcweir SvStream* SfxMedium::GetOutStream() 673cdf0e10cSrcweir { 674cdf0e10cSrcweir if ( !pOutStream ) 675cdf0e10cSrcweir { 676cdf0e10cSrcweir // Create a temp. file if there is none because we always 677cdf0e10cSrcweir // need one. 678cdf0e10cSrcweir CreateTempFile( sal_False ); 679cdf0e10cSrcweir 680cdf0e10cSrcweir if ( pImp->pTempFile ) 681cdf0e10cSrcweir { 682cdf0e10cSrcweir pOutStream = new SvFileStream( aName, STREAM_STD_READWRITE ); 683cdf0e10cSrcweir CloseStorage(); 684cdf0e10cSrcweir } 685cdf0e10cSrcweir } 686cdf0e10cSrcweir 687cdf0e10cSrcweir return pOutStream; 688cdf0e10cSrcweir } 689cdf0e10cSrcweir 690cdf0e10cSrcweir //------------------------------------------------------------------ 691cdf0e10cSrcweir sal_Bool SfxMedium::CloseOutStream() 692cdf0e10cSrcweir { 693cdf0e10cSrcweir CloseOutStream_Impl(); 694cdf0e10cSrcweir return sal_True; 695cdf0e10cSrcweir } 696cdf0e10cSrcweir 697cdf0e10cSrcweir sal_Bool SfxMedium::CloseOutStream_Impl() 698cdf0e10cSrcweir { 699cdf0e10cSrcweir if ( pOutStream ) 700cdf0e10cSrcweir { 701cdf0e10cSrcweir // if there is a storage based on the OutStream, we have to 702cdf0e10cSrcweir // close the storage, too, because otherwise the storage 703cdf0e10cSrcweir // would use an invalid ( deleted ) stream. 704cdf0e10cSrcweir //TODO/MBA: how to deal with this?! 705cdf0e10cSrcweir //maybe we need a new flag when the storage was created from the outstream 706cdf0e10cSrcweir if ( pImp->xStorage.is() ) 707cdf0e10cSrcweir { 708cdf0e10cSrcweir //const SvStream *pStorage = aStorage->GetSvStream(); 709cdf0e10cSrcweir //if ( pStorage == pOutStream ) 710cdf0e10cSrcweir CloseStorage(); 711cdf0e10cSrcweir } 712cdf0e10cSrcweir 713cdf0e10cSrcweir delete pOutStream; 714cdf0e10cSrcweir pOutStream = NULL; 715cdf0e10cSrcweir } 716cdf0e10cSrcweir 717cdf0e10cSrcweir if ( !pInStream ) 718cdf0e10cSrcweir { 719cdf0e10cSrcweir // input part of the stream is not used so the whole stream can be closed 720cdf0e10cSrcweir // TODO/LATER: is it correct? 721cdf0e10cSrcweir pImp->xStream = uno::Reference< io::XStream >(); 722cdf0e10cSrcweir if ( pSet ) 723cdf0e10cSrcweir pSet->ClearItem( SID_STREAM ); 724cdf0e10cSrcweir } 725cdf0e10cSrcweir 726cdf0e10cSrcweir return sal_True; 727cdf0e10cSrcweir } 728cdf0e10cSrcweir 729cdf0e10cSrcweir //------------------------------------------------------------------ 730cdf0e10cSrcweir const String& SfxMedium::GetPhysicalName() const 731cdf0e10cSrcweir { 732cdf0e10cSrcweir if ( !aName.Len() && aLogicName.Len() ) 733cdf0e10cSrcweir (( SfxMedium*)this)->CreateFileStream(); 734cdf0e10cSrcweir 735cdf0e10cSrcweir // return the name then 736cdf0e10cSrcweir return aName; 737cdf0e10cSrcweir } 738cdf0e10cSrcweir 739cdf0e10cSrcweir //------------------------------------------------------------------ 740cdf0e10cSrcweir void SfxMedium::CreateFileStream() 741cdf0e10cSrcweir { 742cdf0e10cSrcweir ForceSynchronStream_Impl( sal_True ); 743cdf0e10cSrcweir GetInStream(); 744cdf0e10cSrcweir if( pInStream ) 745cdf0e10cSrcweir { 746cdf0e10cSrcweir CreateTempFile( sal_False ); 747cdf0e10cSrcweir pImp->bIsTemp = sal_True; 748cdf0e10cSrcweir CloseInStream_Impl(); 749cdf0e10cSrcweir } 750cdf0e10cSrcweir } 751cdf0e10cSrcweir 752cdf0e10cSrcweir //------------------------------------------------------------------ 753cdf0e10cSrcweir sal_Bool SfxMedium::Commit() 754cdf0e10cSrcweir { 755cdf0e10cSrcweir if( pImp->xStorage.is() ) 756cdf0e10cSrcweir StorageCommit_Impl(); 757cdf0e10cSrcweir else if( pOutStream ) 758cdf0e10cSrcweir pOutStream->Flush(); 759cdf0e10cSrcweir else if( pInStream ) 760cdf0e10cSrcweir pInStream->Flush(); 761cdf0e10cSrcweir 762cdf0e10cSrcweir if ( GetError() == SVSTREAM_OK ) 763cdf0e10cSrcweir { 764cdf0e10cSrcweir // does something only in case there is a temporary file ( means aName points to different location than aLogicName ) 765cdf0e10cSrcweir Transfer_Impl(); 766cdf0e10cSrcweir } 767cdf0e10cSrcweir 768cdf0e10cSrcweir sal_Bool bResult = ( GetError() == SVSTREAM_OK ); 769cdf0e10cSrcweir 770cdf0e10cSrcweir if ( bResult && DocNeedsFileDateCheck() ) 771cdf0e10cSrcweir GetInitFileDate( sal_True ); 772cdf0e10cSrcweir 773cdf0e10cSrcweir // remove truncation mode from the flags 774cdf0e10cSrcweir nStorOpenMode &= (~STREAM_TRUNC); 775cdf0e10cSrcweir return bResult; 776cdf0e10cSrcweir } 777cdf0e10cSrcweir 778cdf0e10cSrcweir //------------------------------------------------------------------ 779cdf0e10cSrcweir sal_Bool SfxMedium::IsStorage() 780cdf0e10cSrcweir { 781cdf0e10cSrcweir if ( pImp->xStorage.is() ) 782cdf0e10cSrcweir return sal_True; 783cdf0e10cSrcweir 784cdf0e10cSrcweir if ( bTriedStorage ) 785cdf0e10cSrcweir return pImp->bIsStorage; 786cdf0e10cSrcweir 787cdf0e10cSrcweir if ( pImp->pTempFile ) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir String aURL; 790cdf0e10cSrcweir if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aURL ) ) 791cdf0e10cSrcweir { 792cdf0e10cSrcweir DBG_ERROR("Physical name not convertable!"); 793cdf0e10cSrcweir } 794cdf0e10cSrcweir pImp->bIsStorage = SotStorage::IsStorageFile( aURL ) && !SotStorage::IsOLEStorage( aURL); 795cdf0e10cSrcweir if ( !pImp->bIsStorage ) 796cdf0e10cSrcweir bTriedStorage = sal_True; 797cdf0e10cSrcweir } 798cdf0e10cSrcweir else if ( GetInStream() ) 799cdf0e10cSrcweir { 800cdf0e10cSrcweir pImp->bIsStorage = SotStorage::IsStorageFile( pInStream ) && !SotStorage::IsOLEStorage( pInStream ); 801cdf0e10cSrcweir if ( !pInStream->GetError() && !pImp->bIsStorage ) 802cdf0e10cSrcweir bTriedStorage = sal_True; 803cdf0e10cSrcweir } 804cdf0e10cSrcweir 805cdf0e10cSrcweir return pImp->bIsStorage; 806cdf0e10cSrcweir } 807cdf0e10cSrcweir 808cdf0e10cSrcweir //------------------------------------------------------------------ 809cdf0e10cSrcweir Link SfxMedium::GetDataAvailableLink() const 810cdf0e10cSrcweir { 811cdf0e10cSrcweir return pImp->aAvailableLink.GetLink(); 812cdf0e10cSrcweir } 813cdf0e10cSrcweir 814cdf0e10cSrcweir //------------------------------------------------------------------ 815cdf0e10cSrcweir Link SfxMedium::GetDoneLink() const 816cdf0e10cSrcweir { 817cdf0e10cSrcweir return pImp->aDoneLink.GetLink(); 818cdf0e10cSrcweir } 819cdf0e10cSrcweir 820cdf0e10cSrcweir //------------------------------------------------------------------ 821cdf0e10cSrcweir sal_Bool SfxMedium::IsPreview_Impl() 822cdf0e10cSrcweir { 823cdf0e10cSrcweir sal_Bool bPreview = sal_False; 824cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pPreview, SfxBoolItem, SID_PREVIEW, sal_False); 825cdf0e10cSrcweir if ( pPreview ) 826cdf0e10cSrcweir bPreview = pPreview->GetValue(); 827cdf0e10cSrcweir else 828cdf0e10cSrcweir { 829cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False); 830cdf0e10cSrcweir if ( pFlags ) 831cdf0e10cSrcweir { 832cdf0e10cSrcweir String aFileFlags = pFlags->GetValue(); 833cdf0e10cSrcweir aFileFlags.ToUpperAscii(); 834cdf0e10cSrcweir if ( STRING_NOTFOUND != aFileFlags.Search( 'B' ) ) 835cdf0e10cSrcweir bPreview = sal_True; 836cdf0e10cSrcweir } 837cdf0e10cSrcweir } 838cdf0e10cSrcweir 839cdf0e10cSrcweir return bPreview; 840cdf0e10cSrcweir } 841cdf0e10cSrcweir 842cdf0e10cSrcweir //------------------------------------------------------------------ 843cdf0e10cSrcweir void SfxMedium::StorageBackup_Impl() 844cdf0e10cSrcweir { 845cdf0e10cSrcweir ::ucbhelper::Content aOriginalContent; 846cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 847cdf0e10cSrcweir 848cdf0e10cSrcweir sal_Bool bBasedOnOriginalFile = ( !pImp->pTempFile && !( aLogicName.Len() && pImp->m_bSalvageMode ) 849cdf0e10cSrcweir && GetURLObject().GetMainURL( INetURLObject::NO_DECODE ).getLength() 850cdf0e10cSrcweir && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) 851cdf0e10cSrcweir && ::utl::UCBContentHelper::IsDocument( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ); 852cdf0e10cSrcweir 853cdf0e10cSrcweir if ( bBasedOnOriginalFile && !pImp->m_aBackupURL.getLength() 854cdf0e10cSrcweir && ::ucbhelper::Content::create( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, aOriginalContent ) ) 855cdf0e10cSrcweir { 856cdf0e10cSrcweir DoInternalBackup_Impl( aOriginalContent ); 857cdf0e10cSrcweir if( !pImp->m_aBackupURL.getLength() ) 858cdf0e10cSrcweir SetError( ERRCODE_SFX_CANTCREATEBACKUP, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 859cdf0e10cSrcweir } 860cdf0e10cSrcweir } 861cdf0e10cSrcweir 862cdf0e10cSrcweir //------------------------------------------------------------------ 863cdf0e10cSrcweir ::rtl::OUString SfxMedium::GetBackup_Impl() 864cdf0e10cSrcweir { 865cdf0e10cSrcweir if ( !pImp->m_aBackupURL.getLength() ) 866cdf0e10cSrcweir StorageBackup_Impl(); 867cdf0e10cSrcweir 868cdf0e10cSrcweir return pImp->m_aBackupURL; 869cdf0e10cSrcweir } 870cdf0e10cSrcweir 871cdf0e10cSrcweir //------------------------------------------------------------------ 872cdf0e10cSrcweir uno::Reference < embed::XStorage > SfxMedium::GetOutputStorage() 873cdf0e10cSrcweir { 874cdf0e10cSrcweir if ( GetError() ) 875cdf0e10cSrcweir return uno::Reference< embed::XStorage >(); 876cdf0e10cSrcweir 877cdf0e10cSrcweir // if the medium was constructed with a Storage: use this one, not a temp. storage 878cdf0e10cSrcweir // if a temporary storage already exists: use it 879cdf0e10cSrcweir if ( pImp->xStorage.is() && ( !aLogicName.Len() || pImp->pTempFile ) ) 880cdf0e10cSrcweir return pImp->xStorage; 881cdf0e10cSrcweir 882cdf0e10cSrcweir // if necessary close stream that was used for reading 883cdf0e10cSrcweir if ( pInStream && !pInStream->IsWritable() ) 884cdf0e10cSrcweir CloseInStream(); 885cdf0e10cSrcweir 886cdf0e10cSrcweir DBG_ASSERT( !pOutStream, "OutStream in a readonly Medium?!" ); 887cdf0e10cSrcweir 888cdf0e10cSrcweir // TODO/LATER: The current solution is to store the document temporary and then copy it to the target location; 889cdf0e10cSrcweir // in future it should be stored directly and then copied to the temporary location, since in this case no 890cdf0e10cSrcweir // file attributes have to be preserved and system copying mechanics could be used instead of streaming. 891cdf0e10cSrcweir CreateTempFileNoCopy(); 892cdf0e10cSrcweir 893cdf0e10cSrcweir return GetStorage(); 894cdf0e10cSrcweir } 895cdf0e10cSrcweir 896cdf0e10cSrcweir //------------------------------------------------------------------ 897cdf0e10cSrcweir void SfxMedium::SetEncryptionDataToStorage_Impl() 898cdf0e10cSrcweir { 899cdf0e10cSrcweir // in case media-descriptor contains password it should be used on opening 900cdf0e10cSrcweir if ( pImp->xStorage.is() && pSet ) 901cdf0e10cSrcweir { 902cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aEncryptionData; 903cdf0e10cSrcweir if ( GetEncryptionData_Impl( pSet, aEncryptionData ) ) 904cdf0e10cSrcweir { 905cdf0e10cSrcweir // replace the password with encryption data 906cdf0e10cSrcweir pSet->ClearItem( SID_PASSWORD ); 907cdf0e10cSrcweir pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aEncryptionData ) ) ); 908cdf0e10cSrcweir 909cdf0e10cSrcweir try 910cdf0e10cSrcweir { 911cdf0e10cSrcweir ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( pImp->xStorage, aEncryptionData ); 912cdf0e10cSrcweir } 913cdf0e10cSrcweir catch( uno::Exception& ) 914cdf0e10cSrcweir { 915cdf0e10cSrcweir OSL_ENSURE( sal_False, "It must be possible to set a common password for the storage" ); 916cdf0e10cSrcweir // TODO/LATER: set the error code in case of problem 917cdf0e10cSrcweir // SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 918cdf0e10cSrcweir } 919cdf0e10cSrcweir } 920cdf0e10cSrcweir } 921cdf0e10cSrcweir } 922cdf0e10cSrcweir 9239c0c1533SAndrea Pescetti //->i126305 ----------------------------------------------------------------- 9249c0c1533SAndrea Pescetti //for the time being the aData holds a single OUString, the owner of the lock 9259c0c1533SAndrea Pescetti sal_Int8 SfxMedium::ShowLockedWebDAVDocumentDialog( const uno::Sequence< ::rtl::OUString >& aData, sal_Bool bIsLoading ) 9269c0c1533SAndrea Pescetti { 9279c0c1533SAndrea Pescetti sal_Int8 nResult = LOCK_UI_NOLOCK; 9289c0c1533SAndrea Pescetti 9299c0c1533SAndrea Pescetti // show the interaction regarding the document opening 9309c0c1533SAndrea Pescetti uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler(); 9319c0c1533SAndrea Pescetti 9329c0c1533SAndrea Pescetti if ( ::svt::DocumentLockFile::IsInteractionAllowed() && xHandler.is() && bIsLoading ) 9339c0c1533SAndrea Pescetti { 9349c0c1533SAndrea Pescetti ::rtl::OUString aDocumentURL = GetURLObject().GetLastName(); 9359c0c1533SAndrea Pescetti ::rtl::OUString aInfo; 9369c0c1533SAndrea Pescetti ::rtl::Reference< ::ucbhelper::InteractionRequest > xInteractionRequestImpl; 9379c0c1533SAndrea Pescetti 9389c0c1533SAndrea Pescetti aInfo = aData[0]; 9399c0c1533SAndrea Pescetti if(aData.getLength() > 1 && aData[1].getLength() > 0) 9409c0c1533SAndrea Pescetti { 9419c0c1533SAndrea Pescetti aInfo += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\n\n" ) ); 9429c0c1533SAndrea Pescetti aInfo += aData[1]; 9439c0c1533SAndrea Pescetti } 9449c0c1533SAndrea Pescetti 9459c0c1533SAndrea Pescetti if ( bIsLoading ) 9469c0c1533SAndrea Pescetti { 9479c0c1533SAndrea Pescetti xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( 9489c0c1533SAndrea Pescetti uno::makeAny( document::LockedDocumentRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) ); 9499c0c1533SAndrea Pescetti } 9509c0c1533SAndrea Pescetti else 9519c0c1533SAndrea Pescetti { 9529c0c1533SAndrea Pescetti xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( 9539c0c1533SAndrea Pescetti uno::makeAny( document::LockedOnSavingRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) ); 9549c0c1533SAndrea Pescetti } 9559c0c1533SAndrea Pescetti 9569c0c1533SAndrea Pescetti uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 3 ); 9579c0c1533SAndrea Pescetti aContinuations[0] = new ::ucbhelper::InteractionAbort( xInteractionRequestImpl.get() ); 9589c0c1533SAndrea Pescetti aContinuations[1] = new ::ucbhelper::InteractionApprove( xInteractionRequestImpl.get() ); 9599c0c1533SAndrea Pescetti aContinuations[2] = new ::ucbhelper::InteractionDisapprove( xInteractionRequestImpl.get() ); 9609c0c1533SAndrea Pescetti xInteractionRequestImpl->setContinuations( aContinuations ); 9619c0c1533SAndrea Pescetti 9629c0c1533SAndrea Pescetti xHandler->handle( xInteractionRequestImpl.get() ); 9639c0c1533SAndrea Pescetti 9649c0c1533SAndrea Pescetti ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xInteractionRequestImpl->getSelection(); 9659c0c1533SAndrea Pescetti if ( uno::Reference< task::XInteractionAbort >( xSelected.get(), uno::UNO_QUERY ).is() ) 9669c0c1533SAndrea Pescetti { 9679c0c1533SAndrea Pescetti SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 9689c0c1533SAndrea Pescetti } 9699c0c1533SAndrea Pescetti else if ( uno::Reference< task::XInteractionDisapprove >( xSelected.get(), uno::UNO_QUERY ).is() ) 9709c0c1533SAndrea Pescetti { 9719c0c1533SAndrea Pescetti // alien lock on loading, user has selected to edit a copy of document 9729c0c1533SAndrea Pescetti // TODO/LATER: alien lock on saving, user has selected to do SaveAs to different location 9739c0c1533SAndrea Pescetti // means that a copy of the document should be opened 9749c0c1533SAndrea Pescetti GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); 9759c0c1533SAndrea Pescetti } 9769c0c1533SAndrea Pescetti else // if ( XSelected == aContinuations[1] ) 9779c0c1533SAndrea Pescetti { 9789c0c1533SAndrea Pescetti // alien lock on loading, user has selected to retry saving 9799c0c1533SAndrea Pescetti // TODO/LATER: alien lock on saving, user has selected to retry saving 9809c0c1533SAndrea Pescetti if ( bIsLoading ) 9819c0c1533SAndrea Pescetti GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 9829c0c1533SAndrea Pescetti else 9839c0c1533SAndrea Pescetti nResult = LOCK_UI_TRY; 9849c0c1533SAndrea Pescetti } 9859c0c1533SAndrea Pescetti } 9869c0c1533SAndrea Pescetti else 9879c0c1533SAndrea Pescetti { 9889c0c1533SAndrea Pescetti if ( bIsLoading ) 9899c0c1533SAndrea Pescetti { 9909c0c1533SAndrea Pescetti // if no interaction handler is provided the default answer is open readonly 9919c0c1533SAndrea Pescetti // that usually happens in case the document is loaded per API 9929c0c1533SAndrea Pescetti // so the document must be opened readonly for backward compatibility 9939c0c1533SAndrea Pescetti GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 9949c0c1533SAndrea Pescetti } 9959c0c1533SAndrea Pescetti else 9969c0c1533SAndrea Pescetti SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 9979c0c1533SAndrea Pescetti } 9989c0c1533SAndrea Pescetti 9999c0c1533SAndrea Pescetti return nResult; 10009c0c1533SAndrea Pescetti } 10019c0c1533SAndrea Pescetti //<-i126305 10029c0c1533SAndrea Pescetti 1003cdf0e10cSrcweir //------------------------------------------------------------------ 1004cdf0e10cSrcweir sal_Int8 SfxMedium::ShowLockedDocumentDialog( const uno::Sequence< ::rtl::OUString >& aData, sal_Bool bIsLoading, sal_Bool bOwnLock ) 1005cdf0e10cSrcweir { 1006cdf0e10cSrcweir sal_Int8 nResult = LOCK_UI_NOLOCK; 1007cdf0e10cSrcweir 1008cdf0e10cSrcweir // show the interaction regarding the document opening 1009cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler(); 1010cdf0e10cSrcweir 1011cdf0e10cSrcweir if ( ::svt::DocumentLockFile::IsInteractionAllowed() && xHandler.is() && ( bIsLoading || bOwnLock ) ) 1012cdf0e10cSrcweir { 1013cdf0e10cSrcweir ::rtl::OUString aDocumentURL = GetURLObject().GetLastName(); 1014cdf0e10cSrcweir ::rtl::OUString aInfo; 1015cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionRequest > xInteractionRequestImpl; 1016cdf0e10cSrcweir 1017cdf0e10cSrcweir if ( bOwnLock ) 1018cdf0e10cSrcweir { 1019cdf0e10cSrcweir if ( aData.getLength() > LOCKFILE_EDITTIME_ID ) 1020cdf0e10cSrcweir aInfo = aData[LOCKFILE_EDITTIME_ID]; 1021cdf0e10cSrcweir 1022cdf0e10cSrcweir xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( 1023cdf0e10cSrcweir document::OwnLockOnDocumentRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo, !bIsLoading ) ) ); 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir else 1026cdf0e10cSrcweir { 1027cdf0e10cSrcweir if ( aData.getLength() > LOCKFILE_EDITTIME_ID ) 1028cdf0e10cSrcweir { 1029cdf0e10cSrcweir if ( aData[LOCKFILE_OOOUSERNAME_ID].getLength() ) 1030cdf0e10cSrcweir aInfo = aData[LOCKFILE_OOOUSERNAME_ID]; 1031cdf0e10cSrcweir else 1032cdf0e10cSrcweir aInfo = aData[LOCKFILE_SYSUSERNAME_ID]; 1033cdf0e10cSrcweir 1034cdf0e10cSrcweir if ( aInfo.getLength() && aData[LOCKFILE_EDITTIME_ID].getLength() ) 1035cdf0e10cSrcweir { 1036cdf0e10cSrcweir aInfo += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " ( " ) ); 1037cdf0e10cSrcweir aInfo += aData[LOCKFILE_EDITTIME_ID]; 1038cdf0e10cSrcweir aInfo += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " )" ) ); 1039cdf0e10cSrcweir } 1040cdf0e10cSrcweir } 1041cdf0e10cSrcweir 1042cdf0e10cSrcweir if ( bIsLoading ) 1043cdf0e10cSrcweir { 1044cdf0e10cSrcweir xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( 1045cdf0e10cSrcweir document::LockedDocumentRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) ); 1046cdf0e10cSrcweir } 1047cdf0e10cSrcweir else 1048cdf0e10cSrcweir { 1049cdf0e10cSrcweir xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( 1050cdf0e10cSrcweir document::LockedOnSavingRequest( ::rtl::OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) ); 1051cdf0e10cSrcweir 1052cdf0e10cSrcweir } 1053cdf0e10cSrcweir } 1054cdf0e10cSrcweir 1055cdf0e10cSrcweir uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 3 ); 1056cdf0e10cSrcweir aContinuations[0] = new ::ucbhelper::InteractionAbort( xInteractionRequestImpl.get() ); 1057cdf0e10cSrcweir aContinuations[1] = new ::ucbhelper::InteractionApprove( xInteractionRequestImpl.get() ); 1058cdf0e10cSrcweir aContinuations[2] = new ::ucbhelper::InteractionDisapprove( xInteractionRequestImpl.get() ); 1059cdf0e10cSrcweir xInteractionRequestImpl->setContinuations( aContinuations ); 1060cdf0e10cSrcweir 1061cdf0e10cSrcweir xHandler->handle( xInteractionRequestImpl.get() ); 1062cdf0e10cSrcweir 1063cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xInteractionRequestImpl->getSelection(); 1064cdf0e10cSrcweir if ( uno::Reference< task::XInteractionAbort >( xSelected.get(), uno::UNO_QUERY ).is() ) 1065cdf0e10cSrcweir { 1066cdf0e10cSrcweir SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1067cdf0e10cSrcweir } 1068cdf0e10cSrcweir else if ( uno::Reference< task::XInteractionDisapprove >( xSelected.get(), uno::UNO_QUERY ).is() ) 1069cdf0e10cSrcweir { 1070cdf0e10cSrcweir // own lock on loading, user has selected to ignore the lock 1071cdf0e10cSrcweir // own lock on saving, user has selected to ignore the lock 1072cdf0e10cSrcweir // alien lock on loading, user has selected to edit a copy of document 1073cdf0e10cSrcweir // TODO/LATER: alien lock on saving, user has selected to do SaveAs to different location 1074cdf0e10cSrcweir if ( bIsLoading && !bOwnLock ) 1075cdf0e10cSrcweir { 1076cdf0e10cSrcweir // means that a copy of the document should be opened 1077cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); 1078cdf0e10cSrcweir } 1079cdf0e10cSrcweir else if ( bOwnLock ) 1080cdf0e10cSrcweir nResult = LOCK_UI_SUCCEEDED; 1081cdf0e10cSrcweir } 1082cdf0e10cSrcweir else // if ( XSelected == aContinuations[1] ) 1083cdf0e10cSrcweir { 1084cdf0e10cSrcweir // own lock on loading, user has selected to open readonly 1085cdf0e10cSrcweir // own lock on saving, user has selected to open readonly 1086cdf0e10cSrcweir // alien lock on loading, user has selected to retry saving 1087cdf0e10cSrcweir // TODO/LATER: alien lock on saving, user has selected to retry saving 1088cdf0e10cSrcweir 1089cdf0e10cSrcweir if ( bIsLoading ) 1090cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 1091cdf0e10cSrcweir else 1092cdf0e10cSrcweir nResult = LOCK_UI_TRY; 1093cdf0e10cSrcweir } 1094cdf0e10cSrcweir } 1095cdf0e10cSrcweir else 1096cdf0e10cSrcweir { 1097cdf0e10cSrcweir if ( bIsLoading ) 1098cdf0e10cSrcweir { 1099cdf0e10cSrcweir // if no interaction handler is provided the default answer is open readonly 1100cdf0e10cSrcweir // that usually happens in case the document is loaded per API 1101cdf0e10cSrcweir // so the document must be opened readonly for backward compatibility 1102cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 1103cdf0e10cSrcweir } 1104cdf0e10cSrcweir else 1105cdf0e10cSrcweir SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir } 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir return nResult; 1110cdf0e10cSrcweir } 1111cdf0e10cSrcweir 1112cdf0e10cSrcweir //------------------------------------------------------------------ 1113cdf0e10cSrcweir sal_Bool SfxMedium::LockOrigFileOnDemand( sal_Bool bLoading, sal_Bool bNoUI ) 1114cdf0e10cSrcweir { 1115cdf0e10cSrcweir // returns true if the document can be opened for editing ( even if it should be a copy ) 1116cdf0e10cSrcweir // otherwise the document should be opened readonly 1117cdf0e10cSrcweir // if user cancel the loading the ERROR_ABORT is set 1118cdf0e10cSrcweir 1119cdf0e10cSrcweir if ( pImp->m_bLocked && bLoading && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) 1120cdf0e10cSrcweir { 1121cdf0e10cSrcweir // if the document is already locked the system locking might be temporarely off after storing 1122cdf0e10cSrcweir // check whether the system file locking should be taken again 1123cdf0e10cSrcweir GetLockingStream_Impl(); 1124cdf0e10cSrcweir } 1125cdf0e10cSrcweir 1126cdf0e10cSrcweir sal_Bool bResult = pImp->m_bLocked; 1127cdf0e10cSrcweir 1128cdf0e10cSrcweir if ( !bResult ) 1129cdf0e10cSrcweir { 1130cdf0e10cSrcweir // no read-write access is necessary on loading if the document is explicitly opened as copy 1131cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False); 1132cdf0e10cSrcweir bResult = ( bLoading && pTemplateItem && pTemplateItem->GetValue() ); 1133cdf0e10cSrcweir } 1134cdf0e10cSrcweir 1135cdf0e10cSrcweir if ( !bResult && !IsReadOnly() ) 1136cdf0e10cSrcweir { 1137cdf0e10cSrcweir sal_Bool bContentReadonly = sal_False; 1138cdf0e10cSrcweir if ( bLoading && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) 1139cdf0e10cSrcweir { 1140cdf0e10cSrcweir // let the original document be opened to check the possibility to open it for editing 1141cdf0e10cSrcweir // and to let the writable stream stay open to hold the lock on the document 1142cdf0e10cSrcweir GetLockingStream_Impl(); 1143cdf0e10cSrcweir } 1144cdf0e10cSrcweir 1145cdf0e10cSrcweir // "IsReadOnly" property does not allow to detect whether the file is readonly always 1146cdf0e10cSrcweir // so we try always to open the file for editing 1147cdf0e10cSrcweir // the file is readonly only in case the read-write stream can not be opened 1148cdf0e10cSrcweir if ( bLoading && !pImp->m_xLockingStream.is() ) 1149cdf0e10cSrcweir { 1150cdf0e10cSrcweir try 1151cdf0e10cSrcweir { 1152cdf0e10cSrcweir // MediaDescriptor does this check also, the duplication should be avoided in future 1153cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 1154cdf0e10cSrcweir ::ucbhelper::Content aContent( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); 1155cdf0e10cSrcweir aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bContentReadonly; 1156cdf0e10cSrcweir } 1157cdf0e10cSrcweir catch( uno::Exception ) 1158cdf0e10cSrcweir {} 1159cdf0e10cSrcweir 1160cdf0e10cSrcweir if ( !bContentReadonly ) 1161cdf0e10cSrcweir { 1162cdf0e10cSrcweir // the file is not readonly, check the ACL 1163cdf0e10cSrcweir 1164cdf0e10cSrcweir String aPhysPath; 1165cdf0e10cSrcweir if ( ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), aPhysPath ) ) 1166cdf0e10cSrcweir bContentReadonly = IsReadonlyAccordingACL( aPhysPath.GetBuffer() ); 1167cdf0e10cSrcweir } 1168cdf0e10cSrcweir } 1169cdf0e10cSrcweir 1170cdf0e10cSrcweir // do further checks only if the file not readonly in fs 1171cdf0e10cSrcweir if ( !bContentReadonly ) 1172cdf0e10cSrcweir { 1173cdf0e10cSrcweir // the special file locking should be used only for file URLs 1174cdf0e10cSrcweir if ( ::utl::LocalFileHelper::IsLocalFile( aLogicName ) ) 1175cdf0e10cSrcweir { 1176cdf0e10cSrcweir 1177cdf0e10cSrcweir // in case of storing the document should request the output before locking 1178cdf0e10cSrcweir if ( bLoading ) 1179cdf0e10cSrcweir { 1180cdf0e10cSrcweir // let the stream be opened to check the system file locking 1181cdf0e10cSrcweir GetMedium_Impl(); 1182cdf0e10cSrcweir } 1183cdf0e10cSrcweir 1184cdf0e10cSrcweir sal_Int8 bUIStatus = LOCK_UI_NOLOCK; 1185cdf0e10cSrcweir 1186cdf0e10cSrcweir // check whether system file locking has been used, the default value is false 1187cdf0e10cSrcweir sal_Bool bUseSystemLock = IsSystemFileLockingUsed(); 1188cdf0e10cSrcweir 1189cdf0e10cSrcweir // TODO/LATER: This implementation does not allow to detect the system lock on saving here, actually this is no big problem 1190cdf0e10cSrcweir // if system lock is used the writeable stream should be available 1191cdf0e10cSrcweir sal_Bool bHandleSysLocked = ( bLoading && bUseSystemLock && !pImp->xStream.is() && !pOutStream ); 1192cdf0e10cSrcweir 1193cdf0e10cSrcweir do 1194cdf0e10cSrcweir { 1195cdf0e10cSrcweir try 1196cdf0e10cSrcweir { 1197cdf0e10cSrcweir ::svt::DocumentLockFile aLockFile( aLogicName ); 1198cdf0e10cSrcweir if ( !bHandleSysLocked ) 1199cdf0e10cSrcweir { 1200cdf0e10cSrcweir try 1201cdf0e10cSrcweir { 1202cdf0e10cSrcweir bResult = aLockFile.CreateOwnLockFile(); 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir catch ( ucb::InteractiveIOException& e ) 1205cdf0e10cSrcweir { 1206*30acf5e8Spfg // exception means that the lock file can not be successfully accessed 1207cdf0e10cSrcweir // in this case it should be ignored if system file locking is anyway active 1208cdf0e10cSrcweir if ( bUseSystemLock || !IsOOoLockFileUsed() ) 1209cdf0e10cSrcweir { 1210cdf0e10cSrcweir bResult = sal_True; 1211cdf0e10cSrcweir // take the ownership over the lock file 1212cdf0e10cSrcweir aLockFile.OverwriteOwnLockFile(); 1213cdf0e10cSrcweir } 1214cdf0e10cSrcweir else if ( e.Code == IOErrorCode_INVALID_PARAMETER ) 1215cdf0e10cSrcweir { 1216cdf0e10cSrcweir // system file locking is not active, ask user whether he wants to open the document without any locking 1217cdf0e10cSrcweir uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler(); 1218cdf0e10cSrcweir 1219cdf0e10cSrcweir if ( xHandler.is() ) 1220cdf0e10cSrcweir { 1221cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionRequest > xIgnoreRequestImpl 1222cdf0e10cSrcweir = new ::ucbhelper::InteractionRequest( uno::makeAny( document::LockFileIgnoreRequest() ) ); 1223cdf0e10cSrcweir 1224cdf0e10cSrcweir uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 2 ); 1225cdf0e10cSrcweir aContinuations[0] = new ::ucbhelper::InteractionAbort( xIgnoreRequestImpl.get() ); 1226cdf0e10cSrcweir aContinuations[1] = new ::ucbhelper::InteractionApprove( xIgnoreRequestImpl.get() ); 1227cdf0e10cSrcweir xIgnoreRequestImpl->setContinuations( aContinuations ); 1228cdf0e10cSrcweir 1229cdf0e10cSrcweir xHandler->handle( xIgnoreRequestImpl.get() ); 1230cdf0e10cSrcweir 1231cdf0e10cSrcweir ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xIgnoreRequestImpl->getSelection(); 1232cdf0e10cSrcweir bResult = ( uno::Reference< task::XInteractionApprove >( xSelected.get(), uno::UNO_QUERY ).is() ); 1233cdf0e10cSrcweir } 1234cdf0e10cSrcweir } 1235cdf0e10cSrcweir } 1236cdf0e10cSrcweir catch ( uno::Exception& ) 1237cdf0e10cSrcweir { 1238*30acf5e8Spfg // exception means that the lock file can not be successfully accessed 1239cdf0e10cSrcweir // in this case it should be ignored if system file locking is anyway active 1240cdf0e10cSrcweir if ( bUseSystemLock || !IsOOoLockFileUsed() ) 1241cdf0e10cSrcweir { 1242cdf0e10cSrcweir bResult = sal_True; 1243cdf0e10cSrcweir // take the ownership over the lock file 1244cdf0e10cSrcweir aLockFile.OverwriteOwnLockFile(); 1245cdf0e10cSrcweir } 1246cdf0e10cSrcweir } 1247cdf0e10cSrcweir 1248cdf0e10cSrcweir // in case OOo locking is turned off the lock file is still written if possible 1249cdf0e10cSrcweir // but it is ignored while deciding whether the document should be opened for editing or not 1250cdf0e10cSrcweir if ( !bResult && !IsOOoLockFileUsed() ) 1251cdf0e10cSrcweir { 1252cdf0e10cSrcweir bResult = sal_True; 1253cdf0e10cSrcweir // take the ownership over the lock file 1254cdf0e10cSrcweir aLockFile.OverwriteOwnLockFile(); 1255cdf0e10cSrcweir } 1256cdf0e10cSrcweir } 1257cdf0e10cSrcweir 1258cdf0e10cSrcweir 1259cdf0e10cSrcweir if ( !bResult ) 1260cdf0e10cSrcweir { 1261cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aData; 1262cdf0e10cSrcweir try 1263cdf0e10cSrcweir { 1264cdf0e10cSrcweir // impossibility to get data is no real problem 1265cdf0e10cSrcweir aData = aLockFile.GetLockData(); 1266cdf0e10cSrcweir } 1267cdf0e10cSrcweir catch( uno::Exception ) {} 1268cdf0e10cSrcweir 1269cdf0e10cSrcweir sal_Bool bOwnLock = sal_False; 1270cdf0e10cSrcweir 1271cdf0e10cSrcweir if ( !bHandleSysLocked ) 1272cdf0e10cSrcweir { 1273cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aOwnData = aLockFile.GenerateOwnEntry(); 1274cdf0e10cSrcweir bOwnLock = ( aData.getLength() > LOCKFILE_USERURL_ID 1275cdf0e10cSrcweir && aOwnData.getLength() > LOCKFILE_USERURL_ID 1276cdf0e10cSrcweir && aOwnData[LOCKFILE_SYSUSERNAME_ID].equals( aData[LOCKFILE_SYSUSERNAME_ID] ) ); 1277cdf0e10cSrcweir 1278cdf0e10cSrcweir if ( bOwnLock 1279cdf0e10cSrcweir && aOwnData[LOCKFILE_LOCALHOST_ID].equals( aData[LOCKFILE_LOCALHOST_ID] ) 1280cdf0e10cSrcweir && aOwnData[LOCKFILE_USERURL_ID].equals( aData[LOCKFILE_USERURL_ID] ) ) 1281cdf0e10cSrcweir { 1282cdf0e10cSrcweir // this is own lock from the same installation, it could remain because of crash 1283cdf0e10cSrcweir bResult = sal_True; 1284cdf0e10cSrcweir } 1285cdf0e10cSrcweir } 1286cdf0e10cSrcweir 1287cdf0e10cSrcweir if ( !bResult && !bNoUI ) 1288cdf0e10cSrcweir { 1289cdf0e10cSrcweir bUIStatus = ShowLockedDocumentDialog( aData, bLoading, bOwnLock ); 1290cdf0e10cSrcweir if ( bUIStatus == LOCK_UI_SUCCEEDED ) 1291cdf0e10cSrcweir { 1292cdf0e10cSrcweir // take the ownership over the lock file 1293cdf0e10cSrcweir bResult = aLockFile.OverwriteOwnLockFile(); 1294cdf0e10cSrcweir } 1295cdf0e10cSrcweir } 1296cdf0e10cSrcweir 1297cdf0e10cSrcweir bHandleSysLocked = sal_False; 1298cdf0e10cSrcweir } 1299cdf0e10cSrcweir } 1300cdf0e10cSrcweir catch( uno::Exception& ) 1301cdf0e10cSrcweir { 1302cdf0e10cSrcweir } 1303cdf0e10cSrcweir } while( !bResult && bUIStatus == LOCK_UI_TRY ); 1304cdf0e10cSrcweir 1305cdf0e10cSrcweir pImp->m_bLocked = bResult; 1306cdf0e10cSrcweir } 1307cdf0e10cSrcweir else 1308cdf0e10cSrcweir { 13099c0c1533SAndrea Pescetti //->i126305 13109c0c1533SAndrea Pescetti // check if path scheme is http:// or https:// 13119c0c1533SAndrea Pescetti ::rtl::OUString aScheme = INetURLObject::GetScheme(GetURLObject().GetProtocol()); 13129c0c1533SAndrea Pescetti if( aScheme.equalsIgnoreAsciiCaseAscii( INET_HTTP_SCHEME ) || 13139c0c1533SAndrea Pescetti aScheme.equalsIgnoreAsciiCaseAscii( INET_HTTPS_SCHEME ) ) 13149c0c1533SAndrea Pescetti { 13159c0c1533SAndrea Pescetti //so, this is webdav stuff... 13169c0c1533SAndrea Pescetti Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = GetInteractionHandler(); 13179c0c1533SAndrea Pescetti if ( !bResult ) 13189c0c1533SAndrea Pescetti { 13199c0c1533SAndrea Pescetti // no read-write access is necessary on loading if the document is explicitly opened as copy 13209c0c1533SAndrea Pescetti SFX_ITEMSET_ARG( GetItemSet(), pTemplateItem, SfxBoolItem, SID_TEMPLATE, sal_False); 13219c0c1533SAndrea Pescetti bResult = ( bLoading && pTemplateItem && pTemplateItem->GetValue() ); 13229c0c1533SAndrea Pescetti } 13239c0c1533SAndrea Pescetti 13249c0c1533SAndrea Pescetti if ( !bResult && !IsReadOnly() ) 13259c0c1533SAndrea Pescetti { 13269c0c1533SAndrea Pescetti 13279c0c1533SAndrea Pescetti // in case of storing the document should request the output before locking 13289c0c1533SAndrea Pescetti if ( bLoading ) 13299c0c1533SAndrea Pescetti { 13309c0c1533SAndrea Pescetti // let the stream be opened to check the system file locking 13319c0c1533SAndrea Pescetti GetMedium_Impl(); 13329c0c1533SAndrea Pescetti } 13339c0c1533SAndrea Pescetti 13349c0c1533SAndrea Pescetti sal_Int8 bUIStatus = LOCK_UI_NOLOCK; 13359c0c1533SAndrea Pescetti do 13369c0c1533SAndrea Pescetti { 13379c0c1533SAndrea Pescetti if( !bResult ) 13389c0c1533SAndrea Pescetti { 13399c0c1533SAndrea Pescetti Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv; 13409c0c1533SAndrea Pescetti uno::Reference< task::XInteractionHandler > xCHandler = GetAuthenticationInteractionHandler(); 13419c0c1533SAndrea Pescetti xComEnv = new ::ucbhelper::CommandEnvironment( xCHandler, 13429c0c1533SAndrea Pescetti Reference< ::com::sun::star::ucb::XProgressHandler >() ); 13439c0c1533SAndrea Pescetti ::ucbhelper::Content aContentToLock( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xComEnv); 13449c0c1533SAndrea Pescetti rtl::OUString aOwner; 13459c0c1533SAndrea Pescetti try { 13469c0c1533SAndrea Pescetti aContentToLock.lock(); 13479c0c1533SAndrea Pescetti bResult = sal_True; 13489c0c1533SAndrea Pescetti } 13499c0c1533SAndrea Pescetti catch( ucb::InteractiveLockingLockNotAvailableException ) 13509c0c1533SAndrea Pescetti { 13519c0c1533SAndrea Pescetti // signalled when the lock can not be done because the method is known but not allowed on the resource 13529c0c1533SAndrea Pescetti // the resource is still available, can be worked upon, at your risk 13539c0c1533SAndrea Pescetti // so ask user whether he wants to open the document without any locking 13549c0c1533SAndrea Pescetti uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler(); 13559c0c1533SAndrea Pescetti 13569c0c1533SAndrea Pescetti if ( xHandler.is() ) 13579c0c1533SAndrea Pescetti { 13589c0c1533SAndrea Pescetti ::rtl::Reference< ::ucbhelper::InteractionRequest > xIgnoreRequestImpl 13599c0c1533SAndrea Pescetti = new ::ucbhelper::InteractionRequest( uno::makeAny( document::LockFileIgnoreRequest() ) ); 13609c0c1533SAndrea Pescetti 13619c0c1533SAndrea Pescetti uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( 2 ); 13629c0c1533SAndrea Pescetti aContinuations[0] = new ::ucbhelper::InteractionAbort( xIgnoreRequestImpl.get() ); 13639c0c1533SAndrea Pescetti aContinuations[1] = new ::ucbhelper::InteractionApprove( xIgnoreRequestImpl.get() ); 13649c0c1533SAndrea Pescetti xIgnoreRequestImpl->setContinuations( aContinuations ); 13659c0c1533SAndrea Pescetti 13669c0c1533SAndrea Pescetti xHandler->handle( xIgnoreRequestImpl.get() ); 13679c0c1533SAndrea Pescetti 13689c0c1533SAndrea Pescetti ::rtl::Reference< ::ucbhelper::InteractionContinuation > xSelected = xIgnoreRequestImpl->getSelection(); 13699c0c1533SAndrea Pescetti bResult = ( uno::Reference< task::XInteractionApprove >( xSelected.get(), uno::UNO_QUERY ).is() ); 13709c0c1533SAndrea Pescetti } 13719c0c1533SAndrea Pescetti } 13729c0c1533SAndrea Pescetti catch( ucb::InteractiveLockingLockedException& e ) 13739c0c1533SAndrea Pescetti { 13749c0c1533SAndrea Pescetti // here get the lock owner currently active 13759c0c1533SAndrea Pescetti aOwner = e.Owner; 13769c0c1533SAndrea Pescetti rtl::OUString aExtendedError; 13779c0c1533SAndrea Pescetti 13789c0c1533SAndrea Pescetti if ( !bResult && !bNoUI ) 13799c0c1533SAndrea Pescetti { 13809c0c1533SAndrea Pescetti uno::Sequence< ::rtl::OUString > aData( 2 ); 13819c0c1533SAndrea Pescetti 13829c0c1533SAndrea Pescetti aData[0] = aOwner; 13839c0c1533SAndrea Pescetti aData[1] = aExtendedError; 13849c0c1533SAndrea Pescetti bUIStatus = ShowLockedWebDAVDocumentDialog( aData, bLoading ); 13859c0c1533SAndrea Pescetti if ( bUIStatus == LOCK_UI_SUCCEEDED ) 13869c0c1533SAndrea Pescetti { 13879c0c1533SAndrea Pescetti // take the ownership over the lock file, accept the current lock (already there) 13889c0c1533SAndrea Pescetti bResult = sal_True; 13899c0c1533SAndrea Pescetti } 13909c0c1533SAndrea Pescetti } 13919c0c1533SAndrea Pescetti } 13929c0c1533SAndrea Pescetti } 13939c0c1533SAndrea Pescetti } while( !bResult && bUIStatus == LOCK_UI_TRY ); 13949c0c1533SAndrea Pescetti } 13959c0c1533SAndrea Pescetti 13969c0c1533SAndrea Pescetti if ( !bResult && GetError() == ERRCODE_NONE ) 13979c0c1533SAndrea Pescetti { 13989c0c1533SAndrea Pescetti // the error should be set in case it is storing process 13999c0c1533SAndrea Pescetti // or the document has been opened for editing explicitly 14009c0c1533SAndrea Pescetti SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, sal_False ); 14019c0c1533SAndrea Pescetti if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->GetValue()) ) 14029c0c1533SAndrea Pescetti SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 14039c0c1533SAndrea Pescetti else 14049c0c1533SAndrea Pescetti GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 14059c0c1533SAndrea Pescetti } 14069c0c1533SAndrea Pescetti 14079c0c1533SAndrea Pescetti pImp->m_bLocked = bResult; 14089c0c1533SAndrea Pescetti } 14099c0c1533SAndrea Pescetti else 14109c0c1533SAndrea Pescetti { 14119c0c1533SAndrea Pescetti // this is neither file URL nor WebDAV, check whether the file is readonly 1412cdf0e10cSrcweir bResult = !bContentReadonly; 1413cdf0e10cSrcweir } 14149c0c1533SAndrea Pescetti //<-i126305 14159c0c1533SAndrea Pescetti } 1416cdf0e10cSrcweir } 1417cdf0e10cSrcweir } 1418cdf0e10cSrcweir 1419cdf0e10cSrcweir if ( !bResult && GetError() == ERRCODE_NONE ) 1420cdf0e10cSrcweir { 1421cdf0e10cSrcweir // the error should be set in case it is storing process 1422cdf0e10cSrcweir // or the document has been opened for editing explicitly 1423cdf0e10cSrcweir 1424cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, sal_False ); 1425cdf0e10cSrcweir if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->GetValue()) ) 1426cdf0e10cSrcweir SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1427cdf0e10cSrcweir else 1428cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 1429cdf0e10cSrcweir } 1430cdf0e10cSrcweir 1431cdf0e10cSrcweir // when the file is locked, get the current file date 1432cdf0e10cSrcweir if ( bResult && DocNeedsFileDateCheck() ) 1433cdf0e10cSrcweir GetInitFileDate( sal_True ); 1434cdf0e10cSrcweir 1435cdf0e10cSrcweir return bResult; 1436cdf0e10cSrcweir } 1437cdf0e10cSrcweir 1438cdf0e10cSrcweir //------------------------------------------------------------------ 1439cdf0e10cSrcweir uno::Reference < embed::XStorage > SfxMedium::GetStorage( sal_Bool bCreateTempIfNo ) 1440cdf0e10cSrcweir { 1441cdf0e10cSrcweir if ( pImp->xStorage.is() || bTriedStorage ) 1442cdf0e10cSrcweir return pImp->xStorage; 1443cdf0e10cSrcweir 1444cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 1445cdf0e10cSrcweir 1446cdf0e10cSrcweir // the medium should be retrieved before temporary file creation 1447cdf0e10cSrcweir // to let the MediaDescriptor be filled with the streams 1448cdf0e10cSrcweir GetMedium_Impl(); 1449cdf0e10cSrcweir 1450cdf0e10cSrcweir if ( bCreateTempIfNo ) 1451cdf0e10cSrcweir CreateTempFile( sal_False ); 1452cdf0e10cSrcweir 1453cdf0e10cSrcweir GetMedium_Impl(); 1454cdf0e10cSrcweir 1455cdf0e10cSrcweir if ( GetError() ) 1456cdf0e10cSrcweir return pImp->xStorage; 1457cdf0e10cSrcweir 1458cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pRepairItem, SfxBoolItem, SID_REPAIRPACKAGE, sal_False); 1459cdf0e10cSrcweir if ( pRepairItem && pRepairItem->GetValue() ) 1460cdf0e10cSrcweir { 1461cdf0e10cSrcweir // the storage should be created for repairing mode 1462cdf0e10cSrcweir CreateTempFile( sal_False ); 1463cdf0e10cSrcweir GetMedium_Impl(); 1464cdf0e10cSrcweir 1465cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XProgressHandler > xProgressHandler; 1466cdf0e10cSrcweir Reference< ::com::sun::star::task::XStatusIndicator > xStatusIndicator; 1467cdf0e10cSrcweir 1468cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pxProgressItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, sal_False ); 1469cdf0e10cSrcweir if( pxProgressItem && ( pxProgressItem->GetValue() >>= xStatusIndicator ) ) 1470cdf0e10cSrcweir xProgressHandler = Reference< ::com::sun::star::ucb::XProgressHandler >( 1471cdf0e10cSrcweir new utl::ProgressHandlerWrap( xStatusIndicator ) ); 1472cdf0e10cSrcweir 1473cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aAddProps( 2 ); 1474cdf0e10cSrcweir aAddProps[0].Name = ::rtl::OUString::createFromAscii( "RepairPackage" ); 1475cdf0e10cSrcweir aAddProps[0].Value <<= (sal_Bool)sal_True; 1476cdf0e10cSrcweir aAddProps[1].Name = ::rtl::OUString::createFromAscii( "StatusIndicator" ); 1477cdf0e10cSrcweir aAddProps[1].Value <<= xProgressHandler; 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir // the first arguments will be filled later 1480cdf0e10cSrcweir aArgs.realloc( 3 ); 1481cdf0e10cSrcweir aArgs[2] <<= aAddProps; 1482cdf0e10cSrcweir } 1483cdf0e10cSrcweir 1484cdf0e10cSrcweir if ( pImp->xStream.is() ) 1485cdf0e10cSrcweir { 1486cdf0e10cSrcweir // since the storage is based on temporary stream we open it always read-write 1487cdf0e10cSrcweir aArgs[0] <<= pImp->xStream; 1488cdf0e10cSrcweir aArgs[1] <<= embed::ElementModes::READWRITE; 1489cdf0e10cSrcweir pImp->bStorageBasedOnInStream = sal_True; 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir else if ( pImp->xInputStream.is() ) 1492cdf0e10cSrcweir { 1493cdf0e10cSrcweir // since the storage is based on temporary stream we open it always read-write 1494cdf0e10cSrcweir aArgs[0] <<= pImp->xInputStream; 1495cdf0e10cSrcweir aArgs[1] <<= embed::ElementModes::READ; 1496cdf0e10cSrcweir pImp->bStorageBasedOnInStream = sal_True; 1497cdf0e10cSrcweir } 1498cdf0e10cSrcweir else 1499cdf0e10cSrcweir { 1500cdf0e10cSrcweir CloseStreams_Impl(); 1501cdf0e10cSrcweir aArgs[0] <<= ::rtl::OUString( aName ); 1502cdf0e10cSrcweir aArgs[1] <<= embed::ElementModes::READ; 1503cdf0e10cSrcweir pImp->bStorageBasedOnInStream = sal_False; 1504cdf0e10cSrcweir } 1505cdf0e10cSrcweir 1506cdf0e10cSrcweir try 1507cdf0e10cSrcweir { 1508cdf0e10cSrcweir pImp->xStorage = uno::Reference< embed::XStorage >( 1509cdf0e10cSrcweir ::comphelper::OStorageHelper::GetStorageFactory()->createInstanceWithArguments( aArgs ), 1510cdf0e10cSrcweir uno::UNO_QUERY ); 1511cdf0e10cSrcweir } 1512cdf0e10cSrcweir catch( uno::Exception& ) 1513cdf0e10cSrcweir { 1514cdf0e10cSrcweir // impossibility to create the storage is no error 1515cdf0e10cSrcweir } 1516cdf0e10cSrcweir 1517cdf0e10cSrcweir if( ( pImp->nLastStorageError = GetError() ) != SVSTREAM_OK ) 1518cdf0e10cSrcweir { 1519cdf0e10cSrcweir pImp->xStorage = 0; 1520cdf0e10cSrcweir if ( pInStream ) 1521cdf0e10cSrcweir pInStream->Seek(0); 1522cdf0e10cSrcweir return uno::Reference< embed::XStorage >(); 1523cdf0e10cSrcweir } 1524cdf0e10cSrcweir 1525cdf0e10cSrcweir bTriedStorage = sal_True; 1526cdf0e10cSrcweir 1527cdf0e10cSrcweir // TODO/LATER: Get versionlist on demand 1528cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1529cdf0e10cSrcweir { 1530cdf0e10cSrcweir SetEncryptionDataToStorage_Impl(); 1531cdf0e10cSrcweir GetVersionList(); 1532cdf0e10cSrcweir } 1533cdf0e10cSrcweir 1534cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pVersion, SfxInt16Item, SID_VERSION, sal_False); 1535cdf0e10cSrcweir 1536cdf0e10cSrcweir sal_Bool bResetStorage = sal_False; 1537cdf0e10cSrcweir if ( pVersion && pVersion->GetValue() ) 1538cdf0e10cSrcweir { 1539cdf0e10cSrcweir // Alle verf"ugbaren Versionen einlesen 1540cdf0e10cSrcweir if ( pImp->aVersions.getLength() ) 1541cdf0e10cSrcweir { 1542cdf0e10cSrcweir // Die zum Kommentar passende Version suchen 1543cdf0e10cSrcweir // Die Versionen sind von 1 an durchnumeriert, mit negativen 1544cdf0e10cSrcweir // Versionsnummern werden die Versionen von der aktuellen aus 1545cdf0e10cSrcweir // r"uckw"arts gez"ahlt 1546cdf0e10cSrcweir short nVersion = pVersion ? pVersion->GetValue() : 0; 1547cdf0e10cSrcweir if ( nVersion<0 ) 1548cdf0e10cSrcweir nVersion = ( (short) pImp->aVersions.getLength() ) + nVersion; 1549cdf0e10cSrcweir else if ( nVersion ) 1550cdf0e10cSrcweir nVersion--; 1551cdf0e10cSrcweir 1552cdf0e10cSrcweir util::RevisionTag& rTag = pImp->aVersions[nVersion]; 1553cdf0e10cSrcweir { 1554cdf0e10cSrcweir // SubStorage f"ur alle Versionen "offnen 1555cdf0e10cSrcweir uno::Reference < embed::XStorage > xSub = pImp->xStorage->openStorageElement( DEFINE_CONST_UNICODE( "Versions" ), 1556cdf0e10cSrcweir embed::ElementModes::READ ); 1557cdf0e10cSrcweir 1558cdf0e10cSrcweir DBG_ASSERT( xSub.is(), "Versionsliste, aber keine Versionen!" ); 1559cdf0e10cSrcweir 1560cdf0e10cSrcweir // Dort ist die Version als gepackter Stream gespeichert 1561cdf0e10cSrcweir uno::Reference < io::XStream > xStr = xSub->openStreamElement( rTag.Identifier, embed::ElementModes::READ ); 1562cdf0e10cSrcweir SvStream* pStream = utl::UcbStreamHelper::CreateStream( xStr ); 1563cdf0e10cSrcweir if ( pStream && pStream->GetError() == SVSTREAM_OK ) 1564cdf0e10cSrcweir { 1565cdf0e10cSrcweir // Stream ins TempDir auspacken 1566cdf0e10cSrcweir ::utl::TempFile aTempFile; 1567cdf0e10cSrcweir String aTmpName = aTempFile.GetURL(); 1568cdf0e10cSrcweir SvFileStream aTmpStream( aTmpName, SFX_STREAM_READWRITE ); 1569cdf0e10cSrcweir 1570cdf0e10cSrcweir *pStream >> aTmpStream; 1571cdf0e10cSrcweir aTmpStream.Close(); 1572cdf0e10cSrcweir 1573cdf0e10cSrcweir // Datei als Storage "offnen 1574cdf0e10cSrcweir nStorOpenMode = SFX_STREAM_READONLY; 1575cdf0e10cSrcweir pImp->xStorage = comphelper::OStorageHelper::GetStorageFromURL( aTmpName, embed::ElementModes::READ ); 1576cdf0e10cSrcweir pImp->bStorageBasedOnInStream = sal_False; 1577cdf0e10cSrcweir String aTemp; 1578cdf0e10cSrcweir ::utl::LocalFileHelper::ConvertURLToPhysicalName( aTmpName, aTemp ); 1579cdf0e10cSrcweir SetPhysicalName_Impl( aTemp ); 1580cdf0e10cSrcweir 1581cdf0e10cSrcweir pImp->bIsTemp = sal_True; 1582cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 1583cdf0e10cSrcweir // TODO/MBA 1584cdf0e10cSrcweir pImp->aVersions.realloc(0); 1585cdf0e10cSrcweir } 1586cdf0e10cSrcweir else 1587cdf0e10cSrcweir bResetStorage = sal_True; 1588cdf0e10cSrcweir } 1589cdf0e10cSrcweir } 1590cdf0e10cSrcweir else 1591cdf0e10cSrcweir bResetStorage = sal_True; 1592cdf0e10cSrcweir } 1593cdf0e10cSrcweir 1594cdf0e10cSrcweir if ( bResetStorage ) 1595cdf0e10cSrcweir { 1596cdf0e10cSrcweir pImp->xStorage = 0; 1597cdf0e10cSrcweir if ( pInStream ) 1598cdf0e10cSrcweir pInStream->Seek( 0L ); 1599cdf0e10cSrcweir } 1600cdf0e10cSrcweir 1601cdf0e10cSrcweir pImp->bIsStorage = pImp->xStorage.is(); 1602cdf0e10cSrcweir return pImp->xStorage; 1603cdf0e10cSrcweir } 1604cdf0e10cSrcweir 1605cdf0e10cSrcweir //------------------------------------------------------------------ 1606cdf0e10cSrcweir uno::Reference< embed::XStorage > SfxMedium::GetZipStorageToSign_Impl( sal_Bool bReadOnly ) 1607cdf0e10cSrcweir { 1608cdf0e10cSrcweir if ( !GetError() && !pImp->m_xZipStorage.is() ) 1609cdf0e10cSrcweir { 1610cdf0e10cSrcweir // very careful!!! 1611cdf0e10cSrcweir // if bReadOnly == sal_False and there is no temporary file the original file might be used 1612cdf0e10cSrcweir GetMedium_Impl(); 1613cdf0e10cSrcweir 1614cdf0e10cSrcweir try 1615cdf0e10cSrcweir { 1616cdf0e10cSrcweir // we can not sign document if there is no stream 1617cdf0e10cSrcweir // should it be possible at all? 1618cdf0e10cSrcweir if ( !bReadOnly && pImp->xStream.is() ) 1619cdf0e10cSrcweir { 1620cdf0e10cSrcweir pImp->m_xZipStorage = ::comphelper::OStorageHelper::GetStorageOfFormatFromStream( ZIP_STORAGE_FORMAT_STRING, pImp->xStream, embed::ElementModes::READWRITE ); 1621cdf0e10cSrcweir } 1622cdf0e10cSrcweir else if ( pImp->xInputStream.is() ) 1623cdf0e10cSrcweir { 1624cdf0e10cSrcweir pImp->m_xZipStorage = ::comphelper::OStorageHelper::GetStorageOfFormatFromInputStream( ZIP_STORAGE_FORMAT_STRING, pImp->xInputStream ); 1625cdf0e10cSrcweir } 1626cdf0e10cSrcweir } 1627cdf0e10cSrcweir catch( uno::Exception& ) 1628cdf0e10cSrcweir { 1629cdf0e10cSrcweir OSL_ENSURE( sal_False, "No possibility to get readonly version of storage from medium!\n" ); 1630cdf0e10cSrcweir } 1631cdf0e10cSrcweir 1632cdf0e10cSrcweir if ( GetError() ) // do not remove warnings 1633cdf0e10cSrcweir ResetError(); 1634cdf0e10cSrcweir } 1635cdf0e10cSrcweir 1636cdf0e10cSrcweir return pImp->m_xZipStorage; 1637cdf0e10cSrcweir } 1638cdf0e10cSrcweir 1639cdf0e10cSrcweir //------------------------------------------------------------------ 1640cdf0e10cSrcweir void SfxMedium::CloseZipStorage_Impl() 1641cdf0e10cSrcweir { 1642cdf0e10cSrcweir if ( pImp->m_xZipStorage.is() ) 1643cdf0e10cSrcweir { 1644cdf0e10cSrcweir try { 1645cdf0e10cSrcweir pImp->m_xZipStorage->dispose(); 1646cdf0e10cSrcweir } catch( uno::Exception& ) 1647cdf0e10cSrcweir {} 1648cdf0e10cSrcweir 1649cdf0e10cSrcweir pImp->m_xZipStorage = uno::Reference< embed::XStorage >(); 1650cdf0e10cSrcweir } 1651cdf0e10cSrcweir } 1652cdf0e10cSrcweir 1653cdf0e10cSrcweir //------------------------------------------------------------------ 1654cdf0e10cSrcweir void SfxMedium::CloseStorage() 1655cdf0e10cSrcweir { 1656cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1657cdf0e10cSrcweir { 1658cdf0e10cSrcweir uno::Reference < lang::XComponent > xComp( pImp->xStorage, uno::UNO_QUERY ); 1659cdf0e10cSrcweir // in the salvage mode the medium does not own the storage 1660cdf0e10cSrcweir if ( pImp->bDisposeStorage && !pImp->m_bSalvageMode ) 1661cdf0e10cSrcweir { 1662cdf0e10cSrcweir try { 1663cdf0e10cSrcweir xComp->dispose(); 1664cdf0e10cSrcweir } catch( uno::Exception& ) 1665cdf0e10cSrcweir { 1666cdf0e10cSrcweir OSL_ENSURE( sal_False, "Medium's storage is already disposed!\n" ); 1667cdf0e10cSrcweir } 1668cdf0e10cSrcweir } 1669cdf0e10cSrcweir 1670cdf0e10cSrcweir pImp->xStorage = 0; 1671cdf0e10cSrcweir pImp->bStorageBasedOnInStream = sal_False; 1672cdf0e10cSrcweir } 1673cdf0e10cSrcweir 1674cdf0e10cSrcweir bTriedStorage = sal_False; 1675cdf0e10cSrcweir pImp->bIsStorage = sal_False; 1676cdf0e10cSrcweir } 1677cdf0e10cSrcweir 1678cdf0e10cSrcweir void SfxMedium::CanDisposeStorage_Impl( sal_Bool bDisposeStorage ) 1679cdf0e10cSrcweir { 1680cdf0e10cSrcweir pImp->bDisposeStorage = bDisposeStorage; 1681cdf0e10cSrcweir } 1682cdf0e10cSrcweir 1683cdf0e10cSrcweir sal_Bool SfxMedium::WillDisposeStorageOnClose_Impl() 1684cdf0e10cSrcweir { 1685cdf0e10cSrcweir return pImp->bDisposeStorage; 1686cdf0e10cSrcweir } 1687cdf0e10cSrcweir 1688cdf0e10cSrcweir //------------------------------------------------------------------ 1689cdf0e10cSrcweir void SfxMedium::SetOpenMode( StreamMode nStorOpen, 1690cdf0e10cSrcweir sal_Bool bDirectP, 1691cdf0e10cSrcweir sal_Bool bDontClose ) 1692cdf0e10cSrcweir { 1693cdf0e10cSrcweir if ( nStorOpenMode != nStorOpen ) 1694cdf0e10cSrcweir { 1695cdf0e10cSrcweir nStorOpenMode = nStorOpen; 1696cdf0e10cSrcweir 1697cdf0e10cSrcweir if( !bDontClose ) 1698cdf0e10cSrcweir { 1699cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1700cdf0e10cSrcweir CloseStorage(); 1701cdf0e10cSrcweir 1702cdf0e10cSrcweir CloseStreams_Impl(); 1703cdf0e10cSrcweir } 1704cdf0e10cSrcweir } 1705cdf0e10cSrcweir 1706cdf0e10cSrcweir bDirect = bDirectP; 1707cdf0e10cSrcweir bSetFilter = sal_False; 1708cdf0e10cSrcweir } 1709cdf0e10cSrcweir 1710cdf0e10cSrcweir //------------------------------------------------------------------ 1711cdf0e10cSrcweir sal_Bool SfxMedium::UseBackupToRestore_Impl( ::ucbhelper::Content& aOriginalContent, 1712cdf0e10cSrcweir const Reference< ::com::sun::star::ucb::XCommandEnvironment >& xComEnv ) 1713cdf0e10cSrcweir { 1714cdf0e10cSrcweir try 1715cdf0e10cSrcweir { 1716cdf0e10cSrcweir ::ucbhelper::Content aTransactCont( pImp->m_aBackupURL, xComEnv ); 1717cdf0e10cSrcweir 1718cdf0e10cSrcweir Reference< XInputStream > aOrigInput = aTransactCont.openStream(); 1719cdf0e10cSrcweir aOriginalContent.writeStream( aOrigInput, sal_True ); 1720cdf0e10cSrcweir return sal_True; 1721cdf0e10cSrcweir } 1722cdf0e10cSrcweir catch( Exception& ) 1723cdf0e10cSrcweir { 1724cdf0e10cSrcweir // in case of failure here the backup file should not be removed 1725cdf0e10cSrcweir // TODO/LATER: a message should be used to let user know about the backup 1726cdf0e10cSrcweir pImp->m_bRemoveBackup = sal_False; 1727cdf0e10cSrcweir // TODO/LATER: needs a specific error code 1728cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1729cdf0e10cSrcweir } 1730cdf0e10cSrcweir 1731cdf0e10cSrcweir return sal_False; 1732cdf0e10cSrcweir } 1733cdf0e10cSrcweir 1734cdf0e10cSrcweir //------------------------------------------------------------------ 1735cdf0e10cSrcweir sal_Bool SfxMedium::StorageCommit_Impl() 1736cdf0e10cSrcweir { 1737cdf0e10cSrcweir sal_Bool bResult = sal_False; 1738cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 1739cdf0e10cSrcweir ::ucbhelper::Content aOriginalContent; 1740cdf0e10cSrcweir 1741cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1742cdf0e10cSrcweir { 1743cdf0e10cSrcweir if ( !GetError() ) 1744cdf0e10cSrcweir { 1745cdf0e10cSrcweir uno::Reference < embed::XTransactedObject > xTrans( pImp->xStorage, uno::UNO_QUERY ); 1746cdf0e10cSrcweir if ( xTrans.is() ) 1747cdf0e10cSrcweir { 1748cdf0e10cSrcweir try 1749cdf0e10cSrcweir { 1750cdf0e10cSrcweir xTrans->commit(); 1751cdf0e10cSrcweir CloseZipStorage_Impl(); 1752cdf0e10cSrcweir bResult = sal_True; 1753cdf0e10cSrcweir } 1754cdf0e10cSrcweir catch ( embed::UseBackupException& aBackupExc ) 1755cdf0e10cSrcweir { 1756cdf0e10cSrcweir // since the temporary file is created always now, the scenario is close to be impossible 1757cdf0e10cSrcweir if ( !pImp->pTempFile ) 1758cdf0e10cSrcweir { 1759cdf0e10cSrcweir OSL_ENSURE( pImp->m_aBackupURL.getLength(), "No backup on storage commit!\n" ); 1760cdf0e10cSrcweir if ( pImp->m_aBackupURL.getLength() 1761cdf0e10cSrcweir && ::ucbhelper::Content::create( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), 1762cdf0e10cSrcweir xDummyEnv, 1763cdf0e10cSrcweir aOriginalContent ) ) 1764cdf0e10cSrcweir { 1765cdf0e10cSrcweir // use backup to restore the file 1766cdf0e10cSrcweir // the storage has already disconnected from original location 1767cdf0e10cSrcweir CloseAndReleaseStreams_Impl(); 1768cdf0e10cSrcweir if ( !UseBackupToRestore_Impl( aOriginalContent, xDummyEnv ) ) 1769cdf0e10cSrcweir { 1770cdf0e10cSrcweir // connect the medium to the temporary file of the storage 1771cdf0e10cSrcweir pImp->aContent = ::ucbhelper::Content(); 1772cdf0e10cSrcweir aName = aBackupExc.TemporaryFileURL; 1773cdf0e10cSrcweir OSL_ENSURE( aName.Len(), "The exception _must_ contain the temporary URL!\n" ); 1774cdf0e10cSrcweir } 1775cdf0e10cSrcweir } 1776cdf0e10cSrcweir 1777cdf0e10cSrcweir if ( !GetError() ) 1778cdf0e10cSrcweir SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1779cdf0e10cSrcweir } 1780cdf0e10cSrcweir } 1781cdf0e10cSrcweir catch ( uno::Exception& ) 1782cdf0e10cSrcweir { 1783cdf0e10cSrcweir //TODO/LATER: improve error handling 1784cdf0e10cSrcweir SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 1785cdf0e10cSrcweir } 1786cdf0e10cSrcweir } 1787cdf0e10cSrcweir } 1788cdf0e10cSrcweir } 1789cdf0e10cSrcweir 1790cdf0e10cSrcweir return bResult; 1791cdf0e10cSrcweir } 1792cdf0e10cSrcweir 1793cdf0e10cSrcweir //------------------------------------------------------------------ 1794cdf0e10cSrcweir sal_Bool SfxMedium::TransactedTransferForFS_Impl( const INetURLObject& aSource, 1795cdf0e10cSrcweir const INetURLObject& aDest, 1796cdf0e10cSrcweir const Reference< ::com::sun::star::ucb::XCommandEnvironment >& xComEnv ) 1797cdf0e10cSrcweir { 1798cdf0e10cSrcweir sal_Bool bResult = sal_False; 1799cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 1800cdf0e10cSrcweir Reference< XOutputStream > aDestStream; 1801cdf0e10cSrcweir ::ucbhelper::Content aOriginalContent; 1802cdf0e10cSrcweir 1803cdf0e10cSrcweir try 1804cdf0e10cSrcweir { 1805cdf0e10cSrcweir aOriginalContent = ::ucbhelper::Content( aDest.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); 1806cdf0e10cSrcweir } 1807cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandAbortedException& ) 1808cdf0e10cSrcweir { 1809cdf0e10cSrcweir eError = ERRCODE_ABORT; 1810cdf0e10cSrcweir } 1811cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException& ) 1812cdf0e10cSrcweir { 1813cdf0e10cSrcweir eError = ERRCODE_ABORT; 1814cdf0e10cSrcweir } 1815cdf0e10cSrcweir catch (const ::com::sun::star::ucb::ContentCreationException& ex) 1816cdf0e10cSrcweir { 1817cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1818cdf0e10cSrcweir if ( 1819cdf0e10cSrcweir (ex.eError == ::com::sun::star::ucb::ContentCreationError_NO_CONTENT_PROVIDER ) || 1820cdf0e10cSrcweir (ex.eError == ::com::sun::star::ucb::ContentCreationError_CONTENT_CREATION_FAILED) 1821cdf0e10cSrcweir ) 1822cdf0e10cSrcweir { 1823cdf0e10cSrcweir eError = ERRCODE_IO_NOTEXISTSPATH; 1824cdf0e10cSrcweir } 1825cdf0e10cSrcweir } 1826cdf0e10cSrcweir catch (const ::com::sun::star::uno::Exception&) 1827cdf0e10cSrcweir { 1828cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1829cdf0e10cSrcweir } 1830cdf0e10cSrcweir 1831cdf0e10cSrcweir if( !eError || (eError & ERRCODE_WARNING_MASK) ) 1832cdf0e10cSrcweir { 1833cdf0e10cSrcweir if ( pImp->xStorage.is() ) 1834cdf0e10cSrcweir CloseStorage(); 1835cdf0e10cSrcweir 1836cdf0e10cSrcweir CloseStreams_Impl(); 1837cdf0e10cSrcweir 1838cdf0e10cSrcweir ::ucbhelper::Content aTempCont; 1839cdf0e10cSrcweir if( ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv, aTempCont ) ) 1840cdf0e10cSrcweir { 1841cdf0e10cSrcweir sal_Bool bTransactStarted = sal_False; 1842cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pOverWrite, SfxBoolItem, SID_OVERWRITE, sal_False ); 1843cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pRename, SfxBoolItem, SID_RENAME, sal_False ); 1844cdf0e10cSrcweir sal_Bool bRename = pRename ? pRename->GetValue() : sal_False; 1845cdf0e10cSrcweir sal_Bool bOverWrite = pOverWrite ? pOverWrite->GetValue() : !bRename; 1846cdf0e10cSrcweir 1847cdf0e10cSrcweir try 1848cdf0e10cSrcweir { 1849cdf0e10cSrcweir if( bOverWrite && ::utl::UCBContentHelper::IsDocument( aDest.GetMainURL( INetURLObject::NO_DECODE ) ) ) 1850cdf0e10cSrcweir { 1851cdf0e10cSrcweir if( ! pImp->m_aBackupURL.getLength() ) 1852cdf0e10cSrcweir DoInternalBackup_Impl( aOriginalContent ); 1853cdf0e10cSrcweir 1854cdf0e10cSrcweir if( pImp->m_aBackupURL.getLength() ) 1855cdf0e10cSrcweir { 1856cdf0e10cSrcweir Reference< XInputStream > aTempInput = aTempCont.openStream(); 1857cdf0e10cSrcweir bTransactStarted = sal_True; 1858cdf0e10cSrcweir aOriginalContent.setPropertyValue( ::rtl::OUString::createFromAscii( "Size" ), 1859cdf0e10cSrcweir uno::makeAny( (sal_Int64)0 ) ); 1860cdf0e10cSrcweir aOriginalContent.writeStream( aTempInput, bOverWrite ); 1861cdf0e10cSrcweir bResult = sal_True; 1862cdf0e10cSrcweir } 1863cdf0e10cSrcweir else 1864cdf0e10cSrcweir { 1865cdf0e10cSrcweir eError = ERRCODE_SFX_CANTCREATEBACKUP; 1866cdf0e10cSrcweir } 1867cdf0e10cSrcweir } 1868cdf0e10cSrcweir else 1869cdf0e10cSrcweir { 1870cdf0e10cSrcweir Reference< XInputStream > aTempInput = aTempCont.openStream(); 1871cdf0e10cSrcweir aOriginalContent.writeStream( aTempInput, bOverWrite ); 1872cdf0e10cSrcweir bResult = sal_True; 1873cdf0e10cSrcweir } 1874cdf0e10cSrcweir } 1875cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandAbortedException& ) 1876cdf0e10cSrcweir { 1877cdf0e10cSrcweir eError = ERRCODE_ABORT; 1878cdf0e10cSrcweir } 1879cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException& ) 1880cdf0e10cSrcweir { 1881cdf0e10cSrcweir eError = ERRCODE_ABORT; 1882cdf0e10cSrcweir } 1883cdf0e10cSrcweir catch ( ::com::sun::star::ucb::InteractiveIOException& r ) 1884cdf0e10cSrcweir { 1885cdf0e10cSrcweir if ( r.Code == IOErrorCode_ACCESS_DENIED ) 1886cdf0e10cSrcweir eError = ERRCODE_IO_ACCESSDENIED; 1887cdf0e10cSrcweir else if ( r.Code == IOErrorCode_NOT_EXISTING ) 1888cdf0e10cSrcweir eError = ERRCODE_IO_NOTEXISTS; 1889cdf0e10cSrcweir else if ( r.Code == IOErrorCode_CANT_READ ) 1890cdf0e10cSrcweir eError = ERRCODE_IO_CANTREAD; 1891cdf0e10cSrcweir else 1892cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1893cdf0e10cSrcweir } 1894cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 1895cdf0e10cSrcweir { 1896cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 1897cdf0e10cSrcweir } 1898cdf0e10cSrcweir 1899cdf0e10cSrcweir if ( bResult ) 1900cdf0e10cSrcweir { 1901cdf0e10cSrcweir if ( pImp->pTempFile ) 1902cdf0e10cSrcweir { 1903cdf0e10cSrcweir pImp->pTempFile->EnableKillingFile( sal_True ); 1904cdf0e10cSrcweir delete pImp->pTempFile; 1905cdf0e10cSrcweir pImp->pTempFile = NULL; 1906cdf0e10cSrcweir } 1907cdf0e10cSrcweir } 1908cdf0e10cSrcweir else if ( bTransactStarted ) 1909cdf0e10cSrcweir { 1910cdf0e10cSrcweir UseBackupToRestore_Impl( aOriginalContent, xDummyEnv ); 1911cdf0e10cSrcweir } 1912cdf0e10cSrcweir } 1913cdf0e10cSrcweir else 1914cdf0e10cSrcweir eError = ERRCODE_IO_CANTREAD; 1915cdf0e10cSrcweir } 1916cdf0e10cSrcweir 1917cdf0e10cSrcweir return bResult; 1918cdf0e10cSrcweir } 1919cdf0e10cSrcweir 1920cdf0e10cSrcweir //------------------------------------------------------------------ 1921cdf0e10cSrcweir sal_Bool SfxMedium::TryDirectTransfer( const ::rtl::OUString& aURL, SfxItemSet& aTargetSet ) 1922cdf0e10cSrcweir { 1923cdf0e10cSrcweir if ( GetError() ) 1924cdf0e10cSrcweir return sal_False; 1925cdf0e10cSrcweir 1926cdf0e10cSrcweir // if the document had no password it should be stored without password 1927cdf0e10cSrcweir // if the document had password it should be stored with the same password 1928cdf0e10cSrcweir // otherwise the stream copying can not be done 1929cdf0e10cSrcweir SFX_ITEMSET_ARG( &aTargetSet, pNewPassItem, SfxStringItem, SID_PASSWORD, sal_False ); 1930cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pOldPassItem, SfxStringItem, SID_PASSWORD, sal_False ); 1931cdf0e10cSrcweir if ( ( !pNewPassItem && !pOldPassItem ) 1932cdf0e10cSrcweir || ( pNewPassItem && pOldPassItem && pNewPassItem->GetValue().Equals( pOldPassItem->GetValue() ) ) ) 1933cdf0e10cSrcweir { 1934cdf0e10cSrcweir // the filter must be the same 1935cdf0e10cSrcweir SFX_ITEMSET_ARG( &aTargetSet, pNewFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 1936cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pOldFilterItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 1937cdf0e10cSrcweir if ( pNewFilterItem && pOldFilterItem && pNewFilterItem->GetValue().Equals( pOldFilterItem->GetValue() ) ) 1938cdf0e10cSrcweir { 1939cdf0e10cSrcweir // get the input stream and copy it 1940cdf0e10cSrcweir // in case of success return true 1941cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = GetInputStream(); 1942cdf0e10cSrcweir 1943cdf0e10cSrcweir ResetError(); 1944cdf0e10cSrcweir if ( xInStream.is() ) 1945cdf0e10cSrcweir { 1946cdf0e10cSrcweir try 1947cdf0e10cSrcweir { 1948cdf0e10cSrcweir uno::Reference< io::XSeekable > xSeek( xInStream, uno::UNO_QUERY ); 1949cdf0e10cSrcweir sal_Int64 nPos = 0; 1950cdf0e10cSrcweir if ( xSeek.is() ) 1951cdf0e10cSrcweir { 1952cdf0e10cSrcweir nPos = xSeek->getPosition(); 1953cdf0e10cSrcweir xSeek->seek( 0 ); 1954cdf0e10cSrcweir } 1955cdf0e10cSrcweir 1956cdf0e10cSrcweir uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; 1957cdf0e10cSrcweir ::ucbhelper::Content aTargetContent( aURL, xEnv ); 1958cdf0e10cSrcweir 1959cdf0e10cSrcweir InsertCommandArgument aInsertArg; 1960cdf0e10cSrcweir aInsertArg.Data = xInStream; 1961cdf0e10cSrcweir SFX_ITEMSET_ARG( &aTargetSet, pRename, SfxBoolItem, SID_RENAME, sal_False ); 1962cdf0e10cSrcweir SFX_ITEMSET_ARG( &aTargetSet, pOverWrite, SfxBoolItem, SID_OVERWRITE, sal_False ); 1963cdf0e10cSrcweir if ( (pOverWrite && !pOverWrite->GetValue()) // argument says: never overwrite 1964cdf0e10cSrcweir || (pRename && pRename->GetValue()) ) // argument says: rename file 1965cdf0e10cSrcweir aInsertArg.ReplaceExisting = sal_False; 1966cdf0e10cSrcweir else 1967cdf0e10cSrcweir aInsertArg.ReplaceExisting = sal_True; // default is overwrite existing files 1968cdf0e10cSrcweir 1969cdf0e10cSrcweir Any aCmdArg; 1970cdf0e10cSrcweir aCmdArg <<= aInsertArg; 1971cdf0e10cSrcweir aTargetContent.executeCommand( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ), 1972cdf0e10cSrcweir aCmdArg ); 1973cdf0e10cSrcweir 1974cdf0e10cSrcweir if ( xSeek.is() ) 1975cdf0e10cSrcweir xSeek->seek( nPos ); 1976cdf0e10cSrcweir 1977cdf0e10cSrcweir return sal_True; 1978cdf0e10cSrcweir } 1979cdf0e10cSrcweir catch( uno::Exception& ) 1980cdf0e10cSrcweir {} 1981cdf0e10cSrcweir } 1982cdf0e10cSrcweir } 1983cdf0e10cSrcweir } 1984cdf0e10cSrcweir 1985cdf0e10cSrcweir return sal_False; 1986cdf0e10cSrcweir } 1987cdf0e10cSrcweir 1988cdf0e10cSrcweir //------------------------------------------------------------------ 1989cdf0e10cSrcweir void SfxMedium::Transfer_Impl() 1990cdf0e10cSrcweir { 1991cdf0e10cSrcweir // The transfer is required only in two cases: either if there is a temporary file or if there is a salvage item 1992cdf0e10cSrcweir String aNameURL; 1993cdf0e10cSrcweir if ( pImp->pTempFile ) 1994cdf0e10cSrcweir aNameURL = pImp->pTempFile->GetURL(); 1995cdf0e10cSrcweir else if ( aLogicName.Len() && pImp->m_bSalvageMode ) 1996cdf0e10cSrcweir { 1997*30acf5e8Spfg // makes sense only in case logic name is set 1998cdf0e10cSrcweir if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aNameURL ) ) 1999cdf0e10cSrcweir OSL_ENSURE( sal_False, "The medium name is not convertable!\n" ); 2000cdf0e10cSrcweir } 2001cdf0e10cSrcweir 2002cdf0e10cSrcweir if ( aNameURL.Len() && ( !eError || (eError & ERRCODE_WARNING_MASK) ) ) 2003cdf0e10cSrcweir { 2004cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxMedium::Transfer_Impl, copying to target" ); 2005cdf0e10cSrcweir 2006cdf0e10cSrcweir Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; 2007cdf0e10cSrcweir Reference< XOutputStream > rOutStream; 2008cdf0e10cSrcweir 2009cdf0e10cSrcweir // in case an output stream is provided from outside and the URL is correct 2010cdf0e10cSrcweir // commit to the stream 2011cdf0e10cSrcweir if( aLogicName.CompareToAscii( "private:stream", 14 ) == COMPARE_EQUAL ) 2012cdf0e10cSrcweir { 2013cdf0e10cSrcweir // TODO/LATER: support storing to SID_STREAM 2014cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pOutStreamItem, SfxUnoAnyItem, SID_OUTPUTSTREAM, sal_False); 2015cdf0e10cSrcweir if( pOutStreamItem && ( pOutStreamItem->GetValue() >>= rOutStream ) ) 2016cdf0e10cSrcweir { 2017cdf0e10cSrcweir if ( pImp->xStorage.is() ) 2018cdf0e10cSrcweir CloseStorage(); 2019cdf0e10cSrcweir 2020cdf0e10cSrcweir CloseStreams_Impl(); 2021cdf0e10cSrcweir 2022cdf0e10cSrcweir INetURLObject aSource( aNameURL ); 2023cdf0e10cSrcweir ::ucbhelper::Content aTempCont; 2024cdf0e10cSrcweir if( ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aTempCont ) ) 2025cdf0e10cSrcweir { 2026cdf0e10cSrcweir try 2027cdf0e10cSrcweir { 2028cdf0e10cSrcweir sal_Int32 nRead; 2029cdf0e10cSrcweir sal_Int32 nBufferSize = 32767; 2030cdf0e10cSrcweir Sequence < sal_Int8 > aSequence ( nBufferSize ); 2031cdf0e10cSrcweir Reference< XInputStream > aTempInput = aTempCont.openStream(); 2032cdf0e10cSrcweir 2033cdf0e10cSrcweir do 2034cdf0e10cSrcweir { 2035cdf0e10cSrcweir nRead = aTempInput->readBytes ( aSequence, nBufferSize ); 2036cdf0e10cSrcweir if ( nRead < nBufferSize ) 2037cdf0e10cSrcweir { 2038cdf0e10cSrcweir Sequence < sal_Int8 > aTempBuf ( aSequence.getConstArray(), nRead ); 2039cdf0e10cSrcweir rOutStream->writeBytes ( aTempBuf ); 2040cdf0e10cSrcweir } 2041cdf0e10cSrcweir else 2042cdf0e10cSrcweir rOutStream->writeBytes ( aSequence ); 2043cdf0e10cSrcweir } 2044cdf0e10cSrcweir while ( nRead == nBufferSize ); 2045cdf0e10cSrcweir 2046cdf0e10cSrcweir // remove temporary file 2047cdf0e10cSrcweir if ( pImp->pTempFile ) 2048cdf0e10cSrcweir { 2049cdf0e10cSrcweir pImp->pTempFile->EnableKillingFile( sal_True ); 2050cdf0e10cSrcweir delete pImp->pTempFile; 2051cdf0e10cSrcweir pImp->pTempFile = NULL; 2052cdf0e10cSrcweir } 2053cdf0e10cSrcweir } 2054cdf0e10cSrcweir catch( Exception& ) 2055cdf0e10cSrcweir {} 2056cdf0e10cSrcweir } 2057cdf0e10cSrcweir } 2058cdf0e10cSrcweir else 2059cdf0e10cSrcweir { 2060cdf0e10cSrcweir DBG_ERROR( "Illegal Output stream parameter!\n" ); 2061cdf0e10cSrcweir SetError( ERRCODE_IO_GENERAL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 2062cdf0e10cSrcweir } 2063cdf0e10cSrcweir 2064cdf0e10cSrcweir // free the reference 2065cdf0e10cSrcweir if ( pSet ) 2066cdf0e10cSrcweir pSet->ClearItem( SID_OUTPUTSTREAM ); 2067cdf0e10cSrcweir 2068cdf0e10cSrcweir return; 2069cdf0e10cSrcweir } 2070cdf0e10cSrcweir 2071cdf0e10cSrcweir GetContent(); 2072cdf0e10cSrcweir if ( !pImp->aContent.get().is() ) 2073cdf0e10cSrcweir { 2074cdf0e10cSrcweir eError = ERRCODE_IO_NOTEXISTS; 2075cdf0e10cSrcweir return; 2076cdf0e10cSrcweir } 2077cdf0e10cSrcweir 2078cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pSegmentSize, SfxInt32Item, SID_SEGMENTSIZE, sal_False); 2079cdf0e10cSrcweir if ( pSegmentSize ) 2080cdf0e10cSrcweir { 2081cdf0e10cSrcweir // this file must be stored into a disk spanned package 2082cdf0e10cSrcweir try 2083cdf0e10cSrcweir { 2084cdf0e10cSrcweir uno::Reference < embed::XStorage > xStor = comphelper::OStorageHelper::GetStorageFromURL( GetName(), 2085cdf0e10cSrcweir embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); 2086cdf0e10cSrcweir 2087cdf0e10cSrcweir // set segment size property; package will automatically be divided in pieces fitting 2088cdf0e10cSrcweir // into this size 2089cdf0e10cSrcweir ::com::sun::star::uno::Any aAny; 2090cdf0e10cSrcweir aAny <<= pSegmentSize->GetValue(); 2091cdf0e10cSrcweir 2092cdf0e10cSrcweir uno::Reference < beans::XPropertySet > xSet( pImp->xStorage, uno::UNO_QUERY ); 2093cdf0e10cSrcweir xSet->setPropertyValue( String::CreateFromAscii("SegmentSize"), aAny ); 2094cdf0e10cSrcweir 2095cdf0e10cSrcweir // copy the temporary storage into the disk spanned package 2096cdf0e10cSrcweir GetStorage()->copyToStorage( xStor ); 2097cdf0e10cSrcweir uno::Reference < embed::XTransactedObject > xTrans( pImp->xStorage, uno::UNO_QUERY ); 2098cdf0e10cSrcweir if ( xTrans.is() ) 2099cdf0e10cSrcweir xTrans->commit(); 2100cdf0e10cSrcweir 2101cdf0e10cSrcweir } 2102cdf0e10cSrcweir catch ( uno::Exception& ) 2103cdf0e10cSrcweir { 2104cdf0e10cSrcweir //TODO/MBA: error handling 2105cdf0e10cSrcweir } 2106cdf0e10cSrcweir return; 2107cdf0e10cSrcweir } 2108cdf0e10cSrcweir 2109cdf0e10cSrcweir INetURLObject aDest( GetURLObject() ); 2110cdf0e10cSrcweir 2111cdf0e10cSrcweir // source is the temp file written so far 2112cdf0e10cSrcweir INetURLObject aSource( aNameURL ); 2113cdf0e10cSrcweir 2114cdf0e10cSrcweir // a special case, an interaction handler should be used for 2115cdf0e10cSrcweir // authentication in case it is available 2116cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv; 2117cdf0e10cSrcweir Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = GetInteractionHandler(); 2118cdf0e10cSrcweir if (xInteractionHandler.is()) 2119cdf0e10cSrcweir xComEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, 2120cdf0e10cSrcweir Reference< ::com::sun::star::ucb::XProgressHandler >() ); 2121cdf0e10cSrcweir 2122cdf0e10cSrcweir if ( ::utl::LocalFileHelper::IsLocalFile( aDest.GetMainURL( INetURLObject::NO_DECODE ) ) || !aDest.removeSegment() ) 2123cdf0e10cSrcweir { 2124cdf0e10cSrcweir TransactedTransferForFS_Impl( aSource, aDest, xComEnv ); 2125cdf0e10cSrcweir } 2126cdf0e10cSrcweir else 2127cdf0e10cSrcweir { 2128cdf0e10cSrcweir // create content for the parent folder and call transfer on that content with the source content 2129cdf0e10cSrcweir // and the destination file name as parameters 2130cdf0e10cSrcweir ::ucbhelper::Content aSourceContent; 2131cdf0e10cSrcweir ::ucbhelper::Content aTransferContent; 2132cdf0e10cSrcweir 2133cdf0e10cSrcweir String aFileName = GetLongName(); 2134cdf0e10cSrcweir if ( !aFileName.Len() ) 2135cdf0e10cSrcweir aFileName = GetURLObject().getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 2136cdf0e10cSrcweir 2137cdf0e10cSrcweir try 2138cdf0e10cSrcweir { 2139cdf0e10cSrcweir aTransferContent = ::ucbhelper::Content( aDest.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); 2140cdf0e10cSrcweir } 2141cdf0e10cSrcweir catch (const ::com::sun::star::ucb::ContentCreationException& ex) 2142cdf0e10cSrcweir { 2143cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 2144cdf0e10cSrcweir if ( 2145cdf0e10cSrcweir (ex.eError == ::com::sun::star::ucb::ContentCreationError_NO_CONTENT_PROVIDER ) || 2146cdf0e10cSrcweir (ex.eError == ::com::sun::star::ucb::ContentCreationError_CONTENT_CREATION_FAILED) 2147cdf0e10cSrcweir ) 2148cdf0e10cSrcweir { 2149cdf0e10cSrcweir eError = ERRCODE_IO_NOTEXISTSPATH; 2150cdf0e10cSrcweir } 2151cdf0e10cSrcweir } 2152cdf0e10cSrcweir catch (const ::com::sun::star::uno::Exception&) 2153cdf0e10cSrcweir { 2154cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 2155cdf0e10cSrcweir } 2156cdf0e10cSrcweir 2157cdf0e10cSrcweir if ( !eError || (eError & ERRCODE_WARNING_MASK) ) 2158cdf0e10cSrcweir { 2159cdf0e10cSrcweir // free resources, otherwise the transfer may fail 2160cdf0e10cSrcweir if ( pImp->xStorage.is() ) 2161cdf0e10cSrcweir CloseStorage(); 2162cdf0e10cSrcweir 2163cdf0e10cSrcweir CloseStreams_Impl(); 2164cdf0e10cSrcweir 2165cdf0e10cSrcweir ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aSourceContent ); 2166cdf0e10cSrcweir 2167cdf0e10cSrcweir // check for external parameters that may customize the handling of NameClash situations 2168cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pRename, SfxBoolItem, SID_RENAME, sal_False ); 2169cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pOverWrite, SfxBoolItem, SID_OVERWRITE, sal_False ); 2170cdf0e10cSrcweir sal_Int32 nNameClash; 2171cdf0e10cSrcweir if ( pOverWrite && !pOverWrite->GetValue() ) 2172cdf0e10cSrcweir // argument says: never overwrite 2173cdf0e10cSrcweir nNameClash = NameClash::ERROR; 2174cdf0e10cSrcweir else if ( pRename && pRename->GetValue() ) 2175cdf0e10cSrcweir // argument says: rename file 2176cdf0e10cSrcweir nNameClash = NameClash::RENAME; 2177cdf0e10cSrcweir else 2178cdf0e10cSrcweir // default is overwrite existing files 2179cdf0e10cSrcweir nNameClash = NameClash::OVERWRITE; 2180cdf0e10cSrcweir 2181cdf0e10cSrcweir try 2182cdf0e10cSrcweir { 2183cdf0e10cSrcweir if (!aTransferContent.transferContent( aSourceContent, ::ucbhelper::InsertOperation_COPY, aFileName, nNameClash )) 2184cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 2185cdf0e10cSrcweir } 2186cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandAbortedException& ) 2187cdf0e10cSrcweir { 2188cdf0e10cSrcweir eError = ERRCODE_ABORT; 2189cdf0e10cSrcweir } 2190cdf0e10cSrcweir catch ( ::com::sun::star::ucb::CommandFailedException& ) 2191cdf0e10cSrcweir { 2192cdf0e10cSrcweir eError = ERRCODE_ABORT; 2193cdf0e10cSrcweir } 2194cdf0e10cSrcweir catch ( ::com::sun::star::ucb::InteractiveIOException& r ) 2195cdf0e10cSrcweir { 2196cdf0e10cSrcweir if ( r.Code == IOErrorCode_ACCESS_DENIED ) 2197cdf0e10cSrcweir eError = ERRCODE_IO_ACCESSDENIED; 2198cdf0e10cSrcweir else if ( r.Code == IOErrorCode_NOT_EXISTING ) 2199cdf0e10cSrcweir eError = ERRCODE_IO_NOTEXISTS; 2200cdf0e10cSrcweir else if ( r.Code == IOErrorCode_CANT_READ ) 2201cdf0e10cSrcweir eError = ERRCODE_IO_CANTREAD; 2202cdf0e10cSrcweir else 2203cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 2204cdf0e10cSrcweir } 2205cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 2206cdf0e10cSrcweir { 2207cdf0e10cSrcweir eError = ERRCODE_IO_GENERAL; 2208cdf0e10cSrcweir } 2209cdf0e10cSrcweir 2210cdf0e10cSrcweir // do not switch from temporary file in case of nonfile protocol 2211cdf0e10cSrcweir } 2212cdf0e10cSrcweir } 2213cdf0e10cSrcweir 2214cdf0e10cSrcweir if ( ( !eError || (eError & ERRCODE_WARNING_MASK) ) && !pImp->pTempFile ) 2215cdf0e10cSrcweir { 2216cdf0e10cSrcweir // without a TempFile the physical and logical name should be the same after successful transfer 2217cdf0e10cSrcweir ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), 2218cdf0e10cSrcweir aName ); 2219cdf0e10cSrcweir pImp->m_bSalvageMode = sal_False; 2220cdf0e10cSrcweir } 2221cdf0e10cSrcweir } 2222cdf0e10cSrcweir } 2223cdf0e10cSrcweir 2224cdf0e10cSrcweir //------------------------------------------------------------------ 2225cdf0e10cSrcweir void SfxMedium::DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent, 2226cdf0e10cSrcweir const String& aPrefix, 2227cdf0e10cSrcweir const String& aExtension, 2228cdf0e10cSrcweir const String& aDestDir ) 2229cdf0e10cSrcweir { 2230cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxMedium::DoInternalBackup_Impl( with destdir )" ); 2231cdf0e10cSrcweir 2232cdf0e10cSrcweir if ( pImp->m_aBackupURL.getLength() ) 2233cdf0e10cSrcweir return; // the backup was done already 2234cdf0e10cSrcweir 2235cdf0e10cSrcweir ::utl::TempFile aTransactTemp( aPrefix, &aExtension, &aDestDir ); 2236cdf0e10cSrcweir aTransactTemp.EnableKillingFile( sal_False ); 2237cdf0e10cSrcweir 2238cdf0e10cSrcweir INetURLObject aBackObj( aTransactTemp.GetURL() ); 2239cdf0e10cSrcweir ::rtl::OUString aBackupName = aBackObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 2240cdf0e10cSrcweir 2241cdf0e10cSrcweir Reference < ::com::sun::star::ucb::XCommandEnvironment > xDummyEnv; 2242cdf0e10cSrcweir ::ucbhelper::Content aBackupCont; 2243cdf0e10cSrcweir if( ::ucbhelper::Content::create( aDestDir, xDummyEnv, aBackupCont ) ) 2244cdf0e10cSrcweir { 2245cdf0e10cSrcweir try 2246cdf0e10cSrcweir { 2247cdf0e10cSrcweir if( aBackupCont.transferContent( aOriginalContent, 2248cdf0e10cSrcweir ::ucbhelper::InsertOperation_COPY, 2249cdf0e10cSrcweir aBackupName, 2250cdf0e10cSrcweir NameClash::OVERWRITE ) ) 2251cdf0e10cSrcweir { 2252cdf0e10cSrcweir pImp->m_aBackupURL = aBackObj.GetMainURL( INetURLObject::NO_DECODE ); 2253cdf0e10cSrcweir pImp->m_bRemoveBackup = sal_True; 2254cdf0e10cSrcweir } 2255cdf0e10cSrcweir } 2256cdf0e10cSrcweir catch( Exception& ) 2257cdf0e10cSrcweir {} 2258cdf0e10cSrcweir } 2259cdf0e10cSrcweir 2260cdf0e10cSrcweir if ( !pImp->m_aBackupURL.getLength() ) 2261cdf0e10cSrcweir aTransactTemp.EnableKillingFile( sal_True ); 2262cdf0e10cSrcweir } 2263cdf0e10cSrcweir 2264cdf0e10cSrcweir //------------------------------------------------------------------ 2265cdf0e10cSrcweir void SfxMedium::DoInternalBackup_Impl( const ::ucbhelper::Content& aOriginalContent ) 2266cdf0e10cSrcweir { 2267cdf0e10cSrcweir if ( pImp->m_aBackupURL.getLength() ) 2268cdf0e10cSrcweir return; // the backup was done already 2269cdf0e10cSrcweir 2270cdf0e10cSrcweir ::rtl::OUString aFileName = GetURLObject().getName( INetURLObject::LAST_SEGMENT, 2271cdf0e10cSrcweir true, 2272cdf0e10cSrcweir INetURLObject::NO_DECODE ); 2273cdf0e10cSrcweir 2274cdf0e10cSrcweir sal_Int32 nPrefixLen = aFileName.lastIndexOf( '.' ); 2275cdf0e10cSrcweir String aPrefix = ( nPrefixLen == -1 ) ? aFileName : aFileName.copy( 0, nPrefixLen ); 2276cdf0e10cSrcweir String aExtension = ( nPrefixLen == -1 ) ? String() : String(aFileName.copy( nPrefixLen )); 2277cdf0e10cSrcweir String aBakDir = SvtPathOptions().GetBackupPath(); 2278cdf0e10cSrcweir 2279cdf0e10cSrcweir DoInternalBackup_Impl( aOriginalContent, aPrefix, aExtension, aBakDir ); 2280cdf0e10cSrcweir 2281cdf0e10cSrcweir if ( !pImp->m_aBackupURL.getLength() ) 2282cdf0e10cSrcweir { 2283cdf0e10cSrcweir // the copiing to the backup catalog failed ( for example because 2284cdf0e10cSrcweir // of using an encrypted partition as target catalog ) 2285cdf0e10cSrcweir // since the user did not specify to make backup explicitly 2286cdf0e10cSrcweir // office should try to make backup in another place, 2287cdf0e10cSrcweir // target catalog does not look bad for this case ( and looks 2288cdf0e10cSrcweir // to be the only way for encrypted partitions ) 2289cdf0e10cSrcweir 2290cdf0e10cSrcweir INetURLObject aDest = GetURLObject(); 2291cdf0e10cSrcweir if ( aDest.removeSegment() ) 2292cdf0e10cSrcweir DoInternalBackup_Impl( aOriginalContent, aPrefix, aExtension, aDest.GetMainURL( INetURLObject::NO_DECODE ) ); 2293cdf0e10cSrcweir } 2294cdf0e10cSrcweir } 2295cdf0e10cSrcweir 2296cdf0e10cSrcweir 2297cdf0e10cSrcweir //------------------------------------------------------------------ 2298cdf0e10cSrcweir void SfxMedium::DoBackup_Impl() 2299cdf0e10cSrcweir { 2300cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mv76033) SfxMedium::DoBackup_Impl" ); 2301cdf0e10cSrcweir 2302cdf0e10cSrcweir // source file name is the logical name of this medium 2303cdf0e10cSrcweir INetURLObject aSource( GetURLObject() ); 2304cdf0e10cSrcweir 2305cdf0e10cSrcweir // there is nothing to backup in case source file does not exist 2306cdf0e10cSrcweir if ( !::utl::UCBContentHelper::IsDocument( aSource.GetMainURL( INetURLObject::NO_DECODE ) ) ) 2307cdf0e10cSrcweir return; 2308cdf0e10cSrcweir 2309cdf0e10cSrcweir sal_Bool bSuccess = sal_False; 2310cdf0e10cSrcweir 2311cdf0e10cSrcweir // get path for backups 2312cdf0e10cSrcweir String aBakDir = SvtPathOptions().GetBackupPath(); 2313cdf0e10cSrcweir if( aBakDir.Len() ) 2314cdf0e10cSrcweir { 2315cdf0e10cSrcweir // create content for the parent folder ( = backup folder ) 2316cdf0e10cSrcweir ::ucbhelper::Content aContent; 2317cdf0e10cSrcweir Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; 2318cdf0e10cSrcweir if( ::ucbhelper::Content::create( aBakDir, xEnv, aContent ) ) 2319cdf0e10cSrcweir { 2320cdf0e10cSrcweir // save as ".bak" file 2321cdf0e10cSrcweir INetURLObject aDest( aBakDir ); 2322cdf0e10cSrcweir aDest.insertName( aSource.getName() ); 2323cdf0e10cSrcweir aDest.setExtension( DEFINE_CONST_UNICODE( "bak" ) ); 2324cdf0e10cSrcweir String aFileName = aDest.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 2325cdf0e10cSrcweir 2326cdf0e10cSrcweir // create a content for the source file 2327cdf0e10cSrcweir ::ucbhelper::Content aSourceContent; 2328cdf0e10cSrcweir if ( ::ucbhelper::Content::create( aSource.GetMainURL( INetURLObject::NO_DECODE ), xEnv, aSourceContent ) ) 2329cdf0e10cSrcweir { 2330cdf0e10cSrcweir try 2331cdf0e10cSrcweir { 2332cdf0e10cSrcweir // do the transfer ( copy source file to backup dir ) 2333cdf0e10cSrcweir bSuccess = aContent.transferContent( aSourceContent, 2334cdf0e10cSrcweir ::ucbhelper::InsertOperation_COPY, 2335cdf0e10cSrcweir aFileName, 2336cdf0e10cSrcweir NameClash::OVERWRITE ); 2337cdf0e10cSrcweir if( bSuccess ) 2338cdf0e10cSrcweir { 2339cdf0e10cSrcweir pImp->m_aBackupURL = aDest.GetMainURL( INetURLObject::NO_DECODE ); 2340cdf0e10cSrcweir pImp->m_bRemoveBackup = sal_False; 2341cdf0e10cSrcweir } 2342cdf0e10cSrcweir } 2343cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 2344cdf0e10cSrcweir { 2345cdf0e10cSrcweir } 2346cdf0e10cSrcweir } 2347cdf0e10cSrcweir } 2348cdf0e10cSrcweir } 2349cdf0e10cSrcweir 2350cdf0e10cSrcweir if ( !bSuccess ) 2351cdf0e10cSrcweir { 2352cdf0e10cSrcweir eError = ERRCODE_SFX_CANTCREATEBACKUP; 2353cdf0e10cSrcweir } 2354cdf0e10cSrcweir } 2355cdf0e10cSrcweir 2356cdf0e10cSrcweir //------------------------------------------------------------------ 2357cdf0e10cSrcweir void SfxMedium::ClearBackup_Impl() 2358cdf0e10cSrcweir { 2359cdf0e10cSrcweir if( pImp->m_bRemoveBackup ) 2360cdf0e10cSrcweir { 2361cdf0e10cSrcweir // currently a document is always stored in a new medium, 2362cdf0e10cSrcweir // thus if a backup can not be removed the backup URL should not be cleaned 2363cdf0e10cSrcweir if ( pImp->m_aBackupURL.getLength() ) 2364cdf0e10cSrcweir { 2365cdf0e10cSrcweir if ( ::utl::UCBContentHelper::Kill( pImp->m_aBackupURL ) ) 2366cdf0e10cSrcweir // || !::utl::UCBContentHelper::IsDocument( pImp->m_aBackupURL ) ); 2367cdf0e10cSrcweir { 2368cdf0e10cSrcweir pImp->m_bRemoveBackup = sal_False; 2369cdf0e10cSrcweir pImp->m_aBackupURL = ::rtl::OUString(); 2370cdf0e10cSrcweir } 2371cdf0e10cSrcweir else 2372cdf0e10cSrcweir { 2373cdf0e10cSrcweir 2374cdf0e10cSrcweir DBG_ERROR("Couldn't remove backup file!"); 2375cdf0e10cSrcweir } 2376cdf0e10cSrcweir } 2377cdf0e10cSrcweir } 2378cdf0e10cSrcweir else 2379cdf0e10cSrcweir pImp->m_aBackupURL = ::rtl::OUString(); 2380cdf0e10cSrcweir } 2381cdf0e10cSrcweir 2382cdf0e10cSrcweir //---------------------------------------------------------------- 2383cdf0e10cSrcweir void SfxMedium::GetLockingStream_Impl() 2384cdf0e10cSrcweir { 2385cdf0e10cSrcweir if ( ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) 2386cdf0e10cSrcweir && !pImp->m_xLockingStream.is() ) 2387cdf0e10cSrcweir { 2388cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pWriteStreamItem, SfxUnoAnyItem, SID_STREAM, sal_False); 2389cdf0e10cSrcweir if ( pWriteStreamItem ) 2390cdf0e10cSrcweir pWriteStreamItem->GetValue() >>= pImp->m_xLockingStream; 2391cdf0e10cSrcweir 2392cdf0e10cSrcweir if ( !pImp->m_xLockingStream.is() ) 2393cdf0e10cSrcweir { 2394cdf0e10cSrcweir // open the original document 2395cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > xProps; 2396cdf0e10cSrcweir TransformItems( SID_OPENDOC, *GetItemSet(), xProps ); 2397cdf0e10cSrcweir comphelper::MediaDescriptor aMedium( xProps ); 2398cdf0e10cSrcweir 2399cdf0e10cSrcweir aMedium.addInputStreamOwnLock(); 2400cdf0e10cSrcweir 2401cdf0e10cSrcweir uno::Reference< io::XInputStream > xInputStream; 2402cdf0e10cSrcweir aMedium[comphelper::MediaDescriptor::PROP_STREAM()] >>= pImp->m_xLockingStream; 2403cdf0e10cSrcweir aMedium[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream; 2404cdf0e10cSrcweir 2405cdf0e10cSrcweir if ( !pImp->pTempFile && !aName.Len() ) 2406cdf0e10cSrcweir { 2407*30acf5e8Spfg // the medium is still based on the original file, it makes sense to initialize the streams 2408cdf0e10cSrcweir if ( pImp->m_xLockingStream.is() ) 2409cdf0e10cSrcweir pImp->xStream = pImp->m_xLockingStream; 2410cdf0e10cSrcweir 2411cdf0e10cSrcweir if ( xInputStream.is() ) 2412cdf0e10cSrcweir pImp->xInputStream = xInputStream; 2413cdf0e10cSrcweir 2414cdf0e10cSrcweir if ( !pImp->xInputStream.is() && pImp->xStream.is() ) 2415cdf0e10cSrcweir pImp->xInputStream = pImp->xStream->getInputStream(); 2416cdf0e10cSrcweir } 2417cdf0e10cSrcweir } 2418cdf0e10cSrcweir } 2419cdf0e10cSrcweir } 2420cdf0e10cSrcweir 2421cdf0e10cSrcweir //---------------------------------------------------------------- 2422cdf0e10cSrcweir void SfxMedium::GetMedium_Impl() 2423cdf0e10cSrcweir { 2424cdf0e10cSrcweir if ( !pInStream ) 2425cdf0e10cSrcweir { 2426cdf0e10cSrcweir pImp->bDownloadDone = sal_False; 2427cdf0e10cSrcweir Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = GetInteractionHandler(); 2428cdf0e10cSrcweir 2429cdf0e10cSrcweir //TODO/MBA: need support for SID_STREAM 2430cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pWriteStreamItem, SfxUnoAnyItem, SID_STREAM, sal_False); 2431cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pInStreamItem, SfxUnoAnyItem, SID_INPUTSTREAM, sal_False); 2432cdf0e10cSrcweir if ( pWriteStreamItem ) 2433cdf0e10cSrcweir { 2434cdf0e10cSrcweir pWriteStreamItem->GetValue() >>= pImp->xStream; 2435cdf0e10cSrcweir 2436cdf0e10cSrcweir if ( pInStreamItem ) 2437cdf0e10cSrcweir pInStreamItem->GetValue() >>= pImp->xInputStream; 2438cdf0e10cSrcweir 2439cdf0e10cSrcweir if ( !pImp->xInputStream.is() && pImp->xStream.is() ) 2440cdf0e10cSrcweir pImp->xInputStream = pImp->xStream->getInputStream(); 2441cdf0e10cSrcweir } 2442cdf0e10cSrcweir else if ( pInStreamItem ) 2443cdf0e10cSrcweir { 2444cdf0e10cSrcweir pInStreamItem->GetValue() >>= pImp->xInputStream; 2445cdf0e10cSrcweir } 2446cdf0e10cSrcweir else 2447cdf0e10cSrcweir { 2448cdf0e10cSrcweir uno::Sequence < beans::PropertyValue > xProps; 2449cdf0e10cSrcweir String aFileName; 2450cdf0e10cSrcweir if ( aName.Len() ) 2451cdf0e10cSrcweir { 2452cdf0e10cSrcweir if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aFileName ) ) 2453cdf0e10cSrcweir { 2454cdf0e10cSrcweir DBG_ERROR("Physical name not convertable!"); 2455cdf0e10cSrcweir } 2456cdf0e10cSrcweir } 2457cdf0e10cSrcweir else 2458cdf0e10cSrcweir aFileName = GetName(); 2459cdf0e10cSrcweir 2460cdf0e10cSrcweir // in case the temporary file exists the streams should be initialized from it, 2461cdf0e10cSrcweir // but the original MediaDescriptor should not be changed 2462cdf0e10cSrcweir sal_Bool bFromTempFile = ( pImp->pTempFile != NULL ); 2463cdf0e10cSrcweir 2464cdf0e10cSrcweir if ( !bFromTempFile ) 2465cdf0e10cSrcweir { 2466cdf0e10cSrcweir GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, aFileName ) ); 2467cdf0e10cSrcweir if( !(nStorOpenMode & STREAM_WRITE ) ) 2468cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 2469cdf0e10cSrcweir if (xInteractionHandler.is()) 2470cdf0e10cSrcweir GetItemSet()->Put( SfxUnoAnyItem( SID_INTERACTIONHANDLER, makeAny(xInteractionHandler) ) ); 2471cdf0e10cSrcweir } 2472cdf0e10cSrcweir 2473cdf0e10cSrcweir if ( m_xInputStreamToLoadFrom.is() ) 2474cdf0e10cSrcweir { 2475cdf0e10cSrcweir pImp->xInputStream = m_xInputStreamToLoadFrom; 2476cdf0e10cSrcweir pImp->xInputStream->skipBytes(0); 2477cdf0e10cSrcweir if(m_bIsReadOnly) 2478cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) ); 2479cdf0e10cSrcweir 2480cdf0e10cSrcweir // m_xInputStreamToLoadFrom = 0; 2481cdf0e10cSrcweir } 2482cdf0e10cSrcweir else 2483cdf0e10cSrcweir { 2484cdf0e10cSrcweir TransformItems( SID_OPENDOC, *GetItemSet(), xProps ); 2485cdf0e10cSrcweir comphelper::MediaDescriptor aMedium( xProps ); 2486cdf0e10cSrcweir 2487cdf0e10cSrcweir if ( pImp->m_xLockingStream.is() && !bFromTempFile ) 2488cdf0e10cSrcweir { 2489cdf0e10cSrcweir // the medium is not based on the temporary file, so the original stream can be used 2490cdf0e10cSrcweir pImp->xStream = pImp->m_xLockingStream; 2491cdf0e10cSrcweir } 2492cdf0e10cSrcweir else 2493cdf0e10cSrcweir { 2494cdf0e10cSrcweir if ( bFromTempFile ) 2495cdf0e10cSrcweir { 2496cdf0e10cSrcweir aMedium[comphelper::MediaDescriptor::PROP_URL()] <<= ::rtl::OUString( aFileName ); 2497cdf0e10cSrcweir aMedium.erase( comphelper::MediaDescriptor::PROP_READONLY() ); 2498cdf0e10cSrcweir aMedium.addInputStream(); 2499cdf0e10cSrcweir } 2500cdf0e10cSrcweir else if ( ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) 2501cdf0e10cSrcweir { 2502cdf0e10cSrcweir // use the special locking approach only for file URLs 2503cdf0e10cSrcweir aMedium.addInputStreamOwnLock(); 2504cdf0e10cSrcweir } 2505cdf0e10cSrcweir else 25069c0c1533SAndrea Pescetti { 25079c0c1533SAndrea Pescetti //add acheck for protocol, to see if it's http or https then add 25089c0c1533SAndrea Pescetti //the interecation handler to be used by the authentication dialog 25099c0c1533SAndrea Pescetti ::rtl::OUString aScheme = INetURLObject::GetScheme(GetURLObject().GetProtocol()); 25109c0c1533SAndrea Pescetti if( aScheme.equalsIgnoreAsciiCaseAscii( INET_HTTP_SCHEME ) || 25119c0c1533SAndrea Pescetti aScheme.equalsIgnoreAsciiCaseAscii( INET_HTTPS_SCHEME ) ) 25129c0c1533SAndrea Pescetti { 25139c0c1533SAndrea Pescetti aMedium[comphelper::MediaDescriptor::PROP_AUTHENTICATIONHANDLER()] <<= GetAuthenticationInteractionHandler(); 25149c0c1533SAndrea Pescetti } 2515cdf0e10cSrcweir aMedium.addInputStream(); 25169c0c1533SAndrea Pescetti } 2517cdf0e10cSrcweir 2518cdf0e10cSrcweir // the ReadOnly property set in aMedium is ignored 2519cdf0e10cSrcweir // the check is done in LockOrigFileOnDemand() for file and non-file URLs 2520cdf0e10cSrcweir 2521cdf0e10cSrcweir //TODO/MBA: what happens if property is not there?! 2522cdf0e10cSrcweir aMedium[comphelper::MediaDescriptor::PROP_STREAM()] >>= pImp->xStream; 2523cdf0e10cSrcweir aMedium[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= pImp->xInputStream; 2524cdf0e10cSrcweir } 2525cdf0e10cSrcweir 2526cdf0e10cSrcweir GetContent(); 2527cdf0e10cSrcweir if ( !pImp->xInputStream.is() && pImp->xStream.is() ) 2528cdf0e10cSrcweir pImp->xInputStream = pImp->xStream->getInputStream(); 2529cdf0e10cSrcweir } 2530cdf0e10cSrcweir 2531cdf0e10cSrcweir if ( !bFromTempFile ) 2532cdf0e10cSrcweir { 2533cdf0e10cSrcweir //TODO/MBA: need support for SID_STREAM 2534cdf0e10cSrcweir if ( pImp->xStream.is() ) 2535cdf0e10cSrcweir GetItemSet()->Put( SfxUsrAnyItem( SID_STREAM, makeAny( pImp->xStream ) ) ); 2536cdf0e10cSrcweir 2537cdf0e10cSrcweir GetItemSet()->Put( SfxUsrAnyItem( SID_INPUTSTREAM, makeAny( pImp->xInputStream ) ) ); 2538cdf0e10cSrcweir } 2539cdf0e10cSrcweir } 2540cdf0e10cSrcweir 2541cdf0e10cSrcweir //TODO/MBA: ErrorHandling - how to transport error from MediaDescriptor 2542cdf0e10cSrcweir if ( !GetError() && !pImp->xStream.is() && !pImp->xInputStream.is() ) 25433b5992cdSOliver-Rainer Wittmann { 2544cdf0e10cSrcweir SetError( ERRCODE_IO_ACCESSDENIED, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 25453b5992cdSOliver-Rainer Wittmann } 2546cdf0e10cSrcweir 2547cdf0e10cSrcweir if ( !GetError() ) 2548cdf0e10cSrcweir { 2549cdf0e10cSrcweir if ( pImp->xStream.is() ) 25503b5992cdSOliver-Rainer Wittmann { 2551cdf0e10cSrcweir pInStream = utl::UcbStreamHelper::CreateStream( pImp->xStream ); 25523b5992cdSOliver-Rainer Wittmann } 2553cdf0e10cSrcweir else if ( pImp->xInputStream.is() ) 25543b5992cdSOliver-Rainer Wittmann { 2555cdf0e10cSrcweir pInStream = utl::UcbStreamHelper::CreateStream( pImp->xInputStream ); 2556cdf0e10cSrcweir } 25573b5992cdSOliver-Rainer Wittmann } 2558cdf0e10cSrcweir 2559cdf0e10cSrcweir pImp->bDownloadDone = sal_True; 2560cdf0e10cSrcweir pImp->aDoneLink.ClearPendingCall(); 2561cdf0e10cSrcweir pImp->aDoneLink.Call( (void*) GetError() ); 2562cdf0e10cSrcweir } 2563cdf0e10cSrcweir } 2564cdf0e10cSrcweir 2565cdf0e10cSrcweir //---------------------------------------------------------------- 2566cdf0e10cSrcweir sal_Bool SfxMedium::IsRemote() 2567cdf0e10cSrcweir { 2568cdf0e10cSrcweir return bRemote; 2569cdf0e10cSrcweir } 2570cdf0e10cSrcweir 2571cdf0e10cSrcweir //------------------------------------------------------------------ 2572cdf0e10cSrcweir 2573cdf0e10cSrcweir void SfxMedium::SetUpdatePickList(sal_Bool bVal) 2574cdf0e10cSrcweir { 2575cdf0e10cSrcweir if(!pImp) 2576cdf0e10cSrcweir pImp = new SfxMedium_Impl( this ); 2577cdf0e10cSrcweir pImp->bUpdatePickList = bVal; 2578cdf0e10cSrcweir } 2579cdf0e10cSrcweir //------------------------------------------------------------------ 2580cdf0e10cSrcweir 2581cdf0e10cSrcweir sal_Bool SfxMedium::IsUpdatePickList() const 2582cdf0e10cSrcweir { 2583cdf0e10cSrcweir return pImp? pImp->bUpdatePickList: sal_True; 2584cdf0e10cSrcweir } 2585cdf0e10cSrcweir //---------------------------------------------------------------- 2586cdf0e10cSrcweir 2587cdf0e10cSrcweir void SfxMedium::SetDoneLink( const Link& rLink ) 2588cdf0e10cSrcweir { 2589cdf0e10cSrcweir pImp->aDoneLink = rLink; 2590cdf0e10cSrcweir } 2591cdf0e10cSrcweir 2592cdf0e10cSrcweir //---------------------------------------------------------------- 2593cdf0e10cSrcweir 2594cdf0e10cSrcweir void SfxMedium::SetDataAvailableLink( const Link& rLink ) 2595cdf0e10cSrcweir { 2596cdf0e10cSrcweir pImp->aAvailableLink = rLink; 2597cdf0e10cSrcweir } 2598cdf0e10cSrcweir 2599cdf0e10cSrcweir //---------------------------------------------------------------- 2600cdf0e10cSrcweir void SfxMedium::StartDownload() 2601cdf0e10cSrcweir { 2602cdf0e10cSrcweir GetInStream(); 2603cdf0e10cSrcweir } 2604cdf0e10cSrcweir 2605cdf0e10cSrcweir void SfxMedium::DownLoad( const Link& aLink ) 2606cdf0e10cSrcweir { 2607cdf0e10cSrcweir SetDoneLink( aLink ); 2608cdf0e10cSrcweir GetInStream(); 2609cdf0e10cSrcweir if ( pInStream && !aLink.IsSet() ) 2610cdf0e10cSrcweir { 2611cdf0e10cSrcweir while( !pImp->bDownloadDone ) 2612cdf0e10cSrcweir Application::Yield(); 2613cdf0e10cSrcweir } 2614cdf0e10cSrcweir } 2615cdf0e10cSrcweir 2616cdf0e10cSrcweir //------------------------------------------------------------------ 2617cdf0e10cSrcweir void SfxMedium::Init_Impl() 2618cdf0e10cSrcweir /* [Beschreibung] 2619cdf0e10cSrcweir Setzt in den Logischen Namen eine gueltige ::com::sun::star::util::URL (Falls zuvor ein Filename 2620cdf0e10cSrcweir drin war) und setzt den physikalschen Namen auf den Filenamen, falls 2621cdf0e10cSrcweir vorhanden. 2622cdf0e10cSrcweir */ 2623cdf0e10cSrcweir 2624cdf0e10cSrcweir { 2625cdf0e10cSrcweir Reference< XOutputStream > rOutStream; 2626cdf0e10cSrcweir 2627cdf0e10cSrcweir // TODO/LATER: handle lifetime of storages 2628cdf0e10cSrcweir pImp->bDisposeStorage = sal_False; 2629cdf0e10cSrcweir 2630cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False); 2631cdf0e10cSrcweir if ( pSalvageItem && !pSalvageItem->GetValue().Len() ) 2632cdf0e10cSrcweir { 2633cdf0e10cSrcweir pSalvageItem = NULL; 2634cdf0e10cSrcweir pSet->ClearItem( SID_DOC_SALVAGE ); 2635cdf0e10cSrcweir } 2636cdf0e10cSrcweir 2637cdf0e10cSrcweir if( aLogicName.Len() ) 2638cdf0e10cSrcweir { 2639cdf0e10cSrcweir INetURLObject aUrl( aLogicName ); 2640cdf0e10cSrcweir INetProtocol eProt = aUrl.GetProtocol(); 2641cdf0e10cSrcweir if ( eProt == INET_PROT_NOT_VALID ) 2642cdf0e10cSrcweir { 2643cdf0e10cSrcweir DBG_ERROR ( "Unknown protocol!" ); 2644cdf0e10cSrcweir } 2645cdf0e10cSrcweir else 2646cdf0e10cSrcweir { 2647cdf0e10cSrcweir if ( aUrl.HasMark() ) 2648cdf0e10cSrcweir { 2649cdf0e10cSrcweir aLogicName = aUrl.GetURLNoMark( INetURLObject::NO_DECODE ); 2650cdf0e10cSrcweir GetItemSet()->Put( SfxStringItem( SID_JUMPMARK, aUrl.GetMark() ) ); 2651cdf0e10cSrcweir } 2652cdf0e10cSrcweir 2653cdf0e10cSrcweir // try to convert the URL into a physical name - but never change a physical name 2654cdf0e10cSrcweir // physical name may be set if the logical name is changed after construction 2655cdf0e10cSrcweir if ( !aName.Len() ) 2656cdf0e10cSrcweir ::utl::LocalFileHelper::ConvertURLToPhysicalName( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), aName ); 2657cdf0e10cSrcweir else { 2658cdf0e10cSrcweir DBG_ASSERT( pSalvageItem, "Suspicious change of logical name!" ); 2659cdf0e10cSrcweir } 2660cdf0e10cSrcweir } 2661cdf0e10cSrcweir } 2662cdf0e10cSrcweir 2663cdf0e10cSrcweir if ( pSalvageItem && pSalvageItem->GetValue().Len() ) 2664cdf0e10cSrcweir { 2665cdf0e10cSrcweir aLogicName = pSalvageItem->GetValue(); 2666cdf0e10cSrcweir DELETEZ( pURLObj ); 2667cdf0e10cSrcweir pImp->m_bSalvageMode = sal_True; 2668cdf0e10cSrcweir } 2669cdf0e10cSrcweir 2670cdf0e10cSrcweir // in case output stream is by mistake here 2671cdf0e10cSrcweir // clear the reference 2672cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pOutStreamItem, SfxUnoAnyItem, SID_OUTPUTSTREAM, sal_False); 2673cdf0e10cSrcweir if( pOutStreamItem 2674cdf0e10cSrcweir && ( !( pOutStreamItem->GetValue() >>= rOutStream ) 2675cdf0e10cSrcweir || !aLogicName.CompareToAscii( "private:stream", 14 ) == COMPARE_EQUAL ) ) 2676cdf0e10cSrcweir { 2677cdf0e10cSrcweir pSet->ClearItem( SID_OUTPUTSTREAM ); 2678cdf0e10cSrcweir DBG_ERROR( "Unexpected Output stream parameter!\n" ); 2679cdf0e10cSrcweir } 2680cdf0e10cSrcweir 2681cdf0e10cSrcweir if ( aLogicName.Len() ) 2682cdf0e10cSrcweir { 2683cdf0e10cSrcweir // if the logic name is set it should be set in MediaDescriptor as well 2684cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False ); 2685cdf0e10cSrcweir if ( !pFileNameItem ) 2686cdf0e10cSrcweir { 2687cdf0e10cSrcweir // let the ItemSet be created if necessary 2688cdf0e10cSrcweir GetItemSet()->Put( SfxStringItem( SID_FILE_NAME, INetURLObject( aLogicName ).GetMainURL( INetURLObject::NO_DECODE ) ) ); 2689cdf0e10cSrcweir } 2690cdf0e10cSrcweir } 2691cdf0e10cSrcweir 2692cdf0e10cSrcweir SetIsRemote_Impl(); 2693cdf0e10cSrcweir } 2694cdf0e10cSrcweir 2695cdf0e10cSrcweir //------------------------------------------------------------------ 2696cdf0e10cSrcweir SfxMedium::SfxMedium() 2697cdf0e10cSrcweir : IMPL_CTOR( sal_False, 0 ), // bRoot, pURLObj 2698cdf0e10cSrcweir 2699cdf0e10cSrcweir pFilter(0), 2700cdf0e10cSrcweir pSet(0), 2701cdf0e10cSrcweir pImp(new SfxMedium_Impl( this )) 2702cdf0e10cSrcweir { 2703cdf0e10cSrcweir Init_Impl(); 2704cdf0e10cSrcweir } 2705cdf0e10cSrcweir //------------------------------------------------------------------ 2706cdf0e10cSrcweir 2707cdf0e10cSrcweir SfxMedium::SfxMedium( const SfxMedium& rMedium, sal_Bool bTemporary ) 2708cdf0e10cSrcweir : SvRefBase(), 2709cdf0e10cSrcweir IMPL_CTOR( sal_True, // bRoot, pURLObj 2710cdf0e10cSrcweir rMedium.pURLObj ? new INetURLObject(*rMedium.pURLObj) : 0 ), 2711cdf0e10cSrcweir pImp(new SfxMedium_Impl( this )) 2712cdf0e10cSrcweir { 2713cdf0e10cSrcweir bDirect = rMedium.IsDirect(); 2714cdf0e10cSrcweir nStorOpenMode = rMedium.GetOpenMode(); 2715cdf0e10cSrcweir if ( !bTemporary ) 2716cdf0e10cSrcweir aName = rMedium.aName; 2717cdf0e10cSrcweir 2718cdf0e10cSrcweir pImp->bIsTemp = bTemporary; 2719cdf0e10cSrcweir DBG_ASSERT( ! rMedium.pImp->bIsTemp, "Temporaeres Medium darf nicht kopiert werden" ); 2720cdf0e10cSrcweir aLogicName = rMedium.aLogicName; 2721cdf0e10cSrcweir pSet = rMedium.GetItemSet() ? new SfxItemSet(*rMedium.GetItemSet()) : 0; 2722cdf0e10cSrcweir pFilter = rMedium.pFilter; 2723cdf0e10cSrcweir Init_Impl(); 2724cdf0e10cSrcweir if( bTemporary ) 2725cdf0e10cSrcweir CreateTempFile( sal_True ); 2726cdf0e10cSrcweir } 2727cdf0e10cSrcweir 2728cdf0e10cSrcweir //------------------------------------------------------------------ 2729cdf0e10cSrcweir 2730cdf0e10cSrcweir void SfxMedium::UseInteractionHandler( sal_Bool bUse ) 2731cdf0e10cSrcweir { 2732cdf0e10cSrcweir pImp->bAllowDefaultIntHdl = bUse; 2733cdf0e10cSrcweir } 2734cdf0e10cSrcweir 2735cdf0e10cSrcweir //------------------------------------------------------------------ 2736cdf0e10cSrcweir 2737cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > 27389c0c1533SAndrea Pescetti SfxMedium::GetAuthenticationInteractionHandler() 27399c0c1533SAndrea Pescetti { 27409c0c1533SAndrea Pescetti // search a possible existing handler inside cached item set 27419c0c1533SAndrea Pescetti if ( pSet ) 27429c0c1533SAndrea Pescetti { 27439c0c1533SAndrea Pescetti ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xHandler; 27449c0c1533SAndrea Pescetti SFX_ITEMSET_ARG( pSet, pHandler, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False); 27459c0c1533SAndrea Pescetti if ( pHandler && (pHandler->GetValue() >>= xHandler) && xHandler.is() ) 27469c0c1533SAndrea Pescetti return xHandler; 27479c0c1533SAndrea Pescetti } 27489c0c1533SAndrea Pescetti 27499c0c1533SAndrea Pescetti // otherwhise return cached default handler ... if it exist. 27509c0c1533SAndrea Pescetti if ( pImp->xCredentialInteraction.is() ) 27519c0c1533SAndrea Pescetti return pImp->xCredentialInteraction; 27529c0c1533SAndrea Pescetti 27539c0c1533SAndrea Pescetti // create default handler and cache it! 27549c0c1533SAndrea Pescetti ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); 27559c0c1533SAndrea Pescetti if ( xFactory.is() ) 27569c0c1533SAndrea Pescetti { 27579c0c1533SAndrea Pescetti pImp->xCredentialInteraction = ::com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler >( 27589c0c1533SAndrea Pescetti xFactory->createInstance( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ), ::com::sun::star::uno::UNO_QUERY ); 27599c0c1533SAndrea Pescetti return pImp->xCredentialInteraction; 27609c0c1533SAndrea Pescetti } 27619c0c1533SAndrea Pescetti 27629c0c1533SAndrea Pescetti return ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >(); 27639c0c1533SAndrea Pescetti } 27649c0c1533SAndrea Pescetti 27659c0c1533SAndrea Pescetti //------------------------------------------------------------------ 27669c0c1533SAndrea Pescetti 27679c0c1533SAndrea Pescetti ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > 2768cdf0e10cSrcweir SfxMedium::GetInteractionHandler() 2769cdf0e10cSrcweir { 277086e1cf34SPedro Giffuni // if interaction isn't allowed explicitly ... return empty reference! 2771cdf0e10cSrcweir if ( !pImp->bUseInteractionHandler ) 2772cdf0e10cSrcweir return ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >(); 2773cdf0e10cSrcweir 2774cdf0e10cSrcweir // search a possible existing handler inside cached item set 2775cdf0e10cSrcweir if ( pSet ) 2776cdf0e10cSrcweir { 2777cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > xHandler; 2778cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pHandler, SfxUnoAnyItem, SID_INTERACTIONHANDLER, sal_False); 2779cdf0e10cSrcweir if ( pHandler && (pHandler->GetValue() >>= xHandler) && xHandler.is() ) 2780cdf0e10cSrcweir return xHandler; 2781cdf0e10cSrcweir } 2782cdf0e10cSrcweir 278386e1cf34SPedro Giffuni // if default interaction isn't allowed explicitly ... return empty reference! 2784cdf0e10cSrcweir if ( !pImp->bAllowDefaultIntHdl ) 2785cdf0e10cSrcweir return ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >(); 2786cdf0e10cSrcweir 2787cdf0e10cSrcweir // otherwhise return cached default handler ... if it exist. 2788cdf0e10cSrcweir if ( pImp->xInteraction.is() ) 2789cdf0e10cSrcweir return pImp->xInteraction; 2790cdf0e10cSrcweir 2791cdf0e10cSrcweir // create default handler and cache it! 2792cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); 2793cdf0e10cSrcweir if ( xFactory.is() ) 2794cdf0e10cSrcweir { 27959c0c1533SAndrea Pescetti pImp->xInteraction = ::com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler >( 27969c0c1533SAndrea Pescetti xFactory->createInstance( DEFINE_CONST_UNICODE("com.sun.star.task.InteractionHandler") ), ::com::sun::star::uno::UNO_QUERY ); 2797cdf0e10cSrcweir return pImp->xInteraction; 2798cdf0e10cSrcweir } 2799cdf0e10cSrcweir 2800cdf0e10cSrcweir return ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >(); 2801cdf0e10cSrcweir } 2802cdf0e10cSrcweir 2803cdf0e10cSrcweir //---------------------------------------------------------------- 2804cdf0e10cSrcweir 2805cdf0e10cSrcweir void SfxMedium::SetFilter( const SfxFilter* pFilterP, sal_Bool /*bResetOrig*/ ) 2806cdf0e10cSrcweir { 2807cdf0e10cSrcweir pFilter = pFilterP; 2808cdf0e10cSrcweir pImp->nFileVersion = 0; 2809cdf0e10cSrcweir } 2810cdf0e10cSrcweir 2811cdf0e10cSrcweir //---------------------------------------------------------------- 2812cdf0e10cSrcweir 2813cdf0e10cSrcweir const SfxFilter* SfxMedium::GetOrigFilter( sal_Bool bNotCurrent ) const 2814cdf0e10cSrcweir { 2815cdf0e10cSrcweir return ( pImp->pOrigFilter || bNotCurrent ) ? pImp->pOrigFilter : pFilter; 2816cdf0e10cSrcweir } 2817cdf0e10cSrcweir 2818cdf0e10cSrcweir //---------------------------------------------------------------- 2819cdf0e10cSrcweir 2820cdf0e10cSrcweir void SfxMedium::SetOrigFilter_Impl( const SfxFilter* pOrigFilter ) 2821cdf0e10cSrcweir { 2822cdf0e10cSrcweir pImp->pOrigFilter = pOrigFilter; 2823cdf0e10cSrcweir } 2824cdf0e10cSrcweir 2825cdf0e10cSrcweir //------------------------------------------------------------------ 2826cdf0e10cSrcweir 2827cdf0e10cSrcweir sal_uInt32 SfxMedium::CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bWriter ) 2828cdf0e10cSrcweir { 2829cdf0e10cSrcweir sal_uInt32 nHash = 0; 2830cdf0e10cSrcweir 2831cdf0e10cSrcweir if ( aPasswd.getLength() ) 2832cdf0e10cSrcweir { 2833cdf0e10cSrcweir if ( bWriter ) 2834cdf0e10cSrcweir { 2835cdf0e10cSrcweir nHash = ::comphelper::DocPasswordHelper::GetWordHashAsUINT32( aPasswd ); 2836cdf0e10cSrcweir } 2837cdf0e10cSrcweir else 2838cdf0e10cSrcweir { 2839cdf0e10cSrcweir rtl_TextEncoding nEncoding = RTL_TEXTENCODING_UTF8; 2840cdf0e10cSrcweir 2841cdf0e10cSrcweir // if the MS-filter should be used 2842cdf0e10cSrcweir // use the inconsistent algorithm to find the encoding specified by MS 2843cdf0e10cSrcweir nEncoding = osl_getThreadTextEncoding(); 2844cdf0e10cSrcweir switch( nEncoding ) 2845cdf0e10cSrcweir { 2846cdf0e10cSrcweir case RTL_TEXTENCODING_ISO_8859_15: 2847cdf0e10cSrcweir case RTL_TEXTENCODING_MS_874: 2848cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1250: 2849cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1251: 2850cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1252: 2851cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1253: 2852cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1254: 2853cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1255: 2854cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1256: 2855cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1257: 2856cdf0e10cSrcweir case RTL_TEXTENCODING_MS_1258: 2857cdf0e10cSrcweir case RTL_TEXTENCODING_SHIFT_JIS: 2858cdf0e10cSrcweir case RTL_TEXTENCODING_GB_2312: 2859cdf0e10cSrcweir case RTL_TEXTENCODING_BIG5: 2860cdf0e10cSrcweir // in case the system uses an encoding from the list above, it should be used 2861cdf0e10cSrcweir break; 2862cdf0e10cSrcweir 2863cdf0e10cSrcweir default: 2864cdf0e10cSrcweir // in case other encoding is used, use one of the encodings from the list 2865cdf0e10cSrcweir nEncoding = RTL_TEXTENCODING_MS_1250; 2866cdf0e10cSrcweir break; 2867cdf0e10cSrcweir } 2868cdf0e10cSrcweir 2869cdf0e10cSrcweir nHash = ::comphelper::DocPasswordHelper::GetXLHashAsUINT16( aPasswd, nEncoding ); 2870cdf0e10cSrcweir } 2871cdf0e10cSrcweir } 2872cdf0e10cSrcweir 2873cdf0e10cSrcweir return nHash; 2874cdf0e10cSrcweir } 2875cdf0e10cSrcweir 2876cdf0e10cSrcweir //------------------------------------------------------------------ 2877cdf0e10cSrcweir 2878cdf0e10cSrcweir void SfxMedium::Close() 2879cdf0e10cSrcweir { 2880cdf0e10cSrcweir if ( pImp->xStorage.is() ) 2881cdf0e10cSrcweir { 2882cdf0e10cSrcweir // don't close the streams if they belong to the 2883cdf0e10cSrcweir // storage 2884cdf0e10cSrcweir //TODO/MBA: how to?! Do we need the flag?! 2885cdf0e10cSrcweir /* 2886cdf0e10cSrcweir const SvStream *pStream = aStorage->GetSvStream(); 2887cdf0e10cSrcweir if ( pStream && pStream == pInStream ) 2888cdf0e10cSrcweir { 2889cdf0e10cSrcweir CloseZipStorage_Impl(); 2890cdf0e10cSrcweir pInStream = NULL; 2891cdf0e10cSrcweir pImp->xInputStream = Reference < XInputStream >(); 2892cdf0e10cSrcweir pImp->xLockBytes.Clear(); 2893cdf0e10cSrcweir if ( pSet ) 2894cdf0e10cSrcweir pSet->ClearItem( SID_INPUTSTREAM ); 2895cdf0e10cSrcweir aStorage->SetDeleteStream( sal_True ); 2896cdf0e10cSrcweir } 2897cdf0e10cSrcweir else if ( pStream && pStream == pOutStream ) 2898cdf0e10cSrcweir { 2899cdf0e10cSrcweir pOutStream = NULL; 2900cdf0e10cSrcweir aStorage->SetDeleteStream( sal_True ); 2901cdf0e10cSrcweir } */ 2902cdf0e10cSrcweir 2903cdf0e10cSrcweir CloseStorage(); 2904cdf0e10cSrcweir } 2905cdf0e10cSrcweir 2906cdf0e10cSrcweir CloseStreams_Impl(); 2907cdf0e10cSrcweir 2908cdf0e10cSrcweir UnlockFile( sal_False ); 2909cdf0e10cSrcweir } 2910cdf0e10cSrcweir 2911cdf0e10cSrcweir void SfxMedium::CloseAndRelease() 2912cdf0e10cSrcweir { 2913cdf0e10cSrcweir if ( pImp->xStorage.is() ) 2914cdf0e10cSrcweir { 2915cdf0e10cSrcweir // don't close the streams if they belong to the 2916cdf0e10cSrcweir // storage 2917cdf0e10cSrcweir //TODO/MBA: how to?! Do we need the flag?! 2918cdf0e10cSrcweir /* 2919cdf0e10cSrcweir const SvStream *pStream = aStorage->GetSvStream(); 2920cdf0e10cSrcweir if ( pStream && pStream == pInStream ) 2921cdf0e10cSrcweir { 2922cdf0e10cSrcweir CloseZipStorage_Impl(); 2923cdf0e10cSrcweir pInStream = NULL; 2924cdf0e10cSrcweir pImp->xInputStream = Reference < XInputStream >(); 2925cdf0e10cSrcweir pImp->xLockBytes.Clear(); 2926cdf0e10cSrcweir if ( pSet ) 2927cdf0e10cSrcweir pSet->ClearItem( SID_INPUTSTREAM ); 2928cdf0e10cSrcweir aStorage->SetDeleteStream( sal_True ); 2929cdf0e10cSrcweir } 2930cdf0e10cSrcweir else if ( pStream && pStream == pOutStream ) 2931cdf0e10cSrcweir { 2932cdf0e10cSrcweir pOutStream = NULL; 2933cdf0e10cSrcweir aStorage->SetDeleteStream( sal_True ); 2934cdf0e10cSrcweir } */ 2935cdf0e10cSrcweir 2936cdf0e10cSrcweir CloseStorage(); 2937cdf0e10cSrcweir } 2938cdf0e10cSrcweir 2939cdf0e10cSrcweir CloseAndReleaseStreams_Impl(); 2940cdf0e10cSrcweir 2941cdf0e10cSrcweir UnlockFile( sal_True ); 2942cdf0e10cSrcweir } 2943cdf0e10cSrcweir 2944cdf0e10cSrcweir void SfxMedium::UnlockFile( sal_Bool bReleaseLockStream ) 2945cdf0e10cSrcweir { 29469c0c1533SAndrea Pescetti //->i126305 29479c0c1533SAndrea Pescetti //check if the file is local 29489c0c1533SAndrea Pescetti if ( ::utl::LocalFileHelper::IsLocalFile( aLogicName ) ) 29499c0c1533SAndrea Pescetti { 29509c0c1533SAndrea Pescetti //<-i126305 2951cdf0e10cSrcweir if ( pImp->m_xLockingStream.is() ) 2952cdf0e10cSrcweir { 2953cdf0e10cSrcweir if ( bReleaseLockStream ) 2954cdf0e10cSrcweir { 2955cdf0e10cSrcweir try 2956cdf0e10cSrcweir { 2957cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = pImp->m_xLockingStream->getInputStream(); 2958cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutStream = pImp->m_xLockingStream->getOutputStream(); 2959cdf0e10cSrcweir if ( xInStream.is() ) 2960cdf0e10cSrcweir xInStream->closeInput(); 2961cdf0e10cSrcweir if ( xOutStream.is() ) 2962cdf0e10cSrcweir xOutStream->closeOutput(); 2963cdf0e10cSrcweir } 2964cdf0e10cSrcweir catch( uno::Exception& ) 2965cdf0e10cSrcweir {} 2966cdf0e10cSrcweir } 2967cdf0e10cSrcweir 2968cdf0e10cSrcweir pImp->m_xLockingStream = uno::Reference< io::XStream >(); 2969cdf0e10cSrcweir } 2970cdf0e10cSrcweir 2971cdf0e10cSrcweir if ( pImp->m_bLocked ) 2972cdf0e10cSrcweir { 2973cdf0e10cSrcweir try 2974cdf0e10cSrcweir { 2975cdf0e10cSrcweir pImp->m_bLocked = sal_False; 2976cdf0e10cSrcweir ::svt::DocumentLockFile aLockFile( aLogicName ); 2977cdf0e10cSrcweir // TODO/LATER: A warning could be shown in case the file is not the own one 2978cdf0e10cSrcweir aLockFile.RemoveFile(); 2979cdf0e10cSrcweir } 2980cdf0e10cSrcweir catch( uno::Exception& ) 2981cdf0e10cSrcweir {} 2982cdf0e10cSrcweir } 29839c0c1533SAndrea Pescetti //->i126305 29849c0c1533SAndrea Pescetti } 29859c0c1533SAndrea Pescetti else 29869c0c1533SAndrea Pescetti { 29879c0c1533SAndrea Pescetti //not local, check if webdav 29889c0c1533SAndrea Pescetti ::rtl::OUString aScheme = INetURLObject::GetScheme(GetURLObject().GetProtocol()); 29899c0c1533SAndrea Pescetti if( aScheme.equalsIgnoreAsciiCaseAscii( INET_HTTP_SCHEME ) || 29909c0c1533SAndrea Pescetti aScheme.equalsIgnoreAsciiCaseAscii( INET_HTTPS_SCHEME ) ) 29919c0c1533SAndrea Pescetti { 29929c0c1533SAndrea Pescetti if ( pImp->m_bLocked ) 29939c0c1533SAndrea Pescetti { 29949c0c1533SAndrea Pescetti // an interaction handler should be used for authentication 29959c0c1533SAndrea Pescetti try { 29969c0c1533SAndrea Pescetti Reference< ::com::sun::star::task::XInteractionHandler > xHandler = GetAuthenticationInteractionHandler(); 29979c0c1533SAndrea Pescetti Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv; 29989c0c1533SAndrea Pescetti xComEnv = new ::ucbhelper::CommandEnvironment( xHandler, 29999c0c1533SAndrea Pescetti Reference< ::com::sun::star::ucb::XProgressHandler >() ); 30009c0c1533SAndrea Pescetti ::ucbhelper::Content aContentToUnlock( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), xComEnv); 30019c0c1533SAndrea Pescetti pImp->m_bLocked = sal_False; 30029c0c1533SAndrea Pescetti aContentToUnlock.unlock(); 30039c0c1533SAndrea Pescetti } 30049c0c1533SAndrea Pescetti catch (ucb::InteractiveNetworkReadException& e) 30059c0c1533SAndrea Pescetti { 30069c0c1533SAndrea Pescetti //signalled when this resource can not be unlocked, for whatever reason 30079c0c1533SAndrea Pescetti } 30089c0c1533SAndrea Pescetti catch( uno::Exception& ) 30099c0c1533SAndrea Pescetti {} 30109c0c1533SAndrea Pescetti } 30119c0c1533SAndrea Pescetti } 30129c0c1533SAndrea Pescetti } 30139c0c1533SAndrea Pescetti //<-i126305 3014cdf0e10cSrcweir } 3015cdf0e10cSrcweir 3016cdf0e10cSrcweir void SfxMedium::CloseAndReleaseStreams_Impl() 3017cdf0e10cSrcweir { 3018cdf0e10cSrcweir CloseZipStorage_Impl(); 3019cdf0e10cSrcweir 3020cdf0e10cSrcweir uno::Reference< io::XInputStream > xInToClose = pImp->xInputStream; 3021cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutToClose; 3022cdf0e10cSrcweir if ( pImp->xStream.is() ) 3023cdf0e10cSrcweir { 3024cdf0e10cSrcweir xOutToClose = pImp->xStream->getOutputStream(); 3025cdf0e10cSrcweir 3026cdf0e10cSrcweir // if the locking stream is closed here the related member should be cleaned 3027cdf0e10cSrcweir if ( pImp->xStream == pImp->m_xLockingStream ) 3028cdf0e10cSrcweir pImp->m_xLockingStream = uno::Reference< io::XStream >(); 3029cdf0e10cSrcweir } 3030cdf0e10cSrcweir 3031cdf0e10cSrcweir // The probably exsisting SvStream wrappers should be closed first 3032cdf0e10cSrcweir CloseStreams_Impl(); 3033cdf0e10cSrcweir 3034cdf0e10cSrcweir // in case of salvage mode the storage is based on the streams 3035cdf0e10cSrcweir if ( !pImp->m_bSalvageMode ) 3036cdf0e10cSrcweir { 3037cdf0e10cSrcweir try 3038cdf0e10cSrcweir { 3039cdf0e10cSrcweir if ( xInToClose.is() ) 3040cdf0e10cSrcweir xInToClose->closeInput(); 3041cdf0e10cSrcweir if ( xOutToClose.is() ) 3042cdf0e10cSrcweir xOutToClose->closeOutput(); 3043cdf0e10cSrcweir } 3044cdf0e10cSrcweir catch ( uno::Exception& ) 3045cdf0e10cSrcweir { 3046cdf0e10cSrcweir } 3047cdf0e10cSrcweir } 3048cdf0e10cSrcweir } 3049cdf0e10cSrcweir 3050cdf0e10cSrcweir //------------------------------------------------------------------ 3051cdf0e10cSrcweir void SfxMedium::CloseStreams_Impl() 3052cdf0e10cSrcweir { 3053cdf0e10cSrcweir CloseInStream_Impl(); 3054cdf0e10cSrcweir CloseOutStream_Impl(); 3055cdf0e10cSrcweir 3056cdf0e10cSrcweir if ( pSet ) 3057cdf0e10cSrcweir pSet->ClearItem( SID_CONTENT ); 3058cdf0e10cSrcweir 3059cdf0e10cSrcweir pImp->aContent = ::ucbhelper::Content(); 3060cdf0e10cSrcweir } 3061cdf0e10cSrcweir 3062cdf0e10cSrcweir //------------------------------------------------------------------ 3063cdf0e10cSrcweir 3064cdf0e10cSrcweir void SfxMedium::RefreshName_Impl() 3065cdf0e10cSrcweir { 3066cdf0e10cSrcweir #if 0 //(dv) 3067cdf0e10cSrcweir if ( pImp->aContent.get().is() ) 3068cdf0e10cSrcweir { 3069cdf0e10cSrcweir String aNameP = pImp->xAnchor->GetViewURL(); 3070cdf0e10cSrcweir pImp->aOrigURL = aNameP; 3071cdf0e10cSrcweir aLogicName = aNameP; 3072cdf0e10cSrcweir DELETEZ( pURLObj ); 3073cdf0e10cSrcweir if (aLogicName.Len()) 3074cdf0e10cSrcweir aLogicName = GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); 3075cdf0e10cSrcweir SetIsRemote_Impl(); 3076cdf0e10cSrcweir } 3077cdf0e10cSrcweir #endif //(dv) 3078cdf0e10cSrcweir } 3079cdf0e10cSrcweir 3080cdf0e10cSrcweir void SfxMedium::SetIsRemote_Impl() 3081cdf0e10cSrcweir { 3082cdf0e10cSrcweir INetURLObject aObj( GetName() ); 3083cdf0e10cSrcweir switch( aObj.GetProtocol() ) 3084cdf0e10cSrcweir { 3085cdf0e10cSrcweir case INET_PROT_FTP: 3086cdf0e10cSrcweir case INET_PROT_HTTP: 3087cdf0e10cSrcweir case INET_PROT_HTTPS: 3088cdf0e10cSrcweir case INET_PROT_POP3: 3089cdf0e10cSrcweir case INET_PROT_NEWS: 3090cdf0e10cSrcweir case INET_PROT_IMAP: 3091cdf0e10cSrcweir // case INET_PROT_OUT: 3092cdf0e10cSrcweir case INET_PROT_VIM: 3093cdf0e10cSrcweir bRemote = sal_True; break; 3094cdf0e10cSrcweir default: 3095cdf0e10cSrcweir bRemote = ( GetName().CompareToAscii( "private:msgid", 13 ) == COMPARE_EQUAL ); 3096cdf0e10cSrcweir break; 3097cdf0e10cSrcweir } 3098cdf0e10cSrcweir 3099cdf0e10cSrcweir // Da Dateien, die Remote geschrieben werden zur Uebertragung auch 3100cdf0e10cSrcweir // gelesen werden koennen muessen 3101cdf0e10cSrcweir if( bRemote ) 3102cdf0e10cSrcweir nStorOpenMode |= STREAM_READ; 3103cdf0e10cSrcweir } 3104cdf0e10cSrcweir 3105cdf0e10cSrcweir 3106cdf0e10cSrcweir 3107cdf0e10cSrcweir void SfxMedium::SetName( const String& aNameP, sal_Bool bSetOrigURL ) 3108cdf0e10cSrcweir { 3109cdf0e10cSrcweir if( !pImp->aOrigURL.Len() ) 3110cdf0e10cSrcweir pImp->aOrigURL = aLogicName; 3111cdf0e10cSrcweir if( bSetOrigURL ) 3112cdf0e10cSrcweir pImp->aOrigURL = aNameP; 3113cdf0e10cSrcweir aLogicName = aNameP; 3114cdf0e10cSrcweir DELETEZ( pURLObj ); 3115cdf0e10cSrcweir pImp->aContent = ::ucbhelper::Content(); 3116cdf0e10cSrcweir Init_Impl(); 3117cdf0e10cSrcweir } 3118cdf0e10cSrcweir 3119cdf0e10cSrcweir //---------------------------------------------------------------- 3120cdf0e10cSrcweir const String& SfxMedium::GetOrigURL() const 3121cdf0e10cSrcweir { 3122cdf0e10cSrcweir return !pImp->aOrigURL.Len() ? (String &)aLogicName : pImp->aOrigURL; 3123cdf0e10cSrcweir } 3124cdf0e10cSrcweir 3125cdf0e10cSrcweir //---------------------------------------------------------------- 3126cdf0e10cSrcweir 3127cdf0e10cSrcweir void SfxMedium::SetPhysicalName_Impl( const String& rNameP ) 3128cdf0e10cSrcweir { 3129cdf0e10cSrcweir if ( rNameP != aName ) 3130cdf0e10cSrcweir { 3131cdf0e10cSrcweir if( pImp->pTempFile ) 3132cdf0e10cSrcweir { 3133cdf0e10cSrcweir delete pImp->pTempFile; 3134cdf0e10cSrcweir pImp->pTempFile = NULL; 3135cdf0e10cSrcweir } 3136cdf0e10cSrcweir 3137cdf0e10cSrcweir if ( aName.Len() || rNameP.Len() ) 3138cdf0e10cSrcweir pImp->aContent = ::ucbhelper::Content(); 3139cdf0e10cSrcweir 3140cdf0e10cSrcweir aName = rNameP; 3141cdf0e10cSrcweir bTriedStorage = sal_False; 3142cdf0e10cSrcweir pImp->bIsStorage = sal_False; 3143cdf0e10cSrcweir } 3144cdf0e10cSrcweir } 3145cdf0e10cSrcweir 3146cdf0e10cSrcweir //------------------------------------------------------------------ 3147cdf0e10cSrcweir void SfxMedium::SetTemporary( sal_Bool bTemp ) 3148cdf0e10cSrcweir { 3149cdf0e10cSrcweir pImp->bIsTemp = bTemp; 3150cdf0e10cSrcweir } 3151cdf0e10cSrcweir 3152cdf0e10cSrcweir //------------------------------------------------------------------ 3153cdf0e10cSrcweir sal_Bool SfxMedium::IsTemporary() const 3154cdf0e10cSrcweir { 3155cdf0e10cSrcweir return pImp->bIsTemp; 3156cdf0e10cSrcweir } 3157cdf0e10cSrcweir 3158cdf0e10cSrcweir //------------------------------------------------------------------ 3159cdf0e10cSrcweir 3160cdf0e10cSrcweir sal_Bool SfxMedium::Exists( sal_Bool /*bForceSession*/ ) 3161cdf0e10cSrcweir { 3162cdf0e10cSrcweir DBG_ERROR( "Not implemented!" ); 3163cdf0e10cSrcweir return sal_True; 3164cdf0e10cSrcweir } 3165cdf0e10cSrcweir 3166cdf0e10cSrcweir //------------------------------------------------------------------ 3167cdf0e10cSrcweir 3168cdf0e10cSrcweir void SfxMedium::ReOpen() 3169cdf0e10cSrcweir { 3170cdf0e10cSrcweir sal_Bool bUseInteractionHandler = pImp->bUseInteractionHandler; 3171cdf0e10cSrcweir pImp->bUseInteractionHandler = sal_False; 3172cdf0e10cSrcweir GetMedium_Impl(); 3173cdf0e10cSrcweir pImp->bUseInteractionHandler = bUseInteractionHandler; 3174cdf0e10cSrcweir } 3175cdf0e10cSrcweir 3176cdf0e10cSrcweir //------------------------------------------------------------------ 3177cdf0e10cSrcweir 3178cdf0e10cSrcweir void SfxMedium::CompleteReOpen() 3179cdf0e10cSrcweir { 3180cdf0e10cSrcweir // do not use temporary file for reopen and in case of success throw the temporary file away 3181cdf0e10cSrcweir sal_Bool bUseInteractionHandler = pImp->bUseInteractionHandler; 3182cdf0e10cSrcweir pImp->bUseInteractionHandler = sal_False; 3183cdf0e10cSrcweir 3184cdf0e10cSrcweir ::utl::TempFile* pTmpFile = NULL; 3185cdf0e10cSrcweir if ( pImp->pTempFile ) 3186cdf0e10cSrcweir { 3187cdf0e10cSrcweir pTmpFile = pImp->pTempFile; 3188cdf0e10cSrcweir pImp->pTempFile = NULL; 3189cdf0e10cSrcweir aName = String(); 3190cdf0e10cSrcweir } 3191cdf0e10cSrcweir 3192cdf0e10cSrcweir GetMedium_Impl(); 3193cdf0e10cSrcweir 3194cdf0e10cSrcweir if ( GetError() ) 3195cdf0e10cSrcweir { 3196cdf0e10cSrcweir if ( pImp->pTempFile ) 3197cdf0e10cSrcweir { 3198cdf0e10cSrcweir pImp->pTempFile->EnableKillingFile( sal_True ); 3199cdf0e10cSrcweir delete pImp->pTempFile; 3200cdf0e10cSrcweir } 3201cdf0e10cSrcweir pImp->pTempFile = pTmpFile; 3202cdf0e10cSrcweir if ( pImp->pTempFile ) 3203cdf0e10cSrcweir aName = pImp->pTempFile->GetFileName(); 3204cdf0e10cSrcweir } 3205cdf0e10cSrcweir else 3206cdf0e10cSrcweir { 3207cdf0e10cSrcweir pTmpFile->EnableKillingFile( sal_True ); 3208cdf0e10cSrcweir delete pTmpFile; 3209cdf0e10cSrcweir 3210cdf0e10cSrcweir } 3211cdf0e10cSrcweir 3212cdf0e10cSrcweir pImp->bUseInteractionHandler = bUseInteractionHandler; 3213cdf0e10cSrcweir } 3214cdf0e10cSrcweir 3215cdf0e10cSrcweir //------------------------------------------------------------------ 3216cdf0e10cSrcweir SfxMedium::SfxMedium 3217cdf0e10cSrcweir ( 3218cdf0e10cSrcweir const String &rName, StreamMode nOpenMode, sal_Bool bDirectP, 3219cdf0e10cSrcweir const SfxFilter *pFlt, SfxItemSet *pInSet 3220cdf0e10cSrcweir ) 3221cdf0e10cSrcweir : IMPL_CTOR( sal_False, 0 ), // bRoot, pURLObj 3222cdf0e10cSrcweir pFilter(pFlt), 3223cdf0e10cSrcweir pSet( pInSet ), 3224cdf0e10cSrcweir pImp(new SfxMedium_Impl( this )) 3225cdf0e10cSrcweir { 3226cdf0e10cSrcweir aLogicName = rName; 3227cdf0e10cSrcweir nStorOpenMode = nOpenMode; 3228cdf0e10cSrcweir bDirect = bDirectP; 3229cdf0e10cSrcweir Init_Impl(); 3230cdf0e10cSrcweir } 3231cdf0e10cSrcweir 3232cdf0e10cSrcweir 3233cdf0e10cSrcweir SfxMedium::SfxMedium( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) 3234cdf0e10cSrcweir : IMPL_CTOR( sal_False, 0 ), // bRoot, pURLObj 3235cdf0e10cSrcweir pFilter(0), 3236cdf0e10cSrcweir pSet(0), 3237cdf0e10cSrcweir pImp(new SfxMedium_Impl( this )) 3238cdf0e10cSrcweir { 3239cdf0e10cSrcweir SfxAllItemSet *pParams = new SfxAllItemSet( SFX_APP()->GetPool() ); 3240cdf0e10cSrcweir pSet = pParams; 3241cdf0e10cSrcweir TransformParameters( SID_OPENDOC, aArgs, *pParams ); 3242cdf0e10cSrcweir 3243cdf0e10cSrcweir String aFilterName; 3244cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFilterNameItem, SfxStringItem, SID_FILTER_NAME, sal_False ); 3245cdf0e10cSrcweir if( pFilterNameItem ) 3246cdf0e10cSrcweir aFilterName = pFilterNameItem->GetValue(); 3247cdf0e10cSrcweir pFilter = SFX_APP()->GetFilterMatcher().GetFilter4FilterName( aFilterName ); 3248cdf0e10cSrcweir 3249cdf0e10cSrcweir sal_Bool bSalvage = sal_False; 3250cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False ); 3251cdf0e10cSrcweir if( pSalvageItem ) 3252cdf0e10cSrcweir { 3253cdf0e10cSrcweir // QUESTION: there is some treatment of Salvage in Init_Impl; align! 3254cdf0e10cSrcweir bSalvage = sal_True; 3255cdf0e10cSrcweir if ( pSalvageItem->GetValue().Len() ) 3256cdf0e10cSrcweir { 3257cdf0e10cSrcweir // if an URL is provided in SalvageItem that means that the FileName refers to a temporary file 3258cdf0e10cSrcweir // that must be copied here 3259cdf0e10cSrcweir 3260cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False ); 3261cdf0e10cSrcweir if (!pFileNameItem) throw uno::RuntimeException(); 3262cdf0e10cSrcweir ::rtl::OUString aNewTempFileURL = SfxMedium::CreateTempCopyWithExt( pFileNameItem->GetValue() ); 3263cdf0e10cSrcweir if ( aNewTempFileURL.getLength() ) 3264cdf0e10cSrcweir { 3265cdf0e10cSrcweir pSet->Put( SfxStringItem( SID_FILE_NAME, aNewTempFileURL ) ); 3266cdf0e10cSrcweir pSet->ClearItem( SID_INPUTSTREAM ); 3267cdf0e10cSrcweir pSet->ClearItem( SID_STREAM ); 3268cdf0e10cSrcweir pSet->ClearItem( SID_CONTENT ); 3269cdf0e10cSrcweir } 3270cdf0e10cSrcweir else 3271cdf0e10cSrcweir { 3272cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can not create a new temporary file for crash recovery!\n" ); 3273cdf0e10cSrcweir } 3274cdf0e10cSrcweir } 3275cdf0e10cSrcweir } 3276cdf0e10cSrcweir 3277cdf0e10cSrcweir sal_Bool bReadOnly = sal_False; 3278cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, sal_False ); 3279cdf0e10cSrcweir if ( pReadOnlyItem && pReadOnlyItem->GetValue() ) 3280cdf0e10cSrcweir bReadOnly = sal_True; 3281cdf0e10cSrcweir 3282cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False ); 3283cdf0e10cSrcweir if (!pFileNameItem) throw uno::RuntimeException(); 3284cdf0e10cSrcweir aLogicName = pFileNameItem->GetValue(); 3285cdf0e10cSrcweir nStorOpenMode = bReadOnly ? SFX_STREAM_READONLY : SFX_STREAM_READWRITE; 3286cdf0e10cSrcweir bDirect = sal_False; 3287cdf0e10cSrcweir Init_Impl(); 3288cdf0e10cSrcweir } 3289cdf0e10cSrcweir 3290cdf0e10cSrcweir 3291cdf0e10cSrcweir //------------------------------------------------------------------ 3292cdf0e10cSrcweir 3293cdf0e10cSrcweir SfxMedium::SfxMedium( const uno::Reference < embed::XStorage >& rStor, const String& rBaseURL, const SfxItemSet* p, sal_Bool bRootP ) 3294cdf0e10cSrcweir : IMPL_CTOR( bRootP, 0 ), // bRoot, pURLObj 3295cdf0e10cSrcweir pSet(0), 3296cdf0e10cSrcweir pImp( new SfxMedium_Impl( this )) 3297cdf0e10cSrcweir { 3298cdf0e10cSrcweir String aType = SfxFilter::GetTypeFromStorage( rStor ); 3299cdf0e10cSrcweir pFilter = SFX_APP()->GetFilterMatcher().GetFilter4EA( aType ); 3300cdf0e10cSrcweir DBG_ASSERT( pFilter, "No Filter for storage found!" ); 3301cdf0e10cSrcweir 3302cdf0e10cSrcweir Init_Impl(); 3303cdf0e10cSrcweir pImp->xStorage = rStor; 3304cdf0e10cSrcweir pImp->bDisposeStorage = sal_False; 3305cdf0e10cSrcweir 3306cdf0e10cSrcweir // always take BaseURL first, could be overwritten by ItemSet 3307cdf0e10cSrcweir GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, rBaseURL ) ); 3308cdf0e10cSrcweir if ( p ) 3309cdf0e10cSrcweir GetItemSet()->Put( *p ); 3310cdf0e10cSrcweir } 3311cdf0e10cSrcweir 3312b45043c5SMathias Bauer SfxMedium::SfxMedium( const uno::Reference < embed::XStorage >& rStor, const String& rBaseURL, const String& rTypeName, const SfxItemSet* p, sal_Bool bRootP ) 3313b45043c5SMathias Bauer : IMPL_CTOR( bRootP, 0 ), // bRoot, pURLObj 3314b45043c5SMathias Bauer pSet(0), 3315b45043c5SMathias Bauer pImp( new SfxMedium_Impl( this )) 3316b45043c5SMathias Bauer { 3317b45043c5SMathias Bauer pFilter = SFX_APP()->GetFilterMatcher().GetFilter4EA( rTypeName ); 3318b45043c5SMathias Bauer DBG_ASSERT( pFilter, "No Filter for storage found!" ); 3319b45043c5SMathias Bauer 3320b45043c5SMathias Bauer Init_Impl(); 3321b45043c5SMathias Bauer pImp->xStorage = rStor; 3322b45043c5SMathias Bauer pImp->bDisposeStorage = sal_False; 3323b45043c5SMathias Bauer 3324b45043c5SMathias Bauer // always take BaseURL first, could be overwritten by ItemSet 3325b45043c5SMathias Bauer GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, rBaseURL ) ); 3326b45043c5SMathias Bauer if ( p ) 3327b45043c5SMathias Bauer GetItemSet()->Put( *p ); 3328b45043c5SMathias Bauer } 3329b45043c5SMathias Bauer 3330cdf0e10cSrcweir //------------------------------------------------------------------ 3331cdf0e10cSrcweir 3332cdf0e10cSrcweir SfxMedium::~SfxMedium() 3333cdf0e10cSrcweir { 3334cdf0e10cSrcweir /* Attention 3335cdf0e10cSrcweir Don't enable CancelTransfers() till you know that the writer/web has changed his asynchronous load 3336cdf0e10cSrcweir behaviour. Otherwhise may StyleSheets inside a html file will be loaded at the right time. 3337cdf0e10cSrcweir => further the help will be empty then ... #100490# 3338cdf0e10cSrcweir */ 3339cdf0e10cSrcweir //CancelTransfers(); 3340cdf0e10cSrcweir 3341cdf0e10cSrcweir // if there is a requirement to clean the backup this is the last possibility to do it 3342cdf0e10cSrcweir ClearBackup_Impl(); 3343cdf0e10cSrcweir 3344cdf0e10cSrcweir Close(); 3345cdf0e10cSrcweir 3346cdf0e10cSrcweir delete pSet; 3347cdf0e10cSrcweir 3348cdf0e10cSrcweir if( pImp->bIsTemp && aName.Len() ) 3349cdf0e10cSrcweir { 3350cdf0e10cSrcweir String aTemp; 3351cdf0e10cSrcweir if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( aName, aTemp )) 3352cdf0e10cSrcweir { 3353cdf0e10cSrcweir DBG_ERROR("Physical name not convertable!"); 3354cdf0e10cSrcweir } 3355cdf0e10cSrcweir 3356cdf0e10cSrcweir if ( !::utl::UCBContentHelper::Kill( aTemp ) ) 3357cdf0e10cSrcweir { 3358cdf0e10cSrcweir DBG_ERROR("Couldn't remove temporary file!"); 3359cdf0e10cSrcweir } 3360cdf0e10cSrcweir } 3361cdf0e10cSrcweir 3362cdf0e10cSrcweir pFilter = 0; 3363cdf0e10cSrcweir 3364cdf0e10cSrcweir delete pURLObj; 3365cdf0e10cSrcweir delete pImp; 3366cdf0e10cSrcweir } 3367cdf0e10cSrcweir 3368cdf0e10cSrcweir //------------------------------------------------------------------ 3369cdf0e10cSrcweir void SfxMedium::SetItemSet(SfxItemSet *pNewSet) 3370cdf0e10cSrcweir { 3371cdf0e10cSrcweir delete pSet; 3372cdf0e10cSrcweir pSet = pNewSet; 3373cdf0e10cSrcweir } 3374cdf0e10cSrcweir 3375cdf0e10cSrcweir //---------------------------------------------------------------- 3376cdf0e10cSrcweir const INetURLObject& SfxMedium::GetURLObject() const 3377cdf0e10cSrcweir { 3378cdf0e10cSrcweir if( !pURLObj ) 3379cdf0e10cSrcweir { 3380cdf0e10cSrcweir SfxMedium* pThis = const_cast < SfxMedium* > (this); 3381cdf0e10cSrcweir pThis->pURLObj = new INetURLObject( aLogicName ); 3382cdf0e10cSrcweir if ( pThis->pURLObj->HasMark() ) 3383cdf0e10cSrcweir (*pThis->pURLObj) = INetURLObject( aLogicName ).GetURLNoMark(); 3384cdf0e10cSrcweir } 3385cdf0e10cSrcweir 3386cdf0e10cSrcweir return *pURLObj; 3387cdf0e10cSrcweir } 3388cdf0e10cSrcweir 3389cdf0e10cSrcweir //---------------------------------------------------------------- 3390cdf0e10cSrcweir 3391cdf0e10cSrcweir const String& SfxMedium::GetPreRedirectedURL() const 3392cdf0e10cSrcweir { 3393cdf0e10cSrcweir return pImp->aPreRedirectionURL; 3394cdf0e10cSrcweir } 3395cdf0e10cSrcweir //---------------------------------------------------------------- 3396cdf0e10cSrcweir 3397cdf0e10cSrcweir sal_uInt32 SfxMedium::GetMIMEAndRedirect( String& /*rName*/ ) 3398cdf0e10cSrcweir { 3399cdf0e10cSrcweir /* dv !!!! not needed any longer ? 3400cdf0e10cSrcweir INetProtocol eProt = GetURLObject().GetProtocol(); 3401cdf0e10cSrcweir if( eProt == INET_PROT_FTP && SvBinding::ShouldUseFtpProxy( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) 3402cdf0e10cSrcweir { 3403cdf0e10cSrcweir Any aAny( UCB_Helper::GetProperty( GetContent(), WID_FLAG_IS_FOLDER ) ); 3404cdf0e10cSrcweir sal_Bool bIsFolder = sal_False; 3405cdf0e10cSrcweir if ( ( aAny >>= bIsFolder ) && bIsFolder ) 3406cdf0e10cSrcweir return ERRCODE_NONE; 3407cdf0e10cSrcweir } 3408cdf0e10cSrcweir 3409cdf0e10cSrcweir GetMedium_Impl(); 3410cdf0e10cSrcweir if( !eError && pImp->xBinding.Is() ) 3411cdf0e10cSrcweir { 3412cdf0e10cSrcweir eError = pImp->xBinding->GetMimeType( rName ); 3413cdf0e10cSrcweir 3414cdf0e10cSrcweir // Wir koennen keine Parameter wie CharSets usw. 3415cdf0e10cSrcweir rName = rName.GetToken( 0, ';' ); 3416cdf0e10cSrcweir if( !eError ) 3417cdf0e10cSrcweir { 3418cdf0e10cSrcweir if( !pImp->aPreRedirectionURL.Len() ) 3419cdf0e10cSrcweir pImp->aPreRedirectionURL = aLogicName; 3420cdf0e10cSrcweir SetName( pImp->xBinding->GetRedirectedURL() ); 3421cdf0e10cSrcweir } 3422cdf0e10cSrcweir pImp->aExpireTime = pImp->xBinding->GetExpireDateTime(); 3423cdf0e10cSrcweir } 3424cdf0e10cSrcweir return eError; 3425cdf0e10cSrcweir */ 3426cdf0e10cSrcweir return 0; 3427cdf0e10cSrcweir } 3428cdf0e10cSrcweir 3429cdf0e10cSrcweir //---------------------------------------------------------------- 3430cdf0e10cSrcweir 3431cdf0e10cSrcweir void SfxMedium::SetReferer( const String& rRefer ) 3432cdf0e10cSrcweir { 3433cdf0e10cSrcweir pImp->aReferer = rRefer; 3434cdf0e10cSrcweir } 3435cdf0e10cSrcweir //---------------------------------------------------------------- 3436cdf0e10cSrcweir 3437cdf0e10cSrcweir const String& SfxMedium::GetReferer( ) const 3438cdf0e10cSrcweir { 3439cdf0e10cSrcweir return pImp->aReferer; 3440cdf0e10cSrcweir } 3441cdf0e10cSrcweir 3442cdf0e10cSrcweir //---------------------------------------------------------------- 3443cdf0e10cSrcweir 3444cdf0e10cSrcweir void SfxMedium::SetExpired_Impl( const DateTime& rDateTime ) 3445cdf0e10cSrcweir { 3446cdf0e10cSrcweir pImp->aExpireTime = rDateTime; 3447cdf0e10cSrcweir } 3448cdf0e10cSrcweir //---------------------------------------------------------------- 3449cdf0e10cSrcweir 3450cdf0e10cSrcweir sal_Bool SfxMedium::IsExpired() const 3451cdf0e10cSrcweir { 3452cdf0e10cSrcweir return pImp->aExpireTime.IsValid() && pImp->aExpireTime < DateTime(); 3453cdf0e10cSrcweir } 3454cdf0e10cSrcweir //---------------------------------------------------------------- 3455cdf0e10cSrcweir 3456cdf0e10cSrcweir void SfxMedium::ForceSynchronStream_Impl( sal_Bool bForce ) 3457cdf0e10cSrcweir { 3458cdf0e10cSrcweir if( pInStream ) 3459cdf0e10cSrcweir { 3460cdf0e10cSrcweir SvLockBytes* pBytes = pInStream->GetLockBytes(); 3461cdf0e10cSrcweir if( pBytes ) 3462cdf0e10cSrcweir pBytes->SetSynchronMode( bForce ); 3463cdf0e10cSrcweir } 3464cdf0e10cSrcweir pImp->bForceSynchron = bForce; 3465cdf0e10cSrcweir } 3466cdf0e10cSrcweir 3467cdf0e10cSrcweir //---------------------------------------------------------------- 3468cdf0e10cSrcweir SfxFrame* SfxMedium::GetLoadTargetFrame() const 3469cdf0e10cSrcweir { 3470cdf0e10cSrcweir return pImp->wLoadTargetFrame; 3471cdf0e10cSrcweir } 3472cdf0e10cSrcweir //---------------------------------------------------------------- 3473cdf0e10cSrcweir 3474cdf0e10cSrcweir void SfxMedium::SetLoadTargetFrame(SfxFrame* pFrame ) 3475cdf0e10cSrcweir { 3476cdf0e10cSrcweir pImp->wLoadTargetFrame = pFrame; 3477cdf0e10cSrcweir } 3478cdf0e10cSrcweir //---------------------------------------------------------------- 3479cdf0e10cSrcweir 3480cdf0e10cSrcweir void SfxMedium::SetStorage_Impl( const uno::Reference < embed::XStorage >& rStor ) 3481cdf0e10cSrcweir { 3482cdf0e10cSrcweir pImp->xStorage = rStor; 3483cdf0e10cSrcweir } 3484cdf0e10cSrcweir //---------------------------------------------------------------- 3485cdf0e10cSrcweir 3486cdf0e10cSrcweir SfxItemSet* SfxMedium::GetItemSet() const 3487cdf0e10cSrcweir { 3488cdf0e10cSrcweir // this method *must* return an ItemSet, returning NULL can cause crashes 3489cdf0e10cSrcweir if( !pSet ) 3490cdf0e10cSrcweir ((SfxMedium*)this)->pSet = new SfxAllItemSet( SFX_APP()->GetPool() ); 3491cdf0e10cSrcweir return pSet; 3492cdf0e10cSrcweir } 3493cdf0e10cSrcweir //---------------------------------------------------------------- 3494cdf0e10cSrcweir 3495cdf0e10cSrcweir SvKeyValueIterator* SfxMedium::GetHeaderAttributes_Impl() 3496cdf0e10cSrcweir { 3497cdf0e10cSrcweir if( !pImp->xAttributes.Is() ) 3498cdf0e10cSrcweir { 3499cdf0e10cSrcweir pImp->xAttributes = SvKeyValueIteratorRef( new SvKeyValueIterator ); 3500cdf0e10cSrcweir 3501cdf0e10cSrcweir if ( GetContent().is() ) 3502cdf0e10cSrcweir { 3503cdf0e10cSrcweir pImp->bIsCharsetInitialized = sal_True; 3504cdf0e10cSrcweir 3505cdf0e10cSrcweir try 3506cdf0e10cSrcweir { 3507cdf0e10cSrcweir Any aAny = pImp->aContent.getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) ); 3508cdf0e10cSrcweir ::rtl::OUString aContentType; 3509cdf0e10cSrcweir aAny >>= aContentType; 3510cdf0e10cSrcweir 3511cdf0e10cSrcweir pImp->xAttributes->Append( SvKeyValue( ::rtl::OUString::createFromAscii( "content-type" ), aContentType ) ); 3512cdf0e10cSrcweir } 3513cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 3514cdf0e10cSrcweir { 3515cdf0e10cSrcweir } 3516cdf0e10cSrcweir } 3517cdf0e10cSrcweir } 3518cdf0e10cSrcweir 3519cdf0e10cSrcweir return pImp->xAttributes; 3520cdf0e10cSrcweir } 3521cdf0e10cSrcweir //---------------------------------------------------------------- 3522cdf0e10cSrcweir 3523cdf0e10cSrcweir SvCompatWeakHdl* SfxMedium::GetHdl() 3524cdf0e10cSrcweir { 3525cdf0e10cSrcweir return pImp->GetHdl(); 3526cdf0e10cSrcweir } 3527cdf0e10cSrcweir 3528cdf0e10cSrcweir sal_Bool SfxMedium::IsDownloadDone_Impl() 3529cdf0e10cSrcweir { 3530cdf0e10cSrcweir return pImp->bDownloadDone; 3531cdf0e10cSrcweir } 3532cdf0e10cSrcweir 3533cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SfxMedium::GetInputStream() 3534cdf0e10cSrcweir { 3535cdf0e10cSrcweir if ( !pImp->xInputStream.is() ) 3536cdf0e10cSrcweir GetMedium_Impl(); 3537cdf0e10cSrcweir return pImp->xInputStream; 3538cdf0e10cSrcweir } 3539cdf0e10cSrcweir 3540cdf0e10cSrcweir const uno::Sequence < util::RevisionTag >& SfxMedium::GetVersionList( bool _bNoReload ) 3541cdf0e10cSrcweir { 3542cdf0e10cSrcweir // if the medium has no name, then this medium should represent a new document and can have no version info 3543cdf0e10cSrcweir if ( ( !_bNoReload || !pImp->m_bVersionsAlreadyLoaded ) && !pImp->aVersions.getLength() && 3544cdf0e10cSrcweir ( aName.Len() || aLogicName.Len() ) && GetStorage().is() ) 3545cdf0e10cSrcweir { 3546cdf0e10cSrcweir uno::Reference < document::XDocumentRevisionListPersistence > xReader( comphelper::getProcessServiceFactory()->createInstance( 3547cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.document.DocumentRevisionListPersistence") ), uno::UNO_QUERY ); 3548cdf0e10cSrcweir if ( xReader.is() ) 3549cdf0e10cSrcweir { 3550cdf0e10cSrcweir try 3551cdf0e10cSrcweir { 3552cdf0e10cSrcweir pImp->aVersions = xReader->load( GetStorage() ); 3553cdf0e10cSrcweir } 3554cdf0e10cSrcweir catch ( uno::Exception& ) 3555cdf0e10cSrcweir { 3556cdf0e10cSrcweir } 3557cdf0e10cSrcweir } 3558cdf0e10cSrcweir } 3559cdf0e10cSrcweir 3560cdf0e10cSrcweir if ( !pImp->m_bVersionsAlreadyLoaded ) 3561cdf0e10cSrcweir pImp->m_bVersionsAlreadyLoaded = sal_True; 3562cdf0e10cSrcweir 3563cdf0e10cSrcweir return pImp->aVersions; 3564cdf0e10cSrcweir } 3565cdf0e10cSrcweir 3566cdf0e10cSrcweir uno::Sequence < util::RevisionTag > SfxMedium::GetVersionList( const uno::Reference < embed::XStorage >& xStorage ) 3567cdf0e10cSrcweir { 3568cdf0e10cSrcweir uno::Reference < document::XDocumentRevisionListPersistence > xReader( comphelper::getProcessServiceFactory()->createInstance( 3569cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.document.DocumentRevisionListPersistence") ), uno::UNO_QUERY ); 3570cdf0e10cSrcweir if ( xReader.is() ) 3571cdf0e10cSrcweir { 3572cdf0e10cSrcweir try 3573cdf0e10cSrcweir { 3574cdf0e10cSrcweir return xReader->load( xStorage ); 3575cdf0e10cSrcweir } 3576cdf0e10cSrcweir catch ( uno::Exception& ) 3577cdf0e10cSrcweir { 3578cdf0e10cSrcweir } 3579cdf0e10cSrcweir } 3580cdf0e10cSrcweir 3581cdf0e10cSrcweir return uno::Sequence < util::RevisionTag >(); 3582cdf0e10cSrcweir } 3583cdf0e10cSrcweir 3584cdf0e10cSrcweir sal_uInt16 SfxMedium::AddVersion_Impl( util::RevisionTag& rRevision ) 3585cdf0e10cSrcweir { 3586cdf0e10cSrcweir if ( GetStorage().is() ) 3587cdf0e10cSrcweir { 3588cdf0e10cSrcweir // Einen eindeutigen Namen f"ur den Stream ermitteln 3589cdf0e10cSrcweir SvULongs aLongs; 3590cdf0e10cSrcweir sal_Int32 nLength = pImp->aVersions.getLength(); 3591cdf0e10cSrcweir for ( sal_Int32 m=0; m<nLength; m++ ) 3592cdf0e10cSrcweir { 3593cdf0e10cSrcweir sal_uInt32 nVer = (sal_uInt32) String( pImp->aVersions[m].Identifier ).Copy(7).ToInt32(); 3594cdf0e10cSrcweir sal_uInt16 n; 3595cdf0e10cSrcweir for ( n=0; n<aLongs.Count(); n++ ) 3596cdf0e10cSrcweir if ( nVer<aLongs[n] ) 3597cdf0e10cSrcweir break; 3598cdf0e10cSrcweir 3599cdf0e10cSrcweir aLongs.Insert( nVer, n ); 3600cdf0e10cSrcweir } 3601cdf0e10cSrcweir 3602cdf0e10cSrcweir sal_uInt16 nKey; 3603cdf0e10cSrcweir for ( nKey=0; nKey<aLongs.Count(); nKey++ ) 3604cdf0e10cSrcweir if ( aLongs[nKey] > ( sal_uIntPtr ) nKey+1 ) 3605cdf0e10cSrcweir break; 3606cdf0e10cSrcweir 3607cdf0e10cSrcweir String aRevName = DEFINE_CONST_UNICODE( "Version" ); 3608cdf0e10cSrcweir aRevName += String::CreateFromInt32( nKey + 1 ); 3609cdf0e10cSrcweir pImp->aVersions.realloc( nLength+1 ); 3610cdf0e10cSrcweir rRevision.Identifier = aRevName; 3611cdf0e10cSrcweir pImp->aVersions[nLength] = rRevision; 3612cdf0e10cSrcweir return nKey; 3613cdf0e10cSrcweir } 3614cdf0e10cSrcweir 3615cdf0e10cSrcweir return 0; 3616cdf0e10cSrcweir } 3617cdf0e10cSrcweir 3618cdf0e10cSrcweir sal_Bool SfxMedium::RemoveVersion_Impl( const ::rtl::OUString& rName ) 3619cdf0e10cSrcweir { 3620cdf0e10cSrcweir if ( !pImp->aVersions.getLength() ) 3621cdf0e10cSrcweir return sal_False; 3622cdf0e10cSrcweir 3623cdf0e10cSrcweir sal_Int32 nLength = pImp->aVersions.getLength(); 3624cdf0e10cSrcweir for ( sal_Int32 n=0; n<nLength; n++ ) 3625cdf0e10cSrcweir { 3626cdf0e10cSrcweir if ( pImp->aVersions[n].Identifier == rName ) 3627cdf0e10cSrcweir { 3628cdf0e10cSrcweir for ( sal_Int32 m=n; m<nLength-1; m++ ) 3629cdf0e10cSrcweir pImp->aVersions[m] = pImp->aVersions[m+1]; 3630cdf0e10cSrcweir pImp->aVersions.realloc(nLength-1); 3631cdf0e10cSrcweir return sal_True; 3632cdf0e10cSrcweir } 3633cdf0e10cSrcweir } 3634cdf0e10cSrcweir 3635cdf0e10cSrcweir return sal_False; 3636cdf0e10cSrcweir } 3637cdf0e10cSrcweir 3638cdf0e10cSrcweir sal_Bool SfxMedium::TransferVersionList_Impl( SfxMedium& rMedium ) 3639cdf0e10cSrcweir { 3640cdf0e10cSrcweir if ( rMedium.pImp->aVersions.getLength() ) 3641cdf0e10cSrcweir { 3642cdf0e10cSrcweir pImp->aVersions = rMedium.pImp->aVersions; 3643cdf0e10cSrcweir return sal_True; 3644cdf0e10cSrcweir } 3645cdf0e10cSrcweir 3646cdf0e10cSrcweir return sal_False; 3647cdf0e10cSrcweir } 3648cdf0e10cSrcweir 3649cdf0e10cSrcweir sal_Bool SfxMedium::SaveVersionList_Impl( sal_Bool /*bUseXML*/ ) 3650cdf0e10cSrcweir { 3651cdf0e10cSrcweir if ( GetStorage().is() ) 3652cdf0e10cSrcweir { 3653cdf0e10cSrcweir if ( !pImp->aVersions.getLength() ) 3654cdf0e10cSrcweir return sal_True; 3655cdf0e10cSrcweir 3656cdf0e10cSrcweir uno::Reference < document::XDocumentRevisionListPersistence > xWriter( comphelper::getProcessServiceFactory()->createInstance( 3657cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.document.DocumentRevisionListPersistence") ), uno::UNO_QUERY ); 3658cdf0e10cSrcweir if ( xWriter.is() ) 3659cdf0e10cSrcweir { 3660cdf0e10cSrcweir try 3661cdf0e10cSrcweir { 3662cdf0e10cSrcweir xWriter->store( GetStorage(), pImp->aVersions ); 3663cdf0e10cSrcweir return sal_True; 3664cdf0e10cSrcweir } 3665cdf0e10cSrcweir catch ( uno::Exception& ) 3666cdf0e10cSrcweir { 3667cdf0e10cSrcweir } 3668cdf0e10cSrcweir } 3669cdf0e10cSrcweir } 3670cdf0e10cSrcweir 3671cdf0e10cSrcweir return sal_False; 3672cdf0e10cSrcweir } 3673cdf0e10cSrcweir 3674cdf0e10cSrcweir //---------------------------------------------------------------- 3675cdf0e10cSrcweir sal_Bool SfxMedium::IsReadOnly() 3676cdf0e10cSrcweir { 3677cdf0e10cSrcweir sal_Bool bReadOnly = sal_False; 3678cdf0e10cSrcweir 367986e1cf34SPedro Giffuni // a) ReadOnly filter can't produce read/write contents! 3680cdf0e10cSrcweir bReadOnly = ( 3681cdf0e10cSrcweir (pFilter ) && 3682cdf0e10cSrcweir ((pFilter->GetFilterFlags() & SFX_FILTER_OPENREADONLY) == SFX_FILTER_OPENREADONLY) 3683cdf0e10cSrcweir ); 3684cdf0e10cSrcweir 3685cdf0e10cSrcweir // b) if filter allow read/write contents .. check open mode of the storage 3686cdf0e10cSrcweir if (!bReadOnly) 3687cdf0e10cSrcweir bReadOnly = !( GetOpenMode() & STREAM_WRITE ); 3688cdf0e10cSrcweir 3689cdf0e10cSrcweir // c) the API can force the readonly state! 3690cdf0e10cSrcweir if (!bReadOnly) 3691cdf0e10cSrcweir { 3692cdf0e10cSrcweir SFX_ITEMSET_ARG( GetItemSet(), pItem, SfxBoolItem, SID_DOC_READONLY, sal_False); 3693cdf0e10cSrcweir if (pItem) 3694cdf0e10cSrcweir bReadOnly = pItem->GetValue(); 3695cdf0e10cSrcweir } 3696cdf0e10cSrcweir 3697cdf0e10cSrcweir return bReadOnly; 3698cdf0e10cSrcweir } 3699cdf0e10cSrcweir 3700cdf0e10cSrcweir //---------------------------------------------------------------- 3701cdf0e10cSrcweir sal_Bool SfxMedium::SetWritableForUserOnly( const ::rtl::OUString& aURL ) 3702cdf0e10cSrcweir { 3703cdf0e10cSrcweir // UCB does not allow to allow write access only for the user, 3704cdf0e10cSrcweir // use osl API 3705cdf0e10cSrcweir sal_Bool bResult = sal_False; 3706cdf0e10cSrcweir 3707cdf0e10cSrcweir ::osl::DirectoryItem aDirItem; 3708cdf0e10cSrcweir if ( ::osl::DirectoryItem::get( aURL, aDirItem ) == ::osl::FileBase::E_None ) 3709cdf0e10cSrcweir { 3710cdf0e10cSrcweir ::osl::FileStatus aFileStatus( FileStatusMask_Attributes ); 3711cdf0e10cSrcweir if ( aDirItem.getFileStatus( aFileStatus ) == osl::FileBase::E_None 3712cdf0e10cSrcweir && aFileStatus.isValid( FileStatusMask_Attributes ) ) 3713cdf0e10cSrcweir { 3714cdf0e10cSrcweir sal_uInt64 nAttributes = aFileStatus.getAttributes(); 3715cdf0e10cSrcweir 3716cdf0e10cSrcweir nAttributes &= ~(Attribute_OwnWrite | 3717cdf0e10cSrcweir Attribute_GrpWrite | 3718cdf0e10cSrcweir Attribute_OthWrite | 3719cdf0e10cSrcweir Attribute_ReadOnly); 3720cdf0e10cSrcweir nAttributes |= Attribute_OwnWrite; 3721cdf0e10cSrcweir 3722cdf0e10cSrcweir bResult = ( osl::File::setAttributes( aURL, nAttributes ) == ::osl::FileBase::E_None ); 3723cdf0e10cSrcweir } 3724cdf0e10cSrcweir } 3725cdf0e10cSrcweir 3726cdf0e10cSrcweir return bResult; 3727cdf0e10cSrcweir } 3728cdf0e10cSrcweir 3729cdf0e10cSrcweir //---------------------------------------------------------------- 3730cdf0e10cSrcweir void SfxMedium::CreateTempFile( sal_Bool bReplace ) 3731cdf0e10cSrcweir { 3732cdf0e10cSrcweir if ( pImp->pTempFile ) 3733cdf0e10cSrcweir { 3734cdf0e10cSrcweir if ( !bReplace ) 3735cdf0e10cSrcweir return; 3736cdf0e10cSrcweir 3737cdf0e10cSrcweir DELETEZ( pImp->pTempFile ); 3738cdf0e10cSrcweir aName = String(); 3739cdf0e10cSrcweir } 3740cdf0e10cSrcweir 37413b5992cdSOliver-Rainer Wittmann do 37423b5992cdSOliver-Rainer Wittmann { 3743cdf0e10cSrcweir pImp->pTempFile = new ::utl::TempFile(); 37443b5992cdSOliver-Rainer Wittmann if ( GetName().Equals( pImp->pTempFile->GetURL() ) ) 37453b5992cdSOliver-Rainer Wittmann { 37463b5992cdSOliver-Rainer Wittmann delete pImp->pTempFile; 37473b5992cdSOliver-Rainer Wittmann pImp->pTempFile = NULL; 37483b5992cdSOliver-Rainer Wittmann } 37493b5992cdSOliver-Rainer Wittmann } while ( pImp->pTempFile == NULL ); 3750cdf0e10cSrcweir pImp->pTempFile->EnableKillingFile( sal_True ); 3751cdf0e10cSrcweir aName = pImp->pTempFile->GetFileName(); 3752cdf0e10cSrcweir ::rtl::OUString aTmpURL = pImp->pTempFile->GetURL(); 3753cdf0e10cSrcweir if ( !aName.Len() || !aTmpURL.getLength() ) 3754cdf0e10cSrcweir { 3755cdf0e10cSrcweir SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 3756cdf0e10cSrcweir return; 3757cdf0e10cSrcweir } 3758cdf0e10cSrcweir 3759cdf0e10cSrcweir if ( !( nStorOpenMode & STREAM_TRUNC ) ) 3760cdf0e10cSrcweir { 3761cdf0e10cSrcweir sal_Bool bTransferSuccess = sal_False; 3762cdf0e10cSrcweir 3763cdf0e10cSrcweir if ( GetContent().is() 3764cdf0e10cSrcweir && ::utl::LocalFileHelper::IsLocalFile( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) 3765cdf0e10cSrcweir && ::utl::UCBContentHelper::IsDocument( GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ) ) 3766cdf0e10cSrcweir { 3767cdf0e10cSrcweir // if there is already such a document, we should copy it 3768cdf0e10cSrcweir // if it is a file system use OS copy process 3769cdf0e10cSrcweir try 3770cdf0e10cSrcweir { 3771cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv; 3772cdf0e10cSrcweir INetURLObject aTmpURLObj( aTmpURL ); 3773cdf0e10cSrcweir ::rtl::OUString aFileName = aTmpURLObj.getName( INetURLObject::LAST_SEGMENT, 3774cdf0e10cSrcweir true, 3775cdf0e10cSrcweir INetURLObject::DECODE_WITH_CHARSET ); 3776cdf0e10cSrcweir if ( aFileName.getLength() && aTmpURLObj.removeSegment() ) 3777cdf0e10cSrcweir { 3778cdf0e10cSrcweir ::ucbhelper::Content aTargetContent( aTmpURLObj.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); 3779cdf0e10cSrcweir if ( aTargetContent.transferContent( pImp->aContent, ::ucbhelper::InsertOperation_COPY, aFileName, NameClash::OVERWRITE ) ) 3780cdf0e10cSrcweir { 3781cdf0e10cSrcweir SetWritableForUserOnly( aTmpURL ); 3782cdf0e10cSrcweir bTransferSuccess = sal_True; 3783cdf0e10cSrcweir } 3784cdf0e10cSrcweir } 3785cdf0e10cSrcweir } 3786cdf0e10cSrcweir catch( uno::Exception& ) 3787cdf0e10cSrcweir {} 3788cdf0e10cSrcweir 3789cdf0e10cSrcweir if ( bTransferSuccess ) 3790cdf0e10cSrcweir { 3791cdf0e10cSrcweir CloseOutStream(); 3792cdf0e10cSrcweir CloseInStream(); 3793cdf0e10cSrcweir } 3794cdf0e10cSrcweir } 3795cdf0e10cSrcweir 3796cdf0e10cSrcweir if ( !bTransferSuccess && pInStream ) 3797cdf0e10cSrcweir { 3798cdf0e10cSrcweir // the case when there is no URL-access available or this is a remote protocoll 3799cdf0e10cSrcweir // but there is an input stream 3800cdf0e10cSrcweir GetOutStream(); 3801cdf0e10cSrcweir if ( pOutStream ) 3802cdf0e10cSrcweir { 3803cdf0e10cSrcweir char *pBuf = new char [8192]; 3804cdf0e10cSrcweir sal_uInt32 nErr = ERRCODE_NONE; 3805cdf0e10cSrcweir 3806cdf0e10cSrcweir pInStream->Seek(0); 3807cdf0e10cSrcweir pOutStream->Seek(0); 3808cdf0e10cSrcweir 3809cdf0e10cSrcweir while( !pInStream->IsEof() && nErr == ERRCODE_NONE ) 3810cdf0e10cSrcweir { 3811cdf0e10cSrcweir sal_uInt32 nRead = pInStream->Read( pBuf, 8192 ); 3812cdf0e10cSrcweir nErr = pInStream->GetError(); 3813cdf0e10cSrcweir pOutStream->Write( pBuf, nRead ); 3814cdf0e10cSrcweir } 3815cdf0e10cSrcweir 3816cdf0e10cSrcweir bTransferSuccess = sal_True; 3817cdf0e10cSrcweir delete[] pBuf; 3818cdf0e10cSrcweir CloseInStream(); 3819cdf0e10cSrcweir } 3820cdf0e10cSrcweir CloseOutStream_Impl(); 3821cdf0e10cSrcweir } 3822cdf0e10cSrcweir else 3823cdf0e10cSrcweir { 3824cdf0e10cSrcweir // Quite strange design, but currently it is expected that in this case no transfer happens 3825cdf0e10cSrcweir // TODO/LATER: get rid of this inconsistent part of the call design 3826cdf0e10cSrcweir bTransferSuccess = sal_True; 3827cdf0e10cSrcweir CloseInStream(); 3828cdf0e10cSrcweir } 3829cdf0e10cSrcweir 3830cdf0e10cSrcweir if ( !bTransferSuccess ) 3831cdf0e10cSrcweir { 3832cdf0e10cSrcweir SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 3833cdf0e10cSrcweir return; 3834cdf0e10cSrcweir } 3835cdf0e10cSrcweir } 3836cdf0e10cSrcweir 3837cdf0e10cSrcweir CloseStorage(); 3838cdf0e10cSrcweir } 3839cdf0e10cSrcweir 3840cdf0e10cSrcweir //---------------------------------------------------------------- 3841cdf0e10cSrcweir void SfxMedium::CreateTempFileNoCopy() 3842cdf0e10cSrcweir { 3843cdf0e10cSrcweir // this call always replaces the existing temporary file 3844cdf0e10cSrcweir if ( pImp->pTempFile ) 38453b5992cdSOliver-Rainer Wittmann { 3846cdf0e10cSrcweir delete pImp->pTempFile; 38473b5992cdSOliver-Rainer Wittmann pImp->pTempFile = NULL; 38483b5992cdSOliver-Rainer Wittmann } 3849cdf0e10cSrcweir 38503b5992cdSOliver-Rainer Wittmann do 38513b5992cdSOliver-Rainer Wittmann { 3852cdf0e10cSrcweir pImp->pTempFile = new ::utl::TempFile(); 38533b5992cdSOliver-Rainer Wittmann if ( GetName().Equals( pImp->pTempFile->GetURL() ) ) 38543b5992cdSOliver-Rainer Wittmann { 38553b5992cdSOliver-Rainer Wittmann delete pImp->pTempFile; 38563b5992cdSOliver-Rainer Wittmann pImp->pTempFile = NULL; 38573b5992cdSOliver-Rainer Wittmann } 38583b5992cdSOliver-Rainer Wittmann } while ( pImp->pTempFile == NULL ); 3859cdf0e10cSrcweir pImp->pTempFile->EnableKillingFile( sal_True ); 3860cdf0e10cSrcweir aName = pImp->pTempFile->GetFileName(); 3861cdf0e10cSrcweir if ( !aName.Len() ) 3862cdf0e10cSrcweir { 3863cdf0e10cSrcweir SetError( ERRCODE_IO_CANTWRITE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); 3864cdf0e10cSrcweir return; 3865cdf0e10cSrcweir } 3866cdf0e10cSrcweir 3867cdf0e10cSrcweir CloseOutStream_Impl(); 3868cdf0e10cSrcweir CloseStorage(); 3869cdf0e10cSrcweir } 3870cdf0e10cSrcweir 3871cdf0e10cSrcweir ::rtl::OUString SfxMedium::GetCharset() 3872cdf0e10cSrcweir { 3873cdf0e10cSrcweir if( !pImp->bIsCharsetInitialized ) 3874cdf0e10cSrcweir { 3875cdf0e10cSrcweir // Set an error in case there is no content? 3876cdf0e10cSrcweir if ( GetContent().is() ) 3877cdf0e10cSrcweir { 3878cdf0e10cSrcweir pImp->bIsCharsetInitialized = sal_True; 3879cdf0e10cSrcweir 3880cdf0e10cSrcweir try 3881cdf0e10cSrcweir { 3882cdf0e10cSrcweir Any aAny = pImp->aContent.getPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ) ); 3883cdf0e10cSrcweir ::rtl::OUString aField; 3884cdf0e10cSrcweir aAny >>= aField; 3885cdf0e10cSrcweir 3886cdf0e10cSrcweir ::rtl::OString sContent = ::rtl::OUStringToOString( aField, RTL_TEXTENCODING_ASCII_US ); 3887cdf0e10cSrcweir ByteString sType, sSubType; 3888cdf0e10cSrcweir INetContentTypeParameterList aParameters; 3889cdf0e10cSrcweir 3890cdf0e10cSrcweir if( INetContentTypes::parse( sContent, sType, sSubType, &aParameters ) ) 3891cdf0e10cSrcweir { 3892cdf0e10cSrcweir const INetContentTypeParameter * pCharset = aParameters.find("charset"); 3893cdf0e10cSrcweir if (pCharset != 0) 3894cdf0e10cSrcweir pImp->aCharset = pCharset->m_sValue; 3895cdf0e10cSrcweir } 3896cdf0e10cSrcweir } 3897cdf0e10cSrcweir catch ( ::com::sun::star::uno::Exception& ) 3898cdf0e10cSrcweir { 3899cdf0e10cSrcweir } 3900cdf0e10cSrcweir } 3901cdf0e10cSrcweir } 3902cdf0e10cSrcweir 3903cdf0e10cSrcweir return pImp->aCharset; 3904cdf0e10cSrcweir } 3905cdf0e10cSrcweir 3906cdf0e10cSrcweir void SfxMedium::SetCharset( ::rtl::OUString aChs ) 3907cdf0e10cSrcweir { 3908cdf0e10cSrcweir pImp->bIsCharsetInitialized = sal_True; 3909cdf0e10cSrcweir pImp->aCharset = aChs; 3910cdf0e10cSrcweir } 3911cdf0e10cSrcweir 3912cdf0e10cSrcweir sal_Bool SfxMedium::SignContents_Impl( sal_Bool bScriptingContent, const ::rtl::OUString& aODFVersion, sal_Bool bHasValidDocumentSignature ) 3913cdf0e10cSrcweir { 3914cdf0e10cSrcweir sal_Bool bChanges = sal_False; 3915cdf0e10cSrcweir 3916cdf0e10cSrcweir // the medium should be closed to be able to sign, the caller is responsible to close it 3917cdf0e10cSrcweir if ( !IsOpen() && !GetError() ) 3918cdf0e10cSrcweir { 3919cdf0e10cSrcweir // The component should know if there was a valid document signature, since 3920cdf0e10cSrcweir // it should show a warning in this case 3921cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 3922cdf0e10cSrcweir aArgs[0] <<= aODFVersion; 3923cdf0e10cSrcweir aArgs[1] <<= bHasValidDocumentSignature; 3924cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::security::XDocumentDigitalSignatures > xSigner( 3925cdf0e10cSrcweir comphelper::getProcessServiceFactory()->createInstanceWithArguments( 3926cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ), 3927cdf0e10cSrcweir aArgs ), 3928cdf0e10cSrcweir ::com::sun::star::uno::UNO_QUERY ); 3929cdf0e10cSrcweir 3930cdf0e10cSrcweir if ( xSigner.is() ) 3931cdf0e10cSrcweir { 3932cdf0e10cSrcweir uno::Reference< embed::XStorage > xWriteableZipStor; 3933cdf0e10cSrcweir if ( !IsReadOnly() ) 3934cdf0e10cSrcweir { 3935cdf0e10cSrcweir // we can reuse the temporary file if there is one already 3936cdf0e10cSrcweir CreateTempFile( sal_False ); 3937cdf0e10cSrcweir GetMedium_Impl(); 3938cdf0e10cSrcweir 3939cdf0e10cSrcweir try 3940cdf0e10cSrcweir { 3941cdf0e10cSrcweir if ( !pImp->xStream.is() ) 3942cdf0e10cSrcweir throw uno::RuntimeException(); 3943cdf0e10cSrcweir 3944cdf0e10cSrcweir xWriteableZipStor = ::comphelper::OStorageHelper::GetStorageOfFormatFromStream( ZIP_STORAGE_FORMAT_STRING, pImp->xStream ); 3945cdf0e10cSrcweir if ( !xWriteableZipStor.is() ) 3946cdf0e10cSrcweir throw uno::RuntimeException(); 3947cdf0e10cSrcweir 3948cdf0e10cSrcweir uno::Reference< embed::XStorage > xMetaInf = xWriteableZipStor->openStorageElement( 3949cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "META-INF" ) ), 3950cdf0e10cSrcweir embed::ElementModes::READWRITE ); 3951cdf0e10cSrcweir if ( !xMetaInf.is() ) 3952cdf0e10cSrcweir throw uno::RuntimeException(); 3953cdf0e10cSrcweir 3954cdf0e10cSrcweir if ( bScriptingContent ) 3955cdf0e10cSrcweir { 3956cdf0e10cSrcweir // If the signature has already the document signature it will be removed 3957cdf0e10cSrcweir // after the scripting signature is inserted. 3958cdf0e10cSrcweir uno::Reference< io::XStream > xStream( 3959cdf0e10cSrcweir xMetaInf->openStreamElement( xSigner->getScriptingContentSignatureDefaultStreamName(), 3960cdf0e10cSrcweir embed::ElementModes::READWRITE ), 3961cdf0e10cSrcweir uno::UNO_SET_THROW ); 3962cdf0e10cSrcweir 3963cdf0e10cSrcweir if ( xSigner->signScriptingContent( GetZipStorageToSign_Impl(), xStream ) ) 3964cdf0e10cSrcweir { 3965cdf0e10cSrcweir // remove the document signature if any 3966cdf0e10cSrcweir ::rtl::OUString aDocSigName = xSigner->getDocumentContentSignatureDefaultStreamName(); 3967cdf0e10cSrcweir if ( aDocSigName.getLength() && xMetaInf->hasByName( aDocSigName ) ) 3968cdf0e10cSrcweir xMetaInf->removeElement( aDocSigName ); 3969cdf0e10cSrcweir 3970cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW ); 3971cdf0e10cSrcweir xTransact->commit(); 3972cdf0e10cSrcweir xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW ); 3973cdf0e10cSrcweir xTransact->commit(); 3974cdf0e10cSrcweir 3975cdf0e10cSrcweir // the temporary file has been written, commit it to the original file 3976cdf0e10cSrcweir Commit(); 3977cdf0e10cSrcweir bChanges = sal_True; 3978cdf0e10cSrcweir } 3979cdf0e10cSrcweir } 3980cdf0e10cSrcweir else 3981cdf0e10cSrcweir { 3982cdf0e10cSrcweir uno::Reference< io::XStream > xStream( 3983cdf0e10cSrcweir xMetaInf->openStreamElement( xSigner->getDocumentContentSignatureDefaultStreamName(), 3984cdf0e10cSrcweir embed::ElementModes::READWRITE ), 3985cdf0e10cSrcweir uno::UNO_SET_THROW ); 3986cdf0e10cSrcweir 3987cdf0e10cSrcweir if ( xSigner->signDocumentContent( GetZipStorageToSign_Impl(), xStream ) ) 3988cdf0e10cSrcweir { 3989cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW ); 3990cdf0e10cSrcweir xTransact->commit(); 3991cdf0e10cSrcweir xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW ); 3992cdf0e10cSrcweir xTransact->commit(); 3993cdf0e10cSrcweir 3994cdf0e10cSrcweir // the temporary file has been written, commit it to the original file 3995cdf0e10cSrcweir Commit(); 3996cdf0e10cSrcweir bChanges = sal_True; 3997cdf0e10cSrcweir } 3998cdf0e10cSrcweir } 3999cdf0e10cSrcweir } 4000cdf0e10cSrcweir catch ( uno::Exception& ) 4001cdf0e10cSrcweir { 4002cdf0e10cSrcweir OSL_ENSURE( sal_False, "Couldn't use signing functionality!\n" ); 4003cdf0e10cSrcweir } 4004cdf0e10cSrcweir 4005cdf0e10cSrcweir CloseAndRelease(); 4006cdf0e10cSrcweir } 4007cdf0e10cSrcweir else 4008cdf0e10cSrcweir { 4009cdf0e10cSrcweir try 4010cdf0e10cSrcweir { 4011cdf0e10cSrcweir if ( bScriptingContent ) 4012cdf0e10cSrcweir xSigner->showScriptingContentSignatures( GetZipStorageToSign_Impl(), uno::Reference< io::XInputStream >() ); 4013cdf0e10cSrcweir else 4014cdf0e10cSrcweir xSigner->showDocumentContentSignatures( GetZipStorageToSign_Impl(), uno::Reference< io::XInputStream >() ); 4015cdf0e10cSrcweir } 4016cdf0e10cSrcweir catch( uno::Exception& ) 4017cdf0e10cSrcweir { 4018cdf0e10cSrcweir OSL_ENSURE( sal_False, "Couldn't use signing functionality!\n" ); 4019cdf0e10cSrcweir } 4020cdf0e10cSrcweir } 4021cdf0e10cSrcweir } 4022cdf0e10cSrcweir 4023cdf0e10cSrcweir ResetError(); 4024cdf0e10cSrcweir } 4025cdf0e10cSrcweir 4026cdf0e10cSrcweir return bChanges; 4027cdf0e10cSrcweir } 4028cdf0e10cSrcweir 4029cdf0e10cSrcweir //---------------------------------------------------------------- 4030cdf0e10cSrcweir sal_uInt16 SfxMedium::GetCachedSignatureState_Impl() 4031cdf0e10cSrcweir { 4032cdf0e10cSrcweir return pImp->m_nSignatureState; 4033cdf0e10cSrcweir } 4034cdf0e10cSrcweir 4035cdf0e10cSrcweir //---------------------------------------------------------------- 4036cdf0e10cSrcweir void SfxMedium::SetCachedSignatureState_Impl( sal_uInt16 nState ) 4037cdf0e10cSrcweir { 4038cdf0e10cSrcweir pImp->m_nSignatureState = nState; 4039cdf0e10cSrcweir } 4040cdf0e10cSrcweir 4041cdf0e10cSrcweir sal_Bool SfxMedium::HasStorage_Impl() const 4042cdf0e10cSrcweir { 4043cdf0e10cSrcweir return pImp->xStorage.is(); 4044cdf0e10cSrcweir } 4045cdf0e10cSrcweir 4046cdf0e10cSrcweir sal_Bool SfxMedium::IsOpen() const 4047cdf0e10cSrcweir { 4048cdf0e10cSrcweir return pInStream || pOutStream || pImp->xStorage.is(); 4049cdf0e10cSrcweir } 4050cdf0e10cSrcweir 4051cdf0e10cSrcweir ::rtl::OUString SfxMedium::CreateTempCopyWithExt( const ::rtl::OUString& aURL ) 4052cdf0e10cSrcweir { 4053cdf0e10cSrcweir ::rtl::OUString aResult; 4054cdf0e10cSrcweir 4055cdf0e10cSrcweir if ( aURL.getLength() ) 4056cdf0e10cSrcweir { 4057cdf0e10cSrcweir sal_Int32 nPrefixLen = aURL.lastIndexOf( '.' ); 4058cdf0e10cSrcweir String aExt = ( nPrefixLen == -1 ) ? String() : String( aURL.copy( nPrefixLen ) ); 4059cdf0e10cSrcweir 4060cdf0e10cSrcweir ::rtl::OUString aNewTempFileURL = ::utl::TempFile( String(), &aExt ).GetURL(); 4061cdf0e10cSrcweir if ( aNewTempFileURL.getLength() ) 4062cdf0e10cSrcweir { 4063cdf0e10cSrcweir INetURLObject aSource( aURL ); 4064cdf0e10cSrcweir INetURLObject aDest( aNewTempFileURL ); 4065cdf0e10cSrcweir ::rtl::OUString aFileName = aDest.getName( INetURLObject::LAST_SEGMENT, 4066cdf0e10cSrcweir true, 4067cdf0e10cSrcweir INetURLObject::DECODE_WITH_CHARSET ); 4068cdf0e10cSrcweir if ( aFileName.getLength() && aDest.removeSegment() ) 4069cdf0e10cSrcweir { 4070cdf0e10cSrcweir try 4071cdf0e10cSrcweir { 4072cdf0e10cSrcweir uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > xComEnv; 4073cdf0e10cSrcweir ::ucbhelper::Content aTargetContent( aDest.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); 4074cdf0e10cSrcweir ::ucbhelper::Content aSourceContent( aSource.GetMainURL( INetURLObject::NO_DECODE ), xComEnv ); 4075cdf0e10cSrcweir if ( aTargetContent.transferContent( aSourceContent, 4076cdf0e10cSrcweir ::ucbhelper::InsertOperation_COPY, 4077cdf0e10cSrcweir aFileName, 4078cdf0e10cSrcweir NameClash::OVERWRITE ) ) 4079cdf0e10cSrcweir { 4080cdf0e10cSrcweir // Success 4081cdf0e10cSrcweir aResult = aNewTempFileURL; 4082cdf0e10cSrcweir } 4083cdf0e10cSrcweir } 4084cdf0e10cSrcweir catch( uno::Exception& ) 4085cdf0e10cSrcweir {} 4086cdf0e10cSrcweir } 4087cdf0e10cSrcweir } 4088cdf0e10cSrcweir } 4089cdf0e10cSrcweir 4090cdf0e10cSrcweir return aResult; 4091cdf0e10cSrcweir } 4092cdf0e10cSrcweir 4093cdf0e10cSrcweir sal_Bool SfxMedium::CallApproveHandler( const uno::Reference< task::XInteractionHandler >& xHandler, uno::Any aRequest, sal_Bool bAllowAbort ) 4094cdf0e10cSrcweir { 4095cdf0e10cSrcweir sal_Bool bResult = sal_False; 4096cdf0e10cSrcweir 4097cdf0e10cSrcweir if ( xHandler.is() ) 4098cdf0e10cSrcweir { 4099cdf0e10cSrcweir try 4100cdf0e10cSrcweir { 4101cdf0e10cSrcweir uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( bAllowAbort ? 2 : 1 ); 4102cdf0e10cSrcweir 4103cdf0e10cSrcweir ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove ); 4104cdf0e10cSrcweir aContinuations[ 0 ] = pApprove.get(); 4105cdf0e10cSrcweir 4106cdf0e10cSrcweir if ( bAllowAbort ) 4107cdf0e10cSrcweir { 4108cdf0e10cSrcweir ::rtl::Reference< ::comphelper::OInteractionAbort > pAbort( new ::comphelper::OInteractionAbort ); 4109cdf0e10cSrcweir aContinuations[ 1 ] = pAbort.get(); 4110cdf0e10cSrcweir } 4111cdf0e10cSrcweir 4112cdf0e10cSrcweir xHandler->handle(::framework::InteractionRequest::CreateRequest (aRequest,aContinuations)); 4113cdf0e10cSrcweir bResult = pApprove->wasSelected(); 4114cdf0e10cSrcweir } 4115cdf0e10cSrcweir catch( const Exception& ) 4116cdf0e10cSrcweir { 4117cdf0e10cSrcweir } 4118cdf0e10cSrcweir } 4119cdf0e10cSrcweir 4120cdf0e10cSrcweir return bResult; 4121cdf0e10cSrcweir } 4122cdf0e10cSrcweir 4123cdf0e10cSrcweir ::rtl::OUString SfxMedium::SwitchDocumentToTempFile() 4124cdf0e10cSrcweir { 4125cdf0e10cSrcweir // the method returns empty string in case of failure 4126cdf0e10cSrcweir ::rtl::OUString aResult; 4127cdf0e10cSrcweir ::rtl::OUString aOrigURL = aLogicName; 4128cdf0e10cSrcweir 4129cdf0e10cSrcweir if ( aOrigURL.getLength() ) 4130cdf0e10cSrcweir { 4131cdf0e10cSrcweir sal_Int32 nPrefixLen = aOrigURL.lastIndexOf( '.' ); 4132cdf0e10cSrcweir String aExt = ( nPrefixLen == -1 ) ? String() : String( aOrigURL.copy( nPrefixLen ) ); 4133cdf0e10cSrcweir ::rtl::OUString aNewURL = ::utl::TempFile( String(), &aExt ).GetURL(); 4134cdf0e10cSrcweir 4135cdf0e10cSrcweir // TODO/LATER: In future the aLogicName should be set to shared folder URL 4136cdf0e10cSrcweir // and a temporary file should be created. Transport_Impl should be impossible then. 4137cdf0e10cSrcweir if ( aNewURL.getLength() ) 4138cdf0e10cSrcweir { 4139cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage = GetStorage(); 4140cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY ); 4141cdf0e10cSrcweir 4142cdf0e10cSrcweir if ( xOptStorage.is() ) 4143cdf0e10cSrcweir { 4144cdf0e10cSrcweir // TODO/LATER: reuse the pImp->pTempFile if it already exists 4145cdf0e10cSrcweir CanDisposeStorage_Impl( sal_False ); 4146cdf0e10cSrcweir Close(); 4147cdf0e10cSrcweir SetPhysicalName_Impl( String() ); 4148cdf0e10cSrcweir SetName( aNewURL ); 4149cdf0e10cSrcweir 4150cdf0e10cSrcweir // remove the readonly state 4151cdf0e10cSrcweir sal_Bool bWasReadonly = sal_False; 4152cdf0e10cSrcweir nStorOpenMode = SFX_STREAM_READWRITE; 4153cdf0e10cSrcweir SFX_ITEMSET_ARG( pSet, pReadOnlyItem, SfxBoolItem, SID_DOC_READONLY, sal_False ); 4154cdf0e10cSrcweir if ( pReadOnlyItem && pReadOnlyItem->GetValue() ) 4155cdf0e10cSrcweir bWasReadonly = sal_True; 4156cdf0e10cSrcweir GetItemSet()->ClearItem( SID_DOC_READONLY ); 4157cdf0e10cSrcweir 4158cdf0e10cSrcweir GetMedium_Impl(); 4159cdf0e10cSrcweir LockOrigFileOnDemand( sal_False, sal_False ); 4160cdf0e10cSrcweir CreateTempFile( sal_True ); 4161cdf0e10cSrcweir GetMedium_Impl(); 4162cdf0e10cSrcweir 4163cdf0e10cSrcweir if ( pImp->xStream.is() ) 4164cdf0e10cSrcweir { 4165cdf0e10cSrcweir try 4166cdf0e10cSrcweir { 4167cdf0e10cSrcweir xOptStorage->writeAndAttachToStream( pImp->xStream ); 4168cdf0e10cSrcweir pImp->xStorage = xStorage; 4169cdf0e10cSrcweir aResult = aNewURL; 4170cdf0e10cSrcweir } 4171cdf0e10cSrcweir catch( uno::Exception& ) 4172cdf0e10cSrcweir {} 4173cdf0e10cSrcweir } 4174cdf0e10cSrcweir 4175cdf0e10cSrcweir if ( !aResult.getLength() ) 4176cdf0e10cSrcweir { 4177cdf0e10cSrcweir Close(); 4178cdf0e10cSrcweir SetPhysicalName_Impl( String() ); 4179cdf0e10cSrcweir SetName( aOrigURL ); 4180cdf0e10cSrcweir if ( bWasReadonly ) 4181cdf0e10cSrcweir { 4182cdf0e10cSrcweir // set the readonly state back 4183cdf0e10cSrcweir nStorOpenMode = SFX_STREAM_READONLY; 4184cdf0e10cSrcweir GetItemSet()->Put( SfxBoolItem(SID_DOC_READONLY, sal_True)); 4185cdf0e10cSrcweir } 4186cdf0e10cSrcweir GetMedium_Impl(); 4187cdf0e10cSrcweir pImp->xStorage = xStorage; 4188cdf0e10cSrcweir } 4189cdf0e10cSrcweir } 4190cdf0e10cSrcweir } 4191cdf0e10cSrcweir } 4192cdf0e10cSrcweir 4193cdf0e10cSrcweir return aResult; 4194cdf0e10cSrcweir } 4195cdf0e10cSrcweir 4196cdf0e10cSrcweir sal_Bool SfxMedium::SwitchDocumentToFile( ::rtl::OUString aURL ) 4197cdf0e10cSrcweir { 4198cdf0e10cSrcweir // the method is only for storage based documents 4199cdf0e10cSrcweir sal_Bool bResult = sal_False; 4200cdf0e10cSrcweir ::rtl::OUString aOrigURL = aLogicName; 4201cdf0e10cSrcweir 4202cdf0e10cSrcweir if ( aURL.getLength() && aOrigURL.getLength() ) 4203cdf0e10cSrcweir { 4204cdf0e10cSrcweir uno::Reference< embed::XStorage > xStorage = GetStorage(); 4205cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY ); 4206cdf0e10cSrcweir 4207cdf0e10cSrcweir if ( xOptStorage.is() ) 4208cdf0e10cSrcweir { 4209cdf0e10cSrcweir // TODO/LATER: reuse the pImp->pTempFile if it already exists 4210cdf0e10cSrcweir CanDisposeStorage_Impl( sal_False ); 4211cdf0e10cSrcweir Close(); 4212cdf0e10cSrcweir SetPhysicalName_Impl( String() ); 4213cdf0e10cSrcweir SetName( aURL ); 4214cdf0e10cSrcweir 4215cdf0e10cSrcweir // open the temporary file based document 4216cdf0e10cSrcweir GetMedium_Impl(); 4217cdf0e10cSrcweir LockOrigFileOnDemand( sal_False, sal_False ); 4218cdf0e10cSrcweir CreateTempFile( sal_True ); 4219cdf0e10cSrcweir GetMedium_Impl(); 4220cdf0e10cSrcweir 4221cdf0e10cSrcweir if ( pImp->xStream.is() ) 4222cdf0e10cSrcweir { 4223cdf0e10cSrcweir try 4224cdf0e10cSrcweir { 4225cdf0e10cSrcweir uno::Reference< io::XTruncate > xTruncate( pImp->xStream, uno::UNO_QUERY_THROW ); 4226cdf0e10cSrcweir if ( xTruncate.is() ) 4227cdf0e10cSrcweir xTruncate->truncate(); 4228cdf0e10cSrcweir 4229cdf0e10cSrcweir xOptStorage->writeAndAttachToStream( pImp->xStream ); 4230cdf0e10cSrcweir pImp->xStorage = xStorage; 4231cdf0e10cSrcweir bResult = sal_True; 4232cdf0e10cSrcweir } 4233cdf0e10cSrcweir catch( uno::Exception& ) 4234cdf0e10cSrcweir {} 4235cdf0e10cSrcweir } 4236cdf0e10cSrcweir 4237cdf0e10cSrcweir if ( !bResult ) 4238cdf0e10cSrcweir { 4239cdf0e10cSrcweir Close(); 4240cdf0e10cSrcweir SetPhysicalName_Impl( String() ); 4241cdf0e10cSrcweir SetName( aOrigURL ); 4242cdf0e10cSrcweir GetMedium_Impl(); 4243cdf0e10cSrcweir pImp->xStorage = xStorage; 4244cdf0e10cSrcweir } 4245cdf0e10cSrcweir } 4246cdf0e10cSrcweir } 4247cdf0e10cSrcweir 4248cdf0e10cSrcweir return bResult; 4249cdf0e10cSrcweir } 4250cdf0e10cSrcweir 4251