Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLIndexTitleTemplateContext.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 "XMLIndexTitleTemplateContext.hxx"
21
#include <xmloff/xmlictxt.hxx>
22
#include <xmloff/xmlimp.hxx>
23
#include <xmloff/xmlnamespace.hxx>
24
#include <xmloff/xmltoken.hxx>
25
#include <sal/log.hxx>
26
27
#include <com/sun/star/container/XNameContainer.hpp>
28
#include <com/sun/star/beans/XPropertySet.hpp>
29
30
31
using ::com::sun::star::beans::XPropertySet;
32
using ::com::sun::star::uno::Any;
33
using ::com::sun::star::uno::Reference;
34
using ::xmloff::token::XML_STYLE_NAME;
35
36
37
XMLIndexTitleTemplateContext::XMLIndexTitleTemplateContext(
38
    SvXMLImport& rImport,
39
    Reference<XPropertySet> & rPropSet)
40
121
:   SvXMLImportContext(rImport)
41
121
,   bStyleNameOK(false)
42
121
,   rTOCPropertySet(rPropSet)
43
121
{
44
121
}
45
46
47
XMLIndexTitleTemplateContext::~XMLIndexTitleTemplateContext()
48
121
{
49
121
}
50
51
void XMLIndexTitleTemplateContext::startFastElement(
52
    sal_Int32 /*nElement*/,
53
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
54
121
{
55
    // there's only one attribute: style-name
56
121
    for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
57
126
    {
58
126
        if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME) )
59
119
        {
60
119
            sStyleName = aIter.toString();
61
119
            OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
62
119
                XmlStyleFamily::TEXT_PARAGRAPH, sStyleName );
63
119
            const Reference < css::container::XNameContainer >&
64
119
                rStyles = GetImport().GetTextImport()->GetParaStyles();
65
119
            bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
66
119
        }
67
7
        else
68
126
            XMLOFF_WARN_UNKNOWN("xmloff", aIter);
69
126
    }
70
121
}
71
72
void XMLIndexTitleTemplateContext::endFastElement(sal_Int32 )
73
114
{
74
114
    Any aAny;
75
76
114
    aAny <<= sContent.makeStringAndClear();
77
114
    rTOCPropertySet->setPropertyValue(u"Title"_ustr, aAny);
78
79
114
    if (bStyleNameOK)
80
56
    {
81
56
        aAny <<= GetImport().GetStyleDisplayName(
82
56
                                XmlStyleFamily::TEXT_PARAGRAPH,
83
56
                                sStyleName );
84
56
        rTOCPropertySet->setPropertyValue(u"ParaStyleHeading"_ustr, aAny);
85
56
    }
86
114
}
87
88
void XMLIndexTitleTemplateContext::characters(
89
    const OUString& sString)
90
174
{
91
174
    sContent.append(sString);
92
174
}
93
94
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */