Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/writerperfect/source/writer/exp/xmltbli.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
10
#include "xmltbli.hxx"
11
12
#include "txtparai.hxx"
13
#include "xmlimp.hxx"
14
#include "xmltext.hxx"
15
16
#include <sal/log.hxx>
17
18
using namespace com::sun::star;
19
20
namespace writerperfect::exp
21
{
22
namespace
23
{
24
/// Handler for <table:table-row>.
25
class XMLTableRowContext : public XMLImportContext
26
{
27
public:
28
    XMLTableRowContext(XMLImport& rImport);
29
30
    rtl::Reference<XMLImportContext>
31
    CreateChildContext(const OUString& rName,
32
                       const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
33
    int GetColumn() const;
34
    void SetColumn(int nColumn);
35
36
    void SAL_CALL
37
    startElement(const OUString& rName,
38
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
39
    void SAL_CALL endElement(const OUString& rName) override;
40
41
private:
42
    int m_nColumn = 0;
43
};
44
45
/// Handler for <table:cell>.
46
class XMLTableCellContext : public XMLImportContext
47
{
48
public:
49
    XMLTableCellContext(XMLImport& rImport, XMLTableRowContext& rRow);
50
51
    rtl::Reference<XMLImportContext>
52
    CreateChildContext(const OUString& rName,
53
                       const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
54
55
    void SAL_CALL
56
    startElement(const OUString& rName,
57
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
58
    void SAL_CALL endElement(const OUString& rName) override;
59
60
private:
61
    XMLTableRowContext& m_rRow;
62
};
63
}
64
65
XMLTableCellContext::XMLTableCellContext(XMLImport& rImport, XMLTableRowContext& rRow)
66
0
    : XMLImportContext(rImport)
67
0
    , m_rRow(rRow)
68
0
{
69
0
}
70
71
rtl::Reference<XMLImportContext> XMLTableCellContext::CreateChildContext(
72
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
73
0
{
74
0
    return CreateTextChildContext(GetImport(), rName);
75
0
}
76
77
void XMLTableCellContext::startElement(
78
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
79
0
{
80
0
    librevenge::RVNGPropertyList aPropertyList;
81
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
82
0
    {
83
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
84
0
        const OUString aAttributeValue = xAttribs->getValueByIndex(i);
85
86
0
        if (aAttributeName == "table:style-name")
87
0
            FillStyles(aAttributeValue, GetImport().GetAutomaticCellStyles(),
88
0
                       GetImport().GetCellStyles(), aPropertyList);
89
0
        else
90
0
        {
91
0
            OString sName = OUStringToOString(aAttributeName, RTL_TEXTENCODING_UTF8);
92
0
            OString sValue = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
93
0
            aPropertyList.insert(sName.getStr(), sValue.getStr());
94
0
        }
95
0
    }
96
0
    aPropertyList.insert("librevenge:column", m_rRow.GetColumn());
97
0
    GetImport().GetGenerator().openTableCell(aPropertyList);
98
0
    m_rRow.SetColumn(m_rRow.GetColumn() + 1);
99
0
}
100
101
void XMLTableCellContext::endElement(const OUString& /*rName*/)
102
0
{
103
0
    GetImport().GetGenerator().closeTableCell();
104
0
}
105
106
namespace
107
{
108
/// Handler for <table:table-column>.
109
class XMLTableColumnContext : public XMLImportContext
110
{
111
public:
112
    XMLTableColumnContext(XMLImport& rImport, librevenge::RVNGPropertyListVector& rColumns);
113
114
    void SAL_CALL
115
    startElement(const OUString& rName,
116
                 const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
117
118
private:
119
    librevenge::RVNGPropertyListVector& m_rColumns;
120
};
121
}
122
123
XMLTableColumnContext::XMLTableColumnContext(XMLImport& rImport,
124
                                             librevenge::RVNGPropertyListVector& rColumns)
125
0
    : XMLImportContext(rImport)
126
0
    , m_rColumns(rColumns)
127
0
{
128
0
}
129
130
void XMLTableColumnContext::startElement(
131
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
132
0
{
133
0
    librevenge::RVNGPropertyList aPropertyList;
134
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
135
0
    {
136
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
137
0
        const OUString aAttributeValue = xAttribs->getValueByIndex(i);
138
139
0
        if (aAttributeName == "table:style-name")
140
0
            FillStyles(aAttributeValue, GetImport().GetAutomaticColumnStyles(),
141
0
                       GetImport().GetColumnStyles(), aPropertyList);
142
0
    }
143
0
    m_rColumns.append(aPropertyList);
144
0
}
145
146
XMLTableRowContext::XMLTableRowContext(XMLImport& rImport)
147
0
    : XMLImportContext(rImport)
148
0
{
149
0
}
150
151
rtl::Reference<XMLImportContext> XMLTableRowContext::CreateChildContext(
152
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
153
0
{
154
0
    if (rName == "table:table-cell")
155
0
        return new XMLTableCellContext(GetImport(), *this);
156
0
    if (rName == "table:covered-table-cell")
157
0
    {
158
0
        ++m_nColumn;
159
0
        GetImport().GetGenerator().insertCoveredTableCell(librevenge::RVNGPropertyList());
160
0
    }
161
0
    else
162
0
        SAL_WARN("writerperfect", "XMLTableRowContext::CreateChildContext: unhandled " << rName);
163
0
    return nullptr;
164
0
}
165
166
void XMLTableRowContext::startElement(
167
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
168
0
{
169
0
    librevenge::RVNGPropertyList aPropertyList;
170
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
171
0
    {
172
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
173
0
        const OUString aAttributeValue = xAttribs->getValueByIndex(i);
174
175
0
        if (aAttributeName == "table:style-name")
176
0
            FillStyles(aAttributeValue, GetImport().GetAutomaticRowStyles(),
177
0
                       GetImport().GetRowStyles(), aPropertyList);
178
0
    }
179
0
    GetImport().GetGenerator().openTableRow(aPropertyList);
180
0
}
181
182
void XMLTableRowContext::endElement(const OUString& /*rName*/)
183
0
{
184
0
    GetImport().GetGenerator().closeTableRow();
185
0
}
186
187
0
int XMLTableRowContext::GetColumn() const { return m_nColumn; }
188
189
0
void XMLTableRowContext::SetColumn(int nColumn) { m_nColumn = nColumn; }
190
191
XMLTableContext::XMLTableContext(XMLImport& rImport, bool bTopLevel)
192
0
    : XMLImportContext(rImport)
193
0
    , m_bTopLevel(bTopLevel)
194
0
{
195
0
}
196
197
rtl::Reference<XMLImportContext> XMLTableContext::CreateChildContext(
198
    const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
199
0
{
200
0
    if (rName == "table:table-column")
201
        // Make sure columns are parsed before we open the table.
202
0
        return new XMLTableColumnContext(GetImport(), m_aColumns);
203
204
0
    if (!m_bTableOpened)
205
0
    {
206
0
        if (!m_aColumns.empty())
207
0
            m_aPropertyList.insert("librevenge:table-columns", m_aColumns);
208
0
        GetImport().GetGenerator().openTable(m_aPropertyList);
209
0
        m_bTableOpened = true;
210
0
    }
211
212
0
    if (rName == "table:table-row")
213
0
        return new XMLTableRowContext(GetImport());
214
215
0
    SAL_WARN("writerperfect", "XMLTableContext::CreateChildContext: unhandled " << rName);
216
217
0
    return nullptr;
218
0
}
219
220
void XMLTableContext::startElement(
221
    const OUString& /*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs)
222
0
{
223
0
    for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
224
0
    {
225
0
        const OUString aAttributeName = xAttribs->getNameByIndex(i);
226
0
        const OUString aAttributeValue = xAttribs->getValueByIndex(i);
227
228
0
        if (aAttributeName == "table:style-name")
229
0
        {
230
0
            FillStyles(aAttributeValue, GetImport().GetAutomaticTableStyles(),
231
0
                       GetImport().GetTableStyles(), m_aPropertyList);
232
0
            if (m_bTopLevel)
233
0
                GetImport().HandlePageSpan(m_aPropertyList);
234
0
        }
235
0
        else
236
0
        {
237
0
            OString sName = OUStringToOString(aAttributeName, RTL_TEXTENCODING_UTF8);
238
0
            OString sValue = OUStringToOString(aAttributeValue, RTL_TEXTENCODING_UTF8);
239
0
            m_aPropertyList.insert(sName.getStr(), sValue.getStr());
240
0
        }
241
0
    }
242
0
}
243
244
void XMLTableContext::endElement(const OUString& /*rName*/)
245
0
{
246
0
    if (m_bTableOpened)
247
0
    {
248
0
        GetImport().GetGenerator().closeTable();
249
0
    }
250
0
}
251
252
} // namespace writerperfect::exp
253
254
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */