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

Generated by: LCOV version 1.10