xref: /trunk/main/xmloff/source/text/txtvfldi.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 /** @#file
32  *
33  *  export of all variable related text fields (and database display field)
34  */
35 #include "txtvfldi.hxx"
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/txtimp.hxx>
38 #include <xmloff/xmlnumi.hxx>
39 #include "xmloff/xmlnmspe.hxx"
40 #include <xmloff/nmspmap.hxx>
41 #include "xmloff/i18nmap.hxx"
42 #include <xmloff/xmlimp.hxx>
43 #include <xmloff/xmluconv.hxx>
44 #include <xmloff/xmlement.hxx>
45 #include <com/sun/star/text/SetVariableType.hpp>
46 #include <com/sun/star/text/XTextField.hpp>
47 #include <com/sun/star/text/XDependentTextField.hpp>
48 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
49 #include <com/sun/star/beans/XPropertySet.hpp>
50 #include <com/sun/star/beans/XPropertySetInfo.hpp>
51 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 #include <com/sun/star/xml/sax/XAttributeList.hpp>
53 
54 #ifndef _RTL_USTRING
55 #include <rtl/ustring.hxx>
56 #endif
57 #include <tools/debug.hxx>
58 
59 
60 // service names
61 static const sal_Char sAPI_textfield_prefix[]	= "com.sun.star.text.TextField.";
62 static const sal_Char sAPI_fieldmaster_prefix[] = "com.sun.star.text.FieldMaster.";
63 static const sal_Char sAPI_input[]				= "Input";
64 static const sal_Char sAPI_input_user[]			= "InputUser";
65 static const sal_Char sAPI_get_expression[] 	= "GetExpression";
66 static const sal_Char sAPI_set_expression[] 	= "SetExpression";
67 static const sal_Char sAPI_user[]				= "User";
68 static const sal_Char sAPI_table_formula[]      = "TableFormula";
69 static const sal_Char sAPI_database[]			= "com.sun.star.text.TextField.Database";
70 static const sal_Char sAPI_fieldmaster_database[] = "com.sun.star.text.FieldMaster.Database";
71 
72 // property names
73 static const sal_Char sAPI_hint[] 				= "Hint";
74 static const sal_Char sAPI_help[] 				= "Help";
75 static const sal_Char sAPI_tooltip[] 			= "Tooltip";
76 static const sal_Char sAPI_content[]			= "Content";
77 static const sal_Char sAPI_sub_type[]			= "SubType";
78 static const sal_Char sAPI_is_expression[]		= "IsExpression";
79 static const sal_Char sAPI_is_input[]			= "Input";
80 static const sal_Char sAPI_is_show_formula[]	= "IsShowFormula";
81 static const sal_Char sAPI_numbering_type[]		= "NumberingType";
82 static const sal_Char sAPI_number_format[]		= "NumberFormat";
83 static const sal_Char sAPI_name[]				= "Name";
84 static const sal_Char sAPI_numbering_separator[]	= "NumberingSeparator";
85 static const sal_Char sAPI_chapter_numbering_level[]= "ChapterNumberingLevel";
86 static const sal_Char sAPI_value[]				= "Value";
87 static const sal_Char sAPI_is_visible[]			= "IsVisible";
88 static const sal_Char sAPI_variable_subtype[]	= "VariableSubtype";
89 static const sal_Char sAPI_data_column_name[]	= "DataColumnName";
90 static const sal_Char sAPI_is_data_base_format[]	= "DataBaseFormat";
91 static const sal_Char sAPI_current_presentation[]	= "CurrentPresentation";
92 static const sal_Char sAPI_sequence_value[]		= "SequenceValue";
93 static const sal_Char sAPI_is_fixed_language[] = "IsFixedLanguage";
94 
95 
96 using ::rtl::OUString;
97 using ::rtl::OUStringBuffer;
98 
99 using namespace ::com::sun::star;
100 using namespace ::com::sun::star::uno;
101 using namespace ::com::sun::star::beans;
102 using namespace ::com::sun::star::text;
103 using namespace ::com::sun::star::style;
104 using namespace ::xmloff::token;
105 
106 
107 
108 //
109 // XMLVarFieldImportContext: superclass for all variable related fields
110 //
111 
112 TYPEINIT1( XMLVarFieldImportContext, XMLTextFieldImportContext );
113 
114 XMLVarFieldImportContext::XMLVarFieldImportContext(
115 	SvXMLImport& rImport, XMLTextImportHelper& rHlp,
116 	const sal_Char* pServiceName, sal_uInt16 nPrfx,
117 	const OUString& rLocalName,
118 	sal_Bool bName, sal_Bool bFormula, sal_Bool bFormulaDefault,
119 	sal_Bool bDescription, sal_Bool bHelp, sal_Bool bHint, sal_Bool bVisible,
120     sal_Bool bIsDisplayFormula,
121 	sal_Bool bType, sal_Bool bStyle, sal_Bool bValue,
122 	sal_Bool bPresentation) :
123 		XMLTextFieldImportContext(rImport, rHlp, pServiceName, nPrfx, rLocalName),
124 		sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)),
125 		sPropertyHint(RTL_CONSTASCII_USTRINGPARAM(sAPI_hint)),
126         sPropertyHelp(RTL_CONSTASCII_USTRINGPARAM(sAPI_help)),
127         sPropertyTooltip(RTL_CONSTASCII_USTRINGPARAM(sAPI_tooltip)),
128 		sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_visible)),
129 		sPropertyIsDisplayFormula(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_show_formula)),
130 		sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)),
131 		aValueHelper(rImport, rHlp, bType, bStyle, bValue, sal_False),
132 		bDisplayFormula(sal_False),
133 		bDisplayNone(sal_False),
134 		bNameOK(sal_False),
135 		bFormulaOK(sal_False),
136 		bDescriptionOK(sal_False),
137         bHelpOK(sal_False),
138         bHintOK(sal_False),
139 		bDisplayOK(sal_False),
140 		bSetName(bName),
141 		bSetFormula(bFormula),
142 		bSetFormulaDefault(bFormulaDefault),
143 		bSetDescription(bDescription),
144         bSetHelp(bHelp),
145         bSetHint(bHint),
146 		bSetVisible(bVisible),
147 		bSetDisplayFormula(bIsDisplayFormula),
148 		bSetPresentation(bPresentation)
149 {
150 }
151 
152 void XMLVarFieldImportContext::ProcessAttribute(
153 	sal_uInt16 nAttrToken,
154 	const OUString& sAttrValue )
155 {
156 	switch (nAttrToken)
157 		{
158 		case XML_TOK_TEXTFIELD_NAME:
159 			sName = sAttrValue;
160 			bNameOK = sal_True;
161 			bValid = sal_True;		// we assume: field with name is valid!
162 			break;
163 		case XML_TOK_TEXTFIELD_DESCRIPTION:
164 			sDescription = sAttrValue;
165 			bDescriptionOK = sal_True;
166 			break;
167         case XML_TOK_TEXTFIELD_HELP:
168             sHelp = sAttrValue;
169             bHelpOK = true;
170             break;
171         case XML_TOK_TEXTFIELD_HINT:
172             sHint = sAttrValue;
173             bHintOK = true;
174             break;
175 		case XML_TOK_TEXTFIELD_FORMULA:
176 			{
177 				OUString sTmp;
178 				sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
179 						_GetKeyByAttrName( sAttrValue, &sTmp, sal_False );
180 				if( XML_NAMESPACE_OOOW == nPrefix )
181 				{
182 					sFormula = sTmp;
183 					bFormulaOK = sal_True;
184 				}
185 				else
186 					sFormula = sAttrValue;
187 			}
188 			break;
189 		case XML_TOK_TEXTFIELD_DISPLAY:
190 			if (IsXMLToken(sAttrValue, XML_FORMULA))
191 			{
192 				bDisplayFormula = sal_True;
193 				bDisplayNone = sal_False;
194 				bDisplayOK = sal_True;
195 			}
196 			else if (IsXMLToken(sAttrValue, XML_VALUE))
197 			{
198 				bDisplayFormula = sal_False;
199 				bDisplayNone = sal_False;
200 				bDisplayOK = sal_True;
201 			}
202 			else if (IsXMLToken(sAttrValue, XML_NONE))
203 			{
204 				bDisplayFormula = sal_False;
205 				bDisplayNone = sal_True;
206 				bDisplayOK = sal_True;
207 			} // else: no change
208 			DBG_ASSERT(!(bDisplayFormula && bDisplayNone),
209 					   "illegal display values");
210 			break;
211 		default:
212 			// delegate all others to value helper
213 			aValueHelper.ProcessAttribute(nAttrToken, sAttrValue);
214 			break;
215 		}
216 }
217 
218 void XMLVarFieldImportContext::PrepareField(
219 	const Reference<XPropertySet> & xPropertySet)
220 {
221 	// bSetName: not implemented
222 
223 	if (bSetFormula)
224 	{
225 		if (!bFormulaOK && bSetFormulaDefault)
226 		{
227 			sFormula = GetContent();
228 			bFormulaOK = sal_True;
229 		}
230 
231 		if (bFormulaOK)
232 		{
233 			Any aAny;
234 			aAny <<= sFormula;
235 			xPropertySet->setPropertyValue(sPropertyContent, aAny);
236 		}
237 	}
238 
239 	if (bSetDescription && bDescriptionOK)
240 	{
241 		Any aAny;
242 		aAny <<= sDescription;
243 		xPropertySet->setPropertyValue(sPropertyHint, aAny);
244 	}
245 
246     if (bSetHelp && bHelpOK)
247     {
248 		Any aAny;
249 		aAny <<= sHelp;
250 		xPropertySet->setPropertyValue(sPropertyHelp, aAny);
251     }
252 
253     if (bSetHint && bHintOK)
254     {
255 		Any aAny;
256 		aAny <<= sHint;
257 		xPropertySet->setPropertyValue(sPropertyTooltip, aAny);
258     }
259 
260 	if (bSetVisible && bDisplayOK)
261 	{
262 		Any aAny;
263 		sal_Bool bTmp = ! (bDisplayNone && bDisplayOK);
264 		aAny.setValue( &bTmp, ::getBooleanCppuType());
265 		xPropertySet->setPropertyValue(sPropertyIsVisible, aAny);
266 	}
267 
268 	// workaround for #no-bug#: display formula by default
269 	if (xPropertySet->getPropertySetInfo()->
270 				hasPropertyByName(sPropertyIsDisplayFormula) &&
271 		!bSetDisplayFormula)
272 	{
273 		bDisplayFormula = sal_False;
274 		bSetDisplayFormula = sal_True;
275 	}
276 
277 
278 	if (bSetDisplayFormula)
279 	{
280 		Any aAny;
281 		sal_Bool bTmp = bDisplayFormula && bDisplayOK;
282 		aAny.setValue( &bTmp, ::getBooleanCppuType());
283 		xPropertySet->setPropertyValue(sPropertyIsDisplayFormula, aAny);
284 	}
285 
286 	// delegate to value helper
287 	aValueHelper.SetDefault(GetContent());
288 	aValueHelper.PrepareField(xPropertySet);
289 
290 	// finally, set the curren presentation
291 	if (bSetPresentation)
292 	{
293 		Any aAny;
294 		aAny <<= GetContent();
295 		xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
296 	}
297 }
298 
299 
300 
301 
302 
303 //
304 // variable set fields
305 //
306 
307 TYPEINIT1( XMLSetVarFieldImportContext, XMLVarFieldImportContext );
308 
309 XMLSetVarFieldImportContext::XMLSetVarFieldImportContext(
310 	SvXMLImport& rImport, XMLTextImportHelper& rHlp,
311 	const sal_Char* pServiceName, sal_uInt16 nPrfx,
312 	const OUString& rLocalName, VarType eVarType,
313 	sal_Bool bName, sal_Bool bFormula, sal_Bool bFormulaDefault,
314 	sal_Bool bDescription, sal_Bool bHelp, sal_Bool bHint, sal_Bool bVisible, sal_Bool bIsDisplayFormula,
315 	sal_Bool bType, sal_Bool bStyle, sal_Bool bValue, sal_Bool bPresentation) :
316 		XMLVarFieldImportContext(rImport, rHlp, pServiceName,
317 								 nPrfx, rLocalName,
318 								 bName, bFormula, bFormulaDefault,
319 								 bDescription, bHelp, bHint, bVisible, bIsDisplayFormula,
320 								 bType, bStyle, bValue, bPresentation),
321 		eFieldType(eVarType)
322 {
323 }
324 
325 void XMLSetVarFieldImportContext::EndElement()
326 {
327 	// should we call PrepareField on the field, or rather on it's master?
328 	// currently: call on field (just like superclass)
329 	// possible alternatives: call on master
330 	// 						  call field or master depending on variable
331 	//						  PrepareMaster() in addition to PrepareField()
332 
333 	DBG_ASSERT(GetServiceName().getLength()>0, "no service name for element!");
334 
335 	if (bValid)
336 	{
337 		DBG_ASSERT(GetName().getLength()>0, "variable name needed!");
338 
339 		// find field master
340 		Reference<XPropertySet> xMaster;
341 		if (FindFieldMaster(xMaster))
342 		{
343 			// create field/Service
344 			Reference<XPropertySet> xPropSet;
345 			if (CreateField(xPropSet, OUString::createFromAscii(sAPI_textfield_prefix) + GetServiceName()))
346 			{
347 				Reference<XDependentTextField> xDepTextField(xPropSet, UNO_QUERY);
348 				if (xDepTextField.is())
349 				{
350 					// attach field to field master
351 					xDepTextField->attachTextFieldMaster(xMaster);
352 
353 					// attach field to document
354 					Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
355 					if (xTextContent.is())
356 					{
357 						try {
358 						// insert, set field properties and exit!
359 						GetImportHelper().InsertTextContent(xTextContent);
360 						PrepareField(xPropSet);
361 						} catch (lang::IllegalArgumentException & /*e*/)
362 						{
363 							// ignore e: #i54023#
364 						};
365 						return;
366 					}
367 				}
368 			}
369 		}
370 	}
371 
372 	// above: exit on success; so for all error cases we end up here!
373 	// write element content
374 	GetImportHelper().InsertString(GetContent());
375 }
376 
377 sal_Bool XMLSetVarFieldImportContext::FindFieldMaster(
378 	Reference<XPropertySet> & xMaster)
379 {
380 	// currently: delegate to XMLVariableDeclImportContext;
381 	// shoud eventually go here
382 	return XMLVariableDeclImportContext::FindFieldMaster(xMaster,
383 														 GetImport(),
384 														 GetImportHelper(),
385 														 GetName(),
386 														 eFieldType);
387 }
388 
389 
390 
391 //
392 // sequence field
393 //
394 
395 TYPEINIT1( XMLSequenceFieldImportContext, XMLSetVarFieldImportContext );
396 
397 XMLSequenceFieldImportContext::XMLSequenceFieldImportContext(
398 	SvXMLImport& rImport, XMLTextImportHelper& rHlp,
399 	sal_uInt16 nPrfx, const OUString& rLocalName) :
400 		XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression,
401 									nPrfx, rLocalName, VarTypeSequence,
402 									// name, formula
403 									sal_True, sal_True, sal_True,
404 									sal_False, sal_False, sal_False, sal_False,
405                                     sal_False,
406 									sal_False, sal_False, sal_False, sal_True),
407 
408 		sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)),
409 		sPropertySequenceValue(RTL_CONSTASCII_USTRINGPARAM(sAPI_sequence_value)),
410 		sNumFormat(OUString::valueOf(sal_Unicode('1'))),
411 		sNumFormatSync(GetXMLToken(XML_FALSE)),
412 		bRefNameOK(sal_False)
413 {
414 }
415 
416 void XMLSequenceFieldImportContext::ProcessAttribute(
417 	sal_uInt16 nAttrToken, const OUString& sAttrValue )
418 {
419 	switch (nAttrToken)
420 	{
421 		case XML_TOK_TEXTFIELD_NUM_FORMAT:
422 			sNumFormat = sAttrValue;
423 			break;
424 		case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
425 			sNumFormatSync = sAttrValue;
426 			break;
427 		case XML_TOK_TEXTFIELD_REF_NAME:
428 			sRefName = sAttrValue;
429 			bRefNameOK = sal_True;
430 			break;
431 		default:
432 			// delegate to super class (name, formula)
433 			XMLSetVarFieldImportContext::ProcessAttribute(nAttrToken,
434 														  sAttrValue);
435 			break;
436 	} // switch
437 }
438 
439 void XMLSequenceFieldImportContext::PrepareField(
440 	const Reference<XPropertySet> & xPropertySet)
441 {
442 	// delegate to super class (formula)
443 	XMLSetVarFieldImportContext::PrepareField(xPropertySet);
444 
445 	// set format
446 	sal_Int16 nNumType = NumberingType::ARABIC;
447 	GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, sNumFormat, sNumFormatSync );
448 	Any aAny;
449 	aAny <<= nNumType;
450 	xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
451 
452 	// handle reference name
453 	if (bRefNameOK)
454 	{
455 		aAny = xPropertySet->getPropertyValue(sPropertySequenceValue);
456 		sal_Int16 nValue = 0;
457 		aAny >>= nValue;
458 		GetImportHelper().InsertSequenceID(sRefName, GetName(), nValue);
459 	}
460 }
461 
462 
463 
464 //
465 // variable set field
466 //
467 
468 TYPEINIT1( XMLVariableSetFieldImportContext, XMLSetVarFieldImportContext );
469 
470 XMLVariableSetFieldImportContext::XMLVariableSetFieldImportContext(
471 	SvXMLImport& rImport, XMLTextImportHelper& rHlp,
472 	sal_uInt16 nPrfx, const OUString& rLocalName) :
473 		XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression,
474 									nPrfx, rLocalName, VarTypeSimple,
475 									// name, formula, value&type, style,
476 									// display none
477 									sal_True, sal_True, sal_True,
478 									sal_False, sal_False, sal_False,
479                                     sal_True, sal_False,
480 									sal_True, sal_True, sal_True,
481 									sal_True),
482 		sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
483 {
484 }
485 
486 void XMLVariableSetFieldImportContext::PrepareField(
487 		const Reference<XPropertySet> & xPropertySet)
488 {
489 	// set type
490 	Any aAny;
491 	aAny <<= (IsStringValue()? SetVariableType::STRING : SetVariableType::VAR);
492 	xPropertySet->setPropertyValue(sPropertySubType, aAny);
493 
494 	// the remainder is handled by super class
495 	XMLSetVarFieldImportContext::PrepareField(xPropertySet);
496 }
497 
498 
499 
500 //
501 // variable input field
502 //
503 
504 TYPEINIT1( XMLVariableInputFieldImportContext, XMLSetVarFieldImportContext );
505 
506 XMLVariableInputFieldImportContext::XMLVariableInputFieldImportContext(
507 	SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
508 	const OUString& rLocalName) :
509 		XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression,
510 									nPrfx, rLocalName, VarTypeSimple,
511 									// name, description, display none/formula,
512 									// value&type, style, formula
513 									sal_True, sal_True, sal_True,
514 									sal_True, sal_True, sal_True,
515                                     sal_True, sal_False,
516 									sal_True, sal_True, sal_True,
517 									sal_True),
518 		sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)),
519 		sPropertyIsInput(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_input))
520 {
521 }
522 
523 void XMLVariableInputFieldImportContext::PrepareField(
524 		const Reference<XPropertySet> & xPropertySet)
525 {
526 	// set type (input field)
527 	Any aAny;
528 	sal_Bool bTrue = sal_True;
529 	aAny.setValue( &bTrue, ::getBooleanCppuType() );
530 	xPropertySet->setPropertyValue(sPropertyIsInput, aAny);
531 
532 	// set type
533 	aAny <<= (IsStringValue()? SetVariableType::STRING : SetVariableType::VAR);
534 	xPropertySet->setPropertyValue(sPropertySubType, aAny);
535 
536 	// the remainder is handled by super class
537 	XMLSetVarFieldImportContext::PrepareField(xPropertySet);
538 }
539 
540 
541 
542 //
543 // user field
544 //
545 
546 TYPEINIT1( XMLUserFieldImportContext, XMLSetVarFieldImportContext );
547 
548 XMLUserFieldImportContext::XMLUserFieldImportContext(
549 	SvXMLImport& rImport, XMLTextImportHelper& rHlp,
550 	sal_uInt16 nPrfx, const OUString& rLocalName) :
551 		XMLSetVarFieldImportContext(rImport, rHlp, sAPI_user, nPrfx,
552 									rLocalName, VarTypeUserField,
553 									// name, display none/formula, style
554 									sal_True, sal_False, sal_False,
555 									sal_False, sal_False, sal_False, sal_True,
556                                     sal_True,
557 									sal_False, sal_True, sal_False,
558 									sal_False)
559 {
560 }
561 
562 
563 
564 //
565 // user input field
566 //
567 
568 TYPEINIT1( XMLUserFieldInputImportContext, XMLVarFieldImportContext );
569 
570 // bug: doesn't work (SO API lacking)
571 XMLUserFieldInputImportContext::XMLUserFieldInputImportContext(
572 	SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
573 	const OUString& rLocalName) :
574 		XMLVarFieldImportContext(rImport, rHlp, sAPI_input_user,
575 								 nPrfx, rLocalName,
576 								 // name, description, style
577 								 sal_True, sal_False, sal_False,
578                                  sal_True, sal_False, sal_False,
579 								 sal_False, sal_False,
580 								 sal_False /*???*/, sal_True, sal_False,
581 								 sal_False)
582 {
583 }
584 
585 void XMLUserFieldInputImportContext::PrepareField(
586 	const Reference<XPropertySet> & xPropertySet)
587 {
588 	Any aAny;
589 	aAny <<= GetName();
590 	xPropertySet->setPropertyValue(sPropertyContent, aAny);
591 
592 	// delegate to super class
593 	XMLVarFieldImportContext::PrepareField(xPropertySet);
594 }
595 
596 
597 //
598 // variable get field
599 //
600 
601 TYPEINIT1( XMLVariableGetFieldImportContext, XMLVarFieldImportContext );
602 
603 XMLVariableGetFieldImportContext::XMLVariableGetFieldImportContext(
604 	SvXMLImport& rImport, XMLTextImportHelper& rHlp,
605 	sal_uInt16 nPrfx, const OUString& rLocalName) :
606 		XMLVarFieldImportContext(rImport, rHlp, sAPI_get_expression,
607 								 nPrfx, rLocalName,
608 								 // name, style, display formula
609 								 sal_True, sal_False, sal_False,
610 								 sal_False, sal_False, sal_False,
611                                  sal_False, sal_True,
612 								 sal_True, sal_True, sal_False,
613 								 sal_True),
614 		sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
615 {
616 }
617 
618 void XMLVariableGetFieldImportContext::PrepareField(
619 		const Reference<XPropertySet> & xPropertySet)
620 {
621 	// set name
622   	Any aAny;
623 	aAny <<= GetName();
624 	xPropertySet->setPropertyValue(sPropertyContent, aAny);
625 
626 	// the remainder is handled by super class
627 	XMLVarFieldImportContext::PrepareField(xPropertySet);
628 }
629 
630 
631 
632 //
633 // expression field
634 //
635 
636 TYPEINIT1( XMLExpressionFieldImportContext, XMLVarFieldImportContext );
637 
638 XMLExpressionFieldImportContext::XMLExpressionFieldImportContext(
639 	SvXMLImport& rImport, XMLTextImportHelper& rHlp,
640 	sal_uInt16 nPrfx, const OUString& rLocalName) :
641 		XMLVarFieldImportContext(rImport, rHlp, sAPI_get_expression,
642 								 nPrfx, rLocalName,
643 								 // formula, type, style, display formula
644 								 sal_False, sal_True, sal_True,
645 								 sal_False, sal_False, sal_False,
646                                  sal_False, sal_True,
647 								 sal_True, sal_True, sal_False,
648 								 sal_True),
649 		sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
650 {
651 	bValid = sal_True;	// always valid
652 }
653 
654 
655 void XMLExpressionFieldImportContext::PrepareField(
656 	const Reference<XPropertySet> & xPropertySet)
657 {
658 	sal_Int16 nSubType = SetVariableType::FORMULA;
659 	Any aAny;
660 	aAny <<= nSubType;
661 	xPropertySet->setPropertyValue(sPropertySubType, aAny);
662 
663 	// delegate to super class
664 	XMLVarFieldImportContext::PrepareField(xPropertySet);
665 }
666 
667 
668 
669 //
670 // text input field
671 //
672 
673 TYPEINIT1( XMLTextInputFieldImportContext, XMLVarFieldImportContext );
674 
675 XMLTextInputFieldImportContext::XMLTextInputFieldImportContext(
676 	SvXMLImport& rImport, XMLTextImportHelper& rHlp,
677 	sal_uInt16 nPrfx, const OUString& sLocalName) :
678 		XMLVarFieldImportContext(rImport, rHlp, sAPI_input,
679 								 nPrfx, sLocalName,
680 								 // description
681 								 sal_False, sal_False, sal_False,
682 								 sal_True, sal_True, sal_True,
683                                  sal_False, sal_False,
684 								 sal_False, sal_False, sal_False,
685 								 sal_False),
686 		sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content))
687 {
688 	bValid = sal_True;	// always valid
689 }
690 
691 void XMLTextInputFieldImportContext::PrepareField(
692 	const Reference<XPropertySet> & xPropertySet)
693 {
694 	XMLVarFieldImportContext::PrepareField(xPropertySet);
695 
696 	Any aAny;
697 	aAny <<= GetContent();
698 	xPropertySet->setPropertyValue(sPropertyContent, aAny);
699 }
700 
701 
702 //
703 // table formula field
704 //
705 
706 TYPEINIT1( XMLTableFormulaImportContext, XMLTextFieldImportContext );
707 
708 XMLTableFormulaImportContext::XMLTableFormulaImportContext(
709     SvXMLImport& rImport,
710     XMLTextImportHelper& rHlp,
711     sal_uInt16 nPrfx,
712     const OUString& rLocalName) :
713         XMLTextFieldImportContext(rImport, rHlp, sAPI_table_formula,
714                                   nPrfx, rLocalName),
715         sPropertyIsShowFormula(RTL_CONSTASCII_USTRINGPARAM("IsShowFormula")),
716         sPropertyCurrentPresentation(
717             RTL_CONSTASCII_USTRINGPARAM("CurrentPresentation")),
718         aValueHelper(rImport, rHlp, sal_False, sal_True, sal_False, sal_True),
719         sFormula(),
720         bIsShowFormula(sal_False)
721 {
722 }
723 
724 XMLTableFormulaImportContext::~XMLTableFormulaImportContext()
725 {
726 }
727 
728 void XMLTableFormulaImportContext::ProcessAttribute(
729     sal_uInt16 nAttrToken,
730     const OUString& sAttrValue )
731 {
732     switch (nAttrToken)
733     {
734         case XML_TOK_TEXTFIELD_FORMULA:
735             aValueHelper.ProcessAttribute( nAttrToken, sAttrValue );
736             bValid = sal_True;  // we need a formula!
737             break;
738 
739         case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
740             aValueHelper.ProcessAttribute( nAttrToken, sAttrValue );
741             break;
742         case XML_TOK_TEXTFIELD_DISPLAY:
743             if ( sAttrValue.equalsAsciiL(
744                 RTL_CONSTASCII_STRINGPARAM("formula")) )
745                  bIsShowFormula = sal_True;
746             break;
747         default:
748             // unknown attribute -> ignore
749             break;
750     }
751 }
752 
753 void XMLTableFormulaImportContext::PrepareField(
754     const Reference<XPropertySet> & xPropertySet)
755 {
756     // set format and formula
757     aValueHelper.PrepareField( xPropertySet );
758 
759     Any aAny;
760 
761     // set 'show formula' and presentation
762     aAny.setValue( &bIsShowFormula, ::getBooleanCppuType() );
763     xPropertySet->setPropertyValue( sPropertyIsShowFormula, aAny );
764 
765 	aAny <<= GetContent();
766 	xPropertySet->setPropertyValue( sPropertyCurrentPresentation, aAny );
767 }
768 
769 
770 
771 //
772 // variable declarations
773 //
774 // Should be adapted to XMLVarField-/XMLSetVarFieldImportContext scheme!
775 //
776 
777 
778 
779 //
780 // declaration containter import (<variable/user-field/sequence-decls>)
781 //
782 
783 TYPEINIT1( XMLVariableDeclsImportContext, SvXMLImportContext );
784 
785 XMLVariableDeclsImportContext::XMLVariableDeclsImportContext(
786 	SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
787 	const OUString& rLocalName,	enum VarType eVarType) :
788 		SvXMLImportContext(rImport, nPrfx, rLocalName),
789 		eVarDeclsContextType(eVarType),
790 		rImportHelper(rHlp)
791 {
792 }
793 
794 SvXMLImportContext* XMLVariableDeclsImportContext::CreateChildContext(
795 	sal_uInt16 nPrefix, const OUString& rLocalName,
796 	const Reference<xml::sax::XAttributeList> & xAttrList )
797 {
798 	enum XMLTokenEnum eElementName;
799 	SvXMLImportContext* pImportContext = NULL;
800 
801 	if( XML_NAMESPACE_TEXT == nPrefix )
802     {
803 		switch (eVarDeclsContextType)
804         {
805             case VarTypeSequence:
806                 eElementName = XML_SEQUENCE_DECL;
807                 break;
808             case VarTypeSimple:
809                 eElementName = XML_VARIABLE_DECL;
810                 break;
811             case VarTypeUserField:
812                 eElementName = XML_USER_FIELD_DECL;
813                 break;
814             default:
815                 DBG_ERROR("unknown field type!");
816                 eElementName = XML_SEQUENCE_DECL;
817 				break;
818         }
819 
820 		if( IsXMLToken( rLocalName, eElementName ) )
821         {
822 			pImportContext = new XMLVariableDeclImportContext(
823 				GetImport(), rImportHelper, nPrefix, rLocalName, xAttrList,
824 				eVarDeclsContextType);
825 		}
826 	}
827 
828 	// if no context was created, use default context
829 	if (NULL == pImportContext) {
830 		pImportContext = SvXMLImportContext::CreateChildContext(nPrefix,
831 																rLocalName,
832 																xAttrList);
833 	}
834 
835 	return pImportContext;
836 }
837 
838 
839 
840 //
841 // declaration import (<variable/user-field/sequence-decl> elements)
842 //
843 
844 TYPEINIT1( XMLVariableDeclImportContext, SvXMLImportContext );
845 
846 XMLVariableDeclImportContext::XMLVariableDeclImportContext(
847 	SvXMLImport& rImport, XMLTextImportHelper& rHlp,
848 	sal_uInt16 nPrfx, const OUString& rLocalName,
849 	const Reference<xml::sax::XAttributeList> & xAttrList,
850 	enum VarType eVarType) :
851 		SvXMLImportContext(rImport, nPrfx, rLocalName),
852 		// bug?? which properties for userfield/userfieldmaster
853 		sPropertyName(RTL_CONSTASCII_USTRINGPARAM(sAPI_name)),
854 		sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)),
855 		sPropertyNumberingLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_chapter_numbering_level)),
856 		sPropertyNumberingSeparator(RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_separator)),
857 		sPropertyIsExpression(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_expression)),
858 		aValueHelper(rImport, rHlp, sal_True, sal_False, sal_True, sal_False),
859 		nNumLevel(-1), cSeparationChar('.')
860 {
861 	if ( (XML_NAMESPACE_TEXT == nPrfx) &&
862 		 ( ( IsXMLToken( rLocalName, XML_SEQUENCE_DECL )) ||
863 		   ( IsXMLToken( rLocalName, XML_VARIABLE_DECL)) ||
864 		   ( IsXMLToken( rLocalName, XML_USER_FIELD_DECL))    )) {
865 
866 		// TODO: check validity (need name!)
867 
868 		// parse attributes
869 		sal_Int16 nLength = xAttrList->getLength();
870 		for(sal_Int16 i=0; i<nLength; i++) {
871 
872 			OUString sLocalName;
873 			sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
874 				GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
875 
876 			sal_uInt16 nToken = rHlp.
877 				GetTextFieldAttrTokenMap().Get(nPrefix, sLocalName);
878 
879 			switch (nToken)
880 			{
881 				case XML_TOK_TEXTFIELD_NAME:
882 					sName = xAttrList->getValueByIndex(i);
883 					break;
884 				case XML_TOK_TEXTFIELD_NUMBERING_LEVEL:
885 				{
886 					sal_Int32 nLevel;
887 					sal_Bool bRet = SvXMLUnitConverter::convertNumber(
888 						nLevel, xAttrList->getValueByIndex(i), 0,
889 						GetImport().GetTextImport()->GetChapterNumbering()->
890 															   	getCount());
891 					if (bRet)
892 					{
893 						nNumLevel = static_cast< sal_Int8 >( nLevel-1 ); // API numbers -1..9
894 					}
895 					break;
896 				}
897 				case XML_TOK_TEXTFIELD_NUMBERING_SEPARATOR:
898 					cSeparationChar =
899 						(sal_Char)xAttrList->getValueByIndex(i).toChar();
900 					break;
901 
902 				default:
903 					// delegate to value helper
904 					aValueHelper.ProcessAttribute(nToken,
905 												  xAttrList->getValueByIndex(i));
906 					break;
907 			}
908 		}
909 
910 		Reference<XPropertySet> xFieldMaster;
911 		if (FindFieldMaster(xFieldMaster, GetImport(), rHlp,
912 							sName, eVarType))
913 		{
914 			// now we have a field master: process attributes!
915 			Any aAny;
916 
917 			switch (eVarType)
918 			{
919 			case VarTypeSequence:
920 				aAny <<= nNumLevel;
921 				xFieldMaster->setPropertyValue(sPropertyNumberingLevel, aAny);
922 
923 				if (nNumLevel >= 0)
924 				{
925 					OUString sStr(&cSeparationChar, 1);
926 					aAny <<= sStr;
927 					xFieldMaster->setPropertyValue(
928 						sPropertyNumberingSeparator, aAny);
929 				}
930 				break;
931 			case VarTypeSimple:
932                 {
933                     // set string or non-string SubType (#93192#)
934                     // The SubType was already set in the FindFieldMaster
935                     // method, but it needs to be adjusted if it's a string.
936                     aAny <<= aValueHelper.IsStringValue()
937                         ? SetVariableType::STRING : SetVariableType::VAR;
938                     xFieldMaster->setPropertyValue(sPropertySubType, aAny);
939                 }
940                 break;
941 			case VarTypeUserField:
942 			{
943 				sal_Bool bTmp = !aValueHelper.IsStringValue();
944 				aAny.setValue(&bTmp, ::getBooleanCppuType());
945 				xFieldMaster->setPropertyValue(sPropertyIsExpression, aAny);
946 				aValueHelper.PrepareField(xFieldMaster);
947 				break;
948 			}
949 			default:
950 				DBG_ERROR("unkown varfield type");
951 			} // switch
952 		} // else: no field master found/constructed
953 	} // else: no sequence-decl
954 }
955 
956 
957 
958 sal_Bool XMLVariableDeclImportContext::FindFieldMaster(
959 	Reference<XPropertySet> & xMaster, SvXMLImport& rImport,
960 	XMLTextImportHelper& rImportHelper,
961 	const OUString& sVarName, enum VarType eVarType)
962 {
963 	static sal_Int32 nCollisionCount = 0;
964 
965 	// rename field
966 	// currently: no family in use! Use 0.
967 	OUString sName = rImportHelper.GetRenameMap().Get(
968         sal::static_int_cast< sal_uInt16 >(eVarType), sVarName);
969 
970 	// get text fields supplier and field masters
971 	Reference<XTextFieldsSupplier> xTextFieldsSupp(rImport.GetModel(),
972 												   UNO_QUERY);
973 	Reference<container::XNameAccess> xFieldMasterNameAccess(
974 		xTextFieldsSupp->getTextFieldMasters(), UNO_QUERY);
975 
976 	OUStringBuffer sBuffer;
977 	sBuffer.appendAscii(sAPI_fieldmaster_prefix);
978 	sBuffer.appendAscii(sAPI_set_expression);
979 	sBuffer.appendAscii(".");
980 	sBuffer.append(sName);
981 	OUString sVarServiceName = sBuffer.makeStringAndClear();
982 
983 	sBuffer.appendAscii(sAPI_fieldmaster_prefix);
984 	sBuffer.appendAscii(sAPI_user);
985 	sBuffer.appendAscii(".");
986 	sBuffer.append(sName);
987 	OUString sUserServiceName = sBuffer.makeStringAndClear();
988 
989 	if (xFieldMasterNameAccess->hasByName(sVarServiceName)) {
990 		// variable field master already in document
991 
992 		Any aAny = xFieldMasterNameAccess->getByName(sVarServiceName);
993 		aAny >>= xMaster;
994 
995 		aAny = xMaster->getPropertyValue(
996 			// sPropertySubType
997 			OUString::createFromAscii(sAPI_sub_type)
998 			);
999 		sal_Int16 nType = 0;
1000 		aAny >>= nType;
1001 
1002 		enum VarType eFMVarType =
1003 			(SetVariableType::SEQUENCE == nType) ?
1004 				VarTypeSequence : VarTypeSimple;
1005 
1006 		if (eFMVarType != eVarType)
1007 		{
1008 			OUString sNew;
1009 
1010 			// FIXME! cant find if name is taken already!!!!
1011 
1012 			nCollisionCount++;
1013 			OUStringBuffer aBuf;
1014 			aBuf.append(sName);
1015 			aBuf.appendAscii("_renamed_");
1016 			aBuf.append(nCollisionCount);
1017 			sNew = aBuf.makeStringAndClear();
1018 
1019 			rImportHelper.GetRenameMap().Add(
1020                 sal::static_int_cast< sal_uInt16 >(eVarType), sName, sNew);
1021 
1022 			// call FindFieldMaster recursively to create new master
1023 			return FindFieldMaster(xMaster, rImport, rImportHelper,
1024 								   sNew, eVarType);
1025 		}
1026 	} else if (xFieldMasterNameAccess->hasByName(sUserServiceName)) {
1027 		// user field: get field master
1028 		Any aAny = xFieldMasterNameAccess->getByName(sUserServiceName);
1029 		aAny >>= xMaster;
1030 
1031 		if (VarTypeUserField != eVarType) {
1032 			// find new name that is not taken
1033 			OUString sNew;
1034 
1035 			// FIXME! cant find if name is taken already!!!!
1036 
1037 			nCollisionCount++;
1038 			OUStringBuffer aBuf;
1039 			aBuf.append(sName);
1040 			aBuf.appendAscii("_renamed_");
1041 			aBuf.append(nCollisionCount);
1042 			sNew = aBuf.makeStringAndClear();
1043 
1044 			rImportHelper.GetRenameMap().Add(
1045                 sal::static_int_cast< sal_uInt16 >(eVarType), sName, sNew);
1046 
1047 			// call FindFieldMaster recursively to create new master
1048 			return FindFieldMaster(xMaster, rImport, rImportHelper,
1049 								   sNew, eVarType);
1050 		}
1051 	} else {
1052 		// field name not used: create field master
1053 
1054 		// import -> model is MultiServiceFactory -> createInstance
1055 		Reference<lang::XMultiServiceFactory>
1056 			xFactory(rImport.GetModel(),UNO_QUERY);
1057 		if( xFactory.is() )	{
1058 
1059 			OUStringBuffer sService;
1060 			sService.appendAscii(sAPI_fieldmaster_prefix);
1061 			sService.appendAscii((eVarType==VarTypeUserField) ?
1062 								 sAPI_user : sAPI_set_expression);
1063 			Reference<XInterface> xIfc =
1064 				xFactory->createInstance( sService.makeStringAndClear() );
1065 			if (xIfc.is()) {
1066 				Reference<XPropertySet> xTmp( xIfc, UNO_QUERY );
1067 				xMaster = xTmp;
1068 
1069 				// set name
1070 				Any aAny;
1071 				aAny <<= sName;
1072 				xMaster->setPropertyValue(
1073 					// sPropertyName
1074 					OUString::createFromAscii(sAPI_name)
1075 					, aAny);
1076 
1077 				if (eVarType != VarTypeUserField) {
1078 					// set subtype for setexp field
1079 
1080 					aAny <<= ((eVarType == VarTypeSimple) ?
1081 							  SetVariableType::VAR :
1082 							  SetVariableType::SEQUENCE);
1083 					xMaster->setPropertyValue(
1084 						// sPropertySubType
1085 						OUString::createFromAscii(sAPI_sub_type)
1086 						, aAny);
1087 				} // else : user field: no subtype
1088 
1089 			} else {
1090 				return sal_False;
1091 			}
1092 		} else {
1093 			return sal_False;
1094 		}
1095 	}
1096 
1097 	DBG_ASSERT(xMaster.is(), "no field master found!?!");
1098 	return sal_True;
1099 }
1100 
1101 
1102 //
1103 // Database Display field import
1104 //
1105 
1106 
1107 TYPEINIT1( XMLDatabaseDisplayImportContext, XMLDatabaseFieldImportContext );
1108 
1109 XMLDatabaseDisplayImportContext::XMLDatabaseDisplayImportContext(
1110 	SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
1111 	const OUString& rLocalName) :
1112 		XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database,
1113 									  nPrfx, rLocalName, false),
1114 		sPropertyColumnName(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_column_name)),
1115 		sPropertyDatabaseFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_data_base_format)),
1116 		sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)),
1117         sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_visible)),
1118 		aValueHelper(rImport, rHlp, sal_False, sal_True, sal_False, sal_False),
1119 		bColumnOK(sal_False),
1120         bDisplay( sal_True ),
1121         bDisplayOK( sal_False )
1122 {
1123 }
1124 
1125 void XMLDatabaseDisplayImportContext::ProcessAttribute(
1126 	sal_uInt16 nAttrToken, const OUString& sAttrValue )
1127 {
1128 	switch (nAttrToken)
1129 	{
1130 		case XML_TOK_TEXTFIELD_COLUMN_NAME:
1131 			sColumnName = sAttrValue;
1132 			bColumnOK = sal_True;
1133 			break;
1134         case XML_TOK_TEXTFIELD_DISPLAY:
1135             {
1136                 sal_Bool bNone = IsXMLToken( sAttrValue, XML_NONE );
1137                 sal_Bool bValue = IsXMLToken( sAttrValue, XML_VALUE );
1138                 bDisplay = bValue;
1139                 bDisplayOK = bNone || bValue;
1140             }
1141             break;
1142 		case XML_TOK_TEXTFIELD_DATABASE_NAME:
1143 		case XML_TOK_TEXTFIELD_TABLE_NAME:
1144         case XML_TOK_TEXTFIELD_TABLE_TYPE:
1145 			// handled by super class
1146 			XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1147 															sAttrValue);
1148 			break;
1149 		default:
1150 			// remainder handled by value helper
1151 			aValueHelper.ProcessAttribute(nAttrToken, sAttrValue);
1152 			break;
1153 	}
1154 
1155 	bValid = bTableOK && bDatabaseOK && bColumnOK;
1156 }
1157 
1158 void XMLDatabaseDisplayImportContext::EndElement()
1159 {
1160 	// we have an EndElement of our own, because database fields need
1161 	// to be attached to a field master before they can be inserted into
1162 	// the document. Database stuff (database, table, column) all goes
1163 	// to the field master, value & style go to the field.
1164 
1165 	if (bValid)
1166 	{
1167 
1168 		// so here goes: we start with the master
1169 		Reference<XPropertySet> xMaster;
1170 
1171 		// create and prepare field master first
1172 		if (CreateField(xMaster,
1173 						OUString(RTL_CONSTASCII_USTRINGPARAM(
1174 							sAPI_fieldmaster_database))))
1175 		{
1176 			Any aAny;
1177 			aAny <<= sColumnName;
1178 			xMaster->setPropertyValue(sPropertyColumnName, aAny);
1179 
1180 			// fieldmaster takes database, table and column name
1181 			XMLDatabaseFieldImportContext::PrepareField(xMaster);
1182 
1183 			// create field
1184 			Reference<XPropertySet> xField;
1185 			if (CreateField(xField,
1186 							OUString(RTL_CONSTASCII_USTRINGPARAM(
1187 								sAPI_database))))
1188 			{
1189 				// attach field master
1190 				Reference<XDependentTextField> xDepField(xField, UNO_QUERY);
1191 				if (xDepField.is())
1192 				{
1193 					// attach field to field master
1194 					xDepField->attachTextFieldMaster(xMaster);
1195 
1196 					// attach field to document
1197 					Reference<XTextContent> xTextContent(xField, UNO_QUERY);
1198 					if (xTextContent.is())
1199 					{
1200 						// insert, set field properties and exit!
1201 						GetImportHelper().InsertTextContent(xTextContent);
1202 
1203 						// prepare field: format from database?
1204 						sal_Bool bTmp = !aValueHelper.IsFormatOK();
1205 						aAny.setValue( &bTmp, ::getBooleanCppuType() );
1206 						xField->setPropertyValue(sPropertyDatabaseFormat,aAny);
1207 
1208 						// value, value-type and format done by value helper
1209 						aValueHelper.PrepareField(xField);
1210 
1211                         // visibility
1212                         if( bDisplayOK )
1213                         {
1214                             aAny.setValue( &bDisplay, ::getBooleanCppuType() );
1215                             xField->setPropertyValue(sPropertyIsVisible, aAny);
1216                         }
1217 
1218 						// set presentation
1219 						aAny <<= GetContent();
1220 						xField->setPropertyValue(sPropertyCurrentPresentation,
1221 													aAny);
1222 
1223 						// success!
1224 						return;
1225 					}
1226 				}
1227 			}
1228 		}
1229 	}
1230 
1231 	// above: exit on success; so for all error cases we end up here!
1232 	// write element content
1233 	GetImportHelper().InsertString(GetContent());
1234 }
1235 
1236 
1237 //
1238 // value import helper
1239 //
1240 
1241 enum ValueType
1242 {
1243 	XML_VALUE_TYPE_STRING,
1244 	XML_VALUE_TYPE_FLOAT,
1245 	XML_VALUE_TYPE_CURRENCY,
1246 	XML_VALUE_TYPE_PERCENTAGE,
1247 	XML_VALUE_TYPE_DATE,
1248 	XML_VALUE_TYPE_TIME,
1249 	XML_VALUE_TYPE_BOOLEAN
1250 };
1251 
1252 static SvXMLEnumMapEntry __READONLY_DATA aValueTypeMap[] =
1253 {
1254 	{ XML_FLOAT, 		XML_VALUE_TYPE_FLOAT },
1255 	{ XML_CURRENCY, 	XML_VALUE_TYPE_CURRENCY },
1256 	{ XML_PERCENTAGE, 	XML_VALUE_TYPE_PERCENTAGE },
1257 	{ XML_DATE, 		XML_VALUE_TYPE_DATE },
1258 	{ XML_TIME, 		XML_VALUE_TYPE_TIME },
1259 	{ XML_BOOLEAN, 	    XML_VALUE_TYPE_BOOLEAN },
1260 	{ XML_STRING, 		XML_VALUE_TYPE_STRING },
1261     { XML_TOKEN_INVALID, 0 }
1262 };
1263 
1264 XMLValueImportHelper::XMLValueImportHelper(
1265 	SvXMLImport& rImprt,
1266 	XMLTextImportHelper& rHlp,
1267 	sal_Bool bType, sal_Bool bStyle, sal_Bool bValue, sal_Bool bFormula) :
1268 		sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)),
1269 		sPropertyValue(RTL_CONSTASCII_USTRINGPARAM(sAPI_value)),
1270 		sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)),
1271         sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed_language)),
1272 
1273 		rImport(rImprt),
1274 		rHelper(rHlp),
1275 
1276 		fValue(0.0),
1277 		nFormatKey(0),
1278         bIsDefaultLanguage(sal_True),
1279 
1280 		bStringType(sal_False),
1281 		bFormatOK(sal_False),
1282 		bTypeOK(sal_False),
1283 		bStringValueOK(sal_False),
1284 		bFloatValueOK(sal_False),
1285 		bFormulaOK(sal_False),
1286 
1287 		bSetType(bType),
1288 		bSetValue(bValue),
1289 		bSetStyle(bStyle),
1290 		bSetFormula(bFormula),
1291 
1292 		bStringDefault(sal_True),
1293 		bFormulaDefault(sal_True)
1294 {
1295 }
1296 
1297 XMLValueImportHelper::~XMLValueImportHelper()
1298 {
1299 }
1300 
1301 void XMLValueImportHelper::ProcessAttribute(
1302 	sal_uInt16 nAttrToken, const OUString& sAttrValue )
1303 {
1304 	switch (nAttrToken)
1305 	{
1306 		case XML_TOK_TEXTFIELD_VALUE_TYPE:
1307 		{
1308 			// convert enum
1309 			sal_uInt16 nTmp = 0;
1310 			sal_Bool bRet = SvXMLUnitConverter::convertEnum(
1311 				nTmp, sAttrValue, aValueTypeMap);
1312 
1313 			if (bRet) {
1314 				ValueType eValueType = (ValueType)nTmp;
1315 
1316 				bTypeOK = sal_True;
1317 
1318 				switch (eValueType)
1319 				{
1320 					case XML_VALUE_TYPE_STRING:
1321 						bStringType = sal_True;
1322 						break;
1323 					case XML_VALUE_TYPE_FLOAT:
1324 					case XML_VALUE_TYPE_CURRENCY:
1325 					case XML_VALUE_TYPE_PERCENTAGE:
1326 					case XML_VALUE_TYPE_DATE:
1327 					case XML_VALUE_TYPE_TIME:
1328 					case XML_VALUE_TYPE_BOOLEAN:
1329 						bStringType = sal_False;
1330 						break;
1331 
1332 					default:
1333 						DBG_ERROR("unknown value type");
1334 						bTypeOK = sal_False;
1335 				}
1336 			}
1337 			break;
1338 		}
1339 
1340 		case XML_TOK_TEXTFIELD_VALUE:
1341 		{
1342 			double fTmp;
1343 			sal_Bool bRet = SvXMLUnitConverter::convertDouble(fTmp,sAttrValue);
1344 			if (bRet) {
1345 				bFloatValueOK = sal_True;
1346 				fValue = fTmp;
1347 			}
1348 			break;
1349 		}
1350 
1351 		case XML_TOK_TEXTFIELD_TIME_VALUE:
1352 		{
1353 			double fTmp;
1354 			sal_Bool bRet = SvXMLUnitConverter::convertTime(fTmp,sAttrValue);
1355 			if (bRet) {
1356 				bFloatValueOK = sal_True;
1357 				fValue = fTmp;
1358 			}
1359 			break;
1360 		}
1361 
1362 		case XML_TOK_TEXTFIELD_DATE_VALUE:
1363 		{
1364 			double fTmp;
1365 			sal_Bool bRet = rImport.GetMM100UnitConverter().
1366 				convertDateTime(fTmp,sAttrValue);
1367 			if (bRet) {
1368 				bFloatValueOK = sal_True;
1369 				fValue = fTmp;
1370 			}
1371 			break;
1372 		}
1373 
1374 		case XML_TOK_TEXTFIELD_BOOL_VALUE:
1375 		{
1376 			sal_Bool bTmp;
1377 			sal_Bool bRet = SvXMLUnitConverter::convertBool(bTmp,sAttrValue);
1378 			if (bRet) {
1379 				bFloatValueOK = sal_True;
1380 				fValue = (bTmp ? 1.0 : 0.0);
1381 			}
1382             else
1383             {
1384                 double fTmp;
1385                 bRet = SvXMLUnitConverter::convertDouble(fTmp,sAttrValue);
1386                 if (bRet) {
1387                     bFloatValueOK = sal_True;
1388                     fValue = fTmp;
1389                 }
1390             }
1391 			break;
1392 		}
1393 
1394 		case XML_TOK_TEXTFIELD_STRING_VALUE:
1395 			sValue = sAttrValue;
1396 			bStringValueOK = sal_True;
1397 			break;
1398 
1399 		case XML_TOK_TEXTFIELD_FORMULA:
1400 			{
1401 				OUString sTmp;
1402 				sal_uInt16 nPrefix = rImport.GetNamespaceMap().
1403 						_GetKeyByAttrName( sAttrValue, &sTmp, sal_False );
1404 				if( XML_NAMESPACE_OOOW == nPrefix )
1405 				{
1406 					sFormula = sTmp;
1407 					bFormulaOK = sal_True;
1408 				}
1409 				else
1410 					sFormula = sAttrValue;
1411 			}
1412 			break;
1413 
1414 		case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1415 		{
1416 			sal_Int32 nKey = rHelper.GetDataStyleKey(
1417 										  sAttrValue, &bIsDefaultLanguage);
1418 			if (-1 != nKey)
1419 			{
1420 				nFormatKey = nKey;
1421 				bFormatOK = sal_True;
1422 			}
1423 			break;
1424 		}
1425 	} // switch
1426 }
1427 
1428 void XMLValueImportHelper::PrepareField(
1429 	const Reference<XPropertySet> & xPropertySet)
1430 {
1431     Any aAny;
1432 
1433 	if (bSetType)
1434 	{
1435 		// ??? how to set type?
1436 	}
1437 
1438 	if (bSetFormula)
1439 	{
1440 		aAny <<= (!bFormulaOK && bFormulaDefault) ? sDefault : sFormula;
1441 		xPropertySet->setPropertyValue(sPropertyContent, aAny);
1442 	}
1443 
1444 	// format/style
1445 	if (bSetStyle && bFormatOK)
1446 	{
1447 		aAny <<= nFormatKey;
1448 		xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
1449 
1450         if( xPropertySet->getPropertySetInfo()->
1451                 hasPropertyByName( sPropertyIsFixedLanguage ) )
1452         {
1453             sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage;
1454             aAny.setValue( &bIsFixedLanguage, ::getBooleanCppuType() );
1455             xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny );
1456         }
1457 	}
1458 
1459 	// value: string or float
1460 	if (bSetValue)
1461 	{
1462 		if (bStringType)
1463 		{
1464 			aAny <<= (!bStringValueOK && bStringDefault) ? sDefault : sValue;
1465 			xPropertySet->setPropertyValue(sPropertyContent, aAny);
1466 		}
1467 		else
1468 		{
1469 			aAny <<= fValue;
1470 			xPropertySet->setPropertyValue(sPropertyValue, aAny);
1471 		}
1472 	}
1473 }
1474 
1475