[Libreoffice-commits] core.git: sw/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Thu Apr 15 13:26:13 UTC 2021
sw/source/core/inc/txmsrt.hxx | 2 +-
sw/source/core/tox/txmsrt.cxx | 35 +++++++++++++++++------------------
2 files changed, 18 insertions(+), 19 deletions(-)
New commits:
commit 6c9a86a6392662f1115d3fe6b793a451101429b7
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Apr 15 13:07:37 2021 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Apr 15 15:25:31 2021 +0200
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 at collabora.com>
Tested-by: Jenkins
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;
More information about the Libreoffice-commits
mailing list