Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/text/XMLTextListItemContext.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 <xmloff/xmlimp.hxx>
21
#include <xmloff/xmlnamespace.hxx>
22
#include <xmloff/xmltoken.hxx>
23
#include "txtparai.hxx"
24
#include <txtlists.hxx>
25
#include "XMLTextListBlockContext.hxx"
26
#include <xmloff/txtimp.hxx>
27
#include <com/sun/star/container/XNameContainer.hpp>
28
#include <com/sun/star/beans/XPropertySet.hpp>
29
#include <com/sun/star/style/XStyle.hpp>
30
#include <xmloff/xmlnumi.hxx>
31
#include <xmloff/ProgressBarHelper.hxx>
32
#include "XMLTextListItemContext.hxx"
33
#include <sal/log.hxx>
34
35
36
using namespace ::com::sun::star;
37
using namespace ::com::sun::star::uno;
38
using namespace ::xmloff::token;
39
40
41
XMLTextListItemContext::XMLTextListItemContext(
42
                        SvXMLImport& rImport,
43
                        XMLTextImportHelper& rTxtImp,
44
                        const Reference< xml::sax::XFastAttributeList > & xAttrList,
45
                        const bool bIsHeader )
46
0
    : SvXMLImportContext( rImport ),
47
0
      rTxtImport( rTxtImp ),
48
0
      nStartValue( -1 ),
49
0
      mnSubListCount( 0 )
50
0
{
51
0
    for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
52
0
    {
53
0
        if( !bIsHeader && aIter.getToken() == XML_ELEMENT(TEXT, XML_START_VALUE) )
54
0
        {
55
0
            sal_Int32 nTmp = aIter.toInt32();
56
0
            if( nTmp >= 0 && nTmp <= SHRT_MAX )
57
0
                nStartValue = static_cast<sal_Int16>(nTmp);
58
0
        }
59
0
        else if ( aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_OVERRIDE) )
60
0
        {
61
0
            OUString sListStyleOverrideName = aIter.toString();
62
0
            if ( !sListStyleOverrideName.isEmpty() )
63
0
            {
64
0
                OUString sDisplayStyleName(
65
0
                        GetImport().GetStyleDisplayName( XmlStyleFamily::TEXT_LIST,
66
0
                                                         sListStyleOverrideName ) );
67
0
                const Reference < container::XNameContainer >& rNumStyles =
68
0
                                                    rTxtImp.GetNumberingStyles();
69
0
                if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
70
0
                {
71
0
                    Reference < style::XStyle > xStyle;
72
0
                    Any aAny = rNumStyles->getByName( sDisplayStyleName );
73
0
                    aAny >>= xStyle;
74
75
0
                    uno::Reference< beans::XPropertySet > xPropSet( xStyle, UNO_QUERY );
76
0
                    aAny = xPropSet->getPropertyValue(u"NumberingRules"_ustr);
77
0
                    aAny >>= mxNumRulesOverride;
78
0
                }
79
0
                else
80
0
                {
81
0
                    const SvxXMLListStyleContext* pListStyle =
82
0
                                        rTxtImp.FindAutoListStyle( sListStyleOverrideName );
83
0
                    if( pListStyle )
84
0
                    {
85
0
                        mxNumRulesOverride = pListStyle->GetNumRules();
86
0
                        if( !mxNumRulesOverride.is() )
87
0
                        {
88
0
                            pListStyle->CreateAndInsertAuto();
89
0
                            mxNumRulesOverride = pListStyle->GetNumRules();
90
0
                        }
91
0
                    }
92
0
                }
93
0
            }
94
0
        }
95
0
        else if ( aIter.getToken() == XML_ELEMENT(XML, XML_ID) )
96
0
        {
97
//FIXME: there is no UNO API for list items
98
0
        }
99
0
        else
100
0
            XMLOFF_WARN_UNKNOWN("xmloff", aIter);
101
0
    }
102
103
    // If this is a <text:list-item> element, then remember it as a sign
104
    // that a bullet has to be generated.
105
0
    if( !bIsHeader ) {
106
0
        rTxtImport.GetTextListHelper().SetListItem( this );
107
0
    }
108
109
0
}
110
111
XMLTextListItemContext::~XMLTextListItemContext()
112
0
{
113
0
}
114
115
void XMLTextListItemContext::endFastElement(sal_Int32 )
116
0
{
117
    // finish current list item
118
0
    rTxtImport.GetTextListHelper().SetListItem( nullptr );
119
0
}
120
121
css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextListItemContext::createFastChildContext(
122
    sal_Int32 nElement,
123
    const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
124
0
{
125
0
    SvXMLImportContext *pContext = nullptr;
126
127
0
    switch( nElement )
128
0
    {
129
0
    case XML_ELEMENT(TEXT, XML_H):
130
0
    case XML_ELEMENT(TEXT, XML_P):
131
0
    case XML_ELEMENT(LO_EXT, XML_P):
132
0
        pContext = new XMLParaContext( GetImport(), nElement,
133
0
                                       xAttrList );
134
0
        if (rTxtImport.IsProgress())
135
0
            GetImport().GetProgressBarHelper()->Increment();
136
137
0
        break;
138
0
    case XML_ELEMENT(TEXT, XML_LIST):
139
0
        ++mnSubListCount;
140
0
        pContext = new XMLTextListBlockContext( GetImport(), rTxtImport,
141
0
                                                xAttrList,
142
0
                                                (mnSubListCount > 1) );
143
0
        break;
144
0
    default:
145
0
        XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
146
0
    }
147
148
0
    return pContext;
149
0
}
150
151
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */