Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLSectionExport.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 "XMLSectionExport.hxx"
21
#include <o3tl/any.hxx>
22
#include <rtl/ustring.hxx>
23
#include <rtl/ustrbuf.hxx>
24
#include <osl/diagnose.h>
25
#include <com/sun/star/frame/XModel.hpp>
26
#include <com/sun/star/lang/Locale.hpp>
27
#include <com/sun/star/container/XIndexReplace.hpp>
28
#include <com/sun/star/beans/XPropertySet.hpp>
29
#include <com/sun/star/beans/PropertyValue.hpp>
30
#include <com/sun/star/beans/PropertyValues.hpp>
31
#include <com/sun/star/text/XTextSection.hpp>
32
#include <com/sun/star/text/SectionFileLink.hpp>
33
#include <com/sun/star/container/XNamed.hpp>
34
#include <com/sun/star/container/XNameAccess.hpp>
35
#include <com/sun/star/text/XDocumentIndex.hpp>
36
#include <com/sun/star/text/BibliographyDataField.hpp>
37
#include <com/sun/star/text/XTextFieldsSupplier.hpp>
38
#include <com/sun/star/text/XChapterNumberingSupplier.hpp>
39
#include <com/sun/star/text/ChapterFormat.hpp>
40
41
#include <comphelper/base64.hxx>
42
43
#include <xmloff/xmltoken.hxx>
44
#include <xmloff/xmlnamespace.hxx>
45
#include <xmloff/families.hxx>
46
#include <xmloff/xmluconv.hxx>
47
#include <xmloff/namespacemap.hxx>
48
#include <xmloff/xmlexp.hxx>
49
#include <xmloff/xmlement.hxx>
50
#include <txtflde.hxx>
51
52
53
using namespace ::com::sun::star;
54
using namespace ::com::sun::star::text;
55
using namespace ::com::sun::star::uno;
56
using namespace ::xmloff::token;
57
58
using ::com::sun::star::beans::XPropertySet;
59
using ::com::sun::star::beans::PropertyValue;
60
using ::com::sun::star::beans::PropertyValues;
61
using ::com::sun::star::container::XIndexReplace;
62
using ::com::sun::star::container::XNameAccess;
63
using ::com::sun::star::container::XNamed;
64
using ::com::sun::star::lang::Locale;
65
66
67
XMLSectionExport::XMLSectionExport(
68
    SvXMLExport& rExp,
69
    XMLTextParagraphExport& rParaExp)
70
0
:   rExport(rExp)
71
0
,   rParaExport(rParaExp)
72
0
,   bHeadingDummiesExported( false )
73
0
{
74
0
}
75
76
77
void XMLSectionExport::ExportSectionStart(
78
    const Reference<XTextSection> & rSection,
79
    bool bAutoStyles)
80
0
{
81
0
    Reference<XPropertySet> xPropertySet(rSection, UNO_QUERY);
82
83
    // always export section (auto) style
84
0
    if (bAutoStyles)
85
0
    {
86
        // get PropertySet and add section style
87
0
        GetParaExport().Add( XmlStyleFamily::TEXT_SECTION, xPropertySet );
88
0
    }
89
0
    else
90
0
    {
91
        // always export section style
92
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
93
0
                                     GetParaExport().Find(
94
0
                                     XmlStyleFamily::TEXT_SECTION,
95
0
                                     xPropertySet, u""_ustr ) );
96
97
        // xml:id for RDF metadata
98
0
        GetExport().AddAttributeXmlId(rSection);
99
100
        // export index or regular section
101
0
        Reference<XDocumentIndex> xIndex;
102
0
        if (GetIndex(rSection, xIndex))
103
0
        {
104
0
            if (xIndex.is())
105
0
            {
106
                // we are an index
107
0
                ExportIndexStart(xIndex);
108
0
            }
109
0
            else
110
0
            {
111
                // we are an index header
112
0
                ExportIndexHeaderStart(rSection);
113
0
            }
114
0
        }
115
0
        else
116
0
        {
117
            // we are not an index
118
0
            ExportRegularSectionStart(rSection);
119
0
        }
120
0
    }
121
0
}
122
123
bool XMLSectionExport::GetIndex(
124
    const Reference<XTextSection> & rSection,
125
    Reference<XDocumentIndex> & rIndex)
126
0
{
127
    // first, reset result
128
0
    bool bRet = false;
129
0
    rIndex = nullptr;
130
131
    // get section Properties
132
0
    Reference<XPropertySet> xSectionPropSet(rSection, UNO_QUERY);
133
134
    // then check if this section happens to be inside an index
135
0
    if (xSectionPropSet->getPropertySetInfo()->
136
0
                                    hasPropertyByName(u"DocumentIndex"_ustr))
137
0
    {
138
0
        Any aAny = xSectionPropSet->getPropertyValue(u"DocumentIndex"_ustr);
139
0
        Reference<XDocumentIndex> xDocumentIndex;
140
0
        aAny >>= xDocumentIndex;
141
142
        // OK, are we inside of an index
143
0
        if (xDocumentIndex.is())
144
0
        {
145
            // is the enclosing index identical with "our" section?
146
0
            Reference<XPropertySet> xIndexPropSet(xDocumentIndex, UNO_QUERY);
147
0
            aAny = xIndexPropSet->getPropertyValue(u"ContentSection"_ustr);
148
0
            Reference<XTextSection> xEnclosingSection;
149
0
            aAny >>= xEnclosingSection;
150
151
            // if the enclosing section is "our" section, then we are an index!
152
0
            if (rSection == xEnclosingSection)
153
0
            {
154
0
                rIndex = std::move(xDocumentIndex);
155
0
                bRet = true;
156
0
            }
157
            // else: index header or regular section
158
159
            // is the enclosing index identical with the header section?
160
0
            aAny = xIndexPropSet->getPropertyValue(u"HeaderSection"_ustr);
161
            // now mis-named: contains header section
162
0
            aAny >>= xEnclosingSection;
163
164
            // if the enclosing section is "our" section, then we are an index!
165
0
            if (rSection == xEnclosingSection)
166
0
            {
167
0
                bRet = true;
168
0
            }
169
            // else: regular section
170
0
        }
171
        // else: we aren't even inside of an index
172
0
    }
173
    // else: we don't even know what an index is.
174
175
0
    return bRet;
176
0
}
177
178
179
void XMLSectionExport::ExportSectionEnd(
180
    const Reference<XTextSection> & rSection,
181
    bool bAutoStyles)
182
0
{
183
    // no end section for styles
184
0
    if (bAutoStyles)
185
0
        return;
186
187
0
    enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
188
189
    // export index or regular section end
190
0
    Reference<XDocumentIndex> xIndex;
191
0
    if (GetIndex(rSection, xIndex))
192
0
    {
193
0
        if (xIndex.is())
194
0
        {
195
            // index end: close index body element
196
0
            GetExport().EndElement( XML_NAMESPACE_TEXT, XML_INDEX_BODY,
197
0
                                    true );
198
0
            GetExport().IgnorableWhitespace();
199
200
0
            switch (MapSectionType(xIndex->getServiceName()))
201
0
            {
202
0
                case TEXT_SECTION_TYPE_TOC:
203
0
                    eElement = XML_TABLE_OF_CONTENT;
204
0
                    break;
205
206
0
                case TEXT_SECTION_TYPE_ILLUSTRATION:
207
0
                    eElement = XML_ILLUSTRATION_INDEX;
208
0
                    break;
209
210
0
                case TEXT_SECTION_TYPE_ALPHABETICAL:
211
0
                    eElement = XML_ALPHABETICAL_INDEX;
212
0
                    break;
213
214
0
                case TEXT_SECTION_TYPE_TABLE:
215
0
                    eElement = XML_TABLE_INDEX;
216
0
                    break;
217
218
0
                case TEXT_SECTION_TYPE_OBJECT:
219
0
                    eElement = XML_OBJECT_INDEX;
220
0
                    break;
221
222
0
                case TEXT_SECTION_TYPE_USER:
223
0
                    eElement = XML_USER_INDEX;
224
0
                    break;
225
226
0
                case TEXT_SECTION_TYPE_BIBLIOGRAPHY:
227
0
                    eElement = XML_BIBLIOGRAPHY;
228
0
                    break;
229
230
0
                default:
231
0
                    OSL_FAIL("unknown index type");
232
                    // default: skip index!
233
0
                    break;
234
0
            }
235
0
        }
236
0
        else
237
0
        {
238
0
            eElement = XML_INDEX_TITLE;
239
0
        }
240
0
    }
241
0
    else
242
0
    {
243
0
        eElement = XML_SECTION;
244
0
    }
245
246
0
    if (XML_TOKEN_INVALID != eElement)
247
0
    {
248
        // any old attributes?
249
0
        GetExport().CheckAttrList();
250
251
        // element surrounded by whitespace
252
0
        GetExport().EndElement( XML_NAMESPACE_TEXT, eElement, true);
253
0
        GetExport().IgnorableWhitespace();
254
0
    }
255
0
    else
256
0
    {
257
0
        OSL_FAIL("Need element name!");
258
0
    }
259
    // else: autostyles -> ignore
260
0
}
261
262
void XMLSectionExport::ExportIndexStart(
263
    const Reference<XDocumentIndex> & rIndex)
264
0
{
265
    // get PropertySet
266
0
    Reference<XPropertySet> xPropertySet(rIndex, UNO_QUERY);
267
268
0
    switch (MapSectionType(rIndex->getServiceName()))
269
0
    {
270
0
        case TEXT_SECTION_TYPE_TOC:
271
0
            ExportTableOfContentStart(xPropertySet);
272
0
            break;
273
274
0
        case TEXT_SECTION_TYPE_ILLUSTRATION:
275
0
            ExportIllustrationIndexStart(xPropertySet);
276
0
            break;
277
278
0
        case TEXT_SECTION_TYPE_ALPHABETICAL:
279
0
            ExportAlphabeticalIndexStart(xPropertySet);
280
0
            break;
281
282
0
        case TEXT_SECTION_TYPE_TABLE:
283
0
            ExportTableIndexStart(xPropertySet);
284
0
            break;
285
286
0
        case TEXT_SECTION_TYPE_OBJECT:
287
0
            ExportObjectIndexStart(xPropertySet);
288
0
            break;
289
290
0
        case TEXT_SECTION_TYPE_USER:
291
0
            ExportUserIndexStart(xPropertySet);
292
0
            break;
293
294
0
        case TEXT_SECTION_TYPE_BIBLIOGRAPHY:
295
0
            ExportBibliographyStart(xPropertySet);
296
0
            break;
297
298
0
        default:
299
            // skip index
300
0
            OSL_FAIL("unknown index type");
301
0
            break;
302
0
    }
303
0
}
304
305
void XMLSectionExport::ExportIndexHeaderStart(
306
    const Reference<XTextSection> & rSection)
307
0
{
308
    // export name, dammit!
309
0
    Reference<XNamed> xName(rSection, UNO_QUERY);
310
0
    GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xName->getName());
311
0
    Reference<XPropertySet> xPropSet(rSection, UNO_QUERY);
312
0
    Any aAny = xPropSet->getPropertyValue(u"IsProtected"_ustr);
313
0
    if (*o3tl::doAccess<bool>(aAny))
314
0
    {
315
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TRUE);
316
0
    }
317
318
    // format already handled -> export only start element
319
0
    GetExport().StartElement( XML_NAMESPACE_TEXT, XML_INDEX_TITLE, true );
320
0
    GetExport().IgnorableWhitespace();
321
0
}
322
323
324
SvXMLEnumStringMapEntry<SectionTypeEnum> const aIndexTypeMap[] =
325
{
326
    ENUM_STRING_MAP_ENTRY( "com.sun.star.text.ContentIndex", TEXT_SECTION_TYPE_TOC ),
327
    ENUM_STRING_MAP_ENTRY( "com.sun.star.text.DocumentIndex", TEXT_SECTION_TYPE_ALPHABETICAL ),
328
    ENUM_STRING_MAP_ENTRY( "com.sun.star.text.TableIndex", TEXT_SECTION_TYPE_TABLE ),
329
    ENUM_STRING_MAP_ENTRY( "com.sun.star.text.ObjectIndex", TEXT_SECTION_TYPE_OBJECT ),
330
    ENUM_STRING_MAP_ENTRY( "com.sun.star.text.Bibliography", TEXT_SECTION_TYPE_BIBLIOGRAPHY ),
331
    ENUM_STRING_MAP_ENTRY( "com.sun.star.text.UserIndex", TEXT_SECTION_TYPE_USER ),
332
    ENUM_STRING_MAP_ENTRY( "com.sun.star.text.IllustrationsIndex", TEXT_SECTION_TYPE_ILLUSTRATION ),
333
    { nullptr, 0, SectionTypeEnum(0) }
334
};
335
336
enum SectionTypeEnum XMLSectionExport::MapSectionType(
337
    std::u16string_view rServiceName)
338
0
{
339
0
    enum SectionTypeEnum eType = TEXT_SECTION_TYPE_UNKNOWN;
340
341
0
    SvXMLUnitConverter::convertEnum(eType, rServiceName, aIndexTypeMap);
342
343
    // TODO: index header section types, etc.
344
345
0
    return eType;
346
0
}
347
348
void XMLSectionExport::ExportRegularSectionStart(
349
    const Reference<XTextSection> & rSection)
350
0
{
351
    // style name already handled in ExportSectionStart(...)
352
353
0
    Reference<XNamed> xName(rSection, UNO_QUERY);
354
0
    GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xName->getName());
355
356
    // get XPropertySet for other values
357
0
    Reference<XPropertySet> xPropSet(rSection, UNO_QUERY);
358
359
    // condition and display
360
0
    Any aAny = xPropSet->getPropertyValue(u"Condition"_ustr);
361
0
    OUString sCond;
362
0
    aAny >>= sCond;
363
0
    enum XMLTokenEnum eDisplay = XML_TOKEN_INVALID;
364
0
    if (!sCond.isEmpty())
365
0
    {
366
0
        OUString sQValue =
367
0
            GetExport().GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_OOOW,
368
0
                                                         sCond, false );
369
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_CONDITION, sQValue);
370
0
        eDisplay = XML_CONDITION;
371
372
        // #97450# store hidden-status (of conditional sections only)
373
0
        aAny = xPropSet->getPropertyValue(u"IsCurrentlyVisible"_ustr);
374
0
        if (! *o3tl::doAccess<bool>(aAny))
375
0
        {
376
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_IS_HIDDEN,
377
0
                                     XML_TRUE);
378
0
        }
379
0
    }
380
0
    else
381
0
    {
382
0
        eDisplay = XML_NONE;
383
0
    }
384
0
    aAny = xPropSet->getPropertyValue(u"IsVisible"_ustr);
385
0
    if (! *o3tl::doAccess<bool>(aAny))
386
0
    {
387
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_DISPLAY, eDisplay);
388
0
    }
389
390
    // protect + protection key
391
0
    aAny = xPropSet->getPropertyValue(u"IsProtected"_ustr);
392
0
    if (*o3tl::doAccess<bool>(aAny))
393
0
    {
394
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TRUE);
395
0
    }
396
0
    Sequence<sal_Int8> aPassword;
397
0
    xPropSet->getPropertyValue(u"ProtectionKey"_ustr) >>= aPassword;
398
0
    if (aPassword.hasElements())
399
0
    {
400
0
        OUStringBuffer aBuffer;
401
0
        ::comphelper::Base64::encode(aBuffer, aPassword);
402
        // in ODF 1.0/1.1 the algorithm was left unspecified so we can write anything
403
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTION_KEY,
404
0
                                 aBuffer.makeStringAndClear());
405
0
        if (aPassword.getLength() == 32 && GetExport().getSaneDefaultVersion() >= SvtSaveOptions::ODFSVER_012)
406
0
        {
407
            // attribute exists in ODF 1.2 or later; default is SHA1 so no need to write that
408
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTION_KEY_DIGEST_ALGORITHM,
409
                    // write the URL from ODF 1.2, not the W3C one
410
0
                    u"http://www.w3.org/2000/09/xmldsig#sha256"_ustr);
411
0
        }
412
0
    }
413
414
    // export element
415
0
    GetExport().IgnorableWhitespace();
416
0
    GetExport().StartElement( XML_NAMESPACE_TEXT, XML_SECTION, true );
417
418
    // data source
419
    // unfortunately, we have to test all relevant strings for non-zero length
420
0
    aAny = xPropSet->getPropertyValue(u"FileLink"_ustr);
421
0
    SectionFileLink aFileLink;
422
0
    aAny >>= aFileLink;
423
424
0
    aAny = xPropSet->getPropertyValue(u"LinkRegion"_ustr);
425
0
    OUString sRegionName;
426
0
    aAny >>= sRegionName;
427
428
0
    if ( !aFileLink.FileURL.isEmpty() ||
429
0
         !aFileLink.FilterName.isEmpty() ||
430
0
         !sRegionName.isEmpty())
431
0
    {
432
0
        if (!aFileLink.FileURL.isEmpty())
433
0
        {
434
0
            GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF,
435
0
                                     GetExport().GetRelativeReference( aFileLink.FileURL) );
436
0
        }
437
438
0
        if (!aFileLink.FilterName.isEmpty())
439
0
        {
440
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FILTER_NAME,
441
0
                                     aFileLink.FilterName);
442
0
        }
443
444
0
        if (!sRegionName.isEmpty())
445
0
        {
446
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_SECTION_NAME,
447
0
                                     sRegionName);
448
0
        }
449
450
0
        SvXMLElementExport aElem(GetExport(),
451
0
                                 XML_NAMESPACE_TEXT, XML_SECTION_SOURCE,
452
0
                                 true, true);
453
0
    }
454
0
    else
455
0
    {
456
        // check for DDE first
457
0
        if (xPropSet->getPropertySetInfo()->hasPropertyByName(u"DDECommandFile"_ustr))
458
0
        {
459
            // data source DDE
460
            // unfortunately, we have to test all relevant strings for
461
            // non-zero length
462
0
            aAny = xPropSet->getPropertyValue(u"DDECommandFile"_ustr);
463
0
            OUString sApplication;
464
0
            aAny >>= sApplication;
465
0
            aAny = xPropSet->getPropertyValue(u"DDECommandType"_ustr);
466
0
            OUString sTopic;
467
0
            aAny >>= sTopic;
468
0
            aAny = xPropSet->getPropertyValue(u"DDECommandElement"_ustr);
469
0
            OUString sItem;
470
0
            aAny >>= sItem;
471
472
0
            if ( !sApplication.isEmpty() ||
473
0
                 !sTopic.isEmpty() ||
474
0
                 !sItem.isEmpty())
475
0
            {
476
0
                GetExport().AddAttribute(XML_NAMESPACE_OFFICE,
477
0
                                         XML_DDE_APPLICATION, sApplication);
478
0
                GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_TOPIC,
479
0
                                         sTopic);
480
0
                GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_DDE_ITEM,
481
0
                                         sItem);
482
483
0
                aAny = xPropSet->getPropertyValue(u"IsAutomaticUpdate"_ustr);
484
0
                if (*o3tl::doAccess<bool>(aAny))
485
0
                {
486
0
                    GetExport().AddAttribute(XML_NAMESPACE_OFFICE,
487
0
                                             XML_AUTOMATIC_UPDATE, XML_TRUE);
488
0
                }
489
490
0
                SvXMLElementExport aElem(GetExport(),
491
0
                                         XML_NAMESPACE_OFFICE,
492
0
                                         XML_DDE_SOURCE, true, true);
493
0
            }
494
            // else: no DDE data source
495
0
        }
496
        // else: no DDE on this system
497
0
    }
498
0
}
499
500
void XMLSectionExport::ExportTableOfContentStart(
501
    const Reference<XPropertySet> & rPropertySet)
502
0
{
503
    // export TOC element start
504
0
    ExportBaseIndexStart(XML_TABLE_OF_CONTENT, rPropertySet);
505
506
    // scope for table-of-content-source element
507
0
    {
508
        // TOC specific index source attributes:
509
510
        // outline-level: 1..10
511
0
        sal_Int16 nLevel = sal_Int16();
512
0
        if( rPropertySet->getPropertyValue(u"Level"_ustr) >>= nLevel )
513
0
        {
514
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT,
515
0
                                     XML_OUTLINE_LEVEL,
516
0
                                     OUString::number(nLevel));
517
0
        }
518
519
        // use outline level
520
0
        ExportBoolean(rPropertySet, u"CreateFromOutline"_ustr,
521
0
                          XML_USE_OUTLINE_LEVEL, true);
522
523
        // use index marks
524
0
        ExportBoolean(rPropertySet, u"CreateFromMarks"_ustr,
525
0
                      XML_USE_INDEX_MARKS, true);
526
527
        // use level styles
528
0
        ExportBoolean(rPropertySet, u"CreateFromLevelParagraphStyles"_ustr,
529
0
                      XML_USE_INDEX_SOURCE_STYLES, false);
530
531
0
        ExportBaseIndexSource(TEXT_SECTION_TYPE_TOC, rPropertySet);
532
0
    }
533
534
0
    ExportBaseIndexBody(TEXT_SECTION_TYPE_TOC, rPropertySet);
535
0
}
536
537
void XMLSectionExport::ExportObjectIndexStart(
538
    const Reference<XPropertySet> & rPropertySet)
539
0
{
540
    // export index start
541
0
    ExportBaseIndexStart(XML_OBJECT_INDEX, rPropertySet);
542
543
    // scope for index source element
544
0
    {
545
0
        ExportBoolean(rPropertySet, u"CreateFromOtherEmbeddedObjects"_ustr,
546
0
                      XML_USE_OTHER_OBJECTS, false);
547
0
        ExportBoolean(rPropertySet, u"CreateFromStarCalc"_ustr,
548
0
                      XML_USE_SPREADSHEET_OBJECTS, false);
549
0
        ExportBoolean(rPropertySet, u"CreateFromStarChart"_ustr,
550
0
                      XML_USE_CHART_OBJECTS, false);
551
0
        ExportBoolean(rPropertySet, u"CreateFromStarDraw"_ustr,
552
0
                      XML_USE_DRAW_OBJECTS, false);
553
0
        ExportBoolean(rPropertySet, u"CreateFromStarMath"_ustr,
554
0
                      XML_USE_MATH_OBJECTS, false);
555
556
0
        ExportBaseIndexSource(TEXT_SECTION_TYPE_OBJECT, rPropertySet);
557
0
    }
558
559
0
    ExportBaseIndexBody(TEXT_SECTION_TYPE_OBJECT, rPropertySet);
560
0
}
561
562
void XMLSectionExport::ExportIllustrationIndexStart(
563
    const Reference<XPropertySet> & rPropertySet)
564
0
{
565
    // export index start
566
0
    ExportBaseIndexStart(XML_ILLUSTRATION_INDEX, rPropertySet);
567
568
    // scope for index source element
569
0
    {
570
        // export common attributes for illustration and table indices
571
0
        ExportTableAndIllustrationIndexSourceAttributes(rPropertySet);
572
573
0
        ExportBaseIndexSource(TEXT_SECTION_TYPE_ILLUSTRATION, rPropertySet);
574
0
    }
575
576
0
    ExportBaseIndexBody(TEXT_SECTION_TYPE_ILLUSTRATION, rPropertySet);
577
0
}
578
579
void XMLSectionExport::ExportTableIndexStart(
580
    const Reference<XPropertySet> & rPropertySet)
581
0
{
582
    // export index start
583
0
    ExportBaseIndexStart(XML_TABLE_INDEX, rPropertySet);
584
585
    // scope for index source element
586
0
    {
587
        // export common attributes for illustration and table indices
588
0
        ExportTableAndIllustrationIndexSourceAttributes(rPropertySet);
589
590
0
        ExportBaseIndexSource(TEXT_SECTION_TYPE_TABLE, rPropertySet);
591
0
    }
592
593
0
    ExportBaseIndexBody(TEXT_SECTION_TYPE_TABLE, rPropertySet);
594
0
}
595
596
void XMLSectionExport::ExportAlphabeticalIndexStart(
597
    const Reference<XPropertySet> & rPropertySet)
598
0
{
599
    // export TOC element start
600
0
    ExportBaseIndexStart(XML_ALPHABETICAL_INDEX, rPropertySet);
601
602
    // scope for table-of-content-source element
603
0
    {
604
605
        // style name (if present)
606
0
        Any aAny = rPropertySet->getPropertyValue(u"MainEntryCharacterStyleName"_ustr);
607
0
        OUString sStyleName;
608
0
        aAny >>= sStyleName;
609
0
        if (!sStyleName.isEmpty())
610
0
        {
611
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT,
612
0
                                     XML_MAIN_ENTRY_STYLE_NAME,
613
0
                                     GetExport().EncodeStyleName( sStyleName ));
614
0
        }
615
616
        // other (boolean) attributes
617
0
        ExportBoolean(rPropertySet, u"IsCaseSensitive"_ustr, XML_IGNORE_CASE,
618
0
                      false, true);
619
0
        ExportBoolean(rPropertySet, u"UseAlphabeticalSeparators"_ustr,
620
0
                      XML_ALPHABETICAL_SEPARATORS, false);
621
0
        ExportBoolean(rPropertySet, u"UseCombinedEntries"_ustr, XML_COMBINE_ENTRIES,
622
0
                      true);
623
0
        ExportBoolean(rPropertySet, u"UseDash"_ustr, XML_COMBINE_ENTRIES_WITH_DASH,
624
0
                      false);
625
0
        ExportBoolean(rPropertySet, u"UseKeyAsEntry"_ustr, XML_USE_KEYS_AS_ENTRIES,
626
0
                      false);
627
0
        ExportBoolean(rPropertySet, u"UsePP"_ustr, XML_COMBINE_ENTRIES_WITH_PP,
628
0
                      true);
629
0
        ExportBoolean(rPropertySet, u"UseUpperCase"_ustr, XML_CAPITALIZE_ENTRIES,
630
0
                      false);
631
0
        ExportBoolean(rPropertySet, u"IsCommaSeparated"_ustr, XML_COMMA_SEPARATED,
632
0
                      false);
633
634
        // sort algorithm
635
0
        aAny = rPropertySet->getPropertyValue(u"SortAlgorithm"_ustr);
636
0
        OUString sAlgorithm;
637
0
        aAny >>= sAlgorithm;
638
0
        if (!sAlgorithm.isEmpty())
639
0
        {
640
0
            GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_SORT_ALGORITHM,
641
0
                                      sAlgorithm );
642
0
        }
643
644
        // locale
645
0
        aAny = rPropertySet->getPropertyValue(u"Locale"_ustr);
646
0
        Locale aLocale;
647
0
        aAny >>= aLocale;
648
0
        GetExport().AddLanguageTagAttributes( XML_NAMESPACE_FO, XML_NAMESPACE_STYLE, aLocale, true);
649
650
0
        ExportBaseIndexSource(TEXT_SECTION_TYPE_ALPHABETICAL, rPropertySet);
651
0
    }
652
653
0
    ExportBaseIndexBody(TEXT_SECTION_TYPE_ALPHABETICAL, rPropertySet);
654
0
}
655
656
void XMLSectionExport::ExportUserIndexStart(
657
    const Reference<XPropertySet> & rPropertySet)
658
0
{
659
    // export TOC element start
660
0
    ExportBaseIndexStart(XML_USER_INDEX, rPropertySet);
661
662
    // scope for table-of-content-source element
663
0
    {
664
        // bool attributes
665
0
        ExportBoolean(rPropertySet, u"CreateFromEmbeddedObjects"_ustr,
666
0
                      XML_USE_OBJECTS, false);
667
0
        ExportBoolean(rPropertySet, u"CreateFromGraphicObjects"_ustr,
668
0
                      XML_USE_GRAPHICS, false);
669
0
        ExportBoolean(rPropertySet, u"CreateFromMarks"_ustr,
670
0
                      XML_USE_INDEX_MARKS, false);
671
0
        ExportBoolean(rPropertySet, u"CreateFromTables"_ustr,
672
0
                      XML_USE_TABLES, false);
673
0
        ExportBoolean(rPropertySet, u"CreateFromTextFrames"_ustr,
674
0
                      XML_USE_FLOATING_FRAMES, false);
675
0
        ExportBoolean(rPropertySet, u"UseLevelFromSource"_ustr,
676
0
                      XML_COPY_OUTLINE_LEVELS, false);
677
0
        ExportBoolean(rPropertySet, u"CreateFromLevelParagraphStyles"_ustr,
678
0
                      XML_USE_INDEX_SOURCE_STYLES, false);
679
680
0
        Any aAny = rPropertySet->getPropertyValue( u"UserIndexName"_ustr );
681
0
        OUString sIndexName;
682
0
        aAny >>= sIndexName;
683
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_INDEX_NAME,
684
0
                                 sIndexName);
685
686
0
        ExportBaseIndexSource(TEXT_SECTION_TYPE_USER, rPropertySet);
687
0
    }
688
689
0
    ExportBaseIndexBody(TEXT_SECTION_TYPE_USER, rPropertySet);
690
0
}
691
692
void XMLSectionExport::ExportBibliographyStart(
693
    const Reference<XPropertySet> & rPropertySet)
694
0
{
695
    // export TOC element start
696
0
    ExportBaseIndexStart(XML_BIBLIOGRAPHY, rPropertySet);
697
698
    // scope for table-of-content-source element
699
0
    {
700
        // No attributes. Fine.
701
702
0
        ExportBaseIndexSource(TEXT_SECTION_TYPE_BIBLIOGRAPHY, rPropertySet);
703
0
    }
704
705
0
    ExportBaseIndexBody(TEXT_SECTION_TYPE_BIBLIOGRAPHY, rPropertySet);
706
0
}
707
708
709
void XMLSectionExport::ExportBaseIndexStart(
710
    XMLTokenEnum eElement,
711
    const Reference<XPropertySet> & rPropertySet)
712
0
{
713
    // protect + protection key
714
0
    Any aAny = rPropertySet->getPropertyValue(u"IsProtected"_ustr);
715
0
    if (*o3tl::doAccess<bool>(aAny))
716
0
    {
717
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_PROTECTED, XML_TRUE);
718
0
    }
719
720
    // index name
721
0
    OUString sIndexName;
722
0
    rPropertySet->getPropertyValue(u"Name"_ustr) >>= sIndexName;
723
0
    if ( !sIndexName.isEmpty() )
724
0
    {
725
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, sIndexName);
726
0
    }
727
728
    // index  Element start
729
0
    GetExport().IgnorableWhitespace();
730
0
    GetExport().StartElement( XML_NAMESPACE_TEXT, eElement, false );
731
0
}
732
733
const XMLTokenEnum aTypeSourceElementNameMap[] =
734
{
735
    XML_TABLE_OF_CONTENT_SOURCE,        // TOC
736
    XML_TABLE_INDEX_SOURCE,         // table index
737
    XML_ILLUSTRATION_INDEX_SOURCE,      // illustration index
738
    XML_OBJECT_INDEX_SOURCE,            // object index
739
    XML_USER_INDEX_SOURCE,              // user index
740
    XML_ALPHABETICAL_INDEX_SOURCE,      // alphabetical index
741
    XML_BIBLIOGRAPHY_SOURCE         // bibliography
742
};
743
744
void XMLSectionExport::ExportBaseIndexSource(
745
    SectionTypeEnum eType,
746
    const Reference<XPropertySet> & rPropertySet)
747
0
{
748
    // check type
749
0
    OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type");
750
0
    OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type");
751
752
0
    Any aAny;
753
754
    // common attributes; not supported by bibliography
755
0
    if (eType != TEXT_SECTION_TYPE_BIBLIOGRAPHY)
756
0
    {
757
        // document or chapter index?
758
0
        aAny = rPropertySet->getPropertyValue(u"CreateFromChapter"_ustr);
759
0
        if (*o3tl::doAccess<bool>(aAny))
760
0
        {
761
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT,
762
0
                                     XML_INDEX_SCOPE, XML_CHAPTER);
763
0
        }
764
765
        // tab-stops relative to margin?
766
0
        aAny = rPropertySet->getPropertyValue(u"IsRelativeTabstops"_ustr);
767
0
        if (! *o3tl::doAccess<bool>(aAny))
768
0
        {
769
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT,
770
0
                                     XML_RELATIVE_TAB_STOP_POSITION,
771
0
                                     XML_FALSE);
772
0
        }
773
0
    }
774
775
    // the index source element (all indices)
776
0
    SvXMLElementExport aElem(GetExport(),
777
0
                             XML_NAMESPACE_TEXT,
778
0
                             GetXMLToken(
779
0
                                 aTypeSourceElementNameMap[
780
0
                                    eType - TEXT_SECTION_TYPE_TOC]),
781
0
                             true, true);
782
783
    // scope for title template (all indices)
784
0
    {
785
        // header style name
786
0
        aAny = rPropertySet->getPropertyValue(u"ParaStyleHeading"_ustr);
787
0
        OUString sStyleName;
788
0
        aAny >>= sStyleName;
789
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT,
790
0
                                 XML_STYLE_NAME,
791
0
                                 GetExport().EncodeStyleName( sStyleName ));
792
793
        // title template
794
0
        SvXMLElementExport aHeaderTemplate(GetExport(),
795
0
                                           XML_NAMESPACE_TEXT,
796
0
                                           XML_INDEX_TITLE_TEMPLATE,
797
0
                                           true, false);
798
799
        // title as element content
800
0
        aAny = rPropertySet->getPropertyValue(u"Title"_ustr);
801
0
        OUString sTitleString;
802
0
        aAny >>= sTitleString;
803
0
        GetExport().Characters(sTitleString);
804
0
    }
805
806
    // export level templates (all indices)
807
0
    aAny = rPropertySet->getPropertyValue(u"LevelFormat"_ustr);
808
0
    Reference<XIndexReplace> xLevelTemplates;
809
0
    aAny >>= xLevelTemplates;
810
811
    // iterate over level formats;
812
    // skip element 0 (empty template for title)
813
0
    sal_Int32 nLevelCount = xLevelTemplates->getCount();
814
0
    for(sal_Int32 i = 1; i<nLevelCount; i++)
815
0
    {
816
        // get sequence
817
0
        Sequence<PropertyValues> aTemplateSequence;
818
0
        aAny = xLevelTemplates->getByIndex(i);
819
0
        aAny >>= aTemplateSequence;
820
821
        // export the sequence (abort export if an error occurred; #91214#)
822
0
        bool bResult =
823
0
            ExportIndexTemplate(eType, i, rPropertySet, aTemplateSequence);
824
0
        if ( !bResult )
825
0
            break;
826
0
    }
827
828
    // only TOC and user index:
829
    // styles from which to build the index (LevelParagraphStyles)
830
0
    if ( (TEXT_SECTION_TYPE_TOC == eType) ||
831
0
         (TEXT_SECTION_TYPE_USER == eType)   )
832
0
    {
833
0
        aAny = rPropertySet->getPropertyValue(u"LevelParagraphStyles"_ustr);
834
0
        Reference<XIndexReplace> xLevelParagraphStyles;
835
0
        aAny >>= xLevelParagraphStyles;
836
0
        ExportLevelParagraphStyles(xLevelParagraphStyles);
837
0
    }
838
0
    else if (TEXT_SECTION_TYPE_ILLUSTRATION == eType
839
0
            || TEXT_SECTION_TYPE_OBJECT == eType
840
0
            || TEXT_SECTION_TYPE_TABLE == eType)
841
0
    {
842
0
        Any const any(rPropertySet->getPropertyValue(u"CreateFromParagraphStyle"_ustr));
843
0
        if (any.hasValue() &&
844
0
            (rExport.getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED))
845
0
        {
846
0
            OUString const styleName(any.get<OUString>());
847
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME,
848
0
                         GetExport().EncodeStyleName(styleName));
849
850
0
            SvXMLElementExport const e(GetExport(),
851
0
                XML_NAMESPACE_LO_EXT, XML_INDEX_SOURCE_STYLE, true, false);
852
0
        }
853
0
    }
854
0
}
855
856
857
void XMLSectionExport::ExportBaseIndexBody(
858
    SectionTypeEnum eType,
859
    const Reference<XPropertySet> &)
860
0
{
861
    // type not used; checked anyway.
862
0
    OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type");
863
0
    OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type");
864
865
    // export start only
866
867
    // any old attributes?
868
0
    GetExport().CheckAttrList();
869
870
    // start surrounded by whitespace
871
0
    GetExport().IgnorableWhitespace();
872
0
    GetExport().StartElement( XML_NAMESPACE_TEXT, XML_INDEX_BODY, true );
873
0
}
874
875
void XMLSectionExport::ExportTableAndIllustrationIndexSourceAttributes(
876
    const Reference<XPropertySet> & rPropertySet)
877
0
{
878
    // use caption
879
0
    Any aAny = rPropertySet->getPropertyValue(u"CreateFromLabels"_ustr);
880
0
    if (! *o3tl::doAccess<bool>(aAny))
881
0
    {
882
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT,
883
0
                                 XML_USE_CAPTION, XML_FALSE);
884
0
    }
885
886
    // sequence name
887
0
    aAny = rPropertySet->getPropertyValue(u"LabelCategory"_ustr);
888
0
    OUString sSequenceName;
889
0
    aAny >>= sSequenceName;
890
0
    GetExport().AddAttribute(XML_NAMESPACE_TEXT,
891
0
                             XML_CAPTION_SEQUENCE_NAME,
892
0
                             sSequenceName);
893
894
    // caption format
895
0
    aAny = rPropertySet->getPropertyValue(u"LabelDisplayType"_ustr);
896
0
    sal_Int16 nType = 0;
897
0
    aAny >>= nType;
898
0
    GetExport().AddAttribute(XML_NAMESPACE_TEXT,
899
0
                             XML_CAPTION_SEQUENCE_FORMAT,
900
0
                             XMLTextFieldExport::MapReferenceType(nType));
901
0
}
902
903
904
// map index of LevelFormats to attribute value;
905
// level 0 is always the header
906
const XMLTokenEnum aLevelNameTOCMap[] =
907
    { XML_TOKEN_INVALID, XML_1, XML_2, XML_3, XML_4, XML_5, XML_6, XML_7,
908
          XML_8, XML_9, XML_10, XML_TOKEN_INVALID };
909
const XMLTokenEnum aLevelNameTableMap[] =
910
    { XML_TOKEN_INVALID, XML__EMPTY, XML_TOKEN_INVALID };
911
const XMLTokenEnum aLevelNameAlphaMap[] =
912
    { XML_TOKEN_INVALID, XML_SEPARATOR, XML_1, XML_2, XML_3, XML_TOKEN_INVALID };
913
const XMLTokenEnum aLevelNameBibliographyMap[] =
914
    { XML_TOKEN_INVALID, XML_ARTICLE, XML_BOOK, XML_BOOKLET, XML_CONFERENCE,
915
          XML_CUSTOM1, XML_CUSTOM2, XML_CUSTOM3, XML_CUSTOM4,
916
          XML_CUSTOM5, XML_EMAIL, XML_INBOOK, XML_INCOLLECTION,
917
          XML_INPROCEEDINGS, XML_JOURNAL,
918
          XML_MANUAL, XML_MASTERSTHESIS, XML_MISC, XML_PHDTHESIS,
919
          XML_PROCEEDINGS, XML_TECHREPORT, XML_UNPUBLISHED, XML_WWW,
920
          XML_TOKEN_INVALID };
921
922
const XMLTokenEnum* const aTypeLevelNameMap[] =
923
{
924
    aLevelNameTOCMap,           // TOC
925
    aLevelNameTableMap,         // table index
926
    aLevelNameTableMap,         // illustration index
927
    aLevelNameTableMap,         // object index
928
    aLevelNameTOCMap,           // user index
929
    aLevelNameAlphaMap,         // alphabetical index
930
    aLevelNameBibliographyMap   // bibliography
931
};
932
933
constexpr OUString aLevelStylePropNameTOCMap[] =
934
    { u""_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel2"_ustr, u"ParaStyleLevel3"_ustr,
935
          u"ParaStyleLevel4"_ustr, u"ParaStyleLevel5"_ustr, u"ParaStyleLevel6"_ustr,
936
          u"ParaStyleLevel7"_ustr, u"ParaStyleLevel8"_ustr, u"ParaStyleLevel9"_ustr,
937
          u"ParaStyleLevel10"_ustr, u""_ustr };
938
constexpr OUString aLevelStylePropNameTableMap[] =
939
    { u""_ustr, u"ParaStyleLevel1"_ustr, u""_ustr };
940
constexpr OUString aLevelStylePropNameAlphaMap[] =
941
    { u""_ustr, u"ParaStyleSeparator"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel2"_ustr,
942
          u"ParaStyleLevel3"_ustr, u""_ustr };
943
constexpr OUString aLevelStylePropNameBibliographyMap[] =
944
          // TODO: replace with real property names, when available
945
    { u""_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
946
          u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
947
          u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
948
          u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
949
          u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,u"ParaStyleLevel1"_ustr,
950
          u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
951
          u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr, u"ParaStyleLevel1"_ustr,
952
          u"ParaStyleLevel1"_ustr,
953
          u""_ustr };
954
955
constexpr const OUString* aTypeLevelStylePropNameMap[] =
956
{
957
    aLevelStylePropNameTOCMap,          // TOC
958
    aLevelStylePropNameTableMap,        // table index
959
    aLevelStylePropNameTableMap,        // illustration index
960
    aLevelStylePropNameTableMap,        // object index
961
    aLevelStylePropNameTOCMap,          // user index
962
    aLevelStylePropNameAlphaMap,        // alphabetical index
963
    aLevelStylePropNameBibliographyMap  // bibliography
964
};
965
966
const XMLTokenEnum aTypeLevelAttrMap[] =
967
{
968
    XML_OUTLINE_LEVEL,      // TOC
969
    XML_TOKEN_INVALID,      // table index
970
    XML_TOKEN_INVALID,      // illustration index
971
    XML_TOKEN_INVALID,      // object index
972
    XML_OUTLINE_LEVEL,      // user index
973
    XML_OUTLINE_LEVEL,      // alphabetical index
974
    XML_BIBLIOGRAPHY_TYPE   // bibliography
975
};
976
977
const XMLTokenEnum aTypeElementNameMap[] =
978
{
979
    XML_TABLE_OF_CONTENT_ENTRY_TEMPLATE,    // TOC
980
    XML_TABLE_INDEX_ENTRY_TEMPLATE,     // table index
981
    XML_ILLUSTRATION_INDEX_ENTRY_TEMPLATE,  // illustration index
982
    XML_OBJECT_INDEX_ENTRY_TEMPLATE,        // object index
983
    XML_USER_INDEX_ENTRY_TEMPLATE,          // user index
984
    XML_ALPHABETICAL_INDEX_ENTRY_TEMPLATE,  // alphabetical index
985
    XML_BIBLIOGRAPHY_ENTRY_TEMPLATE     // bibliography
986
};
987
988
989
bool XMLSectionExport::ExportIndexTemplate(
990
    SectionTypeEnum eType,
991
    sal_Int32 nOutlineLevel,
992
    const Reference<XPropertySet> & rPropertySet,
993
    const Sequence<Sequence<PropertyValue> > & rValues)
994
0
{
995
0
    OSL_ENSURE(eType >= TEXT_SECTION_TYPE_TOC, "illegal index type");
996
0
    OSL_ENSURE(eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY, "illegal index type");
997
0
    OSL_ENSURE(nOutlineLevel >= 0, "illegal outline level");
998
999
0
    if ( (eType >= TEXT_SECTION_TYPE_TOC) &&
1000
0
         (eType <= TEXT_SECTION_TYPE_BIBLIOGRAPHY) &&
1001
0
         (nOutlineLevel >= 0) )
1002
0
    {
1003
        // get level name and level attribute name from aLevelNameMap;
1004
0
        const XMLTokenEnum eLevelAttrName(
1005
0
            aTypeLevelAttrMap[eType-TEXT_SECTION_TYPE_TOC]);
1006
0
        const XMLTokenEnum eLevelName(
1007
0
            aTypeLevelNameMap[eType-TEXT_SECTION_TYPE_TOC][nOutlineLevel]);
1008
1009
        // #92124#: some old documents may be broken, then they have
1010
        // too many template levels; we need to recognize this and
1011
        // export only as many as is legal for the respective index
1012
        // type. To do this, we simply return an error flag, which
1013
        // will then abort further template level exports.
1014
0
        OSL_ENSURE(XML_TOKEN_INVALID != eLevelName, "can't find level name");
1015
0
        if ( XML_TOKEN_INVALID == eLevelName )
1016
0
        {
1017
            // output level not found? Then end of templates! #91214#
1018
0
            return false;
1019
0
        }
1020
1021
        // output level name
1022
0
        if ((XML_TOKEN_INVALID != eLevelName) && (XML_TOKEN_INVALID != eLevelAttrName))
1023
0
        {
1024
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1025
0
                                          GetXMLToken(eLevelAttrName),
1026
0
                                          GetXMLToken(eLevelName));
1027
0
        }
1028
1029
        // paragraph level style name
1030
0
        const OUString pPropName(
1031
0
            aTypeLevelStylePropNameMap[eType-TEXT_SECTION_TYPE_TOC][nOutlineLevel]);
1032
0
        OSL_ENSURE(!pPropName.isEmpty(), "can't find property name");
1033
0
        if (!pPropName.isEmpty())
1034
0
        {
1035
0
            Any aAny = rPropertySet->getPropertyValue(pPropName);
1036
0
            OUString sParaStyleName;
1037
0
            aAny >>= sParaStyleName;
1038
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1039
0
                                     XML_STYLE_NAME,
1040
0
                                     GetExport().EncodeStyleName( sParaStyleName ));
1041
0
        }
1042
1043
        // template element
1044
0
        const XMLTokenEnum eElementName(
1045
0
            aTypeElementNameMap[eType - TEXT_SECTION_TYPE_TOC]);
1046
0
        SvXMLElementExport aLevelTemplate(GetExport(),
1047
0
                                          XML_NAMESPACE_TEXT,
1048
0
                                          GetXMLToken(eElementName),
1049
0
                                          true, true);
1050
1051
        // export sequence
1052
0
        for(auto& rValue : rValues)
1053
0
        {
1054
0
            ExportIndexTemplateElement(
1055
0
                eType,  //i90246
1056
0
                rValue);
1057
0
        }
1058
0
    }
1059
1060
0
    return true;
1061
0
}
1062
1063
namespace {
1064
1065
enum TemplateTypeEnum
1066
{
1067
    TOK_TTYPE_ENTRY_NUMBER,
1068
    TOK_TTYPE_ENTRY_TEXT,
1069
    TOK_TTYPE_TAB_STOP,
1070
    TOK_TTYPE_TEXT,
1071
    TOK_TTYPE_PAGE_NUMBER,
1072
    TOK_TTYPE_CHAPTER_INFO,
1073
    TOK_TTYPE_HYPERLINK_START,
1074
    TOK_TTYPE_HYPERLINK_END,
1075
    TOK_TTYPE_BIBLIOGRAPHY,
1076
    TOK_TTYPE_INVALID
1077
};
1078
1079
enum TemplateParamEnum
1080
{
1081
    TOK_TPARAM_TOKEN_TYPE,
1082
    TOK_TPARAM_CHAR_STYLE,
1083
    TOK_TPARAM_TAB_RIGHT_ALIGNED,
1084
    TOK_TPARAM_TAB_POSITION,
1085
    TOK_TPARAM_TAB_WITH_TAB, // #i21237#
1086
    TOK_TPARAM_TAB_FILL_CHAR,
1087
    TOK_TPARAM_TEXT,
1088
    TOK_TPARAM_CHAPTER_FORMAT,
1089
    TOK_TPARAM_CHAPTER_LEVEL,//i53420
1090
    TOK_TPARAM_BIBLIOGRAPHY_DATA
1091
};
1092
1093
}
1094
1095
SvXMLEnumStringMapEntry<TemplateTypeEnum> const aTemplateTypeMap[] =
1096
{
1097
    ENUM_STRING_MAP_ENTRY( "TokenEntryNumber",  TOK_TTYPE_ENTRY_NUMBER ),
1098
    ENUM_STRING_MAP_ENTRY( "TokenEntryText",    TOK_TTYPE_ENTRY_TEXT ),
1099
    ENUM_STRING_MAP_ENTRY( "TokenTabStop",      TOK_TTYPE_TAB_STOP ),
1100
    ENUM_STRING_MAP_ENTRY( "TokenText",         TOK_TTYPE_TEXT ),
1101
    ENUM_STRING_MAP_ENTRY( "TokenPageNumber",   TOK_TTYPE_PAGE_NUMBER ),
1102
    ENUM_STRING_MAP_ENTRY( "TokenChapterInfo",  TOK_TTYPE_CHAPTER_INFO ),
1103
    ENUM_STRING_MAP_ENTRY( "TokenHyperlinkStart", TOK_TTYPE_HYPERLINK_START ),
1104
    ENUM_STRING_MAP_ENTRY( "TokenHyperlinkEnd", TOK_TTYPE_HYPERLINK_END ),
1105
    ENUM_STRING_MAP_ENTRY( "TokenBibliographyDataField", TOK_TTYPE_BIBLIOGRAPHY ),
1106
    { nullptr, 0, TemplateTypeEnum(0)}
1107
};
1108
1109
SvXMLEnumStringMapEntry<TemplateParamEnum> const aTemplateParamMap[] =
1110
{
1111
    ENUM_STRING_MAP_ENTRY( "TokenType",             TOK_TPARAM_TOKEN_TYPE ),
1112
    ENUM_STRING_MAP_ENTRY( "CharacterStyleName",    TOK_TPARAM_CHAR_STYLE ),
1113
    ENUM_STRING_MAP_ENTRY( "TabStopRightAligned",   TOK_TPARAM_TAB_RIGHT_ALIGNED ),
1114
    ENUM_STRING_MAP_ENTRY( "TabStopPosition",       TOK_TPARAM_TAB_POSITION ),
1115
    ENUM_STRING_MAP_ENTRY( "TabStopFillCharacter",  TOK_TPARAM_TAB_FILL_CHAR ),
1116
    // #i21237#
1117
    ENUM_STRING_MAP_ENTRY( "WithTab",               TOK_TPARAM_TAB_WITH_TAB ),
1118
    ENUM_STRING_MAP_ENTRY( "Text",                  TOK_TPARAM_TEXT ),
1119
    ENUM_STRING_MAP_ENTRY( "ChapterFormat",         TOK_TPARAM_CHAPTER_FORMAT ),
1120
    ENUM_STRING_MAP_ENTRY( "ChapterLevel",          TOK_TPARAM_CHAPTER_LEVEL ),//i53420
1121
    ENUM_STRING_MAP_ENTRY( "BibliographyDataField", TOK_TPARAM_BIBLIOGRAPHY_DATA ),
1122
    { nullptr, 0, TemplateParamEnum(0)}
1123
};
1124
1125
SvXMLEnumMapEntry<sal_Int16> const aBibliographyDataFieldMap[] =
1126
{
1127
    { XML_ADDRESS,              BibliographyDataField::ADDRESS },
1128
    { XML_ANNOTE,               BibliographyDataField::ANNOTE },
1129
    { XML_AUTHOR,               BibliographyDataField::AUTHOR },
1130
    { XML_BIBLIOGRAPHY_TYPE,    BibliographyDataField::BIBILIOGRAPHIC_TYPE },
1131
    { XML_BOOKTITLE,            BibliographyDataField::BOOKTITLE },
1132
    { XML_CHAPTER,              BibliographyDataField::CHAPTER },
1133
    { XML_CUSTOM1,              BibliographyDataField::CUSTOM1 },
1134
    { XML_CUSTOM2,              BibliographyDataField::CUSTOM2 },
1135
    { XML_CUSTOM3,              BibliographyDataField::CUSTOM3 },
1136
    { XML_CUSTOM4,              BibliographyDataField::CUSTOM4 },
1137
    { XML_CUSTOM5,              BibliographyDataField::CUSTOM5 },
1138
    { XML_EDITION,              BibliographyDataField::EDITION },
1139
    { XML_EDITOR,               BibliographyDataField::EDITOR },
1140
    { XML_HOWPUBLISHED,         BibliographyDataField::HOWPUBLISHED },
1141
    { XML_IDENTIFIER,           BibliographyDataField::IDENTIFIER },
1142
    { XML_INSTITUTION,          BibliographyDataField::INSTITUTION },
1143
    { XML_ISBN,                 BibliographyDataField::ISBN },
1144
    { XML_JOURNAL,              BibliographyDataField::JOURNAL },
1145
    { XML_MONTH,                BibliographyDataField::MONTH },
1146
    { XML_NOTE,                 BibliographyDataField::NOTE },
1147
    { XML_NUMBER,               BibliographyDataField::NUMBER },
1148
    { XML_ORGANIZATIONS,        BibliographyDataField::ORGANIZATIONS },
1149
    { XML_PAGES,                BibliographyDataField::PAGES },
1150
    { XML_PUBLISHER,            BibliographyDataField::PUBLISHER },
1151
    { XML_REPORT_TYPE,          BibliographyDataField::REPORT_TYPE },
1152
    { XML_SCHOOL,               BibliographyDataField::SCHOOL },
1153
    { XML_SERIES,               BibliographyDataField::SERIES },
1154
    { XML_TITLE,                BibliographyDataField::TITLE },
1155
    { XML_URL,                  BibliographyDataField::URL },
1156
    { XML_VOLUME,               BibliographyDataField::VOLUME },
1157
    { XML_YEAR,                 BibliographyDataField::YEAR },
1158
    { XML_TOKEN_INVALID, 0 }
1159
};
1160
1161
void XMLSectionExport::ExportIndexTemplateElement(
1162
    SectionTypeEnum eType,  //i90246
1163
    const Sequence<PropertyValue> & rValues)
1164
0
{
1165
    // variables for template values
1166
1167
    // char style
1168
0
    OUString sCharStyle;
1169
0
    bool bCharStyleOK = false;
1170
1171
    // text
1172
0
    OUString sText;
1173
0
    bool bTextOK = false;
1174
1175
    // tab position
1176
0
    bool bRightAligned = false;
1177
1178
    // tab position
1179
0
    sal_Int32 nTabPosition = 0;
1180
0
    bool bTabPositionOK = false;
1181
1182
    // fill character
1183
0
    OUString sFillChar;
1184
0
    bool bFillCharOK = false;
1185
1186
    // chapter format
1187
0
    sal_Int16 nChapterFormat = 0;
1188
0
    bool bChapterFormatOK = false;
1189
1190
    // outline max level
1191
0
    sal_Int16 nLevel = 0;
1192
0
    bool bLevelOK = false;
1193
1194
    // Bibliography Data
1195
0
    sal_Int16 nBibliographyData = 0;
1196
0
    bool bBibliographyDataOK = false;
1197
1198
    // With Tab Stop #i21237#
1199
0
    bool bWithTabStop = false;
1200
0
    bool bWithTabStopOK = false;
1201
1202
    //i90246, the ODF version being written to is:
1203
0
    const SvtSaveOptions::ODFSaneDefaultVersion aODFVersion = rExport.getSaneDefaultVersion();
1204
    //the above version cannot be used for old OOo (OOo 1.0) formats!
1205
1206
    // token type
1207
0
    enum TemplateTypeEnum nTokenType = TOK_TTYPE_INVALID;
1208
1209
0
    for(const auto& rValue : rValues)
1210
0
    {
1211
0
        TemplateParamEnum nToken;
1212
0
        if ( SvXMLUnitConverter::convertEnum( nToken, rValue.Name,
1213
0
                                              aTemplateParamMap ) )
1214
0
        {
1215
            // Only use direct and default values.
1216
            // Wrong. no property states, so ignore.
1217
            // if ( (beans::PropertyState_DIRECT_VALUE == rValues[i].State) ||
1218
            //      (beans::PropertyState_DEFAULT_VALUE == rValues[i].State)  )
1219
1220
0
            switch (nToken)
1221
0
            {
1222
0
                case TOK_TPARAM_TOKEN_TYPE:
1223
0
                {
1224
0
                    OUString sVal;
1225
0
                    rValue.Value >>= sVal;
1226
0
                    SvXMLUnitConverter::convertEnum( nTokenType, sVal, aTemplateTypeMap);
1227
0
                    break;
1228
0
                }
1229
1230
0
                case TOK_TPARAM_CHAR_STYLE:
1231
                    // only valid, if not empty
1232
0
                    rValue.Value >>= sCharStyle;
1233
0
                    bCharStyleOK = !sCharStyle.isEmpty();
1234
0
                    break;
1235
1236
0
                case TOK_TPARAM_TEXT:
1237
0
                    rValue.Value >>= sText;
1238
0
                    bTextOK = true;
1239
0
                    break;
1240
1241
0
                case TOK_TPARAM_TAB_RIGHT_ALIGNED:
1242
0
                    bRightAligned =
1243
0
                        *o3tl::doAccess<bool>(rValue.Value);
1244
0
                    break;
1245
1246
0
                case TOK_TPARAM_TAB_POSITION:
1247
0
                    rValue.Value >>= nTabPosition;
1248
0
                    bTabPositionOK = true;
1249
0
                    break;
1250
1251
                // #i21237#
1252
0
                case TOK_TPARAM_TAB_WITH_TAB:
1253
0
                    bWithTabStop = *o3tl::doAccess<bool>(rValue.Value);
1254
0
                    bWithTabStopOK = true;
1255
0
                    break;
1256
1257
0
                case TOK_TPARAM_TAB_FILL_CHAR:
1258
0
                    rValue.Value >>= sFillChar;
1259
0
                    bFillCharOK = true;
1260
0
                    break;
1261
1262
0
                case TOK_TPARAM_CHAPTER_FORMAT:
1263
0
                    rValue.Value >>= nChapterFormat;
1264
0
                    bChapterFormatOK = true;
1265
0
                    break;
1266
//---> i53420
1267
0
                case TOK_TPARAM_CHAPTER_LEVEL:
1268
0
                    rValue.Value >>= nLevel;
1269
0
                    bLevelOK = true;
1270
0
                    break;
1271
0
                case TOK_TPARAM_BIBLIOGRAPHY_DATA:
1272
0
                    rValue.Value >>= nBibliographyData;
1273
0
                    bBibliographyDataOK = true;
1274
0
                    break;
1275
0
            }
1276
0
        }
1277
0
    }
1278
1279
    // convert type to token (and check validity) ...
1280
0
    XMLTokenEnum eElement(XML_TOKEN_INVALID);
1281
0
    sal_uInt16 nNamespace(XML_NAMESPACE_TEXT);
1282
0
    switch(nTokenType)
1283
0
    {
1284
0
        case TOK_TTYPE_ENTRY_TEXT:
1285
0
            eElement = XML_INDEX_ENTRY_TEXT;
1286
0
            break;
1287
0
        case TOK_TTYPE_TAB_STOP:
1288
            // test validity
1289
0
            if ( bRightAligned || bTabPositionOK || bFillCharOK )
1290
0
            {
1291
0
                eElement = XML_INDEX_ENTRY_TAB_STOP;
1292
0
            }
1293
0
            break;
1294
0
        case TOK_TTYPE_TEXT:
1295
            // test validity
1296
0
            if (bTextOK)
1297
0
            {
1298
0
                eElement = XML_INDEX_ENTRY_SPAN;
1299
0
            }
1300
0
            break;
1301
0
        case TOK_TTYPE_PAGE_NUMBER:
1302
0
            eElement = XML_INDEX_ENTRY_PAGE_NUMBER;
1303
0
            break;
1304
0
        case TOK_TTYPE_CHAPTER_INFO:    // keyword index
1305
0
            eElement = XML_INDEX_ENTRY_CHAPTER;
1306
0
            break;
1307
0
        case TOK_TTYPE_ENTRY_NUMBER:    // table of content
1308
0
            eElement = XML_INDEX_ENTRY_CHAPTER;
1309
0
            break;
1310
0
        case TOK_TTYPE_HYPERLINK_START:
1311
0
            eElement = XML_INDEX_ENTRY_LINK_START;
1312
0
            break;
1313
0
        case TOK_TTYPE_HYPERLINK_END:
1314
0
            eElement = XML_INDEX_ENTRY_LINK_END;
1315
0
            break;
1316
0
        case TOK_TTYPE_BIBLIOGRAPHY:
1317
0
            if (bBibliographyDataOK)
1318
0
            {
1319
0
                eElement = XML_INDEX_ENTRY_BIBLIOGRAPHY;
1320
0
            }
1321
0
            break;
1322
0
        default:
1323
0
            ; // unknown/unimplemented template
1324
0
            break;
1325
0
    }
1326
1327
0
    if (eType != TEXT_SECTION_TYPE_TOC)
1328
0
    {
1329
0
        switch (nTokenType)
1330
0
        {
1331
0
            case TOK_TTYPE_HYPERLINK_START:
1332
0
            case TOK_TTYPE_HYPERLINK_END:
1333
0
                if (SvtSaveOptions::ODFSVER_012 < aODFVersion)
1334
0
                {
1335
0
                    assert(eType == TEXT_SECTION_TYPE_ILLUSTRATION
1336
0
                        || eType == TEXT_SECTION_TYPE_OBJECT
1337
0
                        || eType == TEXT_SECTION_TYPE_TABLE
1338
0
                        || eType == TEXT_SECTION_TYPE_USER);
1339
                    // ODF 1.3 OFFICE-3941
1340
0
                    nNamespace = (SvtSaveOptions::ODFSVER_013 <= aODFVersion)
1341
0
                        ? XML_NAMESPACE_TEXT
1342
0
                        : XML_NAMESPACE_LO_EXT;
1343
0
                }
1344
0
                else
1345
0
                {
1346
0
                    eElement = XML_TOKEN_INVALID; // not allowed in ODF <= 1.2
1347
0
                }
1348
0
                break;
1349
0
            default:
1350
0
                break;
1351
0
        }
1352
0
    }
1353
1354
    //--->i90246
1355
    //check the ODF version being exported
1356
0
    if (aODFVersion == SvtSaveOptions::ODFSVER_011
1357
0
        || aODFVersion == SvtSaveOptions::ODFSVER_010)
1358
0
    {
1359
0
        bLevelOK = false;
1360
0
        if (TOK_TTYPE_CHAPTER_INFO == nTokenType)
1361
0
        {
1362
            //if we are emitting for ODF 1.1 or 1.0, this information can be used for alphabetical index only
1363
            //it's not permitted in other indexes
1364
0
            if (eType != TEXT_SECTION_TYPE_ALPHABETICAL)
1365
0
            {
1366
0
                eElement = XML_TOKEN_INVALID; //not permitted, invalidate the element
1367
0
            }
1368
0
            else //maps format for 1.1 & 1.0
1369
0
            {
1370
                // a few word here: OOo up to 2.4 uses the field chapter info in Alphabetical index
1371
                // in a way different from the ODF 1.1/1.0 specification:
1372
1373
                // ODF1.1/1.0         OOo display in chapter info                       ODF1.2
1374
                //                    (used in alphabetical index only
1375
1376
                // number             chapter number without pre/postfix                plain-number
1377
                // number-and-name    chapter number without pre/postfix plus title     plain-number-and-name
1378
1379
                // with issue i89791 the reading of ODF 1.1 and 1.0 was corrected
1380
                // this one corrects the writing back from ODF 1.2 to ODF 1.1/1.0
1381
                // unfortunately if there is another application which interprets correctly ODF1.1/1.0,
1382
                // the resulting alphabetical index will be rendered wrong by OOo 2.4 version
1383
1384
0
                switch( nChapterFormat )
1385
0
                {
1386
0
                case ChapterFormat::DIGIT:
1387
0
                    nChapterFormat = ChapterFormat::NUMBER;
1388
0
                    break;
1389
0
                case ChapterFormat::NO_PREFIX_SUFFIX:
1390
0
                    nChapterFormat = ChapterFormat::NAME_NUMBER;
1391
0
                    break;
1392
0
                }
1393
0
            }
1394
0
        }
1395
0
        else if (TOK_TTYPE_ENTRY_NUMBER == nTokenType)
1396
0
        {
1397
            //in case of ODF 1.1 or 1.0 the only allowed number format is "number"
1398
            //so, force it...
1399
            // The only expected 'foreign' nChapterFormat is
1400
            // ' ChapterFormat::DIGIT', forced to 'none, since the
1401
            // 'value allowed in ODF 1.1 and 1.0 is 'number' the default
1402
            // this can be obtained by simply disabling the chapter format
1403
0
            bChapterFormatOK = false;
1404
0
        }
1405
0
    }
1406
1407
    // ... and write Element
1408
0
    if (eElement == XML_TOKEN_INVALID)
1409
0
        return;
1410
1411
    // character style (for most templates)
1412
0
    if (bCharStyleOK)
1413
0
    {
1414
0
        switch (nTokenType)
1415
0
        {
1416
0
            case TOK_TTYPE_ENTRY_TEXT:
1417
0
            case TOK_TTYPE_TEXT:
1418
0
            case TOK_TTYPE_PAGE_NUMBER:
1419
0
            case TOK_TTYPE_ENTRY_NUMBER:
1420
0
            case TOK_TTYPE_HYPERLINK_START:
1421
0
            case TOK_TTYPE_HYPERLINK_END:
1422
0
            case TOK_TTYPE_BIBLIOGRAPHY:
1423
0
            case TOK_TTYPE_CHAPTER_INFO:
1424
0
            case TOK_TTYPE_TAB_STOP:
1425
0
                GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1426
0
                                         XML_STYLE_NAME,
1427
0
                             GetExport().EncodeStyleName( sCharStyle) );
1428
0
                break;
1429
0
            default:
1430
0
                ; // nothing: no character style
1431
0
                break;
1432
0
        }
1433
0
    }
1434
1435
    // tab properties
1436
0
    if (TOK_TTYPE_TAB_STOP == nTokenType)
1437
0
    {
1438
        // tab type
1439
0
        GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_TYPE,
1440
0
                                 bRightAligned ? XML_RIGHT : XML_LEFT);
1441
1442
0
        if (bTabPositionOK && (! bRightAligned))
1443
0
        {
1444
            // position for left tabs (convert to measure)
1445
0
            OUStringBuffer sBuf;
1446
0
            GetExport().GetMM100UnitConverter().convertMeasureToXML(sBuf,
1447
0
                                                             nTabPosition);
1448
0
            GetExport().AddAttribute(XML_NAMESPACE_STYLE,
1449
0
                                     XML_POSITION,
1450
0
                                     sBuf.makeStringAndClear());
1451
0
        }
1452
1453
        // fill char ("leader char")
1454
0
        if (bFillCharOK && !sFillChar.isEmpty())
1455
0
        {
1456
0
            GetExport().AddAttribute(XML_NAMESPACE_STYLE,
1457
0
                                     XML_LEADER_CHAR, sFillChar);
1458
0
        }
1459
1460
        // #i21237#
1461
0
        if (bWithTabStopOK && ! bWithTabStop)
1462
0
        {
1463
0
               GetExport().AddAttribute(XML_NAMESPACE_STYLE,
1464
0
                                     XML_WITH_TAB,
1465
0
                                     XML_FALSE);
1466
0
        }
1467
0
    }
1468
1469
    // bibliography data
1470
0
    if (TOK_TTYPE_BIBLIOGRAPHY == nTokenType)
1471
0
    {
1472
0
        OSL_ENSURE(bBibliographyDataOK, "need bibl data");
1473
0
        OUStringBuffer sBuf;
1474
0
        if (SvXMLUnitConverter::convertEnum( sBuf, nBibliographyData,
1475
0
                                             aBibliographyDataFieldMap ) )
1476
0
        {
1477
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1478
0
                                     XML_BIBLIOGRAPHY_DATA_FIELD,
1479
0
                                     sBuf.makeStringAndClear());
1480
0
        }
1481
0
    }
1482
1483
    // chapter info
1484
0
    if (TOK_TTYPE_CHAPTER_INFO == nTokenType)
1485
0
    {
1486
0
        OSL_ENSURE(bChapterFormatOK, "need chapter info");
1487
0
        GetExport().AddAttribute(
1488
0
            XML_NAMESPACE_TEXT, XML_DISPLAY,
1489
0
            XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat));
1490
//---> i53420
1491
0
        if (bLevelOK)
1492
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL,
1493
0
                                 OUString::number(nLevel));
1494
0
    }
1495
1496
//--->i53420
1497
0
    if (TOK_TTYPE_ENTRY_NUMBER == nTokenType)
1498
0
    {
1499
0
        if (bChapterFormatOK)
1500
0
            GetExport().AddAttribute(
1501
0
                XML_NAMESPACE_TEXT, XML_DISPLAY,
1502
0
                XMLTextFieldExport::MapChapterDisplayFormat(nChapterFormat));
1503
1504
0
        if (bLevelOK)
1505
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_OUTLINE_LEVEL,
1506
0
                                 OUString::number(nLevel));
1507
0
    }
1508
    // export template
1509
0
    SvXMLElementExport aTemplateElement(GetExport(), nNamespace,
1510
0
                                        GetXMLToken(eElement),
1511
0
                                        true, false)
1512
0
        ;
1513
1514
    // entry text or span element: write text
1515
0
    if (TOK_TTYPE_TEXT == nTokenType)
1516
0
    {
1517
0
        GetExport().Characters(sText);
1518
0
    }
1519
0
}
1520
1521
void XMLSectionExport::ExportLevelParagraphStyles(
1522
    Reference<XIndexReplace> const & xLevelParagraphStyles)
1523
0
{
1524
    // iterate over levels
1525
0
    sal_Int32 nPLevelCount = xLevelParagraphStyles->getCount();
1526
0
    for(sal_Int32 nLevel = 0; nLevel < nPLevelCount; nLevel++)
1527
0
    {
1528
0
        Any aAny = xLevelParagraphStyles->getByIndex(nLevel);
1529
0
        Sequence<OUString> aStyleNames;
1530
0
        aAny >>= aStyleNames;
1531
1532
        // export only if at least one style is contained
1533
0
        if (aStyleNames.hasElements())
1534
0
        {
1535
            // level attribute; we count 1..10; API 0..9
1536
0
            sal_Int32 nLevelPlusOne = nLevel + 1;
1537
0
            GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1538
0
                                     XML_OUTLINE_LEVEL,
1539
0
                                     OUString::number(nLevelPlusOne));
1540
1541
            // source styles element
1542
0
            SvXMLElementExport aParaStyles(GetExport(),
1543
0
                                           XML_NAMESPACE_TEXT,
1544
0
                                           XML_INDEX_SOURCE_STYLES,
1545
0
                                           true, true);
1546
1547
            // iterate over styles in this level
1548
0
            for (const auto& rStyleName : aStyleNames)
1549
0
            {
1550
                // stylename attribute
1551
0
                GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1552
0
                                         XML_STYLE_NAME,
1553
0
                             GetExport().EncodeStyleName(rStyleName) );
1554
1555
                // element
1556
0
                SvXMLElementExport aParaStyle(GetExport(),
1557
0
                                              XML_NAMESPACE_TEXT,
1558
0
                                              XML_INDEX_SOURCE_STYLE,
1559
0
                                              true, false);
1560
0
            }
1561
0
        }
1562
0
    }
1563
0
}
1564
1565
void XMLSectionExport::ExportBoolean(
1566
    const Reference<XPropertySet> & rPropSet,
1567
    const OUString& sPropertyName,
1568
    enum XMLTokenEnum eAttributeName,
1569
    bool bDefault,
1570
    bool bInvert)
1571
0
{
1572
0
    OSL_ENSURE(eAttributeName != XML_TOKEN_INVALID, "Need attribute name");
1573
1574
0
    Any aAny = rPropSet->getPropertyValue(sPropertyName);
1575
0
    bool bTmp = *o3tl::doAccess<bool>(aAny);
1576
1577
    // value = value ^ bInvert
1578
    // omit if value == default
1579
0
    if ( (bTmp != bInvert) != bDefault )
1580
0
    {
1581
        // export non-default value (since default is omitted)
1582
0
        GetExport().AddAttribute(XML_NAMESPACE_TEXT,
1583
0
                                 eAttributeName,
1584
0
                                 bDefault ? XML_FALSE : XML_TRUE);
1585
0
    }
1586
0
}
1587
1588
void XMLSectionExport::ExportBibliographyConfiguration(SvXMLExport& rExport)
1589
0
{
1590
    // first: get field master (via text field supplier)
1591
0
    Reference<XTextFieldsSupplier> xTextFieldsSupp( rExport.GetModel(),
1592
0
                                                    UNO_QUERY );
1593
0
    if ( !xTextFieldsSupp.is() )
1594
0
        return;
1595
1596
0
    static constexpr OUString sFieldMaster_Bibliography(u"com.sun.star.text.FieldMaster.Bibliography"_ustr);
1597
1598
    // get bibliography field master
1599
0
    Reference<XNameAccess> xMasters =
1600
0
        xTextFieldsSupp->getTextFieldMasters();
1601
0
    if ( !xMasters->hasByName(sFieldMaster_Bibliography) )
1602
0
        return;
1603
1604
0
    Any aAny =
1605
0
        xMasters->getByName(sFieldMaster_Bibliography);
1606
0
    Reference<XPropertySet> xPropSet;
1607
0
    aAny >>= xPropSet;
1608
1609
0
    OSL_ENSURE( xPropSet.is(), "field master must have XPropSet" );
1610
1611
0
    OUString sTmp;
1612
1613
0
    aAny = xPropSet->getPropertyValue(u"BracketBefore"_ustr);
1614
0
    aAny >>= sTmp;
1615
0
    rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_PREFIX, sTmp);
1616
1617
0
    aAny = xPropSet->getPropertyValue(u"BracketAfter"_ustr);
1618
0
    aAny >>= sTmp;
1619
0
    rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_SUFFIX, sTmp);
1620
1621
0
    aAny = xPropSet->getPropertyValue(u"IsNumberEntries"_ustr);
1622
0
    if (*o3tl::doAccess<bool>(aAny))
1623
0
    {
1624
0
        rExport.AddAttribute(XML_NAMESPACE_TEXT,
1625
0
                             XML_NUMBERED_ENTRIES, XML_TRUE);
1626
0
    }
1627
1628
0
    aAny = xPropSet->getPropertyValue(u"IsSortByPosition"_ustr);
1629
0
    if (! *o3tl::doAccess<bool>(aAny))
1630
0
    {
1631
0
        rExport.AddAttribute(XML_NAMESPACE_TEXT,
1632
0
                             XML_SORT_BY_POSITION, XML_FALSE);
1633
0
    }
1634
1635
    // sort algorithm
1636
0
    aAny = xPropSet->getPropertyValue(u"SortAlgorithm"_ustr);
1637
0
    OUString sAlgorithm;
1638
0
    aAny >>= sAlgorithm;
1639
0
    if( !sAlgorithm.isEmpty() )
1640
0
    {
1641
0
        rExport.AddAttribute( XML_NAMESPACE_TEXT,
1642
0
                              XML_SORT_ALGORITHM, sAlgorithm );
1643
0
    }
1644
1645
    // locale
1646
0
    aAny = xPropSet->getPropertyValue(u"Locale"_ustr);
1647
0
    Locale aLocale;
1648
0
    aAny >>= aLocale;
1649
0
    rExport.AddLanguageTagAttributes( XML_NAMESPACE_FO, XML_NAMESPACE_STYLE, aLocale, true);
1650
1651
    // configuration element
1652
0
    SvXMLElementExport aElement(rExport, XML_NAMESPACE_TEXT,
1653
0
                                XML_BIBLIOGRAPHY_CONFIGURATION,
1654
0
                                true, true);
1655
1656
    // sort keys
1657
0
    aAny = xPropSet->getPropertyValue(u"SortKeys"_ustr);
1658
0
    Sequence<Sequence<PropertyValue> > aKeys;
1659
0
    aAny >>= aKeys;
1660
0
    for (const Sequence<PropertyValue>& rKey : aKeys)
1661
0
    {
1662
0
        for(const PropertyValue& rValue : rKey)
1663
0
        {
1664
0
            if (rValue.Name == "SortKey")
1665
0
            {
1666
0
                sal_Int16 nKey = 0;
1667
0
                rValue.Value >>= nKey;
1668
0
                OUStringBuffer sBuf;
1669
0
                if (SvXMLUnitConverter::convertEnum( sBuf, nKey,
1670
0
                                         aBibliographyDataFieldMap ) )
1671
0
                {
1672
0
                    rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_KEY,
1673
0
                                         sBuf.makeStringAndClear());
1674
0
                }
1675
0
            }
1676
0
            else if (rValue.Name == "IsSortAscending")
1677
0
            {
1678
0
                bool bTmp = *o3tl::doAccess<bool>(rValue.Value);
1679
0
                rExport.AddAttribute(XML_NAMESPACE_TEXT,
1680
0
                                     XML_SORT_ASCENDING,
1681
0
                                     bTmp ? XML_TRUE : XML_FALSE);
1682
0
            }
1683
0
        }
1684
1685
0
        SvXMLElementExport aKeyElem(rExport,
1686
0
                                    XML_NAMESPACE_TEXT, XML_SORT_KEY,
1687
0
                                    true, true);
1688
0
    }
1689
0
}
1690
1691
1692
bool XMLSectionExport::IsMuteSection(
1693
    const Reference<XTextSection> & rSection) const
1694
0
{
1695
0
    bool bRet = false;
1696
1697
    // a section is mute if
1698
    // 1) it exists
1699
    // 2) the SaveLinkedSections flag (at the export) is false
1700
    // 3) the IsGlobalDocumentSection property is true
1701
    // 4) it is not an Index
1702
1703
0
    if ( (!rExport.IsSaveLinkedSections()) && rSection.is() )
1704
0
    {
1705
        // walk the section chain and set bRet if any is linked
1706
0
        for(Reference<XTextSection> aSection(rSection);
1707
0
            aSection.is();
1708
0
            aSection = aSection->getParentSection())
1709
0
        {
1710
            // check if it is a global document section (linked or index)
1711
0
            Reference<XPropertySet> xPropSet(aSection, UNO_QUERY);
1712
0
            if (xPropSet.is())
1713
0
            {
1714
0
                Any aAny = xPropSet->getPropertyValue(u"IsGlobalDocumentSection"_ustr);
1715
1716
0
                if ( *o3tl::doAccess<bool>(aAny) )
1717
0
                {
1718
0
                    Reference<XDocumentIndex> xIndex;
1719
0
                    if (! GetIndex(rSection, xIndex))
1720
0
                    {
1721
0
                        bRet = true;
1722
1723
                        // early out if result is known
1724
0
                        break;
1725
0
                    }
1726
0
                }
1727
0
            }
1728
            // section has no properties: ignore
1729
0
        }
1730
0
    }
1731
    // else: no section, or always save sections: default (false)
1732
1733
0
    return bRet;
1734
0
}
1735
1736
bool XMLSectionExport::IsMuteSection(
1737
    const Reference<XTextContent> & rSection,
1738
    bool bDefault) const
1739
0
{
1740
    // default: like default argument
1741
0
    bool bRet = bDefault;
1742
1743
0
    Reference<XPropertySet> xPropSet(rSection->getAnchor(), UNO_QUERY);
1744
0
    if (xPropSet.is())
1745
0
    {
1746
0
        if (xPropSet->getPropertySetInfo()->hasPropertyByName(u"TextSection"_ustr))
1747
0
        {
1748
0
            Any aAny = xPropSet->getPropertyValue(u"TextSection"_ustr);
1749
0
            Reference<XTextSection> xSection;
1750
0
            aAny >>= xSection;
1751
1752
0
            bRet = IsMuteSection(xSection);
1753
0
        }
1754
        // else: return default
1755
0
    }
1756
    // else: return default
1757
1758
0
    return bRet;
1759
0
}
1760
1761
bool XMLSectionExport::IsInSection(
1762
    const Reference<XTextSection> & rEnclosingSection,
1763
    const Reference<XTextContent> & rContent,
1764
    bool bDefault)
1765
0
{
1766
    // default: like default argument
1767
0
    bool bRet = bDefault;
1768
0
    OSL_ENSURE(rEnclosingSection.is(), "enclosing section expected");
1769
1770
0
    Reference<XPropertySet> xPropSet(rContent, UNO_QUERY);
1771
0
    if (xPropSet.is())
1772
0
    {
1773
0
        if (xPropSet->getPropertySetInfo()->hasPropertyByName(u"TextSection"_ustr))
1774
0
        {
1775
0
            Any aAny = xPropSet->getPropertyValue(u"TextSection"_ustr);
1776
0
            Reference<XTextSection> xSection;
1777
0
            aAny >>= xSection;
1778
1779
            // now walk chain of text sections (if we have one)
1780
0
            if (xSection.is())
1781
0
            {
1782
0
                do
1783
0
                {
1784
0
                    bRet = (rEnclosingSection == xSection);
1785
0
                    xSection = xSection->getParentSection();
1786
0
                }
1787
0
                while (!bRet && xSection.is());
1788
0
            }
1789
0
            else
1790
0
                bRet = false;   // no section -> can't be inside
1791
0
        }
1792
        // else: no TextSection property -> return default
1793
0
    }
1794
    // else: no XPropertySet -> return default
1795
1796
0
    return bRet;
1797
0
}
1798
1799
1800
void XMLSectionExport::ExportMasterDocHeadingDummies()
1801
0
{
1802
0
    if( bHeadingDummiesExported )
1803
0
        return;
1804
1805
0
    Reference< XChapterNumberingSupplier > xCNSupplier( rExport.GetModel(),
1806
0
                                                        UNO_QUERY );
1807
1808
0
    Reference< XIndexReplace > xChapterNumbering;
1809
0
    if( xCNSupplier.is() )
1810
0
        xChapterNumbering = xCNSupplier->getChapterNumberingRules();
1811
1812
0
    if( !xChapterNumbering.is() )
1813
0
        return;
1814
1815
0
    sal_Int32 nCount = xChapterNumbering->getCount();
1816
0
    for( sal_Int32 nLevel = 0; nLevel < nCount; nLevel++ )
1817
0
    {
1818
0
        OUString sStyle;
1819
0
        Sequence<PropertyValue> aProperties;
1820
0
        xChapterNumbering->getByIndex( nLevel ) >>= aProperties;
1821
0
        auto pProp = std::find_if(std::cbegin(aProperties), std::cend(aProperties),
1822
0
            [](const PropertyValue& rProp) { return rProp.Name == "HeadingStyleName"; });
1823
0
        if (pProp != std::cend(aProperties))
1824
0
            pProp->Value >>= sStyle;
1825
1826
0
        if( !sStyle.isEmpty() )
1827
0
        {
1828
0
            GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
1829
0
                                      GetExport().EncodeStyleName( sStyle ) );
1830
1831
0
            GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_LEVEL,
1832
0
                                        OUString::number( nLevel + 1 ) );
1833
0
            SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT, XML_H,
1834
0
                                        true, false );
1835
0
        }
1836
0
    }
1837
1838
0
    bHeadingDummiesExported  = true;
1839
0
}
1840
1841
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */