sfx2/inc/sfx2/sfxbasemodel.hxx | 3 + sfx2/source/doc/sfxbasemodel.cxx | 78 ++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 37 deletions(-)
New commits: commit 51617bb6c1374a9e699f67964c586e70d8ab0dbc Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Thu Apr 11 00:18:40 2013 -0400 Share error handling code between DoLoad() and DoLoadExternal(). Change-Id: I34167b80e9ac31b32639cd3be903ba9edbdfa41a diff --git a/sfx2/inc/sfx2/sfxbasemodel.hxx b/sfx2/inc/sfx2/sfxbasemodel.hxx index 9c15b50..524c86b 100644 --- a/sfx2/inc/sfx2/sfxbasemodel.hxx +++ b/sfx2/inc/sfx2/sfxbasemodel.hxx @@ -91,6 +91,7 @@ #include <svl/lstner.hxx> +class SfxMedium; class SfxPrinter; class SfxViewShell; class SfxObjectShell ; @@ -1456,6 +1457,8 @@ private: SAL_DLLPRIVATE void loadCmisProperties(); + SAL_DLLPRIVATE void handleLoadError( sal_uInt32 nError, SfxMedium* pMedium ); + //________________________________________________________________________________________________________ // private variables and methods //________________________________________________________________________________________________________ diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index c84e2ad..5b28cc2 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -1851,15 +1851,14 @@ void SAL_CALL SfxBaseModel::load( const Sequence< beans::PropertyValue >& seqA SfxMedium* pMedium = new SfxMedium( seqArguments ); + sal_uInt32 nError = ERRCODE_NONE; OUString aFilterProvider = getFilterProvider(seqArguments); if (!aFilterProvider.isEmpty()) { if (!m_pData->m_pObjectShell->DoLoadExternal(pMedium)) - { - throw task::ErrorCodeIOException( - OUString(), Reference<XInterface>(), ERRCODE_IO_CANTREAD); - } + nError = ERRCODE_IO_GENERAL; + handleLoadError(nError, pMedium); pMedium->SetUpdatePickList(false); return; } @@ -1879,7 +1878,6 @@ void SAL_CALL SfxBaseModel::load( const Sequence< beans::PropertyValue >& seqA sal_Bool bSalvage = pSalvageItem ? sal_True : sal_False; // load document - sal_uInt32 nError = ERRCODE_NONE; if ( !m_pData->m_pObjectShell->DoLoad(pMedium) ) nError=ERRCODE_IO_GENERAL; @@ -1948,38 +1946,7 @@ void SAL_CALL SfxBaseModel::load( const Sequence< beans::PropertyValue >& seqA m_pData->m_pObjectShell->ResetError(); - if ( nError ) - { - sal_Bool bSilent = sal_False; - SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSilentItem, SfxBoolItem, SID_SILENT, sal_False); - if( pSilentItem ) - bSilent = pSilentItem->GetValue(); - - sal_Bool bWarning = ((nError & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK); - if ( nError != ERRCODE_IO_BROKENPACKAGE && !bSilent ) - { - // broken package was handled already - if ( SfxObjectShell::UseInteractionToHandleError( xHandler, nError ) && !bWarning ) - { - // abort loading (except for warnings) - nError = ERRCODE_IO_ABORT; - } - } - - if ( m_pData->m_pObjectShell->GetMedium() != pMedium ) - { - // for whatever reason document now has another medium - OSL_FAIL("Document has rejected the medium?!"); - delete pMedium; - } - - if ( !bWarning ) // #i30711# don't abort loading if it's only a warning - { - throw task::ErrorCodeIOException( OUString(), - Reference< XInterface >(), - nError ? nError : ERRCODE_IO_CANTREAD ); - } - } + handleLoadError(nError, pMedium); loadCmisProperties( ); @@ -2711,6 +2678,43 @@ void SfxBaseModel::loadCmisProperties( ) } } +void SfxBaseModel::handleLoadError( sal_uInt32 nError, SfxMedium* pMedium ) +{ + if (!nError) + // No error condition. + return; + + bool bSilent = false; + SFX_ITEMSET_ARG( pMedium->GetItemSet(), pSilentItem, SfxBoolItem, SID_SILENT, false); + if( pSilentItem ) + bSilent = pSilentItem->GetValue(); + + bool bWarning = ((nError & ERRCODE_WARNING_MASK) == ERRCODE_WARNING_MASK); + if ( nError != ERRCODE_IO_BROKENPACKAGE && !bSilent ) + { + // broken package was handled already + if ( SfxObjectShell::UseInteractionToHandleError(pMedium->GetInteractionHandler(), nError) && !bWarning) + { + // abort loading (except for warnings) + nError = ERRCODE_IO_ABORT; + } + } + + if ( m_pData->m_pObjectShell->GetMedium() != pMedium ) + { + // for whatever reason document now has another medium + OSL_FAIL("Document has rejected the medium?!"); + delete pMedium; + } + + if ( !bWarning ) // #i30711# don't abort loading if it's only a warning + { + throw task::ErrorCodeIOException( OUString(), + Reference< XInterface >(), + nError ? nError : ERRCODE_IO_CANTREAD ); + } +} + //________________________________________________________________________________________________________ // SfxListener //________________________________________________________________________________________________________ commit 516d8f0247cc4f79736549b656f2d916ac285ba3 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Wed Apr 10 23:54:49 2013 -0400 Handle load error correctly. When we fail to load a new document, we shouldn't manually delete the SfxMedium instance there since SfxObjectShell gets to own it after the DoLoadExternal call. And we need to throw an error instead of simply return from load(). Change-Id: Ic194d47dd1caaab3034aba1b9add54c9b5338a38 diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index a333a98..c84e2ad 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -1856,8 +1856,8 @@ void SAL_CALL SfxBaseModel::load( const Sequence< beans::PropertyValue >& seqA { if (!m_pData->m_pObjectShell->DoLoadExternal(pMedium)) { - delete pMedium; - return; + throw task::ErrorCodeIOException( + OUString(), Reference<XInterface>(), ERRCODE_IO_CANTREAD); } pMedium->SetUpdatePickList(false); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits