diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2017-11-10 19:04:35 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2017-11-19 21:15:54 +0100 |
commit | 2b2f1352c72280dd25ed3bef090a3c708ee4b964 (patch) | |
tree | 077d196bd438cf4e7b0f9bed466acbe14ae59d5c /sw/source | |
parent | 40acf8d6447065077acba9e800c56239f58c8262 (diff) |
tdf#86087 Save relative links in DOCX
Save links depending on preferences set
Options -> Load/Save -> General -> Save URLs relative to ...
Change-Id: I96d06cfdc405d1e1254515106926374aee279f6c
Reviewed-on: https://gerrit.libreoffice.org/44785
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/filter/ww8/attributeoutputbase.hxx | 6 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8nds.cxx | 68 |
2 files changed, 74 insertions, 0 deletions
diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx b/sw/source/filter/ww8/attributeoutputbase.hxx index 94ed269fa453..028961cd1d8b 100644 --- a/sw/source/filter/ww8/attributeoutputbase.hxx +++ b/sw/source/filter/ww8/attributeoutputbase.hxx @@ -34,6 +34,7 @@ #include <wrtswtbl.hxx> #include <fldbas.hxx> #include <IDocumentRedlineAccess.hxx> +#include <unotools/saveopt.hxx> #include <vector> @@ -146,6 +147,11 @@ enum StyleType class AttributeOutputBase { +private: + SvtSaveOptions m_aSaveOpt; + + OUString ConvertURL( const OUString& rUrl, bool bAbsoluteOut ); + public: /// Export the state of RTL/CJK. virtual void RTLAndCJKState( bool bIsRTL, sal_uInt16 nScript ) = 0; diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index a9d5146d7dac..281232ca5bfd 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -23,6 +23,10 @@ #include <algorithm> #include <iostream> +#include <oox/core/filterbase.hxx> +#include "docxexport.hxx" +#include "docxexportfilter.hxx" + #include <i18nlangtag/mslangid.hxx> #include <hintids.hxx> #include <comphelper/string.hxx> @@ -939,6 +943,62 @@ OUString &TruncateBookmark( OUString &rRet ) return 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(); + sExportedDocumentURL = rWriter.GetMedia()->GetURLObject().GetPath(); + } + } + } + + INetURLObject anAbsoluteParent( sExportedDocumentURL ); + if ( anAbsoluteParent.GetURLPath().isEmpty() ) + { + // DOC filter returns system path (without file:///) + anAbsoluteParent.setFSysPath( sExportedDocumentURL, FSysStyle::Detect ); + anAbsoluteParent.setFinalSlash(); + } + OUString sConvertedParent = INetURLObject::GetScheme( anAbsoluteParent.GetProtocol() ) + anAbsoluteParent.GetURLPath(); + OUString sParentPath = sConvertedParent.isEmpty() ? sExportedDocumentURL : sConvertedParent; + + if ( bAbsoluteOut ) + { + INetURLObject anAbsoluteNew; + + if ( anAbsoluteParent.GetNewAbsURL( rUrl, &anAbsoluteNew ) ) + sURL = anAbsoluteNew.GetMainURL( INetURLObject::DecodeMechanism::WithCharset ); + else + sURL = rUrl; + } + else + { + OUString sToConvert = rUrl.replaceAll( "\\", "/" ); + INetURLObject aURL( sToConvert ); + sToConvert = INetURLObject::GetScheme( aURL.GetProtocol() ) + aURL.GetURLPath(); + OUString sRelative = INetURLObject::GetRelURL( sParentPath, sToConvert, INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism::WithCharset ); + if ( !sRelative.isEmpty() ) + sURL = sRelative; + } + + return sURL; +} + bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rTarget*/, OUString* pLinkURL, OUString* pMark ) { bool bBookMarkOnly = false; @@ -975,6 +1035,14 @@ bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rT INetURLObject aURL( rUrl, INetProtocol::NotValid ); sURL = aURL.GetURLNoMark( INetURLObject::DecodeMechanism::Unambiguous ); sMark = aURL.GetMark( INetURLObject::DecodeMechanism::Unambiguous ); + INetProtocol aProtocol = aURL.GetProtocol(); + + if ( aProtocol == INetProtocol::File || aProtocol == INetProtocol::NotValid ) + { + // INetProtocol::NotValid - may be a relative link + bool bExportRelative = m_aSaveOpt.IsSaveRelFSys(); + sURL = ConvertURL( rUrl, !bExportRelative ); + } } if ( !sMark.isEmpty() && sURL.isEmpty() ) |