Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/xmloff/xmlimppr.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
#ifndef INCLUDED_XMLOFF_XMLIMPPR_HXX
20
#define INCLUDED_XMLOFF_XMLIMPPR_HXX
21
22
#include <rtl/ref.hxx>
23
#include <sal/config.h>
24
#include <xmloff/dllapi.h>
25
#include <sal/types.h>
26
#include <rtl/ustring.hxx>
27
28
#include <vector>
29
#include <salhelper/simplereferenceobject.hxx>
30
31
namespace com::sun::star::beans { class XMultiPropertySet; }
32
namespace com::sun::star::beans { class XPropertySet; }
33
namespace com::sun::star::beans { class XPropertySetInfo; }
34
namespace com::sun::star::beans { class XTolerantMultiPropertySet; }
35
namespace com::sun::star::beans { struct PropertyValue; }
36
namespace com::sun::star::container { class XNameContainer; }
37
namespace com::sun::star::uno { class Any; }
38
namespace com::sun::star::uno { template <typename > class Reference; }
39
namespace com::sun::star::uno { template <typename > class Sequence; }
40
namespace com::sun::star::xml::sax { class XFastAttributeList; }
41
#if defined __GNUC__ // gcc does not like visibility annotation on enum
42
namespace com::sun::star::drawing { enum class FillStyle; }
43
#else
44
namespace com::sun::star::drawing { enum class SAL_DLLPUBLIC_RTTI FillStyle; }
45
#endif
46
47
struct XMLPropertyState;
48
class XMLPropertySetMapper;
49
50
51
class SvXMLUnitConverter;
52
class SvXMLNamespaceMap;
53
class SvXMLImport;
54
55
/** This struct is used as an optional parameter to the static
56
 * _FillPropertySet() methods.
57
 *
58
 * It should not be used in any other context.
59
 */
60
struct ContextID_Index_Pair
61
{
62
    sal_Int16 /*const*/ nContextID;
63
    sal_Int32 nIndex;
64
    css::drawing::FillStyle /*const*/ nExpectedFillStyle;
65
};
66
67
class XMLOFF_DLLPUBLIC SvXMLImportPropertyMapper
68
{
69
    std::unique_ptr< SvXMLImportPropertyMapper> mxNextMapper;
70
71
    SvXMLImport& m_rImport;   // access to error handling
72
73
    SvXMLImportPropertyMapper(SvXMLImportPropertyMapper const &) = delete;
74
    SvXMLImportPropertyMapper& operator =(SvXMLImportPropertyMapper const &) = delete;
75
76
protected:
77
78
    rtl::Reference< XMLPropertySetMapper > maPropMapper;
79
161k
    SvXMLImport& GetImport() const { return m_rImport;}
80
81
public:
82
83
    SvXMLImportPropertyMapper(
84
            rtl::Reference< XMLPropertySetMapper > xMapper,
85
            SvXMLImport& rImport);
86
    virtual ~SvXMLImportPropertyMapper();
87
88
    // Add an ImportPropertyMapper at the end of the import mapper chain.
89
    // The added mapper MUST not be used outside the Mapper chain any longer,
90
    // because its PropertyMapper will be replaced.
91
    void ChainImportMapper(
92
        std::unique_ptr< SvXMLImportPropertyMapper> rMapper );
93
94
    /** fills the given itemset with the attributes in the given list
95
      * the map is only searched within the range
96
      * [nStartIdx, nEndIdx[
97
      */
98
    void importXML(
99
            ::std::vector< XMLPropertyState >& rProperties,
100
            const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
101
            const SvXMLUnitConverter& rUnitConverter,
102
            const SvXMLNamespaceMap& rNamespaceMap,
103
            sal_uInt32 nPropType,
104
            sal_Int32 nStartIdx, sal_Int32 nEndIdx ) const;
105
106
    /** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */
107
    virtual bool handleSpecialItem(
108
            XMLPropertyState& rProperty,
109
            ::std::vector< XMLPropertyState >& rProperties,
110
            const OUString& rValue,
111
            const SvXMLUnitConverter& rUnitConverter,
112
            const SvXMLNamespaceMap& rNamespaceMap ) const;
113
114
    /** This method is called when all attributes have benn processed. It may be used to remove items that are incomplete */
115
    virtual void finished(std::vector<XMLPropertyState>& rProperties, sal_Int32 nStartIndex,
116
                          sal_Int32 nEndIndex, const sal_uInt32 nPropType) const;
117
118
    void CheckSpecialContext(
119
            const ::std::vector< XMLPropertyState >& rProperties,
120
            const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
121
            ContextID_Index_Pair* pSpecialContextIds ) const;
122
123
    bool FillPropertySet(
124
            const ::std::vector< XMLPropertyState >& rProperties,
125
            const css::uno::Reference< css::beans::XPropertySet >& rPropSet,
126
            ContextID_Index_Pair* pSpecialContextIds = nullptr ) const;
127
128
    void FillPropertySequence(
129
            const ::std::vector< XMLPropertyState >& aProperties,
130
            css::uno::Sequence< css::beans::PropertyValue >& rValues )
131
            const;
132
133
    inline const rtl::Reference< XMLPropertySetMapper >&
134
        getPropertySetMapper() const;
135
136
137
    /** implementation helper for FillPropertySet: fill an XPropertySet.
138
     * Exceptions will be asserted. */
139
    static bool FillPropertySet_(
140
        const ::std::vector<XMLPropertyState> & rProperties,
141
        const css::uno::Reference< css::beans::XPropertySet> & rPropSet,
142
        const css::uno::Reference< css::beans::XPropertySetInfo> & rPropSetInfo,
143
        const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
144
        SvXMLImport& rImport,
145
146
        // parameter for use by txtstyli.cxx; allows efficient
147
        // catching the combined characters property
148
        ContextID_Index_Pair* pSpecialContextIds );
149
150
    /** implementation helper for FillPropertySet: fill an XMultiPropertySet.
151
     * If unsuccessful, set return value. */
152
    static bool FillMultiPropertySet_(
153
        const ::std::vector<XMLPropertyState> & rProperties,
154
        const css::uno::Reference< css::beans::XMultiPropertySet> & rMultiPropSet,
155
        const css::uno::Reference< css::beans::XPropertySetInfo> & rPropSetInfo,
156
        const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
157
158
        // parameters for use by txtstyli.cxx; allows efficient
159
        // catching the combined characters property
160
        ContextID_Index_Pair* pSpecialContextIds );
161
162
    /** implementation helper for FillPropertySet: fill an XTolerantMultiPropertySet.
163
     * If unsuccessful, set return value. */
164
    static bool FillTolerantMultiPropertySet_(
165
        const ::std::vector<XMLPropertyState> & rProperties,
166
        const css::uno::Reference< css::beans::XTolerantMultiPropertySet> & rTolPropSet,
167
        const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
168
        SvXMLImport& rImport,
169
170
        // parameters for use by txtstyli.cxx; allows efficient
171
        // catching the combined characters property
172
        ContextID_Index_Pair* pSpecialContextIds );
173
174
175
    static void PrepareForMultiPropertySet_(
176
        const ::std::vector<XMLPropertyState> & rProperties,
177
        const css::uno::Reference< css::beans::XPropertySetInfo> & rPropSetInfo,
178
        const rtl::Reference<XMLPropertySetMapper> & rPropMapper,
179
        ContextID_Index_Pair* pSpecialContextIds,
180
        css::uno::Sequence< OUString >& rNames,
181
        css::uno::Sequence< css::uno::Any >& rValues);
182
183
private:
184
    void importXMLAttribute(
185
        std::vector< XMLPropertyState >& rProperties,
186
        const SvXMLUnitConverter& rUnitConverter,
187
        const SvXMLNamespaceMap& rNamespaceMap,
188
        sal_uInt32 nPropType,
189
        sal_Int32 nStartIdx,
190
        sal_Int32 nEndIdx,
191
        css::uno::Reference< css::container::XNameContainer >& xAttrContainer,
192
        const OUString& sAttrName,
193
        const OUString& aNamespaceURI,
194
        const OUString& sValue) const;
195
};
196
197
198
inline const rtl::Reference< XMLPropertySetMapper >&
199
    SvXMLImportPropertyMapper::getPropertySetMapper() const
200
10.0M
{
201
10.0M
    return maPropMapper;
202
10.0M
}
203
204
namespace xmloff {
205
206
bool IsIgnoreFillStyleNamedItem(
207
        css::uno::Reference<css::beans::XPropertySet> const& xProps,
208
        css::drawing::FillStyle nExpectedFillStyle);
209
210
}
211
212
#endif // INCLUDED_XMLOFF_XMLIMPPR_HXX
213
214
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */