Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/ppt/commonbehaviorcontext.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 <rtl/ustrbuf.hxx>
21
#include <sal/log.hxx>
22
23
#include <oox/helper/attributelist.hxx>
24
#include <oox/token/namespaces.hxx>
25
#include <oox/ppt/pptfilterhelpers.hxx>
26
#include <sax/fastattribs.hxx>
27
28
#include "commonbehaviorcontext.hxx"
29
#include "commontimenodecontext.hxx"
30
#include "timetargetelementcontext.hxx"
31
32
#include <string.h>
33
34
using namespace ::oox::core;
35
using namespace ::com::sun::star::uno;
36
using namespace ::com::sun::star::xml::sax;
37
38
namespace oox::ppt {
39
40
    CommonBehaviorContext::CommonBehaviorContext( FragmentHandler2 const & rParent,
41
            const TimeNodePtr & pNode)
42
360
        : FragmentHandler2(rParent)
43
360
            , mbInAttrList( false )
44
360
            , mbIsInAttrName( false )
45
360
            , mpNode(pNode)
46
360
    {
47
360
    }
48
49
    CommonBehaviorContext::~CommonBehaviorContext( ) noexcept
50
360
    {
51
360
    }
52
53
    void CommonBehaviorContext::onEndElement()
54
802
    {
55
802
        switch( getCurrentElement() )
56
802
        {
57
360
        case PPT_TOKEN( cBhvr ):
58
360
        {
59
360
            if( !maAttributes.empty() )
60
220
            {
61
220
                OUStringBuffer sAttributes;
62
220
                for (auto const& attribute : maAttributes)
63
222
                {
64
222
                    if( !sAttributes.isEmpty() )
65
2
                    {
66
2
                        sAttributes.append( ";" );
67
2
                    }
68
222
                    sAttributes.append( attribute.name );
69
222
                }
70
220
                OUString sTmp( sAttributes.makeStringAndClear() );
71
220
                mpNode->getNodeProperties()[ NP_ATTRIBUTENAME ] <<= sTmp;
72
220
            }
73
360
            break;
74
0
        }
75
220
        case PPT_TOKEN( attrNameLst ):
76
220
            mbInAttrList = false;
77
220
            break;
78
222
        case PPT_TOKEN( attrName ):
79
222
            if( mbIsInAttrName )
80
222
            {
81
222
                const ImplAttributeNameConversion *attrConv = getAttributeConversionList();
82
1.67k
                while( attrConv->mpMSName != nullptr )
83
1.67k
                {
84
1.67k
                    if(msCurrentAttribute.equalsAscii( attrConv->mpMSName ) )
85
222
                    {
86
222
                        Attribute attr;
87
222
                        attr.name = OUString( attrConv->mpAPIName,
88
222
                                              strlen(attrConv->mpAPIName),
89
222
                                              RTL_TEXTENCODING_ASCII_US );
90
222
                        attr.type = attrConv->meAttribute;
91
222
                        maAttributes.push_back( attr );
92
222
                        SAL_INFO("oox.ppt", "OOX: attrName is " << msCurrentAttribute << " -> " << attrConv->mpAPIName );
93
222
                        break;
94
222
                    }
95
1.44k
                    attrConv++;
96
1.44k
                }
97
222
                mbIsInAttrName = false;
98
222
            }
99
222
            break;
100
222
        default:
101
0
            break;
102
802
        }
103
802
    }
104
105
    void CommonBehaviorContext::onCharacters( const OUString& aChars )
106
222
    {
107
222
        if( mbIsInAttrName )
108
222
        {
109
222
            msCurrentAttribute += aChars;
110
222
        }
111
222
    }
112
113
    ::oox::core::ContextHandlerRef CommonBehaviorContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
114
1.16k
    {
115
1.16k
        switch ( aElementToken )
116
1.16k
        {
117
360
        case PPT_TOKEN( cTn ):
118
360
            return new CommonTimeNodeContext( *this, aElementToken, rAttribs.getFastAttributeList(), mpNode );
119
360
        case PPT_TOKEN( tgtEl ):
120
360
            return new TimeTargetElementContext( *this, mpNode->getTarget() );
121
220
        case PPT_TOKEN( attrNameLst ):
122
220
            mbInAttrList = true;
123
220
            return this;
124
222
        case PPT_TOKEN( attrName ):
125
222
        {
126
222
            if( mbInAttrList )
127
222
            {
128
222
                mbIsInAttrName = true;
129
222
                msCurrentAttribute.clear();
130
222
            }
131
0
            else
132
0
            {
133
0
                SAL_INFO("oox.ppt", "OOX: Attribute Name outside an Attribute List" );
134
0
            }
135
222
            return this;
136
222
        }
137
0
        default:
138
0
            break;
139
1.16k
        }
140
141
0
        return this;
142
1.16k
    }
143
144
}
145
146
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */