diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-04-15 13:07:37 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-04-15 15:25:31 +0200 |
commit | 6c9a86a6392662f1115d3fe6b793a451101429b7 (patch) | |
tree | d3760b026ef4151641658db5ec9555d63b5881e7 /sw | |
parent | 6614144435b9e9143a4d20c46a727ddbca5b18e8 (diff) |
sw: avoid rel<->abs URL conversion in SwTOXAuthority::GetSourceURL()
Suggested at
<https://gerrit.libreoffice.org/c/core/+/114104/2#message-5dce4cbf4bac90d4bad0726e50eb79cca0e40de9>,
turns out we can clear the fragment of a relative URL without converting
to an absolute one, which is less code and probably behaves better with
a not yet saved document (empty base URL).
Change-Id: I8cee210aada10a3e8049e5b7a6921f1be4445bb8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114124
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/inc/txmsrt.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/tox/txmsrt.cxx | 35 |
2 files changed, 18 insertions, 19 deletions
diff --git a/sw/source/core/inc/txmsrt.hxx b/sw/source/core/inc/txmsrt.hxx index ac89aab96c1b..873e683c451e 100644 --- a/sw/source/core/inc/txmsrt.hxx +++ b/sw/source/core/inc/txmsrt.hxx @@ -299,7 +299,7 @@ public: OUString GetText(sal_uInt16 nAuthField, const SwRootFrame* pLayout) const; /// Gets the URL of the underlying SwAuthEntry, ignoring its page number. - OUString GetSourceURL(const OUString& rText) const; + static OUString GetSourceURL(const OUString& rText); }; #endif // INCLUDED_SW_SOURCE_CORE_INC_TXMSRT_HXX diff --git a/sw/source/core/tox/txmsrt.cxx b/sw/source/core/tox/txmsrt.cxx index dade7ad0c5b2..193dc1d48a71 100644 --- a/sw/source/core/tox/txmsrt.cxx +++ b/sw/source/core/tox/txmsrt.cxx @@ -17,9 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <com/sun/star/uri/UriReferenceFactory.hpp> + #include <unotools/charclass.hxx> #include <osl/diagnose.h> #include <tools/urlobj.hxx> +#include <comphelper/processfactory.hxx> #include <txtfld.hxx> #include <doc.hxx> #include <IDocumentLayoutAccess.hxx> @@ -843,30 +846,26 @@ OUString SwTOXAuthority::GetText(sal_uInt16 nAuthField, const SwRootFrame* pLayo return sText; } -OUString SwTOXAuthority::GetSourceURL(const OUString& rText) const +OUString SwTOXAuthority::GetSourceURL(const OUString& rText) { OUString aText = rText; - SwDoc* pDoc = static_cast<SwAuthorityFieldType*>(m_rField.GetField()->GetTyp())->GetDoc(); - SwDocShell* pDocShell = pDoc->GetDocShell(); - OUString aBasePath = pDocShell->getDocumentBaseURL(); - OUString aAbs - = INetURLObject::GetAbsURL(aBasePath, aText, INetURLObject::EncodeMechanism::WasEncoded, - INetURLObject::DecodeMechanism::WithCharset); - bool bRelative = aAbs != aText; - - INetURLObject aObject(aAbs); - if (aObject.GetMark().startsWith("page=")) + uno::Reference<uri::XUriReferenceFactory> xUriReferenceFactory + = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext()); + uno::Reference<uri::XUriReference> xUriRef; + try { - aObject.SetMark(OUString()); - aText = aObject.GetMainURL(INetURLObject::DecodeMechanism::NONE); + xUriRef = xUriReferenceFactory->parse(aText); } - - if (bRelative) + catch (const uno::Exception& rException) + { + SAL_WARN("sw.core", + "SwTOXAuthority::GetSourceURL: failed to parse url: " << rException.Message); + } + if (xUriRef.is() && xUriRef->getFragment().startsWith("page=")) { - aText - = INetURLObject::GetRelURL(aBasePath, aText, INetURLObject::EncodeMechanism::WasEncoded, - INetURLObject::DecodeMechanism::WithCharset); + xUriRef->clearFragment(); + aText = xUriRef->getUriReference(); } return aText; |