include/sfx2/objsh.hxx                          |    2 
 include/sfx2/strings.hrc                        |    3 -
 sfx2/source/doc/objmisc.cxx                     |   54 +++++++++++++++++++-----
 writerfilter/source/ooxml/OOXMLDocumentImpl.cxx |    6 --
 4 files changed, 47 insertions(+), 18 deletions(-)

New commits:
commit 92e7f28f9aff78907bad030be80a9ea9452a3ddc
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Nov 27 18:07:30 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Nov 29 06:23:33 2023 +0100

    Related: tdf#104718 Use package repair request and behavior
    
    Same as in other places handling that:
    * SfxBaseModel::load (sfx2/source/doc/sfxbasemodel.cxx);
    * StorageFilterDetect::detect 
(filter/source/storagefilterdetect/filterdetect.cxx);
    * TypeDetection::impl_detectTypeFlatAndDeep 
(filter/source/config/cache/typedetection.cxx)
    
    In these cases, the same handler is used (RequestPackageReparation);
    when the user approves an attempt to repair the package, the media
    descriptor gets "RepairPackage" property set to true (this produces
    a "(repaired document)" appended to the document title); also, the
    document is opened in template mode (so saving it doesn't simply
    overwrite the original broken document, but asks for a new name).
    
    Re-using this logic, and checking if the "RepairPackage" is already
    set, allows to unify the behavior, and to avoid duplicate warnings
    when the user already approved repair of a broken package.
    
    The request won't contain the details of the XML problem; but it
    will be shown if rejected anyway, so OK for the diagnostics.
    
    Change-Id: Ic997f89272212227479d14236f5e7788298a904a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160001
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index fd23ae4af437..20e497b6e4af 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -475,7 +475,7 @@ public:
     void                        AvoidRecentDocs(bool bAvoid) { 
mbAvoidRecentDocs = bAvoid; }
 
     /// On first error ask user if import should continue; return saved answer.
-    bool                        
IsContinueImportOnFilterExceptions(std::u16string_view aErrMessage);
+    bool                        IsContinueImportOnFilterExceptions();
 
     // Transfer IFace
     bool                        IsAbortingImport() const;
diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc
index 300e1036169b..d28fa1cc22b7 100644
--- a/include/sfx2/strings.hrc
+++ b/include/sfx2/strings.hrc
@@ -70,9 +70,6 @@
 #define STR_QMSG_SEL_FOLDER_DELETE              
NC_("STR_QMSG_SEL_FOLDER_DELETE", "Do you want to delete the selected 
category?")
 #define STR_QMSG_TEMPLATE_OVERWRITE             
NC_("STR_QMSG_TEMPLATE_OVERWRITE", "A template named $1 already exists in $2. 
Do you want to overwrite it?")
 #define STR_QMSG_SEL_TEMPLATE_DELETE            
NC_("STR_QMSG_SEL_TEMPLATE_DELETE", "Do you want to delete the selected 
templates?")
-#define STR_QMSG_ERROR_OPENING_FILE             
NC_("STR_QMSG_ERROR_OPENING_FILE", "An error occurred during opening the file. 
This may be caused by incorrect file contents.\n")
-#define STR_QMSG_ERROR_OPENING_FILE_DETAILS     
NC_("STR_QMSG_ERROR_OPENING_FILE_DETAILS", "The error details are:\n")
-#define STR_QMSG_ERROR_OPENING_FILE_CONTINUE    
NC_("STR_QMSG_ERROR_OPENING_FILE_CONTINUE", "\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?")
 
 #define STR_HELP_WINDOW_TITLE                   NC_("STR_HELP_WINDOW_TITLE", 
"%PRODUCTNAME Help")
 #define STR_HELP_BUTTON_INDEX_ON                
NC_("STR_HELP_BUTTON_INDEX_ON", "Show Navigation Pane")
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 57deb4fe9de8..ede8983608c6 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -50,6 +50,7 @@
 #include <com/sun/star/uno/Any.h>
 #include <com/sun/star/task/ErrorCodeRequest2.hpp>
 
+#include <comphelper/lok.hxx>
 #include <comphelper/processfactory.hxx>
 #include <comphelper/string.hxx>
 
@@ -66,6 +67,7 @@
 #include <basic/sbx.hxx>
 #include <svtools/sfxecode.hxx>
 
+#include <unotools/mediadescriptor.hxx>
 #include <unotools/ucbhelper.hxx>
 #include <tools/urlobj.hxx>
 #include <svl/sharecontrolfile.hxx>
@@ -80,6 +82,7 @@
 #include <ucbhelper/simpleinteractionrequest.hxx>
 #include <officecfg/Office/Common.hxx>
 
+#include <sfx2/brokenpackageint.hxx>
 #include <sfx2/signaturestate.hxx>
 #include <sfx2/app.hxx>
 #include <appdata.hxx>
@@ -1937,20 +1940,51 @@ bool SfxObjectShell_Impl::hasTrustedScriptingSignature(
     return bResult;
 }
 
-bool SfxObjectShell::IsContinueImportOnFilterExceptions(std::u16string_view 
aErrMessage)
+bool SfxObjectShell::IsContinueImportOnFilterExceptions()
 {
     if (mbContinueImportOnFilterExceptions == undefined)
     {
-        if (Application::GetDialogCancelMode() == DialogCancelMode::Off)
+        if (!pMedium)
         {
-            // Ask the user to try to continue or abort loading
-            OUString aMessage = SfxResId(STR_QMSG_ERROR_OPENING_FILE);
-            if (!aErrMessage.empty())
-                aMessage += SfxResId(STR_QMSG_ERROR_OPENING_FILE_DETAILS) + 
aErrMessage;
-            aMessage += SfxResId(STR_QMSG_ERROR_OPENING_FILE_CONTINUE);
-            std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(nullptr,
-                                                      
VclMessageType::Question, VclButtonsType::YesNo, aMessage));
-            mbContinueImportOnFilterExceptions = (xBox->run() == RET_YES) ? 
yes : no;
+            mbContinueImportOnFilterExceptions = no;
+            return false;
+        }
+
+        if (utl::MediaDescriptor desc(pMedium->GetArgs());
+            !desc.getUnpackedValueOrDefault("RepairAllowed", true))
+        {
+            mbContinueImportOnFilterExceptions = no;
+            return false;
+        }
+
+        if (const SfxBoolItem* pRepairItem
+            = pMedium->GetItemSet().GetItem(SID_REPAIRPACKAGE, false);
+            pRepairItem && pRepairItem->GetValue())
+        {
+            mbContinueImportOnFilterExceptions = yes;
+            return true;
+        }
+
+        auto xInteractionHandler = pMedium->GetInteractionHandler();
+        if (!xInteractionHandler)
+        {
+            mbContinueImportOnFilterExceptions = no;
+            return false;
+        }
+
+        const OUString aDocName(pMedium->GetURLObject().getName(
+            INetURLObject::LAST_SEGMENT, true, 
INetURLObject::DecodeMechanism::WithCharset));
+        RequestPackageReparation aRequest(aDocName);
+        xInteractionHandler->handle(aRequest.GetRequest());
+        if (aRequest.isApproved())
+        {
+            mbContinueImportOnFilterExceptions = yes;
+            // lok: we want to overwrite file in jail, so don't use template 
flag
+            bool bIsLOK = comphelper::LibreOfficeKit::isActive();
+            // allow repair
+            pMedium->GetItemSet().Put(SfxBoolItem(SID_REPAIRPACKAGE, true));
+            pMedium->GetItemSet().Put(SfxBoolItem(SID_TEMPLATE, !bIsLOK));
+            pMedium->GetItemSet().Put(SfxStringItem(SID_DOCINFO_TITLE, 
aDocName));
         }
         else
             mbContinueImportOnFilterExceptions = no;
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx 
b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
index 1d1fee55a809..d9900ea7e4fc 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
@@ -514,15 +514,13 @@ void OOXMLDocumentImpl::resolve(Stream & rStream)
     {
         xParser->parseStream(aParserInput);
     }
-    catch (xml::sax::SAXException const& rErr)
+    catch (xml::sax::SAXException const&)
     {
         // don't silently swallow these - handlers may not have been executed,
         // and the domain mapper is likely in an inconsistent state
         // 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(
-                Concat2View("SAXException: " + rErr.Message)))
+        if (!rShell || !rShell->IsContinueImportOnFilterExceptions())
             throw;
     }
     catch (uno::RuntimeException const&)

Reply via email to