Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/xmloff/source/text/XMLSectionFootnoteConfigImport.cxx
Line
Count
Source (jump to first uncovered line)
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 "XMLSectionFootnoteConfigImport.hxx"
21
22
#include <rtl/ustring.hxx>
23
#include <com/sun/star/uno/Reference.h>
24
#include <com/sun/star/style/NumberingType.hpp>
25
#include <sal/log.hxx>
26
#include <sax/tools/converter.hxx>
27
#include <utility>
28
#include <xmloff/xmlimp.hxx>
29
#include <xmloff/xmltoken.hxx>
30
#include <xmloff/xmluconv.hxx>
31
#include <xmloff/xmlprmap.hxx>
32
#include <xmloff/xmlnamespace.hxx>
33
#include <xmloff/maptype.hxx>
34
#include <xmloff/txtprmap.hxx>
35
36
37
using namespace ::xmloff::token;
38
using namespace ::com::sun::star::style;
39
40
using ::std::vector;
41
using ::com::sun::star::uno::Any;
42
using ::com::sun::star::uno::Reference;
43
44
45
XMLSectionFootnoteConfigImport::XMLSectionFootnoteConfigImport(
46
    SvXMLImport& rImport,
47
    sal_Int32 /*nElement*/,
48
    vector<XMLPropertyState> & rProps,
49
    rtl::Reference<XMLPropertySetMapper> xMapperRef) :
50
16
        SvXMLImportContext(rImport),
51
16
        rProperties(rProps),
52
16
        rMapper(std::move(xMapperRef))
53
16
{
54
16
}
55
56
XMLSectionFootnoteConfigImport::~XMLSectionFootnoteConfigImport()
57
16
{
58
16
}
59
60
void XMLSectionFootnoteConfigImport::startFastElement(
61
    sal_Int32 /*nElement*/,
62
    const Reference<css::xml::sax::XFastAttributeList> & xAttrList)
63
16
{
64
16
    bool bNumOwn = false;
65
16
    bool bNumRestart = false;
66
16
    bool bEndnote = false;
67
16
    sal_Int16 nNumRestartAt = 0;
68
16
    OUString sNumPrefix;
69
16
    OUString sNumSuffix;
70
16
    OUString sNumFormat;
71
16
    OUString sNumLetterSync;
72
73
    // iterate over xattribute list and fill values
74
16
    for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList))
75
32
    {
76
32
        switch(aIter.getToken())
77
32
        {
78
16
            case XML_ELEMENT(TEXT, XML_START_VALUE):
79
16
            {
80
16
                sal_Int32 nTmp;
81
16
                if (::sax::Converter::convertNumber(nTmp, aIter.toView()))
82
16
                {
83
16
                    nNumRestartAt = static_cast< sal_Int16 >( nTmp ) - 1;
84
16
                    bNumRestart = true;
85
16
                }
86
16
                break;
87
0
            }
88
16
            case XML_ELEMENT(TEXT, XML_NOTE_CLASS):
89
16
            {
90
16
                if( IsXMLToken( aIter, XML_ENDNOTE ) )
91
16
                    bEndnote = true;
92
16
                break;
93
0
            }
94
0
            case XML_ELEMENT(STYLE, XML_NUM_PREFIX):
95
0
            {
96
0
                sNumPrefix = aIter.toString();
97
0
                bNumOwn = true;
98
0
                break;
99
0
            }
100
0
            case XML_ELEMENT(STYLE, XML_NUM_SUFFIX):
101
0
            {
102
0
                sNumSuffix = aIter.toString();
103
0
                bNumOwn = true;
104
0
                break;
105
0
            }
106
0
            case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
107
0
            {
108
0
                sNumFormat = aIter.toString();
109
0
                bNumOwn = true;
110
0
                break;
111
0
            }
112
0
            case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
113
0
            {
114
0
                sNumLetterSync = aIter.toString();
115
0
                bNumOwn = true;
116
0
                break;
117
0
            }
118
0
            default:
119
0
                XMLOFF_WARN_UNKNOWN("xmloff", aIter);
120
32
        }
121
32
    }
122
123
    // OK, now we have all values and can fill the XMLPropertyState vector
124
125
16
    sal_Int32 nIndex = rMapper->FindEntryIndex( bEndnote ?
126
16
        CTF_SECTION_ENDNOTE_NUM_OWN : CTF_SECTION_FOOTNOTE_NUM_OWN );
127
16
    XMLPropertyState aNumOwn( nIndex, css::uno::Any(bNumOwn) );
128
16
    rProperties.push_back( aNumOwn );
129
130
16
    nIndex = rMapper->FindEntryIndex( bEndnote ?
131
16
        CTF_SECTION_ENDNOTE_NUM_RESTART : CTF_SECTION_FOOTNOTE_NUM_RESTART );
132
16
    XMLPropertyState aNumRestart( nIndex, css::uno::Any(bNumRestart) );
133
16
    rProperties.push_back( aNumRestart );
134
135
16
    nIndex = rMapper->FindEntryIndex( bEndnote ?
136
16
        CTF_SECTION_ENDNOTE_NUM_RESTART_AT :
137
16
        CTF_SECTION_FOOTNOTE_NUM_RESTART_AT );
138
16
    XMLPropertyState aNumRestartAtState( nIndex, css::uno::Any(nNumRestartAt) );
139
16
    rProperties.push_back( aNumRestartAtState );
140
141
16
    sal_Int16 nNumType = NumberingType::ARABIC;
142
16
    GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
143
16
                                                    sNumFormat,
144
16
                                                    sNumLetterSync );
145
16
    nIndex = rMapper->FindEntryIndex( bEndnote ?
146
16
        CTF_SECTION_ENDNOTE_NUM_TYPE : CTF_SECTION_FOOTNOTE_NUM_TYPE );
147
16
    XMLPropertyState aNumFormatState( nIndex, css::uno::Any(nNumType) );
148
16
    rProperties.push_back( aNumFormatState );
149
150
16
    nIndex = rMapper->FindEntryIndex( bEndnote ?
151
16
        CTF_SECTION_ENDNOTE_NUM_PREFIX : CTF_SECTION_FOOTNOTE_NUM_PREFIX );
152
16
    XMLPropertyState aPrefixState( nIndex, css::uno::Any(sNumPrefix) );
153
16
    rProperties.push_back( aPrefixState );
154
155
16
    nIndex = rMapper->FindEntryIndex( bEndnote ?
156
16
        CTF_SECTION_ENDNOTE_NUM_SUFFIX : CTF_SECTION_FOOTNOTE_NUM_SUFFIX );
157
16
    XMLPropertyState aSuffixState( nIndex, css::uno::Any(sNumSuffix) );
158
16
    rProperties.push_back( aSuffixState );
159
160
16
    nIndex = rMapper->FindEntryIndex( bEndnote ?
161
16
        CTF_SECTION_ENDNOTE_END : CTF_SECTION_FOOTNOTE_END );
162
16
    XMLPropertyState aEndState( nIndex, css::uno::Any(true) ); // we're inside the element, so this is true
163
16
    rProperties.push_back( aEndState );
164
16
}
165
166
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */