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

Generated by: LCOV version 1.10