1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 * XML import of all variable related text fields plus database display field
25 #ifndef INCLUDED_XMLOFF_INC_TXTVFLDI_HXX
26 #define INCLUDED_XMLOFF_INC_TXTVFLDI_HXX
28 #include "txtfldi.hxx"
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/beans/XPropertySetInfo.hpp>
33 /** helper class: parses value-type and associated value attributes */
34 class XMLValueImportHelper final
37 const OUString sPropertyContent
;
38 const OUString sPropertyValue
;
39 const OUString sPropertyNumberFormat
;
40 const OUString sPropertyIsFixedLanguage
;
43 XMLTextImportHelper
& rHelper
;
45 OUString sValue
; /// string value (only valid if bStringValueOK)
46 double fValue
; /// double value (only valid if bFloatValueOK)
47 sal_Int32 nFormatKey
; /// format key (only valid of bFormatOK)
48 OUString sFormula
; /// formula string
49 OUString sDefault
; /// default (see bStringDefault/bFormulaDef.)
50 bool bIsDefaultLanguage
;/// format (of nFormatKey) has system language?
52 bool bStringType
; /// is this a string (or a float) type?
53 bool bFormatOK
; /// have we read a style:data-style-name attr.?
54 bool bTypeOK
; /// have we read a value-type attribute?
55 bool bStringValueOK
; /// have we read a string-value attr.?
56 bool bFloatValueOK
; /// have we read any of the float attr.s?
57 bool bFormulaOK
; /// have we read the formula attribute?
59 const bool bSetType
; /// should PrepareField set the SetExp subtype?
60 const bool bSetValue
; /// should PrepareField set content/value?
61 const bool bSetStyle
; /// should PrepareField set NumberFormat?
62 const bool bSetFormula
; /// should PrepareField set Formula?
66 SvXMLImport
& rImprt
, /// XML Import
67 XMLTextImportHelper
& rHlp
, /// text import helper
68 bool bType
, /// process type (PrepareField)
69 bool bStyle
, /// process data style (P.F.)
70 bool bValue
, /// process value (Prep.Field)
71 bool bFormula
); /// process formula (Prep.F.)
73 ~XMLValueImportHelper();
75 /// process attribute values
76 void ProcessAttribute( sal_uInt16 nAttrToken
,
77 const OUString
& sAttrValue
);
79 /// prepare XTextField for insertion into document
81 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
);
83 /// is value a string (rather than double)?
84 inline bool IsStringValue() { return bStringType
; }
86 /// has format been read?
87 inline bool IsFormatOK() { return bFormatOK
; }
89 inline void SetDefault(const OUString
& sStr
) { sDefault
= sStr
; }
94 * abstract parent class for all variable related fields
95 * - variable-set/get/decl (not -decls),
96 * - user-field-get/decl (not -decls),
97 * - sequence/-decl (not -decls),
101 * Processes the following attributes:
105 * - value, value-type, data-style-name (via XMLValueImportHelper)
108 * Each attribute has a corresponding member, a bool variable to indicate
109 * whether it was set or not, and a bool variable whether it should be set
110 * using the standard property name.
112 * bValid is set true, when name is found!
113 * (Most variable related fields are valid, if a name is
114 * found. However, some are always valid. In this case, setting bValid
117 class XMLVarFieldImportContext
: public XMLTextFieldImportContext
120 const OUString sPropertyContent
;
121 const OUString sPropertyHint
;
122 const OUString sPropertyHelp
;
123 const OUString sPropertyTooltip
;
124 const OUString sPropertyIsVisible
;
125 const OUString sPropertyIsDisplayFormula
;
126 const OUString sPropertyCurrentPresentation
;
129 OUString sName
; /// name attribute
130 OUString sFormula
; /// formula attribute
131 OUString sDescription
; /// description
132 OUString sHelp
; /// help text
133 OUString sHint
; /// hint
134 XMLValueImportHelper aValueHelper
; /// value, value-type, and style
135 bool bDisplayFormula
; /// display formula?(rather than value)
136 bool bDisplayNone
; /// hide field?
138 bool bNameOK
; /// sName was set
139 bool bFormulaOK
; /// sFormula was set
140 bool bDescriptionOK
; /// sDescription was set
141 bool bHelpOK
; /// sHelp was set
142 bool bHintOK
; /// sHint was set
143 bool bDisplayOK
; /// sDisplayFormula/-None were set
145 bool bSetFormula
; /// set Formula property
146 bool bSetFormulaDefault
; /// use content as default for formula
147 bool bSetDescription
; /// set sDescription with Hint-property
150 bool bSetVisible
; /// set IsVisible
151 bool bSetDisplayFormula
; /// set DisplayFormula (sub type???)
152 bool bSetPresentation
; /// set presentation frm elem. content?
157 XMLVarFieldImportContext(
158 // for XMLTextFieldImportContext:
159 SvXMLImport
& rImport
, /// XML Import
160 XMLTextImportHelper
& rHlp
, /// text import helper
161 const sal_Char
* pServiceName
, /// name of SO API service
162 sal_uInt16 nPrfx
, /// namespace prefix
163 const OUString
& rLocalName
, /// element name w/o prefix
164 // config variables for PrepareField behavior:
165 bool bFormula
, /// set Formula property
166 bool bFormulaDefault
, /// use content as default for formula
167 bool bDescription
, /// set sDescription with Hint-property
170 bool bVisible
, /// set IsVisible (display attr)
171 bool bDisplayFormula
, /// set ??? (display attr.)
172 bool bType
, /// set value type with ???-property
173 bool bStyle
, /// set data style (NumberFormat-Prop.)
174 bool bValue
, /// set value with Content/Value-Prop.
175 bool bPresentation
); /// set presentation from elem. content
178 /// process attribute values
179 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
180 const OUString
& sAttrValue
) override
;
182 /// prepare XTextField for insertion into document
183 virtual void PrepareField(
184 const css::uno::Reference
<
185 css::beans::XPropertySet
> & xPropertySet
) override
;
187 // various accessor methods:
188 const OUString
& GetName() { return sName
; }
189 inline bool IsStringValue() { return aValueHelper
.IsStringValue();}
193 /** import variable get fields (<text:variable-get>) */
194 class XMLVariableGetFieldImportContext
: public XMLVarFieldImportContext
199 XMLVariableGetFieldImportContext(
200 SvXMLImport
& rImport
, /// XML Import
201 XMLTextImportHelper
& rHlp
, /// Text import helper
202 sal_uInt16 nPrfx
, /// namespace prefix
203 const OUString
& rLocalName
); /// element name w/o prefix
207 /// prepare XTextField for insertion into document
208 virtual void PrepareField(
209 const css::uno::Reference
<
210 css::beans::XPropertySet
> & xPropertySet
) override
;
214 /** import expression fields (<text:expression>) */
215 class XMLExpressionFieldImportContext
: public XMLVarFieldImportContext
217 const OUString sPropertySubType
;
222 XMLExpressionFieldImportContext(
223 SvXMLImport
& rImport
, /// XML Import
224 XMLTextImportHelper
& rHlp
, /// Text import helper
225 sal_uInt16 nPrfx
, /// namespace prefix
226 const OUString
& sLocalName
); /// element name w/o prefix
229 virtual void PrepareField(
230 const css::uno::Reference
<
231 css::beans::XPropertySet
> & xPropertySet
) override
;
234 /*** import text input fields (<text:text-input>) */
235 class XMLTextInputFieldImportContext
: public XMLVarFieldImportContext
239 XMLTextInputFieldImportContext(
240 SvXMLImport
& rImport
, /// XML Import
241 XMLTextImportHelper
& rHlp
, /// Text import helper
242 sal_uInt16 nPrfx
, /// namespace prefix
243 const OUString
& sLocalName
); /// element name w/o prefix
246 virtual void PrepareField(
247 const css::uno::Reference
<
248 css::beans::XPropertySet
> & xPropertySet
) override
;
253 * uperclass for variable/user-set, var/user-input, and sequence fields
254 * inds field master of appropriate type and attaches field to it.
256 class XMLSetVarFieldImportContext
: public XMLVarFieldImportContext
258 const VarType eFieldType
;
263 XMLSetVarFieldImportContext(
264 // for XMLTextFieldImportContext:
265 SvXMLImport
& rImport
, /// see XMLTextFieldImportContext
266 XMLTextImportHelper
& rHlp
, /// see XMLTextFieldImportContext
267 const sal_Char
* pServiceName
, /// see XMLTextFieldImportContext
268 sal_uInt16 nPrfx
, /// see XMLTextFieldImportContext
269 const OUString
& rLocalName
, /// see XMLTextFieldImportContext
270 // for finding appropriate field master (see EndElement())
271 VarType eVarType
, /// variable type
273 bool bFormula
, /// see XMLTextFieldImportContext
274 bool bFormulaDefault
, /// see XMLTextFieldImportContext
275 bool bDescription
, /// see XMLTextFieldImportContext
276 bool bHelp
, /// see XMLTextFieldImportContext
277 bool bHint
, /// see XMLTextFieldImportContext
278 bool bVisible
, /// see XMLTextFieldImportContext
279 bool bDisplayFormula
, /// see XMLTextFieldImportContext
280 bool bType
, /// see XMLTextFieldImportContext
281 bool bStyle
, /// see XMLTextFieldImportContext
282 bool bValue
, /// see XMLTextFieldImportContext
283 bool bPresentation
); /// see XMLTextFieldImportContext
287 /// create XTextField, attach master and insert into document;
288 /// also calls PrepareTextField
289 virtual void EndElement() override
;
291 /// find appropriate field master
292 bool FindFieldMaster(
294 css::beans::XPropertySet
> & xMaster
);
298 /** import variable set fields (<text:variable-set>) */
299 class XMLVariableSetFieldImportContext
: public XMLSetVarFieldImportContext
301 const OUString sPropertySubType
;
306 XMLVariableSetFieldImportContext(
307 SvXMLImport
& rImport
, /// XML Import
308 XMLTextImportHelper
& rHlp
, /// Text import helper
309 sal_uInt16 nPrfx
, /// namespace prefix
310 const OUString
& rLocalName
); /// element name w/o prefix
313 /// prepare XTextField for insertion into document
314 virtual void PrepareField(
315 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
) override
;
319 /** variable input fields (<text:variable-input>) */
320 class XMLVariableInputFieldImportContext
: public XMLSetVarFieldImportContext
322 const OUString sPropertySubType
;
323 const OUString sPropertyIsInput
;
328 XMLVariableInputFieldImportContext(
329 SvXMLImport
& rImport
, /// XML Import
330 XMLTextImportHelper
& rHlp
, /// Text import helper
331 sal_uInt16 nPrfx
, /// namespace prefix
332 const OUString
& rLocalName
); /// element name w/o prefix
336 /// prepare XTextField for insertion into document
337 virtual void PrepareField(
338 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
) override
;
342 /** user fields (<text:user-field-get>) */
343 class XMLUserFieldImportContext
: public XMLSetVarFieldImportContext
349 XMLUserFieldImportContext(
350 SvXMLImport
& rImport
, /// XML Import
351 XMLTextImportHelper
& rHlp
, /// Text import helper
352 sal_uInt16 nPrfx
, /// namespace prefix
353 const OUString
& rLocalName
); /// element name w/o prefix
356 /** user input fields (<text:user-field-input>) */
357 class XMLUserFieldInputImportContext
: public XMLVarFieldImportContext
363 XMLUserFieldInputImportContext(
364 SvXMLImport
& rImport
, /// XML Import
365 XMLTextImportHelper
& rHlp
, /// Text import helper
366 sal_uInt16 nPrfx
, /// namespace prefix
367 const OUString
& rLocalName
); /// element name w/o prefix
369 virtual void PrepareField(
370 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
) override
;
374 /** sequence fields (<text:sequence>) */
375 class XMLSequenceFieldImportContext
: public XMLSetVarFieldImportContext
377 const OUString sPropertyNumberFormat
;
378 const OUString sPropertySequenceValue
;
380 OUString sNumFormatSync
;
388 XMLSequenceFieldImportContext(
389 SvXMLImport
& rImport
, /// XML Import
390 XMLTextImportHelper
& rHlp
, /// Text import helper
391 sal_uInt16 nPrfx
, /// namespace prefix
392 const OUString
& rLocalName
); /// element name w/o prefix
396 /// process attribute values
397 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
398 const OUString
& sAttrValue
) override
;
400 /// prepare XTextField for insertion into document
401 virtual void PrepareField(
402 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
) override
;
407 * variable declaration container for all variable fields
408 * (variable-decls, user-field-decls, sequence-decls)
410 class XMLVariableDeclsImportContext
: public SvXMLImportContext
412 enum VarType eVarDeclsContextType
;
413 XMLTextImportHelper
& rImportHelper
;
418 XMLVariableDeclsImportContext(
419 SvXMLImport
& rImport
, /// XML Import
420 XMLTextImportHelper
& rHlp
, /// text import helper
421 sal_uInt16 nPrfx
, /// namespace prefix
422 const OUString
& rLocalName
, /// element name w/o prefix
423 enum VarType eVarType
); /// variable type
425 virtual SvXMLImportContext
*CreateChildContext(
427 const OUString
& rLocalName
,
428 const css::uno::Reference
<css::xml::sax::XAttributeList
> & xAttrList
) override
;
432 * variable field declarations
433 * (variable-decl, user-field-decl, sequence-decl)
435 class XMLVariableDeclImportContext
: public SvXMLImportContext
437 const OUString sPropertySubType
;
438 const OUString sPropertyNumberingLevel
;
439 const OUString sPropertyNumberingSeparator
;
440 const OUString sPropertyIsExpression
;
443 XMLValueImportHelper aValueHelper
;
445 sal_Unicode cSeparationChar
;
450 XMLVariableDeclImportContext(
451 SvXMLImport
& rImport
, /// XML Import
452 XMLTextImportHelper
& rHlp
, /// text import helper
453 sal_uInt16 nPrfx
, /// namespace prefix
454 const OUString
& rLocalName
, /// element name w/o prefix
455 const css::uno::Reference
< css::xml::sax::XAttributeList
> & xAttrList
,/// list of element attributes
456 enum VarType eVarType
); /// variable type
458 /// get field master for name and rename if appropriate
459 static bool FindFieldMaster(css::uno::Reference
<css::beans::XPropertySet
> & xMaster
,
460 SvXMLImport
& rImport
,
461 XMLTextImportHelper
& rHelper
,
462 const OUString
& sVarName
,
463 enum VarType eVarType
);
467 /** import table formula fields (deprecated; for Writer 2.0 compatibility) */
468 class XMLTableFormulaImportContext
: public XMLTextFieldImportContext
470 const OUString sPropertyIsShowFormula
;
471 const OUString sPropertyCurrentPresentation
;
473 XMLValueImportHelper aValueHelper
;
480 XMLTableFormulaImportContext(
481 SvXMLImport
& rImport
, /// XML Import
482 XMLTextImportHelper
& rHlp
, /// text import helper
483 sal_uInt16 nPrfx
, /// namespace prefix
484 const OUString
& rLocalName
); /// element name w/o prefix
485 virtual ~XMLTableFormulaImportContext() override
;
489 /// process attribute values
490 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
491 const OUString
& sAttrValue
) override
;
493 /// prepare XTextField for insertion into document
494 virtual void PrepareField(
495 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
) override
;
499 /** import database display fields (<text:database-display>) */
500 class XMLDatabaseDisplayImportContext
: public XMLDatabaseFieldImportContext
502 const OUString sPropertyColumnName
;
503 const OUString sPropertyDatabaseFormat
;
504 const OUString sPropertyCurrentPresentation
;
505 const OUString sPropertyIsVisible
;
507 XMLValueImportHelper aValueHelper
;
509 OUString sColumnName
;
518 XMLDatabaseDisplayImportContext(
519 SvXMLImport
& rImport
, /// XML Import
520 XMLTextImportHelper
& rHlp
, /// text import helper
521 sal_uInt16 nPrfx
, /// namespace prefix
522 const OUString
& rLocalName
); /// element name w/o prefix
526 /// process attribute values
527 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
528 const OUString
& sAttrValue
) override
;
530 /// create, prepare and insert database field master and database field
531 virtual void EndElement() override
;
536 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */