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

Generated by: LCOV version 1.10