1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <osl/thread.h>
#include <sal/log.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/sequence.hxx>
#include <xmloff/xmlscripti.hxx>
#include "sdxmlimp_impl.hxx"
#include "ximpbody.hxx"
#include <xmloff/xmlmetai.hxx>
#include "ximpstyl.hxx"
#include <xmloff/xmlnmspe.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/DocumentSettingsContext.hxx>
#include <com/sun/star/awt/Rectangle.hpp>
#include <com/sun/star/form/XFormsSupplier.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <xmloff/settingsstore.hxx>
#include <xmloff/ProgressBarHelper.hxx>
#include <xmloff/XMLFontStylesContext.hxx>
#include <com/sun/star/document/XDocumentProperties.hpp>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
using namespace ::com::sun::star;
using namespace ::xmloff::token;
namespace {
class SdXMLBodyContext_Impl : public SvXMLImportContext
{
SdXMLImport& GetSdImport() { return static_cast<SdXMLImport&>(GetImport()); }
public:
SdXMLBodyContext_Impl( SdXMLImport& rImport );<--- Class 'SdXMLBodyContext_Impl' has a constructor with 1 argument that is not explicit. [+]Class 'SdXMLBodyContext_Impl' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {}
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
};
}
SdXMLBodyContext_Impl::SdXMLBodyContext_Impl( SdXMLImport& rImport ) :
SvXMLImportContext( rImport )
{
}
css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLBodyContext_Impl::createFastChildContext(
sal_Int32 /*nElement*/,
const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ )
{
return new SdXMLBodyContext(GetSdImport());
}
namespace {
// NB: virtually inherit so we can multiply inherit properly
// in SdXMLFlatDocContext_Impl
class SdXMLDocContext_Impl : public virtual SvXMLImportContext
{
protected:
SdXMLImport& GetSdImport() { return static_cast<SdXMLImport&>(GetImport()); }
public:
SdXMLDocContext_Impl( SdXMLImport& rImport );<--- Class 'SdXMLDocContext_Impl' has a constructor with 1 argument that is not explicit. [+]Class 'SdXMLDocContext_Impl' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
virtual void SAL_CALL characters( const OUString& /*aChars*/ ) override {}
virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override {}
virtual void SAL_CALL endFastElement( sal_Int32 /*nElement*/ ) override {}
};
}
SdXMLDocContext_Impl::SdXMLDocContext_Impl(
SdXMLImport& rImport )
: SvXMLImportContext(rImport)
{
}
uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SdXMLDocContext_Impl::createFastChildContext(
sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
{
switch (nElement)
{
case XML_ELEMENT(OFFICE, XML_SCRIPTS):
{
if( GetImport().getImportFlags() & SvXMLImportFlags::SCRIPTS )
{
// office:script inside office:document
return new XMLScriptContext( GetSdImport(), GetSdImport().GetModel() );
}
break;
}
case XML_ELEMENT(OFFICE, XML_MASTER_STYLES):
{
if( GetImport().getImportFlags() & SvXMLImportFlags::MASTERSTYLES )
{
// office:master-styles inside office:document
return GetSdImport().CreateMasterStylesContext();
}
break;
}
case XML_ELEMENT(OFFICE, XML_BODY):
{
if( GetImport().getImportFlags() & SvXMLImportFlags::CONTENT )
{
// office:body inside office:document
return new SdXMLBodyContext_Impl(GetSdImport());
}
break;
}
case XML_ELEMENT(OFFICE, XML_SETTINGS):
{
if( GetImport().getImportFlags() & SvXMLImportFlags::SETTINGS )
{
return new XMLDocumentSettingsContext(GetImport());
}
break;
}
case XML_ELEMENT(OFFICE, XML_STYLES):
{
if( GetImport().getImportFlags() & SvXMLImportFlags::STYLES )
{
// office:styles inside office:document
return GetSdImport().CreateStylesContext();
}
break;
}
case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES):
{
if( GetImport().getImportFlags() & SvXMLImportFlags::AUTOSTYLES )
{
// office:automatic-styles inside office:document
return GetSdImport().CreateAutoStylesContext();
}
break;
}
case XML_ELEMENT(OFFICE, XML_FONT_FACE_DECLS):
{
return GetSdImport().CreateFontDeclsContext();
break;<--- Consecutive return, break, continue, goto or throw statements are unnecessary. [+]Consecutive return, break, continue, goto or throw statements are unnecessary. The second statement can never be executed, and so should be removed.
}
case XML_ELEMENT(OFFICE, XML_META):
{
SAL_INFO("xmloff.draw", "XML_ELEMENT(OFFICE, XML_META): should not have come here, maybe document is invalid?");
break;
}
}
return nullptr;
}
namespace {
// context for flat file xml format
class SdXMLFlatDocContext_Impl
: public SdXMLDocContext_Impl, public SvXMLMetaDocumentContext
{
public:
SdXMLFlatDocContext_Impl( SdXMLImport& i_rImport,
const uno::Reference<document::XDocumentProperties>& i_xDocProps );
virtual void SAL_CALL startFastElement( sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
virtual void SAL_CALL characters( const OUString& aChars ) override;
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
};
}
SdXMLFlatDocContext_Impl::SdXMLFlatDocContext_Impl( SdXMLImport& i_rImport,
const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
SvXMLImportContext(i_rImport),
SdXMLDocContext_Impl(i_rImport),
SvXMLMetaDocumentContext(i_rImport, i_xDocProps)
{
}
void SAL_CALL SdXMLFlatDocContext_Impl::startFastElement( sal_Int32 nElement,
const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
{
SvXMLMetaDocumentContext::startFastElement(nElement, xAttrList);
}
void SAL_CALL SdXMLFlatDocContext_Impl::endFastElement( sal_Int32 nElement )
{
SvXMLMetaDocumentContext::endFastElement(nElement);
}
void SAL_CALL SdXMLFlatDocContext_Impl::characters( const OUString& rChars )
{
SvXMLMetaDocumentContext::characters(rChars);
}
uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SdXMLFlatDocContext_Impl::createFastChildContext(
sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
{
// behave like meta base class iff we encounter office:meta
if ( nElement == XML_ELEMENT( OFFICE, XML_META ) ) {
return SvXMLMetaDocumentContext::createFastChildContext(
nElement, xAttrList );
} else {
return SdXMLDocContext_Impl::createFastChildContext(
nElement, xAttrList );
}
}
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_comp_Impress_XMLOasisImporter_get_implementation(<--- The function 'com_sun_star_comp_Impress_XMLOasisImporter_get_implementation' is never used.
uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
{
return cppu::acquire(
new SdXMLImport(pCtx, "XMLImpressImportOasis", false, SvXMLImportFlags::ALL));
}
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_comp_Draw_XMLOasisImporter_get_implementation(uno::XComponentContext* pCtx,<--- The function 'com_sun_star_comp_Draw_XMLOasisImporter_get_implementation' is never used.
uno::Sequence<uno::Any> const& /*rSeq*/)
{
return cppu::acquire(new SdXMLImport(pCtx, "XMLDrawImportOasis", true, SvXMLImportFlags::ALL));
}
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_comp_Draw_XMLOasisStylesImporter_get_implementation(uno::XComponentContext* pCtx,<--- The function 'com_sun_star_comp_Draw_XMLOasisStylesImporter_get_implementation' is never used.
uno::Sequence<uno::Any> const& /*rSeq*/)
{
return cppu::acquire(new SdXMLImport(pCtx, "XMLDrawStylesImportOasis", true,
SvXMLImportFlags::STYLES | SvXMLImportFlags::AUTOSTYLES
| SvXMLImportFlags::MASTERSTYLES));
}
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_comp_Draw_XMLOasisContentImporter_get_implementation(<--- The function 'com_sun_star_comp_Draw_XMLOasisContentImporter_get_implementation' is never used.
uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
{
return cppu::acquire(new SdXMLImport(pCtx, "XMLDrawContentImportOasis", true,
SvXMLImportFlags::AUTOSTYLES | SvXMLImportFlags::CONTENT
| SvXMLImportFlags::SCRIPTS
| SvXMLImportFlags::FONTDECLS));
}
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_comp_Draw_XMLOasisMetaImporter_get_implementation(<--- The function 'com_sun_star_comp_Draw_XMLOasisMetaImporter_get_implementation' is never used.
uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
{
return cppu::acquire(
new SdXMLImport(pCtx, "XMLDrawMetaImportOasis", true, SvXMLImportFlags::META));
}
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_comp_Draw_XMLOasisSettingsImporter_get_implementation(<--- The function 'com_sun_star_comp_Draw_XMLOasisSettingsImporter_get_implementation' is never used.
uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
{
return cppu::acquire(
new SdXMLImport(pCtx, "XMLDrawSettingsImportOasis", true, SvXMLImportFlags::SETTINGS));
}
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_comp_Impress_XMLOasisStylesImporter_get_implementation(<--- The function 'com_sun_star_comp_Impress_XMLOasisStylesImporter_get_implementation' is never used.
uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
{
return cppu::acquire(new SdXMLImport(pCtx, "XMLImpressStylesImportOasis", false,
SvXMLImportFlags::STYLES | SvXMLImportFlags::AUTOSTYLES
| SvXMLImportFlags::MASTERSTYLES));
}
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_comp_Impress_XMLOasisContentImporter_get_implementation(<--- The function 'com_sun_star_comp_Impress_XMLOasisContentImporter_get_implementation' is never used.
uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
{
return cppu::acquire(new SdXMLImport(pCtx, "XMLImpressContentImportOasis", false,
SvXMLImportFlags::AUTOSTYLES | SvXMLImportFlags::CONTENT
| SvXMLImportFlags::SCRIPTS
| SvXMLImportFlags::FONTDECLS));
}
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_comp_Impress_XMLOasisMetaImporter_get_implementation(<--- The function 'com_sun_star_comp_Impress_XMLOasisMetaImporter_get_implementation' is never used.
uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
{
return cppu::acquire(
new SdXMLImport(pCtx, "XMLImpressMetaImportOasis", false, SvXMLImportFlags::META));
}
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
com_sun_star_comp_Impress_XMLOasisSettingsImporter_get_implementation(<--- The function 'com_sun_star_comp_Impress_XMLOasisSettingsImporter_get_implementation' is never used.
uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/)
{
return cppu::acquire(
new SdXMLImport(pCtx, "XMLImpressSettingsImportOasis", false, SvXMLImportFlags::SETTINGS));
}
SdXMLImport::SdXMLImport(
const css::uno::Reference< css::uno::XComponentContext >& xContext,
OUString const & implementationName,
bool bIsDraw, SvXMLImportFlags nImportFlags )
: SvXMLImport( xContext, implementationName, nImportFlags ),
mnNewPageCount(0),
mnNewMasterPageCount(0),
mbIsDraw(bIsDraw),
mbLoadDoc(true),
mbPreview(false)
{
// add namespaces
GetNamespaceMap().Add(
GetXMLToken(XML_NP_PRESENTATION),
GetXMLToken(XML_N_PRESENTATION),
XML_NAMESPACE_PRESENTATION);
GetNamespaceMap().Add(
GetXMLToken(XML_NP_SMIL),
GetXMLToken(XML_N_SMIL_COMPAT),
XML_NAMESPACE_SMIL);
}
// XImporter
void SAL_CALL SdXMLImport::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
{
SvXMLImport::setTargetDocument( xDoc );
uno::Reference< lang::XServiceInfo > xDocServices( GetModel(), uno::UNO_QUERY );
if( !xDocServices.is() )
throw lang::IllegalArgumentException();
mbIsDraw = !xDocServices->supportsService("com.sun.star.presentation.PresentationDocument");
// prepare access to styles
uno::Reference< style::XStyleFamiliesSupplier > xFamSup( GetModel(), uno::UNO_QUERY );
if(xFamSup.is())
mxDocStyleFamilies = xFamSup->getStyleFamilies();
// prepare access to master pages
uno::Reference < drawing::XMasterPagesSupplier > xMasterPagesSupplier(GetModel(), uno::UNO_QUERY);
if(xMasterPagesSupplier.is())
mxDocMasterPages = xMasterPagesSupplier->getMasterPages();
// prepare access to draw pages
uno::Reference <drawing::XDrawPagesSupplier> xDrawPagesSupplier(GetModel(), uno::UNO_QUERY);
if(!xDrawPagesSupplier.is())
throw lang::IllegalArgumentException();
mxDocDrawPages = xDrawPagesSupplier->getDrawPages();
if(!mxDocDrawPages.is())
throw lang::IllegalArgumentException();
if( mxDocDrawPages.is() && mxDocDrawPages->getCount() > 0 )
{
uno::Reference< form::XFormsSupplier > xFormsSupp;
mxDocDrawPages->getByIndex(0) >>= xFormsSupp;
mbIsFormsSupported = xFormsSupp.is();
}
// #88546# enable progress bar increments, SdXMLImport is only used for
// draw/impress import
GetShapeImport()->enableHandleProgressBar();
uno::Reference< lang::XMultiServiceFactory > xFac( GetModel(), uno::UNO_QUERY );
if( xFac.is() )
{
uno::Sequence< OUString > sSNS( xFac->getAvailableServiceNames() );
if (comphelper::findValue(sSNS, "com.sun.star.drawing.TableShape") != -1)
mbIsTableShapeSupported = true;
}
}
// XInitialization
void SAL_CALL SdXMLImport::initialize( const uno::Sequence< uno::Any >& aArguments )
{
SvXMLImport::initialize( aArguments );
uno::Reference< beans::XPropertySet > xInfoSet( getImportInfo() );
if( xInfoSet.is() )
{
uno::Reference< beans::XPropertySetInfo > xInfoSetInfo( xInfoSet->getPropertySetInfo() );
if( xInfoSetInfo->hasPropertyByName( gsPageLayouts ) )
xInfoSet->getPropertyValue( gsPageLayouts ) >>= mxPageLayouts;
if( xInfoSetInfo->hasPropertyByName( gsPreview ) )
xInfoSet->getPropertyValue( gsPreview ) >>= mbPreview;
OUString const sOrganizerMode(
"OrganizerMode");
if (xInfoSetInfo->hasPropertyByName(sOrganizerMode))
{
bool bStyleOnly(false);
if (xInfoSet->getPropertyValue(sOrganizerMode) >>= bStyleOnly)
{
mbLoadDoc = !bStyleOnly;
}
}
}
}
const SvXMLTokenMap& SdXMLImport::GetBodyElemTokenMap()
{
if(!mpBodyElemTokenMap)
{
static const SvXMLTokenMapEntry aBodyElemTokenMap[] =
{
{ XML_NAMESPACE_DRAW, XML_PAGE, XML_TOK_BODY_PAGE },
{ XML_NAMESPACE_PRESENTATION, XML_SETTINGS, XML_TOK_BODY_SETTINGS },
{ XML_NAMESPACE_PRESENTATION, XML_HEADER_DECL, XML_TOK_BODY_HEADER_DECL },
{ XML_NAMESPACE_PRESENTATION, XML_FOOTER_DECL, XML_TOK_BODY_FOOTER_DECL },
{ XML_NAMESPACE_PRESENTATION, XML_DATE_TIME_DECL,XML_TOK_BODY_DATE_TIME_DECL },
XML_TOKEN_MAP_END
};
mpBodyElemTokenMap = std::make_unique<SvXMLTokenMap>(aBodyElemTokenMap);
}
return *mpBodyElemTokenMap;
}
const SvXMLTokenMap& SdXMLImport::GetStylesElemTokenMap()
{
if(!mpStylesElemTokenMap)
{
static const SvXMLTokenMapEntry aStylesElemTokenMap[] =
{
{ XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT, XML_TOK_STYLES_PAGE_MASTER },
{ XML_NAMESPACE_STYLE, XML_PRESENTATION_PAGE_LAYOUT, XML_TOK_STYLES_PRESENTATION_PAGE_LAYOUT },
{ XML_NAMESPACE_STYLE, XML_STYLE, XML_TOK_STYLES_STYLE },
XML_TOKEN_MAP_END
};
mpStylesElemTokenMap = std::make_unique<SvXMLTokenMap>(aStylesElemTokenMap);
}
return *mpStylesElemTokenMap;
}
const SvXMLTokenMap& SdXMLImport::GetMasterPageElemTokenMap()
{
if(!mpMasterPageElemTokenMap)
{
static const SvXMLTokenMapEntry aMasterPageElemTokenMap[] =
{
{ XML_NAMESPACE_STYLE, XML_STYLE, XML_TOK_MASTERPAGE_STYLE },
{ XML_NAMESPACE_PRESENTATION, XML_NOTES, XML_TOK_MASTERPAGE_NOTES },
XML_TOKEN_MAP_END
};
mpMasterPageElemTokenMap = std::make_unique<SvXMLTokenMap>(aMasterPageElemTokenMap);
}
return *mpMasterPageElemTokenMap;
}
const SvXMLTokenMap& SdXMLImport::GetPageMasterAttrTokenMap()
{
if(!mpPageMasterAttrTokenMap)
{
static const SvXMLTokenMapEntry aPageMasterAttrTokenMap[] =
{
{ XML_NAMESPACE_STYLE, XML_NAME, XML_TOK_PAGEMASTER_NAME },
XML_TOKEN_MAP_END
};
mpPageMasterAttrTokenMap = std::make_unique<SvXMLTokenMap>(aPageMasterAttrTokenMap);
}
return *mpPageMasterAttrTokenMap;
}
const SvXMLTokenMap& SdXMLImport::GetPageMasterStyleAttrTokenMap()
{
if(!mpPageMasterStyleAttrTokenMap)
{
static const SvXMLTokenMapEntry aPageMasterStyleAttrTokenMap[] =
{
{ XML_NAMESPACE_FO, XML_MARGIN_TOP, XML_TOK_PAGEMASTERSTYLE_MARGIN_TOP },
{ XML_NAMESPACE_FO, XML_MARGIN_BOTTOM, XML_TOK_PAGEMASTERSTYLE_MARGIN_BOTTOM },
{ XML_NAMESPACE_FO, XML_MARGIN_LEFT, XML_TOK_PAGEMASTERSTYLE_MARGIN_LEFT },
{ XML_NAMESPACE_FO, XML_MARGIN_RIGHT, XML_TOK_PAGEMASTERSTYLE_MARGIN_RIGHT },
{ XML_NAMESPACE_FO, XML_PAGE_WIDTH, XML_TOK_PAGEMASTERSTYLE_PAGE_WIDTH },
{ XML_NAMESPACE_FO, XML_PAGE_HEIGHT, XML_TOK_PAGEMASTERSTYLE_PAGE_HEIGHT },
{ XML_NAMESPACE_STYLE, XML_PRINT_ORIENTATION, XML_TOK_PAGEMASTERSTYLE_PAGE_ORIENTATION },
XML_TOKEN_MAP_END
};
mpPageMasterStyleAttrTokenMap = std::make_unique<SvXMLTokenMap>(aPageMasterStyleAttrTokenMap);
}
return *mpPageMasterStyleAttrTokenMap;
}
const SvXMLTokenMap& SdXMLImport::GetPresentationPlaceholderAttrTokenMap()
{
if(!mpPresentationPlaceholderAttrTokenMap)
{
static const SvXMLTokenMapEntry aPresentationPlaceholderAttrTokenMap[] =
{
{ XML_NAMESPACE_PRESENTATION, XML_OBJECT, XML_TOK_PRESENTATIONPLACEHOLDER_OBJECTNAME },
{ XML_NAMESPACE_SVG, XML_X, XML_TOK_PRESENTATIONPLACEHOLDER_X },
{ XML_NAMESPACE_SVG, XML_Y, XML_TOK_PRESENTATIONPLACEHOLDER_Y },
{ XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_PRESENTATIONPLACEHOLDER_WIDTH },
{ XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_PRESENTATIONPLACEHOLDER_HEIGHT },
XML_TOKEN_MAP_END
};
mpPresentationPlaceholderAttrTokenMap = std::make_unique<SvXMLTokenMap>(aPresentationPlaceholderAttrTokenMap);
}
return *mpPresentationPlaceholderAttrTokenMap;
}
SvXMLImportContext *SdXMLImport::CreateFastContext( sal_Int32 nElement,
const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
{
SvXMLImportContext* pContext = nullptr;
switch (nElement)
{
case XML_ELEMENT( OFFICE, XML_DOCUMENT_STYLES ):
case XML_ELEMENT( OFFICE, XML_DOCUMENT_CONTENT ):
case XML_ELEMENT( OFFICE, XML_DOCUMENT_SETTINGS ):
pContext = new SdXMLDocContext_Impl(*this);
break;
case XML_ELEMENT( OFFICE, XML_DOCUMENT_META ):
pContext = CreateMetaContext(nElement, xAttrList);
break;
case XML_ELEMENT( OFFICE, XML_DOCUMENT ):
{
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
GetModel(), uno::UNO_QUERY_THROW);
// flat OpenDocument file format
pContext = new SdXMLFlatDocContext_Impl( *this, xDPS->getDocumentProperties());
}
break;
}
return pContext;
}
SvXMLImportContext *SdXMLImport::CreateMetaContext(const sal_Int32 /*nElement*/,
const uno::Reference<xml::sax::XFastAttributeList>&)
{
SvXMLImportContext* pContext = nullptr;
if (getImportFlags() & SvXMLImportFlags::META)
{
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
GetModel(), uno::UNO_QUERY_THROW);
uno::Reference<document::XDocumentProperties> const xDocProps(
!mbLoadDoc ? nullptr : xDPS->getDocumentProperties());
pContext = new SvXMLMetaDocumentContext(*this, xDocProps);
}
return pContext;
}
SvXMLStylesContext *SdXMLImport::CreateStylesContext()
{
if(GetShapeImport()->GetStylesContext())
return GetShapeImport()->GetStylesContext();
GetShapeImport()->SetStylesContext(new SdXMLStylesContext(
*this, false));
return GetShapeImport()->GetStylesContext();
}
SvXMLStylesContext *SdXMLImport::CreateAutoStylesContext()
{
if(GetShapeImport()->GetAutoStylesContext())
return GetShapeImport()->GetAutoStylesContext();
GetShapeImport()->SetAutoStylesContext(new SdXMLStylesContext(
*this, true));
return GetShapeImport()->GetAutoStylesContext();
}
SvXMLImportContext* SdXMLImport::CreateMasterStylesContext()
{
if (!mxMasterStylesContext.is())
mxMasterStylesContext.set(new SdXMLMasterStylesContext(*this));
return mxMasterStylesContext.get();
}
SvXMLImportContext *SdXMLImport::CreateFontDeclsContext()
{
XMLFontStylesContext *pFSContext =
new XMLFontStylesContext( *this, osl_getThreadTextEncoding() );
SetFontDecls( pFSContext );
return pFSContext;
}
void SdXMLImport::SetViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& aViewProps)
{
uno::Reference< beans::XPropertySet > xPropSet( GetModel(), uno::UNO_QUERY );
if( !xPropSet.is() )
return;
awt::Rectangle aVisArea( 0,0, 28000, 21000 );
for( const auto& rViewProp : aViewProps )
{
const OUString& rName = rViewProp.Name;
const uno::Any rValue = rViewProp.Value;
if ( rName == "VisibleAreaTop" )
{
rValue >>= aVisArea.Y;
}
else if ( rName == "VisibleAreaLeft" )
{
rValue >>= aVisArea.X;
}
else if ( rName == "VisibleAreaWidth" )
{
rValue >>= aVisArea.Width;
}
else if ( rName == "VisibleAreaHeight" )
{
rValue >>= aVisArea.Height;
}
}
try
{
xPropSet->setPropertyValue("VisibleArea", uno::makeAny( aVisArea ) );
}
catch(const css::uno::Exception&)
{
/* #i79978# since old documents may contain invalid view settings, this is nothing to worry the user about.
uno::Sequence<OUString> aSeq(0);
SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, aSeq, e.Message, NULL );
*/
}
}
void SdXMLImport::SetConfigurationSettings(const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps)
{
uno::Reference< lang::XMultiServiceFactory > xFac( GetModel(), uno::UNO_QUERY );
if( !xFac.is() )
return;
uno::Reference< beans::XPropertySet > xProps( xFac->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY );
if( !xProps.is() )
return;
uno::Reference< beans::XPropertySetInfo > xInfo( xProps->getPropertySetInfo() );
if( !xInfo.is() )
return;
const uno::Sequence<beans::PropertyValue>* pValues = &aConfigProps;
DocumentSettingsSerializer *pFilter;
pFilter = dynamic_cast<DocumentSettingsSerializer *>(xProps.get());
uno::Sequence<beans::PropertyValue> aFiltered;
if( pFilter )
{
aFiltered = pFilter->filterStreamsFromStorage( GetDocumentBase(), GetSourceStorage(), aConfigProps );
pValues = &aFiltered;
}
for( const auto& rValue : *pValues )
{
try
{
const OUString& rProperty = rValue.Name;
if( xInfo->hasPropertyByName( rProperty ) )
xProps->setPropertyValue( rProperty, rValue.Value );
}
catch(const uno::Exception&)
{
SAL_INFO("xmloff.draw", "#SdXMLImport::SetConfigurationSettings: Exception!" );
}
}
}
// #80365# override this method to read and use the hint value from the
// written meta information. If no info is found, guess 10 draw objects
//void SdXMLImport::SetStatisticAttributes(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
void SdXMLImport::SetStatistics(
const uno::Sequence<beans::NamedValue> & i_rStats)
{
static const char* s_stats[] =
{ "ObjectCount", nullptr };
SvXMLImport::SetStatistics(i_rStats);
sal_uInt32 nCount(10);
for (const auto& rStat : i_rStats) {
for (const char** pStat = s_stats; *pStat != nullptr; ++pStat) {
if (rStat.Name.equalsAscii(*pStat)) {
sal_Int32 val = 0;
if (rStat.Value >>= val) {
nCount = val;
} else {
SAL_WARN("xmloff.draw", "SdXMLImport::SetStatistics: invalid entry");
}
}
}
}
if(nCount)
{
GetProgressBarHelper()->SetReference(nCount);
GetProgressBarHelper()->SetValue(0);
}
}
void SdXMLImport::AddHeaderDecl( const OUString& rName, const OUString& rText )
{
if( !rName.isEmpty() && !rText.isEmpty() )
maHeaderDeclsMap[rName] = rText;
}
void SdXMLImport::AddFooterDecl( const OUString& rName, const OUString& rText )
{
if( !rName.isEmpty() && !rText.isEmpty() )
maFooterDeclsMap[rName] = rText;
}
void SdXMLImport::AddDateTimeDecl( const OUString& rName, const OUString& rText, bool bFixed, const OUString& rDateTimeFormat )
{
if( !rName.isEmpty() && (!rText.isEmpty() || !bFixed) )
{
DateTimeDeclContextImpl aDecl;
aDecl.maStrText = rText;
aDecl.mbFixed = bFixed;
aDecl.maStrDateTimeFormat = rDateTimeFormat;
maDateTimeDeclsMap[rName] = aDecl;
}
}
OUString SdXMLImport::GetHeaderDecl( const OUString& rName ) const
{
OUString aRet;
HeaderFooterDeclMap::const_iterator aIter( maHeaderDeclsMap.find( rName ) );
if( aIter != maHeaderDeclsMap.end() )
aRet = (*aIter).second;
return aRet;
}
OUString SdXMLImport::GetFooterDecl( const OUString& rName ) const
{
OUString aRet;
HeaderFooterDeclMap::const_iterator aIter( maFooterDeclsMap.find( rName ) );
if( aIter != maFooterDeclsMap.end() )
aRet = (*aIter).second;
return aRet;
}
OUString SdXMLImport::GetDateTimeDecl( const OUString& rName, bool& rbFixed, OUString& rDateTimeFormat )
{
DateTimeDeclContextImpl aDecl;
DateTimeDeclMap::const_iterator aIter( maDateTimeDeclsMap.find( rName ) );
if( aIter != maDateTimeDeclsMap.end() )
aDecl = (*aIter).second;
rbFixed = aDecl.mbFixed;
rDateTimeFormat = aDecl.maStrDateTimeFormat;
return aDecl.maStrText;
}
void SdXMLImport::NotifyEmbeddedFontRead()
{
uno::Reference< lang::XMultiServiceFactory > xFac( GetModel(), uno::UNO_QUERY );
if( xFac.is() )
{
uno::Reference< beans::XPropertySet > xProps( xFac->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY );
if( xProps.is() )
xProps->setPropertyValue("EmbedFonts", uno::makeAny( true ) );
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|