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/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
157
:   SvXMLImportContext(rImport)
41
157
,   bStyleNameOK(false)
42
157
,   rTOCPropertySet(rPropSet)
43
157
{
44
157
}
45
46
47
XMLIndexTitleTemplateContext::~XMLIndexTitleTemplateContext()
48
157
{
49
157
}
50
51
void XMLIndexTitleTemplateContext::startFastElement(
52
    sal_Int32 /*nElement*/,
53
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
54
157
{
55
    // there's only one attribute: style-name
56
157
    for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
57
158
    {
58
158
        if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME) )
59
152
        {
60
152
            sStyleName = aIter.toString();
61
152
            OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
62
152
                XmlStyleFamily::TEXT_PARAGRAPH, sStyleName );
63
152
            const Reference < css::container::XNameContainer >&
64
152
                rStyles = GetImport().GetTextImport()->GetParaStyles();
65
152
            bStyleNameOK = rStyles.is() && rStyles->hasByName( sDisplayStyleName );
66
152
        }
67
6
        else
68
158
            XMLOFF_WARN_UNKNOWN("xmloff", aIter);
69
158
    }
70
157
}
71
72
void XMLIndexTitleTemplateContext::endFastElement(sal_Int32 )
73
147
{
74
147
    Any aAny;
75
76
147
    aAny <<= sContent.makeStringAndClear();
77
147
    rTOCPropertySet->setPropertyValue(u"Title"_ustr, aAny);
78
79
147
    if (bStyleNameOK)
80
71
    {
81
71
        aAny <<= GetImport().GetStyleDisplayName(
82
71
                                XmlStyleFamily::TEXT_PARAGRAPH,
83
71
                                sStyleName );
84
71
        rTOCPropertySet->setPropertyValue(u"ParaStyleHeading"_ustr, aAny);
85
71
    }
86
147
}
87
88
void XMLIndexTitleTemplateContext::characters(
89
    const OUString& sString)
90
239
{
91
239
    sContent.append(sString);
92
239
}
93
94
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */