1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include "ximpbody.hxx"
27 #include <xmloff/prstylei.hxx>
28 #include "ximpnote.hxx"
29 #include <com/sun/star/drawing/XDrawPage.hpp>
30 #include <com/sun/star/drawing/XDrawPages.hpp>
31 #include <com/sun/star/container/XNamed.hpp>
32 #include <com/sun/star/presentation/XPresentationPage.hpp>
33 #include "ximpstyl.hxx"
34 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
37
38 #include "unointerfacetouniqueidentifiermapper.hxx"
39 #include <xmloff/xmluconv.hxx>
40 #include <xmloff/xmlprmap.hxx>
41 #include <xmloff/families.hxx>
42 #include "ximpshow.hxx"
43 #include "PropertySetMerger.hxx"
44 #include "animationimport.hxx"
45 #include <tools/string.hxx>
46
47 using ::rtl::OUString;
48 using ::rtl::OUStringBuffer;
49
50 using namespace ::com::sun::star;
51
52 //////////////////////////////////////////////////////////////////////////////
53
SdXMLDrawPageContext(SdXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList> & xAttrList,uno::Reference<drawing::XShapes> & rShapes)54 SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport,
55 sal_uInt16 nPrfx, const OUString& rLocalName,
56 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
57 uno::Reference< drawing::XShapes >& rShapes)
58 : SdXMLGenericPageContext( rImport, nPrfx, rLocalName, xAttrList, rShapes )
59 , mbHadSMILNodes( false )
60 {
61 bool bHaveXmlId( false );
62 OUString sXmlId;
63
64 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
65
66 for(sal_Int16 i=0; i < nAttrCount; i++)
67 {
68 OUString sAttrName = xAttrList->getNameByIndex( i );
69 OUString aLocalName;
70 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
71 OUString sValue = xAttrList->getValueByIndex( i );
72 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetDrawPageAttrTokenMap();
73
74 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
75 {
76 case XML_TOK_DRAWPAGE_NAME:
77 {
78 maName = sValue;
79 break;
80 }
81 case XML_TOK_DRAWPAGE_STYLE_NAME:
82 {
83 maStyleName = sValue;
84 break;
85 }
86 case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME:
87 {
88 maMasterPageName = sValue;
89 break;
90 }
91 case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME:
92 {
93 maPageLayoutName = sValue;
94 break;
95 }
96 case XML_TOK_DRAWPAGE_USE_HEADER_NAME:
97 {
98 maUseHeaderDeclName = sValue;
99 break;
100 }
101 case XML_TOK_DRAWPAGE_USE_FOOTER_NAME:
102 {
103 maUseFooterDeclName = sValue;
104 break;
105 }
106 case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME:
107 {
108 maUseDateTimeDeclName = sValue;
109 break;
110 }
111 case XML_TOK_DRAWPAGE_DRAWID:
112 {
113 if (!bHaveXmlId) { sXmlId = sValue; }
114 }
115 break;
116 case XML_TOK_DRAWPAGE_XMLID:
117 {
118 sXmlId = sValue;
119 bHaveXmlId = true;
120 }
121 break;
122 case XML_TOK_DRAWPAGE_HREF:
123 {
124 maHREF = sValue;
125 break;
126 }
127 }
128 }
129
130 if (sXmlId.getLength())
131 {
132 uno::Reference< uno::XInterface > const xRef( rShapes.get() );
133 GetImport().getInterfaceToIdentifierMapper().registerReference(
134 sXmlId, xRef );
135 }
136 GetImport().GetShapeImport()->startPage( rShapes );
137
138 uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
139
140 // set PageName?
141 if(maName.getLength())
142 {
143 if(xShapeDrawPage.is())
144 {
145 uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
146 if(xNamed.is())
147 xNamed->setName(maName);
148 }
149 }
150
151 // set MasterPage?
152 if(maMasterPageName.getLength())
153 {
154 // #85906# Code for setting masterpage needs complete rework
155 // since GetSdImport().GetMasterStylesContext() gives always ZERO
156 // because of content/style file split. Now the nechanism is to
157 // compare the wanted masterpage-name with the existing masterpages
158 // which were loaded and created in the styles section loading.
159 uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
160 uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
161 uno::Reference< drawing::XDrawPage > xMasterPage;
162
163 if(xDrawPage.is() && xMasterPages.is())
164 {
165 sal_Bool bDone(sal_False);
166 OUString sDisplayName( rImport.GetStyleDisplayName(
167 XML_STYLE_FAMILY_MASTER_PAGE, maMasterPageName ) );
168
169 for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
170 {
171 uno::Any aAny(xMasterPages->getByIndex(a));
172 aAny >>= xMasterPage;
173
174 if(xMasterPage.is())
175 {
176 uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
177 if(xMasterNamed.is())
178 {
179 OUString sMasterPageName = xMasterNamed->getName();
180
181 if(sMasterPageName.getLength() &&
182 sMasterPageName.equals(sDisplayName))
183 {
184 xDrawPage->setMasterPage(xMasterPage);
185 bDone = sal_True;
186 }
187 }
188 }
189 }
190
191 DBG_ASSERT( bDone, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" );
192 }
193 }
194
195 SetStyle( maStyleName );
196
197 if( maHREF.getLength() )
198 {
199 uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY );
200 if( xProps.is() )
201 {
202 sal_Int32 nIndex = maHREF.lastIndexOf( (sal_Unicode)'#' );
203 if( nIndex != -1 )
204 {
205 OUString aFileName( maHREF.copy( 0, nIndex ) );
206 OUString aBookmarkName( maHREF.copy( nIndex+1 ) );
207
208 maHREF = GetImport().GetAbsoluteReference( aFileName );
209 maHREF += String( (sal_Unicode)'#' );
210 maHREF += aBookmarkName;
211 }
212
213 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "BookmarkURL" ) ), uno::makeAny( maHREF ) );
214 }
215 }
216
217 SetLayout();
218
219 DeleteAllShapes();
220 }
221
222 //////////////////////////////////////////////////////////////////////////////
223
~SdXMLDrawPageContext()224 SdXMLDrawPageContext::~SdXMLDrawPageContext()
225 {
226 }
227
228 //////////////////////////////////////////////////////////////////////////////
229
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList> & xAttrList)230 SvXMLImportContext *SdXMLDrawPageContext::CreateChildContext( sal_uInt16 nPrefix,
231 const OUString& rLocalName,
232 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
233 {
234 SvXMLImportContext *pContext = 0L;
235 const SvXMLTokenMap& rTokenMap = GetSdImport().GetDrawPageElemTokenMap();
236
237 // some special objects inside draw:page context
238 switch(rTokenMap.Get(nPrefix, rLocalName))
239 {
240 case XML_TOK_DRAWPAGE_NOTES:
241 {
242 if( GetSdImport().IsImpress() )
243 {
244 // get notes page
245 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
246 if(xPresPage.is())
247 {
248 uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
249 if(xNotesDrawPage.is())
250 {
251 uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
252 if(xNewShapes.is())
253 {
254 // presentation:notes inside draw:page context
255 pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
256 }
257 }
258 }
259 }
260 break;
261 }
262 case XML_TOK_DRAWPAGE_PAR:
263 case XML_TOK_DRAWPAGE_SEQ:
264 {
265 if( GetSdImport().IsImpress() )
266 {
267 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
268 if(xNodeSupplier.is())
269 {
270 pContext = new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nPrefix, rLocalName, xAttrList );
271 mbHadSMILNodes = true;
272 }
273 }
274 break;
275 }
276 }
277
278 // call parent when no own context was created
279 if(!pContext)
280 pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
281
282 return pContext;
283 }
284
EndElement()285 void SdXMLDrawPageContext::EndElement()
286 {
287 SdXMLGenericPageContext::EndElement();
288 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
289
290 if( mbHadSMILNodes )
291 {
292 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
293 uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
294 if(xNodeSupplier.is())
295 xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier->getAnimationNode(), xPageProps );
296 }
297 }
298
299 //////////////////////////////////////////////////////////////////////////////
300 //////////////////////////////////////////////////////////////////////////////
301
SdXMLBodyContext(SdXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName)302 SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport,
303 sal_uInt16 nPrfx, const OUString& rLocalName )
304 : SvXMLImportContext( rImport, nPrfx, rLocalName )
305 {
306 }
307
308 //////////////////////////////////////////////////////////////////////////////
309
~SdXMLBodyContext()310 SdXMLBodyContext::~SdXMLBodyContext()
311 {
312 }
313
314 //////////////////////////////////////////////////////////////////////////////
315
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)316 SvXMLImportContext *SdXMLBodyContext::CreateChildContext(
317 sal_uInt16 nPrefix,
318 const OUString& rLocalName,
319 const uno::Reference< xml::sax::XAttributeList>& xAttrList )
320 {
321 SvXMLImportContext *pContext = 0L;
322 const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap();
323
324 switch(rTokenMap.Get(nPrefix, rLocalName))
325 {
326 case XML_TOK_BODY_HEADER_DECL:
327 case XML_TOK_BODY_FOOTER_DECL:
328 case XML_TOK_BODY_DATE_TIME_DECL:
329 {
330 pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList );
331 break;
332 }
333 case XML_TOK_BODY_PAGE:
334 {
335 // only read the first page in preview mode
336 if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
337 {
338 // import this page
339 uno::Reference< drawing::XDrawPage > xNewDrawPage;
340 uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
341
342 if( !xDrawPages.is() )
343 break;
344
345 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
346 {
347 // new page, create and insert
348 xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
349 }
350 else
351 {
352 // existing page, use it
353 uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
354 aAny >>= xNewDrawPage;
355 }
356
357 // increment global import page counter
358 GetSdImport().IncrementNewPageCount();
359
360 if(xNewDrawPage.is())
361 {
362 uno::Reference< drawing::XShapes > xNewShapes(xNewDrawPage, uno::UNO_QUERY);
363 if(xNewShapes.is())
364 {
365 // draw:page inside office:body context
366 pContext = new SdXMLDrawPageContext(GetSdImport(), nPrefix, rLocalName, xAttrList,
367 xNewShapes);
368 }
369 }
370 }
371 break;
372 }
373 case XML_TOK_BODY_SETTINGS:
374 {
375 pContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList );
376 }
377 }
378
379 // call parent when no own context was created
380 if(!pContext)
381 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
382
383 return pContext;
384 }
385