LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - xmlDataSourceSetting.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 91 0.0 %
Date: 2012-08-25 Functions: 0 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 155 0.0 %

           Branch data     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                 :            : #include "xmlDataSourceSetting.hxx"
      21                 :            : #include "xmlDataSource.hxx"
      22                 :            : #include <sax/tools/converter.hxx>
      23                 :            : #include "xmlfilter.hxx"
      24                 :            : #include <xmloff/xmltoken.hxx>
      25                 :            : #include <xmloff/xmlnmspe.hxx>
      26                 :            : #include <xmloff/nmspmap.hxx>
      27                 :            : #include "xmlEnums.hxx"
      28                 :            : #include "xmlstrings.hrc"
      29                 :            : #include <rtl/strbuf.hxx>
      30                 :            : #include <tools/debug.hxx>
      31                 :            : 
      32                 :            : namespace dbaxml
      33                 :            : {
      34                 :            :     using namespace ::com::sun::star::uno;
      35                 :            :     using namespace ::com::sun::star::xml::sax;
      36                 :            : DBG_NAME(OXMLDataSourceSetting)
      37                 :            : 
      38                 :          0 : OXMLDataSourceSetting::OXMLDataSourceSetting( ODBFilter& rImport
      39                 :            :                 ,sal_uInt16 nPrfx
      40                 :            :                 ,const ::rtl::OUString& _sLocalName
      41                 :            :                 ,const Reference< XAttributeList > & _xAttrList
      42                 :            :                 ,OXMLDataSourceSetting* _pContainer) :
      43                 :            :     SvXMLImportContext( rImport, nPrfx, _sLocalName )
      44                 :            :     ,m_pContainer(_pContainer)
      45         [ #  # ]:          0 :     ,m_bIsList(sal_False)
      46                 :            : {
      47                 :            :     DBG_CTOR(OXMLDataSourceSetting,NULL);
      48                 :            : 
      49         [ #  # ]:          0 :     m_aPropType = ::getVoidCppuType();
      50                 :            : 
      51                 :            :     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
      52                 :          0 :     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
      53         [ #  # ]:          0 :     const SvXMLTokenMap& rTokenMap = rImport.GetDataSourceInfoElemTokenMap();
      54                 :            : 
      55 [ #  # ][ #  # ]:          0 :     sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
                 [ #  # ]
      56         [ #  # ]:          0 :     for(sal_Int16 i = 0; i < nLength; ++i)
      57                 :            :     {
      58                 :          0 :         ::rtl::OUString sLocalName;
      59 [ #  # ][ #  # ]:          0 :         rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
      60         [ #  # ]:          0 :         sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
      61 [ #  # ][ #  # ]:          0 :         rtl::OUString sValue = _xAttrList->getValueByIndex( i );
      62                 :            : 
      63         [ #  # ]:          0 :         switch( rTokenMap.Get( nPrefix, sLocalName ) )
           [ #  #  #  # ]
      64                 :            :         {
      65                 :            :             case XML_TOK_DATA_SOURCE_SETTING_IS_LIST:
      66                 :          0 :                 m_bIsList = sValue == "true";
      67                 :          0 :                 break;
      68                 :            :             case XML_TOK_DATA_SOURCE_SETTING_TYPE:
      69                 :            :                 {
      70                 :            :                     // needs to be translated into a ::com::sun::star::uno::Type
      71                 :            :                     DECLARE_STL_USTRINGACCESS_MAP( ::com::sun::star::uno::Type, MapString2Type );
      72 [ #  # ][ #  # ]:          0 :                     static MapString2Type s_aTypeNameMap;
         [ #  # ][ #  # ]
      73         [ #  # ]:          0 :                     if (!s_aTypeNameMap.size())
      74                 :            :                     {
      75 [ #  # ][ #  # ]:          0 :                         s_aTypeNameMap[GetXMLToken( XML_BOOLEAN)]   = ::getBooleanCppuType();
                 [ #  # ]
      76 [ #  # ][ #  # ]:          0 :                         s_aTypeNameMap[GetXMLToken( XML_FLOAT)]     = ::getCppuType( static_cast< double* >(NULL) );
                 [ #  # ]
      77 [ #  # ][ #  # ]:          0 :                         s_aTypeNameMap[GetXMLToken( XML_DOUBLE)]    = ::getCppuType( static_cast< double* >(NULL) );
                 [ #  # ]
      78 [ #  # ][ #  # ]:          0 :                         s_aTypeNameMap[GetXMLToken( XML_STRING)]    = ::getCppuType( static_cast< ::rtl::OUString* >(NULL) );
                 [ #  # ]
      79 [ #  # ][ #  # ]:          0 :                         s_aTypeNameMap[GetXMLToken( XML_INT)]       = ::getCppuType( static_cast< sal_Int32* >(NULL) );
                 [ #  # ]
      80 [ #  # ][ #  # ]:          0 :                         s_aTypeNameMap[GetXMLToken( XML_SHORT)]     = ::getCppuType( static_cast< sal_Int16* >(NULL) );
                 [ #  # ]
      81 [ #  # ][ #  # ]:          0 :                         s_aTypeNameMap[GetXMLToken( XML_VOID)]      = ::getVoidCppuType();
                 [ #  # ]
      82                 :            :                     }
      83                 :            : 
      84         [ #  # ]:          0 :                     const ConstMapString2TypeIterator aTypePos = s_aTypeNameMap.find(sValue);
      85                 :            :                     OSL_ENSURE(s_aTypeNameMap.end() != aTypePos, "OXMLDataSourceSetting::OXMLDataSourceSetting: invalid type!");
      86         [ #  # ]:          0 :                     if (s_aTypeNameMap.end() != aTypePos)
      87                 :          0 :                         m_aPropType = aTypePos->second;
      88                 :            :                 }
      89                 :          0 :                 break;
      90                 :            :             case XML_TOK_DATA_SOURCE_SETTING_NAME:
      91                 :          0 :                 m_aSetting.Name = sValue;
      92                 :          0 :                 break;
      93                 :            :         }
      94                 :          0 :     }
      95                 :            : 
      96                 :          0 : }
      97                 :            : // -----------------------------------------------------------------------------
      98                 :            : 
      99         [ #  # ]:          0 : OXMLDataSourceSetting::~OXMLDataSourceSetting()
     100                 :            : {
     101                 :            :     DBG_DTOR(OXMLDataSourceSetting,NULL);
     102         [ #  # ]:          0 : }
     103                 :            : // -----------------------------------------------------------------------------
     104                 :          0 : SvXMLImportContext* OXMLDataSourceSetting::CreateChildContext(
     105                 :            :         sal_uInt16 nPrefix,
     106                 :            :         const ::rtl::OUString& rLocalName,
     107                 :            :         const Reference< XAttributeList > & xAttrList )
     108                 :            : {
     109                 :          0 :     SvXMLImportContext *pContext = 0;
     110                 :          0 :     const SvXMLTokenMap&    rTokenMap   = GetOwnImport().GetDataSourceInfoElemTokenMap();
     111                 :            : 
     112      [ #  #  # ]:          0 :     switch( rTokenMap.Get( nPrefix, rLocalName ) )
     113                 :            :     {
     114                 :            :         case XML_TOK_DATA_SOURCE_SETTING:
     115                 :          0 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     116         [ #  # ]:          0 :             pContext = new OXMLDataSourceSetting( GetOwnImport(), nPrefix, rLocalName,xAttrList);
     117                 :          0 :             break;
     118                 :            :         case XML_TOK_DATA_SOURCE_SETTING_VALUE:
     119                 :          0 :             GetOwnImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
     120         [ #  # ]:          0 :             pContext = new OXMLDataSourceSetting( GetOwnImport(), nPrefix, rLocalName,xAttrList,this );
     121                 :          0 :             break;
     122                 :            :     }
     123                 :            : 
     124         [ #  # ]:          0 :     if( !pContext )
     125         [ #  # ]:          0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     126                 :            : 
     127                 :          0 :     return pContext;
     128                 :            : }
     129                 :            : // -----------------------------------------------------------------------------
     130                 :          0 : void OXMLDataSourceSetting::EndElement()
     131                 :            : {
     132         [ #  # ]:          0 :     if ( !m_aSetting.Name.isEmpty() )
     133                 :            :     {
     134 [ #  # ][ #  # ]:          0 :         if ( m_bIsList && m_aInfoSequence.getLength() )
                 [ #  # ]
     135                 :          0 :             m_aSetting.Value <<= m_aInfoSequence;
     136                 :            : 
     137                 :            :         // if our property is of type string, but was empty, ensure that
     138                 :            :         // we don't add a VOID value
     139 [ #  # ][ #  # ]:          0 :         if ( !m_bIsList && ( m_aPropType.getTypeClass() == TypeClass_STRING ) && !m_aSetting.Value.hasValue() )
         [ #  # ][ #  # ]
     140         [ #  # ]:          0 :             m_aSetting.Value <<= ::rtl::OUString();
     141                 :            : 
     142                 :          0 :         GetOwnImport().addInfo(m_aSetting);
     143                 :            :     }
     144                 :          0 : }
     145                 :            : // -----------------------------------------------------------------------------
     146                 :          0 : void OXMLDataSourceSetting::Characters( const ::rtl::OUString& rChars )
     147                 :            : {
     148         [ #  # ]:          0 :     if ( m_pContainer )
     149                 :          0 :         m_pContainer->addValue(rChars);
     150                 :          0 : }
     151                 :            : // -----------------------------------------------------------------------------
     152                 :          0 : void OXMLDataSourceSetting::addValue(const ::rtl::OUString& _sValue)
     153                 :            : {
     154                 :          0 :     Any aValue;
     155         [ #  # ]:          0 :     if( TypeClass_VOID != m_aPropType.getTypeClass() )
     156         [ #  # ]:          0 :         aValue = convertString(m_aPropType, _sValue);
     157                 :            : 
     158         [ #  # ]:          0 :     if ( !m_bIsList )
     159                 :          0 :         m_aSetting.Value = aValue;
     160                 :            :     else
     161                 :            :     {
     162                 :          0 :         sal_Int32 nPos = m_aInfoSequence.getLength();
     163         [ #  # ]:          0 :         m_aInfoSequence.realloc(nPos+1);
     164         [ #  # ]:          0 :         m_aInfoSequence[nPos] = aValue;
     165                 :          0 :     }
     166                 :          0 : }
     167                 :            : // -----------------------------------------------------------------------------
     168                 :          0 : ODBFilter& OXMLDataSourceSetting::GetOwnImport()
     169                 :            : {
     170                 :          0 :     return static_cast<ODBFilter&>(GetImport());
     171                 :            : }
     172                 :            : // -----------------------------------------------------------------------------
     173                 :          0 : Any OXMLDataSourceSetting::convertString(const ::com::sun::star::uno::Type& _rExpectedType, const ::rtl::OUString& _rReadCharacters)
     174                 :            : {
     175                 :          0 :     Any aReturn;
     176   [ #  #  #  #  :          0 :     switch (_rExpectedType.getTypeClass())
                   #  # ]
     177                 :            :     {
     178                 :            :         case TypeClass_BOOLEAN:     // sal_Bool
     179                 :            :         {
     180                 :          0 :             bool bValue(false);
     181                 :            :         #if OSL_DEBUG_LEVEL > 0
     182                 :            :             sal_Bool bSuccess =
     183                 :            :         #endif
     184         [ #  # ]:          0 :                 ::sax::Converter::convertBool(bValue, _rReadCharacters);
     185                 :            :             OSL_ENSURE(bSuccess,
     186                 :            :                     ::rtl::OStringBuffer("OXMLDataSourceSetting::convertString: could not convert \"")
     187                 :            :                 .append(::rtl::OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US))
     188                 :            :                 .append("\" into a boolean!").getStr());
     189         [ #  # ]:          0 :             aReturn <<= bValue;
     190                 :            :         }
     191                 :          0 :         break;
     192                 :            :         case TypeClass_SHORT:       // sal_Int16
     193                 :            :         case TypeClass_LONG:        // sal_Int32
     194                 :            :             {   // it's a real int32/16 property
     195                 :          0 :                 sal_Int32 nValue(0);
     196                 :            :         #if OSL_DEBUG_LEVEL > 0
     197                 :            :                 sal_Bool bSuccess =
     198                 :            :         #endif
     199         [ #  # ]:          0 :                     ::sax::Converter::convertNumber(nValue, _rReadCharacters);
     200                 :            :                 OSL_ENSURE(bSuccess,
     201                 :            :                         ::rtl::OStringBuffer("OXMLDataSourceSetting::convertString: could not convert \"")
     202                 :            :                     .append(::rtl::OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US))
     203                 :            :                     .append("\" into an integer!").getStr());
     204         [ #  # ]:          0 :                 if (TypeClass_SHORT == _rExpectedType.getTypeClass())
     205         [ #  # ]:          0 :                     aReturn <<= (sal_Int16)nValue;
     206                 :            :                 else
     207         [ #  # ]:          0 :                     aReturn <<= (sal_Int32)nValue;
     208                 :            :                 break;
     209                 :            :             }
     210                 :            :         case TypeClass_HYPER:
     211                 :            :         {
     212                 :            :             OSL_FAIL("OXMLDataSourceSetting::convertString: 64-bit integers not implemented yet!");
     213                 :            :         }
     214                 :          0 :         break;
     215                 :            :         case TypeClass_DOUBLE:
     216                 :            :         {
     217                 :          0 :             double nValue = 0.0;
     218                 :            :         #if OSL_DEBUG_LEVEL > 0
     219                 :            :             sal_Bool bSuccess =
     220                 :            :         #endif
     221         [ #  # ]:          0 :                 ::sax::Converter::convertDouble(nValue, _rReadCharacters);
     222                 :            :             OSL_ENSURE(bSuccess,
     223                 :            :                     ::rtl::OStringBuffer("OXMLDataSourceSetting::convertString: could not convert \"")
     224                 :            :                 .append(rtl::OUStringToOString(_rReadCharacters, RTL_TEXTENCODING_ASCII_US))
     225                 :            :                 .append("\" into a double!").getStr());
     226         [ #  # ]:          0 :             aReturn <<= (double)nValue;
     227                 :            :         }
     228                 :          0 :         break;
     229                 :            :         case TypeClass_STRING:
     230         [ #  # ]:          0 :             aReturn <<= _rReadCharacters;
     231                 :          0 :             break;
     232                 :            :         default:
     233                 :            :             OSL_FAIL("OXMLDataSourceSetting::convertString: invalid type class!");
     234                 :            :     }
     235                 :            : 
     236                 :          0 :     return aReturn;
     237                 :            : }
     238                 :            : 
     239                 :            : //----------------------------------------------------------------------------
     240                 :            : } // namespace dbaxml
     241                 :            : // -----------------------------------------------------------------------------
     242                 :            : 
     243                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10