Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/inc/txtvfldi.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
/** @#file
21
 *
22
 *  XML import of all variable related text fields plus database display field
23
 */
24
25
#pragma once
26
27
#include "txtfldi.hxx"
28
#include <com/sun/star/beans/XPropertySet.hpp>
29
30
31
/** helper class: parses value-type and associated value attributes */
32
class XMLValueImportHelper final
33
{
34
    SvXMLImport& rImport;
35
    XMLTextImportHelper& rHelper;
36
37
    OUString sValue;     /// string value (only valid if bStringValueOK)
38
    double fValue;              /// double value (only valid if bFloatValueOK)
39
    sal_Int32 nFormatKey;       /// format key (only valid of bFormatOK)
40
    OUString sFormula;   /// formula string
41
    OUString sDefault;   /// default (see bStringDefault/bFormulaDef.)
42
    bool bIsDefaultLanguage;/// format (of nFormatKey) has system language?
43
44
    bool bStringType;       /// is this a string (or a float) type?
45
    bool bFormatOK;         /// have we read a style:data-style-name attr.?
46
    bool bStringValueOK;    /// have we read a string-value attr.?
47
    bool bFormulaOK;        /// have we read the formula attribute?
48
49
    const bool bSetType;    /// should PrepareField set the SetExp subtype?
50
    const bool bSetValue;   /// should PrepareField set content/value?
51
    const bool bSetStyle;   /// should PrepareField set NumberFormat?
52
    const bool bSetFormula; /// should PrepareField set Formula?
53
54
public:
55
    XMLValueImportHelper(
56
        SvXMLImport& rImprt,                    /// XML Import
57
        XMLTextImportHelper& rHlp,              /// text import helper
58
        bool bType,                         /// process type (PrepareField)
59
        bool bStyle,                        /// process data style (P.F.)
60
        bool bValue,                        /// process value (Prep.Field)
61
        bool bFormula);                     /// process formula (Prep.F.)
62
63
    /// process attribute values
64
    void ProcessAttribute( sal_Int32 nAttrToken,
65
                           std::string_view sAttrValue );
66
67
    /// prepare XTextField for insertion into document
68
    void PrepareField(
69
        const css::uno::Reference<css::beans::XPropertySet> & xPropertySet);
70
71
    /// is value a string (rather than double)?
72
0
    bool IsStringValue() const { return bStringType; }
73
74
    /// has format been read?
75
299
    bool IsFormatOK() const { return bFormatOK; }
76
77
632
    void SetDefault(const OUString& sStr) { sDefault = sStr; }
78
};
79
80
81
/**
82
 * abstract parent class for all variable related fields
83
 * - variable-set/get/decl      (not -decls),
84
 * - user-field-get/decl        (not -decls),
85
 * - sequence/-decl             (not -decls),
86
 * - expression,
87
 * - text-input
88
 *
89
 * Processes the following attributes:
90
 * - name
91
 * - formula
92
 * - display
93
 * - value, value-type, data-style-name (via XMLValueImportHelper)
94
 * - description.
95
 *
96
 * Each attribute has a corresponding member, a bool variable to indicate
97
 * whether it was set or not, and a bool variable whether it should be set
98
 * using the standard property name.
99
 *
100
 * bValid is set true, when name is found!
101
 * (Most variable related fields are valid, if a name is
102
 * found. However, some are always valid. In this case, setting bValid
103
 * does not matter.)
104
 */
105
class XMLVarFieldImportContext : public XMLTextFieldImportContext
106
{
107
private:
108
    OUString sName;              /// name attribute
109
    OUString sFormula;           /// formula attribute
110
    OUString sDescription;       /// description
111
    OUString sHelp;              /// help text
112
    OUString sHint;              /// hint
113
    XMLValueImportHelper aValueHelper;  /// value, value-type, and style
114
    bool bDisplayFormula;           /// display formula?(rather than value)
115
    bool bDisplayNone;              /// hide field?
116
117
    bool bFormulaOK;                /// sFormula was set
118
    bool bDescriptionOK;            /// sDescription was set
119
    bool bHelpOK;                   /// sHelp was set
120
    bool bHintOK;                   /// sHint was set
121
    bool bDisplayOK;                /// sDisplayFormula/-None were set
122
123
    bool bSetFormula;               /// set Formula property
124
    bool bSetFormulaDefault;        /// use content as default for formula
125
    bool bSetDescription;           /// set sDescription with Hint-property
126
    bool bSetHelp;
127
    bool bSetHint;
128
    bool bSetVisible;               /// set IsVisible
129
    bool bSetDisplayFormula;        /// set DisplayFormula (sub type???)
130
    bool bSetPresentation;          /// set presentation frm elem. content?
131
132
public:
133
134
135
    XMLVarFieldImportContext(
136
        // for XMLTextFieldImportContext:
137
        SvXMLImport& rImport,           /// XML Import
138
        XMLTextImportHelper& rHlp,      /// text import helper
139
        const OUString& pServiceName, /// name of SO API service
140
        // config variables for PrepareField behavior:
141
        bool bFormula,              /// set Formula property
142
        bool bFormulaDefault,       /// use content as default for formula
143
        bool bDescription,          /// set sDescription with Hint-property
144
        bool bHelp,
145
        bool bHint,
146
        bool bVisible,              /// set IsVisible (display attr)
147
        bool bDisplayFormula,       /// set ??? (display attr.)
148
        bool bType,                 /// set value type with ???-property
149
        bool bStyle,                /// set data style (NumberFormat-Prop.)
150
        bool bValue,                /// set value with Content/Value-Prop.
151
        bool bPresentation);        /// set presentation from elem. content
152
153
protected:
154
    /// process attribute values
155
    virtual void ProcessAttribute( sal_Int32 nAttrToken,
156
                                   std::string_view sAttrValue ) override;
157
158
    /// prepare XTextField for insertion into document
159
    virtual void PrepareField(
160
        const css::uno::Reference<
161
        css::beans::XPropertySet> & xPropertySet) override;
162
163
    // various accessor methods:
164
666
    const OUString& GetName() const { return sName; }
165
0
    bool IsStringValue() const { return aValueHelper.IsStringValue();}
166
};
167
168
169
/** import variable get fields (<text:variable-get>) */
170
class XMLVariableGetFieldImportContext final : public XMLVarFieldImportContext
171
{
172
public:
173
174
175
    XMLVariableGetFieldImportContext(
176
        SvXMLImport& rImport,                   /// XML Import
177
        XMLTextImportHelper& rHlp);             /// Text import helper
178
179
180
private:
181
    /// prepare XTextField for insertion into document
182
    virtual void PrepareField(
183
        const css::uno::Reference<
184
        css::beans::XPropertySet> & xPropertySet) override;
185
};
186
187
188
/** import expression fields (<text:expression>) */
189
class XMLExpressionFieldImportContext final : public XMLVarFieldImportContext
190
{
191
public:
192
193
    XMLExpressionFieldImportContext(
194
        SvXMLImport& rImport,                   /// XML Import
195
        XMLTextImportHelper& rHlp);              /// Text import helper
196
197
private:
198
    virtual void PrepareField(
199
        const css::uno::Reference<
200
        css::beans::XPropertySet> & xPropertySet) override;
201
};
202
203
/*** import text input fields (<text:text-input>) */
204
class XMLTextInputFieldImportContext final : public XMLVarFieldImportContext
205
{
206
public:
207
208
    XMLTextInputFieldImportContext(
209
        SvXMLImport& rImport,                   /// XML Import
210
        XMLTextImportHelper& rHlp);             /// Text import helper
211
212
private:
213
    virtual void PrepareField(
214
        const css::uno::Reference<
215
        css::beans::XPropertySet> & xPropertySet) override;
216
};
217
218
219
/**
220
 * upperclass for variable/user-set, var/user-input, and sequence fields
221
 * inds field master of appropriate type and attaches field to it.
222
 */
223
class XMLSetVarFieldImportContext : public XMLVarFieldImportContext
224
{
225
    const VarType eFieldType;
226
227
public:
228
229
230
    XMLSetVarFieldImportContext(
231
        // for XMLTextFieldImportContext:
232
        SvXMLImport& rImport,           /// see XMLTextFieldImportContext
233
        XMLTextImportHelper& rHlp,      /// see XMLTextFieldImportContext
234
        const OUString& pServiceName, /// see XMLTextFieldImportContext
235
        // for finding appropriate field master (see endFastElement())
236
        VarType eVarType,               /// variable type
237
        // config variables:
238
        bool bFormula,              /// see XMLTextFieldImportContext
239
        bool bFormulaDefault,       /// see XMLTextFieldImportContext
240
        bool bDescription,          /// see XMLTextFieldImportContext
241
        bool bHelp,                 /// see XMLTextFieldImportContext
242
        bool bHint,                 /// see XMLTextFieldImportContext
243
        bool bVisible,              /// see XMLTextFieldImportContext
244
        bool bDisplayFormula,       /// see XMLTextFieldImportContext
245
        bool bType,                 /// see XMLTextFieldImportContext
246
        bool bStyle,                /// see XMLTextFieldImportContext
247
        bool bValue,                /// see XMLTextFieldImportContext
248
        bool bPresentation);        /// see XMLTextFieldImportContext
249
250
protected:
251
252
    /// create XTextField, attach master and insert into document;
253
    /// also calls PrepareTextField
254
    virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
255
256
    /// find appropriate field master
257
    bool FindFieldMaster(
258
        css::uno::Reference<
259
        css::beans::XPropertySet> & xMaster);
260
};
261
262
263
/** import variable set fields (<text:variable-set>) */
264
class XMLVariableSetFieldImportContext final : public XMLSetVarFieldImportContext
265
{
266
public:
267
268
    XMLVariableSetFieldImportContext(
269
        SvXMLImport& rImport,                   /// XML Import
270
        XMLTextImportHelper& rHlp);             /// Text import helper
271
\
272
private:
273
    /// prepare XTextField for insertion into document
274
    virtual void PrepareField(
275
        const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
276
};
277
278
279
/** variable input fields (<text:variable-input>) */
280
class XMLVariableInputFieldImportContext final : public XMLSetVarFieldImportContext
281
{
282
public:
283
284
285
    XMLVariableInputFieldImportContext(
286
        SvXMLImport& rImport,                   /// XML Import
287
        XMLTextImportHelper& rHlp);             /// Text import helper
288
289
private:
290
291
    /// prepare XTextField for insertion into document
292
    virtual void PrepareField(
293
        const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
294
};
295
296
297
/** user fields (<text:user-field-get>) */
298
class XMLUserFieldImportContext final : public XMLSetVarFieldImportContext
299
{
300
301
public:
302
303
304
    XMLUserFieldImportContext(
305
        SvXMLImport& rImport,                   /// XML Import
306
        XMLTextImportHelper& rHlp);             /// Text import helper
307
};
308
309
/** user input fields (<text:user-field-input>) */
310
class XMLUserFieldInputImportContext final : public XMLVarFieldImportContext
311
{
312
313
public:
314
315
316
    XMLUserFieldInputImportContext(
317
        SvXMLImport& rImport,                   /// XML Import
318
        XMLTextImportHelper& rHlp);             /// Text import helper
319
320
    virtual void PrepareField(
321
        const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
322
};
323
324
325
/** sequence fields (<text:sequence>) */
326
class XMLSequenceFieldImportContext final : public XMLSetVarFieldImportContext
327
{
328
    OUString sNumFormat;
329
    OUString sNumFormatSync;
330
    OUString sRefName;
331
332
    bool bRefNameOK;
333
334
public:
335
336
337
    XMLSequenceFieldImportContext(
338
        SvXMLImport& rImport,                   /// XML Import
339
        XMLTextImportHelper& rHlp);             /// Text import helper
340
341
private:
342
343
    /// process attribute values
344
    virtual void ProcessAttribute( sal_Int32 nAttrToken,
345
                                   std::string_view sAttrValue ) override;
346
347
    /// prepare XTextField for insertion into document
348
    virtual void PrepareField(
349
        const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
350
};
351
352
353
/**
354
 * variable declaration container for all variable fields
355
 *      (variable-decls, user-field-decls, sequence-decls)
356
 */
357
class XMLVariableDeclsImportContext final : public SvXMLImportContext
358
{
359
    enum VarType eVarDeclsContextType;
360
    XMLTextImportHelper& rImportHelper;
361
362
public:
363
364
    XMLVariableDeclsImportContext(
365
        SvXMLImport& rImport,                   /// XML Import
366
        XMLTextImportHelper& rHlp,              /// text import helper
367
        enum VarType eVarType);                 /// variable type
368
369
    virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
370
        sal_Int32 nElement,
371
        const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
372
};
373
374
/**
375
 * variable field declarations
376
 *      (variable-decl, user-field-decl, sequence-decl)
377
 */
378
class XMLVariableDeclImportContext final : public SvXMLImportContext
379
{
380
public:
381
382
383
    XMLVariableDeclImportContext(
384
        SvXMLImport& rImport,                   /// XML Import
385
        XMLTextImportHelper& rHlp,              /// text import helper
386
        sal_Int32 nElement,
387
        const css::uno::Reference< css::xml::sax::XFastAttributeList> & xAttrList,/// list of element attributes
388
        enum VarType eVarType);                 /// variable type
389
390
    /// get field master for name and rename if appropriate
391
    static bool FindFieldMaster(css::uno::Reference<css::beans::XPropertySet> & xMaster,
392
                                    SvXMLImport& rImport,
393
                                    XMLTextImportHelper& rHelper,
394
                                    const OUString& sVarName,
395
                                    enum VarType eVarType);
396
};
397
398
399
/** import table formula fields (deprecated; for Writer 2.0 compatibility) */
400
class XMLTableFormulaImportContext final : public XMLTextFieldImportContext
401
{
402
    XMLValueImportHelper aValueHelper;
403
404
    bool bIsShowFormula;
405
406
public:
407
408
    XMLTableFormulaImportContext(
409
        SvXMLImport& rImport,                   /// XML Import
410
        XMLTextImportHelper& rHlp);             /// text import helper
411
412
private:
413
414
    /// process attribute values
415
    virtual void ProcessAttribute( sal_Int32 nAttrToken,
416
                                   std::string_view sAttrValue ) override;
417
418
    /// prepare XTextField for insertion into document
419
    virtual void PrepareField(
420
        const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) override;
421
};
422
423
424
/** import database display fields (<text:database-display>) */
425
class XMLDatabaseDisplayImportContext final : public XMLDatabaseFieldImportContext
426
{
427
    XMLValueImportHelper aValueHelper;
428
429
    OUString sColumnName;
430
    bool bColumnOK;
431
432
    bool bDisplay;
433
    bool bDisplayOK;
434
435
public:
436
437
438
    XMLDatabaseDisplayImportContext(
439
        SvXMLImport& rImport,                   /// XML Import
440
        XMLTextImportHelper& rHlp);              /// text import helper
441
442
private:
443
444
    /// process attribute values
445
    virtual void ProcessAttribute( sal_Int32 nAttrToken,
446
                                   std::string_view sAttrValue ) override;
447
448
    /// create, prepare and insert database field master and database field
449
    virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
450
};
451
452
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */