20#include <config_features.h>
29#include <com/sun/star/task/InteractionHandler.hpp>
30#include <com/sun/star/task/XStatusIndicator.hpp>
31#include <com/sun/star/uno/Reference.h>
32#include <com/sun/star/ucb/XContent.hpp>
33#include <com/sun/star/container/XChild.hpp>
34#include <com/sun/star/document/XDocumentRevisionListPersistence.hpp>
35#include <com/sun/star/document/LockedDocumentRequest.hpp>
36#include <com/sun/star/document/LockedOnSavingRequest.hpp>
37#include <com/sun/star/document/OwnLockOnDocumentRequest.hpp>
38#include <com/sun/star/document/LockFileIgnoreRequest.hpp>
39#include <com/sun/star/document/LockFileCorruptRequest.hpp>
40#include <com/sun/star/document/ChangedByOthersRequest.hpp>
41#include <com/sun/star/document/ReloadEditableRequest.hpp>
42#include <com/sun/star/embed/XTransactedObject.hpp>
43#include <com/sun/star/embed/ElementModes.hpp>
44#include <com/sun/star/embed/UseBackupException.hpp>
45#include <com/sun/star/embed/XOptimizedStorage.hpp>
46#include <com/sun/star/frame/Desktop.hpp>
47#include <com/sun/star/frame/XModel.hpp>
48#include <com/sun/star/frame/XTerminateListener.hpp>
49#include <com/sun/star/graphic/XGraphic.hpp>
50#include <com/sun/star/ucb/ContentCreationException.hpp>
51#include <com/sun/star/ucb/InteractiveIOException.hpp>
52#include <com/sun/star/ucb/CommandFailedException.hpp>
53#include <com/sun/star/ucb/CommandAbortedException.hpp>
54#include <com/sun/star/ucb/InteractiveLockingLockedException.hpp>
55#include <com/sun/star/ucb/InteractiveNetworkReadException.hpp>
56#include <com/sun/star/ucb/InteractiveNetworkWriteException.hpp>
57#include <com/sun/star/ucb/Lock.hpp>
58#include <com/sun/star/ucb/NameClashException.hpp>
59#include <com/sun/star/ucb/XCommandEnvironment.hpp>
60#include <com/sun/star/ucb/XProgressHandler.hpp>
61#include <com/sun/star/io/XOutputStream.hpp>
62#include <com/sun/star/io/XInputStream.hpp>
63#include <com/sun/star/io/XTruncate.hpp>
64#include <com/sun/star/io/XSeekable.hpp>
65#include <com/sun/star/lang/XSingleServiceFactory.hpp>
66#include <com/sun/star/ucb/InsertCommandArgument.hpp>
67#include <com/sun/star/ucb/NameClash.hpp>
68#include <com/sun/star/beans/NamedValue.hpp>
69#include <com/sun/star/beans/PropertyValue.hpp>
70#include <com/sun/star/security/DocumentDigitalSignatures.hpp>
71#include <com/sun/star/security/XCertificate.hpp>
95#include <osl/file.hxx>
100#include <tools/datetime.hxx>
112#include <com/sun/star/document/DocumentRevisionListPersistence.hpp>
119#include <sfx2/sfxsids.hrc>
122#include <officecfg/Office/Common.hxx>
132#include <condition_variable>
134#include <com/sun/star/io/WrongFormatException.hpp>
149struct ReadOnlyMediumEntry
151 ReadOnlyMediumEntry(std::shared_ptr<std::recursive_mutex> pMutex,
152 std::shared_ptr<bool> pIsDestructed)
153 : _pMutex(
std::move(pMutex))
154 , _pIsDestructed(
std::move(pIsDestructed))
157 std::shared_ptr<std::recursive_mutex> _pMutex;
158 std::shared_ptr<bool> _pIsDestructed;
170#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
172bool IsSystemFileLockingUsed()
174#if HAVE_FEATURE_MACOSX_SANDBOX
177 return officecfg::Office::Common::Misc::UseDocumentSystemFileLocking::get();
182bool IsOOoLockFileUsed()
184#if HAVE_FEATURE_MACOSX_SANDBOX
187 return officecfg::Office::Common::Misc::UseDocumentOOoLockFile::get();
193 return officecfg::Office::Common::Misc::UseLocking::get();
198#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
199bool IsWebDAVLockingUsed()
201 return officecfg::Office::Common::Misc::UseWebDAVFileLocking::get();
206sal_uInt64 GetDefaultFileAttributes(
const OUString& rURL)
214 osl::File aFile(rURL);
215 osl::File::RC nRes = aFile.open(osl_File_OpenFlag_Create);
216 if (nRes != osl::File::E_None && nRes != osl::File::E_EXIST)
221 osl::DirectoryItem aItem;
222 if (osl::DirectoryItem::get(rURL, aItem) != osl::DirectoryItem::E_None)
225 osl::FileStatus aStatus(osl_FileStatus_Mask_Attributes);
226 if (aItem.getFileStatus(aStatus) != osl::DirectoryItem::E_None)
229 nRet = aStatus.getAttributes();
247 OUString sPath = rURL.
getFSysPath(FSysStyle::Unix);
252 if (lstat(sPath.toUtf8().getStr(), &buf) != 0)
256 if (buf.st_nlink > 1 || S_ISLNK(buf.st_mode))
267class CheckReadOnlyTaskTerminateListener
268 :
public ::cppu::WeakImplHelper<css::frame::XTerminateListener>
272 void SAL_CALL disposing(
const css::lang::EventObject&
Source)
override;
275 void SAL_CALL queryTermination(
const css::lang::EventObject&
aEvent)
override;
276 void SAL_CALL notifyTermination(
const css::lang::EventObject&
aEvent)
override;
278 bool bIsTerminated =
false;
279 std::condition_variable mCond;
286 CheckReadOnlyTask(
const std::shared_ptr<comphelper::ThreadTaskTag>& pTag);
287 ~CheckReadOnlyTask();
289 virtual void doWork()
override;
297CheckReadOnlyTask::CheckReadOnlyTask(
const std::shared_ptr<comphelper::ThreadTaskTag>& pTag)
299 ,
m_xListener(new CheckReadOnlyTaskTerminateListener)
301 Reference<css::frame::XDesktop> xDesktop
309CheckReadOnlyTask::~CheckReadOnlyTask()
311 Reference<css::frame::XDesktop> xDesktop
327CheckReadOnlyTaskTerminateListener::disposing(
const css::lang::EventObject& )
332CheckReadOnlyTaskTerminateListener::queryTermination(
const css::lang::EventObject& )
337CheckReadOnlyTaskTerminateListener::notifyTermination(
const css::lang::EventObject& )
339 std::unique_lock<std::mutex>
lock(mMutex);
340 bIsTerminated =
true;
382 mutable std::shared_ptr<SfxItemSet>
m_pSet;
442 bUpdatePickList(true),
444 bDownloadDone( true ),
446 bUseInteractionHandler( true ),
447 bAllowDefaultIntHdl( false ),
448 bDisposeStorage( false ),
449 bStorageBasedOnInStream( false ),
450 m_bSalvageMode( false ),
451 m_bVersionsAlreadyLoaded( false ),
453 m_bMSOLockFileCreated( false ),
454 m_bDisableUnlockWebDAV( false ),
455 m_bGotDateTime( false ),
456 m_bRemoveBackup( false ),
457 m_bOriginallyReadOnly(false),
458 m_bOriginallyLoadedReadOnly(false),
459 m_bTriedStorage(false),
461 m_bInputStreamIsReadOnly(false),
463 m_pReloadEvent(nullptr),
477 std::unique_lock<std::recursive_mutex> chkEditLock;
486 if(
pImpl->m_pInStream )
487 pImpl->m_pInStream->ResetError();
488 if(
pImpl->m_pOutStream )
489 pImpl->m_pOutStream->ResetError();
494 return pImpl->m_eWarningError;
499 return pImpl->nLastStorageError;
504 pImpl->m_eError = nError;
509 pImpl->m_eWarningError = nWarningError;
515 if(!lError &&
pImpl->m_pInStream)
516 lError =
pImpl->m_pInStream->GetErrorCode();
517 if(!lError &&
pImpl->m_pOutStream)
518 lError =
pImpl->m_pOutStream->GetErrorCode();
525 if (
pImpl->m_aDateTime.Seconds == aInitDate.Seconds
526 &&
pImpl->m_aDateTime.Minutes == aInitDate.Minutes
527 &&
pImpl->m_aDateTime.Hours == aInitDate.Hours
528 &&
pImpl->m_aDateTime.Day == aInitDate.Day
529 &&
pImpl->m_aDateTime.Month == aInitDate.Month
530 &&
pImpl->m_aDateTime.Year == aInitDate.Year )
535 if ( !xHandler.is() )
541 document::ChangedByOthersRequest() ) );
542 uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations{
543 new ::ucbhelper::InteractionAbort( xInteractionRequestImpl.get() ),
544 new ::ucbhelper::InteractionApprove( xInteractionRequestImpl.get() )
546 xInteractionRequestImpl->setContinuations( aContinuations );
548 xHandler->handle( xInteractionRequestImpl );
551 if ( uno::Reference< task::XInteractionAbort >( xSelected.get(), uno::UNO_QUERY ).is() )
556 catch (
const uno::Exception& )
568 if ( ( bIgnoreOldValue || !
pImpl->m_bGotDateTime ) && !
pImpl->m_aLogicName.isEmpty() )
579 pImpl->m_bGotDateTime =
true;
581 catch (
const css::uno::Exception& )
586 return pImpl->m_aDateTime;
592 if ( !
pImpl->aContent.get().is() )
594 Reference < css::ucb::XContent > xContent;
598 css:: uno::Reference< task::XInteractionHandler > xIH(
601 css::uno::Reference< css::ucb::XProgressHandler > xProgress;
604 const SfxUnoAnyItem* pItem = SfxItemSet::GetItem<SfxUnoAnyItem>(
pImpl->m_pSet.get(), SID_CONTENT,
false);
622 if ( !
pImpl->m_aName.isEmpty() )
623 osl::FileBase::getFileURLFromSystemPath(
pImpl->m_aName,
aURL );
624 else if ( !
pImpl->m_aLogicName.isEmpty() )
626 if (!
aURL.isEmpty() )
631 return pImpl->aContent.get();
639 if ((bIsRemote && !officecfg::Office::Common::Save::URL::Internet::get())
640 || (!bIsRemote && !officecfg::Office::Common::Save::URL::FileSystem::get()))
645 return pBaseURLItem->GetValue();
652 Any aAny =
pImpl->aContent.getPropertyValue(
"BaseURI");
655 catch (
const css::uno::Exception& )
659 if ( aBaseURL.isEmpty() )
668 return pSkipImagesItem && pSkipImagesItem->
GetValue() ==
"SkipImages";
673 if (
pImpl->m_pInStream )
674 return pImpl->m_pInStream.get();
676 if (
pImpl->pTempFile )
680 pImpl->m_eError =
pImpl->m_pInStream->GetError();
682 if (!
pImpl->m_eError && (
pImpl->m_nStorOpenMode & StreamMode::WRITE)
683 && !
pImpl->m_pInStream->IsWritable() )
686 pImpl->m_pInStream.reset();
689 return pImpl->m_pInStream.get();
697 return pImpl->m_pInStream.get();
711 if (
pImpl->m_pInStream &&
pImpl->xStorage.is() )
713 if (
pImpl->bStorageBasedOnInStream )
723 pImpl->m_pInStream.reset();
725 pImpl->m_pSet->ClearItem( SID_INPUTSTREAM );
728 pImpl->xInputStream.clear();
730 if ( !
pImpl->m_pOutStream )
734 pImpl->xStream.clear();
736 pImpl->m_pSet->ClearItem( SID_STREAM );
743 if ( !
pImpl->m_pOutStream )
749 if (
pImpl->pTempFile )
755 if (getenv(
"SFX_MEDIUM_REUSE_STREAM") &&
pImpl->xStream.is())
757 assert(
pImpl->xStream->getOutputStream().is());
759 pImpl->xStream,
false);
766 pImpl->m_aName, StreamMode::STD_READWRITE) );
772 return pImpl->m_pOutStream.get();
783 if (
pImpl->m_pOutStream )
790 if (
pImpl->xStorage.is() )
795 pImpl->m_pOutStream.reset();
798 if ( !
pImpl->m_pInStream )
802 pImpl->xStream.clear();
804 pImpl->m_pSet->ClearItem( SID_STREAM );
811 if (
pImpl->m_aName.isEmpty() && !
pImpl->m_aLogicName.isEmpty() )
815 return pImpl->m_aName;
822 if(
pImpl->m_pInStream )
830 if(
pImpl->m_pInStream )
833 pImpl->bIsTemp =
true;
841 if(
pImpl->xStorage.is() )
843 else if(
pImpl->m_pOutStream )
844 pImpl->m_pOutStream->FlushBuffer();
845 else if(
pImpl->m_pInStream )
846 pImpl->m_pInStream->FlushBuffer();
867 if (
pImpl->xStorage.is() )
870 if (
pImpl->m_bTriedStorage )
871 return pImpl->bIsStorage;
873 if (
pImpl->pTempFile )
876 if ( osl::FileBase::getFileURLFromSystemPath(
pImpl->m_aName,
aURL )
877 != osl::FileBase::E_None )
879 SAL_WARN(
"sfx.doc",
"Physical name '" <<
pImpl->m_aName <<
"' not convertible to file URL");
882 if ( !
pImpl->bIsStorage )
883 pImpl->m_bTriedStorage =
true;
888 if ( !
pImpl->m_pInStream->GetError() && !
pImpl->bIsStorage )
889 pImpl->m_bTriedStorage =
true;
892 return pImpl->bIsStorage;
898 bool bPreview =
false;
907 OUString aFileFlags = pFlags->
GetValue();
908 aFileFlags = aFileFlags.toAsciiUpperCase();
909 if ( -1 != aFileFlags.indexOf(
'B' ) )
921 Reference< css::ucb::XCommandEnvironment > xDummyEnv;
923 bool bBasedOnOriginalFile =
925 && (
pImpl->m_aLogicName.isEmpty() || !
pImpl->m_bSalvageMode )
930 if ( bBasedOnOriginalFile &&
pImpl->m_aBackupURL.isEmpty()
934 if(
pImpl->m_aBackupURL.isEmpty() )
942 if (
pImpl->m_aBackupURL.isEmpty() )
945 return pImpl->m_aBackupURL;
952 return uno::Reference< embed::XStorage >();
956 if (
pImpl->xStorage.is() && (
pImpl->m_aLogicName.isEmpty() ||
pImpl->pTempFile ) )
957 return pImpl->xStorage;
960 if (
pImpl->m_pInStream && !
pImpl->m_pInStream->IsWritable() )
963 DBG_ASSERT( !
pImpl->m_pOutStream,
"OutStream in a readonly Medium?!" );
977 if ( !
pImpl->xStorage.is() || !
pImpl->m_pSet )
980 uno::Sequence< beans::NamedValue > aEncryptionData;
985 pImpl->m_pSet->ClearItem( SID_PASSWORD );
992 catch(
const uno::Exception& )
994 SAL_WARN(
"sfx.doc",
"It must be possible to set a common password for the storage" );
1000#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
1020OUString tryMSOwnerFiles(std::u16string_view sDocURL)
1026 aData = aMSOLockFile.GetLockData();
1028 catch(
const uno::Exception& )
1033 OUString sUserData =
aData[LockFileComponent::OOOUSERNAME];
1035 if (!sUserData.isEmpty())
1036 sUserData +=
" (MS Office)";
1041OUString tryForeignLockfiles(std::u16string_view sDocURL)
1043 OUString sUserData = tryMSOwnerFiles(sDocURL);
1045 return sUserData.trim();
1050 bool bIsLoading,
bool bOwnLock,
1051 bool bHandleSysLocked)
1056 if(
aData[LockFileComponent::OOOUSERNAME].isEmpty() &&
aData[LockFileComponent::SYSUSERNAME].isEmpty() && !bHandleSysLocked )
1062 if ( xHandler.is() && ( bIsLoading || !bHandleSysLocked || bOwnLock ) )
1064 OUString aDocumentURL
1069 sal_Int32 nContinuations = 3;
1073 aInfo =
aData[LockFileComponent::EDITTIME];
1075 xInteractionRequestImpl = new ::ucbhelper::InteractionRequest(
uno::Any(
1076 document::OwnLockOnDocumentRequest( OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo, !bIsLoading ) ) );
1082 if (!bHandleSysLocked)
1085 if ( !
aData[LockFileComponent::OOOUSERNAME].isEmpty() )
1086 aInfo =
aData[LockFileComponent::OOOUSERNAME];
1088 aInfo =
aData[LockFileComponent::SYSUSERNAME];
1090 if (aInfo.isEmpty() && !
GetURLObject().isAnyKnownWebDAVScheme())
1092 aInfo = tryForeignLockfiles(
1095 if ( !aInfo.isEmpty() && !
aData[LockFileComponent::EDITTIME].isEmpty() )
1096 aInfo +=
" ( " +
aData[LockFileComponent::EDITTIME] +
" )";
1100 xInteractionRequestImpl = new ::ucbhelper::InteractionRequest(
uno::Any(
1101 document::LockedOnSavingRequest(OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo)));
1106 xInteractionRequestImpl = new ::ucbhelper::InteractionRequest(
uno::Any(
1107 document::LockedDocumentRequest( OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) );
1111 uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations(nContinuations);
1112 auto pContinuations = aContinuations.getArray();
1113 pContinuations[0] = new ::ucbhelper::InteractionAbort( xInteractionRequestImpl.get() );
1114 pContinuations[1] = new ::ucbhelper::InteractionApprove( xInteractionRequestImpl.get() );
1115 pContinuations[2] = new ::ucbhelper::InteractionDisapprove( xInteractionRequestImpl.get() );
1116 if (nContinuations > 3)
1120 pContinuations[3] = new ::ucbhelper::InteractionRetry(xInteractionRequestImpl.get());
1122 xInteractionRequestImpl->setContinuations( aContinuations );
1124 xHandler->handle( xInteractionRequestImpl );
1126 bool bOpenReadOnly =
false;
1128 if ( uno::Reference< task::XInteractionAbort >( xSelected.get(), uno::UNO_QUERY ).is() )
1132 else if ( uno::Reference< task::XInteractionDisapprove >( xSelected.get(), uno::UNO_QUERY ).is() )
1146 else if (uno::Reference< task::XInteractionRetry >(xSelected.get(), uno::UNO_QUERY).is())
1151 else if (uno::Reference< task::XInteractionApprove >( xSelected.get(), uno::UNO_QUERY ).is())
1153 bOpenReadOnly =
true;
1157 pImpl->m_bNotifyWhenEditable =
true;
1159 bOpenReadOnly =
true;
1204 xIgnoreRequestImpl = new ::ucbhelper::InteractionRequest(
uno::Any( document::LockFileIgnoreRequest() ));
1207 xIgnoreRequestImpl = new ::ucbhelper::InteractionRequest(
uno::Any( document::LockFileCorruptRequest() ));
1211 uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations{
1212 new ::ucbhelper::InteractionAbort(xIgnoreRequestImpl.get()),
1213 new ::ucbhelper::InteractionApprove(xIgnoreRequestImpl.get())
1215 xIgnoreRequestImpl->setContinuations(aContinuations);
1217 xHandler->handle(xIgnoreRequestImpl);
1222 if (uno::Reference<task::XInteractionAbort>(xSelected.get(), uno::UNO_QUERY).is())
1227 else if (!uno::Reference<task::XInteractionApprove>(xSelected.get(), uno::UNO_QUERY).is())
1230 pImpl->m_bNotifyWhenEditable =
true;
1245 bool isSuitableProtocolForLocking(
const OUString & rLogicName)
1249#if !HAVE_FEATURE_MACOSX_SANDBOX
1250 if (eProt == INetProtocol::File) {
1254 return eProt == INetProtocol::Smb || eProt == INetProtocol::Sftp;
1263class LockInteractionHandler :
public ::cppu::WeakImplHelper<task::XInteractionHandler>
1266 uno::Reference<task::XInteractionHandler>
m_xHandler;
1269 explicit LockInteractionHandler(uno::Reference<task::XInteractionHandler>
const& xHandler)
1274 virtual void SAL_CALL handle(uno::Reference<task::XInteractionRequest>
const& xRequest)
override
1276 ucb::InteractiveNetworkWriteException readException;
1277 ucb::InteractiveNetworkReadException writeException;
1278 if ((xRequest->getRequest() >>= readException)
1279 || (xRequest->getRequest() >>= writeException))
1294 bool bTryIgnoreLockFile,
1297#if !HAVE_FEATURE_MULTIUSER_ENVIRONMENT
1300 (void) bTryIgnoreLockFile;
1313 if (!IsWebDAVLockingUsed())
1317 bool bResult =
pImpl->m_bLocked;
1318 bool bIsTemplate =
false;
1323 const SfxBoolItem* pTemplateItem = SfxItemSet::GetItem<SfxBoolItem>(
GetItemSet(), SID_TEMPLATE,
false);
1324 bIsTemplate = ( bLoading && pTemplateItem && pTemplateItem->
GetValue() );
1327 if ( !bIsTemplate && !bResult && !
IsReadOnly() )
1338 if (bLoading || bNoUI)
1340 xCHandler =
new LockInteractionHandler(xCHandler);
1342 Reference< css::ucb::XCommandEnvironment > xComEnv = new ::ucbhelper::CommandEnvironment(
1343 xCHandler, Reference< css::ucb::XProgressHandler >() );
1351 aContentToLock.
lock();
1354 catch ( ucb::InteractiveLockingLockedException& )
1357 if (!bNoUI || pLockData)
1364 aLockData[LockFileComponent::OOOUSERNAME] =
"Unknown user";
1371 aLockData[LockFileComponent::SYSUSERNAME]
1372 = aOwnData[LockFileComponent::SYSUSERNAME];
1374 uno::Sequence<css::ucb::Lock> aLocks;
1376 if ((aContentToLock.
getPropertyValue(
"DAV:lockdiscovery") >>= aLocks) && aLocks.hasElements())
1379 css::ucb::Lock aLock = aLocks[0];
1381 if (aLock.Owner >>= aOwner)
1384 aLockData[LockFileComponent::OOOUSERNAME] = aOwner;
1396 std::copy(aLockData.
begin(), aLockData.
end(), pLockData->
begin());
1400 catch( ucb::InteractiveNetworkWriteException& )
1413 catch( uno::Exception& )
1421 pImpl->m_bLocked = bResult;
1427 const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(
pImpl->m_pSet.get(), SID_DOC_READONLY,
false);
1429 if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->
GetValue()) )
1445 if (!IsLockingUsed())
1452 if (
pImpl->m_bLocked && bLoading
1453 &&
GetURLObject().GetProtocol() == INetProtocol::File )
1460 bool bResult =
pImpl->m_bLocked;
1465 const SfxBoolItem* pTemplateItem = SfxItemSet::GetItem<SfxBoolItem>(
GetItemSet(), SID_TEMPLATE,
false);
1466 bResult = ( bLoading && pTemplateItem && pTemplateItem->
GetValue() );
1471 bool bContentReadonly =
false;
1482 if ( bLoading && !
pImpl->m_xLockingStream.is() )
1487 Reference< css::ucb::XCommandEnvironment > xDummyEnv;
1491 catch(
const uno::Exception& ) {}
1495 if ( !bContentReadonly )
1498 if ( isSuitableProtocolForLocking(
pImpl->m_aLogicName ) )
1518 bool bHandleSysLocked = ( bLoading && bUseSystemLock && !
pImpl->xStream.is() && !
pImpl->m_pOutStream );
1521 std::unique_ptr<osl::File> pFileLock;
1522 if (!bLoading && bUseSystemLock &&
pImpl->pTempFile)
1529 pFileLock = std::make_unique<osl::File>(aDestURL);
1530 auto rc = pFileLock->open(osl_File_OpenFlag_Write);
1531 if (rc == osl::FileBase::E_ACCES)
1532 bHandleSysLocked =
true;
1542 std::unique_ptr<svt::MSODocumentLockFile> pMSOLockFile;
1547 pImpl->m_bMSOLockFileCreated =
true;
1550 bool bIoErr =
false;
1552 if (!bHandleSysLocked)
1558 bResult &= pMSOLockFile->CreateOwnLockFile();
1560 catch (
const uno::Exception&)
1569 else if (bLoading && !bNoUI)
1579 if (!bResult && !IsOOoLockFileUsed() && !bIoErr)
1586 pMSOLockFile->OverwriteOwnLockFile();
1597 catch (
const io::WrongFormatException&)
1601 if (!bIoErr && bLoading && !bNoUI )
1607 catch(
const uno::Exception& )
1610 bIoErr = !bHandleSysLocked;
1613 bool bOwnLock =
false;
1615 if (!bHandleSysLocked)
1618 bOwnLock = aOwnData[LockFileComponent::SYSUSERNAME] ==
aData[LockFileComponent::SYSUSERNAME];
1621 && aOwnData[LockFileComponent::LOCALHOST] ==
aData[LockFileComponent::LOCALHOST]
1622 && aOwnData[LockFileComponent::USERURL] ==
aData[LockFileComponent::USERURL])
1629 if ( !bResult && !bIoErr)
1633 aData, bLoading, bOwnLock, bHandleSysLocked);
1634 else if (bLoading && bTryIgnoreLockFile && !bHandleSysLocked)
1643 pMSOLockFile->OverwriteOwnLockFile();
1645 else if (bLoading && !bHandleSysLocked)
1648 if (!bResult && pLockData)
1655 catch(
const uno::Exception& )
1660 pImpl->m_bLocked = bResult;
1665 bResult = !bContentReadonly;
1678 const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(
pImpl->m_pSet.get(), SID_DOC_READONLY,
false);
1680 if ( !bLoading || (pReadOnlyItem && !pReadOnlyItem->
GetValue()) )
1693 catch(
const uno::Exception& )
1695 TOOLS_WARN_EXCEPTION(
"sfx.doc",
"Locking exception: high probability, that the content has not been created" );
1705 if (
pImpl->xStorage.is() ||
pImpl->m_bTriedStorage )
1706 return pImpl->xStorage;
1708 uno::Sequence< uno::Any > aArgs( 2 );
1709 auto pArgs = aArgs.getArray();
1715 if ( bCreateTempFile )
1721 return pImpl->xStorage;
1723 const SfxBoolItem* pRepairItem = SfxItemSet::GetItem<SfxBoolItem>(
GetItemSet(), SID_REPAIRPACKAGE,
false);
1724 if ( pRepairItem && pRepairItem->
GetValue() )
1730 Reference< css::ucb::XProgressHandler > xProgressHandler;
1731 Reference< css::task::XStatusIndicator > xStatusIndicator;
1733 const SfxUnoAnyItem* pxProgressItem = SfxItemSet::GetItem<SfxUnoAnyItem>(
GetItemSet(), SID_PROGRESS_STATUSBAR_CONTROL,
false);
1734 if( pxProgressItem && ( pxProgressItem->
GetValue() >>= xStatusIndicator ) )
1735 xProgressHandler.set(
new utl::ProgressHandlerWrap( xStatusIndicator ) );
1737 uno::Sequence< beans::PropertyValue > aAddProps{
1744 pArgs = aArgs.getArray();
1745 pArgs[2] <<= aAddProps;
1748 if (
pImpl->xStream.is() )
1751 pArgs[0] <<=
pImpl->xStream;
1752 pArgs[1] <<= embed::ElementModes::READWRITE;
1753 pImpl->bStorageBasedOnInStream =
true;
1754 if (
pImpl->m_bDisableFileSync)
1758 pArgs = aArgs.getArray();
1764 else if (
pImpl->xInputStream.is() )
1767 pArgs[0] <<=
pImpl->xInputStream;
1768 pArgs[1] <<= embed::ElementModes::READ;
1769 pImpl->bStorageBasedOnInStream =
true;
1774 pArgs[0] <<=
pImpl->m_aName;
1775 pArgs[1] <<= embed::ElementModes::READ;
1776 pImpl->bStorageBasedOnInStream =
false;
1784 catch(
const uno::Exception& )
1791 pImpl->xStorage =
nullptr;
1792 if (
pImpl->m_pInStream )
1793 pImpl->m_pInStream->Seek(0);
1794 return uno::Reference< embed::XStorage >();
1797 pImpl->m_bTriedStorage =
true;
1800 if (
pImpl->xStorage.is() )
1806 const SfxInt16Item* pVersion = SfxItemSet::GetItem<SfxInt16Item>(
pImpl->m_pSet.get(), SID_VERSION,
false);
1808 bool bResetStorage =
false;
1809 if ( pVersion && pVersion->
GetValue() )
1812 if (
pImpl->aVersions.hasElements() )
1827 uno::Reference < embed::XStorage > xSub =
pImpl->xStorage->openStorageElement(
"Versions",
1828 embed::ElementModes::READ );
1830 DBG_ASSERT( xSub.is(),
"Version list, but no Versions!" );
1833 uno::Reference < io::XStream > xStr = xSub->openStreamElement( rTag.Identifier, embed::ElementModes::READ );
1838 const OUString aTmpName = ::utl::CreateTempURL();
1841 pStream->ReadStream( aTmpStream );
1848 pImpl->bStorageBasedOnInStream =
false;
1850 osl::FileBase::getSystemPathFromFileURL( aTmpName, aTemp );
1853 pImpl->bIsTemp =
true;
1856 pImpl->aVersions.realloc(0);
1859 bResetStorage =
true;
1863 bResetStorage =
true;
1866 if ( bResetStorage )
1868 pImpl->xStorage.clear();
1869 if (
pImpl->m_pInStream )
1870 pImpl->m_pInStream->Seek( 0 );
1874 return pImpl->xStorage;
1892 else if (
pImpl->xInputStream.is() )
1897 catch(
const uno::Exception& )
1899 SAL_WARN(
"sfx.doc",
"No possibility to get readonly version of storage from medium!" );
1906 return pImpl->m_xZipStorage;
1912 if (
pImpl->m_xZipStorage.is() )
1915 pImpl->m_xZipStorage->dispose();
1916 }
catch(
const uno::Exception& )
1919 pImpl->m_xZipStorage.clear();
1925 if (
pImpl->xStorage.is() )
1927 uno::Reference < lang::XComponent > xComp =
pImpl->xStorage;
1929 if (
pImpl->bDisposeStorage && !
pImpl->m_bSalvageMode )
1933 }
catch(
const uno::Exception& )
1935 SAL_WARN(
"sfx.doc",
"Medium's storage is already disposed!" );
1939 pImpl->xStorage.clear();
1940 pImpl->bStorageBasedOnInStream =
false;
1943 pImpl->m_bTriedStorage =
false;
1944 pImpl->bIsStorage =
false;
1949 pImpl->bDisposeStorage = bDisposeStorage;
1954 return pImpl->bDisposeStorage;
1959 return pImpl->m_nStorOpenMode;
1965 if (
pImpl->m_nStorOpenMode != nStorOpen )
1967 pImpl->m_nStorOpenMode = nStorOpen;
1971 if (
pImpl->xStorage.is() )
1981 const Reference< css::ucb::XCommandEnvironment >& xComEnv )
1987 Reference< XInputStream > aOrigInput = aTransactCont.
openStream();
1995 pImpl->m_bRemoveBackup =
false;
2006 bool bResult =
false;
2007 Reference< css::ucb::XCommandEnvironment > xDummyEnv;
2010 if (
pImpl->xStorage.is() )
2014 uno::Reference < embed::XTransactedObject > xTrans(
pImpl->xStorage, uno::UNO_QUERY );
2023 catch (
const embed::UseBackupException& aBackupExc )
2026 if ( !
pImpl->pTempFile )
2028 OSL_ENSURE( !
pImpl->m_aBackupURL.isEmpty(),
"No backup on storage commit!" );
2029 if ( !
pImpl->m_aBackupURL.isEmpty()
2032 aOriginalContent ) )
2041 pImpl->m_aName = aBackupExc.TemporaryFileURL;
2042 OSL_ENSURE( !
pImpl->m_aName.isEmpty(),
"The exception _must_ contain the temporary URL!" );
2050 catch (
const uno::Exception& )
2065 const Reference< css::ucb::XCommandEnvironment >& xComEnv )
2067 Reference< css::ucb::XCommandEnvironment > xDummyEnv;
2074 catch (
const css::ucb::CommandAbortedException& )
2078 catch (
const css::ucb::CommandFailedException& )
2082 catch (
const css::ucb::ContentCreationException&
ex)
2086 (
ex.eError == css::ucb::ContentCreationError_NO_CONTENT_PROVIDER ) ||
2087 (
ex.eError == css::ucb::ContentCreationError_CONTENT_CREATION_FAILED)
2093 catch (
const css::uno::Exception&)
2098 if(
pImpl->m_eError && !
pImpl->m_eError.IsWarning() )
2101 if (
pImpl->xStorage.is() )
2109 bool bTransactStarted =
false;
2110 const SfxBoolItem* pOverWrite = SfxItemSet::GetItem<SfxBoolItem>(
GetItemSet(), SID_OVERWRITE,
false);
2111 bool bOverWrite = !pOverWrite || pOverWrite->
GetValue();
2112 bool bResult =
false;
2119 && ::utl::UCBContentHelper::IsDocument(
2122 Reference< XInputStream > aTempInput = aTempCont.
openStream();
2123 aOriginalContent.
writeStream( aTempInput, bOverWrite );
2129 sal_uInt64
nAttributes = GetDefaultFileAttributes(aDestMainURL);
2130 if (IsFileMovable(aDest)
2131 && osl::File::replace(aSourceMainURL, aDestMainURL) == osl::FileBase::E_None)
2136 osl::File::setAttributes(aDestMainURL,
nAttributes);
2141 if(
pImpl->m_aBackupURL.isEmpty() )
2144 if( !
pImpl->m_aBackupURL.isEmpty() )
2146 Reference< XInputStream > aTempInput = aTempCont.
openStream();
2147 bTransactStarted =
true;
2149 aOriginalContent.
writeStream( aTempInput, bOverWrite );
2159 catch (
const css::ucb::CommandAbortedException& )
2163 catch (
const css::ucb::CommandFailedException& )
2167 catch (
const css::ucb::InteractiveIOException& r )
2169 if ( r.Code == IOErrorCode_ACCESS_DENIED )
2171 else if ( r.Code == IOErrorCode_NOT_EXISTING )
2173 else if ( r.Code == IOErrorCode_CANT_READ )
2179 catch (
const css::ucb::NameClashException& )
2183 catch (
const css::uno::Exception& )
2190 if (
pImpl->pTempFile )
2192 pImpl->pTempFile->EnableKillingFile();
2193 pImpl->pTempFile.reset();
2216 if ( ( !pNewPassItem && !pOldPassItem )
2217 || ( pNewPassItem && pOldPassItem && pNewPassItem->
GetValue() == pOldPassItem->GetValue() ) )
2221 const SfxStringItem* pOldFilterItem = SfxItemSet::GetItem<SfxStringItem>(
GetItemSet(), SID_FILTER_NAME,
false);
2222 if ( pNewFilterItem && pOldFilterItem && pNewFilterItem->
GetValue() == pOldFilterItem->GetValue() )
2229 if ( xInStream.is() )
2233 uno::Reference< io::XSeekable > xSeek( xInStream, uno::UNO_QUERY );
2237 nPos = xSeek->getPosition();
2241 uno::Reference < css::ucb::XCommandEnvironment > xEnv;
2244 InsertCommandArgument aInsertArg;
2245 aInsertArg.Data = xInStream;
2247 if ( pOverWrite && !pOverWrite->
GetValue() )
2248 aInsertArg.ReplaceExisting =
false;
2250 aInsertArg.ReplaceExisting =
true;
2253 aCmdArg <<= aInsertArg;
2258 xSeek->seek(
nPos );
2262 catch(
const uno::Exception& )
2276 if (
pImpl->pTempFile )
2277 aNameURL =
pImpl->pTempFile->GetURL();
2278 else if ( !
pImpl->m_aLogicName.isEmpty() &&
pImpl->m_bSalvageMode )
2281 if ( osl::FileBase::getFileURLFromSystemPath(
pImpl->m_aName, aNameURL )
2282 != osl::FileBase::E_None )
2283 SAL_WARN(
"sfx.doc",
"The medium name is not convertible!" );
2286 if ( aNameURL.isEmpty() || (
pImpl->m_eError && !
pImpl->m_eError.IsWarning() ) )
2289 SAL_INFO(
"sfx.doc",
"SfxMedium::Transfer_Impl, copying to target" );
2291 Reference < css::ucb::XCommandEnvironment > xEnv;
2292 Reference< XOutputStream > rOutStream;
2296 if (
pImpl->m_aLogicName.startsWith(
"private:stream"))
2299 const SfxUnoAnyItem* pOutStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(
pImpl->m_pSet.get(), SID_OUTPUTSTREAM,
false);
2300 if( pOutStreamItem && ( pOutStreamItem->
GetValue() >>= rOutStream ) )
2302 if (
pImpl->xStorage.is() )
2314 sal_Int32 nBufferSize = 32767;
2315 Sequence < sal_Int8 > aSequence ( nBufferSize );
2316 Reference< XInputStream > aTempInput = aTempCont.
openStream();
2320 nRead = aTempInput->readBytes ( aSequence, nBufferSize );
2321 if ( nRead < nBufferSize )
2323 Sequence < sal_Int8 > aTempBuf ( aSequence.getConstArray(), nRead );
2324 rOutStream->writeBytes ( aTempBuf );
2327 rOutStream->writeBytes ( aSequence );
2329 while ( nRead == nBufferSize );
2332 if (
pImpl->pTempFile )
2334 pImpl->pTempFile->EnableKillingFile();
2335 pImpl->pTempFile.reset();
2344 SAL_WARN(
"sfx.doc",
"Illegal Output stream parameter!" );
2349 if (
pImpl->m_pSet )
2350 pImpl->m_pSet->ClearItem( SID_OUTPUTSTREAM );
2356 if ( !
pImpl->aContent.get().is() )
2369 Reference< css::ucb::XCommandEnvironment > xComEnv;
2371 Reference< css::task::XInteractionHandler > xInteractionHandler =
GetInteractionHandler(bForceInteractionHandler);
2372 if (xInteractionHandler.is())
2373 xComEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler,
2374 Reference< css::ucb::XProgressHandler >() );
2382 if (!
pImpl->m_bDisableFileSync)
2385 osl::File aFile( aDestURL );
2386 if ( aFile.open( osl_File_OpenFlag_Write ) == osl::FileBase::E_None )
2389 SAL_INFO(
"sfx.doc",
"fsync'd saved file '" << aDestURL <<
"'" );
2408 Reference< css::container::XChild> xChild( aDestContent.
get(), uno::UNO_QUERY );
2409 OUString sParentUrl;
2412 Reference< css::ucb::XContent > xParent( xChild->getParent( ), uno::UNO_QUERY );
2413 if ( xParent.is( ) )
2415 sParentUrl = xParent->getIdentifier( )->getContentIdentifier();
2419 if ( sParentUrl.isEmpty() )
2423 aDestURL = sParentUrl;
2434 if ( aFileName.isEmpty() )
2441 catch (
const css::ucb::ContentCreationException&
ex)
2445 (
ex.eError == css::ucb::ContentCreationError_NO_CONTENT_PROVIDER ) ||
2446 (
ex.eError == css::ucb::ContentCreationError_CONTENT_CREATION_FAILED)
2452 catch (
const css::uno::Exception&)
2457 if ( !
pImpl->m_eError ||
pImpl->m_eError.IsWarning() )
2460 if (
pImpl->xStorage.is() )
2468 const SfxBoolItem* pOverWrite = SfxItemSet::GetItem<SfxBoolItem>(
GetItemSet(), SID_OVERWRITE,
false);
2469 sal_Int32 nNameClash;
2470 if ( pOverWrite && !pOverWrite->
GetValue() )
2472 nNameClash = NameClash::ERROR;
2475 nNameClash = NameClash::OVERWRITE;
2481 bool bMajor =
false;
2485 eOperation = ::ucbhelper::InsertOperation::Checkin;
2486 const SfxBoolItem* pMajor = SfxItemSet::GetItem<SfxBoolItem>(
GetItemSet(), SID_DOCINFO_MAJOR,
false);
2487 bMajor = pMajor && pMajor->
GetValue( );
2488 const SfxStringItem* pComments = SfxItemSet::GetItem<SfxStringItem>(
GetItemSet(), SID_DOCINFO_COMMENTS,
false);
2492 OUString sResultURL;
2494 aSourceContent, eOperation,
2495 aFileName, nNameClash,
aMimeType, bMajor, sComment,
2496 &sResultURL, sObjectId );
2498 if ( !sResultURL.isEmpty( ) )
2514 aLockContent.
lock();
2517 catch ( css::uno::Exception & )
2522 catch (
const css::ucb::CommandAbortedException& )
2526 catch (
const css::ucb::CommandFailedException& )
2530 catch (
const css::ucb::InteractiveIOException& r )
2532 if ( r.Code == IOErrorCode_ACCESS_DENIED )
2534 else if ( r.Code == IOErrorCode_NOT_EXISTING )
2536 else if ( r.Code == IOErrorCode_CANT_READ )
2541 catch (
const css::uno::Exception& )
2550 if ( ( !
pImpl->m_eError ||
pImpl->m_eError.IsWarning() ) && !
pImpl->pTempFile )
2553 if (osl::FileBase::getSystemPathFromFileURL(
2555 != osl::FileBase::E_None)
2557 pImpl->m_aName.clear();
2559 pImpl->m_bSalvageMode =
false;
2565 std::u16string_view aPrefix,
2566 std::u16string_view aExtension,
2567 const OUString& aDestDir )
2569 if ( !
pImpl->m_aBackupURL.isEmpty() )
2577 Reference < css::ucb::XCommandEnvironment > xDummyEnv;
2583 OUString sMimeType =
pImpl->getFilterMimeType();
2587 NameClash::OVERWRITE,
2590 pImpl->m_bRemoveBackup =
true;
2596 if (
pImpl->m_aBackupURL.isEmpty() )
2603 if ( !
pImpl->m_aBackupURL.isEmpty() )
2610 sal_Int32 nPrefixLen = aFileName.lastIndexOf(
'.' );
2611 OUString aPrefix = ( nPrefixLen == -1 ) ? aFileName : aFileName.copy( 0, nPrefixLen );
2612 OUString aExtension = ( nPrefixLen == -1 ) ? OUString() : aFileName.copy( nPrefixLen );
2617 Reference < css::ucb::XCommandEnvironment > xEnv;
2621 if ( !
pImpl->m_aBackupURL.isEmpty() )
2646 bool bSuccess =
false;
2650 if( !aBakDir.isEmpty() )
2654 Reference < css::ucb::XCommandEnvironment > xEnv;
2670 OUString sMimeType =
pImpl->getFilterMimeType();
2674 NameClash::OVERWRITE,
2677 pImpl->m_bRemoveBackup =
false;
2680 catch (
const css::uno::Exception& )
2696 if(
pImpl->m_bRemoveBackup )
2700 if ( !
pImpl->m_aBackupURL.isEmpty() )
2702 if ( ::utl::UCBContentHelper::Kill(
pImpl->m_aBackupURL ) )
2704 pImpl->m_bRemoveBackup =
false;
2705 pImpl->m_aBackupURL.clear();
2710 SAL_WARN(
"sfx.doc",
"Couldn't remove backup file!");
2715 pImpl->m_aBackupURL.clear();
2721 if (
GetURLObject().GetProtocol() != INetProtocol::File
2722 ||
pImpl->m_xLockingStream.is() )
2725 const SfxUnoAnyItem* pWriteStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(
pImpl->m_pSet.get(), SID_STREAM,
false);
2726 if ( pWriteStreamItem )
2729 if (
pImpl->m_xLockingStream.is() )
2733 uno::Sequence< beans::PropertyValue > xProps;
2739 uno::Reference< io::XInputStream > xInputStream;
2743 if ( !
pImpl->pTempFile &&
pImpl->m_aName.isEmpty() )
2746 if (
pImpl->m_xLockingStream.is() )
2749 if ( xInputStream.is() )
2750 pImpl->xInputStream = xInputStream;
2752 if ( !
pImpl->xInputStream.is() &&
pImpl->xStream.is() )
2753 pImpl->xInputStream =
pImpl->xStream->getInputStream();
2760 if (
pImpl->m_pInStream
2761 && (!
pImpl->bIsTemp ||
pImpl->xInputStream.is() ||
pImpl->m_xInputStreamToLoadFrom.is() ||
pImpl->xStream.is() ||
pImpl->m_xLockingStream.is() ) )
2764 pImpl->bDownloadDone =
false;
2768 const SfxUnoAnyItem* pWriteStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(
pImpl->m_pSet.get(), SID_STREAM,
false);
2769 const SfxUnoAnyItem* pInStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(
pImpl->m_pSet.get(), SID_INPUTSTREAM,
false);
2770 if ( pWriteStreamItem )
2774 if ( pInStreamItem )
2777 if ( !
pImpl->xInputStream.is() &&
pImpl->xStream.is() )
2778 pImpl->xInputStream =
pImpl->xStream->getInputStream();
2780 else if ( pInStreamItem )
2786 uno::Sequence < beans::PropertyValue > xProps;
2788 if (!
pImpl->m_aName.isEmpty())
2790 if ( osl::FileBase::getFileURLFromSystemPath(
pImpl->m_aName, aFileName )
2791 != osl::FileBase::E_None )
2793 SAL_WARN(
"sfx.doc",
"Physical name not convertible!");
2801 bool bFromTempFile = (
pImpl->pTempFile != nullptr );
2803 if ( !bFromTempFile )
2806 if( !(
pImpl->m_nStorOpenMode & StreamMode::WRITE) )
2808 if (xInteractionHandler.is())
2812 if (
pImpl->m_xInputStreamToLoadFrom.is() )
2814 pImpl->xInputStream =
pImpl->m_xInputStreamToLoadFrom;
2815 if (
pImpl->m_bInputStreamIsReadOnly)
2823 if (
pImpl->m_xLockingStream.is() && !bFromTempFile )
2830 if ( bFromTempFile )
2836 else if (
GetURLObject().GetProtocol() == INetProtocol::File )
2860 if ( !
pImpl->xInputStream.is() &&
pImpl->xStream.is() )
2861 pImpl->xInputStream =
pImpl->xStream->getInputStream();
2864 if ( !bFromTempFile )
2867 if (
pImpl->xStream.is() )
2880 if (
pImpl->xStream.is() )
2882 else if (
pImpl->xInputStream.is() )
2886 pImpl->bDownloadDone =
true;
2887 pImpl->aDoneLink.ClearPendingCall();
2889 pImpl->aDoneLink.Call(
reinterpret_cast<void*
>(sal_uInt32(nError)) );
2894 return pImpl->m_bRemote;
2899 pImpl->bUpdatePickList = bVal;
2904 return pImpl->bUpdatePickList;
2909 pImpl->m_aLongName = rName;
2914 return pImpl->m_aLongName;
2919 pImpl->aDoneLink = rLink;
2942 Reference< XOutputStream > rOutStream;
2945 pImpl->bDisposeStorage =
false;
2947 const SfxStringItem* pSalvageItem = SfxItemSet::GetItem<SfxStringItem>(
pImpl->m_pSet.get(), SID_DOC_SALVAGE,
false);
2948 if ( pSalvageItem && pSalvageItem->
GetValue().isEmpty() )
2950 pSalvageItem =
nullptr;
2951 pImpl->m_pSet->ClearItem( SID_DOC_SALVAGE );
2954 if (!
pImpl->m_aLogicName.isEmpty())
2958 if ( eProt == INetProtocol::NotValid )
2960 SAL_WARN(
"sfx.doc",
"URL <" <<
pImpl->m_aLogicName <<
"> with unknown protocol" );
2966 std::unique_lock<std::recursive_mutex> chkEditLock;
2967 if (
pImpl->m_pCheckEditableWorkerMutex !=
nullptr)
2968 chkEditLock = std::unique_lock<std::recursive_mutex>(
2969 *(
pImpl->m_pCheckEditableWorkerMutex));
2971 if (chkEditLock.owns_lock())
2972 chkEditLock.unlock();
2978 if (
pImpl->m_aName.isEmpty() )
2982 DBG_ASSERT( pSalvageItem,
"Suspicious change of logical name!" );
2989 std::unique_lock<std::recursive_mutex> chkEditLock;
2990 if (
pImpl->m_pCheckEditableWorkerMutex !=
nullptr)
2992 = std::unique_lock<std::recursive_mutex>(*(
pImpl->m_pCheckEditableWorkerMutex));
2994 pImpl->m_pURLObj.reset();
2995 if (chkEditLock.owns_lock())
2996 chkEditLock.unlock();
2997 pImpl->m_bSalvageMode =
true;
3002 const SfxUnoAnyItem* pOutStreamItem = SfxItemSet::GetItem<SfxUnoAnyItem>(
pImpl->m_pSet.get(), SID_OUTPUTSTREAM,
false);
3004 && ( !( pOutStreamItem->
GetValue() >>= rOutStream )
3005 || !
pImpl->m_aLogicName.startsWith(
"private:stream")) )
3007 pImpl->m_pSet->ClearItem( SID_OUTPUTSTREAM );
3008 SAL_WARN(
"sfx.doc",
"Unexpected Output stream parameter!" );
3011 if (!
pImpl->m_aLogicName.isEmpty())
3014 const SfxStringItem* pFileNameItem = SfxItemSet::GetItem<SfxStringItem>(
pImpl->m_pSet.get(), SID_FILE_NAME,
false);
3015 if ( !pFileNameItem )
3026 osl::DirectoryItem item;
3027 if (osl::DirectoryItem::get(
GetName(), item) == osl::FileBase::E_None) {
3028 osl::FileStatus stat(osl_FileStatus_Mask_Attributes);
3029 if (item.getFileStatus(stat) == osl::FileBase::E_None
3030 && stat.isValid(osl_FileStatus_Mask_Attributes))
3032 if ((stat.getAttributes() & osl_File_Attribute_ReadOnly) != 0)
3034 pImpl->m_bOriginallyReadOnly =
true;
3049 pImpl->bAllowDefaultIntHdl = bUse;
3053css::uno::Reference< css::task::XInteractionHandler >
3057 if ( !bGetAlways && !
pImpl->bUseInteractionHandler )
3058 return css::uno::Reference< css::task::XInteractionHandler >();
3061 if (
pImpl->m_pSet )
3063 css::uno::Reference< css::task::XInteractionHandler > xHandler;
3064 const SfxUnoAnyItem* pHandler = SfxItemSet::GetItem<SfxUnoAnyItem>(
pImpl->m_pSet.get(), SID_INTERACTIONHANDLER,
false);
3065 if ( pHandler && (pHandler->
GetValue() >>= xHandler) && xHandler.is() )
3070 if ( !bGetAlways && !
pImpl->bAllowDefaultIntHdl )
3071 return css::uno::Reference< css::task::XInteractionHandler >();
3074 if (
pImpl->xInteraction.is() )
3075 return pImpl->xInteraction;
3078 Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
3079 pImpl->xInteraction.set(
3080 task::InteractionHandler::createWithParent(xContext,
nullptr), UNO_QUERY_THROW );
3081 return pImpl->xInteraction;
3086 pImpl->m_pFilter = pFilter;
3091 return pImpl->m_pFilter;
3096 sal_uInt32 nHash = 0;
3098 if ( !aPasswd.empty() )
3106 rtl_TextEncoding nEncoding = osl_getThreadTextEncoding();
3117 if (
pImpl->xStorage.is() )
3129 if (
pImpl->xStorage.is() )
3141 pImpl->m_bDisableUnlockWebDAV = bDisableUnlockWebDAV;
3146 pImpl->m_bDisableFileSync = bDisableFileSync;
3151#if !HAVE_FEATURE_MULTIUSER_ENVIRONMENT
3152 (void) bReleaseLockStream;
3160 if (!IsWebDAVLockingUsed())
3163 if (
pImpl->m_bLocked )
3168 uno::Reference< css::ucb::XCommandEnvironment > xComEnv = new ::ucbhelper::CommandEnvironment( xHandler,
3169 Reference< css::ucb::XProgressHandler >() );
3171 pImpl->m_bLocked =
false;
3173 if ( !
pImpl->m_bDisableUnlockWebDAV )
3174 aContentToUnlock.
unlock();
3176 catch ( uno::Exception& )
3184 if (
pImpl->m_xLockingStream.is() )
3186 if ( bReleaseLockStream )
3190 uno::Reference< io::XInputStream > xInStream =
pImpl->m_xLockingStream->getInputStream();
3191 uno::Reference< io::XOutputStream > xOutStream =
pImpl->m_xLockingStream->getOutputStream();
3192 if ( xInStream.is() )
3193 xInStream->closeInput();
3194 if ( xOutStream.is() )
3195 xOutStream->closeOutput();
3197 catch(
const uno::Exception& )
3201 pImpl->m_xLockingStream.clear();
3204 if ( !
pImpl->m_bLocked )
3211 pImpl->m_bLocked =
false;
3215 catch(
const io::WrongFormatException& )
3222 catch(
const uno::Exception& )
3225 catch(
const uno::Exception& )
3228 if(!
pImpl->m_bMSOLockFileCreated)
3235 pImpl->m_bLocked =
false;
3239 catch(
const io::WrongFormatException& )
3246 catch(
const uno::Exception& )
3249 catch(
const uno::Exception& )
3251 pImpl->m_bMSOLockFileCreated =
false;
3259 uno::Reference< io::XInputStream > xInToClose =
pImpl->xInputStream;
3260 uno::Reference< io::XOutputStream > xOutToClose;
3261 if (
pImpl->xStream.is() )
3263 xOutToClose =
pImpl->xStream->getOutputStream();
3266 if (
pImpl->xStream ==
pImpl->m_xLockingStream )
3267 pImpl->m_xLockingStream.clear();
3274 if (
pImpl->m_bSalvageMode )
3279 if ( xInToClose.is() )
3280 xInToClose->closeInput();
3281 if ( xOutToClose.is() )
3282 xOutToClose->closeOutput();
3284 catch (
const uno::Exception& )
3295 if (
pImpl->m_pSet )
3296 pImpl->m_pSet->ClearItem( SID_CONTENT );
3307 case INetProtocol::Ftp:
3308 case INetProtocol::Http:
3309 case INetProtocol::Https:
3310 pImpl->m_bRemote =
true;
3313 pImpl->m_bRemote =
GetName().startsWith(
"private:msgid");
3319 if (
pImpl->m_bRemote)
3320 pImpl->m_nStorOpenMode |= StreamMode::READ;
3326 if (
pImpl->aOrigURL.isEmpty())
3329 pImpl->aOrigURL = aNameP;
3330 std::unique_lock<std::recursive_mutex> chkEditLock;
3331 if (
pImpl->m_pCheckEditableWorkerMutex !=
nullptr)
3332 chkEditLock = std::unique_lock<std::recursive_mutex>(*(
pImpl->m_pCheckEditableWorkerMutex));
3333 pImpl->m_aLogicName = aNameP;
3334 pImpl->m_pURLObj.reset();
3335 if (chkEditLock.owns_lock())
3336 chkEditLock.unlock();
3344 return pImpl->aOrigURL.isEmpty() ?
pImpl->m_aLogicName :
pImpl->aOrigURL;
3350 if ( rNameP !=
pImpl->m_aName )
3352 pImpl->pTempFile.reset();
3354 if ( !
pImpl->m_aName.isEmpty() || !rNameP.isEmpty() )
3357 pImpl->m_aName = rNameP;
3358 pImpl->m_bTriedStorage =
false;
3359 pImpl->bIsStorage =
false;
3365 bool bUseInteractionHandler =
pImpl->bUseInteractionHandler;
3366 pImpl->bUseInteractionHandler =
false;
3368 pImpl->bUseInteractionHandler = bUseInteractionHandler;
3374 bool bUseInteractionHandler =
pImpl->bUseInteractionHandler;
3375 pImpl->bUseInteractionHandler =
false;
3377 std::unique_ptr<::utl::TempFileNamed> pTmpFile;
3378 if (
pImpl->pTempFile )
3380 pTmpFile = std::move(
pImpl->pTempFile);
3381 pImpl->m_aName.clear();
3388 if (
pImpl->pTempFile )
3390 pImpl->pTempFile->EnableKillingFile();
3391 pImpl->pTempFile.reset();
3393 pImpl->pTempFile = std::move( pTmpFile );
3394 if (
pImpl->pTempFile )
3395 pImpl->m_aName =
pImpl->pTempFile->GetFileName();
3399 pTmpFile->EnableKillingFile();
3403 pImpl->bUseInteractionHandler = bUseInteractionHandler;
3409 pImpl->m_pSet = pInSet;
3410 pImpl->m_pFilter = std::move(pFilter);
3411 pImpl->m_aLogicName = rName;
3412 pImpl->m_nStorOpenMode = nOpenMode;
3416SfxMedium::SfxMedium(
const OUString &rName,
const OUString &rReferer,
StreamMode nOpenMode, std::shared_ptr<const SfxFilter> pFilter,
const std::shared_ptr<SfxItemSet>& pInSet) :
3419 pImpl->m_pSet = pInSet;
3421 if (s->
GetItem(SID_REFERER) ==
nullptr) {
3424 pImpl->m_pFilter = std::move(pFilter);
3425 pImpl->m_aLogicName = rName;
3426 pImpl->m_nStorOpenMode = nOpenMode;
3434 pImpl->m_pSet.reset( pParams );
3438 OUString aFilterProvider, aFilterName;
3441 if ((pItem =
pImpl->m_pSet->GetItemIfSet(SID_FILTER_PROVIDER)))
3442 aFilterProvider = pItem->
GetValue();
3444 if ((pItem =
pImpl->m_pSet->GetItemIfSet(SID_FILTER_NAME)))
3448 if (aFilterProvider.isEmpty())
3456 pImpl->m_pCustomFilter = std::make_shared<SfxFilter>(aFilterProvider, aFilterName);
3460 const SfxStringItem* pSalvageItem = SfxItemSet::GetItem<SfxStringItem>(
pImpl->m_pSet.get(), SID_DOC_SALVAGE,
false);
3464 if ( !pSalvageItem->
GetValue().isEmpty() )
3469 const SfxStringItem* pFileNameItem = SfxItemSet::GetItem<SfxStringItem>(
pImpl->m_pSet.get(), SID_FILE_NAME,
false);
3470 if (!pFileNameItem)
throw uno::RuntimeException();
3472 if ( !aNewTempFileURL.isEmpty() )
3475 pImpl->m_pSet->ClearItem( SID_INPUTSTREAM );
3476 pImpl->m_pSet->ClearItem( SID_STREAM );
3477 pImpl->m_pSet->ClearItem( SID_CONTENT );
3481 SAL_WARN(
"sfx.doc",
"Can not create a new temporary file for crash recovery!" );
3486 const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(
pImpl->m_pSet.get(), SID_DOC_READONLY,
false);
3487 if ( pReadOnlyItem && pReadOnlyItem->
GetValue() )
3488 pImpl->m_bOriginallyLoadedReadOnly =
true;
3490 const SfxStringItem* pFileNameItem = SfxItemSet::GetItem<SfxStringItem>(
pImpl->m_pSet.get(), SID_FILE_NAME,
false);
3491 if (!pFileNameItem)
throw uno::RuntimeException();
3493 pImpl->m_nStorOpenMode =
pImpl->m_bOriginallyLoadedReadOnly
3500 static constexpr OUStringLiteral
sStream(
u"Stream");
3501 static constexpr OUStringLiteral
sInputStream(
u"InputStream");
3510SfxMedium::SfxMedium(
const uno::Reference < embed::XStorage >& rStor,
const OUString& rBaseURL,
const std::shared_ptr<SfxItemSet>& p ) :
3518 pImpl->xStorage = rStor;
3519 pImpl->bDisposeStorage =
false;
3528SfxMedium::SfxMedium(
const uno::Reference < embed::XStorage >& rStor,
const OUString& rBaseURL,
const OUString &rTypeName,
const std::shared_ptr<SfxItemSet>& p ) :
3535 pImpl->xStorage = rStor;
3536 pImpl->bDisposeStorage =
false;
3554 if( !
pImpl->bIsTemp ||
pImpl->m_aName.isEmpty() )
3558 if ( osl::FileBase::getFileURLFromSystemPath(
pImpl->m_aName, aTemp )
3559 != osl::FileBase::E_None )
3561 SAL_WARN(
"sfx.doc",
"Physical name not convertible!");
3564 if ( !::utl::UCBContentHelper::Kill( aTemp ) )
3566 SAL_WARN(
"sfx.doc",
"Couldn't remove temporary file!");
3572 return pImpl->m_aLogicName;
3577 std::unique_lock<std::recursive_mutex> chkEditLock;
3578 if (
pImpl->m_pCheckEditableWorkerMutex !=
nullptr)
3579 chkEditLock = std::unique_lock<std::recursive_mutex>(*(
pImpl->m_pCheckEditableWorkerMutex));
3581 if (!
pImpl->m_pURLObj)
3584 pImpl->m_pURLObj->SetMark(
u"");
3587 return *
pImpl->m_pURLObj;
3592 pImpl->aExpireTime = rDateTime;
3604 return pImpl->wLoadTargetFrame;
3609 pImpl->m_xInputStreamToLoadFrom = xInputStream;
3610 pImpl->m_bInputStreamIsReadOnly = bIsReadOnly;
3615 pImpl->wLoadTargetFrame = pFrame;
3621 pImpl->xStorage = rStor;
3629 pImpl->m_pSet = std::make_shared<SfxAllItemSet>(
SfxGetpApp()->GetPool() );
3630 return pImpl->m_pSet.get();
3636 if( !
pImpl->xAttributes.is() )
3644 Any aAny =
pImpl->aContent.getPropertyValue(
"MediaType");
3645 OUString aContentType;
3646 aAny >>= aContentType;
3648 pImpl->xAttributes->Append(
SvKeyValue(
"content-type", aContentType ) );
3650 catch (
const css::uno::Exception& )
3656 return pImpl->xAttributes.get();
3661 if ( !
pImpl->xInputStream.is() )
3663 return pImpl->xInputStream;
3669 if ( ( !_bNoReload || !
pImpl->m_bVersionsAlreadyLoaded ) && !
pImpl->aVersions.hasElements() &&
3672 uno::Reference < document::XDocumentRevisionListPersistence > xReader =
3678 catch (
const uno::Exception& )
3683 if ( !
pImpl->m_bVersionsAlreadyLoaded )
3684 pImpl->m_bVersionsAlreadyLoaded =
true;
3686 return pImpl->aVersions;
3691 uno::Reference < document::XDocumentRevisionListPersistence > xReader =
3695 return xReader->load( xStorage );
3697 catch (
const uno::Exception& )
3701 return uno::Sequence < util::RevisionTag >();
3710 std::vector<sal_uInt32> aLongs;
3712 for (
const auto& rVersion : std::as_const(
pImpl->aVersions) )
3714 sal_uInt32 nVer =
static_cast<sal_uInt32
>(
o3tl::toInt32(rVersion.Identifier.subView(7)));
3716 for (
n=0;
n<aLongs.size(); ++
n )
3717 if ( nVer<aLongs[
n] )
3720 aLongs.insert( aLongs.begin()+
n, nVer );
3723 std::vector<sal_uInt32>::size_type nKey;
3724 for ( nKey=0; nKey<aLongs.size(); ++nKey )
3725 if ( aLongs[nKey] > nKey+1 )
3728 OUString aRevName =
"Version" + OUString::number( nKey + 1 );
3730 rRevision.Identifier = aRevName;
3736 if ( !
pImpl->aVersions.hasElements() )
3739 auto pVersion = std::find_if(std::cbegin(
pImpl->aVersions), std::cend(
pImpl->aVersions),
3740 [&rName](
const auto& rVersion) { return rVersion.Identifier == rName; });
3741 if (pVersion != std::cend(
pImpl->aVersions))
3743 auto nIndex =
static_cast<sal_Int32
>(std::distance(std::cbegin(
pImpl->aVersions), pVersion));
3750 if ( rMedium.
pImpl->aVersions.hasElements() )
3764 if ( !
pImpl->aVersions.hasElements() )
3767 uno::Reference < document::XDocumentRevisionListPersistence > xWriter =
3773 catch (
const uno::Exception& )
3781 bool bReadOnly =
pImpl->m_pFilter && (
pImpl->m_pFilter->GetFilterFlags() & SfxFilterFlags::OPENREADONLY);
3800 return pImpl->m_bOriginallyReadOnly;
3805 pImpl->m_bOriginallyReadOnly = val;
3810 return pImpl->m_bOriginallyLoadedReadOnly;
3817 bool bResult =
false;
3819 ::osl::DirectoryItem aDirItem;
3820 if ( ::osl::DirectoryItem::get(
aURL, aDirItem ) == ::osl::FileBase::E_None )
3822 ::osl::FileStatus aFileStatus( osl_FileStatus_Mask_Attributes );
3823 if ( aDirItem.getFileStatus( aFileStatus ) == osl::FileBase::E_None
3824 && aFileStatus.isValid( osl_FileStatus_Mask_Attributes ) )
3826 sal_uInt64
nAttributes = aFileStatus.getAttributes();
3829 osl_File_Attribute_GrpWrite |
3830 osl_File_Attribute_OthWrite |
3831 osl_File_Attribute_ReadOnly);
3833 osl_File_Attribute_OwnRead);
3835 bResult = ( osl::File::setAttributes(
aURL,
nAttributes ) == ::osl::FileBase::E_None );
3845OUString GetLogicBase(
const INetURLObject& rURL, std::unique_ptr<SfxMedium_Impl>
const & pImpl)
3847 OUString aLogicBase;
3849#if HAVE_FEATURE_MACOSX_SANDBOX
3857 if (!pImpl->m_bHasEmbeddedObjects
3858 && rURL.
GetProtocol() == INetProtocol::File && !pImpl->m_pInStream)
3862 aURL.removeSegment();
3874 if (
pImpl->pTempFile )
3879 pImpl->pTempFile.reset();
3880 pImpl->m_aName.clear();
3884 pImpl->pTempFile.reset(new ::utl::TempFileNamed(&aLogicBase));
3885 pImpl->pTempFile->EnableKillingFile();
3886 pImpl->m_aName =
pImpl->pTempFile->GetFileName();
3887 OUString aTmpURL =
pImpl->pTempFile->GetURL();
3888 if (
pImpl->m_aName.isEmpty() || aTmpURL.isEmpty() )
3894 if ( !(
pImpl->m_nStorOpenMode & StreamMode::TRUNC) )
3896 bool bTransferSuccess =
false;
3906 uno::Reference< css::ucb::XCommandEnvironment > xComEnv;
3914 OUString sMimeType =
pImpl->getFilterMimeType();
3917 bTransferSuccess =
true;
3920 catch(
const uno::Exception& )
3923 if ( bTransferSuccess )
3930 if ( !bTransferSuccess &&
pImpl->m_pInStream )
3935 if (
pImpl->m_pOutStream )
3937 std::unique_ptr<char[]> pBuf(
new char [8192]);
3940 pImpl->m_pInStream->Seek(0);
3941 pImpl->m_pOutStream->Seek(0);
3945 sal_uInt32 nRead =
pImpl->m_pInStream->ReadBytes(pBuf.get(), 8192);
3946 nErr =
pImpl->m_pInStream->GetError();
3947 pImpl->m_pOutStream->WriteBytes( pBuf.get(), nRead );
3950 bTransferSuccess =
true;
3959 bTransferSuccess =
true;
3963 if ( !bTransferSuccess )
3977 pImpl->pTempFile.reset();
3980 pImpl->pTempFile.reset(new ::utl::TempFileNamed(&aLogicBase));
3981 pImpl->pTempFile->EnableKillingFile();
3982 pImpl->m_aName =
pImpl->pTempFile->GetFileName();
3983 if (
pImpl->m_aName.isEmpty() )
3994 const css::uno::Reference<css::frame::XModel>& xModel,
bool bHasValidDocumentSignature,
3995 const Reference<XCertificate>& xCertificate)
3997 bool bChanges =
false;
4001 SAL_WARN(
"sfx.doc",
"The medium must be closed by the signer!");
4008 uno::Reference< security::XDocumentDigitalSignatures > xSigner(
4009 security::DocumentDigitalSignatures::createWithVersionAndValidSignature(
4011 auto xModelSigner =
dynamic_cast<sfx2::DigitalSignatures*
>(xSigner.get());
4017 uno::Reference< embed::XStorage > xWriteableZipStor;
4025 if ( !
pImpl->xStream.is() )
4026 throw uno::RuntimeException();
4033 catch (
const io::IOException&)
4041 if ( !xWriteableZipStor.is() && bODF )
4042 throw uno::RuntimeException();
4044 uno::Reference< embed::XStorage > xMetaInf;
4045 if (xWriteableZipStor.is() && xWriteableZipStor->hasByName(
"META-INF"))
4047 xMetaInf = xWriteableZipStor->openStorageElement(
4049 embed::ElementModes::READWRITE );
4050 if ( !xMetaInf.is() )
4051 throw uno::RuntimeException();
4058 uno::Reference< io::XStream >
xStream;
4060 xStream.set(xMetaInf->openStreamElement(xSigner->getDocumentContentSignatureDefaultStreamName(), embed::ElementModes::READWRITE), uno::UNO_SET_THROW);
4062 bool bSuccess = xModelSigner->SignModelWithCertificate(
4067 uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW );
4068 xTransact->commit();
4069 xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW );
4070 xTransact->commit();
4077 else if (xWriteableZipStor.is())
4080 uno::Reference<io::XStream>
xStream;
4083 bool bSuccess = xModelSigner->SignModelWithCertificate(
4088 uno::Reference<embed::XTransactedObject> xTransact(xWriteableZipStor, uno::UNO_QUERY_THROW);
4089 xTransact->commit();
4101 if (xModelSigner->SignModelWithCertificate(
4102 xModel, xCertificate, uno::Reference<embed::XStorage>(),
xStream))
4107 catch (
const uno::Exception& )
4109 SAL_WARN(
"sfx.doc",
"Couldn't use signing functionality!" );
4120 bool bSignScriptingContent,
4121 bool bHasValidDocumentSignature,
4122 const OUString& aSignatureLineId,
4123 const Reference<XCertificate>& xCert,
4124 const Reference<XGraphic>& xValidGraphic,
4125 const Reference<XGraphic>& xInvalidGraphic,
4126 const OUString& aComment)
4128 bool bChanges =
false;
4132 SAL_WARN(
"sfx.doc",
"The medium must be closed by the signer!");
4139 uno::Reference< security::XDocumentDigitalSignatures > xSigner(
4140 security::DocumentDigitalSignatures::createWithVersionAndValidSignature(
4143 xSigner->setParentWindow(pDialogParent->
GetXWindow());
4145 uno::Reference< embed::XStorage > xWriteableZipStor;
4153 if ( !
pImpl->xStream.is() )
4154 throw uno::RuntimeException();
4161 catch (
const io::IOException&)
4169 if ( !xWriteableZipStor.is() && bODF )
4170 throw uno::RuntimeException();
4172 uno::Reference< embed::XStorage > xMetaInf;
4173 if (xWriteableZipStor.is() && xWriteableZipStor->hasByName(
"META-INF"))
4175 xMetaInf = xWriteableZipStor->openStorageElement(
4177 embed::ElementModes::READWRITE );
4178 if ( !xMetaInf.is() )
4179 throw uno::RuntimeException();
4182 if ( bSignScriptingContent )
4186 uno::Reference< io::XStream >
xStream(
4187 xMetaInf->openStreamElement( xSigner->getScriptingContentSignatureDefaultStreamName(),
4188 embed::ElementModes::READWRITE ),
4189 uno::UNO_SET_THROW );
4194 OUString aDocSigName = xSigner->getDocumentContentSignatureDefaultStreamName();
4195 if ( !aDocSigName.isEmpty() && xMetaInf->hasByName( aDocSigName ) )
4196 xMetaInf->removeElement( aDocSigName );
4198 uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW );
4199 xTransact->commit();
4200 xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW );
4201 xTransact->commit();
4213 uno::Reference< io::XStream >
xStream;
4215 xStream.set(xMetaInf->openStreamElement(xSigner->getDocumentContentSignatureDefaultStreamName(), embed::ElementModes::READWRITE), uno::UNO_SET_THROW);
4217 bool bSuccess =
false;
4219 bSuccess = xSigner->signSignatureLine(
4221 xValidGraphic, xInvalidGraphic, aComment);
4228 uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW );
4229 xTransact->commit();
4230 xTransact.set( xWriteableZipStor, uno::UNO_QUERY_THROW );
4231 xTransact->commit();
4238 else if (xWriteableZipStor.is())
4241 uno::Reference<io::XStream>
xStream;
4243 bool bSuccess =
false;
4246 bSuccess = xSigner->signSignatureLine(
4248 xCert, xValidGraphic, xInvalidGraphic, aComment);
4253 bSuccess =xSigner->signDocumentContent(
4259 uno::Reference<embed::XTransactedObject> xTransact(xWriteableZipStor, uno::UNO_QUERY_THROW);
4260 xTransact->commit();
4272 if (xSigner->signDocumentContent(uno::Reference<embed::XStorage>(),
xStream))
4277 catch (
const uno::Exception& )
4279 SAL_WARN(
"sfx.doc",
"Couldn't use signing functionality!" );
4292 return pImpl->m_nSignatureState;
4303 pImpl->m_bHasEmbeddedObjects = bHasEmbeddedObjects;
4308 return pImpl->xStorage.is();
4313 return pImpl->m_pInStream ||
pImpl->m_pOutStream ||
pImpl->xStorage.is();
4320 if ( !
aURL.empty() )
4322 size_t nPrefixLen =
aURL.rfind(
'.' );
4323 std::u16string_view aExt = ( nPrefixLen == std::u16string_view::npos ) ? std::u16string_view() :
aURL.substr( nPrefixLen );
4325 OUString aNewTempFileURL = ::utl::CreateTempURL(
u"",
true, aExt );
4326 if ( !aNewTempFileURL.isEmpty() )
4337 uno::Reference< css::ucb::XCommandEnvironment > xComEnv;
4343 NameClash::OVERWRITE );
4344 aResult = aNewTempFileURL;
4346 catch(
const uno::Exception& )
4357 bool bResult =
false;
4359 if ( xHandler.is() )
4363 uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations( bAllowAbort ? 2 : 1 );
4364 auto pContinuations = aContinuations.getArray();
4367 pContinuations[ 0 ] = pApprove.get();
4372 pContinuations[ 1 ] = pAbort.get();
4376 bResult = pApprove->wasSelected();
4390 OUString aOrigURL =
pImpl->m_aLogicName;
4392 if ( !aOrigURL.isEmpty() )
4394 sal_Int32 nPrefixLen = aOrigURL.lastIndexOf(
'.' );
4395 std::u16string_view aExt = (nPrefixLen == -1)
4396 ? std::u16string_view()
4397 : aOrigURL.subView(nPrefixLen);
4398 OUString aNewURL = ::utl::CreateTempURL(
u"",
true, aExt );
4402 if ( !aNewURL.isEmpty() )
4404 uno::Reference< embed::XStorage > xStorage =
GetStorage();
4405 uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY );
4407 if ( xOptStorage.is() )
4416 bool bWasReadonly =
false;
4418 const SfxBoolItem* pReadOnlyItem = SfxItemSet::GetItem<SfxBoolItem>(
pImpl->m_pSet.get(), SID_DOC_READONLY,
false);
4419 if ( pReadOnlyItem && pReadOnlyItem->
GetValue() )
4420 bWasReadonly =
true;
4428 if (
pImpl->xStream.is() )
4432 xOptStorage->writeAndAttachToStream(
pImpl->xStream );
4433 pImpl->xStorage = xStorage;
4436 catch(
const uno::Exception& )
4447 if ( aResult.isEmpty() )
4453 pImpl->xStorage = xStorage;
4465 bool bResult =
false;
4466 OUString aOrigURL =
pImpl->m_aLogicName;
4468 if ( !
aURL.isEmpty() && !aOrigURL.isEmpty() )
4470 uno::Reference< embed::XStorage > xStorage =
GetStorage();
4471 uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY );
4485 if (
pImpl->xStream.is() )
4489 uno::Reference< io::XTruncate > xTruncate(
pImpl->xStream, uno::UNO_QUERY_THROW );
4490 xTruncate->truncate();
4491 if ( xOptStorage.is() )
4492 xOptStorage->writeAndAttachToStream(
pImpl->xStream );
4493 pImpl->xStorage = xStorage;
4496 catch(
const uno::Exception& )
4506 pImpl->xStorage = xStorage;
4515 pImpl->m_bInCheckIn = bInCheckIn;
4520 return pImpl->m_bInCheckIn;
4526 return pImpl->m_pCheckEditableWorkerMutex;
4532 pImpl->m_pReloadEvent = pEvent;
4538 return pImpl->m_pReloadEvent;
4544 if (!
pImpl->m_bNotifyWhenEditable)
4549 if (
pImpl->m_pCheckEditableWorkerMutex ==
nullptr)
4551 pImpl->m_pCheckEditableWorkerMutex = std::make_shared<std::recursive_mutex>();
4552 if (
pImpl->m_pCheckEditableWorkerMutex ==
nullptr)
4556 pImpl->m_pIsDestructed = std::make_shared<bool>(
false);
4557 if (
pImpl->m_pIsDestructed ==
nullptr)
4563 bool bAddNewEntry =
false;
4566 std::shared_ptr<comphelper::ThreadTaskTag> pTag
4568 if (pTag !=
nullptr)
4571 bAddNewEntry =
true;
4573 std::make_unique<CheckReadOnlyTask>(pTag));
4577 bAddNewEntry =
true;
4581 std::shared_ptr<ReadOnlyMediumEntry> newEntry = std::make_shared<ReadOnlyMediumEntry>(
4582 pImpl->m_pCheckEditableWorkerMutex,
pImpl->m_pIsDestructed);
4584 if (newEntry !=
nullptr)
4595 if (
pImpl->m_pCheckEditableWorkerMutex !=
nullptr)
4597 std::unique_lock<std::recursive_mutex>
lock(*(
pImpl->m_pCheckEditableWorkerMutex));
4599 if (
pImpl->m_pReloadEvent !=
nullptr)
4605 pImpl->m_pReloadEvent =
nullptr;
4608 if (
pImpl->m_pIsDestructed !=
nullptr)
4610 *(
pImpl->m_pIsDestructed) =
true;
4611 pImpl->m_pIsDestructed =
nullptr;
4623 if (pMed ==
nullptr)
4631 OUString aDocumentURL
4634 = new ::ucbhelper::InteractionRequest(
uno::Any(document::ReloadEditableRequest(
4635 OUString(), uno::Reference<uno::XInterface>(), aDocumentURL)));
4636 if (xInteractionRequestImpl !=
nullptr)
4638 uno::Sequence<uno::Reference<task::XInteractionContinuation>> aContinuations{
4639 new ::ucbhelper::InteractionAbort(xInteractionRequestImpl.get()),
4640 new ::ucbhelper::InteractionApprove(xInteractionRequestImpl.get())
4642 xInteractionRequestImpl->setContinuations(aContinuations);
4643 xHandler->handle(xInteractionRequestImpl);
4645 = xInteractionRequestImpl->getSelection();
4646 if (uno::Reference<task::XInteractionApprove>(xSelected.get(), uno::UNO_QUERY).is())
4651 if (pFrame->GetObjectShell()->GetMedium() == pMed)
4656 pFrame->GetDispatcher()->Execute(SID_RELOAD);
4667#if !HAVE_FEATURE_MULTIUSER_ENVIRONMENT
4668 bool bCanReload =
true;
4670 bool bCanReload =
false;
4673 osl::DirectoryItem rItem;
4674 auto nError1 = osl::DirectoryItem::get(aLockFile.
GetURL(), rItem);
4675 if (nError1 == osl::FileBase::E_None)
4681 catch (
const io::WrongFormatException&)
4686 catch (
const uno::Exception&)
4693 = aOwnData[LockFileComponent::SYSUSERNAME] ==
aData[LockFileComponent::SYSUSERNAME];
4695 && aOwnData[LockFileComponent::LOCALHOST] ==
aData[LockFileComponent::LOCALHOST]
4696 && aOwnData[LockFileComponent::USERURL] ==
aData[LockFileComponent::USERURL])
4702 else if (nError1 == osl::FileBase::E_NOENT)
4712 catch (
const io::WrongFormatException&)
4719 catch (
const uno::Exception&)
4725 catch (
const uno::Exception&)
4734void CheckReadOnlyTask::doWork()
4741 std::unique_lock<std::mutex> termLock(
m_xListener->mMutex);
4742 if (
m_xListener->mCond.wait_for(termLock, std::chrono::seconds(60),
4743 [
this] { return m_xListener->bIsTerminated; }))
4752 auto [pMed, roEntry] = *it;
4761 globalLock.unlock();
4763 auto checkForErase = [](
SfxMedium* pMed,
const std::shared_ptr<ReadOnlyMediumEntry>& roEntry) ->
bool
4765 if (pMed ==
nullptr || roEntry ==
nullptr || roEntry->_pMutex ==
nullptr
4766 || roEntry->_pIsDestructed ==
nullptr)
4769 std::unique_lock<std::recursive_mutex> medLock(*(roEntry->_pMutex));
4775 if (aFile.open(osl_File_OpenFlag_Write) != osl::FileBase::E_None)
4781 if (aFile.close() != osl::FileBase::E_None)
4793 if (checkForErase(it->first, it->second))
PropertiesInfo aProperties
SfxApplication * SfxGetpApp()
constexpr OUStringLiteral sInputStream
void TransformItems(sal_uInt16 nSlotId, const SfxItemSet &rSet, uno::Sequence< beans::PropertyValue > &rArgs, const SfxSlot *pSlot)
constexpr OUStringLiteral sStream
void TransformParameters(sal_uInt16 nSlotId, const uno::Sequence< beans::PropertyValue > &rArgs, SfxAllItemSet &rSet, const SfxSlot *pSlot)
const sal_uInt16 nVersion
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
const OUString & GetValue() const
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool isAnyKnownWebDAVScheme() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
OUString GetMark(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetURLNoMark(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetLastName(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool insertName(std::u16string_view rTheName, bool bAppendFinalSlash=false, sal_Int32 nIndex=LAST_SEGMENT, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
INetProtocol GetProtocol() const
bool setExtension(std::u16string_view rTheExtension, sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
OUString getFSysPath(FSysStyle eStyle, sal_Unicode *pDelimiter=nullptr) const
SfxFilterMatcher & GetFilterMatcher()
std::shared_ptr< const SfxFilter > GetFilter4FilterName(const OUString &rName, SfxFilterFlags nMust=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
std::shared_ptr< const SfxFilter > GetFilter4EA(const OUString &rEA, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
static OUString GetTypeFromStorage(const SotStorage &rStg)
sal_Int16 GetValue() const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
uno::Reference< task::XInteractionHandler > xInteraction
SignatureState m_nSignatureState
ErrCode nLastStorageError
StreamMode m_nStorOpenMode
std::shared_ptr< std::recursive_mutex > m_pCheckEditableWorkerMutex
uno::Reference< io::XStream > xStream
::ucbhelper::Content aContent
SfxMedium_Impl & operator=(const SfxMedium_Impl &)=delete
bool m_bMSOLockFileCreated
bool m_bNotifyWhenEditable
std::shared_ptr< bool > m_pIsDestructed
SvKeyValueIteratorRef xAttributes
bool m_bInputStreamIsReadOnly
uno::Reference< io::XInputStream > xInputStream
SfxFrameWeakRef wLoadTargetFrame
bool m_bHasEmbeddedObjects
uno::Reference< embed::XStorage > xStorage
util::DateTime m_aDateTime
uno::Reference< io::XStream > m_xLockingStream
std::shared_ptr< const SfxFilter > m_pFilter
std::unique_ptr<::utl::TempFileNamed > pTempFile
ImplSVEvent * m_pReloadEvent
bool m_bVersionsAlreadyLoaded
std::unique_ptr< INetURLObject > m_pURLObj
svtools::AsynchronLink aDoneLink
bool bUseInteractionHandler
bool m_bOriginallyReadOnly
std::shared_ptr< SfxItemSet > m_pSet
uno::Sequence< util::RevisionTag > aVersions
uno::Reference< io::XInputStream > m_xInputStreamToLoadFrom
bool bStorageBasedOnInStream
bool m_bOriginallyLoadedReadOnly
OUString getFilterMimeType() const
std::shared_ptr< const SfxFilter > m_pCustomFilter
std::unique_ptr< SvStream > m_pInStream
uno::Sequence< beans::PropertyValue > m_aArgs
bool m_bDisableUnlockWebDAV
uno::Reference< embed::XStorage > m_xZipStorage
SfxMedium_Impl(const SfxMedium_Impl &)=delete
std::unique_ptr< SvStream > m_pOutStream
bool CheckCanGetLockfile() const
SAL_DLLPRIVATE void GetLockingStream_Impl()
SfxFrame * GetLoadTargetFrame() const
ErrCode const & GetLastStorageCreationState() const
void CreateTempFileNoCopy()
SAL_DLLPRIVATE void CreateFileStream()
void SetOpenMode(StreamMode nStorOpen, bool bDontClose=false)
const std::shared_ptr< const SfxFilter > & GetFilter() const
void DisableFileSync(bool bDisableFileSync)
Lets Transfer_Impl() not fsync the output file.
SAL_DLLPRIVATE void CloseAndReleaseStreams_Impl()
void SetError(ErrCode nError)
void Close(bool bInDestruction=false)
SAL_DLLPRIVATE void CloseInStream_Impl(bool bInDestruction=false)
void setStreamToLoadFrom(const css::uno::Reference< css::io::XInputStream > &xInputStream, bool bIsReadOnly)
OUString GetBaseURL(bool bForSaving=false)
SAL_DLLPRIVATE void SetEncryptionDataToStorage_Impl()
SAL_DLLPRIVATE bool TryDirectTransfer(const OUString &aURL, SfxItemSet const &aTargetSet)
void SetHasEmbeddedObjects(bool bHasEmbeddedObjects)
SAL_DLLPRIVATE void DoBackup_Impl()
bool IsOriginallyLoadedReadOnly() const
const INetURLObject & GetURLObject() const
void UseInteractionHandler(bool)
SAL_DLLPRIVATE bool IsUpdatePickList() const
css::util::DateTime const & GetInitFileDate(bool bIgnoreOldValue)
SAL_DLLPRIVATE void SetStorage_Impl(const css::uno::Reference< css::embed::XStorage > &xNewStorage)
void Download(const Link< void *, void > &aLink=Link< void *, void >())
LockFileResult LockOrigFileOnDemand(bool bLoading, bool bNoUI, bool bTryIgnoreLockFile=false, LockFileEntry *pLockData=nullptr)
SAL_DLLPRIVATE void DoInternalBackup_Impl(const ::ucbhelper::Content &aOriginalContent)
SAL_DLLPRIVATE void SetPhysicalName_Impl(const OUString &rName)
SAL_DLLPRIVATE SignatureState GetCachedSignatureState_Impl() const
bool IsSkipImages() const
ErrCode GetErrorCode() const
SAL_DLLPRIVATE void SetUpdatePickList(bool)
void SetDoneLink(const Link< void *, void > &rLink)
SAL_DLLPRIVATE void CanDisposeStorage_Impl(bool bDisposeStorage)
void SetInCheckIn(bool bInCheckIn)
SfxItemSet * GetItemSet() const
SAL_DLLPRIVATE void SaveVersionList_Impl()
SAL_DLLPRIVATE bool UseBackupToRestore_Impl(::ucbhelper::Content &aOriginalContent, const css::uno::Reference< css::ucb::XCommandEnvironment > &xComEnv)
bool IsOriginallyReadOnly() const
bool ShowLockFileProblemDialog(MessageDlg nWhichDlg)
SAL_DLLPRIVATE OUString const & GetBackup_Impl()
SAL_DLLPRIVATE bool TransferVersionList_Impl(SfxMedium const &rMedium)
StreamMode GetOpenMode() const
static sal_uInt32 CreatePasswordToModifyHash(std::u16string_view aPasswd, bool bWriter)
std::unique_ptr< SfxMedium_Impl > pImpl
const OUString & GetOrigURL() const
SAL_DLLPRIVATE void SetLongName(const OUString &rName)
void SetName(const OUString &rName, bool bSetOrigURL=false)
const css::uno::Sequence< css::util::RevisionTag > & GetVersionList(bool _bNoReload=false)
const OUString & GetName() const
SAL_DLLPRIVATE bool SignDocumentContentUsingCertificate(const css::uno::Reference< css::frame::XModel > &xModel, bool bHasValidDocumentSignature, const css::uno::Reference< css::security::XCertificate > &xCertificate)
void DisableUnlockWebDAV(bool bDisableUnlockWebDAV=true)
const std::shared_ptr< std::recursive_mutex > & GetCheckEditableMutex() const
SAL_DLLPRIVATE void StorageBackup_Impl()
void CancelCheckEditableEntry(bool bRemoveEvent=true)
void SetWarningError(ErrCode nWarningError)
bool SwitchDocumentToFile(const OUString &aURL)
static bool SetWritableForUserOnly(const OUString &aURL)
SAL_DLLPRIVATE bool HasStorage_Impl() const
static OUString CreateTempCopyWithExt(std::u16string_view aURL)
SAL_DLLPRIVATE SvKeyValueIterator * GetHeaderAttributes_Impl()
void UnlockFile(bool bReleaseLockStream)
SAL_DLLPRIVATE void TransactedTransferForFS_Impl(const INetURLObject &aSource, const INetURLObject &aDest, const css::uno::Reference< css::ucb::XCommandEnvironment > &xComEnv)
SAL_DLLPRIVATE bool WillDisposeStorageOnClose_Impl()
void CreateTempFile(bool bReplace=true)
SAL_DLLPRIVATE void SetCachedSignatureState_Impl(SignatureState nState)
virtual ~SfxMedium() override
static bool CallApproveHandler(const css::uno::Reference< css::task::XInteractionHandler > &xHandler, const css::uno::Any &rRequest, bool bAllowAbort)
void SetOriginallyReadOnly(bool val)
const css::uno::Sequence< css::beans::PropertyValue > & GetArgs() const
SAL_DLLPRIVATE void SetIsRemote_Impl()
SAL_DLLPRIVATE void GetMedium_Impl()
SAL_DLLPRIVATE void RemoveVersion_Impl(const OUString &rVersion)
SAL_DLLPRIVATE const OUString & GetLongName() const
void SetFilter(const std::shared_ptr< const SfxFilter > &pFilter)
Does not take ownership of pFlt but pFlt needs to be around as long as the SfxMedium instance.
ShowLockResult ShowLockedDocumentDialog(const LockFileEntry &aData, bool bIsLoading, bool bOwnLock, bool bHandleSysLocked)
SAL_DLLPRIVATE void CloseStreams_Impl(bool bInDestruction=false)
void SetLoadTargetFrame(SfxFrame *pFrame)
css::uno::Reference< css::ucb::XContent > GetContent() const
css::uno::Reference< css::embed::XStorage > GetStorage(bool bCreateTempFile=true)
SAL_DLLPRIVATE void SetExpired_Impl(const DateTime &rDateTime)
SAL_DLLPRIVATE bool IsPreview_Impl() const
SvStream * GetOutStream()
ImplSVEvent * GetWorkerReloadEvent() const
SAL_DLLPRIVATE void Transfer_Impl()
SAL_DLLPRIVATE void CloseOutStream_Impl()
css::uno::Reference< css::io::XInputStream > const & GetInputStream()
SAL_DLLPRIVATE void ClearBackup_Impl()
void SetWorkerReloadEvent(ImplSVEvent *pEvent)
void AddToCheckEditableWorkerList()
OUString SwitchDocumentToTempFile()
SAL_DLLPRIVATE void AddVersion_Impl(css::util::RevisionTag &rVersion)
void CheckFileDate(const css::util::DateTime &aInitDate)
SAL_DLLPRIVATE css::uno::Reference< css::embed::XStorage > const & GetZipStorageToSign_Impl(bool bReadOnly=true)
bool DocNeedsFileDateCheck() const
SAL_DLLPRIVATE bool StorageCommit_Impl()
SAL_DLLPRIVATE bool SignContents_Impl(weld::Window *pDialogParent, bool bSignScriptingContent, bool bHasValidDocumentSignature, const OUString &aSignatureLineId=OUString(), const css::uno::Reference< css::security::XCertificate > &xCert=css::uno::Reference< css::security::XCertificate >(), const css::uno::Reference< css::graphic::XGraphic > &xValidGraphic=css::uno::Reference< css::graphic::XGraphic >(), const css::uno::Reference< css::graphic::XGraphic > &xInvalidGraphic=css::uno::Reference< css::graphic::XGraphic >(), const OUString &aComment=OUString())
SAL_DLLPRIVATE void Init_Impl()
void SetArgs(const css::uno::Sequence< css::beans::PropertyValue > &rArgs)
SAL_DLLPRIVATE void CloseZipStorage_Impl()
ErrCode GetWarningError() const
const OUString & GetPhysicalName() const
css::uno::Reference< css::embed::XStorage > GetOutputStorage()
css::uno::Reference< css::task::XInteractionHandler > GetInteractionHandler(bool bGetAlways=false)
const css::uno::Any & GetValue() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
static bool IsStorageFile(OUString const &rFileName)
bool IsOLEStorage() const
void SetSynchronMode(bool bTheSync=true)
static SvtFilterOptions & Get()
bool IsMSOLockFileCreationIsEnabled() const
const OUString & GetBackupPath() const
static sal_uInt16 GetXLHashAsUINT16(std::u16string_view aString, rtl_TextEncoding nEnc=RTL_TEXTENCODING_UTF8)
static sal_uInt32 GetWordHashAsUINT32(std::u16string_view aString)
static OUString GetODFVersionFromStorage(const css::uno::Reference< css::embed::XStorage > &xStorage)
static void SetCommonStorageEncryptionData(const css::uno::Reference< css::embed::XStorage > &xStorage, const css::uno::Sequence< css::beans::NamedValue > &aEncryptionData)
static css::uno::Reference< css::embed::XStorage > GetStorageFromURL(const OUString &aURL, sal_Int32 nStorageMode, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
static css::uno::Reference< css::embed::XStorage > GetStorageOfFormatFromInputStream(const OUString &aFormat, const css::uno::Reference< css::io::XInputStream > &xStream, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >(), bool bRepairStorage=false)
static css::uno::Reference< css::lang::XSingleServiceFactory > GetStorageFactory(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
static css::uno::Reference< css::embed::XStorage > GetStorageOfFormatFromStream(const OUString &aFormat, const css::uno::Reference< css::io::XStream > &xStream, sal_Int32 nStorageMode=css::embed::ElementModes::READWRITE, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >(), bool bRepairStorage=false)
iterator erase(iterator it)
css::uno::Sequence< css::beans::PropertyValue > getAsConstPropertyValueList() const
static ThreadPool & getSharedOptimalPool()
static std::shared_ptr< ThreadTaskTag > createThreadTaskTag()
void pushTask(std::unique_ptr< ThreadTask > pTask)
static css::uno::Reference< css::task::XInteractionRequest > CreateRequest(const css::uno::Any &aRequest, const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > &lContinuations)
rtl::Reference< comphelper::ConfigurationListener > m_xListener
LockFileEntry GetLockData()
bool OverwriteOwnLockFile()
void RemoveFileDirectly()
virtual void RemoveFile()
static LockFileEntry GenerateOwnEntry()
const OUString & GetURL() const
virtual void RemoveFile() override
static bool IsMSOSupportedFileFormat(std::u16string_view aURL)
css::uno::Any setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue)
void transferContent(const Content &rSourceContent, InsertOperation eOperation, const OUString &rTitle, const sal_Int32 nNameClashAction, const OUString &rMimeType=OUString(), bool bMajorVersion=false, const OUString &rCommentVersion=OUString(), OUString *pResultURL=nullptr, const OUString &rDocumentId=OUString()) const
css::uno::Any getPropertyValue(const OUString &rPropertyName)
static bool create(const OUString &rURL, const css::uno::Reference< css::ucb::XCommandEnvironment > &rEnv, const css::uno::Reference< css::uno::XComponentContext > &rCtx, Content &rContent)
css::uno::Any executeCommand(const OUString &rCommandName, const css::uno::Any &rCommandArgument)
css::uno::Reference< css::ucb::XContent > get() const
css::uno::Reference< css::io::XInputStream > openStream()
void writeStream(const css::uno::Reference< css::io::XInputStream > &rStream, bool bReplaceExisting)
void EnableKillingFile(bool bEnable=true)
OUString const & GetURL() const
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
static std::mutex g_chkReadOnlyGlobalMutex
static std::unordered_map< SfxMedium *, std::shared_ptr< ReadOnlyMediumEntry > > g_newReadOnlyDocs
IMPL_STATIC_LINK(SfxMedium, ShowReloadEditableDialog, void *, p, void)
callback function, which is triggered by worker thread after successfully checking if the file is edi...
static bool g_bChkReadOnlyTaskRunning
static std::unordered_map< SfxMedium *, std::shared_ptr< ReadOnlyMediumEntry > > g_existingReadOnlyDocs
uno::Reference< task::XInteractionHandler2 > m_xHandler
#define ERRCODE_IO_ACCESSDENIED
#define ERRCODE_IO_CANTREAD
#define ERRCODE_IO_GENERAL
#define ERRCODE_IO_NOTEXISTSPATH
#define ERRCODE_IO_CANTWRITE
#define ERRCODE_IO_NOTEXISTS
#define ERRCODE_IO_ALREADYEXISTS
#define LINK(Instance, Class, Member)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
COMPHELPER_DLLPUBLIC bool isFileUrl(std::u16string_view url)
Reference< XComponentContext > getProcessComponentContext()
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
void removeElementAt(css::uno::Sequence< T > &_rSeq, sal_Int32 _nPos)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
std::shared_ptr< osl::Mutex > const & lock()
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
UNOTOOLS_DLLPUBLIC css::uno::Reference< css::ucb::XCommandEnvironment > getDefaultCommandEnvironment()
bool GetEncryptionData_Impl(const SfxItemSet *pSet, uno::Sequence< beans::NamedValue > &o_rEncryptionData)
#define SFX_STREAM_READONLY
#define SFX_STREAM_READWRITE
#define ERRCODE_SFX_CANTCREATEBACKUP