LCOV - code coverage report
Current view: top level - dbaccess/source/core/recovery - settingsimport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 92 0.0 %
Date: 2012-08-25 Functions: 0 25 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 106 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 "settingsimport.hxx"
      21                 :            : 
      22                 :            : #include <tools/diagnose_ex.h>
      23                 :            : #include <sax/tools/converter.hxx>
      24                 :            : #include <xmloff/xmltoken.hxx>
      25                 :            : 
      26                 :            : //........................................................................
      27                 :            : namespace dbaccess
      28                 :            : {
      29                 :            : //........................................................................
      30                 :            : 
      31                 :            :     /** === begin UNO using === **/
      32                 :            :     using ::com::sun::star::uno::Reference;
      33                 :            :     using ::com::sun::star::uno::XInterface;
      34                 :            :     using ::com::sun::star::uno::UNO_QUERY;
      35                 :            :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      36                 :            :     using ::com::sun::star::uno::UNO_SET_THROW;
      37                 :            :     using ::com::sun::star::uno::Exception;
      38                 :            :     using ::com::sun::star::uno::RuntimeException;
      39                 :            :     using ::com::sun::star::uno::Any;
      40                 :            :     using ::com::sun::star::uno::makeAny;
      41                 :            :     using ::com::sun::star::uno::Sequence;
      42                 :            :     using ::com::sun::star::uno::Type;
      43                 :            :     using ::com::sun::star::xml::sax::XAttributeList;
      44                 :            :     /** === end UNO using === **/
      45                 :            : 
      46                 :            :     //====================================================================
      47                 :            :     //= SettingsImport
      48                 :            :     //====================================================================
      49                 :            :     //--------------------------------------------------------------------
      50                 :          0 :     SettingsImport::SettingsImport()
      51                 :          0 :         :m_refCount( 0 )
      52                 :            :     {
      53                 :          0 :     }
      54                 :            : 
      55                 :            :     //--------------------------------------------------------------------
      56                 :          0 :     SettingsImport::~SettingsImport()
      57                 :            :     {
      58         [ #  # ]:          0 :     }
      59                 :            : 
      60                 :            :     //--------------------------------------------------------------------
      61                 :          0 :     oslInterlockedCount SAL_CALL SettingsImport::acquire()
      62                 :            :     {
      63                 :          0 :         return osl_incrementInterlockedCount( &m_refCount );
      64                 :            :     }
      65                 :            : 
      66                 :            :     //--------------------------------------------------------------------
      67                 :          0 :     oslInterlockedCount SAL_CALL SettingsImport::release()
      68                 :            :     {
      69                 :          0 :         oslInterlockedCount newCount = osl_decrementInterlockedCount( &m_refCount );
      70         [ #  # ]:          0 :         if ( newCount == 0 )
      71         [ #  # ]:          0 :             delete this;
      72                 :          0 :         return newCount;
      73                 :            :     }
      74                 :            : 
      75                 :            :     //--------------------------------------------------------------------
      76                 :          0 :     void SettingsImport::startElement( const Reference< XAttributeList >& i_rAttributes )
      77                 :            :     {
      78                 :            :         // find the name of the setting
      79         [ #  # ]:          0 :         if ( i_rAttributes.is() )
      80                 :            :         {
      81         [ #  # ]:          0 :             m_sItemName = i_rAttributes->getValueByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "config:name" ) ) );
      82         [ #  # ]:          0 :             m_sItemType = i_rAttributes->getValueByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "config:type" ) ) );
      83                 :            :         }
      84                 :          0 :     }
      85                 :            : 
      86                 :            :     //--------------------------------------------------------------------
      87                 :          0 :     void SettingsImport::endElement()
      88                 :            :     {
      89                 :          0 :     }
      90                 :            : 
      91                 :            :     //--------------------------------------------------------------------
      92                 :          0 :     void SettingsImport::characters( const ::rtl::OUString& i_rCharacters )
      93                 :            :     {
      94                 :          0 :         m_aCharacters.append( i_rCharacters );
      95                 :          0 :     }
      96                 :            : 
      97                 :            :     //--------------------------------------------------------------------
      98                 :          0 :     void SettingsImport::split( const ::rtl::OUString& i_rElementName, ::rtl::OUString& o_rNamespace, ::rtl::OUString& o_rLocalName )
      99                 :            :     {
     100                 :          0 :         o_rNamespace = ::rtl::OUString();
     101                 :          0 :         o_rLocalName = i_rElementName;
     102                 :          0 :         const sal_Int32 nSeparatorPos = i_rElementName.indexOf( ':' );
     103         [ #  # ]:          0 :         if ( nSeparatorPos > -1 )
     104                 :            :         {
     105                 :          0 :             o_rNamespace = i_rElementName.copy( 0, nSeparatorPos );
     106                 :          0 :             o_rLocalName = i_rElementName.copy( nSeparatorPos + 1 );
     107                 :            :         }
     108                 :            : 
     109                 :            :         OSL_ENSURE( o_rNamespace == "config", "SettingsImport::split: unexpected namespace!" );
     110                 :            :             // our recovery file is kind of hand-made, so there shouldn't be anything else than "config".
     111                 :            :             // If there is, then just ignore it ...
     112                 :          0 :     }
     113                 :            : 
     114                 :            :     //====================================================================
     115                 :            :     //= IgnoringSettingsImport
     116                 :            :     //====================================================================
     117                 :            :     //--------------------------------------------------------------------
     118                 :          0 :     ::rtl::Reference< SettingsImport > IgnoringSettingsImport::nextState( const ::rtl::OUString& i_rElementName )
     119                 :            :     {
     120                 :            :         (void)i_rElementName;
     121                 :          0 :         return this;
     122                 :            :     }
     123                 :            : 
     124                 :            :     //====================================================================
     125                 :            :     //= OfficeSettingsImport
     126                 :            :     //====================================================================
     127                 :            :     //--------------------------------------------------------------------
     128                 :          0 :     OfficeSettingsImport::OfficeSettingsImport( ::comphelper::NamedValueCollection& o_rSettings )
     129                 :          0 :         :m_rSettings( o_rSettings )
     130                 :            :     {
     131                 :          0 :     }
     132                 :            : 
     133                 :            :     //--------------------------------------------------------------------
     134                 :          0 :     OfficeSettingsImport::~OfficeSettingsImport()
     135                 :            :     {
     136         [ #  # ]:          0 :     }
     137                 :            : 
     138                 :            :     //--------------------------------------------------------------------
     139                 :          0 :     ::rtl::Reference< SettingsImport > OfficeSettingsImport::nextState( const ::rtl::OUString& i_rElementName )
     140                 :            :     {
     141                 :            :         // separate the namespace part from the element name
     142                 :          0 :         ::rtl::OUString sNamespace;
     143                 :          0 :         ::rtl::OUString sLocalName;
     144                 :          0 :         split( i_rElementName, sNamespace, sLocalName );
     145                 :            : 
     146         [ #  # ]:          0 :         if ( sLocalName == "config-item-set" )
     147 [ #  # ][ #  # ]:          0 :             return new ConfigItemSetImport( m_rSettings );
                 [ #  # ]
     148                 :            : 
     149                 :            : #if OSL_DEBUG_LEVEL > 0
     150                 :            :         ::rtl::OString sMessage( "unknown (or unsupported at this place) element name '" );
     151                 :            :         sMessage += ::rtl::OUStringToOString( i_rElementName, RTL_TEXTENCODING_UTF8 );
     152                 :            :         sMessage += "', ignoring";
     153                 :            :         OSL_FAIL( sMessage.getStr() );
     154                 :            : #endif
     155 [ #  # ][ #  # ]:          0 :         return new IgnoringSettingsImport;
                 [ #  # ]
     156                 :            :     }
     157                 :            : 
     158                 :            :     //====================================================================
     159                 :            :     //= ConfigItemImport
     160                 :            :     //====================================================================
     161                 :            :     //--------------------------------------------------------------------
     162                 :          0 :     ConfigItemImport::ConfigItemImport( ::comphelper::NamedValueCollection& o_rSettings )
     163                 :          0 :         :m_rSettings( o_rSettings )
     164                 :            :     {
     165                 :          0 :     }
     166                 :            : 
     167                 :            :     //--------------------------------------------------------------------
     168                 :          0 :     ConfigItemImport::~ConfigItemImport()
     169                 :            :     {
     170         [ #  # ]:          0 :     }
     171                 :            : 
     172                 :            :     //--------------------------------------------------------------------
     173                 :          0 :     ::rtl::Reference< SettingsImport > ConfigItemImport::nextState( const ::rtl::OUString& i_rElementName )
     174                 :            :     {
     175                 :            :         OSL_FAIL( "ConfigItemImport::nextState: unexpected: this class is responsible for child-less items only!" );
     176                 :            :         (void)i_rElementName;
     177         [ #  # ]:          0 :         return new IgnoringSettingsImport;
     178                 :            :     }
     179                 :            : 
     180                 :            :     //--------------------------------------------------------------------
     181                 :          0 :     void ConfigItemImport::endElement()
     182                 :            :     {
     183                 :          0 :         SettingsImport::endElement();
     184                 :            : 
     185                 :          0 :         const ::rtl::OUString sItemName( getItemName() );
     186         [ #  # ]:          0 :         ENSURE_OR_RETURN_VOID( !sItemName.isEmpty(), "no item name -> no item value" );
     187                 :          0 :         Any aValue;
     188         [ #  # ]:          0 :         getItemValue( aValue );
     189 [ #  # ][ #  # ]:          0 :         m_rSettings.put( sItemName, aValue );
     190                 :            :     }
     191                 :            : 
     192                 :            :     //--------------------------------------------------------------------
     193                 :          0 :     void ConfigItemImport::getItemValue( ::com::sun::star::uno::Any& o_rValue ) const
     194                 :            :     {
     195                 :          0 :         o_rValue.clear();
     196                 :            : 
     197                 :            :         // the characters building up th evalue
     198         [ #  # ]:          0 :         ::rtl::OUStringBuffer aCharacters( getAccumulatedCharacters() );
     199         [ #  # ]:          0 :         const ::rtl::OUString sValue = aCharacters.makeStringAndClear();
     200                 :            : 
     201                 :          0 :         const ::rtl::OUString& rItemType( getItemType() );
     202         [ #  # ]:          0 :         ENSURE_OR_RETURN_VOID( !rItemType.isEmpty(), "no item type -> no item value" );
     203                 :            : 
     204 [ #  # ][ #  # ]:          0 :         if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_INT ) )
     205                 :            :         {
     206                 :          0 :             sal_Int32 nValue(0);
     207 [ #  # ][ #  # ]:          0 :             if (::sax::Converter::convertNumber( nValue, sValue ))
     208                 :            :             {
     209         [ #  # ]:          0 :                 o_rValue <<= nValue;
     210                 :            :             }
     211                 :            :             else
     212                 :            :             {
     213                 :            :                 OSL_FAIL( "ConfigItemImport::getItemValue: could not convert an int value!" );
     214                 :            :             }
     215                 :            :         }
     216 [ #  # ][ #  # ]:          0 :         else if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_BOOLEAN ) )
     217                 :            :         {
     218                 :          0 :             bool bValue(false);
     219 [ #  # ][ #  # ]:          0 :             if (::sax::Converter::convertBool( bValue, sValue ))
     220                 :            :             {
     221         [ #  # ]:          0 :                 o_rValue <<= bValue;
     222                 :            :             }
     223                 :            :             else
     224                 :            :             {
     225                 :            :                 OSL_FAIL( "ConfigItemImport::getItemValue: could not convert a boolean value!" );
     226                 :            :             }
     227                 :            :         }
     228 [ #  # ][ #  # ]:          0 :         else if ( ::xmloff::token::IsXMLToken( rItemType, ::xmloff::token::XML_STRING ) )
     229                 :            :         {
     230         [ #  # ]:          0 :             o_rValue <<= sValue;
     231 [ #  # ][ #  # ]:          0 :         }
     232                 :            : #if OSL_DEBUG_LEVEL > 0
     233                 :            :         else
     234                 :            :         {
     235                 :            :             ::rtl::OString sMessage( "ConfigItemImport::getItemValue: unsupported item type '" );
     236                 :            :             sMessage += ::rtl::OUStringToOString( rItemType, RTL_TEXTENCODING_UTF8 );
     237                 :            :             sMessage += "', ignoring";
     238                 :            :             OSL_FAIL( sMessage.getStr() );
     239                 :            :         }
     240                 :            : #endif
     241                 :            :     }
     242                 :            : 
     243                 :            :     //====================================================================
     244                 :            :     //= ConfigItemSetImport
     245                 :            :     //====================================================================
     246                 :            :     //--------------------------------------------------------------------
     247                 :          0 :     ConfigItemSetImport::ConfigItemSetImport( ::comphelper::NamedValueCollection& o_rSettings )
     248         [ #  # ]:          0 :         :ConfigItemImport( o_rSettings )
     249                 :            :     {
     250                 :          0 :     }
     251                 :            : 
     252                 :            :     //--------------------------------------------------------------------
     253         [ #  # ]:          0 :     ConfigItemSetImport::~ConfigItemSetImport()
     254                 :            :     {
     255         [ #  # ]:          0 :     }
     256                 :            : 
     257                 :            :     //--------------------------------------------------------------------
     258                 :          0 :     ::rtl::Reference< SettingsImport > ConfigItemSetImport::nextState( const ::rtl::OUString& i_rElementName )
     259                 :            :     {
     260                 :            :         // separate the namespace part from the element name
     261                 :          0 :         ::rtl::OUString sNamespace;
     262                 :          0 :         ::rtl::OUString sLocalName;
     263                 :          0 :         split( i_rElementName, sNamespace, sLocalName );
     264                 :            : 
     265         [ #  # ]:          0 :         if ( sLocalName == "config-item-set" )
     266 [ #  # ][ #  # ]:          0 :             return new ConfigItemSetImport( m_aChildSettings );
                 [ #  # ]
     267         [ #  # ]:          0 :         if ( sLocalName == "config-item" )
     268 [ #  # ][ #  # ]:          0 :             return new ConfigItemImport( m_aChildSettings );
     269                 :            : 
     270                 :            : #if OSL_DEBUG_LEVEL > 0
     271                 :            :         ::rtl::OString sMessage( "unknown element name '" );
     272                 :            :         sMessage += ::rtl::OUStringToOString( i_rElementName, RTL_TEXTENCODING_UTF8 );
     273                 :            :         sMessage += "', ignoring";
     274                 :            :         OSL_FAIL( sMessage.getStr() );
     275                 :            : #endif
     276 [ #  # ][ #  # ]:          0 :         return new IgnoringSettingsImport;
                 [ #  # ]
     277                 :            :     }
     278                 :            : 
     279                 :            :     //--------------------------------------------------------------------
     280                 :          0 :     void ConfigItemSetImport::getItemValue( Any& o_rValue ) const
     281                 :            :     {
     282         [ #  # ]:          0 :         o_rValue <<= m_aChildSettings.getPropertyValues();
     283                 :          0 :     }
     284                 :            : 
     285                 :            : //........................................................................
     286                 :            : } // namespace dbaccess
     287                 :            : //........................................................................
     288                 :            : 
     289                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10