Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/xmloff/xmlictxt.hxx
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
#ifndef INCLUDED_XMLOFF_XMLICTXT_HXX
21
#define INCLUDED_XMLOFF_XMLICTXT_HXX
22
23
#include <sal/config.h>
24
#include <xmloff/dllapi.h>
25
#include <rtl/ref.hxx>
26
#include <sal/log.hxx>
27
#include <sal/types.h>
28
#include <com/sun/star/xml/sax/XFastContextHandler.hpp>
29
#include <com/sun/star/lang/XTypeProvider.hpp>
30
#include <rtl/ustring.hxx>
31
#include <xmloff/namespacemap.hxx>
32
#include <optional>
33
34
class SvXMLImport;
35
36
class SvXMLImportContext;
37
38
typedef rtl::Reference<SvXMLImportContext> SvXMLImportContextRef;
39
40
/**
41
This class deliberately does not support XWeak, to improve performance when loading
42
large documents.
43
*/
44
class XMLOFF_DLLPUBLIC SvXMLImportContext : public css::xml::sax::XFastContextHandler,
45
                                            public css::lang::XTypeProvider
46
47
{
48
    friend class SvXMLImport;
49
50
    SvXMLImport&                       mrImport;
51
    oslInterlockedCount                m_nRefCount;
52
    std::optional<SvXMLNamespaceMap>  m_xRewindMap;
53
54
2.74M
    SAL_DLLPRIVATE std::optional<SvXMLNamespaceMap> TakeRewindMap() { return std::move(m_xRewindMap); }
55
190k
    SAL_DLLPRIVATE void PutRewindMap(std::optional<SvXMLNamespaceMap>&& p) { m_xRewindMap = std::move(p); }
56
57
protected:
58
59
8.61M
    SvXMLImport& GetImport() { return mrImport; }
60
486k
    const SvXMLImport& GetImport() const { return mrImport; }
61
62
public:
63
64
    /** A contexts constructor does anything that is required if an element
65
     * starts. Namespace processing has been done already.
66
     * Note that virtual methods cannot be used inside constructors. Use
67
     * StartElement instead if this is required. */
68
    SvXMLImportContext( SvXMLImport& rImport );
69
70
    /** A contexts destructor does anything that is required if an element
71
     * ends. By default, nothing is done.
72
     * Note that virtual methods cannot be used inside destructors. Use
73
     * EndElement instead if this is required. */
74
    virtual ~SvXMLImportContext();
75
76
    // css::xml::sax::XFastContextHandler:
77
    virtual void SAL_CALL startFastElement (sal_Int32 Element,
78
        const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs) override;
79
80
    virtual void SAL_CALL startUnknownElement(const OUString & Namespace, const OUString & Name,
81
        const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override;
82
83
    /** endFastElement is called before a context will be destructed, but
84
     * after an elements context has been parsed. It may be used for actions
85
     * that require virtual methods. The default is to do nothing. */
86
    virtual void SAL_CALL endFastElement(sal_Int32 Element) override;
87
88
    virtual void SAL_CALL endUnknownElement(const OUString & Namespace, const OUString & Name) override;
89
90
    virtual css::uno::Reference< XFastContextHandler >  SAL_CALL createFastChildContext(sal_Int32 Element,
91
        const css::uno::Reference<css::xml::sax::XFastAttributeList>& Attribs) override;
92
93
    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(
94
        const OUString & Namespace, const OUString & Name,
95
        const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override;
96
97
    /** This method is called for all characters that are contained in the
98
     * current element. The default is to ignore them. */
99
    virtual void SAL_CALL characters(const OUString & aChars) override;
100
101
    // XInterface
102
    virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) final override;
103
    virtual void SAL_CALL acquire() noexcept final override
104
39.7M
    { osl_atomic_increment(&m_nRefCount); }
105
    virtual void SAL_CALL release() noexcept final override
106
39.7M
    { if (osl_atomic_decrement(&m_nRefCount) == 0) delete this; }
107
108
    // XTypeProvider
109
    virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes(  ) final override;
110
    virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId(  ) final override;
111
};
112
113
#define XMLOFF_WARN_UNKNOWN(area, rIter) \
114
27.5k
    SAL_WARN(area, "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(rIter.getToken()) << " value=" << rIter.toString());
115
116
#define XMLOFF_INFO_UNKNOWN(area, rIter) \
117
47.6k
    SAL_INFO(area, "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(rIter.getToken()) << " value=" << rIter.toString());
118
119
#define XMLOFF_WARN_UNKNOWN_ATTR(area, token, value) \
120
60
    SAL_WARN(area, "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(token) << "=" << value);
121
122
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token) \
123
686k
    SAL_WARN(area, "unknown element " << SvXMLImport::getPrefixAndNameFromToken(token));
124
125
#define XMLOFF_INFO_UNKNOWN_ELEMENT(area, token) \
126
63.3k
    SAL_INFO(area, "unknown element " << SvXMLImport::getPrefixAndNameFromToken(token));
127
128
#endif // INCLUDED_XMLOFF_XMLICTXT_HXX
129
130
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */