LCOV - code coverage report
Current view: top level - xmloff/source/text - txtvfldi.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 252 530 47.5 %
Date: 2014-04-11 Functions: 19 109 17.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10