summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-08-17 11:36:10 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-08-17 11:36:10 +0200
commit0dd82f4ffe7ae462bae30b93d245d2234c55ef84 (patch)
treeefc57bd15842de5a209dcb3beeacd22838db5c44
parent8004bcd6e1180bdeae03200b2e5f6f93351d5e07 (diff)
tdf#86087: Convert relative URLs to absolute upon import of docx etc.
...to fix the import part of tdf#86087. Apparently, "fragment-only" relative same-document URLs (like <#anchor>) are supposed to remain relative; otherwise, various tests like testFdo69548::Import in CppunitTest_sw_ooxmlimport fail. Change-Id: I2dbba2f2f1e225f85e21600e68a3c4cffdb023b2
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx22
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx1
2 files changed, 23 insertions, 0 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 98a9900c2cb8..256e690716bf 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -68,6 +68,7 @@
#include <com/sun/star/text/ControlCharacter.hpp>
#include <com/sun/star/text/XTextColumns.hpp>
#include <oox/mathml/import.hxx>
+#include <rtl/uri.hxx>
#include <GraphicHelpers.hxx>
#include <dmapper/GraphicZOrderHelper.hxx>
@@ -241,6 +242,13 @@ DomainMapper_Impl::DomainMapper_Impl(
m_bParaHadField(false)
{
+ m_aBaseUrl = rMediaDesc.getUnpackedValueOrDefault(
+ utl::MediaDescriptor::PROP_DOCUMENTBASEURL(), OUString());
+ if (m_aBaseUrl.isEmpty()) {
+ m_aBaseUrl = rMediaDesc.getUnpackedValueOrDefault(
+ utl::MediaDescriptor::PROP_URL(), OUString());
+ }
+
appendTableManager( );
GetBodyText();
uno::Reference< text::XTextAppend > xBodyTextAppend( m_xBodyText, uno::UNO_QUERY );
@@ -3867,6 +3875,20 @@ void DomainMapper_Impl::CloseFieldCommand()
if (!sURL.isEmpty())
{
+ // Try to make absolute any relative URLs, except
+ // for relative same-document URLs that only contain
+ // a fragment part:
+ if (!sURL.startsWith("#")) {
+ try {
+ sURL = rtl::Uri::convertRelToAbs(
+ m_aBaseUrl, sURL);
+ } catch (rtl::MalformedUriException & e) {
+ SAL_WARN(
+ "writerfilter.dmapper",
+ "MalformedUriException "
+ << e.getMessage());
+ }
+ }
pContext->SetHyperlinkURL(sURL);
}
}
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 5c34a23f8f2c..ec40e8e00028 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -343,6 +343,7 @@ public:
private:
SourceDocumentType m_eDocumentType;
DomainMapper& m_rDMapper;
+ OUString m_aBaseUrl;
css::uno::Reference<css::text::XTextDocument> m_xTextDocument;
css::uno::Reference<css::beans::XPropertySet> m_xDocumentSettings;
css::uno::Reference<css::lang::XMultiServiceFactory> m_xTextFactory;