Coverage Report

Created: 2026-10-14 09:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLIndexSimpleEntryContext.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 "XMLIndexSimpleEntryContext.hxx"
21
#include "XMLIndexTemplateContext.hxx"
22
#include <utility>
23
#include <xmloff/xmlictxt.hxx>
24
#include <xmloff/xmlimp.hxx>
25
#include <xmloff/txtimp.hxx>
26
#include <xmloff/xmlnamespace.hxx>
27
#include <xmloff/xmltoken.hxx>
28
#include <xmloff/xmluconv.hxx>
29
#include <sal/log.hxx>
30
31
#include <com/sun/star/container/XNameContainer.hpp>
32
33
using ::com::sun::star::beans::PropertyValue;
34
using ::com::sun::star::uno::Reference;
35
using ::com::sun::star::uno::Sequence;
36
using ::com::sun::star::uno::Any;
37
using ::xmloff::token::XML_STYLE_NAME;
38
39
40
XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext(
41
    SvXMLImport& rImport,
42
    OUString aEntry,
43
    XMLIndexTemplateContext& rTemplate )
44
6.14k
:   SvXMLImportContext(rImport)
45
6.14k
,   m_rEntryType(std::move(aEntry))
46
6.14k
,   m_bCharStyleNameOK(false)
47
6.14k
,   m_rTemplateContext(rTemplate)
48
6.14k
,   m_nValues(1)
49
6.14k
{
50
6.14k
}
51
52
XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext()
53
6.14k
{
54
6.14k
}
55
56
void XMLIndexSimpleEntryContext::startFastElement(
57
    sal_Int32 /*nElement*/,
58
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
59
2.66k
{
60
    // we know only one attribute: style-name
61
2.66k
    for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
62
6
    {
63
6
        if(aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME))
64
0
        {
65
0
            m_sCharStyleName = aIter.toString();
66
0
            OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
67
0
                XmlStyleFamily::TEXT_TEXT, m_sCharStyleName );
68
            // #142494#: Check if style exists
69
0
            const Reference < css::container::XNameContainer > & rStyles =
70
0
                GetImport().GetTextImport()->GetTextStyles();
71
0
            if( rStyles.is() && rStyles->hasByName( sDisplayStyleName ) )
72
0
                m_bCharStyleNameOK = true;
73
0
            else
74
0
                m_bCharStyleNameOK = false;
75
0
        }
76
6
        else
77
6
            XMLOFF_INFO_UNKNOWN("xmloff", aIter);
78
6
    }
79
80
    // if we have a style name, set it!
81
2.66k
    if (m_bCharStyleNameOK)
82
0
    {
83
0
        m_nValues++;
84
0
    }
85
86
2.66k
}
87
88
void XMLIndexSimpleEntryContext::endFastElement(sal_Int32 )
89
5.96k
{
90
5.96k
    Sequence<PropertyValue> aValues(m_nValues);
91
92
5.96k
    FillPropertyValues(aValues);
93
5.96k
    m_rTemplateContext.addTemplateEntry(aValues);
94
5.96k
}
95
96
void XMLIndexSimpleEntryContext::FillPropertyValues(
97
    css::uno::Sequence<css::beans::PropertyValue> & rValues)
98
5.96k
{
99
    // due to the limited number of subclasses, we fill the values
100
    // directly into the slots. Subclasses will have to know they can
101
    // only use slot so-and-so.
102
103
5.96k
    auto pValues = rValues.getArray();
104
105
    // token type
106
5.96k
    pValues[0].Name = "TokenType";
107
5.96k
    pValues[0].Value <<= m_rEntryType;
108
109
    // char style
110
5.96k
    if (m_bCharStyleNameOK)
111
653
    {
112
653
        pValues[1].Name = "CharacterStyleName";
113
653
        pValues[1].Value <<= GetImport().GetStyleDisplayName(
114
653
                                    XmlStyleFamily::TEXT_TEXT,
115
653
                                    m_sCharStyleName );
116
653
    }
117
118
5.96k
}
119
120
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */