summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw/source/core/tox/ToxTextGenerator.cxx6
-rw-r--r--sw/source/core/tox/txmsrt.cxx31
2 files changed, 36 insertions, 1 deletions
diff --git a/sw/source/core/tox/ToxTextGenerator.cxx b/sw/source/core/tox/ToxTextGenerator.cxx
index 95952aa06cd2..df37f294796b 100644
--- a/sw/source/core/tox/ToxTextGenerator.cxx
+++ b/sw/source/core/tox/ToxTextGenerator.cxx
@@ -268,7 +268,11 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc,
rBase.FillText( *pTOXNd, aIdx, static_cast<sal_uInt16>(eField), pLayout );
if (eField == ToxAuthorityField::AUTH_FIELD_URL)
{
- OUString aURL(rText.subView(nStartCharStyle));
+ // Get the absolute URL, the text may be a relative one.
+ const auto& rAuthority = static_cast<const SwTOXAuthority&>(rBase);
+ OUString aURL = SwTOXAuthority::GetSourceURL(
+ rAuthority.GetText(AUTH_FIELD_URL, pLayout));
+
mLinkProcessor->CloseLink(rText.getLength(), aURL, /*bRelative=*/false);
}
}
diff --git a/sw/source/core/tox/txmsrt.cxx b/sw/source/core/tox/txmsrt.cxx
index 193dc1d48a71..e0ffc1922701 100644
--- a/sw/source/core/tox/txmsrt.cxx
+++ b/sw/source/core/tox/txmsrt.cxx
@@ -23,6 +23,7 @@
#include <osl/diagnose.h>
#include <tools/urlobj.hxx>
#include <comphelper/processfactory.hxx>
+#include <officecfg/Office/Common.hxx>
#include <txtfld.hxx>
#include <doc.hxx>
#include <IDocumentLayoutAccess.hxx>
@@ -878,6 +879,36 @@ void SwTOXAuthority::FillText(SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt1
if (nAuthField == AUTH_FIELD_URL)
{
aText = GetSourceURL(aText);
+
+ // Convert URL to a relative one if requested.
+ SwDoc* pDoc = static_cast<SwAuthorityFieldType*>(m_rField.GetField()->GetTyp())->GetDoc();
+ SwDocShell* pDocShell = pDoc->GetDocShell();
+ OUString aBaseURL = pDocShell->getDocumentBaseURL();
+ OUString aBaseURIScheme;
+ sal_Int32 nSep = aBaseURL.indexOf(':');
+ if (nSep != -1)
+ {
+ aBaseURIScheme = aBaseURL.copy(0, nSep);
+ }
+
+ uno::Reference<uri::XUriReferenceFactory> xUriReferenceFactory
+ = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext());
+ uno::Reference<uri::XUriReference> xUriRef;
+ try
+ {
+ xUriRef = xUriReferenceFactory->parse(aText);
+ }
+ catch (const uno::Exception& rException)
+ {
+ SAL_WARN("sw.core",
+ "SwTOXAuthority::FillText: failed to parse url: " << rException.Message);
+ }
+
+ bool bSaveRelFSys = officecfg::Office::Common::Save::URL::FileSystem::get();
+ if (xUriRef.is() && bSaveRelFSys && xUriRef->getScheme() == aBaseURIScheme)
+ {
+ aText = INetURLObject::GetRelURL(aBaseURL, aText);
+ }
}
rNd.InsertText(aText, rInsPos);