1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtvfldi.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 * XML import of all variable related text fields plus database display field
36 #ifndef _XMLOFF_TXTVFLDI_HXX
37 #define _XMLOFF_TXTVFLDI_HXX
39 #include "txtvfldi.hxx"
40 #include "txtfldi.hxx"
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/beans/XPropertySetInfo.hpp>
46 /// variable type (for XMLSetVarFieldImportContext)
56 /** helper class: parses value-type and associated value attributes */
57 class XMLValueImportHelper
60 const ::rtl::OUString sPropertyContent
;
61 const ::rtl::OUString sPropertyValue
;
62 const ::rtl::OUString sPropertyFormula
;
63 const ::rtl::OUString sPropertyNumberFormat
;
64 const ::rtl::OUString sPropertyIsFixedLanguage
;
67 XMLTextImportHelper
& rHelper
;
69 ::rtl::OUString sValue
; /// string value (only valid if bStringValueOK)
70 double fValue
; /// double value (only valid if bFloatValueOK)
71 sal_Int32 nFormatKey
; /// format key (only valid of bFormatOK)
72 ::rtl::OUString sFormula
; /// formula string
73 ::rtl::OUString sDefault
; /// default (see bStringDefault/bFormulaDef.)
74 sal_Bool bIsDefaultLanguage
;/// format (of nFormatKey) has system language?
76 sal_Bool bStringType
; /// is this a string (or a float) type?
77 sal_Bool bFormatOK
; /// have we read a style:data-style-name attr.?
78 sal_Bool bTypeOK
; /// have we read a value-type attribute?
79 sal_Bool bStringValueOK
; /// have we read a string-value attr.?
80 sal_Bool bFloatValueOK
; /// have we read any of the float attr.s?
81 sal_Bool bFormulaOK
; /// have we read the formula attribute?
83 const sal_Bool bSetType
; /// should PrepareField set the SetExp subtype?
84 const sal_Bool bSetValue
; /// should PrepareField set content/value?
85 const sal_Bool bSetStyle
; /// should PrepareField set NumberFormat?
86 const sal_Bool bSetFormula
; /// should PrepareField set Formula?
88 const sal_Bool bStringDefault
; /// default: string-value = content
89 const sal_Bool bFormulaDefault
; /// default: formula = content
93 SvXMLImport
& rImprt
, /// XML Import
94 XMLTextImportHelper
& rHlp
, /// text import helper
95 sal_Bool bType
, /// process type (PrepareField)
96 sal_Bool bStyle
, /// process data style (P.F.)
97 sal_Bool bValue
, /// process value (Prep.Field)
98 sal_Bool bFormula
); /// process formula (Prep.F.)
100 virtual ~XMLValueImportHelper();
102 /// process attribute values
103 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
104 const ::rtl::OUString
& sAttrValue
);
106 /// prepare XTextField for insertion into document
107 virtual void PrepareField(
108 const ::com::sun::star::uno::Reference
<
109 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
111 /// is value a string (rather than double)?
112 inline sal_Bool
IsStringValue() { return bStringType
; }
114 /// has format been read?
115 inline sal_Bool
IsFormatOK() { return bFormatOK
; }
117 inline void SetDefault(const ::rtl::OUString
& sStr
) { sDefault
= sStr
; }
123 * abstract parent class for all variable related fields
124 * - variable-set/get/decl (not -decls),
125 * - user-field-get/decl (not -decls),
126 * - sequence/-decl (not -decls),
130 * Processes the following attributes:
134 * - value, value-type, data-style-name (via XMLValueImportHelper)
137 * Each attribute has a corresponding member, a bool variable to indicate
138 * whether it was set or not, and a bool variable whether it should be set
139 * using the standard property name.
141 * bValid is set true, when name is found!
142 * (Most variable related fields are valid, if a name is
143 * found. However, some are always valid. In this case, setting bValid
146 class XMLVarFieldImportContext
: public XMLTextFieldImportContext
149 const ::rtl::OUString sPropertyContent
;
150 const ::rtl::OUString sPropertyHint
;
151 const ::rtl::OUString sPropertyHelp
;
152 const ::rtl::OUString sPropertyTooltip
;
153 const ::rtl::OUString sPropertyIsVisible
;
154 const ::rtl::OUString sPropertyIsDisplayFormula
;
155 const ::rtl::OUString sPropertyCurrentPresentation
;
158 ::rtl::OUString sName
; /// name attribute
159 ::rtl::OUString sFormula
; /// formula attribute
160 ::rtl::OUString sDescription
; /// description
161 ::rtl::OUString sHelp
; /// help text
162 ::rtl::OUString sHint
; /// hint
163 XMLValueImportHelper aValueHelper
; /// value, value-type, and style
164 sal_Bool bDisplayFormula
; /// display formula?(rather than value)
165 sal_Bool bDisplayNone
; /// hide field?
167 sal_Bool bNameOK
; /// sName was set
168 sal_Bool bFormulaOK
; /// sFormula was set
169 sal_Bool bDescriptionOK
; /// sDescription was set
170 sal_Bool bHelpOK
; /// sHelp was set
171 sal_Bool bHintOK
; /// sHint was set
172 sal_Bool bDisplayOK
; /// sDisplayFormula/-None were set
174 sal_Bool bSetName
; /// set sName with ???-property
175 sal_Bool bSetFormula
; /// set Formula property
176 sal_Bool bSetFormulaDefault
; /// use content as default for formula
177 sal_Bool bSetDescription
; /// set sDescription with Hint-property
180 sal_Bool bSetVisible
; /// set IsVisible
181 sal_Bool bSetDisplayFormula
; /// set DisplayFormula (sub type???)
182 sal_Bool bSetPresentation
; /// set presentation frm elem. content?
188 XMLVarFieldImportContext(
189 // for XMLTextFieldImportContext:
190 SvXMLImport
& rImport
, /// XML Import
191 XMLTextImportHelper
& rHlp
, /// text import helper
192 const sal_Char
* pServiceName
, /// name of SO API service
193 sal_uInt16 nPrfx
, /// namespace prefix
194 const ::rtl::OUString
& rLocalName
, /// element name w/o prefix
195 // config variables for PrepareField behavior:
196 sal_Bool bName
, /// set sName with ???-property
197 sal_Bool bFormula
, /// set Formula property
198 sal_Bool bFormulaDefault
, /// use content as default for formula
199 sal_Bool bDescription
, /// set sDescription with Hint-property
202 sal_Bool bVisible
, /// set IsVisible (display attr)
203 sal_Bool bDisplayFormula
, /// set ??? (display attr.)
204 sal_Bool bType
, /// set value type with ???-property
205 sal_Bool bStyle
, /// set data style (NumberFormat-Prop.)
206 sal_Bool bValue
, /// set value with Content/Value-Prop.
207 sal_Bool bPresentation
); /// set presentation from elem. content
210 /// process attribute values
211 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
212 const ::rtl::OUString
& sAttrValue
);
214 /// prepare XTextField for insertion into document
215 virtual void PrepareField(
216 const ::com::sun::star::uno::Reference
<
217 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
219 // various accessor methods:
220 inline ::rtl::OUString
GetName() { return sName
; }
221 inline sal_Bool
IsStringValue() { return aValueHelper
.IsStringValue();}
222 inline sal_Bool
IsNameOK() { return bNameOK
; }
223 inline sal_Bool
IsFormulaOK() { return bFormulaOK
; }
224 inline sal_Bool
IsDescriptionOK() { return bDescriptionOK
; }
225 inline sal_Bool
IsDisplayOK() { return bDisplayOK
; }
230 /** import variable get fields (<text:variable-get>) */
231 class XMLVariableGetFieldImportContext
: public XMLVarFieldImportContext
233 const ::rtl::OUString sPropertySubType
;
239 XMLVariableGetFieldImportContext(
240 SvXMLImport
& rImport
, /// XML Import
241 XMLTextImportHelper
& rHlp
, /// Text import helper
242 sal_uInt16 nPrfx
, /// namespace prefix
243 const ::rtl::OUString
& rLocalName
); /// element name w/o prefix
247 /// prepare XTextField for insertion into document
248 virtual void PrepareField(
249 const ::com::sun::star::uno::Reference
<
250 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
255 /** import expression fields (<text:expression>) */
256 class XMLExpressionFieldImportContext
: public XMLVarFieldImportContext
258 const ::rtl::OUString sPropertySubType
;
264 XMLExpressionFieldImportContext(
265 SvXMLImport
& rImport
, /// XML Import
266 XMLTextImportHelper
& rHlp
, /// Text import helper
267 sal_uInt16 nPrfx
, /// namespace prefix
268 const ::rtl::OUString
& sLocalName
); /// element name w/o prefix
271 virtual void PrepareField(
272 const ::com::sun::star::uno::Reference
<
273 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
276 /*** import text input fields (<text:text-input>) */
277 class XMLTextInputFieldImportContext
: public XMLVarFieldImportContext
279 const ::rtl::OUString sPropertyContent
;
285 XMLTextInputFieldImportContext(
286 SvXMLImport
& rImport
, /// XML Import
287 XMLTextImportHelper
& rHlp
, /// Text import helper
288 sal_uInt16 nPrfx
, /// namespace prefix
289 const ::rtl::OUString
& sLocalName
); /// element name w/o prefix
292 virtual void PrepareField(
293 const ::com::sun::star::uno::Reference
<
294 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
303 * uperclass for variable/user-set, var/user-input, and sequence fields
304 * inds field master of appropriate type and attaches field to it.
306 class XMLSetVarFieldImportContext
: public XMLVarFieldImportContext
308 const VarType eFieldType
;
314 XMLSetVarFieldImportContext(
315 // for XMLTextFieldImportContext:
316 SvXMLImport
& rImport
, /// see XMLTextFieldImportContext
317 XMLTextImportHelper
& rHlp
, /// see XMLTextFieldImportContext
318 const sal_Char
* pServiceName
, /// see XMLTextFieldImportContext
319 sal_uInt16 nPrfx
, /// see XMLTextFieldImportContext
320 const ::rtl::OUString
& rLocalName
, /// see XMLTextFieldImportContext
321 // for finding appropriate field master (see EndElement())
322 VarType eVarType
, /// variable type
324 sal_Bool bName
, /// see XMLTextFieldImportContext
325 sal_Bool bFormula
, /// see XMLTextFieldImportContext
326 sal_Bool bFormulaDefault
, /// see XMLTextFieldImportContext
327 sal_Bool bDescription
, /// see XMLTextFieldImportContext
328 sal_Bool bHelp
, /// see XMLTextFieldImportContext
329 sal_Bool bHint
, /// see XMLTextFieldImportContext
330 sal_Bool bVisible
, /// see XMLTextFieldImportContext
331 sal_Bool bDisplayFormula
, /// see XMLTextFieldImportContext
332 sal_Bool bType
, /// see XMLTextFieldImportContext
333 sal_Bool bStyle
, /// see XMLTextFieldImportContext
334 sal_Bool bValue
, /// see XMLTextFieldImportContext
335 sal_Bool bPresentation
); /// see XMLTextFieldImportContext
339 /// create XTextField, attach master and insert into document;
340 /// also calls PrepareTextField
341 virtual void EndElement();
343 /// find appropriate field master
344 sal_Bool
FindFieldMaster(
345 ::com::sun::star::uno::Reference
<
346 ::com::sun::star::beans::XPropertySet
> & xMaster
);
351 /** import variable set fields (<text:variable-set>) */
352 class XMLVariableSetFieldImportContext
: public XMLSetVarFieldImportContext
354 const ::rtl::OUString sPropertySubType
;
360 XMLVariableSetFieldImportContext(
361 SvXMLImport
& rImport
, /// XML Import
362 XMLTextImportHelper
& rHlp
, /// Text import helper
363 sal_uInt16 nPrfx
, /// namespace prefix
364 const ::rtl::OUString
& rLocalName
); /// element name w/o prefix
367 /// prepare XTextField for insertion into document
368 virtual void PrepareField(
369 const ::com::sun::star::uno::Reference
<
370 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
375 /** variable input fields (<text:variable-input>) */
376 class XMLVariableInputFieldImportContext
: public XMLSetVarFieldImportContext
378 const ::rtl::OUString sPropertySubType
;
379 const ::rtl::OUString sPropertyIsInput
;
385 XMLVariableInputFieldImportContext(
386 SvXMLImport
& rImport
, /// XML Import
387 XMLTextImportHelper
& rHlp
, /// Text import helper
388 sal_uInt16 nPrfx
, /// namespace prefix
389 const ::rtl::OUString
& rLocalName
); /// element name w/o prefix
393 /// prepare XTextField for insertion into document
394 virtual void PrepareField(
395 const ::com::sun::star::uno::Reference
<
396 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
401 /** user fields (<text:user-field-get>) */
402 class XMLUserFieldImportContext
: public XMLSetVarFieldImportContext
409 XMLUserFieldImportContext(
410 SvXMLImport
& rImport
, /// XML Import
411 XMLTextImportHelper
& rHlp
, /// Text import helper
412 sal_uInt16 nPrfx
, /// namespace prefix
413 const ::rtl::OUString
& rLocalName
); /// element name w/o prefix
416 /** user input fields (<text:user-field-input>) */
417 class XMLUserFieldInputImportContext
: public XMLVarFieldImportContext
424 XMLUserFieldInputImportContext(
425 SvXMLImport
& rImport
, /// XML Import
426 XMLTextImportHelper
& rHlp
, /// Text import helper
427 sal_uInt16 nPrfx
, /// namespace prefix
428 const ::rtl::OUString
& rLocalName
); /// element name w/o prefix
430 virtual void PrepareField(
431 const ::com::sun::star::uno::Reference
<
432 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
437 /** sequence fields (<text:sequence>) */
438 class XMLSequenceFieldImportContext
: public XMLSetVarFieldImportContext
440 const ::rtl::OUString sPropertyFormula
;
441 const ::rtl::OUString sPropertyNumberFormat
;
442 const ::rtl::OUString sPropertySequenceValue
;
443 ::rtl::OUString sFormula
;
444 ::rtl::OUString sNumFormat
;
445 ::rtl::OUString sNumFormatSync
;
446 ::rtl::OUString sRefName
;
454 XMLSequenceFieldImportContext(
455 SvXMLImport
& rImport
, /// XML Import
456 XMLTextImportHelper
& rHlp
, /// Text import helper
457 sal_uInt16 nPrfx
, /// namespace prefix
458 const ::rtl::OUString
& rLocalName
); /// element name w/o prefix
462 /// process attribute values
463 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
464 const ::rtl::OUString
& sAttrValue
);
466 /// prepare XTextField for insertion into document
467 virtual void PrepareField(
468 const ::com::sun::star::uno::Reference
<
469 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
478 * variable declaration container for all variable fields
479 * (variable-decls, user-field-decls, sequence-decls)
481 class XMLVariableDeclsImportContext
: public SvXMLImportContext
483 enum VarType eVarDeclsContextType
;
484 XMLTextImportHelper
& rImportHelper
;
490 XMLVariableDeclsImportContext(
491 SvXMLImport
& rImport
, /// XML Import
492 XMLTextImportHelper
& rHlp
, /// text import helper
493 sal_uInt16 nPrfx
, /// namespace prefix
494 const ::rtl::OUString
& rLocalName
, /// element name w/o prefix
495 enum VarType eVarType
); /// variable type
497 virtual SvXMLImportContext
*CreateChildContext(
499 const ::rtl::OUString
& rLocalName
,
500 const ::com::sun::star::uno::Reference
<
501 ::com::sun::star::xml::sax::XAttributeList
> & xAttrList
);
505 * variable field declarations
506 * (variable-decl, user-field-decl, sequence-decl)
508 class XMLVariableDeclImportContext
: public SvXMLImportContext
510 const ::rtl::OUString sPropertyName
;
511 const ::rtl::OUString sPropertySubType
;
512 const ::rtl::OUString sPropertyNumberingLevel
;
513 const ::rtl::OUString sPropertyNumberingSeparator
;
514 const ::rtl::OUString sPropertyIsExpression
;
516 ::rtl::OUString sName
;
517 XMLValueImportHelper aValueHelper
;
519 sal_Unicode cSeparationChar
;
525 XMLVariableDeclImportContext(
526 SvXMLImport
& rImport
, /// XML Import
527 XMLTextImportHelper
& rHlp
, /// text import helper
528 sal_uInt16 nPrfx
, /// namespace prefix
529 const ::rtl::OUString
& rLocalName
, /// element name w/o prefix
530 const ::com::sun::star::uno::Reference
< /// list of element attributes
531 ::com::sun::star::xml::sax::XAttributeList
> & xAttrList
,
532 enum VarType eVarType
); /// variable type
534 /// get field master for name and rename if appropriate
535 static sal_Bool
FindFieldMaster(::com::sun::star::uno::Reference
<
536 ::com::sun::star::beans::XPropertySet
> & xMaster
,
537 SvXMLImport
& rImport
,
538 XMLTextImportHelper
& rHelper
,
539 const ::rtl::OUString
& sVarName
,
540 enum VarType eVarType
);
545 /** import table formula fields (deprecated; for Writer 2.0 compatibility) */
546 class XMLTableFormulaImportContext
: public XMLTextFieldImportContext
548 const ::rtl::OUString sPropertyNumberFormat
;
549 const ::rtl::OUString sPropertyContent
;
550 const ::rtl::OUString sPropertyIsShowFormula
;
551 const ::rtl::OUString sPropertyCurrentPresentation
;
553 XMLValueImportHelper aValueHelper
;
555 ::rtl::OUString sFormula
;
558 sal_Bool bIsShowFormula
;
564 XMLTableFormulaImportContext(
565 SvXMLImport
& rImport
, /// XML Import
566 XMLTextImportHelper
& rHlp
, /// text import helper
567 sal_uInt16 nPrfx
, /// namespace prefix
568 const ::rtl::OUString
& rLocalName
); /// element name w/o prefix
569 virtual ~XMLTableFormulaImportContext();
573 /// process attribute values
574 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
575 const ::rtl::OUString
& sAttrValue
);
577 /// prepare XTextField for insertion into document
578 virtual void PrepareField(
579 const ::com::sun::star::uno::Reference
<
580 ::com::sun::star::beans::XPropertySet
> & xPropertySet
);
585 /** import database display fields (<text:database-display>) */
586 class XMLDatabaseDisplayImportContext
: public XMLDatabaseFieldImportContext
588 const ::rtl::OUString sPropertyColumnName
;
589 const ::rtl::OUString sPropertyDatabaseFormat
;
590 const ::rtl::OUString sPropertyCurrentPresentation
;
591 const ::rtl::OUString sPropertyIsVisible
;
593 XMLValueImportHelper aValueHelper
;
595 ::rtl::OUString sColumnName
;
605 XMLDatabaseDisplayImportContext(
606 SvXMLImport
& rImport
, /// XML Import
607 XMLTextImportHelper
& rHlp
, /// text import helper
608 sal_uInt16 nPrfx
, /// namespace prefix
609 const ::rtl::OUString
& rLocalName
); /// element name w/o prefix
613 /// process attribute values
614 virtual void ProcessAttribute( sal_uInt16 nAttrToken
,
615 const ::rtl::OUString
& sAttrValue
);
617 /// create, prepare and insert database field master and database field
618 virtual void EndElement();