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>
34 /// variable type (for XMLSetVarFieldImportContext)
44 /** helper class: parses value-type and associated value attributes */
45 class XMLValueImportHelper
48 const OUString sPropertyContent
;
49 const OUString sPropertyValue
;
50 const OUString sPropertyNumberFormat
;
51 const OUString sPropertyIsFixedLanguage
;
54 XMLTextImportHelper
& rHelper
;
56 OUString sValue
; /// string value (only valid if bStringValueOK)
57 double fValue
; /// double value (only valid if bFloatValueOK)
58 sal_Int32 nFormatKey
; /// format key (only valid of bFormatOK)
59 OUString sFormula
; /// formula string
60 OUString sDefault
; /// default (see bStringDefault/bFormulaDef.)
61 bool bIsDefaultLanguage
;/// format (of nFormatKey) has system language?
63 bool bStringType
; /// is this a string (or a float) type?
64 bool bFormatOK
; /// have we read a style:data-style-name attr.?
65 bool bTypeOK
; /// have we read a value-type attribute?
66 bool bStringValueOK
; /// have we read a string-value attr.?
67 bool bFloatValueOK
; /// have we read any of the float attr.s?
68 bool bFormulaOK
; /// have we read the formula attribute?
70 const bool bSetType
; /// should PrepareField set the SetExp subtype?
71 const bool bSetValue
; /// should PrepareField set content/value?
72 const bool bSetStyle
; /// should PrepareField set NumberFormat?
73 const bool bSetFormula
; /// should PrepareField set Formula?
75 const bool bStringDefault
; /// default: string-value = content
76 const bool bFormulaDefault
; /// default: formula = content
80 SvXMLImport
& rImprt
, /// XML Import
81 XMLTextImportHelper
& rHlp
, /// text import helper
82 bool bType
, /// process type (PrepareField)
83 bool bStyle
, /// process data style (P.F.)
84 bool bValue
, /// process value (Prep.Field)
85 bool bFormula
); /// process formula (Prep.F.)
87 virtual ~XMLValueImportHelper();
89 /// process attribute values
90 void ProcessAttribute( sal_uInt16 nAttrToken
,
91 const OUString
& sAttrValue
);
93 /// prepare XTextField for insertion into document
95 const ::com::sun::star::uno::Reference
<
96 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
98 /// is value a string (rather than double)?
99 inline bool IsStringValue() { return bStringType
; }
101 /// has format been read?
102 inline bool IsFormatOK() { return bFormatOK
; }
104 inline void SetDefault(const OUString
& sStr
) { sDefault
= sStr
; }
110 * abstract parent class for all variable related fields
111 * - variable-set/get/decl (not -decls),
112 * - user-field-get/decl (not -decls),
113 * - sequence/-decl (not -decls),
117 * Processes the following attributes:
121 * - value, value-type, data-style-name (via XMLValueImportHelper)
124 * Each attribute has a corresponding member, a bool variable to indicate
125 * whether it was set or not, and a bool variable whether it should be set
126 * using the standard property name.
128 * bValid is set true, when name is found!
129 * (Most variable related fields are valid, if a name is
130 * found. However, some are always valid. In this case, setting bValid
133 class XMLVarFieldImportContext
: public XMLTextFieldImportContext
136 const OUString sPropertyContent
;
137 const OUString sPropertyHint
;
138 const OUString sPropertyHelp
;
139 const OUString sPropertyTooltip
;
140 const OUString sPropertyIsVisible
;
141 const OUString sPropertyIsDisplayFormula
;
142 const OUString sPropertyCurrentPresentation
;
145 OUString sName
; /// name attribute
146 OUString sFormula
; /// formula attribute
147 OUString sDescription
; /// description
148 OUString sHelp
; /// help text
149 OUString sHint
; /// hint
150 XMLValueImportHelper aValueHelper
; /// value, value-type, and style
151 bool bDisplayFormula
; /// display formula?(rather than value)
152 bool bDisplayNone
; /// hide field?
154 bool bNameOK
; /// sName was set
155 bool bFormulaOK
; /// sFormula was set
156 bool bDescriptionOK
; /// sDescription was set
157 bool bHelpOK
; /// sHelp was set
158 bool bHintOK
; /// sHint was set
159 bool bDisplayOK
; /// sDisplayFormula/-None were set
161 bool bSetFormula
; /// set Formula property
162 bool bSetFormulaDefault
; /// use content as default for formula
163 bool bSetDescription
; /// set sDescription with Hint-property
166 bool bSetVisible
; /// set IsVisible
167 bool bSetDisplayFormula
; /// set DisplayFormula (sub type???)
168 bool bSetPresentation
; /// set presentation frm elem. content?
174 XMLVarFieldImportContext(
175 // for XMLTextFieldImportContext:
176 SvXMLImport
& rImport
, /// XML Import
177 XMLTextImportHelper
& rHlp
, /// text import helper
178 const sal_Char
* pServiceName
, /// name of SO API service
179 sal_uInt16 nPrfx
, /// namespace prefix
180 const OUString
& rLocalName
, /// element name w/o prefix
181 // config variables for PrepareField behavior:
182 bool bFormula
, /// set Formula property
183 bool bFormulaDefault
, /// use content as default for formula
184 bool bDescription
, /// set sDescription with Hint-property
187 bool bVisible
, /// set IsVisible (display attr)
188 bool bDisplayFormula
, /// set ??? (display attr.)
189 bool bType
, /// set value type with ???-property
190 bool bStyle
, /// set data style (NumberFormat-Prop.)
191 bool bValue
, /// set value with Content/Value-Prop.
192 bool bPresentation
); /// set presentation from elem. content
195 /// process attribute values
196 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
197 const OUString
& sAttrValue
) SAL_OVERRIDE
;
199 /// prepare XTextField for insertion into document
200 virtual void PrepareField(
201 const ::com::sun::star::uno::Reference
<
202 ::com::sun::star::beans::XPropertySet
> & xPropertySet
) SAL_OVERRIDE
;
204 // various accessor methods:
205 inline OUString
GetName() { return sName
; }
206 inline bool IsStringValue() { return aValueHelper
.IsStringValue();}
207 inline bool IsNameOK() { return bNameOK
; }
208 inline bool IsFormulaOK() { return bFormulaOK
; }
209 inline bool IsDescriptionOK() { return bDescriptionOK
; }
210 inline bool IsDisplayOK() { return bDisplayOK
; }
215 /** import variable get fields (<text:variable-get>) */
216 class XMLVariableGetFieldImportContext
: public XMLVarFieldImportContext
222 XMLVariableGetFieldImportContext(
223 SvXMLImport
& rImport
, /// XML Import
224 XMLTextImportHelper
& rHlp
, /// Text import helper
225 sal_uInt16 nPrfx
, /// namespace prefix
226 const OUString
& rLocalName
); /// element name w/o prefix
230 /// prepare XTextField for insertion into document
231 virtual void PrepareField(
232 const ::com::sun::star::uno::Reference
<
233 ::com::sun::star::beans::XPropertySet
> & xPropertySet
) SAL_OVERRIDE
;
238 /** import expression fields (<text:expression>) */
239 class XMLExpressionFieldImportContext
: public XMLVarFieldImportContext
241 const OUString sPropertySubType
;
247 XMLExpressionFieldImportContext(
248 SvXMLImport
& rImport
, /// XML Import
249 XMLTextImportHelper
& rHlp
, /// Text import helper
250 sal_uInt16 nPrfx
, /// namespace prefix
251 const OUString
& sLocalName
); /// element name w/o prefix
254 virtual void PrepareField(
255 const ::com::sun::star::uno::Reference
<
256 ::com::sun::star::beans::XPropertySet
> & xPropertySet
) SAL_OVERRIDE
;
259 /*** import text input fields (<text:text-input>) */
260 class XMLTextInputFieldImportContext
: public XMLVarFieldImportContext
262 const OUString sPropertyContent
;
268 XMLTextInputFieldImportContext(
269 SvXMLImport
& rImport
, /// XML Import
270 XMLTextImportHelper
& rHlp
, /// Text import helper
271 sal_uInt16 nPrfx
, /// namespace prefix
272 const OUString
& sLocalName
); /// element name w/o prefix
275 virtual void PrepareField(
276 const ::com::sun::star::uno::Reference
<
277 ::com::sun::star::beans::XPropertySet
> & xPropertySet
) SAL_OVERRIDE
;
286 * uperclass for variable/user-set, var/user-input, and sequence fields
287 * inds field master of appropriate type and attaches field to it.
289 class XMLSetVarFieldImportContext
: public XMLVarFieldImportContext
291 const VarType eFieldType
;
297 XMLSetVarFieldImportContext(
298 // for XMLTextFieldImportContext:
299 SvXMLImport
& rImport
, /// see XMLTextFieldImportContext
300 XMLTextImportHelper
& rHlp
, /// see XMLTextFieldImportContext
301 const sal_Char
* pServiceName
, /// see XMLTextFieldImportContext
302 sal_uInt16 nPrfx
, /// see XMLTextFieldImportContext
303 const OUString
& rLocalName
, /// see XMLTextFieldImportContext
304 // for finding appropriate field master (see EndElement())
305 VarType eVarType
, /// variable type
307 bool bFormula
, /// see XMLTextFieldImportContext
308 bool bFormulaDefault
, /// see XMLTextFieldImportContext
309 bool bDescription
, /// see XMLTextFieldImportContext
310 bool bHelp
, /// see XMLTextFieldImportContext
311 bool bHint
, /// see XMLTextFieldImportContext
312 bool bVisible
, /// see XMLTextFieldImportContext
313 bool bDisplayFormula
, /// see XMLTextFieldImportContext
314 bool bType
, /// see XMLTextFieldImportContext
315 bool bStyle
, /// see XMLTextFieldImportContext
316 bool bValue
, /// see XMLTextFieldImportContext
317 bool bPresentation
); /// see XMLTextFieldImportContext
321 /// create XTextField, attach master and insert into document;
322 /// also calls PrepareTextField
323 virtual void EndElement() SAL_OVERRIDE
;
325 /// find appropriate field master
326 bool FindFieldMaster(
327 ::com::sun::star::uno::Reference
<
328 ::com::sun::star::beans::XPropertySet
> & xMaster
);
333 /** import variable set fields (<text:variable-set>) */
334 class XMLVariableSetFieldImportContext
: public XMLSetVarFieldImportContext
336 const OUString sPropertySubType
;
342 XMLVariableSetFieldImportContext(
343 SvXMLImport
& rImport
, /// XML Import
344 XMLTextImportHelper
& rHlp
, /// Text import helper
345 sal_uInt16 nPrfx
, /// namespace prefix
346 const OUString
& rLocalName
); /// element name w/o prefix
349 /// prepare XTextField for insertion into document
350 virtual void PrepareField(
351 const ::com::sun::star::uno::Reference
<
352 ::com::sun::star::beans::XPropertySet
> & xPropertySet
) SAL_OVERRIDE
;
357 /** variable input fields (<text:variable-input>) */
358 class XMLVariableInputFieldImportContext
: public XMLSetVarFieldImportContext
360 const OUString sPropertySubType
;
361 const OUString sPropertyIsInput
;
367 XMLVariableInputFieldImportContext(
368 SvXMLImport
& rImport
, /// XML Import
369 XMLTextImportHelper
& rHlp
, /// Text import helper
370 sal_uInt16 nPrfx
, /// namespace prefix
371 const OUString
& rLocalName
); /// element name w/o prefix
375 /// prepare XTextField for insertion into document
376 virtual void PrepareField(
377 const ::com::sun::star::uno::Reference
<
378 ::com::sun::star::beans::XPropertySet
> & xPropertySet
) SAL_OVERRIDE
;
383 /** user fields (<text:user-field-get>) */
384 class XMLUserFieldImportContext
: public XMLSetVarFieldImportContext
391 XMLUserFieldImportContext(
392 SvXMLImport
& rImport
, /// XML Import
393 XMLTextImportHelper
& rHlp
, /// Text import helper
394 sal_uInt16 nPrfx
, /// namespace prefix
395 const OUString
& rLocalName
); /// element name w/o prefix
398 /** user input fields (<text:user-field-input>) */
399 class XMLUserFieldInputImportContext
: public XMLVarFieldImportContext
406 XMLUserFieldInputImportContext(
407 SvXMLImport
& rImport
, /// XML Import
408 XMLTextImportHelper
& rHlp
, /// Text import helper
409 sal_uInt16 nPrfx
, /// namespace prefix
410 const OUString
& rLocalName
); /// element name w/o prefix
412 virtual void PrepareField(
413 const ::com::sun::star::uno::Reference
<
414 ::com::sun::star::beans::XPropertySet
> & xPropertySet
) SAL_OVERRIDE
;
419 /** sequence fields (<text:sequence>) */
420 class XMLSequenceFieldImportContext
: public XMLSetVarFieldImportContext
422 const OUString sPropertyNumberFormat
;
423 const OUString sPropertySequenceValue
;
425 OUString sNumFormatSync
;
434 XMLSequenceFieldImportContext(
435 SvXMLImport
& rImport
, /// XML Import
436 XMLTextImportHelper
& rHlp
, /// Text import helper
437 sal_uInt16 nPrfx
, /// namespace prefix
438 const OUString
& rLocalName
); /// element name w/o prefix
442 /// process attribute values
443 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
444 const OUString
& sAttrValue
) SAL_OVERRIDE
;
446 /// prepare XTextField for insertion into document
447 virtual void PrepareField(
448 const ::com::sun::star::uno::Reference
<
449 ::com::sun::star::beans::XPropertySet
> & xPropertySet
) SAL_OVERRIDE
;
458 * variable declaration container for all variable fields
459 * (variable-decls, user-field-decls, sequence-decls)
461 class XMLVariableDeclsImportContext
: public SvXMLImportContext
463 enum VarType eVarDeclsContextType
;
464 XMLTextImportHelper
& rImportHelper
;
470 XMLVariableDeclsImportContext(
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
475 enum VarType eVarType
); /// variable type
477 virtual SvXMLImportContext
*CreateChildContext(
479 const OUString
& rLocalName
,
480 const ::com::sun::star::uno::Reference
<
481 ::com::sun::star::xml::sax::XAttributeList
> & xAttrList
) SAL_OVERRIDE
;
485 * variable field declarations
486 * (variable-decl, user-field-decl, sequence-decl)
488 class XMLVariableDeclImportContext
: public SvXMLImportContext
490 const OUString sPropertySubType
;
491 const OUString sPropertyNumberingLevel
;
492 const OUString sPropertyNumberingSeparator
;
493 const OUString sPropertyIsExpression
;
496 XMLValueImportHelper aValueHelper
;
498 sal_Unicode cSeparationChar
;
504 XMLVariableDeclImportContext(
505 SvXMLImport
& rImport
, /// XML Import
506 XMLTextImportHelper
& rHlp
, /// text import helper
507 sal_uInt16 nPrfx
, /// namespace prefix
508 const OUString
& rLocalName
, /// element name w/o prefix
509 const ::com::sun::star::uno::Reference
< /// list of element attributes
510 ::com::sun::star::xml::sax::XAttributeList
> & xAttrList
,
511 enum VarType eVarType
); /// variable type
513 /// get field master for name and rename if appropriate
514 static bool FindFieldMaster(::com::sun::star::uno::Reference
<
515 ::com::sun::star::beans::XPropertySet
> & xMaster
,
516 SvXMLImport
& rImport
,
517 XMLTextImportHelper
& rHelper
,
518 const OUString
& sVarName
,
519 enum VarType eVarType
);
524 /** import table formula fields (deprecated; for Writer 2.0 compatibility) */
525 class XMLTableFormulaImportContext
: public XMLTextFieldImportContext
527 const OUString sPropertyIsShowFormula
;
528 const OUString sPropertyCurrentPresentation
;
530 XMLValueImportHelper aValueHelper
;
538 XMLTableFormulaImportContext(
539 SvXMLImport
& rImport
, /// XML Import
540 XMLTextImportHelper
& rHlp
, /// text import helper
541 sal_uInt16 nPrfx
, /// namespace prefix
542 const OUString
& rLocalName
); /// element name w/o prefix
543 virtual ~XMLTableFormulaImportContext();
547 /// process attribute values
548 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
549 const OUString
& sAttrValue
) SAL_OVERRIDE
;
551 /// prepare XTextField for insertion into document
552 virtual void PrepareField(
553 const ::com::sun::star::uno::Reference
<
554 ::com::sun::star::beans::XPropertySet
> & xPropertySet
) SAL_OVERRIDE
;
559 /** import database display fields (<text:database-display>) */
560 class XMLDatabaseDisplayImportContext
: public XMLDatabaseFieldImportContext
562 const OUString sPropertyColumnName
;
563 const OUString sPropertyDatabaseFormat
;
564 const OUString sPropertyCurrentPresentation
;
565 const OUString sPropertyIsVisible
;
567 XMLValueImportHelper aValueHelper
;
569 OUString sColumnName
;
579 XMLDatabaseDisplayImportContext(
580 SvXMLImport
& rImport
, /// XML Import
581 XMLTextImportHelper
& rHlp
, /// text import helper
582 sal_uInt16 nPrfx
, /// namespace prefix
583 const OUString
& rLocalName
); /// element name w/o prefix
587 /// process attribute values
588 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
589 const OUString
& sAttrValue
) SAL_OVERRIDE
;
591 /// create, prepare and insert database field master and database field
592 virtual void EndElement() SAL_OVERRIDE
;
597 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */