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

Generated by: LCOV version 1.10