summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-04-20 11:03:19 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-04-20 15:25:01 +0200
commit0ae159cc40b837a6a47acaf9240dc350fe68d49d (patch)
treeeeb653f43a1a026145104abdc1313cb13b02aa7e /sw/source
parentf067e06c2ff1fa12e5a45c34186aae75a2aff3b1 (diff)
sw bibliography table, text generator: handle relative URLs
Now that the doc model always contains absolute URLs, it is possible to decide when it does and when it doesn't make sense to convert to relative URLs. The bibliography table does a mixed approach: the document text depends on configuration (relative by default), but the underlying URL is an absolute one. This way it's always clickable and the ODT filter can save it as a relative one (again, depending on configuration). With this, all fields are meant to be clickable: biblio field vs biblio table, relative or absolute ones, with or with a (page) fragment, Writer UI vs PDF export. Change-Id: Ib6879709314fa127094faf7fa615fe57289b41f1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114299 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/source')
-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);