tdf#104718: Prompt user to continue on SAXException

Change-Id: Ib0f9a89c670f8d513ebee206a6a1487802f901ff
Reviewed-on: https://gerrit.libreoffice.org/33181
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski 2017-01-16 21:25:25 +03:00
parent 70b05273c9
commit a2ad27a2be
5 changed files with 53 additions and 4 deletions

View File

@ -213,6 +213,9 @@ private:
bool bIsInGenerateThumbnail; //optimize thumbnail generate and store procedure to improve odt saving performance, i120030
bool mbAvoidRecentDocs; ///< Avoid adding to the recent documents list, if not necessary.
enum TriState {undefined, yes, no};
TriState mbContinueImportOnFilterExceptions = undefined; // try to import as much as possible
bool CloseInternal();
SAL_DLLPRIVATE void UpdateTime_Impl(const css::uno::Reference<
@ -458,6 +461,9 @@ public:
/// Don't add to the recent documents - it's an expensive operation, sometimes it is not wanted.
void AvoidRecentDocs(bool bAvoid) { mbAvoidRecentDocs = bAvoid; }
/// On first error ask user if import should continue; return saved answer.
bool IsContinueImportOnFilterExceptions(const OUString& aErrMessage);
// Transfer IFace
bool IsAbortingImport() const;
void FinishedLoading( SfxLoadedFlags nWhich = SfxLoadedFlags::ALL );

View File

@ -127,8 +127,12 @@
#define STR_MSG_EXPORT_SUCCESS (RID_SFX_DOC_START+170)
#define STR_MSG_QUERY_COPY (RID_SFX_DOC_START+171)
#define STR_QMSG_ERROR_OPENING_FILE (RID_SFX_DOC_START+180)
#define STR_QMSG_ERROR_OPENING_FILE_DETAILS (RID_SFX_DOC_START+181)
#define STR_QMSG_ERROR_OPENING_FILE_CONTINUE (RID_SFX_DOC_START+182)
// please update to the last id
#define ACT_SFX_DOC_END STR_MSG_QUERY_COPY
#define ACT_SFX_DOC_END STR_QMSG_ERROR_OPENING_FILE_CONTINUE
#if ACT_SFX_DOC_END > RID_SFX_DOC_END
#error resource overflow in #line, #file
#endif

View File

@ -353,6 +353,21 @@ String STR_QMSG_SEL_TEMPLATE_DELETE
Text [ en-US ] = "Do you want to delete the selected templates?";
};
String STR_QMSG_ERROR_OPENING_FILE
{
Text [ en-US ] = "An error occured during opening the file. This may be caused by incorrect file contents.\n";
};
String STR_QMSG_ERROR_OPENING_FILE_DETAILS
{
Text [ en-US ] = "The error details are:\n";
};
String STR_QMSG_ERROR_OPENING_FILE_CONTINUE
{
Text [ en-US ] = "\nProceeding with import may cause data loss or corruption, and application may become unstable or crash.\n\nDo you want to ignore the error and attempt to continue loading the file?";
};
Image IMG_ACTION_SORT
{
ImageBitmap = Bitmap

View File

@ -1944,4 +1944,24 @@ void SfxObjectShell::StoreLog()
}
}
bool SfxObjectShell::IsContinueImportOnFilterExceptions(const OUString& aErrMessage)
{
if (mbContinueImportOnFilterExceptions == undefined)
{
if (Application::GetDialogCancelMode() == Application::DialogCancelMode::Off)
{
// Ask the user to try to continue or abort loading
OUString aMessage = SfxResId(STR_QMSG_ERROR_OPENING_FILE).toString();
if (!aErrMessage.isEmpty())
aMessage += SfxResId(STR_QMSG_ERROR_OPENING_FILE_DETAILS).toString() + aErrMessage;
aMessage += SfxResId(STR_QMSG_ERROR_OPENING_FILE_CONTINUE).toString();
ScopedVclPtrInstance< MessageDialog > aBox(nullptr, aMessage, VclMessageType::Question, VclButtonsType::YesNo);
mbContinueImportOnFilterExceptions = (aBox->Execute() == RET_YES) ? yes : no;
}
else
mbContinueImportOnFilterExceptions = no;
}
return mbContinueImportOnFilterExceptions == yes;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -41,6 +41,7 @@
#include <unotools/mediadescriptor.hxx>
#include <iostream>
#include "sfx2/objsh.hxx"
// this extern variable is declared in OOXMLStreamImpl.hxx
OUString customTarget;
@ -503,11 +504,14 @@ void OOXMLDocumentImpl::resolve(Stream & rStream)
{
xParser->parseStream(aParserInput);
}
catch (xml::sax::SAXException const&)
catch (xml::sax::SAXException const& rErr)
{
// don't swallow these - handlers may not have been executed,
// don't silently swallow these - handlers may not have been executed,
// and the domain mapper is likely in an inconsistent state
throw;
// In case user chooses to try to continue loading, don't ask again for this file
SfxObjectShell* rShell = SfxObjectShell::GetShellFromComponent(mxModel);
if (!rShell || !rShell->IsContinueImportOnFilterExceptions("SAXException: " + rErr.Message))
throw;
}
catch (uno::RuntimeException const&)
{