Update ooo320-m1
[ooovba.git] / xmloff / source / text / txtvfldi.cxx
blobc419ee03835a3b1909199873abfb83a128690c32
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: txtvfldi.cxx,v $
10 * $Revision: 1.36 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 /** @#file
36 * export of all variable related text fields (and database display field)
38 #include "txtvfldi.hxx"
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/txtimp.hxx>
41 #include <xmloff/xmlnumi.hxx>
42 #include "xmlnmspe.hxx"
43 #include <xmloff/nmspmap.hxx>
44 #include "i18nmap.hxx"
45 #include <xmloff/xmlimp.hxx>
46 #include <xmloff/xmluconv.hxx>
47 #include <xmloff/xmlement.hxx>
48 #include <com/sun/star/text/SetVariableType.hpp>
49 #include <com/sun/star/text/XTextField.hpp>
50 #include <com/sun/star/text/XDependentTextField.hpp>
51 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
52 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <com/sun/star/beans/XPropertySetInfo.hpp>
54 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
55 #include <com/sun/star/xml/sax/XAttributeList.hpp>
57 #ifndef _RTL_USTRING
58 #include <rtl/ustring.hxx>
59 #endif
60 #include <tools/debug.hxx>
63 // service names
64 static const sal_Char sAPI_textfield_prefix[] = "com.sun.star.text.TextField.";
65 static const sal_Char sAPI_fieldmaster_prefix[] = "com.sun.star.text.FieldMaster.";
66 static const sal_Char sAPI_input[] = "Input";
67 static const sal_Char sAPI_input_user[] = "InputUser";
68 static const sal_Char sAPI_get_expression[] = "GetExpression";
69 static const sal_Char sAPI_set_expression[] = "SetExpression";
70 static const sal_Char sAPI_user[] = "User";
71 static const sal_Char sAPI_table_formula[] = "TableFormula";
72 static const sal_Char sAPI_database[] = "com.sun.star.text.TextField.Database";
73 static const sal_Char sAPI_fieldmaster_database[] = "com.sun.star.text.FieldMaster.Database";
75 // property names
76 static const sal_Char sAPI_hint[] = "Hint";
77 static const sal_Char sAPI_help[] = "Help";
78 static const sal_Char sAPI_tooltip[] = "Tooltip";
79 static const sal_Char sAPI_content[] = "Content";
80 static const sal_Char sAPI_sub_type[] = "SubType";
81 static const sal_Char sAPI_is_expression[] = "IsExpression";
82 static const sal_Char sAPI_is_input[] = "Input";
83 static const sal_Char sAPI_is_show_formula[] = "IsShowFormula";
84 static const sal_Char sAPI_numbering_type[] = "NumberingType";
85 static const sal_Char sAPI_number_format[] = "NumberFormat";
86 static const sal_Char sAPI_name[] = "Name";
87 static const sal_Char sAPI_numbering_separator[] = "NumberingSeparator";
88 static const sal_Char sAPI_chapter_numbering_level[]= "ChapterNumberingLevel";
89 static const sal_Char sAPI_value[] = "Value";
90 static const sal_Char sAPI_is_visible[] = "IsVisible";
91 static const sal_Char sAPI_variable_subtype[] = "VariableSubtype";
92 static const sal_Char sAPI_data_column_name[] = "DataColumnName";
93 static const sal_Char sAPI_is_data_base_format[] = "DataBaseFormat";
94 static const sal_Char sAPI_current_presentation[] = "CurrentPresentation";
95 static const sal_Char sAPI_sequence_value[] = "SequenceValue";
96 static const sal_Char sAPI_is_fixed_language[] = "IsFixedLanguage";
99 using ::rtl::OUString;
100 using ::rtl::OUStringBuffer;
102 using namespace ::com::sun::star;
103 using namespace ::com::sun::star::uno;
104 using namespace ::com::sun::star::beans;
105 using namespace ::com::sun::star::text;
106 using namespace ::com::sun::star::style;
107 using namespace ::xmloff::token;
112 // XMLVarFieldImportContext: superclass for all variable related fields
115 TYPEINIT1( XMLVarFieldImportContext, XMLTextFieldImportContext );
117 XMLVarFieldImportContext::XMLVarFieldImportContext(
118 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
119 const sal_Char* pServiceName, sal_uInt16 nPrfx,
120 const OUString& rLocalName,
121 sal_Bool bName, sal_Bool bFormula, sal_Bool bFormulaDefault,
122 sal_Bool bDescription, sal_Bool bHelp, sal_Bool bHint, sal_Bool bVisible,
123 sal_Bool bIsDisplayFormula,
124 sal_Bool bType, sal_Bool bStyle, sal_Bool bValue,
125 sal_Bool bPresentation) :
126 XMLTextFieldImportContext(rImport, rHlp, pServiceName, nPrfx, rLocalName),
127 sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)),
128 sPropertyHint(RTL_CONSTASCII_USTRINGPARAM(sAPI_hint)),
129 sPropertyHelp(RTL_CONSTASCII_USTRINGPARAM(sAPI_help)),
130 sPropertyTooltip(RTL_CONSTASCII_USTRINGPARAM(sAPI_tooltip)),
131 sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_visible)),
132 sPropertyIsDisplayFormula(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_show_formula)),
133 sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)),
134 aValueHelper(rImport, rHlp, bType, bStyle, bValue, sal_False),
135 bDisplayFormula(sal_False),
136 bDisplayNone(sal_False),
137 bNameOK(sal_False),
138 bFormulaOK(sal_False),
139 bDescriptionOK(sal_False),
140 bHelpOK(sal_False),
141 bHintOK(sal_False),
142 bDisplayOK(sal_False),
143 bSetName(bName),
144 bSetFormula(bFormula),
145 bSetFormulaDefault(bFormulaDefault),
146 bSetDescription(bDescription),
147 bSetHelp(bHelp),
148 bSetHint(bHint),
149 bSetVisible(bVisible),
150 bSetDisplayFormula(bIsDisplayFormula),
151 bSetPresentation(bPresentation)
155 void XMLVarFieldImportContext::ProcessAttribute(
156 sal_uInt16 nAttrToken,
157 const OUString& sAttrValue )
159 switch (nAttrToken)
161 case XML_TOK_TEXTFIELD_NAME:
162 sName = sAttrValue;
163 bNameOK = sal_True;
164 bValid = sal_True; // we assume: field with name is valid!
165 break;
166 case XML_TOK_TEXTFIELD_DESCRIPTION:
167 sDescription = sAttrValue;
168 bDescriptionOK = sal_True;
169 break;
170 case XML_TOK_TEXTFIELD_HELP:
171 sHelp = sAttrValue;
172 bHelpOK = true;
173 break;
174 case XML_TOK_TEXTFIELD_HINT:
175 sHint = sAttrValue;
176 bHintOK = true;
177 break;
178 case XML_TOK_TEXTFIELD_FORMULA:
180 OUString sTmp;
181 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
182 _GetKeyByAttrName( sAttrValue, &sTmp, sal_False );
183 if( XML_NAMESPACE_OOOW == nPrefix )
185 sFormula = sTmp;
186 bFormulaOK = sal_True;
188 else
189 sFormula = sAttrValue;
191 break;
192 case XML_TOK_TEXTFIELD_DISPLAY:
193 if (IsXMLToken(sAttrValue, XML_FORMULA))
195 bDisplayFormula = sal_True;
196 bDisplayNone = sal_False;
197 bDisplayOK = sal_True;
199 else if (IsXMLToken(sAttrValue, XML_VALUE))
201 bDisplayFormula = sal_False;
202 bDisplayNone = sal_False;
203 bDisplayOK = sal_True;
205 else if (IsXMLToken(sAttrValue, XML_NONE))
207 bDisplayFormula = sal_False;
208 bDisplayNone = sal_True;
209 bDisplayOK = sal_True;
210 } // else: no change
211 DBG_ASSERT(!(bDisplayFormula && bDisplayNone),
212 "illegal display values");
213 break;
214 default:
215 // delegate all others to value helper
216 aValueHelper.ProcessAttribute(nAttrToken, sAttrValue);
217 break;
221 void XMLVarFieldImportContext::PrepareField(
222 const Reference<XPropertySet> & xPropertySet)
224 // bSetName: not implemented
226 if (bSetFormula)
228 if (!bFormulaOK && bSetFormulaDefault)
230 sFormula = GetContent();
231 bFormulaOK = sal_True;
234 if (bFormulaOK)
236 Any aAny;
237 aAny <<= sFormula;
238 xPropertySet->setPropertyValue(sPropertyContent, aAny);
242 if (bSetDescription && bDescriptionOK)
244 Any aAny;
245 aAny <<= sDescription;
246 xPropertySet->setPropertyValue(sPropertyHint, aAny);
249 if (bSetHelp && bHelpOK)
251 Any aAny;
252 aAny <<= sHelp;
253 xPropertySet->setPropertyValue(sPropertyHelp, aAny);
256 if (bSetHint && bHintOK)
258 Any aAny;
259 aAny <<= sHint;
260 xPropertySet->setPropertyValue(sPropertyTooltip, aAny);
263 if (bSetVisible && bDisplayOK)
265 Any aAny;
266 sal_Bool bTmp = ! (bDisplayNone && bDisplayOK);
267 aAny.setValue( &bTmp, ::getBooleanCppuType());
268 xPropertySet->setPropertyValue(sPropertyIsVisible, aAny);
271 // workaround for #no-bug#: display formula by default
272 if (xPropertySet->getPropertySetInfo()->
273 hasPropertyByName(sPropertyIsDisplayFormula) &&
274 !bSetDisplayFormula)
276 bDisplayFormula = sal_False;
277 bSetDisplayFormula = sal_True;
281 if (bSetDisplayFormula)
283 Any aAny;
284 sal_Bool bTmp = bDisplayFormula && bDisplayOK;
285 aAny.setValue( &bTmp, ::getBooleanCppuType());
286 xPropertySet->setPropertyValue(sPropertyIsDisplayFormula, aAny);
289 // delegate to value helper
290 aValueHelper.SetDefault(GetContent());
291 aValueHelper.PrepareField(xPropertySet);
293 // finally, set the curren presentation
294 if (bSetPresentation)
296 Any aAny;
297 aAny <<= GetContent();
298 xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
307 // variable set fields
310 TYPEINIT1( XMLSetVarFieldImportContext, XMLVarFieldImportContext );
312 XMLSetVarFieldImportContext::XMLSetVarFieldImportContext(
313 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
314 const sal_Char* pServiceName, sal_uInt16 nPrfx,
315 const OUString& rLocalName, VarType eVarType,
316 sal_Bool bName, sal_Bool bFormula, sal_Bool bFormulaDefault,
317 sal_Bool bDescription, sal_Bool bHelp, sal_Bool bHint, sal_Bool bVisible, sal_Bool bIsDisplayFormula,
318 sal_Bool bType, sal_Bool bStyle, sal_Bool bValue, sal_Bool bPresentation) :
319 XMLVarFieldImportContext(rImport, rHlp, pServiceName,
320 nPrfx, rLocalName,
321 bName, bFormula, bFormulaDefault,
322 bDescription, bHelp, bHint, bVisible, bIsDisplayFormula,
323 bType, bStyle, bValue, bPresentation),
324 eFieldType(eVarType)
328 void XMLSetVarFieldImportContext::EndElement()
330 // should we call PrepareField on the field, or rather on it's master?
331 // currently: call on field (just like superclass)
332 // possible alternatives: call on master
333 // call field or master depending on variable
334 // PrepareMaster() in addition to PrepareField()
336 DBG_ASSERT(GetServiceName().getLength()>0, "no service name for element!");
338 if (bValid)
340 DBG_ASSERT(GetName().getLength()>0, "variable name needed!");
342 // find field master
343 Reference<XPropertySet> xMaster;
344 if (FindFieldMaster(xMaster))
346 // create field/Service
347 Reference<XPropertySet> xPropSet;
348 if (CreateField(xPropSet, OUString::createFromAscii(sAPI_textfield_prefix) + GetServiceName()))
350 Reference<XDependentTextField> xDepTextField(xPropSet, UNO_QUERY);
351 if (xDepTextField.is())
353 // attach field to field master
354 xDepTextField->attachTextFieldMaster(xMaster);
356 // attach field to document
357 Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
358 if (xTextContent.is())
360 try {
361 // insert, set field properties and exit!
362 GetImportHelper().InsertTextContent(xTextContent);
363 PrepareField(xPropSet);
364 } catch (lang::IllegalArgumentException & /*e*/)
366 // ignore e: #i54023#
368 return;
375 // above: exit on success; so for all error cases we end up here!
376 // write element content
377 GetImportHelper().InsertString(GetContent());
380 sal_Bool XMLSetVarFieldImportContext::FindFieldMaster(
381 Reference<XPropertySet> & xMaster)
383 // currently: delegate to XMLVariableDeclImportContext;
384 // shoud eventually go here
385 return XMLVariableDeclImportContext::FindFieldMaster(xMaster,
386 GetImport(),
387 GetImportHelper(),
388 GetName(),
389 eFieldType);
395 // sequence field
398 TYPEINIT1( XMLSequenceFieldImportContext, XMLSetVarFieldImportContext );
400 XMLSequenceFieldImportContext::XMLSequenceFieldImportContext(
401 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
402 sal_uInt16 nPrfx, const OUString& rLocalName) :
403 XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression,
404 nPrfx, rLocalName, VarTypeSequence,
405 // name, formula
406 sal_True, sal_True, sal_True,
407 sal_False, sal_False, sal_False, sal_False,
408 sal_False,
409 sal_False, sal_False, sal_False, sal_True),
411 sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)),
412 sPropertySequenceValue(RTL_CONSTASCII_USTRINGPARAM(sAPI_sequence_value)),
413 sNumFormat(OUString::valueOf(sal_Unicode('1'))),
414 sNumFormatSync(GetXMLToken(XML_FALSE)),
415 bRefNameOK(sal_False)
419 void XMLSequenceFieldImportContext::ProcessAttribute(
420 sal_uInt16 nAttrToken, const OUString& sAttrValue )
422 switch (nAttrToken)
424 case XML_TOK_TEXTFIELD_NUM_FORMAT:
425 sNumFormat = sAttrValue;
426 break;
427 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
428 sNumFormatSync = sAttrValue;
429 break;
430 case XML_TOK_TEXTFIELD_REF_NAME:
431 sRefName = sAttrValue;
432 bRefNameOK = sal_True;
433 break;
434 default:
435 // delegate to super class (name, formula)
436 XMLSetVarFieldImportContext::ProcessAttribute(nAttrToken,
437 sAttrValue);
438 break;
439 } // switch
442 void XMLSequenceFieldImportContext::PrepareField(
443 const Reference<XPropertySet> & xPropertySet)
445 // delegate to super class (formula)
446 XMLSetVarFieldImportContext::PrepareField(xPropertySet);
448 // set format
449 sal_Int16 nNumType = NumberingType::ARABIC;
450 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, sNumFormat, sNumFormatSync );
451 Any aAny;
452 aAny <<= nNumType;
453 xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
455 // handle reference name
456 if (bRefNameOK)
458 aAny = xPropertySet->getPropertyValue(sPropertySequenceValue);
459 sal_Int16 nValue = 0;
460 aAny >>= nValue;
461 GetImportHelper().InsertSequenceID(sRefName, GetName(), nValue);
468 // variable set field
471 TYPEINIT1( XMLVariableSetFieldImportContext, XMLSetVarFieldImportContext );
473 XMLVariableSetFieldImportContext::XMLVariableSetFieldImportContext(
474 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
475 sal_uInt16 nPrfx, const OUString& rLocalName) :
476 XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression,
477 nPrfx, rLocalName, VarTypeSimple,
478 // name, formula, value&type, style,
479 // display none
480 sal_True, sal_True, sal_True,
481 sal_False, sal_False, sal_False,
482 sal_True, sal_False,
483 sal_True, sal_True, sal_True,
484 sal_True),
485 sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
489 void XMLVariableSetFieldImportContext::PrepareField(
490 const Reference<XPropertySet> & xPropertySet)
492 // set type
493 Any aAny;
494 aAny <<= (IsStringValue()? SetVariableType::STRING : SetVariableType::VAR);
495 xPropertySet->setPropertyValue(sPropertySubType, aAny);
497 // the remainder is handled by super class
498 XMLSetVarFieldImportContext::PrepareField(xPropertySet);
504 // variable input field
507 TYPEINIT1( XMLVariableInputFieldImportContext, XMLSetVarFieldImportContext );
509 XMLVariableInputFieldImportContext::XMLVariableInputFieldImportContext(
510 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
511 const OUString& rLocalName) :
512 XMLSetVarFieldImportContext(rImport, rHlp, sAPI_set_expression,
513 nPrfx, rLocalName, VarTypeSimple,
514 // name, description, display none/formula,
515 // value&type, style, formula
516 sal_True, sal_True, sal_True,
517 sal_True, sal_True, sal_True,
518 sal_True, sal_False,
519 sal_True, sal_True, sal_True,
520 sal_True),
521 sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)),
522 sPropertyIsInput(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_input))
526 void XMLVariableInputFieldImportContext::PrepareField(
527 const Reference<XPropertySet> & xPropertySet)
529 // set type (input field)
530 Any aAny;
531 sal_Bool bTrue = sal_True;
532 aAny.setValue( &bTrue, ::getBooleanCppuType() );
533 xPropertySet->setPropertyValue(sPropertyIsInput, aAny);
535 // set type
536 aAny <<= (IsStringValue()? SetVariableType::STRING : SetVariableType::VAR);
537 xPropertySet->setPropertyValue(sPropertySubType, aAny);
539 // the remainder is handled by super class
540 XMLSetVarFieldImportContext::PrepareField(xPropertySet);
546 // user field
549 TYPEINIT1( XMLUserFieldImportContext, XMLSetVarFieldImportContext );
551 XMLUserFieldImportContext::XMLUserFieldImportContext(
552 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
553 sal_uInt16 nPrfx, const OUString& rLocalName) :
554 XMLSetVarFieldImportContext(rImport, rHlp, sAPI_user, nPrfx,
555 rLocalName, VarTypeUserField,
556 // name, display none/formula, style
557 sal_True, sal_False, sal_False,
558 sal_False, sal_False, sal_False, sal_True,
559 sal_True,
560 sal_False, sal_True, sal_False,
561 sal_False)
568 // user input field
571 TYPEINIT1( XMLUserFieldInputImportContext, XMLVarFieldImportContext );
573 // bug: doesn't work (SO API lacking)
574 XMLUserFieldInputImportContext::XMLUserFieldInputImportContext(
575 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
576 const OUString& rLocalName) :
577 XMLVarFieldImportContext(rImport, rHlp, sAPI_input_user,
578 nPrfx, rLocalName,
579 // name, description, style
580 sal_True, sal_False, sal_False,
581 sal_True, sal_False, sal_False,
582 sal_False, sal_False,
583 sal_False /*???*/, sal_True, sal_False,
584 sal_False)
588 void XMLUserFieldInputImportContext::PrepareField(
589 const Reference<XPropertySet> & xPropertySet)
591 Any aAny;
592 aAny <<= GetName();
593 xPropertySet->setPropertyValue(sPropertyContent, aAny);
595 // delegate to super class
596 XMLVarFieldImportContext::PrepareField(xPropertySet);
601 // variable get field
604 TYPEINIT1( XMLVariableGetFieldImportContext, XMLVarFieldImportContext );
606 XMLVariableGetFieldImportContext::XMLVariableGetFieldImportContext(
607 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
608 sal_uInt16 nPrfx, const OUString& rLocalName) :
609 XMLVarFieldImportContext(rImport, rHlp, sAPI_get_expression,
610 nPrfx, rLocalName,
611 // name, style, display formula
612 sal_True, sal_False, sal_False,
613 sal_False, sal_False, sal_False,
614 sal_False, sal_True,
615 sal_True, sal_True, sal_False,
616 sal_True),
617 sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
621 void XMLVariableGetFieldImportContext::PrepareField(
622 const Reference<XPropertySet> & xPropertySet)
624 // set name
625 Any aAny;
626 aAny <<= GetName();
627 xPropertySet->setPropertyValue(sPropertyContent, aAny);
629 // the remainder is handled by super class
630 XMLVarFieldImportContext::PrepareField(xPropertySet);
636 // expression field
639 TYPEINIT1( XMLExpressionFieldImportContext, XMLVarFieldImportContext );
641 XMLExpressionFieldImportContext::XMLExpressionFieldImportContext(
642 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
643 sal_uInt16 nPrfx, const OUString& rLocalName) :
644 XMLVarFieldImportContext(rImport, rHlp, sAPI_get_expression,
645 nPrfx, rLocalName,
646 // formula, type, style, display formula
647 sal_False, sal_True, sal_True,
648 sal_False, sal_False, sal_False,
649 sal_False, sal_True,
650 sal_True, sal_True, sal_False,
651 sal_True),
652 sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
654 bValid = sal_True; // always valid
658 void XMLExpressionFieldImportContext::PrepareField(
659 const Reference<XPropertySet> & xPropertySet)
661 sal_Int16 nSubType = SetVariableType::FORMULA;
662 Any aAny;
663 aAny <<= nSubType;
664 xPropertySet->setPropertyValue(sPropertySubType, aAny);
666 // delegate to super class
667 XMLVarFieldImportContext::PrepareField(xPropertySet);
673 // text input field
676 TYPEINIT1( XMLTextInputFieldImportContext, XMLVarFieldImportContext );
678 XMLTextInputFieldImportContext::XMLTextInputFieldImportContext(
679 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
680 sal_uInt16 nPrfx, const OUString& sLocalName) :
681 XMLVarFieldImportContext(rImport, rHlp, sAPI_input,
682 nPrfx, sLocalName,
683 // description
684 sal_False, sal_False, sal_False,
685 sal_True, sal_True, sal_True,
686 sal_False, sal_False,
687 sal_False, sal_False, sal_False,
688 sal_False),
689 sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content))
691 bValid = sal_True; // always valid
694 void XMLTextInputFieldImportContext::PrepareField(
695 const Reference<XPropertySet> & xPropertySet)
697 XMLVarFieldImportContext::PrepareField(xPropertySet);
699 Any aAny;
700 aAny <<= GetContent();
701 xPropertySet->setPropertyValue(sPropertyContent, aAny);
706 // table formula field
709 TYPEINIT1( XMLTableFormulaImportContext, XMLTextFieldImportContext );
711 XMLTableFormulaImportContext::XMLTableFormulaImportContext(
712 SvXMLImport& rImport,
713 XMLTextImportHelper& rHlp,
714 sal_uInt16 nPrfx,
715 const OUString& rLocalName) :
716 XMLTextFieldImportContext(rImport, rHlp, sAPI_table_formula,
717 nPrfx, rLocalName),
718 sPropertyIsShowFormula(RTL_CONSTASCII_USTRINGPARAM("IsShowFormula")),
719 sPropertyCurrentPresentation(
720 RTL_CONSTASCII_USTRINGPARAM("CurrentPresentation")),
721 aValueHelper(rImport, rHlp, sal_False, sal_True, sal_False, sal_True),
722 sFormula(),
723 bIsShowFormula(sal_False)
727 XMLTableFormulaImportContext::~XMLTableFormulaImportContext()
731 void XMLTableFormulaImportContext::ProcessAttribute(
732 sal_uInt16 nAttrToken,
733 const OUString& sAttrValue )
735 switch (nAttrToken)
737 case XML_TOK_TEXTFIELD_FORMULA:
738 aValueHelper.ProcessAttribute( nAttrToken, sAttrValue );
739 bValid = sal_True; // we need a formula!
740 break;
742 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
743 aValueHelper.ProcessAttribute( nAttrToken, sAttrValue );
744 break;
745 case XML_TOK_TEXTFIELD_DISPLAY:
746 if ( sAttrValue.equalsAsciiL(
747 RTL_CONSTASCII_STRINGPARAM("formula")) )
748 bIsShowFormula = sal_True;
749 break;
750 default:
751 // unknown attribute -> ignore
752 break;
756 void XMLTableFormulaImportContext::PrepareField(
757 const Reference<XPropertySet> & xPropertySet)
759 // set format and formula
760 aValueHelper.PrepareField( xPropertySet );
762 Any aAny;
764 // set 'show formula' and presentation
765 aAny.setValue( &bIsShowFormula, ::getBooleanCppuType() );
766 xPropertySet->setPropertyValue( sPropertyIsShowFormula, aAny );
768 aAny <<= GetContent();
769 xPropertySet->setPropertyValue( sPropertyCurrentPresentation, aAny );
775 // variable declarations
777 // Should be adapted to XMLVarField-/XMLSetVarFieldImportContext scheme!
783 // declaration containter import (<variable/user-field/sequence-decls>)
786 TYPEINIT1( XMLVariableDeclsImportContext, SvXMLImportContext );
788 XMLVariableDeclsImportContext::XMLVariableDeclsImportContext(
789 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
790 const OUString& rLocalName, enum VarType eVarType) :
791 SvXMLImportContext(rImport, nPrfx, rLocalName),
792 eVarDeclsContextType(eVarType),
793 rImportHelper(rHlp)
797 SvXMLImportContext* XMLVariableDeclsImportContext::CreateChildContext(
798 sal_uInt16 nPrefix, const OUString& rLocalName,
799 const Reference<xml::sax::XAttributeList> & xAttrList )
801 enum XMLTokenEnum eElementName;
802 SvXMLImportContext* pImportContext = NULL;
804 if( XML_NAMESPACE_TEXT == nPrefix )
806 switch (eVarDeclsContextType)
808 case VarTypeSequence:
809 eElementName = XML_SEQUENCE_DECL;
810 break;
811 case VarTypeSimple:
812 eElementName = XML_VARIABLE_DECL;
813 break;
814 case VarTypeUserField:
815 eElementName = XML_USER_FIELD_DECL;
816 break;
817 default:
818 DBG_ERROR("unknown field type!");
819 eElementName = XML_SEQUENCE_DECL;
820 break;
823 if( IsXMLToken( rLocalName, eElementName ) )
825 pImportContext = new XMLVariableDeclImportContext(
826 GetImport(), rImportHelper, nPrefix, rLocalName, xAttrList,
827 eVarDeclsContextType);
831 // if no context was created, use default context
832 if (NULL == pImportContext) {
833 pImportContext = SvXMLImportContext::CreateChildContext(nPrefix,
834 rLocalName,
835 xAttrList);
838 return pImportContext;
844 // declaration import (<variable/user-field/sequence-decl> elements)
847 TYPEINIT1( XMLVariableDeclImportContext, SvXMLImportContext );
849 XMLVariableDeclImportContext::XMLVariableDeclImportContext(
850 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
851 sal_uInt16 nPrfx, const OUString& rLocalName,
852 const Reference<xml::sax::XAttributeList> & xAttrList,
853 enum VarType eVarType) :
854 SvXMLImportContext(rImport, nPrfx, rLocalName),
855 // bug?? which properties for userfield/userfieldmaster
856 sPropertyName(RTL_CONSTASCII_USTRINGPARAM(sAPI_name)),
857 sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type)),
858 sPropertyNumberingLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_chapter_numbering_level)),
859 sPropertyNumberingSeparator(RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_separator)),
860 sPropertyIsExpression(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_expression)),
861 aValueHelper(rImport, rHlp, sal_True, sal_False, sal_True, sal_False),
862 nNumLevel(-1), cSeparationChar('.')
864 if ( (XML_NAMESPACE_TEXT == nPrfx) &&
865 ( ( IsXMLToken( rLocalName, XML_SEQUENCE_DECL )) ||
866 ( IsXMLToken( rLocalName, XML_VARIABLE_DECL)) ||
867 ( IsXMLToken( rLocalName, XML_USER_FIELD_DECL)) )) {
869 // TODO: check validity (need name!)
871 // parse attributes
872 sal_Int16 nLength = xAttrList->getLength();
873 for(sal_Int16 i=0; i<nLength; i++) {
875 OUString sLocalName;
876 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
877 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
879 sal_uInt16 nToken = rHlp.
880 GetTextFieldAttrTokenMap().Get(nPrefix, sLocalName);
882 switch (nToken)
884 case XML_TOK_TEXTFIELD_NAME:
885 sName = xAttrList->getValueByIndex(i);
886 break;
887 case XML_TOK_TEXTFIELD_NUMBERING_LEVEL:
889 sal_Int32 nLevel;
890 sal_Bool bRet = SvXMLUnitConverter::convertNumber(
891 nLevel, xAttrList->getValueByIndex(i), 0,
892 GetImport().GetTextImport()->GetChapterNumbering()->
893 getCount());
894 if (bRet)
896 nNumLevel = static_cast< sal_Int8 >( nLevel-1 ); // API numbers -1..9
898 break;
900 case XML_TOK_TEXTFIELD_NUMBERING_SEPARATOR:
901 cSeparationChar =
902 (sal_Char)xAttrList->getValueByIndex(i).toChar();
903 break;
905 default:
906 // delegate to value helper
907 aValueHelper.ProcessAttribute(nToken,
908 xAttrList->getValueByIndex(i));
909 break;
913 Reference<XPropertySet> xFieldMaster;
914 if (FindFieldMaster(xFieldMaster, GetImport(), rHlp,
915 sName, eVarType))
917 // now we have a field master: process attributes!
918 Any aAny;
920 switch (eVarType)
922 case VarTypeSequence:
923 aAny <<= nNumLevel;
924 xFieldMaster->setPropertyValue(sPropertyNumberingLevel, aAny);
926 if (nNumLevel >= 0)
928 OUString sStr(&cSeparationChar, 1);
929 aAny <<= sStr;
930 xFieldMaster->setPropertyValue(
931 sPropertyNumberingSeparator, aAny);
933 break;
934 case VarTypeSimple:
936 // set string or non-string SubType (#93192#)
937 // The SubType was already set in the FindFieldMaster
938 // method, but it needs to be adjusted if it's a string.
939 aAny <<= aValueHelper.IsStringValue()
940 ? SetVariableType::STRING : SetVariableType::VAR;
941 xFieldMaster->setPropertyValue(sPropertySubType, aAny);
943 break;
944 case VarTypeUserField:
946 sal_Bool bTmp = !aValueHelper.IsStringValue();
947 aAny.setValue(&bTmp, ::getBooleanCppuType());
948 xFieldMaster->setPropertyValue(sPropertyIsExpression, aAny);
949 aValueHelper.PrepareField(xFieldMaster);
950 break;
952 default:
953 DBG_ERROR("unkown varfield type");
954 } // switch
955 } // else: no field master found/constructed
956 } // else: no sequence-decl
961 sal_Bool XMLVariableDeclImportContext::FindFieldMaster(
962 Reference<XPropertySet> & xMaster, SvXMLImport& rImport,
963 XMLTextImportHelper& rImportHelper,
964 const OUString& sVarName, enum VarType eVarType)
966 static sal_Int32 nCollisionCount = 0;
968 // rename field
969 // currently: no family in use! Use 0.
970 OUString sName = rImportHelper.GetRenameMap().Get(
971 sal::static_int_cast< USHORT >(eVarType), sVarName);
973 // get text fields supplier and field masters
974 Reference<XTextFieldsSupplier> xTextFieldsSupp(rImport.GetModel(),
975 UNO_QUERY);
976 Reference<container::XNameAccess> xFieldMasterNameAccess(
977 xTextFieldsSupp->getTextFieldMasters(), UNO_QUERY);
979 OUStringBuffer sBuffer;
980 sBuffer.appendAscii(sAPI_fieldmaster_prefix);
981 sBuffer.appendAscii(sAPI_set_expression);
982 sBuffer.appendAscii(".");
983 sBuffer.append(sName);
984 OUString sVarServiceName = sBuffer.makeStringAndClear();
986 sBuffer.appendAscii(sAPI_fieldmaster_prefix);
987 sBuffer.appendAscii(sAPI_user);
988 sBuffer.appendAscii(".");
989 sBuffer.append(sName);
990 OUString sUserServiceName = sBuffer.makeStringAndClear();
992 if (xFieldMasterNameAccess->hasByName(sVarServiceName)) {
993 // variable field master already in document
995 Any aAny = xFieldMasterNameAccess->getByName(sVarServiceName);
996 aAny >>= xMaster;
998 aAny = xMaster->getPropertyValue(
999 // sPropertySubType
1000 OUString::createFromAscii(sAPI_sub_type)
1002 sal_Int16 nType = 0;
1003 aAny >>= nType;
1005 enum VarType eFMVarType =
1006 (SetVariableType::SEQUENCE == nType) ?
1007 VarTypeSequence : VarTypeSimple;
1009 if (eFMVarType != eVarType)
1011 OUString sNew;
1013 // FIXME! cant find if name is taken already!!!!
1015 nCollisionCount++;
1016 OUStringBuffer aBuf;
1017 aBuf.append(sName);
1018 aBuf.appendAscii("_renamed_");
1019 aBuf.append(nCollisionCount);
1020 sNew = aBuf.makeStringAndClear();
1022 rImportHelper.GetRenameMap().Add(
1023 sal::static_int_cast< USHORT >(eVarType), sName, sNew);
1025 // call FindFieldMaster recursively to create new master
1026 return FindFieldMaster(xMaster, rImport, rImportHelper,
1027 sNew, eVarType);
1029 } else if (xFieldMasterNameAccess->hasByName(sUserServiceName)) {
1030 // user field: get field master
1031 Any aAny = xFieldMasterNameAccess->getByName(sUserServiceName);
1032 aAny >>= xMaster;
1034 if (VarTypeUserField != eVarType) {
1035 // find new name that is not taken
1036 OUString sNew;
1038 // FIXME! cant find if name is taken already!!!!
1040 nCollisionCount++;
1041 OUStringBuffer aBuf;
1042 aBuf.append(sName);
1043 aBuf.appendAscii("_renamed_");
1044 aBuf.append(nCollisionCount);
1045 sNew = aBuf.makeStringAndClear();
1047 rImportHelper.GetRenameMap().Add(
1048 sal::static_int_cast< USHORT >(eVarType), sName, sNew);
1050 // call FindFieldMaster recursively to create new master
1051 return FindFieldMaster(xMaster, rImport, rImportHelper,
1052 sNew, eVarType);
1054 } else {
1055 // field name not used: create field master
1057 // import -> model is MultiServiceFactory -> createInstance
1058 Reference<lang::XMultiServiceFactory>
1059 xFactory(rImport.GetModel(),UNO_QUERY);
1060 if( xFactory.is() ) {
1062 OUStringBuffer sService;
1063 sService.appendAscii(sAPI_fieldmaster_prefix);
1064 sService.appendAscii((eVarType==VarTypeUserField) ?
1065 sAPI_user : sAPI_set_expression);
1066 Reference<XInterface> xIfc =
1067 xFactory->createInstance( sService.makeStringAndClear() );
1068 if (xIfc.is()) {
1069 Reference<XPropertySet> xTmp( xIfc, UNO_QUERY );
1070 xMaster = xTmp;
1072 // set name
1073 Any aAny;
1074 aAny <<= sName;
1075 xMaster->setPropertyValue(
1076 // sPropertyName
1077 OUString::createFromAscii(sAPI_name)
1078 , aAny);
1080 if (eVarType != VarTypeUserField) {
1081 // set subtype for setexp field
1083 aAny <<= ((eVarType == VarTypeSimple) ?
1084 SetVariableType::VAR :
1085 SetVariableType::SEQUENCE);
1086 xMaster->setPropertyValue(
1087 // sPropertySubType
1088 OUString::createFromAscii(sAPI_sub_type)
1089 , aAny);
1090 } // else : user field: no subtype
1092 } else {
1093 return sal_False;
1095 } else {
1096 return sal_False;
1100 DBG_ASSERT(xMaster.is(), "no field master found!?!");
1101 return sal_True;
1106 // Database Display field import
1110 TYPEINIT1( XMLDatabaseDisplayImportContext, XMLDatabaseFieldImportContext );
1112 XMLDatabaseDisplayImportContext::XMLDatabaseDisplayImportContext(
1113 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
1114 const OUString& rLocalName) :
1115 XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database,
1116 nPrfx, rLocalName, false),
1117 sPropertyColumnName(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_column_name)),
1118 sPropertyDatabaseFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_data_base_format)),
1119 sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)),
1120 sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_visible)),
1121 aValueHelper(rImport, rHlp, sal_False, sal_True, sal_False, sal_False),
1122 bColumnOK(sal_False),
1123 bDisplay( sal_True ),
1124 bDisplayOK( sal_False )
1128 void XMLDatabaseDisplayImportContext::ProcessAttribute(
1129 sal_uInt16 nAttrToken, const OUString& sAttrValue )
1131 switch (nAttrToken)
1133 case XML_TOK_TEXTFIELD_COLUMN_NAME:
1134 sColumnName = sAttrValue;
1135 bColumnOK = sal_True;
1136 break;
1137 case XML_TOK_TEXTFIELD_DISPLAY:
1139 sal_Bool bNone = IsXMLToken( sAttrValue, XML_NONE );
1140 sal_Bool bValue = IsXMLToken( sAttrValue, XML_VALUE );
1141 bDisplay = bValue;
1142 bDisplayOK = bNone || bValue;
1144 break;
1145 case XML_TOK_TEXTFIELD_DATABASE_NAME:
1146 case XML_TOK_TEXTFIELD_TABLE_NAME:
1147 case XML_TOK_TEXTFIELD_TABLE_TYPE:
1148 // handled by super class
1149 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1150 sAttrValue);
1151 break;
1152 default:
1153 // remainder handled by value helper
1154 aValueHelper.ProcessAttribute(nAttrToken, sAttrValue);
1155 break;
1158 bValid = bTableOK && bDatabaseOK && bColumnOK;
1161 void XMLDatabaseDisplayImportContext::EndElement()
1163 // we have an EndElement of our own, because database fields need
1164 // to be attached to a field master before they can be inserted into
1165 // the document. Database stuff (database, table, column) all goes
1166 // to the field master, value & style go to the field.
1168 if (bValid)
1171 // so here goes: we start with the master
1172 Reference<XPropertySet> xMaster;
1174 // create and prepare field master first
1175 if (CreateField(xMaster,
1176 OUString(RTL_CONSTASCII_USTRINGPARAM(
1177 sAPI_fieldmaster_database))))
1179 Any aAny;
1180 aAny <<= sColumnName;
1181 xMaster->setPropertyValue(sPropertyColumnName, aAny);
1183 // fieldmaster takes database, table and column name
1184 XMLDatabaseFieldImportContext::PrepareField(xMaster);
1186 // create field
1187 Reference<XPropertySet> xField;
1188 if (CreateField(xField,
1189 OUString(RTL_CONSTASCII_USTRINGPARAM(
1190 sAPI_database))))
1192 // attach field master
1193 Reference<XDependentTextField> xDepField(xField, UNO_QUERY);
1194 if (xDepField.is())
1196 // attach field to field master
1197 xDepField->attachTextFieldMaster(xMaster);
1199 // attach field to document
1200 Reference<XTextContent> xTextContent(xField, UNO_QUERY);
1201 if (xTextContent.is())
1203 // insert, set field properties and exit!
1204 GetImportHelper().InsertTextContent(xTextContent);
1206 // prepare field: format from database?
1207 sal_Bool bTmp = !aValueHelper.IsFormatOK();
1208 aAny.setValue( &bTmp, ::getBooleanCppuType() );
1209 xField->setPropertyValue(sPropertyDatabaseFormat,aAny);
1211 // value, value-type and format done by value helper
1212 aValueHelper.PrepareField(xField);
1214 // visibility
1215 if( bDisplayOK )
1217 aAny.setValue( &bDisplay, ::getBooleanCppuType() );
1218 xField->setPropertyValue(sPropertyIsVisible, aAny);
1221 // set presentation
1222 aAny <<= GetContent();
1223 xField->setPropertyValue(sPropertyCurrentPresentation,
1224 aAny);
1226 // success!
1227 return;
1234 // above: exit on success; so for all error cases we end up here!
1235 // write element content
1236 GetImportHelper().InsertString(GetContent());
1241 // value import helper
1244 enum ValueType
1246 XML_VALUE_TYPE_STRING,
1247 XML_VALUE_TYPE_FLOAT,
1248 XML_VALUE_TYPE_CURRENCY,
1249 XML_VALUE_TYPE_PERCENTAGE,
1250 XML_VALUE_TYPE_DATE,
1251 XML_VALUE_TYPE_TIME,
1252 XML_VALUE_TYPE_BOOLEAN
1255 static SvXMLEnumMapEntry __READONLY_DATA aValueTypeMap[] =
1257 { XML_FLOAT, XML_VALUE_TYPE_FLOAT },
1258 { XML_CURRENCY, XML_VALUE_TYPE_CURRENCY },
1259 { XML_PERCENTAGE, XML_VALUE_TYPE_PERCENTAGE },
1260 { XML_DATE, XML_VALUE_TYPE_DATE },
1261 { XML_TIME, XML_VALUE_TYPE_TIME },
1262 { XML_BOOLEAN, XML_VALUE_TYPE_BOOLEAN },
1263 { XML_STRING, XML_VALUE_TYPE_STRING },
1264 { XML_TOKEN_INVALID, 0 }
1267 XMLValueImportHelper::XMLValueImportHelper(
1268 SvXMLImport& rImprt,
1269 XMLTextImportHelper& rHlp,
1270 sal_Bool bType, sal_Bool bStyle, sal_Bool bValue, sal_Bool bFormula) :
1271 sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)),
1272 sPropertyValue(RTL_CONSTASCII_USTRINGPARAM(sAPI_value)),
1273 sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format)),
1274 sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed_language)),
1276 rImport(rImprt),
1277 rHelper(rHlp),
1279 fValue(0.0),
1280 nFormatKey(0),
1281 bIsDefaultLanguage(sal_True),
1283 bStringType(sal_False),
1284 bFormatOK(sal_False),
1285 bTypeOK(sal_False),
1286 bStringValueOK(sal_False),
1287 bFloatValueOK(sal_False),
1288 bFormulaOK(sal_False),
1290 bSetType(bType),
1291 bSetValue(bValue),
1292 bSetStyle(bStyle),
1293 bSetFormula(bFormula),
1295 bStringDefault(sal_True),
1296 bFormulaDefault(sal_True)
1300 XMLValueImportHelper::~XMLValueImportHelper()
1304 void XMLValueImportHelper::ProcessAttribute(
1305 sal_uInt16 nAttrToken, const OUString& sAttrValue )
1307 switch (nAttrToken)
1309 case XML_TOK_TEXTFIELD_VALUE_TYPE:
1311 // convert enum
1312 sal_uInt16 nTmp = 0;
1313 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
1314 nTmp, sAttrValue, aValueTypeMap);
1316 if (bRet) {
1317 ValueType eValueType = (ValueType)nTmp;
1319 bTypeOK = sal_True;
1321 switch (eValueType)
1323 case XML_VALUE_TYPE_STRING:
1324 bStringType = sal_True;
1325 break;
1326 case XML_VALUE_TYPE_FLOAT:
1327 case XML_VALUE_TYPE_CURRENCY:
1328 case XML_VALUE_TYPE_PERCENTAGE:
1329 case XML_VALUE_TYPE_DATE:
1330 case XML_VALUE_TYPE_TIME:
1331 case XML_VALUE_TYPE_BOOLEAN:
1332 bStringType = sal_False;
1333 break;
1335 default:
1336 DBG_ERROR("unknown value type");
1337 bTypeOK = sal_False;
1340 break;
1343 case XML_TOK_TEXTFIELD_VALUE:
1345 double fTmp;
1346 sal_Bool bRet = SvXMLUnitConverter::convertDouble(fTmp,sAttrValue);
1347 if (bRet) {
1348 bFloatValueOK = sal_True;
1349 fValue = fTmp;
1351 break;
1354 case XML_TOK_TEXTFIELD_TIME_VALUE:
1356 double fTmp;
1357 sal_Bool bRet = SvXMLUnitConverter::convertTime(fTmp,sAttrValue);
1358 if (bRet) {
1359 bFloatValueOK = sal_True;
1360 fValue = fTmp;
1362 break;
1365 case XML_TOK_TEXTFIELD_DATE_VALUE:
1367 double fTmp;
1368 sal_Bool bRet = rImport.GetMM100UnitConverter().
1369 convertDateTime(fTmp,sAttrValue);
1370 if (bRet) {
1371 bFloatValueOK = sal_True;
1372 fValue = fTmp;
1374 break;
1377 case XML_TOK_TEXTFIELD_BOOL_VALUE:
1379 sal_Bool bTmp;
1380 sal_Bool bRet = SvXMLUnitConverter::convertBool(bTmp,sAttrValue);
1381 if (bRet) {
1382 bFloatValueOK = sal_True;
1383 fValue = (bTmp ? 1.0 : 0.0);
1385 else
1387 double fTmp;
1388 bRet = SvXMLUnitConverter::convertDouble(fTmp,sAttrValue);
1389 if (bRet) {
1390 bFloatValueOK = sal_True;
1391 fValue = fTmp;
1394 break;
1397 case XML_TOK_TEXTFIELD_STRING_VALUE:
1398 sValue = sAttrValue;
1399 bStringValueOK = sal_True;
1400 break;
1402 case XML_TOK_TEXTFIELD_FORMULA:
1404 OUString sTmp;
1405 sal_uInt16 nPrefix = rImport.GetNamespaceMap().
1406 _GetKeyByAttrName( sAttrValue, &sTmp, sal_False );
1407 if( XML_NAMESPACE_OOOW == nPrefix )
1409 sFormula = sTmp;
1410 bFormulaOK = sal_True;
1412 else
1413 sFormula = sAttrValue;
1415 break;
1417 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1419 sal_Int32 nKey = rHelper.GetDataStyleKey(
1420 sAttrValue, &bIsDefaultLanguage);
1421 if (-1 != nKey)
1423 nFormatKey = nKey;
1424 bFormatOK = sal_True;
1426 break;
1428 } // switch
1431 void XMLValueImportHelper::PrepareField(
1432 const Reference<XPropertySet> & xPropertySet)
1434 Any aAny;
1436 if (bSetType)
1438 // ??? how to set type?
1441 if (bSetFormula)
1443 aAny <<= (!bFormulaOK && bFormulaDefault) ? sDefault : sFormula;
1444 xPropertySet->setPropertyValue(sPropertyContent, aAny);
1447 // format/style
1448 if (bSetStyle && bFormatOK)
1450 aAny <<= nFormatKey;
1451 xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
1453 if( xPropertySet->getPropertySetInfo()->
1454 hasPropertyByName( sPropertyIsFixedLanguage ) )
1456 sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage;
1457 aAny.setValue( &bIsFixedLanguage, ::getBooleanCppuType() );
1458 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny );
1462 // value: string or float
1463 if (bSetValue)
1465 if (bStringType)
1467 aAny <<= (!bStringValueOK && bStringDefault) ? sDefault : sValue;
1468 xPropertySet->setPropertyValue(sPropertyContent, aAny);
1470 else
1472 aAny <<= fValue;
1473 xPropertySet->setPropertyValue(sPropertyValue, aAny);