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 XMLTextImportHelper
& rHelper
;
39 OUString sValue
; /// string value (only valid if bStringValueOK)
40 double fValue
; /// double value (only valid if bFloatValueOK)
41 sal_Int32 nFormatKey
; /// format key (only valid of bFormatOK)
42 OUString sFormula
; /// formula string
43 OUString sDefault
; /// default (see bStringDefault/bFormulaDef.)
44 bool bIsDefaultLanguage
;/// format (of nFormatKey) has system language?
46 bool bStringType
; /// is this a string (or a float) type?
47 bool bFormatOK
; /// have we read a style:data-style-name attr.?
48 bool bStringValueOK
; /// have we read a string-value attr.?
49 bool bFormulaOK
; /// have we read the formula attribute?
51 const bool bSetType
; /// should PrepareField set the SetExp subtype?
52 const bool bSetValue
; /// should PrepareField set content/value?
53 const bool bSetStyle
; /// should PrepareField set NumberFormat?
54 const bool bSetFormula
; /// should PrepareField set Formula?
58 SvXMLImport
& rImprt
, /// XML Import
59 XMLTextImportHelper
& rHlp
, /// text import helper
60 bool bType
, /// process type (PrepareField)
61 bool bStyle
, /// process data style (P.F.)
62 bool bValue
, /// process value (Prep.Field)
63 bool bFormula
); /// process formula (Prep.F.)
65 /// process attribute values
66 void ProcessAttribute( sal_uInt16 nAttrToken
,
67 const OUString
& sAttrValue
);
69 /// prepare XTextField for insertion into document
71 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
);
73 /// is value a string (rather than double)?
74 bool IsStringValue() { return bStringType
; }
76 /// has format been read?
77 bool IsFormatOK() { return bFormatOK
; }
79 void SetDefault(const OUString
& sStr
) { sDefault
= sStr
; }
84 * abstract parent class for all variable related fields
85 * - variable-set/get/decl (not -decls),
86 * - user-field-get/decl (not -decls),
87 * - sequence/-decl (not -decls),
91 * Processes the following attributes:
95 * - value, value-type, data-style-name (via XMLValueImportHelper)
98 * Each attribute has a corresponding member, a bool variable to indicate
99 * whether it was set or not, and a bool variable whether it should be set
100 * using the standard property name.
102 * bValid is set true, when name is found!
103 * (Most variable related fields are valid, if a name is
104 * found. However, some are always valid. In this case, setting bValid
107 class XMLVarFieldImportContext
: public XMLTextFieldImportContext
110 OUString sName
; /// name attribute
111 OUString sFormula
; /// formula attribute
112 OUString sDescription
; /// description
113 OUString sHelp
; /// help text
114 OUString sHint
; /// hint
115 XMLValueImportHelper aValueHelper
; /// value, value-type, and style
116 bool bDisplayFormula
; /// display formula?(rather than value)
117 bool bDisplayNone
; /// hide field?
119 bool bFormulaOK
; /// sFormula was set
120 bool bDescriptionOK
; /// sDescription was set
121 bool bHelpOK
; /// sHelp was set
122 bool bHintOK
; /// sHint was set
123 bool bDisplayOK
; /// sDisplayFormula/-None were set
125 bool const bSetFormula
; /// set Formula property
126 bool const bSetFormulaDefault
; /// use content as default for formula
127 bool const bSetDescription
; /// set sDescription with Hint-property
130 bool const bSetVisible
; /// set IsVisible
131 bool bSetDisplayFormula
; /// set DisplayFormula (sub type???)
132 bool const bSetPresentation
; /// set presentation frm elem. content?
137 XMLVarFieldImportContext(
138 // for XMLTextFieldImportContext:
139 SvXMLImport
& rImport
, /// XML Import
140 XMLTextImportHelper
& rHlp
, /// text import helper
141 const sal_Char
* pServiceName
, /// name of SO API service
142 sal_uInt16 nPrfx
, /// namespace prefix
143 const OUString
& rLocalName
, /// element name w/o prefix
144 // config variables for PrepareField behavior:
145 bool bFormula
, /// set Formula property
146 bool bFormulaDefault
, /// use content as default for formula
147 bool bDescription
, /// set sDescription with Hint-property
150 bool bVisible
, /// set IsVisible (display attr)
151 bool bDisplayFormula
, /// set ??? (display attr.)
152 bool bType
, /// set value type with ???-property
153 bool bStyle
, /// set data style (NumberFormat-Prop.)
154 bool bValue
, /// set value with Content/Value-Prop.
155 bool bPresentation
); /// set presentation from elem. content
158 /// process attribute values
159 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
160 const OUString
& sAttrValue
) override
;
162 /// prepare XTextField for insertion into document
163 virtual void PrepareField(
164 const css::uno::Reference
<
165 css::beans::XPropertySet
> & xPropertySet
) override
;
167 // various accessor methods:
168 const OUString
& GetName() { return sName
; }
169 bool IsStringValue() { return aValueHelper
.IsStringValue();}
173 /** import variable get fields (<text:variable-get>) */
174 class XMLVariableGetFieldImportContext
: public XMLVarFieldImportContext
179 XMLVariableGetFieldImportContext(
180 SvXMLImport
& rImport
, /// XML Import
181 XMLTextImportHelper
& rHlp
, /// Text import helper
182 sal_uInt16 nPrfx
, /// namespace prefix
183 const OUString
& rLocalName
); /// element name w/o prefix
187 /// prepare XTextField for insertion into document
188 virtual void PrepareField(
189 const css::uno::Reference
<
190 css::beans::XPropertySet
> & xPropertySet
) override
;
194 /** import expression fields (<text:expression>) */
195 class XMLExpressionFieldImportContext
: public XMLVarFieldImportContext
199 XMLExpressionFieldImportContext(
200 SvXMLImport
& rImport
, /// XML Import
201 XMLTextImportHelper
& rHlp
, /// Text import helper
202 sal_uInt16 nPrfx
, /// namespace prefix
203 const OUString
& sLocalName
); /// element name w/o prefix
206 virtual void PrepareField(
207 const css::uno::Reference
<
208 css::beans::XPropertySet
> & xPropertySet
) override
;
211 /*** import text input fields (<text:text-input>) */
212 class XMLTextInputFieldImportContext
: public XMLVarFieldImportContext
216 XMLTextInputFieldImportContext(
217 SvXMLImport
& rImport
, /// XML Import
218 XMLTextImportHelper
& rHlp
, /// Text import helper
219 sal_uInt16 nPrfx
, /// namespace prefix
220 const OUString
& sLocalName
); /// element name w/o prefix
223 virtual void PrepareField(
224 const css::uno::Reference
<
225 css::beans::XPropertySet
> & xPropertySet
) override
;
230 * upperclass for variable/user-set, var/user-input, and sequence fields
231 * inds field master of appropriate type and attaches field to it.
233 class XMLSetVarFieldImportContext
: public XMLVarFieldImportContext
235 const VarType eFieldType
;
240 XMLSetVarFieldImportContext(
241 // for XMLTextFieldImportContext:
242 SvXMLImport
& rImport
, /// see XMLTextFieldImportContext
243 XMLTextImportHelper
& rHlp
, /// see XMLTextFieldImportContext
244 const sal_Char
* pServiceName
, /// see XMLTextFieldImportContext
245 sal_uInt16 nPrfx
, /// see XMLTextFieldImportContext
246 const OUString
& rLocalName
, /// see XMLTextFieldImportContext
247 // for finding appropriate field master (see EndElement())
248 VarType eVarType
, /// variable type
250 bool bFormula
, /// see XMLTextFieldImportContext
251 bool bFormulaDefault
, /// see XMLTextFieldImportContext
252 bool bDescription
, /// see XMLTextFieldImportContext
253 bool bHelp
, /// see XMLTextFieldImportContext
254 bool bHint
, /// see XMLTextFieldImportContext
255 bool bVisible
, /// see XMLTextFieldImportContext
256 bool bDisplayFormula
, /// see XMLTextFieldImportContext
257 bool bType
, /// see XMLTextFieldImportContext
258 bool bStyle
, /// see XMLTextFieldImportContext
259 bool bValue
, /// see XMLTextFieldImportContext
260 bool bPresentation
); /// see XMLTextFieldImportContext
264 /// create XTextField, attach master and insert into document;
265 /// also calls PrepareTextField
266 virtual void EndElement() override
;
268 /// find appropriate field master
269 bool FindFieldMaster(
271 css::beans::XPropertySet
> & xMaster
);
275 /** import variable set fields (<text:variable-set>) */
276 class XMLVariableSetFieldImportContext
: public XMLSetVarFieldImportContext
280 XMLVariableSetFieldImportContext(
281 SvXMLImport
& rImport
, /// XML Import
282 XMLTextImportHelper
& rHlp
, /// Text import helper
283 sal_uInt16 nPrfx
, /// namespace prefix
284 const OUString
& rLocalName
); /// element name w/o prefix
287 /// prepare XTextField for insertion into document
288 virtual void PrepareField(
289 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
) override
;
293 /** variable input fields (<text:variable-input>) */
294 class XMLVariableInputFieldImportContext
: public XMLSetVarFieldImportContext
299 XMLVariableInputFieldImportContext(
300 SvXMLImport
& rImport
, /// XML Import
301 XMLTextImportHelper
& rHlp
, /// Text import helper
302 sal_uInt16 nPrfx
, /// namespace prefix
303 const OUString
& rLocalName
); /// element name w/o prefix
307 /// prepare XTextField for insertion into document
308 virtual void PrepareField(
309 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
) override
;
313 /** user fields (<text:user-field-get>) */
314 class XMLUserFieldImportContext
: public XMLSetVarFieldImportContext
320 XMLUserFieldImportContext(
321 SvXMLImport
& rImport
, /// XML Import
322 XMLTextImportHelper
& rHlp
, /// Text import helper
323 sal_uInt16 nPrfx
, /// namespace prefix
324 const OUString
& rLocalName
); /// element name w/o prefix
327 /** user input fields (<text:user-field-input>) */
328 class XMLUserFieldInputImportContext
: public XMLVarFieldImportContext
334 XMLUserFieldInputImportContext(
335 SvXMLImport
& rImport
, /// XML Import
336 XMLTextImportHelper
& rHlp
, /// Text import helper
337 sal_uInt16 nPrfx
, /// namespace prefix
338 const OUString
& rLocalName
); /// element name w/o prefix
340 virtual void PrepareField(
341 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
) override
;
345 /** sequence fields (<text:sequence>) */
346 class XMLSequenceFieldImportContext
: public XMLSetVarFieldImportContext
349 OUString sNumFormatSync
;
357 XMLSequenceFieldImportContext(
358 SvXMLImport
& rImport
, /// XML Import
359 XMLTextImportHelper
& rHlp
, /// Text import helper
360 sal_uInt16 nPrfx
, /// namespace prefix
361 const OUString
& rLocalName
); /// element name w/o prefix
365 /// process attribute values
366 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
367 const OUString
& sAttrValue
) override
;
369 /// prepare XTextField for insertion into document
370 virtual void PrepareField(
371 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
) override
;
376 * variable declaration container for all variable fields
377 * (variable-decls, user-field-decls, sequence-decls)
379 class XMLVariableDeclsImportContext
: public SvXMLImportContext
381 enum VarType
const eVarDeclsContextType
;
382 XMLTextImportHelper
& rImportHelper
;
387 XMLVariableDeclsImportContext(
388 SvXMLImport
& rImport
, /// XML Import
389 XMLTextImportHelper
& rHlp
, /// text import helper
390 sal_uInt16 nPrfx
, /// namespace prefix
391 const OUString
& rLocalName
, /// element name w/o prefix
392 enum VarType eVarType
); /// variable type
394 virtual SvXMLImportContextRef
CreateChildContext(
396 const OUString
& rLocalName
,
397 const css::uno::Reference
<css::xml::sax::XAttributeList
> & xAttrList
) override
;
401 * variable field declarations
402 * (variable-decl, user-field-decl, sequence-decl)
404 class XMLVariableDeclImportContext
: public SvXMLImportContext
406 XMLValueImportHelper aValueHelper
;
407 sal_Unicode cSeparationChar
;
412 XMLVariableDeclImportContext(
413 SvXMLImport
& rImport
, /// XML Import
414 XMLTextImportHelper
& rHlp
, /// text import helper
415 sal_uInt16 nPrfx
, /// namespace prefix
416 const OUString
& rLocalName
, /// element name w/o prefix
417 const css::uno::Reference
< css::xml::sax::XAttributeList
> & xAttrList
,/// list of element attributes
418 enum VarType eVarType
); /// variable type
420 /// get field master for name and rename if appropriate
421 static bool FindFieldMaster(css::uno::Reference
<css::beans::XPropertySet
> & xMaster
,
422 SvXMLImport
& rImport
,
423 XMLTextImportHelper
& rHelper
,
424 const OUString
& sVarName
,
425 enum VarType eVarType
);
429 /** import table formula fields (deprecated; for Writer 2.0 compatibility) */
430 class XMLTableFormulaImportContext
: public XMLTextFieldImportContext
432 XMLValueImportHelper aValueHelper
;
438 XMLTableFormulaImportContext(
439 SvXMLImport
& rImport
, /// XML Import
440 XMLTextImportHelper
& rHlp
, /// text import helper
441 sal_uInt16 nPrfx
, /// namespace prefix
442 const OUString
& rLocalName
); /// element name w/o prefix
446 /// process attribute values
447 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
448 const OUString
& sAttrValue
) override
;
450 /// prepare XTextField for insertion into document
451 virtual void PrepareField(
452 const css::uno::Reference
<css::beans::XPropertySet
> & xPropertySet
) override
;
456 /** import database display fields (<text:database-display>) */
457 class XMLDatabaseDisplayImportContext
: public XMLDatabaseFieldImportContext
459 XMLValueImportHelper aValueHelper
;
461 OUString sColumnName
;
470 XMLDatabaseDisplayImportContext(
471 SvXMLImport
& rImport
, /// XML Import
472 XMLTextImportHelper
& rHlp
, /// text import helper
473 sal_uInt16 nPrfx
, /// namespace prefix
474 const OUString
& rLocalName
); /// element name w/o prefix
478 /// process attribute values
479 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
480 const OUString
& sAttrValue
) override
;
482 /// create, prepare and insert database field master and database field
483 virtual void EndElement() override
;
488 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */