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/XMLIndexTableSourceContext.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
21
#include "XMLIndexTableSourceContext.hxx"
22
23
#include <com/sun/star/beans/XPropertySet.hpp>
24
#include <com/sun/star/text/ReferenceFieldPart.hpp>
25
26
#include <sax/tools/converter.hxx>
27
28
#include "XMLIndexTemplateContext.hxx"
29
#include <xmloff/xmlimp.hxx>
30
#include <xmloff/xmlnamespace.hxx>
31
#include <xmloff/xmltoken.hxx>
32
#include <xmloff/xmluconv.hxx>
33
#include <xmloff/xmlement.hxx>
34
#include <rtl/ustring.hxx>
35
36
37
using namespace ::com::sun::star::text;
38
using namespace ::xmloff::token;
39
40
using ::com::sun::star::beans::XPropertySet;
41
using ::com::sun::star::uno::Reference;
42
using ::com::sun::star::uno::Any;
43
44
XMLIndexTableSourceContext::XMLIndexTableSourceContext(
45
    SvXMLImport& rImport, Reference<XPropertySet> & rPropSet)
46
0
    : XMLIndexSourceBaseContext(rImport, rPropSet, UseStyles::Single)
47
0
    , nDisplayFormat(0)
48
0
    , bSequenceOK(false)
49
0
    , bDisplayFormatOK(false)
50
0
    , bUseCaption(true)
51
0
{
52
0
}
53
54
XMLIndexTableSourceContext::~XMLIndexTableSourceContext()
55
0
{
56
0
}
57
58
SvXMLEnumMapEntry<sal_uInt16> const lcl_aReferenceTypeTokenMap[] =
59
{
60
61
    { XML_TEXT,                 ReferenceFieldPart::TEXT },
62
    { XML_CATEGORY_AND_VALUE,   ReferenceFieldPart::CATEGORY_AND_NUMBER },
63
    { XML_CAPTION,              ReferenceFieldPart::ONLY_CAPTION },
64
65
    // wrong values that previous versions wrote:
66
    { XML_CHAPTER,              ReferenceFieldPart::CATEGORY_AND_NUMBER },
67
    { XML_PAGE,                 ReferenceFieldPart::ONLY_CAPTION },
68
69
    { XML_TOKEN_INVALID,        0 }
70
};
71
72
void XMLIndexTableSourceContext::ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter)
73
0
{
74
0
    bool bTmp(false);
75
76
0
    switch (aIter.getToken())
77
0
    {
78
0
        case XML_ELEMENT(TEXT, XML_USE_CAPTION):
79
0
            if (::sax::Converter::convertBool(bTmp, aIter.toView()))
80
0
            {
81
0
                bUseCaption = bTmp;
82
0
            }
83
0
            break;
84
85
0
        case XML_ELEMENT(TEXT, XML_CAPTION_SEQUENCE_NAME):
86
0
            sSequence = aIter.toString();
87
0
            bSequenceOK = true;
88
0
            break;
89
90
0
        case XML_ELEMENT(TEXT, XML_CAPTION_SEQUENCE_FORMAT):
91
0
        {
92
0
             sal_uInt16 nTmp;
93
0
             if (SvXMLUnitConverter::convertEnum(nTmp, aIter.toView(),
94
0
                                                 lcl_aReferenceTypeTokenMap))
95
0
             {
96
0
                 nDisplayFormat = nTmp;
97
0
                 bDisplayFormatOK = true;
98
0
             }
99
0
             break;
100
0
        }
101
102
0
        default:
103
0
            XMLIndexSourceBaseContext::ProcessAttribute(aIter);
104
0
            break;
105
0
    }
106
0
}
107
108
void XMLIndexTableSourceContext::endFastElement(sal_Int32 nElement)
109
0
{
110
0
    rIndexPropertySet->setPropertyValue(u"CreateFromLabels"_ustr, css::uno::Any(bUseCaption));
111
112
0
    if (bSequenceOK)
113
0
    {
114
0
        rIndexPropertySet->setPropertyValue(u"LabelCategory"_ustr, css::uno::Any(sSequence));
115
0
    }
116
117
0
    if (bDisplayFormatOK)
118
0
    {
119
0
        rIndexPropertySet->setPropertyValue(u"LabelDisplayType"_ustr, css::uno::Any(nDisplayFormat));
120
0
    }
121
122
0
    XMLIndexSourceBaseContext::endFastElement(nElement);
123
0
}
124
125
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexTableSourceContext::createFastChildContext(
126
    sal_Int32 nElement,
127
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
128
0
{
129
0
    if ( nElement == XML_ELEMENT(TEXT, XML_TABLE_INDEX_ENTRY_TEMPLATE) )
130
0
    {
131
0
        return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
132
0
                                           aLevelNameTableMap,
133
0
                                           XML_TOKEN_INVALID, // no outline-level attr
134
0
                                           aLevelStylePropNameTableMap,
135
0
                                           aAllowedTokenTypesTable);
136
0
    }
137
0
    else
138
0
    {
139
0
        return XMLIndexSourceBaseContext::createFastChildContext(nElement,
140
0
                                                             xAttrList);
141
0
    }
142
143
0
}
144
145
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */