bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / draw / sdxmlimp.cxx
blobe87237ef88d8b75baf2caf7ee64d4503bf1ca209
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <osl/thread.h>
21 #include <comphelper/processfactory.hxx>
23 #include <xmloff/xmlscripti.hxx>
24 #include "facreg.hxx"
25 #include "sdxmlimp_impl.hxx"
26 #include "ximpbody.hxx"
28 #include <xmloff/xmlmetai.hxx>
29 #include "ximpstyl.hxx"
30 #include <xmloff/xmlnmspe.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <xmloff/DocumentSettingsContext.hxx>
34 #include <com/sun/star/form/XFormsSupplier.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
37 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
38 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
39 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
40 #include "sdpropls.hxx"
41 #include <xmloff/xmlexppr.hxx>
42 #include <xmloff/xmlerror.hxx>
43 #include <xmloff/settingsstore.hxx>
44 #include <com/sun/star/style/XStyle.hpp>
46 #include <xmloff/XMLFontStylesContext.hxx>
48 #include <com/sun/star/document/XDocumentProperties.hpp>
49 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
51 using namespace ::com::sun::star;
52 using namespace ::xmloff::token;
54 class SdXMLBodyContext_Impl : public SvXMLImportContext
56 SdXMLImport& GetSdImport() { return static_cast<SdXMLImport&>(GetImport()); }
58 public:
60 SdXMLBodyContext_Impl( SdXMLImport& rImport, sal_uInt16 nPrfx,
61 const OUString& rLName,
62 const uno::Reference< xml::sax::XAttributeList > & xAttrList );
63 virtual ~SdXMLBodyContext_Impl();
65 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
66 const OUString& rLocalName,
67 const uno::Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
70 SdXMLBodyContext_Impl::SdXMLBodyContext_Impl( SdXMLImport& rImport,
71 sal_uInt16 nPrfx, const OUString& rLName,
72 const uno::Reference< xml::sax::XAttributeList > & ) :
73 SvXMLImportContext( rImport, nPrfx, rLName )
77 SdXMLBodyContext_Impl::~SdXMLBodyContext_Impl()
81 SvXMLImportContext *SdXMLBodyContext_Impl::CreateChildContext(
82 sal_uInt16 /*nPrefix*/,
83 const OUString& rLocalName,
84 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
86 return GetSdImport().CreateBodyContext(rLocalName, xAttrList);
89 // NB: virtually inherit so we can multiply inherit properly
90 // in SdXMLFlatDocContext_Impl
91 class SdXMLDocContext_Impl : public virtual SvXMLImportContext
93 protected:
94 SdXMLImport& GetSdImport() { return static_cast<SdXMLImport&>(GetImport()); }
96 public:
97 SdXMLDocContext_Impl(
98 SdXMLImport& rImport,
99 sal_uInt16 nPrfx,
100 const OUString& rLName,
101 const uno::Reference<xml::sax::XAttributeList>& xAttrList);
102 virtual ~SdXMLDocContext_Impl();
104 TYPEINFO_OVERRIDE();
106 virtual SvXMLImportContext *CreateChildContext(sal_uInt16 nPrefix,
107 const OUString& rLocalName,
108 const uno::Reference<xml::sax::XAttributeList>& xAttrList) SAL_OVERRIDE;
111 SdXMLDocContext_Impl::SdXMLDocContext_Impl(
112 SdXMLImport& rImport,
113 sal_uInt16 nPrfx,
114 const OUString& rLName,
115 const uno::Reference<xml::sax::XAttributeList>&)
116 : SvXMLImportContext(rImport, nPrfx, rLName)
120 SdXMLDocContext_Impl::~SdXMLDocContext_Impl()
124 TYPEINIT1( SdXMLDocContext_Impl, SvXMLImportContext );
126 SvXMLImportContext *SdXMLDocContext_Impl::CreateChildContext(
127 sal_uInt16 nPrefix,
128 const OUString& rLocalName,
129 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
131 SvXMLImportContext* pContext = 0L;
133 const SvXMLTokenMap& rTokenMap = GetSdImport().GetDocElemTokenMap();
134 switch(rTokenMap.Get(nPrefix, rLocalName))
136 case XML_TOK_DOC_FONTDECLS:
138 pContext = GetSdImport().CreateFontDeclsContext( rLocalName, xAttrList );
139 break;
141 case XML_TOK_DOC_SETTINGS:
143 if( GetImport().getImportFlags() & SvXMLImportFlags::SETTINGS )
145 pContext = new XMLDocumentSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList );
147 break;
149 case XML_TOK_DOC_STYLES:
151 if( GetImport().getImportFlags() & SvXMLImportFlags::STYLES )
153 // office:styles inside office:document
154 pContext = GetSdImport().CreateStylesContext(rLocalName, xAttrList);
156 break;
158 case XML_TOK_DOC_AUTOSTYLES:
160 if( GetImport().getImportFlags() & SvXMLImportFlags::AUTOSTYLES )
162 // office:automatic-styles inside office:document
163 pContext = GetSdImport().CreateAutoStylesContext(rLocalName, xAttrList);
165 break;
167 case XML_TOK_DOC_MASTERSTYLES:
169 if( GetImport().getImportFlags() & SvXMLImportFlags::MASTERSTYLES )
171 // office:master-styles inside office:document
172 pContext = GetSdImport().CreateMasterStylesContext(rLocalName, xAttrList);
174 break;
176 case XML_TOK_DOC_META:
178 SAL_INFO("xmloff.draw", "XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
179 break;
181 case XML_TOK_DOC_SCRIPT:
183 if( GetImport().getImportFlags() & SvXMLImportFlags::SCRIPTS )
185 // office:script inside office:document
186 pContext = GetSdImport().CreateScriptContext( rLocalName );
188 break;
190 case XML_TOK_DOC_BODY:
192 if( GetImport().getImportFlags() & SvXMLImportFlags::CONTENT )
194 // office:body inside office:document
195 pContext = new SdXMLBodyContext_Impl(GetSdImport(),nPrefix,
196 rLocalName, xAttrList);
198 break;
202 // call parent when no own context was created
203 if(!pContext)
204 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
206 return pContext;
209 // context for flat file xml format
210 class SdXMLFlatDocContext_Impl
211 : public SdXMLDocContext_Impl, public SvXMLMetaDocumentContext
213 public:
214 SdXMLFlatDocContext_Impl( SdXMLImport& i_rImport,
215 sal_uInt16 i_nPrefix, const OUString & i_rLName,
216 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList,
217 const uno::Reference<document::XDocumentProperties>& i_xDocProps);
219 virtual ~SdXMLFlatDocContext_Impl();
221 virtual SvXMLImportContext *CreateChildContext(
222 sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
223 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList) SAL_OVERRIDE;
226 SdXMLFlatDocContext_Impl::SdXMLFlatDocContext_Impl( SdXMLImport& i_rImport,
227 sal_uInt16 i_nPrefix, const OUString & i_rLName,
228 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList,
229 const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
230 SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
231 SdXMLDocContext_Impl(i_rImport, i_nPrefix, i_rLName, i_xAttrList),
232 SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
233 i_xDocProps)
237 SdXMLFlatDocContext_Impl::~SdXMLFlatDocContext_Impl() { }
239 SvXMLImportContext *SdXMLFlatDocContext_Impl::CreateChildContext(
240 sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
241 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
243 // behave like meta base class iff we encounter office:meta
244 const SvXMLTokenMap& rTokenMap = GetSdImport().GetDocElemTokenMap();
245 if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) {
246 return SvXMLMetaDocumentContext::CreateChildContext(
247 i_nPrefix, i_rLocalName, i_xAttrList );
248 } else {
249 return SdXMLDocContext_Impl::CreateChildContext(
250 i_nPrefix, i_rLocalName, i_xAttrList );
254 #define SERVICE(classname,servicename,implementationname,draw,flags)\
255 uno::Sequence< OUString > SAL_CALL classname##_getSupportedServiceNames() throw()\
257 const OUString aServiceName( servicename );\
258 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );\
259 return aSeq;\
261 OUString SAL_CALL classname##_getImplementationName() throw()\
263 return OUString( implementationname );\
265 uno::Reference< uno::XInterface > SAL_CALL classname##_createInstance(const uno::Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )\
267 return (cppu::OWeakObject*)new SdXMLImport( comphelper::getComponentContext(rSMgr), implementationname, draw, flags ); \
270 SERVICE( XMLImpressImportOasis, "com.sun.star.comp.Impress.XMLOasisImporter", "XMLImpressImportOasis", false, SvXMLImportFlags::ALL )
271 SERVICE( XMLDrawImportOasis, "com.sun.star.comp.Draw.XMLOasisImporter", "XMLDrawImportOasis", true, SvXMLImportFlags::ALL )
273 SERVICE( XMLImpressStylesImportOasis, "com.sun.star.comp.Impress.XMLOasisStylesImporter", "XMLImpressStylesImportOasis", false, SvXMLImportFlags::STYLES|SvXMLImportFlags::AUTOSTYLES|SvXMLImportFlags::MASTERSTYLES )
274 SERVICE( XMLDrawStylesImportOasis, "com.sun.star.comp.Draw.XMLOasisStylesImporter", "XMLImpressStylesImportOasis", true, SvXMLImportFlags::STYLES|SvXMLImportFlags::AUTOSTYLES|SvXMLImportFlags::MASTERSTYLES )
276 SERVICE( XMLImpressContentImportOasis, "com.sun.star.comp.Impress.XMLOasisContentImporter", "XMLImpressContentImportOasis", false, SvXMLImportFlags::AUTOSTYLES|SvXMLImportFlags::CONTENT|SvXMLImportFlags::SCRIPTS|SvXMLImportFlags::FONTDECLS )
277 SERVICE( XMLDrawContentImportOasis, "com.sun.star.comp.Draw.XMLOasisContentImporter", "XMLImpressContentImportOasis", true, SvXMLImportFlags::AUTOSTYLES|SvXMLImportFlags::CONTENT|SvXMLImportFlags::SCRIPTS|SvXMLImportFlags::FONTDECLS )
279 SERVICE( XMLImpressMetaImportOasis, "com.sun.star.comp.Impress.XMLOasisMetaImporter", "XMLImpressMetaImportOasis", false, SvXMLImportFlags::META )
280 SERVICE( XMLDrawMetaImportOasis, "com.sun.star.comp.Draw.XMLOasisMetaImporter", "XMLImpressMetaImportOasis", true, SvXMLImportFlags::META )
282 SERVICE( XMLImpressSettingsImportOasis, "com.sun.star.comp.Impress.XMLOasisSettingsImporter", "XMLImpressSettingsImportOasis", false, SvXMLImportFlags::SETTINGS )
283 SERVICE( XMLDrawSettingsImportOasis, "com.sun.star.comp.Draw.XMLOasisSettingsImporter", "XMLImpressSettingsImportOasis", true, SvXMLImportFlags::SETTINGS )
285 // #110680#
286 SdXMLImport::SdXMLImport(
287 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,
288 OUString const & implementationName,
289 bool bIsDraw, SvXMLImportFlags nImportFlags )
290 : SvXMLImport( xContext, implementationName, nImportFlags ),
291 mpMasterStylesContext(0L),
292 mpDocElemTokenMap(0L),
293 mpBodyElemTokenMap(0L),
294 mpStylesElemTokenMap(0L),
295 mpMasterPageElemTokenMap(0L),
296 mpMasterPageAttrTokenMap(0L),
297 mpPageMasterAttrTokenMap(0L),
298 mpPageMasterStyleAttrTokenMap(0L),
299 mpDrawPageAttrTokenMap(0L),
300 mpDrawPageElemTokenMap(0L),
301 mpPresentationPlaceholderAttrTokenMap(0L),
302 mnStyleFamilyMask(0),
303 mnNewPageCount(0L),
304 mnNewMasterPageCount(0L),
305 mbIsDraw(bIsDraw),
306 mbLoadDoc(true),
307 mbPreview(false),
308 msPageLayouts( "PageLayouts" ),
309 msPreview( "Preview" )
311 // add namespaces
312 GetNamespaceMap().Add(
313 GetXMLToken(XML_NP_PRESENTATION),
314 GetXMLToken(XML_N_PRESENTATION),
315 XML_NAMESPACE_PRESENTATION);
317 GetNamespaceMap().Add(
318 GetXMLToken(XML_NP_SMIL),
319 GetXMLToken(XML_N_SMIL_COMPAT),
320 XML_NAMESPACE_SMIL);
322 GetNamespaceMap().Add(
323 GetXMLToken(XML_NP_ANIMATION),
324 GetXMLToken(XML_N_ANIMATION),
325 XML_NAMESPACE_ANIMATION);
328 // XImporter
329 void SAL_CALL SdXMLImport::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
330 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
332 SvXMLImport::setTargetDocument( xDoc );
334 uno::Reference< lang::XServiceInfo > xDocServices( GetModel(), uno::UNO_QUERY );
335 if( !xDocServices.is() )
336 throw lang::IllegalArgumentException();
338 mbIsDraw = !xDocServices->supportsService("com.sun.star.presentation.PresentationDocument");
340 // prepare access to styles
341 uno::Reference< style::XStyleFamiliesSupplier > xFamSup( GetModel(), uno::UNO_QUERY );
342 if(xFamSup.is())
343 mxDocStyleFamilies = xFamSup->getStyleFamilies();
345 // prepare access to master pages
346 uno::Reference < drawing::XMasterPagesSupplier > xMasterPagesSupplier(GetModel(), uno::UNO_QUERY);
347 if(xMasterPagesSupplier.is())
348 mxDocMasterPages.set(xMasterPagesSupplier->getMasterPages(), css::uno::UNO_QUERY);
350 // prepare access to draw pages
351 uno::Reference <drawing::XDrawPagesSupplier> xDrawPagesSupplier(GetModel(), uno::UNO_QUERY);
352 if(!xDrawPagesSupplier.is())
353 throw lang::IllegalArgumentException();
355 mxDocDrawPages.set(xDrawPagesSupplier->getDrawPages(), css::uno::UNO_QUERY);
356 if(!mxDocDrawPages.is())
357 throw lang::IllegalArgumentException();
359 if( mxDocDrawPages.is() && mxDocDrawPages->getCount() > 0 )
361 uno::Reference< form::XFormsSupplier > xFormsSupp;
362 mxDocDrawPages->getByIndex(0) >>= xFormsSupp;
363 mbIsFormsSupported = xFormsSupp.is();
366 // #88546# enable progress bar increments, SdXMLImport is only used for
367 // draw/impress import
368 GetShapeImport()->enableHandleProgressBar();
370 uno::Reference< lang::XMultiServiceFactory > xFac( GetModel(), uno::UNO_QUERY );
371 if( xFac.is() )
373 uno::Sequence< OUString > sSNS( xFac->getAvailableServiceNames() );
374 sal_Int32 n = sSNS.getLength();
375 const OUString* pSNS( sSNS.getConstArray() );
376 while( --n > 0 )
378 if( (*pSNS++) == "com.sun.star.drawing.TableShape" )
380 mbIsTableShapeSupported = true;
381 break;
387 // XInitialization
388 void SAL_CALL SdXMLImport::initialize( const uno::Sequence< uno::Any >& aArguments )
389 throw( uno::Exception, uno::RuntimeException, std::exception)
391 SvXMLImport::initialize( aArguments );
393 uno::Reference< beans::XPropertySet > xInfoSet( getImportInfo() );
394 if( xInfoSet.is() )
396 uno::Reference< beans::XPropertySetInfo > xInfoSetInfo( xInfoSet->getPropertySetInfo() );
398 if( xInfoSetInfo->hasPropertyByName( msPageLayouts ) )
399 xInfoSet->getPropertyValue( msPageLayouts ) >>= mxPageLayouts;
401 if( xInfoSetInfo->hasPropertyByName( msPreview ) )
402 xInfoSet->getPropertyValue( msPreview ) >>= mbPreview;
404 OUString const sOrganizerMode(
405 "OrganizerMode");
406 if (xInfoSetInfo->hasPropertyByName(sOrganizerMode))
408 bool bStyleOnly(false);
409 if (xInfoSet->getPropertyValue(sOrganizerMode) >>= bStyleOnly)
411 mbLoadDoc = !bStyleOnly;
417 SdXMLImport::~SdXMLImport() throw ()
419 // Styles or AutoStyles context?
420 if(mpMasterStylesContext)
421 mpMasterStylesContext->ReleaseRef();
423 // delete all token maps
424 if(mpDocElemTokenMap)
425 delete mpDocElemTokenMap;
426 if(mpBodyElemTokenMap)
427 delete mpBodyElemTokenMap;
428 if(mpStylesElemTokenMap)
429 delete mpStylesElemTokenMap;
430 if(mpMasterPageElemTokenMap)
431 delete mpMasterPageElemTokenMap;
432 if(mpMasterPageAttrTokenMap)
433 delete mpMasterPageAttrTokenMap;
434 if(mpPageMasterAttrTokenMap)
435 delete mpPageMasterAttrTokenMap;
436 if(mpPageMasterStyleAttrTokenMap)
437 delete mpPageMasterStyleAttrTokenMap;
438 if(mpDrawPageAttrTokenMap)
439 delete mpDrawPageAttrTokenMap;
440 if(mpDrawPageElemTokenMap)
441 delete mpDrawPageElemTokenMap;
442 if(mpPresentationPlaceholderAttrTokenMap)
443 delete mpPresentationPlaceholderAttrTokenMap;
446 const SvXMLTokenMap& SdXMLImport::GetDocElemTokenMap()
448 if(!mpDocElemTokenMap)
450 static const SvXMLTokenMapEntry aDocElemTokenMap[] =
452 { XML_NAMESPACE_OFFICE, XML_FONT_FACE_DECLS, XML_TOK_DOC_FONTDECLS },
453 { XML_NAMESPACE_OFFICE, XML_STYLES, XML_TOK_DOC_STYLES },
454 { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES },
455 { XML_NAMESPACE_OFFICE, XML_MASTER_STYLES, XML_TOK_DOC_MASTERSTYLES },
456 { XML_NAMESPACE_OFFICE, XML_META, XML_TOK_DOC_META },
457 { XML_NAMESPACE_OFFICE, XML_SCRIPTS, XML_TOK_DOC_SCRIPT },
458 { XML_NAMESPACE_OFFICE, XML_BODY, XML_TOK_DOC_BODY },
459 { XML_NAMESPACE_OFFICE, XML_SETTINGS, XML_TOK_DOC_SETTINGS },
460 XML_TOKEN_MAP_END
463 mpDocElemTokenMap = new SvXMLTokenMap(aDocElemTokenMap);
464 } // if(!mpDocElemTokenMap)
466 return *mpDocElemTokenMap;
469 const SvXMLTokenMap& SdXMLImport::GetBodyElemTokenMap()
471 if(!mpBodyElemTokenMap)
473 static const SvXMLTokenMapEntry aBodyElemTokenMap[] =
475 { XML_NAMESPACE_DRAW, XML_PAGE, XML_TOK_BODY_PAGE },
476 { XML_NAMESPACE_PRESENTATION, XML_SETTINGS, XML_TOK_BODY_SETTINGS },
477 { XML_NAMESPACE_PRESENTATION, XML_HEADER_DECL, XML_TOK_BODY_HEADER_DECL },
478 { XML_NAMESPACE_PRESENTATION, XML_FOOTER_DECL, XML_TOK_BODY_FOOTER_DECL },
479 { XML_NAMESPACE_PRESENTATION, XML_DATE_TIME_DECL,XML_TOK_BODY_DATE_TIME_DECL },
481 XML_TOKEN_MAP_END
484 mpBodyElemTokenMap = new SvXMLTokenMap(aBodyElemTokenMap);
485 } // if(!mpBodyElemTokenMap)
487 return *mpBodyElemTokenMap;
490 const SvXMLTokenMap& SdXMLImport::GetStylesElemTokenMap()
492 if(!mpStylesElemTokenMap)
494 static const SvXMLTokenMapEntry aStylesElemTokenMap[] =
496 { XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT, XML_TOK_STYLES_PAGE_MASTER },
497 { XML_NAMESPACE_STYLE, XML_PRESENTATION_PAGE_LAYOUT, XML_TOK_STYLES_PRESENTATION_PAGE_LAYOUT },
498 { XML_NAMESPACE_STYLE, XML_STYLE, XML_TOK_STYLES_STYLE },
499 XML_TOKEN_MAP_END
502 mpStylesElemTokenMap = new SvXMLTokenMap(aStylesElemTokenMap);
503 } // if(!mpStylesElemTokenMap)
505 return *mpStylesElemTokenMap;
508 const SvXMLTokenMap& SdXMLImport::GetMasterPageElemTokenMap()
510 if(!mpMasterPageElemTokenMap)
512 static const SvXMLTokenMapEntry aMasterPageElemTokenMap[] =
514 { XML_NAMESPACE_STYLE, XML_STYLE, XML_TOK_MASTERPAGE_STYLE },
515 { XML_NAMESPACE_PRESENTATION, XML_NOTES, XML_TOK_MASTERPAGE_NOTES },
516 XML_TOKEN_MAP_END
519 mpMasterPageElemTokenMap = new SvXMLTokenMap(aMasterPageElemTokenMap);
520 } // if(!mpMasterPageElemTokenMap)
522 return *mpMasterPageElemTokenMap;
525 const SvXMLTokenMap& SdXMLImport::GetMasterPageAttrTokenMap()
527 if(!mpMasterPageAttrTokenMap)
529 static const SvXMLTokenMapEntry aMasterPageAttrTokenMap[] =
531 { XML_NAMESPACE_STYLE, XML_NAME, XML_TOK_MASTERPAGE_NAME },
532 { XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, XML_TOK_MASTERPAGE_DISPLAY_NAME },
533 { XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, XML_TOK_MASTERPAGE_PAGE_MASTER_NAME },
534 { XML_NAMESPACE_DRAW, XML_STYLE_NAME, XML_TOK_MASTERPAGE_STYLE_NAME },
535 { XML_NAMESPACE_PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME, XML_TOK_MASTERPAGE_PAGE_LAYOUT_NAME },
536 { XML_NAMESPACE_PRESENTATION, XML_USE_HEADER_NAME, XML_TOK_MASTERPAGE_USE_HEADER_NAME },
537 { XML_NAMESPACE_PRESENTATION, XML_USE_FOOTER_NAME, XML_TOK_MASTERPAGE_USE_FOOTER_NAME },
538 { XML_NAMESPACE_PRESENTATION, XML_USE_DATE_TIME_NAME, XML_TOK_MASTERPAGE_USE_DATE_TIME_NAME },
539 XML_TOKEN_MAP_END
542 mpMasterPageAttrTokenMap = new SvXMLTokenMap(aMasterPageAttrTokenMap);
543 } // if(!mpMasterPageAttrTokenMap)
545 return *mpMasterPageAttrTokenMap;
548 const SvXMLTokenMap& SdXMLImport::GetPageMasterAttrTokenMap()
550 if(!mpPageMasterAttrTokenMap)
552 static const SvXMLTokenMapEntry aPageMasterAttrTokenMap[] =
554 { XML_NAMESPACE_STYLE, XML_NAME, XML_TOK_PAGEMASTER_NAME },
555 XML_TOKEN_MAP_END
558 mpPageMasterAttrTokenMap = new SvXMLTokenMap(aPageMasterAttrTokenMap);
559 } // if(!mpPageMasterAttrTokenMap)
561 return *mpPageMasterAttrTokenMap;
564 const SvXMLTokenMap& SdXMLImport::GetPageMasterStyleAttrTokenMap()
566 if(!mpPageMasterStyleAttrTokenMap)
568 static const SvXMLTokenMapEntry aPageMasterStyleAttrTokenMap[] =
570 { XML_NAMESPACE_FO, XML_MARGIN_TOP, XML_TOK_PAGEMASTERSTYLE_MARGIN_TOP },
571 { XML_NAMESPACE_FO, XML_MARGIN_BOTTOM, XML_TOK_PAGEMASTERSTYLE_MARGIN_BOTTOM },
572 { XML_NAMESPACE_FO, XML_MARGIN_LEFT, XML_TOK_PAGEMASTERSTYLE_MARGIN_LEFT },
573 { XML_NAMESPACE_FO, XML_MARGIN_RIGHT, XML_TOK_PAGEMASTERSTYLE_MARGIN_RIGHT },
574 { XML_NAMESPACE_FO, XML_PAGE_WIDTH, XML_TOK_PAGEMASTERSTYLE_PAGE_WIDTH },
575 { XML_NAMESPACE_FO, XML_PAGE_HEIGHT, XML_TOK_PAGEMASTERSTYLE_PAGE_HEIGHT },
576 { XML_NAMESPACE_STYLE, XML_PRINT_ORIENTATION, XML_TOK_PAGEMASTERSTYLE_PAGE_ORIENTATION },
577 XML_TOKEN_MAP_END
580 mpPageMasterStyleAttrTokenMap = new SvXMLTokenMap(aPageMasterStyleAttrTokenMap);
581 } // if(!mpPageMasterStyleAttrTokenMap)
583 return *mpPageMasterStyleAttrTokenMap;
586 const SvXMLTokenMap& SdXMLImport::GetDrawPageAttrTokenMap()
588 if(!mpDrawPageAttrTokenMap)
590 static const SvXMLTokenMapEntry aDrawPageAttrTokenMap[] =
592 { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_DRAWPAGE_NAME },
593 { XML_NAMESPACE_DRAW, XML_STYLE_NAME, XML_TOK_DRAWPAGE_STYLE_NAME },
594 { XML_NAMESPACE_DRAW, XML_MASTER_PAGE_NAME, XML_TOK_DRAWPAGE_MASTER_PAGE_NAME },
595 { XML_NAMESPACE_PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME, XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME },
596 { XML_NAMESPACE_DRAW, XML_ID, XML_TOK_DRAWPAGE_DRAWID },
597 { XML_NAMESPACE_XML, XML_ID, XML_TOK_DRAWPAGE_XMLID },
598 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_DRAWPAGE_HREF },
599 { XML_NAMESPACE_PRESENTATION, XML_USE_HEADER_NAME, XML_TOK_DRAWPAGE_USE_HEADER_NAME },
600 { XML_NAMESPACE_PRESENTATION, XML_USE_FOOTER_NAME, XML_TOK_DRAWPAGE_USE_FOOTER_NAME },
601 { XML_NAMESPACE_PRESENTATION, XML_USE_DATE_TIME_NAME, XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME },
603 XML_TOKEN_MAP_END
606 mpDrawPageAttrTokenMap = new SvXMLTokenMap(aDrawPageAttrTokenMap);
607 } // if(!mpDrawPageAttrTokenMap)
609 return *mpDrawPageAttrTokenMap;
612 const SvXMLTokenMap& SdXMLImport::GetDrawPageElemTokenMap()
614 if(!mpDrawPageElemTokenMap)
616 static const SvXMLTokenMapEntry aDrawPageElemTokenMap[] =
618 { XML_NAMESPACE_PRESENTATION, XML_NOTES, XML_TOK_DRAWPAGE_NOTES },
619 { XML_NAMESPACE_ANIMATION, XML_PAR, XML_TOK_DRAWPAGE_PAR },
620 { XML_NAMESPACE_ANIMATION, XML_SEQ, XML_TOK_DRAWPAGE_SEQ },
621 XML_TOKEN_MAP_END
624 mpDrawPageElemTokenMap = new SvXMLTokenMap(aDrawPageElemTokenMap);
625 } // if(!mpDrawPageElemTokenMap)
627 return *mpDrawPageElemTokenMap;
630 const SvXMLTokenMap& SdXMLImport::GetPresentationPlaceholderAttrTokenMap()
632 if(!mpPresentationPlaceholderAttrTokenMap)
634 static const SvXMLTokenMapEntry aPresentationPlaceholderAttrTokenMap[] =
636 { XML_NAMESPACE_PRESENTATION, XML_OBJECT, XML_TOK_PRESENTATIONPLACEHOLDER_OBJECTNAME },
637 { XML_NAMESPACE_SVG, XML_X, XML_TOK_PRESENTATIONPLACEHOLDER_X },
638 { XML_NAMESPACE_SVG, XML_Y, XML_TOK_PRESENTATIONPLACEHOLDER_Y },
639 { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_PRESENTATIONPLACEHOLDER_WIDTH },
640 { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_PRESENTATIONPLACEHOLDER_HEIGHT },
641 XML_TOKEN_MAP_END
644 mpPresentationPlaceholderAttrTokenMap = new SvXMLTokenMap(aPresentationPlaceholderAttrTokenMap);
645 } // if(!mpPresentationPlaceholderAttrTokenMap)
647 return *mpPresentationPlaceholderAttrTokenMap;
650 SvXMLImportContext *SdXMLImport::CreateContext(sal_uInt16 nPrefix,
651 const OUString& rLocalName,
652 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
654 SvXMLImportContext* pContext = 0;
656 if(XML_NAMESPACE_OFFICE == nPrefix &&
657 ( IsXMLToken( rLocalName, XML_DOCUMENT_STYLES ) ||
658 IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) ||
659 IsXMLToken( rLocalName, XML_DOCUMENT_SETTINGS ) ))
661 pContext = new SdXMLDocContext_Impl(*this, nPrefix, rLocalName, xAttrList);
662 } else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
663 ( IsXMLToken(rLocalName, XML_DOCUMENT_META)) ) {
664 pContext = CreateMetaContext(rLocalName, xAttrList);
665 } else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
666 ( IsXMLToken(rLocalName, XML_DOCUMENT)) ) {
667 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
668 GetModel(), uno::UNO_QUERY_THROW);
669 // flat OpenDocument file format
670 pContext = new SdXMLFlatDocContext_Impl( *this, nPrefix, rLocalName,
671 xAttrList, xDPS->getDocumentProperties());
672 } else {
673 pContext = SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
676 return pContext;
679 SvXMLImportContext *SdXMLImport::CreateMetaContext(const OUString& rLocalName,
680 const uno::Reference<xml::sax::XAttributeList>&)
682 SvXMLImportContext* pContext = 0L;
684 if (getImportFlags() & SvXMLImportFlags::META)
686 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
687 GetModel(), uno::UNO_QUERY_THROW);
688 uno::Reference<document::XDocumentProperties> const xDocProps(
689 (IsStylesOnlyMode()) ? 0 : xDPS->getDocumentProperties());
690 pContext = new SvXMLMetaDocumentContext(*this,
691 XML_NAMESPACE_OFFICE, rLocalName,
692 xDocProps);
695 if(!pContext)
697 pContext = new SvXMLImportContext(*this, XML_NAMESPACE_OFFICE, rLocalName);
700 return pContext;
703 SvXMLImportContext *SdXMLImport::CreateBodyContext(const OUString& rLocalName,
704 const uno::Reference<xml::sax::XAttributeList>&)
706 SvXMLImportContext *pContext = 0;
707 pContext = new SdXMLBodyContext(*this, XML_NAMESPACE_OFFICE, rLocalName);
708 return pContext;
711 SvXMLStylesContext *SdXMLImport::CreateStylesContext(const OUString& rLocalName,
712 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
714 if(GetShapeImport()->GetStylesContext())
715 return GetShapeImport()->GetStylesContext();
717 GetShapeImport()->SetStylesContext(new SdXMLStylesContext(
718 *this, XML_NAMESPACE_OFFICE, rLocalName, xAttrList, false));
720 return GetShapeImport()->GetStylesContext();
723 SvXMLStylesContext *SdXMLImport::CreateAutoStylesContext(const OUString& rLocalName,
724 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
726 if(GetShapeImport()->GetAutoStylesContext())
727 return GetShapeImport()->GetAutoStylesContext();
729 GetShapeImport()->SetAutoStylesContext(new SdXMLStylesContext(
730 *this, XML_NAMESPACE_OFFICE, rLocalName, xAttrList, true));
732 return GetShapeImport()->GetAutoStylesContext();
735 SvXMLImportContext* SdXMLImport::CreateMasterStylesContext(const OUString& rLocalName,
736 const uno::Reference<xml::sax::XAttributeList>&)
738 if(mpMasterStylesContext)
739 return mpMasterStylesContext;
741 mpMasterStylesContext = new SdXMLMasterStylesContext(
742 *this, XML_NAMESPACE_OFFICE, rLocalName);
743 mpMasterStylesContext->AddFirstRef();
745 return mpMasterStylesContext;
748 SvXMLImportContext *SdXMLImport::CreateFontDeclsContext(const OUString& rLocalName,
749 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
751 XMLFontStylesContext *pFSContext =
752 new XMLFontStylesContext( *this, XML_NAMESPACE_OFFICE,
753 rLocalName, xAttrList,
754 osl_getThreadTextEncoding() );
755 SetFontDecls( pFSContext );
756 return pFSContext;
759 SvXMLImportContext *SdXMLImport::CreateScriptContext(
760 const OUString& rLocalName )
762 SvXMLImportContext *pContext = 0;
764 pContext = new XMLScriptContext( *this,
765 XML_NAMESPACE_OFFICE, rLocalName,
766 GetModel() );
767 return pContext;
770 void SdXMLImport::SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aViewProps)
772 uno::Reference< beans::XPropertySet > xPropSet( GetModel(), uno::UNO_QUERY );
773 if( !xPropSet.is() )
774 return;
776 awt::Rectangle aVisArea( 0,0, 28000, 21000 );
777 sal_Int32 nCount = aViewProps.getLength();
779 const beans::PropertyValue* pValues = aViewProps.getConstArray();
781 while( nCount-- )
783 const OUString& rName = pValues->Name;
784 const uno::Any rValue = pValues->Value;
786 if ( rName == "VisibleAreaTop" )
788 rValue >>= aVisArea.Y;
790 else if ( rName == "VisibleAreaLeft" )
792 rValue >>= aVisArea.X;
794 else if ( rName == "VisibleAreaWidth" )
796 rValue >>= aVisArea.Width;
798 else if ( rName == "VisibleAreaHeight" )
800 rValue >>= aVisArea.Height;
803 pValues++;
808 xPropSet->setPropertyValue("VisibleArea", uno::makeAny( aVisArea ) );
810 catch(const com::sun::star::uno::Exception&)
812 /* #i79978# since old documents may contain invalid view settings, this is nothing to worry the user about.
813 uno::Sequence<OUString> aSeq(0);
814 SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, aSeq, e.Message, NULL );
819 void SdXMLImport::SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aConfigProps)
821 uno::Reference< lang::XMultiServiceFactory > xFac( GetModel(), uno::UNO_QUERY );
822 if( !xFac.is() )
823 return;
825 uno::Reference< beans::XPropertySet > xProps( xFac->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY );
826 if( !xProps.is() )
827 return;
829 uno::Reference< beans::XPropertySetInfo > xInfo( xProps->getPropertySetInfo() );
830 if( !xInfo.is() )
831 return;
833 sal_Int32 nCount = aConfigProps.getLength();
834 const beans::PropertyValue* pValues = aConfigProps.getConstArray();
836 DocumentSettingsSerializer *pFilter;
837 pFilter = dynamic_cast<DocumentSettingsSerializer *>(xProps.get());
838 uno::Sequence<beans::PropertyValue> aFiltered;
839 if( pFilter )
841 aFiltered = pFilter->filterStreamsFromStorage( GetDocumentBase(), GetSourceStorage(), aConfigProps );
842 nCount = aFiltered.getLength();
843 pValues = aFiltered.getConstArray();
846 while( nCount-- )
850 const OUString& rProperty = pValues->Name;
851 if( xInfo->hasPropertyByName( rProperty ) )
852 xProps->setPropertyValue( rProperty, pValues->Value );
854 catch(const uno::Exception&)
856 SAL_INFO("xmloff.draw", "#SdXMLImport::SetConfigurationSettings: Exception!" );
859 pValues++;
863 // #80365# override this method to read and use the hint value from the
864 // written meta information. If no info is found, guess 10 draw objects
865 //void SdXMLImport::SetStatisticAttributes(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
866 void SdXMLImport::SetStatistics(
867 const uno::Sequence<beans::NamedValue> & i_rStats)
869 static const char* s_stats[] =
870 { "ObjectCount", 0 };
872 SvXMLImport::SetStatistics(i_rStats);
874 sal_uInt32 nCount(10);
875 for (sal_Int32 i = 0; i < i_rStats.getLength(); ++i) {
876 for (const char** pStat = s_stats; *pStat != 0; ++pStat) {
877 if (i_rStats[i].Name.equalsAscii(*pStat)) {
878 sal_Int32 val = 0;
879 if (i_rStats[i].Value >>= val) {
880 nCount = val;
881 } else {
882 SAL_WARN("xmloff.draw", "SdXMLImport::SetStatistics: invalid entry");
888 if(nCount)
890 GetProgressBarHelper()->SetReference(nCount);
891 GetProgressBarHelper()->SetValue(0);
895 void SdXMLImport::AddHeaderDecl( const OUString& rName, const OUString& rText )
897 if( !rName.isEmpty() && !rText.isEmpty() )
898 maHeaderDeclsMap[rName] = rText;
901 void SdXMLImport::AddFooterDecl( const OUString& rName, const OUString& rText )
903 if( !rName.isEmpty() && !rText.isEmpty() )
904 maFooterDeclsMap[rName] = rText;
907 void SdXMLImport::AddDateTimeDecl( const OUString& rName, const OUString& rText, bool bFixed, const OUString& rDateTimeFormat )
909 if( !rName.isEmpty() && (!rText.isEmpty() || !bFixed) )
911 DateTimeDeclContextImpl aDecl;
912 aDecl.maStrText = rText;
913 aDecl.mbFixed = bFixed;
914 aDecl.maStrDateTimeFormat = rDateTimeFormat;
915 maDateTimeDeclsMap[rName] = aDecl;
919 OUString SdXMLImport::GetHeaderDecl( const OUString& rName ) const
921 OUString aRet;
922 HeaderFooterDeclMap::const_iterator aIter( maHeaderDeclsMap.find( rName ) );
923 if( aIter != maHeaderDeclsMap.end() )
924 aRet = (*aIter).second;
926 return aRet;
929 OUString SdXMLImport::GetFooterDecl( const OUString& rName ) const
931 OUString aRet;
932 HeaderFooterDeclMap::const_iterator aIter( maFooterDeclsMap.find( rName ) );
933 if( aIter != maFooterDeclsMap.end() )
934 aRet = (*aIter).second;
936 return aRet;
939 OUString SdXMLImport::GetDateTimeDecl( const OUString& rName, bool& rbFixed, OUString& rDateTimeFormat )
941 DateTimeDeclContextImpl aDecl;
943 DateTimeDeclMap::const_iterator aIter( maDateTimeDeclsMap.find( rName ) );
944 if( aIter != maDateTimeDeclsMap.end() )
945 aDecl = (*aIter).second;
947 rbFixed = aDecl.mbFixed;
948 rDateTimeFormat = aDecl.maStrDateTimeFormat;
949 return aDecl.maStrText;
952 void SdXMLImport::NotifyEmbeddedFontRead()
954 uno::Reference< lang::XMultiServiceFactory > xFac( GetModel(), uno::UNO_QUERY );
955 if( xFac.is() )
957 uno::Reference< beans::XPropertySet > xProps( xFac->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY );
958 if( xProps.is() )
959 xProps->setPropertyValue("EmbedFonts", uno::makeAny( true ) );
963 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */