Kaydet (Commit) 0dd82f4f authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
üst 8004bcd6
......@@ -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);
}
}
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment