Update ooo320-m1
[ooovba.git] / xmloff / source / draw / sdxmlimp.cxx
blob538dd65384e25a3bbbb1f6c5c364e38da6d0ba96
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdxmlimp.cxx,v $
10 * $Revision: 1.58 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include <tools/string.hxx>
36 #ifndef _XMLOFF_XMLMETAI_HXX
37 #include <xmloff/xmlscripti.hxx>
38 #endif
39 #include "sdxmlimp_impl.hxx"
40 #include "ximpbody.hxx"
42 #ifndef _SFX_XMLMETAI_HXX
43 #include <xmloff/xmlmetai.hxx>
44 #endif
45 #include "ximpstyl.hxx"
46 #include "xmlnmspe.hxx"
47 #include <xmloff/xmltoken.hxx>
48 #include <xmloff/xmluconv.hxx>
49 #include <xmloff/DocumentSettingsContext.hxx>
50 #include <com/sun/star/form/XFormsSupplier.hpp>
51 #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
52 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
53 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
54 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
55 #include "sdpropls.hxx"
56 #include <xmloff/xmlexppr.hxx>
57 #include "xmlerror.hxx"
58 #include <tools/debug.hxx>
59 #include <com/sun/star/style/XStyle.hpp>
61 #include <xmloff/XMLFontStylesContext.hxx>
63 #include <com/sun/star/document/XDocumentProperties.hpp>
64 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
66 using ::rtl::OUString;
67 using ::rtl::OUStringBuffer;
69 using namespace ::com::sun::star;
70 using namespace ::xmloff::token;
72 //////////////////////////////////////////////////////////////////////////////
84 //////////////////////////////////////////////////////////////////////////////
86 class SdXMLBodyContext_Impl : public SvXMLImportContext
88 const SdXMLImport& GetSdImport() const
89 { return (const SdXMLImport&)GetImport(); }
90 SdXMLImport& GetSdImport() { return (SdXMLImport&)GetImport(); }
92 public:
94 SdXMLBodyContext_Impl( SdXMLImport& rImport, sal_uInt16 nPrfx,
95 const OUString& rLName,
96 const uno::Reference< xml::sax::XAttributeList > & xAttrList );
97 virtual ~SdXMLBodyContext_Impl();
99 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
100 const OUString& rLocalName,
101 const uno::Reference< xml::sax::XAttributeList > & xAttrList );
104 SdXMLBodyContext_Impl::SdXMLBodyContext_Impl( SdXMLImport& rImport,
105 sal_uInt16 nPrfx, const OUString& rLName,
106 const uno::Reference< xml::sax::XAttributeList > & ) :
107 SvXMLImportContext( rImport, nPrfx, rLName )
111 SdXMLBodyContext_Impl::~SdXMLBodyContext_Impl()
115 SvXMLImportContext *SdXMLBodyContext_Impl::CreateChildContext(
116 sal_uInt16 /*nPrefix*/,
117 const OUString& rLocalName,
118 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
120 return GetSdImport().CreateBodyContext(rLocalName, xAttrList);
123 //////////////////////////////////////////////////////////////////////////////
125 // NB: virtually inherit so we can multiply inherit properly
126 // in SdXMLFlatDocContext_Impl
127 class SdXMLDocContext_Impl : public virtual SvXMLImportContext
129 protected:
130 const SdXMLImport& GetSdImport() const { return (const SdXMLImport&)GetImport(); }
131 SdXMLImport& GetSdImport() { return (SdXMLImport&)GetImport(); }
133 public:
134 SdXMLDocContext_Impl(
135 SdXMLImport& rImport,
136 USHORT nPrfx,
137 const OUString& rLName,
138 const uno::Reference<xml::sax::XAttributeList>& xAttrList);
139 virtual ~SdXMLDocContext_Impl();
141 TYPEINFO();
143 virtual SvXMLImportContext *CreateChildContext(USHORT nPrefix,
144 const OUString& rLocalName,
145 const uno::Reference<xml::sax::XAttributeList>& xAttrList);
148 //////////////////////////////////////////////////////////////////////////////
150 SdXMLDocContext_Impl::SdXMLDocContext_Impl(
151 SdXMLImport& rImport,
152 USHORT nPrfx,
153 const OUString& rLName,
154 const uno::Reference<xml::sax::XAttributeList>&)
155 : SvXMLImportContext(rImport, nPrfx, rLName)
159 //////////////////////////////////////////////////////////////////////////////
161 SdXMLDocContext_Impl::~SdXMLDocContext_Impl()
165 TYPEINIT1( SdXMLDocContext_Impl, SvXMLImportContext );
167 //////////////////////////////////////////////////////////////////////////////
169 SvXMLImportContext *SdXMLDocContext_Impl::CreateChildContext(
170 USHORT nPrefix,
171 const OUString& rLocalName,
172 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
174 SvXMLImportContext* pContext = 0L;
176 const SvXMLTokenMap& rTokenMap = GetSdImport().GetDocElemTokenMap();
177 switch(rTokenMap.Get(nPrefix, rLocalName))
179 case XML_TOK_DOC_FONTDECLS:
181 pContext = GetSdImport().CreateFontDeclsContext( rLocalName, xAttrList );
182 break;
184 case XML_TOK_DOC_SETTINGS:
186 if( GetImport().getImportFlags() & IMPORT_SETTINGS )
188 pContext = new XMLDocumentSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList );
190 break;
192 case XML_TOK_DOC_STYLES:
194 if( GetImport().getImportFlags() & IMPORT_STYLES )
196 // office:styles inside office:document
197 pContext = GetSdImport().CreateStylesContext(rLocalName, xAttrList);
199 break;
201 case XML_TOK_DOC_AUTOSTYLES:
203 if( GetImport().getImportFlags() & IMPORT_AUTOSTYLES )
205 // office:automatic-styles inside office:document
206 pContext = GetSdImport().CreateAutoStylesContext(rLocalName, xAttrList);
208 break;
210 case XML_TOK_DOC_MASTERSTYLES:
212 if( GetImport().getImportFlags() & IMPORT_MASTERSTYLES )
214 // office:master-styles inside office:document
215 pContext = GetSdImport().CreateMasterStylesContext(rLocalName, xAttrList);
217 break;
219 case XML_TOK_DOC_META:
221 DBG_WARNING("XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
222 break;
224 case XML_TOK_DOC_SCRIPT:
226 if( GetImport().getImportFlags() & IMPORT_SCRIPTS )
228 // office:script inside office:document
229 pContext = GetSdImport().CreateScriptContext( rLocalName );
231 break;
233 case XML_TOK_DOC_BODY:
235 if( GetImport().getImportFlags() & IMPORT_CONTENT )
237 // office:body inside office:document
238 pContext = new SdXMLBodyContext_Impl(GetSdImport(),nPrefix,
239 rLocalName, xAttrList);
241 break;
245 // call parent when no own context was created
246 if(!pContext)
247 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
249 return pContext;
252 //////////////////////////////////////////////////////////////////////////////
254 // context for flat file xml format
255 class SdXMLFlatDocContext_Impl
256 : public SdXMLDocContext_Impl, public SvXMLMetaDocumentContext
258 public:
259 SdXMLFlatDocContext_Impl( SdXMLImport& i_rImport,
260 USHORT i_nPrefix, const OUString & i_rLName,
261 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList,
262 const uno::Reference<document::XDocumentProperties>& i_xDocProps,
263 const uno::Reference<xml::sax::XDocumentHandler>& i_xDocBuilder);
265 virtual ~SdXMLFlatDocContext_Impl();
267 virtual SvXMLImportContext *CreateChildContext(
268 USHORT i_nPrefix, const OUString& i_rLocalName,
269 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList);
272 SdXMLFlatDocContext_Impl::SdXMLFlatDocContext_Impl( SdXMLImport& i_rImport,
273 USHORT i_nPrefix, const OUString & i_rLName,
274 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList,
275 const uno::Reference<document::XDocumentProperties>& i_xDocProps,
276 const uno::Reference<xml::sax::XDocumentHandler>& i_xDocBuilder) :
277 SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
278 SdXMLDocContext_Impl(i_rImport, i_nPrefix, i_rLName, i_xAttrList),
279 SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
280 i_xDocProps, i_xDocBuilder)
284 SdXMLFlatDocContext_Impl::~SdXMLFlatDocContext_Impl() { }
286 SvXMLImportContext *SdXMLFlatDocContext_Impl::CreateChildContext(
287 USHORT i_nPrefix, const OUString& i_rLocalName,
288 const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
290 // behave like meta base class iff we encounter office:meta
291 const SvXMLTokenMap& rTokenMap = GetSdImport().GetDocElemTokenMap();
292 if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) {
293 return SvXMLMetaDocumentContext::CreateChildContext(
294 i_nPrefix, i_rLocalName, i_xAttrList );
295 } else {
296 return SdXMLDocContext_Impl::CreateChildContext(
297 i_nPrefix, i_rLocalName, i_xAttrList );
301 //////////////////////////////////////////////////////////////////////////////
303 #define SERVICE(classname,servicename,implementationname,draw,flags)\
304 uno::Sequence< OUString > SAL_CALL classname##_getSupportedServiceNames() throw()\
306 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( servicename ) );\
307 const uno::Sequence< OUString > aSeq( &aServiceName, 1 );\
308 return aSeq;\
310 OUString SAL_CALL classname##_getImplementationName() throw()\
312 return OUString( RTL_CONSTASCII_USTRINGPARAM( implementationname ) );\
314 uno::Reference< uno::XInterface > SAL_CALL classname##_createInstance(const uno::Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )\
316 return (cppu::OWeakObject*)new SdXMLImport( rSMgr, draw, flags );\
319 SERVICE( XMLImpressImportOasis, "com.sun.star.comp.Impress.XMLOasisImporter", "XMLImpressImportOasis", sal_False, IMPORT_ALL )
320 SERVICE( XMLDrawImportOasis, "com.sun.star.comp.Draw.XMLOasisImporter", "XMLDrawImportOasis", sal_True, IMPORT_ALL )
322 SERVICE( XMLImpressStylesImportOasis, "com.sun.star.comp.Impress.XMLOasisStylesImporter", "XMLImpressStylesImportOasis", sal_False, IMPORT_STYLES|IMPORT_AUTOSTYLES|IMPORT_MASTERSTYLES )
323 SERVICE( XMLDrawStylesImportOasis, "com.sun.star.comp.Draw.XMLOasisStylesImporter", "XMLImpressStylesImportOasis", sal_True, IMPORT_STYLES|IMPORT_AUTOSTYLES|IMPORT_MASTERSTYLES )
325 SERVICE( XMLImpressContentImportOasis, "com.sun.star.comp.Impress.XMLOasisContentImporter", "XMLImpressContentImportOasis", sal_False, IMPORT_AUTOSTYLES|IMPORT_CONTENT|IMPORT_SCRIPTS|IMPORT_FONTDECLS )
326 SERVICE( XMLDrawContentImportOasis, "com.sun.star.comp.Draw.XMLOasisContentImporter", "XMLImpressContentImportOasis", sal_True, IMPORT_AUTOSTYLES|IMPORT_CONTENT|IMPORT_SCRIPTS|IMPORT_FONTDECLS )
328 SERVICE( XMLImpressMetaImportOasis, "com.sun.star.comp.Impress.XMLOasisMetaImporter", "XMLImpressMetaImportOasis", sal_False, IMPORT_META )
329 SERVICE( XMLDrawMetaImportOasis, "com.sun.star.comp.Draw.XMLOasisMetaImporter", "XMLImpressMetaImportOasis", sal_True, IMPORT_META )
331 SERVICE( XMLImpressSettingsImportOasis, "com.sun.star.comp.Impress.XMLOasisSettingsImporter", "XMLImpressSettingsImportOasis", sal_False, IMPORT_SETTINGS )
332 SERVICE( XMLDrawSettingsImportOasis, "com.sun.star.comp.Draw.XMLOasisSettingsImporter", "XMLImpressSettingsImportOasis", sal_True, IMPORT_SETTINGS )
334 //////////////////////////////////////////////////////////////////////////////
336 // #110680#
337 SdXMLImport::SdXMLImport(
338 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
339 sal_Bool bIsDraw, sal_uInt16 nImportFlags )
340 : SvXMLImport( xServiceFactory, nImportFlags ),
341 mpMasterStylesContext(0L),
342 mpDocElemTokenMap(0L),
343 mpBodyElemTokenMap(0L),
344 mpStylesElemTokenMap(0L),
345 mpMasterPageElemTokenMap(0L),
346 mpMasterPageAttrTokenMap(0L),
347 mpPageMasterAttrTokenMap(0L),
348 mpPageMasterStyleAttrTokenMap(0L),
349 mpDrawPageAttrTokenMap(0L),
350 mpDrawPageElemTokenMap(0L),
351 mpPresentationPlaceholderAttrTokenMap(0L),
352 mnStyleFamilyMask(0),
353 mnNewPageCount(0L),
354 mnNewMasterPageCount(0L),
355 mbIsDraw(bIsDraw),
356 mbLoadDoc(sal_True),
357 mbPreview(sal_False),
358 msPageLayouts( RTL_CONSTASCII_USTRINGPARAM( "PageLayouts" ) ),
359 msPreview( RTL_CONSTASCII_USTRINGPARAM( "Preview" ) )
361 // add namespaces
362 GetNamespaceMap().Add(
363 GetXMLToken(XML_NP_PRESENTATION),
364 GetXMLToken(XML_N_PRESENTATION),
365 XML_NAMESPACE_PRESENTATION);
367 GetNamespaceMap().Add(
368 GetXMLToken(XML_NP_SMIL),
369 GetXMLToken(XML_N_SMIL_COMPAT),
370 XML_NAMESPACE_SMIL);
372 GetNamespaceMap().Add(
373 GetXMLToken(XML_NP_ANIMATION),
374 GetXMLToken(XML_N_ANIMATION),
375 XML_NAMESPACE_ANIMATION);
378 // XImporter
379 void SAL_CALL SdXMLImport::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
380 throw(lang::IllegalArgumentException, uno::RuntimeException)
382 SvXMLImport::setTargetDocument( xDoc );
384 uno::Reference< lang::XServiceInfo > xDocServices( GetModel(), uno::UNO_QUERY );
385 if( !xDocServices.is() )
386 throw lang::IllegalArgumentException();
388 mbIsDraw = !xDocServices->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) );
390 // prepare access to styles
391 uno::Reference< style::XStyleFamiliesSupplier > xFamSup( GetModel(), uno::UNO_QUERY );
392 if(xFamSup.is())
393 mxDocStyleFamilies = xFamSup->getStyleFamilies();
395 // prepare access to master pages
396 uno::Reference < drawing::XMasterPagesSupplier > xMasterPagesSupplier(GetModel(), uno::UNO_QUERY);
397 if(xMasterPagesSupplier.is())
398 mxDocMasterPages = mxDocMasterPages.query( xMasterPagesSupplier->getMasterPages() );
400 // prepare access to draw pages
401 uno::Reference <drawing::XDrawPagesSupplier> xDrawPagesSupplier(GetModel(), uno::UNO_QUERY);
402 if(!xDrawPagesSupplier.is())
403 throw lang::IllegalArgumentException();
405 mxDocDrawPages = mxDocDrawPages.query( xDrawPagesSupplier->getDrawPages() );
406 if(!mxDocDrawPages.is())
407 throw lang::IllegalArgumentException();
409 if( mxDocDrawPages.is() && mxDocDrawPages->getCount() > 0 )
411 uno::Reference< form::XFormsSupplier > xFormsSupp;
412 mxDocDrawPages->getByIndex(0) >>= xFormsSupp;
413 mbIsFormsSupported = xFormsSupp.is();
416 // #88546# enable progress bar increments, SdXMLImport is only used for
417 // draw/impress import
418 GetShapeImport()->enableHandleProgressBar();
420 uno::Reference< lang::XMultiServiceFactory > xFac( GetModel(), uno::UNO_QUERY );
421 if( xFac.is() )
423 uno::Sequence< OUString > sSNS( xFac->getAvailableServiceNames() );
424 sal_Int32 n = sSNS.getLength();
425 const OUString* pSNS( sSNS.getConstArray() );
426 while( --n > 0 )
428 if( (*pSNS++).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TableShape") ) )
430 mbIsTableShapeSupported = true;
431 break;
437 // XInitialization
438 void SAL_CALL SdXMLImport::initialize( const uno::Sequence< uno::Any >& aArguments )
439 throw( uno::Exception, uno::RuntimeException)
441 SvXMLImport::initialize( aArguments );
443 uno::Reference< beans::XPropertySet > xInfoSet( getImportInfo() );
444 if( xInfoSet.is() )
446 uno::Reference< beans::XPropertySetInfo > xInfoSetInfo( xInfoSet->getPropertySetInfo() );
448 if( xInfoSetInfo->hasPropertyByName( msPageLayouts ) )
449 xInfoSet->getPropertyValue( msPageLayouts ) >>= mxPageLayouts;
451 if( xInfoSetInfo->hasPropertyByName( msPreview ) )
452 xInfoSet->getPropertyValue( msPreview ) >>= mbPreview;
456 //////////////////////////////////////////////////////////////////////////////
458 SdXMLImport::~SdXMLImport() throw ()
460 // #80365# removed ending of progress bar here, this was an old implementation
461 // and maybe removed on demand
462 // // stop progress view
463 // if(mxStatusIndicator.is())
464 // {
465 // mxStatusIndicator->end();
466 // mxStatusIndicator->reset();
467 // }
469 // Styles or AutoStyles context?
470 if(mpMasterStylesContext)
471 mpMasterStylesContext->ReleaseRef();
473 // delete all token maps
474 if(mpDocElemTokenMap)
475 delete mpDocElemTokenMap;
476 if(mpBodyElemTokenMap)
477 delete mpBodyElemTokenMap;
478 if(mpStylesElemTokenMap)
479 delete mpStylesElemTokenMap;
480 if(mpMasterPageElemTokenMap)
481 delete mpMasterPageElemTokenMap;
482 if(mpMasterPageAttrTokenMap)
483 delete mpMasterPageAttrTokenMap;
484 if(mpPageMasterAttrTokenMap)
485 delete mpPageMasterAttrTokenMap;
486 if(mpPageMasterStyleAttrTokenMap)
487 delete mpPageMasterStyleAttrTokenMap;
488 if(mpDrawPageAttrTokenMap)
489 delete mpDrawPageAttrTokenMap;
490 if(mpDrawPageElemTokenMap)
491 delete mpDrawPageElemTokenMap;
492 if(mpPresentationPlaceholderAttrTokenMap)
493 delete mpPresentationPlaceholderAttrTokenMap;
496 //////////////////////////////////////////////////////////////////////////////
498 void SdXMLImport::SetProgress(sal_Int32 nProg)
500 // set progress view
501 if(mxStatusIndicator.is())
502 mxStatusIndicator->setValue(nProg);
505 //////////////////////////////////////////////////////////////////////////////
507 const SvXMLTokenMap& SdXMLImport::GetDocElemTokenMap()
509 if(!mpDocElemTokenMap)
511 static __FAR_DATA SvXMLTokenMapEntry aDocElemTokenMap[] =
513 { XML_NAMESPACE_OFFICE, XML_FONT_FACE_DECLS, XML_TOK_DOC_FONTDECLS },
514 { XML_NAMESPACE_OFFICE, XML_STYLES, XML_TOK_DOC_STYLES },
515 { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES },
516 { XML_NAMESPACE_OFFICE, XML_MASTER_STYLES, XML_TOK_DOC_MASTERSTYLES },
517 { XML_NAMESPACE_OFFICE, XML_META, XML_TOK_DOC_META },
518 { XML_NAMESPACE_OFFICE, XML_SCRIPTS, XML_TOK_DOC_SCRIPT },
519 { XML_NAMESPACE_OFFICE, XML_BODY, XML_TOK_DOC_BODY },
520 { XML_NAMESPACE_OFFICE, XML_SETTINGS, XML_TOK_DOC_SETTINGS },
521 XML_TOKEN_MAP_END
524 mpDocElemTokenMap = new SvXMLTokenMap(aDocElemTokenMap);
525 } // if(!mpDocElemTokenMap)
527 return *mpDocElemTokenMap;
530 //////////////////////////////////////////////////////////////////////////////
532 const SvXMLTokenMap& SdXMLImport::GetBodyElemTokenMap()
534 if(!mpBodyElemTokenMap)
536 static __FAR_DATA SvXMLTokenMapEntry aBodyElemTokenMap[] =
538 { XML_NAMESPACE_DRAW, XML_PAGE, XML_TOK_BODY_PAGE },
539 { XML_NAMESPACE_PRESENTATION, XML_SETTINGS, XML_TOK_BODY_SETTINGS },
540 { XML_NAMESPACE_PRESENTATION, XML_HEADER_DECL, XML_TOK_BODY_HEADER_DECL },
541 { XML_NAMESPACE_PRESENTATION, XML_FOOTER_DECL, XML_TOK_BODY_FOOTER_DECL },
542 { XML_NAMESPACE_PRESENTATION, XML_DATE_TIME_DECL,XML_TOK_BODY_DATE_TIME_DECL },
544 XML_TOKEN_MAP_END
547 mpBodyElemTokenMap = new SvXMLTokenMap(aBodyElemTokenMap);
548 } // if(!mpBodyElemTokenMap)
550 return *mpBodyElemTokenMap;
553 //////////////////////////////////////////////////////////////////////////////
555 const SvXMLTokenMap& SdXMLImport::GetStylesElemTokenMap()
557 if(!mpStylesElemTokenMap)
559 static __FAR_DATA SvXMLTokenMapEntry aStylesElemTokenMap[] =
561 { XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT, XML_TOK_STYLES_PAGE_MASTER },
562 { XML_NAMESPACE_STYLE, XML_PRESENTATION_PAGE_LAYOUT, XML_TOK_STYLES_PRESENTATION_PAGE_LAYOUT },
563 { XML_NAMESPACE_STYLE, XML_STYLE, XML_TOK_STYLES_STYLE },
564 XML_TOKEN_MAP_END
567 mpStylesElemTokenMap = new SvXMLTokenMap(aStylesElemTokenMap);
568 } // if(!mpStylesElemTokenMap)
570 return *mpStylesElemTokenMap;
573 //////////////////////////////////////////////////////////////////////////////
575 const SvXMLTokenMap& SdXMLImport::GetMasterPageElemTokenMap()
577 if(!mpMasterPageElemTokenMap)
579 static __FAR_DATA SvXMLTokenMapEntry aMasterPageElemTokenMap[] =
581 { XML_NAMESPACE_STYLE, XML_STYLE, XML_TOK_MASTERPAGE_STYLE },
582 { XML_NAMESPACE_PRESENTATION, XML_NOTES, XML_TOK_MASTERPAGE_NOTES },
583 XML_TOKEN_MAP_END
586 mpMasterPageElemTokenMap = new SvXMLTokenMap(aMasterPageElemTokenMap);
587 } // if(!mpMasterPageElemTokenMap)
589 return *mpMasterPageElemTokenMap;
592 //////////////////////////////////////////////////////////////////////////////
594 const SvXMLTokenMap& SdXMLImport::GetMasterPageAttrTokenMap()
596 if(!mpMasterPageAttrTokenMap)
598 static __FAR_DATA SvXMLTokenMapEntry aMasterPageAttrTokenMap[] =
600 { XML_NAMESPACE_STYLE, XML_NAME, XML_TOK_MASTERPAGE_NAME },
601 { XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, XML_TOK_MASTERPAGE_DISPLAY_NAME },
602 { XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT_NAME, XML_TOK_MASTERPAGE_PAGE_MASTER_NAME },
603 { XML_NAMESPACE_DRAW, XML_STYLE_NAME, XML_TOK_MASTERPAGE_STYLE_NAME },
604 { XML_NAMESPACE_PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME, XML_TOK_MASTERPAGE_PAGE_LAYOUT_NAME },
605 { XML_NAMESPACE_PRESENTATION, XML_USE_HEADER_NAME, XML_TOK_MASTERPAGE_USE_HEADER_NAME },
606 { XML_NAMESPACE_PRESENTATION, XML_USE_FOOTER_NAME, XML_TOK_MASTERPAGE_USE_FOOTER_NAME },
607 { XML_NAMESPACE_PRESENTATION, XML_USE_DATE_TIME_NAME, XML_TOK_MASTERPAGE_USE_DATE_TIME_NAME },
608 XML_TOKEN_MAP_END
611 mpMasterPageAttrTokenMap = new SvXMLTokenMap(aMasterPageAttrTokenMap);
612 } // if(!mpMasterPageAttrTokenMap)
614 return *mpMasterPageAttrTokenMap;
617 //////////////////////////////////////////////////////////////////////////////
619 const SvXMLTokenMap& SdXMLImport::GetPageMasterAttrTokenMap()
621 if(!mpPageMasterAttrTokenMap)
623 static __FAR_DATA SvXMLTokenMapEntry aPageMasterAttrTokenMap[] =
625 { XML_NAMESPACE_STYLE, XML_NAME, XML_TOK_PAGEMASTER_NAME },
626 XML_TOKEN_MAP_END
629 mpPageMasterAttrTokenMap = new SvXMLTokenMap(aPageMasterAttrTokenMap);
630 } // if(!mpPageMasterAttrTokenMap)
632 return *mpPageMasterAttrTokenMap;
635 //////////////////////////////////////////////////////////////////////////////
637 const SvXMLTokenMap& SdXMLImport::GetPageMasterStyleAttrTokenMap()
639 if(!mpPageMasterStyleAttrTokenMap)
641 static __FAR_DATA SvXMLTokenMapEntry aPageMasterStyleAttrTokenMap[] =
643 { XML_NAMESPACE_FO, XML_MARGIN_TOP, XML_TOK_PAGEMASTERSTYLE_MARGIN_TOP },
644 { XML_NAMESPACE_FO, XML_MARGIN_BOTTOM, XML_TOK_PAGEMASTERSTYLE_MARGIN_BOTTOM },
645 { XML_NAMESPACE_FO, XML_MARGIN_LEFT, XML_TOK_PAGEMASTERSTYLE_MARGIN_LEFT },
646 { XML_NAMESPACE_FO, XML_MARGIN_RIGHT, XML_TOK_PAGEMASTERSTYLE_MARGIN_RIGHT },
647 { XML_NAMESPACE_FO, XML_PAGE_WIDTH, XML_TOK_PAGEMASTERSTYLE_PAGE_WIDTH },
648 { XML_NAMESPACE_FO, XML_PAGE_HEIGHT, XML_TOK_PAGEMASTERSTYLE_PAGE_HEIGHT },
649 { XML_NAMESPACE_STYLE, XML_PRINT_ORIENTATION, XML_TOK_PAGEMASTERSTYLE_PAGE_ORIENTATION },
650 XML_TOKEN_MAP_END
653 mpPageMasterStyleAttrTokenMap = new SvXMLTokenMap(aPageMasterStyleAttrTokenMap);
654 } // if(!mpPageMasterStyleAttrTokenMap)
656 return *mpPageMasterStyleAttrTokenMap;
659 //////////////////////////////////////////////////////////////////////////////
661 const SvXMLTokenMap& SdXMLImport::GetDrawPageAttrTokenMap()
663 if(!mpDrawPageAttrTokenMap)
665 static __FAR_DATA SvXMLTokenMapEntry aDrawPageAttrTokenMap[] =
667 { XML_NAMESPACE_DRAW, XML_NAME, XML_TOK_DRAWPAGE_NAME },
668 { XML_NAMESPACE_DRAW, XML_STYLE_NAME, XML_TOK_DRAWPAGE_STYLE_NAME },
669 { XML_NAMESPACE_DRAW, XML_MASTER_PAGE_NAME, XML_TOK_DRAWPAGE_MASTER_PAGE_NAME },
670 { XML_NAMESPACE_PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME, XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME },
671 { XML_NAMESPACE_DRAW, XML_ID, XML_TOK_DRAWPAGE_ID },
672 { XML_NAMESPACE_XML, XML_ID, XML_TOK_DRAWPAGE_ID },
673 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_DRAWPAGE_HREF },
674 { XML_NAMESPACE_PRESENTATION, XML_USE_HEADER_NAME, XML_TOK_DRAWPAGE_USE_HEADER_NAME },
675 { XML_NAMESPACE_PRESENTATION, XML_USE_FOOTER_NAME, XML_TOK_DRAWPAGE_USE_FOOTER_NAME },
676 { XML_NAMESPACE_PRESENTATION, XML_USE_DATE_TIME_NAME, XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME },
678 XML_TOKEN_MAP_END
681 mpDrawPageAttrTokenMap = new SvXMLTokenMap(aDrawPageAttrTokenMap);
682 } // if(!mpDrawPageAttrTokenMap)
684 return *mpDrawPageAttrTokenMap;
687 //////////////////////////////////////////////////////////////////////////////
689 const SvXMLTokenMap& SdXMLImport::GetDrawPageElemTokenMap()
691 if(!mpDrawPageElemTokenMap)
693 static __FAR_DATA SvXMLTokenMapEntry aDrawPageElemTokenMap[] =
695 { XML_NAMESPACE_PRESENTATION, XML_NOTES, XML_TOK_DRAWPAGE_NOTES },
696 { XML_NAMESPACE_ANIMATION, XML_PAR, XML_TOK_DRAWPAGE_PAR },
697 { XML_NAMESPACE_ANIMATION, XML_SEQ, XML_TOK_DRAWPAGE_SEQ },
698 XML_TOKEN_MAP_END
701 mpDrawPageElemTokenMap = new SvXMLTokenMap(aDrawPageElemTokenMap);
702 } // if(!mpDrawPageElemTokenMap)
704 return *mpDrawPageElemTokenMap;
707 //////////////////////////////////////////////////////////////////////////////
709 const SvXMLTokenMap& SdXMLImport::GetPresentationPlaceholderAttrTokenMap()
711 if(!mpPresentationPlaceholderAttrTokenMap)
713 static __FAR_DATA SvXMLTokenMapEntry aPresentationPlaceholderAttrTokenMap[] =
715 { XML_NAMESPACE_PRESENTATION, XML_OBJECT, XML_TOK_PRESENTATIONPLACEHOLDER_OBJECTNAME },
716 { XML_NAMESPACE_SVG, XML_X, XML_TOK_PRESENTATIONPLACEHOLDER_X },
717 { XML_NAMESPACE_SVG, XML_Y, XML_TOK_PRESENTATIONPLACEHOLDER_Y },
718 { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_PRESENTATIONPLACEHOLDER_WIDTH },
719 { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_PRESENTATIONPLACEHOLDER_HEIGHT },
720 XML_TOKEN_MAP_END
723 mpPresentationPlaceholderAttrTokenMap = new SvXMLTokenMap(aPresentationPlaceholderAttrTokenMap);
724 } // if(!mpPresentationPlaceholderAttrTokenMap)
726 return *mpPresentationPlaceholderAttrTokenMap;
729 //////////////////////////////////////////////////////////////////////////////
731 SvXMLImportContext *SdXMLImport::CreateContext(USHORT nPrefix,
732 const OUString& rLocalName,
733 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
735 SvXMLImportContext* pContext = 0;
737 if(XML_NAMESPACE_OFFICE == nPrefix &&
738 ( IsXMLToken( rLocalName, XML_DOCUMENT_STYLES ) ||
739 IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT ) ||
740 IsXMLToken( rLocalName, XML_DOCUMENT_SETTINGS ) ))
742 pContext = new SdXMLDocContext_Impl(*this, nPrefix, rLocalName, xAttrList);
743 } else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
744 ( IsXMLToken(rLocalName, XML_DOCUMENT_META)) ) {
745 pContext = CreateMetaContext(rLocalName, xAttrList);
746 } else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
747 ( IsXMLToken(rLocalName, XML_DOCUMENT)) ) {
748 uno::Reference<xml::sax::XDocumentHandler> xDocBuilder(
749 mxServiceFactory->createInstance(::rtl::OUString::createFromAscii(
750 "com.sun.star.xml.dom.SAXDocumentBuilder")),
751 uno::UNO_QUERY_THROW);
752 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
753 GetModel(), uno::UNO_QUERY_THROW);
754 // flat OpenDocument file format
755 pContext = new SdXMLFlatDocContext_Impl( *this, nPrefix, rLocalName,
756 xAttrList, xDPS->getDocumentProperties(), xDocBuilder);
757 } else {
758 pContext = SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
761 return pContext;
764 //////////////////////////////////////////////////////////////////////////////
766 SvXMLImportContext *SdXMLImport::CreateMetaContext(const OUString& rLocalName,
767 const uno::Reference<xml::sax::XAttributeList>&)
769 SvXMLImportContext* pContext = 0L;
771 if (!IsStylesOnlyMode() && (getImportFlags() & IMPORT_META))
773 uno::Reference<xml::sax::XDocumentHandler> xDocBuilder(
774 mxServiceFactory->createInstance(::rtl::OUString::createFromAscii(
775 "com.sun.star.xml.dom.SAXDocumentBuilder")),
776 uno::UNO_QUERY_THROW);
777 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
778 GetModel(), uno::UNO_QUERY_THROW);
779 pContext = new SvXMLMetaDocumentContext(*this,
780 XML_NAMESPACE_OFFICE, rLocalName,
781 xDPS->getDocumentProperties(), xDocBuilder);
784 if(!pContext)
786 pContext = new SvXMLImportContext(*this, XML_NAMESPACE_OFFICE, rLocalName);
789 return pContext;
792 //////////////////////////////////////////////////////////////////////////////
794 SvXMLImportContext *SdXMLImport::CreateBodyContext(const OUString& rLocalName,
795 const uno::Reference<xml::sax::XAttributeList>&)
797 SvXMLImportContext *pContext = 0;
798 pContext = new SdXMLBodyContext(*this, XML_NAMESPACE_OFFICE, rLocalName);
799 return pContext;
802 //////////////////////////////////////////////////////////////////////////////
804 SvXMLStylesContext *SdXMLImport::CreateStylesContext(const OUString& rLocalName,
805 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
807 if(GetShapeImport()->GetStylesContext())
808 return GetShapeImport()->GetStylesContext();
810 GetShapeImport()->SetStylesContext(new SdXMLStylesContext(
811 *this, XML_NAMESPACE_OFFICE, rLocalName, xAttrList, FALSE));
813 return GetShapeImport()->GetStylesContext();
816 //////////////////////////////////////////////////////////////////////////////
818 SvXMLStylesContext *SdXMLImport::CreateAutoStylesContext(const OUString& rLocalName,
819 const uno::Reference<xml::sax::XAttributeList>& xAttrList)
821 if(GetShapeImport()->GetAutoStylesContext())
822 return GetShapeImport()->GetAutoStylesContext();
824 GetShapeImport()->SetAutoStylesContext(new SdXMLStylesContext(
825 *this, XML_NAMESPACE_OFFICE, rLocalName, xAttrList, TRUE));
827 return GetShapeImport()->GetAutoStylesContext();
830 //////////////////////////////////////////////////////////////////////////////
832 SvXMLImportContext* SdXMLImport::CreateMasterStylesContext(const OUString& rLocalName,
833 const uno::Reference<xml::sax::XAttributeList>&)
835 if(mpMasterStylesContext)
836 return mpMasterStylesContext;
838 mpMasterStylesContext = new SdXMLMasterStylesContext(
839 *this, XML_NAMESPACE_OFFICE, rLocalName);
840 mpMasterStylesContext->AddRef();
842 return mpMasterStylesContext;
845 //////////////////////////////////////////////////////////////////////////////
847 SvXMLImportContext *SdXMLImport::CreateFontDeclsContext(const OUString& rLocalName,
848 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
850 XMLFontStylesContext *pFSContext =
851 new XMLFontStylesContext( *this, XML_NAMESPACE_OFFICE,
852 rLocalName, xAttrList,
853 gsl_getSystemTextEncoding() );
854 SetFontDecls( pFSContext );
855 return pFSContext;
858 //////////////////////////////////////////////////////////////////////////////
859 // import pool defaults. Parameter contains pool defaults read
860 // from input data. These data needs to be set at the model.
862 void SdXMLImport::ImportPoolDefaults(const XMLPropStyleContext*)
866 //////////////////////////////////////////////////////////////////////////////
868 SvXMLImportContext *SdXMLImport::CreateScriptContext(
869 const OUString& rLocalName )
871 SvXMLImportContext *pContext = 0;
873 pContext = new XMLScriptContext( *this,
874 XML_NAMESPACE_OFFICE, rLocalName,
875 GetModel() );
876 return pContext;
879 //////////////////////////////////////////////////////////////////////////////
881 void SdXMLImport::SetViewSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aViewProps)
883 uno::Reference< beans::XPropertySet > xPropSet( GetModel(), uno::UNO_QUERY );
884 if( !xPropSet.is() )
885 return;
887 awt::Rectangle aVisArea( 0,0, 28000, 21000 );
888 sal_Int32 nCount = aViewProps.getLength();
890 const beans::PropertyValue* pValues = aViewProps.getConstArray();
892 while( nCount-- )
894 const OUString& rName = pValues->Name;
895 const uno::Any rValue = pValues->Value;
897 if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("VisibleAreaTop") ) )
899 rValue >>= aVisArea.Y;
901 else if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("VisibleAreaLeft") ) )
903 rValue >>= aVisArea.X;
905 else if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("VisibleAreaWidth") ) )
907 rValue >>= aVisArea.Width;
909 else if( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("VisibleAreaHeight") ) )
911 rValue >>= aVisArea.Height;
914 pValues++;
919 xPropSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "VisibleArea" ) ), uno::makeAny( aVisArea ) );
921 catch( com::sun::star::uno::Exception e )
923 uno::Sequence<OUString> aSeq(0);
924 SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, aSeq, e.Message, NULL );
928 void SdXMLImport::SetConfigurationSettings(const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& aConfigProps)
930 uno::Reference< lang::XMultiServiceFactory > xFac( GetModel(), uno::UNO_QUERY );
931 if( !xFac.is() )
932 return;
934 uno::Reference< beans::XPropertySet > xProps( xFac->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.Settings" ) ) ), uno::UNO_QUERY );
935 if( !xProps.is() )
936 return;
938 uno::Reference< beans::XPropertySetInfo > xInfo( xProps->getPropertySetInfo() );
939 if( !xInfo.is() )
940 return;
942 sal_Int32 nCount = aConfigProps.getLength();
943 const beans::PropertyValue* pValues = aConfigProps.getConstArray();
945 while( nCount-- )
949 const OUString& rProperty = pValues->Name;
950 if( xInfo->hasPropertyByName( rProperty ) )
951 xProps->setPropertyValue( rProperty, pValues->Value );
953 catch( uno::Exception& e )
955 (void)e;
956 OSL_TRACE( "#SdXMLImport::SetConfigurationSettings: Exception!" );
959 pValues++;
963 // #80365# overload this method to read and use the hint value from the
964 // written meta information. If no info is found, guess 10 draw objects
965 //void SdXMLImport::SetStatisticAttributes(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
966 void SdXMLImport::SetStatistics(
967 const uno::Sequence<beans::NamedValue> & i_rStats)
969 static const char* s_stats[] =
970 { "ObjectCount", 0 };
972 SvXMLImport::SetStatistics(i_rStats);
974 sal_uInt32 nCount(10);
975 for (sal_Int32 i = 0; i < i_rStats.getLength(); ++i) {
976 for (const char** pStat = s_stats; *pStat != 0; ++pStat) {
977 if (i_rStats[i].Name.equalsAscii(*pStat)) {
978 sal_Int32 val = 0;
979 if (i_rStats[i].Value >>= val) {
980 nCount = val;
981 } else {
982 DBG_ERROR("SdXMLImport::SetStatistics: invalid entry");
988 if(nCount)
990 GetProgressBarHelper()->SetReference(nCount);
991 GetProgressBarHelper()->SetValue(0);
996 // XServiceInfo
997 OUString SAL_CALL SdXMLImport::getImplementationName() throw( uno::RuntimeException )
999 if( IsDraw())
1001 // Draw
1003 switch( getImportFlags())
1005 case IMPORT_ALL:
1006 return XMLDrawImportOasis_getImplementationName();
1007 case (IMPORT_STYLES|IMPORT_AUTOSTYLES|IMPORT_MASTERSTYLES):
1008 return XMLDrawStylesImportOasis_getImplementationName();
1009 case (IMPORT_AUTOSTYLES|IMPORT_CONTENT|IMPORT_SCRIPTS|IMPORT_FONTDECLS):
1010 return XMLDrawContentImportOasis_getImplementationName();
1011 case IMPORT_META:
1012 return XMLDrawMetaImportOasis_getImplementationName();
1013 case IMPORT_SETTINGS:
1014 return XMLDrawSettingsImportOasis_getImplementationName();
1015 default:
1016 return XMLDrawImportOasis_getImplementationName();
1019 else
1021 // Impress
1023 switch( getImportFlags())
1025 case IMPORT_ALL:
1026 return XMLImpressImportOasis_getImplementationName();
1027 case (IMPORT_STYLES|IMPORT_AUTOSTYLES|IMPORT_MASTERSTYLES):
1028 return XMLImpressStylesImportOasis_getImplementationName();
1029 case (IMPORT_AUTOSTYLES|IMPORT_CONTENT|IMPORT_SCRIPTS|IMPORT_FONTDECLS):
1030 return XMLImpressContentImportOasis_getImplementationName();
1031 case IMPORT_META:
1032 return XMLImpressMetaImportOasis_getImplementationName();
1033 case IMPORT_SETTINGS:
1034 return XMLImpressSettingsImportOasis_getImplementationName();
1035 default:
1036 return XMLImpressImportOasis_getImplementationName();
1041 HeaderFooterDeclMap maHeaderDeclsMap;
1042 HeaderFooterDeclMap maFooterDeclsMap;
1043 DateTimeDeclMap maDateTimeDeclsMap;
1045 void SdXMLImport::AddHeaderDecl( const ::rtl::OUString& rName, const ::rtl::OUString& rText )
1047 if( rName.getLength() && rText.getLength() )
1048 maHeaderDeclsMap[rName] = rText;
1051 void SdXMLImport::AddFooterDecl( const ::rtl::OUString& rName, const ::rtl::OUString& rText )
1053 if( rName.getLength() && rText.getLength() )
1054 maFooterDeclsMap[rName] = rText;
1057 void SdXMLImport::AddDateTimeDecl( const ::rtl::OUString& rName, const ::rtl::OUString& rText, sal_Bool bFixed, const ::rtl::OUString& rDateTimeFormat )
1059 if( rName.getLength() && (rText.getLength() || !bFixed) )
1061 DateTimeDeclContextImpl aDecl;
1062 aDecl.maStrText = rText;
1063 aDecl.mbFixed = bFixed;
1064 aDecl.maStrDateTimeFormat = rDateTimeFormat;
1065 maDateTimeDeclsMap[rName] = aDecl;
1069 ::rtl::OUString SdXMLImport::GetHeaderDecl( const ::rtl::OUString& rName ) const
1071 ::rtl::OUString aRet;
1072 HeaderFooterDeclMap::const_iterator aIter( maHeaderDeclsMap.find( rName ) );
1073 if( aIter != maHeaderDeclsMap.end() )
1074 aRet = (*aIter).second;
1076 return aRet;
1079 ::rtl::OUString SdXMLImport::GetFooterDecl( const ::rtl::OUString& rName ) const
1081 ::rtl::OUString aRet;
1082 HeaderFooterDeclMap::const_iterator aIter( maFooterDeclsMap.find( rName ) );
1083 if( aIter != maFooterDeclsMap.end() )
1084 aRet = (*aIter).second;
1086 return aRet;
1089 ::rtl::OUString SdXMLImport::GetDateTimeDecl( const ::rtl::OUString& rName, sal_Bool& rbFixed, ::rtl::OUString& rDateTimeFormat )
1091 DateTimeDeclContextImpl aDecl;
1093 DateTimeDeclMap::const_iterator aIter( maDateTimeDeclsMap.find( rName ) );
1094 if( aIter != maDateTimeDeclsMap.end() )
1095 aDecl = (*aIter).second;
1097 rbFixed = aDecl.mbFixed;
1098 rDateTimeFormat = aDecl.maStrDateTimeFormat;
1099 return aDecl.maStrText;
1102 // eof