[Libreoffice-commits] core.git: sw/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Wed Aug 28 15:20:15 UTC 2019


 sw/source/filter/ww8/attributeoutputbase.hxx |    6 ++++-
 sw/source/filter/ww8/docxattributeoutput.cxx |    3 +-
 sw/source/filter/ww8/rtfattributeoutput.cxx  |    3 +-
 sw/source/filter/ww8/wrtw8nds.cxx            |   28 +--------------------------
 sw/source/filter/ww8/ww8attributeoutput.hxx  |    4 ++-
 5 files changed, 14 insertions(+), 30 deletions(-)

New commits:
commit a1a401acaafee0b1f154d368a247d74d61c62191
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Wed Aug 28 17:02:31 2019 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Aug 28 17:19:54 2019 +0200

    Avoid dynamic_cast in AttributeOutputBase::ConvertURL
    
    This unifies the code for any format using the function.
    
    Note: RTF code currently doesn't use the function, so an empty string
    is used in its ctor.
    
    Change-Id: I8776c095d4527313d06b0620059a892a48a9eaa1
    Reviewed-on: https://gerrit.libreoffice.org/78229
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx b/sw/source/filter/ww8/attributeoutputbase.hxx
index 72116df53bc2..b6eca7f2da22 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -146,6 +146,7 @@ class AttributeOutputBase
 {
 private:
     SvtSaveOptions const m_aSaveOpt;
+    OUString m_sBaseURL; // To be used in ConvertURL
 
     OUString ConvertURL( const OUString& rUrl, bool bAbsoluteOut );
 
@@ -636,7 +637,10 @@ protected:
     ww8::WidthsPtr   GetColumnWidths( ww8::WW8TableNodeInfoInner::Pointer_t const & pTableTextNodeInfoInner );
 
 public:
-    AttributeOutputBase() {}
+    AttributeOutputBase(const OUString& sBaseURL)
+        : m_sBaseURL(sBaseURL)
+    {
+    }
     virtual ~AttributeOutputBase() {}
 
     /// Return the right export class.
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 3d705d76a83a..209a1a1aec0a 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -9029,7 +9029,8 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem )
 }
 
 DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, const FSHelperPtr& pSerializer, oox::drawingml::DrawingML* pDrawingML )
-    : m_rExport( rExport ),
+    : AttributeOutputBase(rExport.GetFilter().getFileUrl()),
+      m_rExport( rExport ),
       m_pSerializer( pSerializer ),
       m_rDrawingML( *pDrawingML ),
       m_bEndCharSdt(false),
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index d8afcc351867..c9705c740717 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -3672,7 +3672,8 @@ bool RtfAttributeOutput::PlaceholderField(const SwField* pField)
 }
 
 RtfAttributeOutput::RtfAttributeOutput(RtfExport& rExport)
-    : m_rExport(rExport)
+    : AttributeOutputBase("") // ConvertURL isn't used now in RTF output
+    , m_rExport(rExport)
     , m_pPrevPageDesc(nullptr)
     , m_nStyleId(0)
     , m_nListId(0)
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 080e24bbfcdc..c67c9e05b9d5 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -874,32 +874,10 @@ static OUString &TruncateBookmark( OUString &rRet )
 OUString AttributeOutputBase::ConvertURL( const OUString& rUrl, bool bAbsoluteOut )
 {
     OUString sURL = rUrl;
-    OUString sExportedDocumentURL = "";
-    {
-        DocxExport* pDocxExport = dynamic_cast<DocxExport*>(&GetExport());
-        if ( pDocxExport )
-        {
-            // DOCX
-            DocxExportFilter& rFilter = pDocxExport->GetFilter();
-            sExportedDocumentURL = rFilter.getFileUrl();
-        }
-        else
-        {
-            // DOC
-            WW8Export* pWW8Export = dynamic_cast<WW8Export*>(&GetExport());
-            if ( pWW8Export )
-            {
-                SwWW8Writer& rWriter = pWW8Export->GetWriter();
-                INetURLObject parent(rWriter.GetMedia()->GetURLObject());
-                parent.removeSegment();
-                sExportedDocumentURL = parent.GetMainURL(INetURLObject::DecodeMechanism::NONE);
-            }
-        }
-    }
 
-    INetURLObject anAbsoluteParent( sExportedDocumentURL );
+    INetURLObject anAbsoluteParent(m_sBaseURL);
     OUString sConvertedParent = INetURLObject::GetScheme( anAbsoluteParent.GetProtocol() ) + anAbsoluteParent.GetURLPath();
-    OUString sParentPath = sConvertedParent.isEmpty() ? sExportedDocumentURL : sConvertedParent;
+    OUString sParentPath = sConvertedParent.isEmpty() ? m_sBaseURL : sConvertedParent;
 
     if ( bAbsoluteOut )
     {
@@ -907,8 +885,6 @@ OUString AttributeOutputBase::ConvertURL( const OUString& rUrl, bool bAbsoluteOu
 
         if ( anAbsoluteParent.GetNewAbsURL( rUrl, &anAbsoluteNew ) )
             sURL = anAbsoluteNew.GetMainURL( INetURLObject::DecodeMechanism::NONE );
-        else
-            sURL = rUrl;
     }
     else
     {
diff --git a/sw/source/filter/ww8/ww8attributeoutput.hxx b/sw/source/filter/ww8/ww8attributeoutput.hxx
index 254b52722be3..35d8db7dfa5e 100644
--- a/sw/source/filter/ww8/ww8attributeoutput.hxx
+++ b/sw/source/filter/ww8/ww8attributeoutput.hxx
@@ -23,6 +23,7 @@
 #include "attributeoutputbase.hxx"
 #include "wrtww8.hxx"
 #include <editeng/boxitem.hxx>
+#include <sfx2/docfile.hxx>
 
 class WW8AttributeOutput : public AttributeOutputBase
 {
@@ -467,7 +468,8 @@ protected:
 
 public:
     explicit WW8AttributeOutput( WW8Export &rWW8Export )
-        : AttributeOutputBase()
+        : AttributeOutputBase(rWW8Export.GetWriter().GetMedia()->GetURLObject().GetMainURL(
+            INetURLObject::DecodeMechanism::NONE))
         , m_rWW8Export(rWW8Export)
         , nPOPosStdLen1(0)
         , nPOPosStdLen2(0)


More information about the Libreoffice-commits mailing list