Coverage Report

Created: 2026-02-14 09:37

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