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

Generated by: LCOV version 1.10