LibreOffice Module xmloff (master)  1
ximpbody.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include "ximpbody.hxx"
21 #include <xmloff/xmlnamespace.hxx>
22 #include "ximpnote.hxx"
23 #include <com/sun/star/drawing/XDrawPage.hpp>
24 #include <com/sun/star/drawing/XDrawPages.hpp>
25 #include <com/sun/star/container/XNamed.hpp>
26 #include <com/sun/star/presentation/XPresentationPage.hpp>
27 #include "ximpstyl.hxx"
28 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
31 
33 #include <xmloff/families.hxx>
34 #include "ximpshow.hxx"
35 #include "layerimp.hxx"
36 #include <animationimport.hxx>
37 #include <sal/log.hxx>
38 
39 using namespace ::com::sun::star;
40 using namespace ::xmloff::token;
41 
43  const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
44  uno::Reference< drawing::XShapes > const & rShapes)
45 : SdXMLGenericPageContext( rImport, xAttrList, rShapes )
46 , mbHadSMILNodes( false )
47 {
48  bool bHaveXmlId( false );
49  OUString sXmlId, sStyleName, sContextName, sMasterPageName, sHREF;
50 
51  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
52  {
53  OUString sValue = aIter.toString();
54  switch(aIter.getToken())
55  {
56  case XML_ELEMENT(DRAW, XML_NAME):
57  {
58  sContextName = sValue;
59  break;
60  }
62  {
63  sStyleName = sValue;
64  break;
65  }
67  {
68  sMasterPageName = sValue;
69  break;
70  }
72  case XML_ELEMENT(PRESENTATION_SO52, XML_PRESENTATION_PAGE_LAYOUT_NAME):
73  case XML_ELEMENT(PRESENTATION_OOO, XML_PRESENTATION_PAGE_LAYOUT_NAME):
74  {
75  maPageLayoutName = sValue;
76  break;
77  }
78  case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME):
79  case XML_ELEMENT(PRESENTATION_SO52, XML_USE_HEADER_NAME):
80  case XML_ELEMENT(PRESENTATION_OOO, XML_USE_HEADER_NAME):
81  {
82  maUseHeaderDeclName = sValue;
83  break;
84  }
85  case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME):
86  case XML_ELEMENT(PRESENTATION_SO52, XML_USE_FOOTER_NAME):
87  case XML_ELEMENT(PRESENTATION_OOO, XML_USE_FOOTER_NAME):
88  {
89  maUseFooterDeclName = sValue;
90  break;
91  }
92  case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME):
93  case XML_ELEMENT(PRESENTATION_SO52, XML_USE_DATE_TIME_NAME):
94  case XML_ELEMENT(PRESENTATION_OOO, XML_USE_DATE_TIME_NAME):
95  {
96  maUseDateTimeDeclName = sValue;
97  break;
98  }
99  case XML_ELEMENT(DRAW, XML_ID):
100  {
101  if (!bHaveXmlId) { sXmlId = sValue; }
102  }
103  break;
104  case XML_ELEMENT(XML, XML_ID):
105  {
106  sXmlId = sValue;
107  bHaveXmlId = true;
108  }
109  break;
110  case XML_ELEMENT(XLINK, XML_HREF):
111  {
112  sHREF = sValue;
113  break;
114  }
115  }
116  }
117 
118  if (!sXmlId.isEmpty())
119  {
120  uno::Reference< uno::XInterface > const xRef( rShapes.get() );
122  sXmlId, xRef );
123  }
124  GetImport().GetShapeImport()->startPage( rShapes );
125 
126  uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY);
127 
128  // set PageName?
129  if(!sContextName.isEmpty())
130  {
131  if(xShapeDrawPage.is())
132  {
133  uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY);
134  if(xNamed.is())
135  xNamed->setName(sContextName);
136  }
137  }
138 
139  // set MasterPage?
140  if(!sMasterPageName.isEmpty())
141  {
142  // #85906# Code for setting masterpage needs complete rework
143  // since GetSdImport().GetMasterStylesContext() gives always ZERO
144  // because of content/style file split. Now the mechanism is to
145  // compare the wanted masterpage-name with the existing masterpages
146  // which were loaded and created in the styles section loading.
147  uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
148  uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY);
149  uno::Reference< drawing::XDrawPage > xMasterPage;
150 
151  if(xDrawPage.is() && xMasterPages.is())
152  {
153  bool bDone(false);
154  OUString sDisplayName( rImport.GetStyleDisplayName(
155  XmlStyleFamily::MASTER_PAGE, sMasterPageName ) );
156 
157  for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++)
158  {
159  uno::Any aAny(xMasterPages->getByIndex(a));
160  aAny >>= xMasterPage;
161 
162  if(xMasterPage.is())
163  {
164  uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY);
165  if(xMasterNamed.is())
166  {
167  OUString sLoopMasterPageName = xMasterNamed->getName();
168 
169  if(!sLoopMasterPageName.isEmpty() && sLoopMasterPageName == sDisplayName)
170  {
171  xDrawPage->setMasterPage(xMasterPage);
172  bDone = true;
173  }
174  }
175  }
176  }
177 
178  SAL_WARN_IF( !bDone, "xmloff", "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a master slide!" );
179  }
180  }
181 
182  SetStyle( sStyleName );
183 
184  if( !sHREF.isEmpty() )
185  {
186  uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY );
187  if( xProps.is() )
188  {
189  sal_Int32 nIndex = sHREF.lastIndexOf( '#' );
190  if( nIndex != -1 )
191  {
192  OUString aFileName( sHREF.copy( 0, nIndex ) );
193  OUString aBookmarkName( sHREF.copy( nIndex+1 ) );
194 
195  sHREF = GetImport().GetAbsoluteReference( aFileName ) + "#"
196  + aBookmarkName;
197  }
198 
199  xProps->setPropertyValue("BookmarkURL", uno::makeAny( sHREF ) );
200  }
201  }
202 
203  SetLayout();
204 
205  DeleteAllShapes();
206 }
207 
209 {
210 }
211 
212 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawPageContext::createFastChildContext(sal_Int32 nElement,
213  const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList)
214 {
215  // some special objects inside draw:page context
216  switch(nElement)
217  {
218  case XML_ELEMENT(PRESENTATION, XML_NOTES):
219  case XML_ELEMENT(PRESENTATION_SO52, XML_NOTES):
220  case XML_ELEMENT(PRESENTATION_OOO, XML_NOTES):
221  {
222  if( GetSdImport().IsImpress() )
223  {
224  // get notes page
225  uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
226  if(xPresPage.is())
227  {
228  uno::Reference< drawing::XDrawPage > xNotesDrawPage = xPresPage->getNotesPage();
229  if(xNotesDrawPage.is())
230  {
231  // presentation:notes inside draw:page context
232  return new SdXMLNotesContext( GetSdImport(), xAttrList, xNotesDrawPage);
233  }
234  }
235  }
236  break;
237  }
238  case XML_ELEMENT(ANIMATION, XML_PAR):
239  case XML_ELEMENT(ANIMATION_OOO, XML_PAR):
240  case XML_ELEMENT(ANIMATION, XML_SEQ):
241  case XML_ELEMENT(ANIMATION_OOO, XML_SEQ):
242  {
243  if( GetSdImport().IsImpress() )
244  {
245  uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
246  if(xNodeSupplier.is())
247  {
248  mbHadSMILNodes = true;
249  return new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nElement, xAttrList );
250  }
251  }
252  break;
253  }
255  {
256  return new SdXMLLayerSetContext( GetSdImport() );
257  }
258  }
259 
260  // call parent when no own context was created
261  return SdXMLGenericPageContext::createFastChildContext(nElement, xAttrList);
262 }
263 
264 void SdXMLDrawPageContext::endFastElement(sal_Int32 nElement)
265 {
268 
269  if( mbHadSMILNodes )
270  {
271  uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY);
272  uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY );
273  if(xNodeSupplier.is())
274  xmloff::AnimationNodeContext::postProcessRootNode( xNodeSupplier->getAnimationNode(), xPageProps );
275  }
276 }
277 
279 : SvXMLImportContext( rImport )
280 {
281 }
282 
284 {
285 }
286 
287 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLBodyContext::createFastChildContext(
288  sal_Int32 nElement,
289  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
290 {
291  switch (nElement)
292  {
293  case XML_ELEMENT(PRESENTATION, XML_SETTINGS):
294  case XML_ELEMENT(PRESENTATION_SO52, XML_SETTINGS):
295  case XML_ELEMENT(PRESENTATION_OOO, XML_SETTINGS):
296  {
297  return new SdXMLShowsContext( GetSdImport(), xAttrList );
298  }
299  case XML_ELEMENT(DRAW, XML_PAGE):
300  {
301  // only read the first page in preview mode
302  if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() )
303  {
304  // import this page
305  uno::Reference< drawing::XDrawPage > xNewDrawPage;
306  uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY);
307 
308  if( !xDrawPages.is() )
309  break;
310 
311  if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount())
312  {
313  // new page, create and insert
314  xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount());
315  }
316  else
317  {
318  // existing page, use it
319  uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount()));
320  aAny >>= xNewDrawPage;
321  }
322 
323  // increment global import page counter
325 
326  if(xNewDrawPage.is())
327  {
328  // draw:page inside office:body context
329  return new SdXMLDrawPageContext(GetSdImport(), xAttrList, xNewDrawPage);
330  }
331  }
332  break;
333  }
334  case XML_ELEMENT(PRESENTATION, XML_HEADER_DECL):
335  case XML_ELEMENT(PRESENTATION, XML_FOOTER_DECL):
336  case XML_ELEMENT(PRESENTATION, XML_DATE_TIME_DECL):
337  {
338  return new SdXMLHeaderFooterDeclContext( GetImport(), xAttrList );
339  break;
340  }
341  default:
342  SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
343  }
344  return nullptr;
345 }
346 
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SdXMLDrawPageContext(SdXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, css::uno::Reference< css::drawing::XShapes > const &rShapes)
Definition: ximpbody.cxx:42
void SetLayout()
sets the presentation layout at this page.
Definition: ximppage.cxx:452
sal_Int32 nIndex
OUString maUseHeaderDeclName
Definition: ximppage.hxx:38
SdXMLBodyContext(SdXMLImport &rImport)
Definition: ximpbody.cxx:278
const SdXMLImport & GetSdImport() const
Definition: ximpbody.hxx:49
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: ximpbody.cxx:287
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
const SdXMLImport & GetSdImport() const
Definition: ximppage.hxx:52
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: ximppage.cxx:319
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString maUseFooterDeclName
Definition: ximppage.hxx:39
virtual ~SdXMLBodyContext() override
Definition: ximpbody.cxx:283
DRAW
::comphelper::UnoInterfaceToUniqueIdentifierMapper & getInterfaceToIdentifierMapper()
Definition: xmlimp.cxx:1852
virtual ~SdXMLDrawPageContext() override
Definition: ximpbody.cxx:208
static OUString getPrefixAndNameFromToken(sal_Int32 nToken)
Definition: xmlimp.cxx:2000
void DeleteAllShapes()
deletes all shapes on this drawing page
Definition: ximppage.cxx:496
uno_Any a
sal_Int32 GetNewPageCount() const
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: ximpbody.cxx:264
OUString maUseDateTimeDeclName
Definition: ximppage.hxx:40
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
OUString GetAbsoluteReference(const OUString &rValue) const
Definition: xmlimp.cxx:1665
OUString GetStyleDisplayName(XmlStyleFamily nFamily, const OUString &rName) const
Definition: xmlimp.cxx:1469
#define SAL_WARN_IF(condition, area, stream)
Handling of tokens in XML:
const css::uno::Reference< css::drawing::XShapes > & GetLocalShapesContext() const
Definition: ximppage.hxx:75
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:94
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: ximpbody.cxx:212
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
Definition: ximppage.cxx:274
#define SAL_WARN(area, stream)
const OUString & registerReference(const css::uno::Reference< css::uno::XInterface > &rInterface)
returns a unique identifier for the given uno object.
void SetStyle(OUString const &rStyleName)
sets the page style on this page
Definition: ximppage.cxx:395
static void postProcessRootNode(const css::uno::Reference< css::animations::XAnimationNode > &xNode, css::uno::Reference< css::beans::XPropertySet > const &xPageProps)
void IncrementNewPageCount()
rtl::Reference< XMLShapeImportHelper > const & GetShapeImport()
Definition: xmlimp.hxx:600
OUString sDisplayName