Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/transform/CreateElemTContext.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 <sal/config.h>
21
22
#include <vector>
23
24
#include "CreateElemTContext.hxx"
25
#include "MutableAttrList.hxx"
26
#include "TransformerBase.hxx"
27
#include "TransformerActions.hxx"
28
#include "FlatTContext.hxx"
29
#include "AttrTransformerAction.hxx"
30
#include <xmloff/namespacemap.hxx>
31
#include <osl/diagnose.h>
32
33
using namespace ::com::sun::star::uno;
34
using namespace ::com::sun::star::xml::sax;
35
using namespace ::xmloff::token;
36
37
XMLCreateElemTransformerContext::XMLCreateElemTransformerContext(
38
        XMLTransformerBase& rImp,
39
        const OUString& rQName,
40
       sal_uInt16 nActionMap ) :
41
0
    XMLTransformerContext( rImp, rQName ),
42
0
    m_nActionMap( nActionMap )
43
0
{
44
0
}
45
46
void XMLCreateElemTransformerContext::StartElement(
47
        const Reference< XAttributeList >& rAttrList )
48
0
{
49
0
    Reference< XAttributeList > xAttrList( rAttrList );
50
51
0
    std::vector<rtl::Reference<XMLTransformerContext>> aChildContexts;
52
53
0
    rtl::Reference<XMLMutableAttributeList> pMutableAttrList;
54
0
    XMLTransformerActions *pActions =
55
0
        GetTransformer().GetUserDefinedActions( m_nActionMap );
56
0
    OSL_ENSURE( pActions, "go no actions" );
57
0
    if( pActions )
58
0
    {
59
0
        sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
60
0
        for( sal_Int16 i=0; i < nAttrCount; ++i )
61
0
        {
62
0
            const OUString aAttrName = xAttrList->getNameByIndex( i );
63
0
            const OUString aAttrValue = xAttrList->getValueByIndex( i );
64
0
            OUString aLocalName;
65
0
            sal_uInt16 nPrefix =
66
0
                GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
67
0
                                                           &aLocalName );
68
69
0
            XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
70
0
            XMLTransformerActions::const_iterator aIter =
71
0
                    pActions->find( aKey );
72
0
            if( aIter != pActions->end() )
73
0
            {
74
0
                if( !pMutableAttrList )
75
0
                {
76
0
                    pMutableAttrList = new XMLMutableAttributeList( xAttrList );
77
0
                    xAttrList = pMutableAttrList;
78
0
                }
79
0
                sal_uInt32 nAction = (*aIter).second.m_nActionType;
80
0
                switch( nAction )
81
0
                {
82
0
                case XML_ATACTION_MOVE_TO_ELEM:
83
0
                    {
84
0
                        OUString aElemQName(
85
0
                            GetTransformer().GetNamespaceMap().GetQNameByKey(
86
0
                                (*aIter).second.GetQNamePrefixFromParam1(),
87
0
                                ::xmloff::token::GetXMLToken(
88
0
                                (*aIter).second.GetQNameTokenFromParam1()) ) );
89
0
                        rtl::Reference<XMLTransformerContext> pContext(
90
0
                            new XMLPersTextContentTContext( GetTransformer(),
91
0
                                                       aElemQName ));
92
0
                        pContext->Characters( aAttrValue );
93
0
                        aChildContexts.push_back(pContext);
94
0
                        pMutableAttrList->RemoveAttributeByIndex( i );
95
0
                        --i;
96
0
                        --nAttrCount;
97
0
                    }
98
0
                    break;
99
0
                default:
100
0
                    OSL_ENSURE( false, "unknown action" );
101
0
                    break;
102
0
                }
103
0
            }
104
0
        }
105
0
    }
106
0
    XMLTransformerContext::StartElement( xAttrList );
107
108
0
    for (auto const & i: aChildContexts)
109
0
    {
110
0
        i->Export();
111
0
    }
112
0
}
113
114
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */