1 |
From c1cda1d83890d2d1583e7652548674f4ca3305c3 Mon Sep 17 00:00:00 2001 |
2 |
From: Michael Stahl <mstahl@redhat.com> |
3 |
Date: Mon, 14 Dec 2015 13:41:57 +0100 |
4 |
Subject: [PATCH 9/9] fix missing BaseURL when loading embedded objects |
5 |
|
6 |
When the object is edited in the UI, the m_xClient is set to a |
7 |
SfxInPlaceClient and the DocumentBaseURL is retrieved from it. But if |
8 |
the object is not edited, it will be loaded during export via the API |
9 |
and without a m_xClient; in this case the DocumentBaseURL must have been |
10 |
set previously to be available during import. |
11 |
|
12 |
There appears to be no way to get the URL of the document via the API |
13 |
while it is being imported; SfxBaseModel's m_sURL is unfortunately only |
14 |
initialized from SfxObjectShell::FinishedLoading(). |
15 |
|
16 |
During ODF import, the SvXMLEmbeddedObjectHelper creates the |
17 |
embedded object, so let's make it pass in the parent's BaseURL. |
18 |
|
19 |
The "DefaultParentBaseURL" parameter already exists but was unused |
20 |
previously. |
21 |
|
22 |
(cherry picked from commit b0fc09daf1086423a9bd457d9a2c043e7ff41451) |
23 |
(cherry picked from commit 4118f8f4c20ae711b95ab3052656bde673aa8852) |
24 |
|
25 |
sw: loading embedded ODF objects requires unordf component |
26 |
|
27 |
(cherry picked from commit b3b7982f4690f4ac0f0e9680970ba544157c36dc) |
28 |
|
29 |
Change-Id: I3d1ed29b3a2c0e77ec606a1d09f7bc07e7860733 |
30 |
Reviewed-on: https://gerrit.libreoffice.org/20761 |
31 |
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> |
32 |
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk> |
33 |
(cherry picked from commit fe4c7f20c272cf7a984d0db79199fe74bd31fc86) |
34 |
--- |
35 |
.../source/container/embeddedobjectcontainer.cxx | 24 ++++++++++++----- |
36 |
include/comphelper/embeddedobjectcontainer.hxx | 6 +++-- |
37 |
include/sfx2/objsh.hxx | 2 ++ |
38 |
reportdesign/inc/ReportDefinition.hxx | 1 + |
39 |
reportdesign/source/core/api/ReportDefinition.cxx | 5 ++++ |
40 |
sfx2/source/doc/objstor.cxx | 6 +++++ |
41 |
svx/source/xml/xmleohlp.cxx | 3 ++- |
42 |
sw/ooxmlexport_setup.mk | 1 + |
43 |
sw/qa/extras/ooxmlexport/ooxmlexport2.cxx | 30 +++++++++++++++++++--- |
44 |
9 files changed, 65 insertions(+), 13 deletions(-) |
45 |
|
46 |
diff --git a/comphelper/source/container/embeddedobjectcontainer.cxx b/comphelper/source/container/embeddedobjectcontainer.cxx |
47 |
index e3696f1..57a63ce 100644 |
48 |
--- a/comphelper/source/container/embeddedobjectcontainer.cxx |
49 |
+++ b/comphelper/source/container/embeddedobjectcontainer.cxx |
50 |
@@ -293,7 +293,9 @@ OUString EmbeddedObjectContainer::GetEmbeddedObjectName( const ::com::sun::star: |
51 |
return OUString(); |
52 |
} |
53 |
|
54 |
-uno::Reference < embed::XEmbeddedObject > EmbeddedObjectContainer::GetEmbeddedObject( const OUString& rName ) |
55 |
+uno::Reference< embed::XEmbeddedObject> |
56 |
+EmbeddedObjectContainer::GetEmbeddedObject( |
57 |
+ const OUString& rName, OUString const*const pBaseURL) |
58 |
{ |
59 |
SAL_WARN_IF( rName.isEmpty(), "comphelper.container", "Empty object name!"); |
60 |
|
61 |
@@ -316,12 +318,15 @@ uno::Reference < embed::XEmbeddedObject > EmbeddedObjectContainer::GetEmbeddedOb |
62 |
if ( aIt != pImpl->maObjectContainer.end() ) |
63 |
xObj = (*aIt).second; |
64 |
else |
65 |
- xObj = Get_Impl( rName, uno::Reference < embed::XEmbeddedObject >() ); |
66 |
+ xObj = Get_Impl(rName, uno::Reference<embed::XEmbeddedObject>(), pBaseURL); |
67 |
|
68 |
return xObj; |
69 |
} |
70 |
|
71 |
-uno::Reference < embed::XEmbeddedObject > EmbeddedObjectContainer::Get_Impl( const OUString& rName, const uno::Reference < embed::XEmbeddedObject >& xCopy ) |
72 |
+uno::Reference<embed::XEmbeddedObject> EmbeddedObjectContainer::Get_Impl( |
73 |
+ const OUString& rName, |
74 |
+ const uno::Reference<embed::XEmbeddedObject>& xCopy, |
75 |
+ rtl::OUString const*const pBaseURL) |
76 |
{ |
77 |
uno::Reference < embed::XEmbeddedObject > xObj; |
78 |
try |
79 |
@@ -341,13 +346,20 @@ uno::Reference < embed::XEmbeddedObject > EmbeddedObjectContainer::Get_Impl( con |
80 |
// object was not added until now - should happen only by calling this method from "inside" |
81 |
//TODO/LATER: it would be good to detect an error when an object should be created already, but isn't (not an "inside" call) |
82 |
uno::Reference < embed::XEmbeddedObjectCreator > xFactory = embed::EmbeddedObjectCreator::create( ::comphelper::getProcessComponentContext() ); |
83 |
- uno::Sequence< beans::PropertyValue > aObjDescr( xCopy.is() ? 2 : 1 ); |
84 |
+ uno::Sequence< beans::PropertyValue > aObjDescr(1 + (xCopy.is() ? 1 : 0) + (pBaseURL ? 1 : 0)); |
85 |
aObjDescr[0].Name = "Parent"; |
86 |
aObjDescr[0].Value <<= pImpl->m_xModel.get(); |
87 |
+ sal_Int32 i = 1; |
88 |
+ if (pBaseURL) |
89 |
+ { |
90 |
+ aObjDescr[i].Name = "DefaultParentBaseURL"; |
91 |
+ aObjDescr[i].Value <<= *pBaseURL; |
92 |
+ ++i; |
93 |
+ } |
94 |
if ( xCopy.is() ) |
95 |
{ |
96 |
- aObjDescr[1].Name = "CloneFrom"; |
97 |
- aObjDescr[1].Value <<= xCopy; |
98 |
+ aObjDescr[i].Name = "CloneFrom"; |
99 |
+ aObjDescr[i].Value <<= xCopy; |
100 |
} |
101 |
|
102 |
uno::Sequence< beans::PropertyValue > aMediaDescr( 1 ); |
103 |
diff --git a/include/comphelper/embeddedobjectcontainer.hxx b/include/comphelper/embeddedobjectcontainer.hxx |
104 |
index 2c8e25f..4848e16 100644 |
105 |
--- a/include/comphelper/embeddedobjectcontainer.hxx |
106 |
+++ b/include/comphelper/embeddedobjectcontainer.hxx |
107 |
@@ -43,6 +43,7 @@ namespace comphelper |
108 |
virtual com::sun::star::uno::Reference < com::sun::star::embed::XStorage > getStorage() const = 0; |
109 |
virtual ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > getInteractionHandler() const = 0; |
110 |
virtual bool isEnableSetModified() const = 0; |
111 |
+ virtual OUString getDocumentBaseURL() const = 0; |
112 |
|
113 |
protected: |
114 |
~IEmbeddedHelper() {} |
115 |
@@ -54,7 +55,8 @@ class COMPHELPER_DLLPUBLIC EmbeddedObjectContainer |
116 |
EmbedImpl* pImpl; |
117 |
|
118 |
::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > Get_Impl( const OUString&, |
119 |
- const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& xCopy); |
120 |
+ const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& xCopy, |
121 |
+ OUString const* pBaseURL = nullptr); |
122 |
|
123 |
public: |
124 |
// add an embedded object to the container storage |
125 |
@@ -92,7 +94,7 @@ public: |
126 |
OUString GetEmbeddedObjectName( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& ); |
127 |
|
128 |
// retrieve an embedded object by name that either has been added already or is available in the container storage |
129 |
- ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > GetEmbeddedObject( const OUString& ); |
130 |
+ ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > GetEmbeddedObject( const OUString&, OUString const* pBaseURL = nullptr ); |
131 |
|
132 |
// create an object from a ClassId |
133 |
::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > |
134 |
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx |
135 |
index d9d4e95..ba1a599 100644 |
136 |
--- a/include/sfx2/objsh.hxx |
137 |
+++ b/include/sfx2/objsh.hxx |
138 |
@@ -557,6 +557,8 @@ public: |
139 |
{ |
140 |
return IsEnableSetModified(); |
141 |
} |
142 |
+ virtual OUString getDocumentBaseURL() const SAL_OVERRIDE; |
143 |
+ |
144 |
comphelper::EmbeddedObjectContainer& GetEmbeddedObjectContainer() const; |
145 |
void ClearEmbeddedObjects(); |
146 |
|
147 |
diff --git a/reportdesign/inc/ReportDefinition.hxx b/reportdesign/inc/ReportDefinition.hxx |
148 |
index c24d9ca..30ce8fb 100644 |
149 |
--- a/reportdesign/inc/ReportDefinition.hxx |
150 |
+++ b/reportdesign/inc/ReportDefinition.hxx |
151 |
@@ -407,6 +407,7 @@ namespace reportdesign |
152 |
virtual ::comphelper::EmbeddedObjectContainer& getEmbeddedObjectContainer() const SAL_OVERRIDE; |
153 |
virtual ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > getInteractionHandler() const SAL_OVERRIDE; |
154 |
virtual bool isEnableSetModified() const SAL_OVERRIDE; |
155 |
+ virtual OUString getDocumentBaseURL() const SAL_OVERRIDE; |
156 |
|
157 |
::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > getContext() const; |
158 |
|
159 |
diff --git a/reportdesign/source/core/api/ReportDefinition.cxx b/reportdesign/source/core/api/ReportDefinition.cxx |
160 |
index b944a97..52fb0e4 100644 |
161 |
--- a/reportdesign/source/core/api/ReportDefinition.cxx |
162 |
+++ b/reportdesign/source/core/api/ReportDefinition.cxx |
163 |
@@ -2569,6 +2569,11 @@ bool OReportDefinition::isEnableSetModified() const |
164 |
return true; |
165 |
} |
166 |
|
167 |
+OUString OReportDefinition::getDocumentBaseURL() const |
168 |
+{ |
169 |
+ return const_cast<OReportDefinition*>(this)->getURL(); |
170 |
+} |
171 |
+ |
172 |
uno::Reference< frame::XTitle > OReportDefinition::impl_getTitleHelper_throw() |
173 |
{ |
174 |
SolarMutexGuard aSolarGuard; |
175 |
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx |
176 |
index 6decd97..cfa5378 100644 |
177 |
--- a/sfx2/source/doc/objstor.cxx |
178 |
+++ b/sfx2/source/doc/objstor.cxx |
179 |
@@ -3647,6 +3647,7 @@ bool SfxObjectShell::QuerySaveSizeExceededModules_Impl( const uno::Reference< ta |
180 |
return true; |
181 |
} |
182 |
|
183 |
+// comphelper::IEmbeddedHelper |
184 |
uno::Reference< task::XInteractionHandler > SfxObjectShell::getInteractionHandler() const |
185 |
{ |
186 |
uno::Reference< task::XInteractionHandler > xRet; |
187 |
@@ -3655,4 +3656,9 @@ uno::Reference< task::XInteractionHandler > SfxObjectShell::getInteractionHandle |
188 |
return xRet; |
189 |
} |
190 |
|
191 |
+OUString SfxObjectShell::getDocumentBaseURL() const |
192 |
+{ |
193 |
+ return GetMedium()->GetBaseURL(); |
194 |
+} |
195 |
+ |
196 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
197 |
diff --git a/svx/source/xml/xmleohlp.cxx b/svx/source/xml/xmleohlp.cxx |
198 |
index f09d951..9668dba 100644 |
199 |
--- a/svx/source/xml/xmleohlp.cxx |
200 |
+++ b/svx/source/xml/xmleohlp.cxx |
201 |
@@ -443,7 +443,8 @@ bool SvXMLEmbeddedObjectHelper::ImplReadObject( |
202 |
// server that was used to create the object. pClassId could be used to specify the server that should |
203 |
// be used for the next opening, but this information seems to be out of the file format responsibility |
204 |
// area. |
205 |
- rContainer.GetEmbeddedObject( aName ); |
206 |
+ OUString const baseURL(mpDocPersist->getDocumentBaseURL()); |
207 |
+ rContainer.GetEmbeddedObject(aName, &baseURL); |
208 |
|
209 |
return true; |
210 |
} |
211 |
diff --git a/sw/ooxmlexport_setup.mk b/sw/ooxmlexport_setup.mk |
212 |
index bd4518d..80a0ea4 100644 |
213 |
--- a/sw/ooxmlexport_setup.mk |
214 |
+++ b/sw/ooxmlexport_setup.mk |
215 |
@@ -65,6 +65,7 @@ define sw_ooxmlexport_components |
216 |
ucb/source/ucp/file/ucpfile1 \ |
217 |
unotools/util/utl \ |
218 |
unoxml/source/service/unoxml \ |
219 |
+ unoxml/source/rdf/unordf \ |
220 |
uui/util/uui \ |
221 |
writerfilter/util/writerfilter \ |
222 |
xmloff/util/xo |
223 |
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx |
224 |
index 8dc4e94..805966d 100644 |
225 |
--- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx |
226 |
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx |
227 |
@@ -479,10 +479,32 @@ DECLARE_OOXMLEXPORT_TEST(testTableBorders, "table-borders.docx") |
228 |
|
229 |
DECLARE_OOXMLEXPORT_TEST(testFdo51550, "fdo51550.odt") |
230 |
{ |
231 |
- // The problem was that we lacked the fallback to export the replacement graphic for OLE objects. |
232 |
- uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); |
233 |
- uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY); |
234 |
- CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount()); |
235 |
+ // The problem was that we lacked the fallback to export the replacement |
236 |
+ // graphic for OLE objects. But we can actually export the OLE itself now, |
237 |
+ // so check that instead. |
238 |
+ uno::Reference<text::XTextEmbeddedObjectsSupplier> xTextEmbeddedObjectsSupplier(mxComponent, uno::UNO_QUERY); |
239 |
+ uno::Reference<container::XIndexAccess> xEmbeddedObjects(xTextEmbeddedObjectsSupplier->getEmbeddedObjects(), uno::UNO_QUERY); |
240 |
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xEmbeddedObjects->getCount()); |
241 |
+ |
242 |
+ xmlDocPtr pXmlDocCT = parseExport("[Content_Types].xml"); |
243 |
+ |
244 |
+ if (!pXmlDocCT) |
245 |
+ return; // initial import |
246 |
+ |
247 |
+ assertXPath(pXmlDocCT, "/ContentType:Types/ContentType:Override[@PartName='/word/embeddings/oleObject1.xlsx']", "ContentType", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
248 |
+ |
249 |
+ // check the rels too |
250 |
+ xmlDocPtr pXmlDocRels = parseExport("word/_rels/document.xml.rels"); |
251 |
+ assertXPath(pXmlDocRels, |
252 |
+ "/rels:Relationships/rels:Relationship[@Target='embeddings/oleObject1.xlsx']", |
253 |
+ "Type", |
254 |
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"); |
255 |
+ // check the content too |
256 |
+ xmlDocPtr pXmlDocContent = parseExport("word/document.xml"); |
257 |
+ assertXPath(pXmlDocContent, |
258 |
+ "/w:document/w:body/w:p/w:r/w:object/o:OLEObject", |
259 |
+ "ProgID", |
260 |
+ "Excel.Sheet.12"); |
261 |
} |
262 |
|
263 |
/* |
264 |
-- |
265 |
2.5.0 |
266 |
|