[Libreoffice-commits] core.git: include/sfx2 sfx2/inc sfx2/source writerfilter/source

Mike Kaganski mike.kaganski at collabora.com
Thu Jan 19 07:02:08 UTC 2017


 include/sfx2/objsh.hxx                          |    6 ++++++
 sfx2/inc/doc.hrc                                |    6 +++++-
 sfx2/source/doc/doc.src                         |   15 +++++++++++++++
 sfx2/source/doc/objmisc.cxx                     |   20 ++++++++++++++++++++
 writerfilter/source/ooxml/OOXMLDocumentImpl.cxx |   10 +++++++---
 5 files changed, 53 insertions(+), 4 deletions(-)

New commits:
commit a2ad27a2be429c6d17ef28c28ac5aee66ad8545d
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Mon Jan 16 21:25:25 2017 +0300

    tdf#104718: Prompt user to continue on SAXException
    
    Change-Id: Ib0f9a89c670f8d513ebee206a6a1487802f901ff
    Reviewed-on: https://gerrit.libreoffice.org/33181
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index bf69c21..7a2e133 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -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 );
diff --git a/sfx2/inc/doc.hrc b/sfx2/inc/doc.hrc
index 388cdf6..29e4f66 100644
--- a/sfx2/inc/doc.hrc
+++ b/sfx2/inc/doc.hrc
@@ -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
diff --git a/sfx2/source/doc/doc.src b/sfx2/source/doc/doc.src
index 978f5e3..d607087 100644
--- a/sfx2/source/doc/doc.src
+++ b/sfx2/source/doc/doc.src
@@ -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
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 806228e..36d8fac 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -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: */
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
index f836cf8..94f2fbb 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
@@ -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&)
         {


More information about the Libreoffice-commits mailing list