xref: /aoo42x/main/xmloff/inc/txtvfldi.hxx (revision ecfe53c5)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 /** @#file
25  *
26  *  XML import of all variable related text fields plus database display field
27  */
28 
29 #ifndef _XMLOFF_TXTVFLDI_HXX
30 #define _XMLOFF_TXTVFLDI_HXX
31 
32 #include "txtvfldi.hxx"
33 #include "txtfldi.hxx"
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/beans/XPropertySetInfo.hpp>
36 
37 
38 
39 /// variable type (for XMLSetVarFieldImportContext)
40 enum VarType
41 {
42 	VarTypeSimple,
43 	VarTypeUserField,
44 	VarTypeSequence
45 };
46 
47 
48 
49 /** helper class: parses value-type and associated value attributes */
50 class XMLValueImportHelper
51 {
52 
53 	const ::rtl::OUString sPropertyContent;
54 	const ::rtl::OUString sPropertyValue;
55 	const ::rtl::OUString sPropertyFormula;
56 	const ::rtl::OUString sPropertyNumberFormat;
57     const ::rtl::OUString sPropertyIsFixedLanguage;
58 
59 	SvXMLImport& rImport;
60 	XMLTextImportHelper& rHelper;
61 
62 	::rtl::OUString sValue;		/// string value (only valid if bStringValueOK)
63 	double fValue;				/// double value (only valid if bFloatValueOK)
64 	sal_Int32 nFormatKey;		/// format key (only valid of bFormatOK)
65 	::rtl::OUString sFormula;	/// formula string
66 	::rtl::OUString sDefault;	/// default (see bStringDefault/bFormulaDef.)
67     sal_Bool bIsDefaultLanguage;/// format (of nFormatKey) has system language?
68 
69 	sal_Bool bStringType; 		/// is this a string (or a float) type?
70 	sal_Bool bFormatOK;			/// have we read a style:data-style-name attr.?
71 	sal_Bool bTypeOK;			/// have we read a value-type attribute?
72 	sal_Bool bStringValueOK;	/// have we read a string-value attr.?
73 	sal_Bool bFloatValueOK;		/// have we read any of the float attr.s?
74 	sal_Bool bFormulaOK;		/// have we read the formula attribute?
75 
76 	const sal_Bool bSetType;	/// should PrepareField set the SetExp subtype?
77 	const sal_Bool bSetValue;	/// should PrepareField set content/value?
78 	const sal_Bool bSetStyle;	/// should PrepareField set NumberFormat?
79 	const sal_Bool bSetFormula;	/// should PrepareField set Formula?
80 
81 	const sal_Bool bStringDefault;	/// default: string-value = content
82 	const sal_Bool bFormulaDefault;	/// default: formula = content
83 
84 public:
85 	XMLValueImportHelper(
86 		SvXMLImport& rImprt,					/// XML Import
87 		XMLTextImportHelper& rHlp,				/// text import helper
88 		sal_Bool bType, 						/// process type (PrepareField)
89 		sal_Bool bStyle,						/// process data style (P.F.)
90 		sal_Bool bValue, 						/// process value (Prep.Field)
91 		sal_Bool bFormula);						/// process formula (Prep.F.)
92 
93 	virtual ~XMLValueImportHelper();
94 
95 	/// process attribute values
96 	virtual void ProcessAttribute( sal_uInt16 nAttrToken,
97 								   const ::rtl::OUString& sAttrValue );
98 
99 	/// prepare XTextField for insertion into document
100 	virtual void PrepareField(
101 		const ::com::sun::star::uno::Reference<
102 		::com::sun::star::beans::XPropertySet> & xPropertySet);
103 
104 	/// is value a string (rather than double)?
IsStringValue()105 	inline sal_Bool IsStringValue() { return bStringType; }
106 
107 	/// has format been read?
IsFormatOK()108 	inline sal_Bool IsFormatOK() { return bFormatOK; }
109 
SetDefault(const::rtl::OUString & sStr)110 	inline void SetDefault(const ::rtl::OUString& sStr) { sDefault = sStr; }
111 };
112 
113 
114 
115 /**
116  * abstract parent class for all variable related fields
117  * - variable-set/get/decl		(not -decls),
118  * - user-field-get/decl		(not -decls),
119  * - sequence/-decl				(not -decls),
120  * - expression,
121  * - text-input
122  *
123  * Processes the following attributes:
124  * - name
125  * - formula
126  * - display
127  * - value, value-type, data-style-name (via XMLValueImportHelper)
128  * - description.
129  *
130  * Each attribute has a corresponding member, a bool variable to indicate
131  * whether it was set or not, and a bool variable whether it should be set
132  * using the standard property name.
133  *
134  * bValid is set true, when name is found!
135  * (Most variable related fields are valid, if a name is
136  * found. However, some are always valid. In this case, setting bValid
137  * does not matter.)
138  */
139 class XMLVarFieldImportContext : public XMLTextFieldImportContext
140 {
141 protected:
142 	const ::rtl::OUString sPropertyContent;
143 	const ::rtl::OUString sPropertyHint;
144 	const ::rtl::OUString sPropertyHelp;
145 	const ::rtl::OUString sPropertyTooltip;
146 	const ::rtl::OUString sPropertyIsVisible;
147 	const ::rtl::OUString sPropertyIsDisplayFormula;
148 	const ::rtl::OUString sPropertyCurrentPresentation;
149 
150 private:
151 	::rtl::OUString sName;				/// name attribute
152 	::rtl::OUString sFormula;			/// formula attribute
153 	::rtl::OUString sDescription;		/// description
154     ::rtl::OUString sHelp;              /// help text
155     ::rtl::OUString sHint;              /// hint
156 	XMLValueImportHelper aValueHelper;	/// value, value-type, and style
157 	sal_Bool bDisplayFormula;			/// display formula?(rather than value)
158 	sal_Bool bDisplayNone;				/// hide field?
159 
160 	sal_Bool bNameOK;					/// sName was set
161 	sal_Bool bFormulaOK;				/// sFormula was set
162 	sal_Bool bDescriptionOK;			/// sDescription was set
163     sal_Bool bHelpOK;                   /// sHelp was set
164     sal_Bool bHintOK;                   /// sHint was set
165 	sal_Bool bDisplayOK;				/// sDisplayFormula/-None were set
166 
167 	sal_Bool bSetName;					/// set sName with ???-property
168 	sal_Bool bSetFormula;				/// set Formula property
169 	sal_Bool bSetFormulaDefault;		/// use content as default for formula
170 	sal_Bool bSetDescription;			/// set sDescription with Hint-property
171     sal_Bool bSetHelp;
172     sal_Bool bSetHint;
173 	sal_Bool bSetVisible;				/// set IsVisible
174 	sal_Bool bSetDisplayFormula;		/// set DisplayFormula (sub type???)
175 	sal_Bool bSetPresentation;			/// set presentation frm elem. content?
176 
177 public:
178 
179 	TYPEINFO();
180 
181 	XMLVarFieldImportContext(
182 		// for XMLTextFieldImportContext:
183 		SvXMLImport& rImport,			/// XML Import
184 		XMLTextImportHelper& rHlp,		/// text import helper
185 		const sal_Char* pServiceName,	/// name of SO API service
186 		sal_uInt16 nPrfx,				/// namespace prefix
187 		const ::rtl::OUString& rLocalName,	/// element name w/o prefix
188 		// config variables for PrepareField behavior:
189 		sal_Bool bName,					/// set sName with ???-property
190 		sal_Bool bFormula,				/// set Formula property
191 		sal_Bool bFormulaDefault,		/// use content as default for formula
192 		sal_Bool bDescription,			/// set sDescription with Hint-property
193         sal_Bool bHelp,
194         sal_Bool bHint,
195 		sal_Bool bVisible,				/// set IsVisible (display attr)
196 		sal_Bool bDisplayFormula,		/// set ??? (display attr.)
197 		sal_Bool bType,					/// set value type with ???-property
198 		sal_Bool bStyle,				/// set data style (NumberFormat-Prop.)
199 		sal_Bool bValue,				/// set value with Content/Value-Prop.
200 		sal_Bool bPresentation);		/// set presentation from elem. content
201 
202 protected:
203 	/// process attribute values
204 	virtual void ProcessAttribute( sal_uInt16 nAttrToken,
205 								   const ::rtl::OUString& sAttrValue );
206 
207 	/// prepare XTextField for insertion into document
208 	virtual void PrepareField(
209 		const ::com::sun::star::uno::Reference<
210 		::com::sun::star::beans::XPropertySet> & xPropertySet);
211 
212 	// various accessor methods:
GetName()213 	inline ::rtl::OUString GetName()	{ return sName; }
IsStringValue()214 	inline sal_Bool IsStringValue()		{ return aValueHelper.IsStringValue();}
IsNameOK()215 	inline sal_Bool IsNameOK()			{ return bNameOK; }
IsFormulaOK()216 	inline sal_Bool IsFormulaOK()		{ return bFormulaOK; }
IsDescriptionOK()217 	inline sal_Bool IsDescriptionOK()	{ return bDescriptionOK; }
IsDisplayOK()218 	inline sal_Bool IsDisplayOK()		{ return bDisplayOK; }
219 };
220 
221 
222 
223 /** import variable get fields (<text:variable-get>) */
224 class XMLVariableGetFieldImportContext : public XMLVarFieldImportContext
225 {
226 	const ::rtl::OUString sPropertySubType;
227 
228 public:
229 
230 	TYPEINFO();
231 
232 	XMLVariableGetFieldImportContext(
233 		SvXMLImport& rImport,					/// XML Import
234 		XMLTextImportHelper& rHlp,				/// Text import helper
235 		sal_uInt16 nPrfx,						/// namespace prefix
236 		const ::rtl::OUString& rLocalName);		/// element name w/o prefix
237 
238 
239 protected:
240 	/// prepare XTextField for insertion into document
241 	virtual void PrepareField(
242 		const ::com::sun::star::uno::Reference<
243 		::com::sun::star::beans::XPropertySet> & xPropertySet);
244 };
245 
246 
247 
248 /** import expression fields (<text:expression>) */
249 class XMLExpressionFieldImportContext : public XMLVarFieldImportContext
250 {
251 	const ::rtl::OUString sPropertySubType;
252 
253 public:
254 
255 	TYPEINFO();
256 
257 	XMLExpressionFieldImportContext(
258 		SvXMLImport& rImport,					/// XML Import
259 		XMLTextImportHelper& rHlp,				/// Text import helper
260 		sal_uInt16 nPrfx,						/// namespace prefix
261 		const ::rtl::OUString& sLocalName);		/// element name w/o prefix
262 
263 protected:
264 	virtual void PrepareField(
265 		const ::com::sun::star::uno::Reference<
266 		::com::sun::star::beans::XPropertySet> & xPropertySet);
267 };
268 
269 /*** import text input fields (<text:text-input>) */
270 class XMLTextInputFieldImportContext : public XMLVarFieldImportContext
271 {
272 	const ::rtl::OUString sPropertyContent;
273 
274 public:
275 
276 	TYPEINFO();
277 
278 	XMLTextInputFieldImportContext(
279 		SvXMLImport& rImport,					/// XML Import
280 		XMLTextImportHelper& rHlp,				/// Text import helper
281 		sal_uInt16 nPrfx,						/// namespace prefix
282 		const ::rtl::OUString& sLocalName);		/// element name w/o prefix
283 
284 protected:
285 	virtual void PrepareField(
286 		const ::com::sun::star::uno::Reference<
287 		::com::sun::star::beans::XPropertySet> & xPropertySet);
288 };
289 
290 
291 
292 
293 
294 
295 /**
296  * uperclass for variable/user-set, var/user-input, and sequence fields
297  * inds field master of appropriate type and attaches field to it.
298  */
299 class XMLSetVarFieldImportContext : public XMLVarFieldImportContext
300 {
301 	const VarType eFieldType;
302 
303 public:
304 
305 	TYPEINFO();
306 
307 	XMLSetVarFieldImportContext(
308 		// for XMLTextFieldImportContext:
309 		SvXMLImport& rImport,			/// see XMLTextFieldImportContext
310 		XMLTextImportHelper& rHlp,		/// see XMLTextFieldImportContext
311 		const sal_Char* pServiceName,	/// see XMLTextFieldImportContext
312 		sal_uInt16 nPrfx,				/// see XMLTextFieldImportContext
313 		const ::rtl::OUString& rLocalName, /// see XMLTextFieldImportContext
314 		// for finding appropriate field master (see EndElement())
315 		VarType eVarType,				/// variable type
316 		// config variables:
317 		sal_Bool bName,					/// see XMLTextFieldImportContext
318 		sal_Bool bFormula,				/// see XMLTextFieldImportContext
319 		sal_Bool bFormulaDefault,		/// see XMLTextFieldImportContext
320 		sal_Bool bDescription,			/// see XMLTextFieldImportContext
321 		sal_Bool bHelp,     			/// see XMLTextFieldImportContext
322 		sal_Bool bHint,	        		/// see XMLTextFieldImportContext
323 		sal_Bool bVisible,				/// see XMLTextFieldImportContext
324 		sal_Bool bDisplayFormula,		/// see XMLTextFieldImportContext
325 		sal_Bool bType,					/// see XMLTextFieldImportContext
326 		sal_Bool bStyle,				/// see XMLTextFieldImportContext
327 		sal_Bool bValue,				/// see XMLTextFieldImportContext
328 		sal_Bool bPresentation);		/// see XMLTextFieldImportContext
329 
330 protected:
331 
332 	/// create XTextField, attach master and insert into document;
333 	/// also calls PrepareTextField
334 	virtual void EndElement();
335 
336 	/// find appropriate field master
337 	sal_Bool FindFieldMaster(
338 		::com::sun::star::uno::Reference<
339 		::com::sun::star::beans::XPropertySet> & xMaster);
340 };
341 
342 
343 
344 /** import variable set fields (<text:variable-set>) */
345 class XMLVariableSetFieldImportContext : public XMLSetVarFieldImportContext
346 {
347 	const ::rtl::OUString sPropertySubType;
348 
349 public:
350 
351 	TYPEINFO();
352 
353 	XMLVariableSetFieldImportContext(
354 		SvXMLImport& rImport,					/// XML Import
355 		XMLTextImportHelper& rHlp,				/// Text import helper
356 		sal_uInt16 nPrfx,						/// namespace prefix
357 		const ::rtl::OUString& rLocalName);		/// element name w/o prefix
358 
359 protected:
360 	/// prepare XTextField for insertion into document
361 	virtual void PrepareField(
362 		const ::com::sun::star::uno::Reference<
363 		::com::sun::star::beans::XPropertySet> & xPropertySet);
364 };
365 
366 
367 
368 /** variable input fields (<text:variable-input>) */
369 class XMLVariableInputFieldImportContext : public XMLSetVarFieldImportContext
370 {
371 	const ::rtl::OUString sPropertySubType;
372 	const ::rtl::OUString sPropertyIsInput;
373 
374 public:
375 
376 	TYPEINFO();
377 
378 	XMLVariableInputFieldImportContext(
379 		SvXMLImport& rImport,					/// XML Import
380 		XMLTextImportHelper& rHlp,				/// Text import helper
381 		sal_uInt16 nPrfx, 						/// namespace prefix
382 		const ::rtl::OUString& rLocalName);		/// element name w/o prefix
383 
384 protected:
385 
386 	/// prepare XTextField for insertion into document
387 	virtual void PrepareField(
388 		const ::com::sun::star::uno::Reference<
389 		::com::sun::star::beans::XPropertySet> & xPropertySet);
390 };
391 
392 
393 
394 /** user fields (<text:user-field-get>) */
395 class XMLUserFieldImportContext : public XMLSetVarFieldImportContext
396 {
397 
398 public:
399 
400 	TYPEINFO();
401 
402 	XMLUserFieldImportContext(
403 		SvXMLImport& rImport,					/// XML Import
404 		XMLTextImportHelper& rHlp,				/// Text import helper
405 		sal_uInt16 nPrfx,						/// namespace prefix
406 		const ::rtl::OUString& rLocalName);		/// element name w/o prefix
407 };
408 
409 /** user input fields (<text:user-field-input>) */
410 class XMLUserFieldInputImportContext : public XMLVarFieldImportContext
411 {
412 
413 public:
414 
415 	TYPEINFO();
416 
417 	XMLUserFieldInputImportContext(
418 		SvXMLImport& rImport,					/// XML Import
419 		XMLTextImportHelper& rHlp,				/// Text import helper
420 		sal_uInt16 nPrfx,						/// namespace prefix
421 		const ::rtl::OUString& rLocalName);		/// element name w/o prefix
422 
423 	virtual void PrepareField(
424 		const ::com::sun::star::uno::Reference<
425 		::com::sun::star::beans::XPropertySet> & xPropertySet);
426 };
427 
428 
429 
430 /** sequence fields (<text:sequence>) */
431 class XMLSequenceFieldImportContext : public XMLSetVarFieldImportContext
432 {
433 	const ::rtl::OUString sPropertyFormula;
434 	const ::rtl::OUString sPropertyNumberFormat;
435 	const ::rtl::OUString sPropertySequenceValue;
436 	::rtl::OUString sFormula;
437 	::rtl::OUString sNumFormat;
438 	::rtl::OUString sNumFormatSync;
439 	::rtl::OUString sRefName;
440 
441 	sal_Bool bRefNameOK;
442 
443 public:
444 
445 	TYPEINFO();
446 
447 	XMLSequenceFieldImportContext(
448 		SvXMLImport& rImport,					/// XML Import
449 		XMLTextImportHelper& rHlp,				/// Text import helper
450 		sal_uInt16 nPrfx,						/// namespace prefix
451 		const ::rtl::OUString& rLocalName);		/// element name w/o prefix
452 
453 protected:
454 
455 	/// process attribute values
456 	virtual void ProcessAttribute( sal_uInt16 nAttrToken,
457 								   const ::rtl::OUString& sAttrValue );
458 
459 	/// prepare XTextField for insertion into document
460 	virtual void PrepareField(
461 		const ::com::sun::star::uno::Reference<
462 		::com::sun::star::beans::XPropertySet> & xPropertySet);
463 };
464 
465 
466 
467 
468 
469 
470 /**
471  * variable declaration container for all variable fields
472  * 		(variable-decls, user-field-decls, sequence-decls)
473  */
474 class XMLVariableDeclsImportContext : public SvXMLImportContext
475 {
476 	enum VarType eVarDeclsContextType;
477 	XMLTextImportHelper& rImportHelper;
478 
479 public:
480 
481 	TYPEINFO();
482 
483 	XMLVariableDeclsImportContext(
484 		SvXMLImport& rImport,					/// XML Import
485 		XMLTextImportHelper& rHlp,				/// text import helper
486 		sal_uInt16 nPrfx,						/// namespace prefix
487 		const ::rtl::OUString& rLocalName,		/// element name w/o prefix
488 		enum VarType eVarType);					/// variable type
489 
490 	virtual SvXMLImportContext *CreateChildContext(
491 		sal_uInt16 nPrefix,
492 		const ::rtl::OUString& rLocalName,
493 		const ::com::sun::star::uno::Reference<
494 		::com::sun::star::xml::sax::XAttributeList> & xAttrList );
495 };
496 
497 /**
498  * variable field declarations
499  * 		(variable-decl, user-field-decl, sequence-decl)
500  */
501 class XMLVariableDeclImportContext : public SvXMLImportContext
502 {
503 	const ::rtl::OUString sPropertyName;
504 	const ::rtl::OUString sPropertySubType;
505 	const ::rtl::OUString sPropertyNumberingLevel;
506 	const ::rtl::OUString sPropertyNumberingSeparator;
507 	const ::rtl::OUString sPropertyIsExpression;
508 
509 	::rtl::OUString sName;
510 	XMLValueImportHelper aValueHelper;
511 	sal_Int8 nNumLevel;
512 	sal_Unicode cSeparationChar;
513 
514 public:
515 
516 	TYPEINFO();
517 
518 	XMLVariableDeclImportContext(
519 		SvXMLImport& rImport,					/// XML Import
520 		XMLTextImportHelper& rHlp,				/// text import helper
521 		sal_uInt16 nPrfx,						/// namespace prefix
522 		const ::rtl::OUString& rLocalName,		/// element name w/o prefix
523 		const ::com::sun::star::uno::Reference< /// list of element attributes
524 		::com::sun::star::xml::sax::XAttributeList> & xAttrList,
525 		enum VarType eVarType);					/// variable type
526 
527 	/// get field master for name and rename if appropriate
528 	static sal_Bool FindFieldMaster(::com::sun::star::uno::Reference<
529 									::com::sun::star::beans::XPropertySet> & xMaster,
530 									SvXMLImport& rImport,
531 									XMLTextImportHelper& rHelper,
532 									const ::rtl::OUString& sVarName,
533 									enum VarType eVarType);
534 };
535 
536 
537 
538 /** import table formula fields (deprecated; for Writer 2.0 compatibility) */
539 class XMLTableFormulaImportContext : public XMLTextFieldImportContext
540 {
541 	const ::rtl::OUString sPropertyNumberFormat;
542 	const ::rtl::OUString sPropertyContent;
543     const ::rtl::OUString sPropertyIsShowFormula;
544 	const ::rtl::OUString sPropertyCurrentPresentation;
545 
546 	XMLValueImportHelper aValueHelper;
547 
548 	::rtl::OUString sFormula;
549 	sal_Bool bFormulaOK;
550 
551     sal_Bool bIsShowFormula;
552 
553 public:
554 
555 	TYPEINFO();
556 
557 	XMLTableFormulaImportContext(
558 		SvXMLImport& rImport,					/// XML Import
559 		XMLTextImportHelper& rHlp,				/// text import helper
560 		sal_uInt16 nPrfx,						/// namespace prefix
561 		const ::rtl::OUString& rLocalName);		/// element name w/o prefix
562     virtual ~XMLTableFormulaImportContext();
563 
564 protected:
565 
566 	/// process attribute values
567 	virtual void ProcessAttribute( sal_uInt16 nAttrToken,
568 								   const ::rtl::OUString& sAttrValue );
569 
570 	/// prepare XTextField for insertion into document
571 	virtual void PrepareField(
572 		const ::com::sun::star::uno::Reference<
573 		::com::sun::star::beans::XPropertySet> & xPropertySet);
574 };
575 
576 
577 
578 /** import database display fields (<text:database-display>) */
579 class XMLDatabaseDisplayImportContext : public XMLDatabaseFieldImportContext
580 {
581 	const ::rtl::OUString sPropertyColumnName;
582 	const ::rtl::OUString sPropertyDatabaseFormat;
583 	const ::rtl::OUString sPropertyCurrentPresentation;
584     const ::rtl::OUString sPropertyIsVisible;
585 
586 	XMLValueImportHelper aValueHelper;
587 
588 	::rtl::OUString sColumnName;
589 	sal_Bool bColumnOK;
590 
591     sal_Bool bDisplay;
592     sal_Bool bDisplayOK;
593 
594 public:
595 
596 	TYPEINFO();
597 
598 	XMLDatabaseDisplayImportContext(
599 		SvXMLImport& rImport,					/// XML Import
600 		XMLTextImportHelper& rHlp,				/// text import helper
601 		sal_uInt16 nPrfx,						/// namespace prefix
602 		const ::rtl::OUString& rLocalName);		/// element name w/o prefix
603 
604 protected:
605 
606 	/// process attribute values
607 	virtual void ProcessAttribute( sal_uInt16 nAttrToken,
608 								   const ::rtl::OUString& sAttrValue );
609 
610 	/// create, prepare and insert database field master and database field
611 	virtual void EndElement();
612 };
613 
614 #endif
615