Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/xmloff/source/transform/NotesTContext.cxx
Line
Count
Source (jump to first uncovered line)
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 <com/sun/star/xml/sax/XDocumentHandler.hpp>
21
#include <osl/diagnose.h>
22
#include <xmloff/namespacemap.hxx>
23
#include <xmloff/xmltoken.hxx>
24
#include <xmloff/xmlnamespace.hxx>
25
26
#include "TransformerBase.hxx"
27
#include "TransformerActions.hxx"
28
#include "AttrTransformerAction.hxx"
29
#include "ActionMapTypesOASIS.hxx"
30
#include "MutableAttrList.hxx"
31
#include "RenameElemTContext.hxx"
32
#include "FlatTContext.hxx"
33
34
#include "NotesTContext.hxx"
35
36
using namespace ::xmloff::token;
37
using namespace ::com::sun::star::uno;
38
using namespace ::com::sun::star::xml::sax;
39
40
XMLNotesTransformerContext::XMLNotesTransformerContext(
41
        XMLTransformerBase& rImp,
42
        const OUString& rQName,
43
        XMLTokenEnum eToken, bool bPersistent ) :
44
0
    XMLPersElemContentTContext( rImp, rQName ),
45
0
    m_bEndNote( false ),
46
0
    m_bPersistent( bPersistent ),
47
0
    m_eTypeToken( eToken )
48
0
{
49
0
}
50
51
XMLNotesTransformerContext::~XMLNotesTransformerContext()
52
0
{
53
0
}
54
55
void XMLNotesTransformerContext::StartElement(
56
        const Reference< XAttributeList >& rAttrList )
57
0
{
58
0
    XMLTransformerActions *pActions =
59
0
        GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS );
60
0
    OSL_ENSURE( pActions, "go no actions" );
61
62
0
    Reference< XAttributeList > xAttrList( rAttrList );
63
0
    rtl::Reference<XMLMutableAttributeList> pMutableAttrList;
64
0
    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
65
0
    for( sal_Int16 i=0; i < nAttrCount; i++ )
66
0
    {
67
0
        const OUString aAttrName = xAttrList->getNameByIndex( i );
68
0
        OUString aLocalName;
69
0
        sal_uInt16 nPrefix =
70
0
            GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
71
0
                                                                 &aLocalName );
72
0
        XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
73
0
        XMLTransformerActions::const_iterator aIter =
74
0
            pActions->find( aKey );
75
0
        if( aIter != pActions->end() )
76
0
        {
77
0
            const OUString aAttrValue = xAttrList->getValueByIndex( i );
78
79
0
            if( !pMutableAttrList )
80
0
            {
81
0
                pMutableAttrList =
82
0
                    new XMLMutableAttributeList( xAttrList );
83
0
                xAttrList = pMutableAttrList;
84
0
            }
85
0
            switch( (*aIter).second.m_nActionType )
86
0
            {
87
0
            case XML_ATACTION_STYLE_FAMILY:
88
0
                {
89
0
                    if( IsXMLToken( aAttrValue, XML_FOOTNOTE ) )
90
0
                    {
91
0
                    }
92
0
                    else if( IsXMLToken( aAttrValue, XML_ENDNOTE ) )
93
0
                    {
94
0
                        m_bEndNote = true;
95
0
                    }
96
0
                    pMutableAttrList->RemoveAttributeByIndex( i );
97
0
                    --i;
98
0
                    --nAttrCount;
99
0
                }
100
0
                break;
101
0
            case XML_ATACTION_DECODE_STYLE_NAME:
102
0
            case XML_ATACTION_DECODE_STYLE_NAME_REF:
103
0
                {
104
0
                    OUString aAttrValue2( aAttrValue );
105
0
                    if( XMLTransformerBase::DecodeStyleName(aAttrValue2) )
106
0
                        pMutableAttrList->SetValueByIndex( i, aAttrValue2 );
107
0
                }
108
0
                break;
109
0
            }
110
0
        }
111
0
    }
112
113
0
    XMLTokenEnum eToken = XML_FOOTNOTE;
114
0
    switch( m_eTypeToken )
115
0
    {
116
0
    case XML_NOTE:
117
0
        eToken = (m_bEndNote ? XML_ENDNOTE : XML_FOOTNOTE);
118
0
        break;
119
0
    case XML_NOTES_CONFIGURATION:
120
0
        eToken = (m_bEndNote ? XML_ENDNOTES_CONFIGURATION
121
0
                             : XML_FOOTNOTES_CONFIGURATION);
122
0
        break;
123
0
    case XML_NOTE_REF:
124
0
        eToken = (m_bEndNote ? XML_ENDNOTE_REF : XML_FOOTNOTE_REF);
125
0
        break;
126
0
    default:
127
0
        OSL_ENSURE( XML_NOTE==m_eTypeToken, "invalid note type" );
128
0
        break;
129
0
    }
130
131
0
    SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey(
132
0
                            XML_NAMESPACE_TEXT,
133
0
                            ::xmloff::token::GetXMLToken( eToken ) ) );
134
0
    if( m_bPersistent )
135
0
        XMLPersElemContentTContext::StartElement( xAttrList );
136
0
    else
137
0
        GetTransformer().GetDocHandler()->startElement( GetExportQName(),
138
0
                                                        xAttrList );
139
0
}
140
141
void XMLNotesTransformerContext::EndElement()
142
0
{
143
0
    if( m_bPersistent )
144
0
    {
145
0
        XMLPersElemContentTContext::EndElement();
146
0
    }
147
0
    else
148
0
    {
149
0
        GetTransformer().GetDocHandler()->endElement( GetExportQName() );
150
0
    }
151
0
}
152
153
rtl::Reference<XMLTransformerContext> XMLNotesTransformerContext::CreateChildContext(
154
        sal_uInt16 nPrefix,
155
        const OUString& rLocalName,
156
        const OUString& rQName,
157
        const Reference< XAttributeList >& rAttrList )
158
0
{
159
0
    rtl::Reference<XMLTransformerContext> pContext;
160
0
    if( XML_NOTE == m_eTypeToken )
161
0
    {
162
0
        if( XML_NAMESPACE_TEXT == nPrefix )
163
0
        {
164
0
            XMLTokenEnum eToken ( XML_TOKEN_INVALID );
165
0
            if( IsXMLToken( rLocalName, XML_NOTE_CITATION ) )
166
0
            {
167
0
                eToken = m_bEndNote ? XML_ENDNOTE_CITATION
168
0
                                  : XML_FOOTNOTE_CITATION;
169
0
            }
170
0
            else if( IsXMLToken( rLocalName, XML_NOTE_BODY ) )
171
0
            {
172
0
                eToken = m_bEndNote ? XML_ENDNOTE_BODY
173
0
                                  : XML_FOOTNOTE_BODY;
174
0
            }
175
176
0
            if( XML_TOKEN_INVALID != eToken )
177
0
            {
178
0
                if( m_bPersistent  )
179
0
                {
180
0
                    pContext.set(new XMLPersTextContentTContext(
181
0
                                    GetTransformer(), rQName,
182
0
                                    XML_NAMESPACE_TEXT,
183
0
                                    eToken ));
184
0
                    AddContent( pContext );
185
186
0
                }
187
0
                else
188
0
                {
189
0
                    pContext.set(new XMLRenameElemTransformerContext(
190
0
                                    GetTransformer(), rQName,
191
0
                                    XML_NAMESPACE_TEXT,
192
0
                                    eToken ));
193
0
                }
194
0
            }
195
0
        }
196
0
    }
197
198
0
    if( !pContext.is() )
199
0
    {
200
0
        pContext = m_bPersistent
201
0
                        ? XMLPersElemContentTContext::CreateChildContext(
202
0
                                nPrefix, rLocalName, rQName, rAttrList )
203
0
                        : XMLTransformerContext::CreateChildContext(
204
0
                                nPrefix, rLocalName, rQName, rAttrList );
205
0
    }
206
207
0
    return pContext;
208
0
}
209
210
bool XMLNotesTransformerContext::IsPersistent() const
211
0
{
212
0
    return m_bPersistent;
213
0
}
214
215
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */