LCOV - code coverage report
Current view: top level - cui/source/options - dbregisterednamesconfig.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 39 0.0 %
Date: 2012-08-25 Functions: 0 2 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 92 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "connpooloptions.hxx"
      30                 :            : #include "dbregisterednamesconfig.hxx"
      31                 :            : #include "dbregistersettings.hxx"
      32                 :            : #include "svx/svxids.hrc"
      33                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      34                 :            : #include <com/sun/star/sdb/XDatabaseRegistrations.hpp>
      35                 :            : #include <comphelper/componentcontext.hxx>
      36                 :            : #include <comphelper/extract.hxx>
      37                 :            : #include <comphelper/processfactory.hxx>
      38                 :            : #include <svl/eitem.hxx>
      39                 :            : #include <svl/itemset.hxx>
      40                 :            : #include <unotools/pathoptions.hxx>
      41                 :            : #include <unotools/confignode.hxx>
      42                 :            : #include <tools/diagnose_ex.h>
      43                 :            : 
      44                 :            : //........................................................................
      45                 :            : namespace svx
      46                 :            : {
      47                 :            : //........................................................................
      48                 :            : 
      49                 :            :     using namespace ::utl;
      50                 :            :     using namespace ::com::sun::star::uno;
      51                 :            :     using namespace ::com::sun::star::sdb;
      52                 :            :     using namespace ::com::sun::star::container;
      53                 :            : 
      54                 :            :     //====================================================================
      55                 :            :     //= DbRegisteredNamesConfig
      56                 :            :     //====================================================================
      57                 :            :     //--------------------------------------------------------------------
      58                 :          0 :     void DbRegisteredNamesConfig::GetOptions( SfxItemSet& _rFillItems )
      59                 :            :     {
      60         [ #  # ]:          0 :         DatabaseRegistrations aSettings;
      61                 :            : 
      62                 :            :         try
      63                 :            :         {
      64 [ #  # ][ #  # ]:          0 :             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
      65                 :            :             Reference< XDatabaseRegistrations > xRegistrations(
      66 [ #  # ][ #  # ]:          0 :                 aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW );
      67                 :            : 
      68 [ #  # ][ #  # ]:          0 :             Sequence< ::rtl::OUString > aRegistrationNames( xRegistrations->getRegistrationNames() );
      69                 :          0 :             const ::rtl::OUString* pRegistrationName = aRegistrationNames.getConstArray();
      70                 :          0 :             const ::rtl::OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength();
      71         [ #  # ]:          0 :             for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName )
      72                 :            :             {
      73 [ #  # ][ #  # ]:          0 :                 ::rtl::OUString sLocation( xRegistrations->getDatabaseLocation( *pRegistrationName ) );
      74         [ #  # ]:          0 :                 aSettings[ *pRegistrationName ] =
      75 [ #  # ][ #  # ]:          0 :                     DatabaseRegistration( sLocation, xRegistrations->isDatabaseRegistrationReadOnly( *pRegistrationName ) );
      76 [ #  # ][ #  # ]:          0 :             }
                 [ #  # ]
      77                 :            :         }
      78         [ #  # ]:          0 :         catch( const Exception& )
      79                 :            :         {
      80                 :            :             DBG_UNHANDLED_EXCEPTION();
      81                 :            :         }
      82                 :            : 
      83 [ #  # ][ #  # ]:          0 :         _rFillItems.Put( DatabaseMapItem( SID_SB_DB_REGISTER, aSettings ) );
                 [ #  # ]
      84                 :          0 :     }
      85                 :            : 
      86                 :            :     //--------------------------------------------------------------------
      87                 :          0 :     void DbRegisteredNamesConfig::SetOptions(const SfxItemSet& _rSourceItems)
      88                 :            :     {
      89                 :            :         // the settings for the single drivers
      90                 :          0 :         SFX_ITEMSET_GET( _rSourceItems, pRegistrations, DatabaseMapItem, SID_SB_DB_REGISTER, sal_True );
      91         [ #  # ]:          0 :         if ( !pRegistrations )
      92                 :          0 :             return;
      93                 :            : 
      94                 :            :         try
      95                 :            :         {
      96 [ #  # ][ #  # ]:          0 :             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
      97                 :            :             Reference< XDatabaseRegistrations > xRegistrations(
      98 [ #  # ][ #  # ]:          0 :                 aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW );
      99                 :            : 
     100                 :          0 :             const DatabaseRegistrations& rNewRegistrations = pRegistrations->getRegistrations();
     101         [ #  # ]:          0 :             for (   DatabaseRegistrations::const_iterator reg = rNewRegistrations.begin();
     102                 :          0 :                     reg != rNewRegistrations.end();
     103                 :            :                     ++reg
     104                 :            :                 )
     105                 :            :             {
     106                 :          0 :                 const ::rtl::OUString sName = reg->first;
     107                 :          0 :                 const ::rtl::OUString sLocation = reg->second.sLocation;
     108                 :            : 
     109 [ #  # ][ #  # ]:          0 :                 if ( xRegistrations->hasRegisteredDatabase( sName ) )
                 [ #  # ]
     110                 :            :                 {
     111 [ #  # ][ #  # ]:          0 :                     if ( !xRegistrations->isDatabaseRegistrationReadOnly( sName ) )
                 [ #  # ]
     112 [ #  # ][ #  # ]:          0 :                         xRegistrations->changeDatabaseLocation( sName, sLocation );
     113                 :            :                     else
     114                 :            :                     {
     115                 :            :                         OSL_ENSURE( xRegistrations->getDatabaseLocation( sName ) == sLocation,
     116                 :            :                             "DbRegisteredNamesConfig::SetOptions: somebody changed a read-only registration. How unrespectful." );
     117                 :            :                     }
     118                 :            :                 }
     119                 :            :                 else
     120 [ #  # ][ #  # ]:          0 :                     xRegistrations->registerDatabaseLocation( sName, sLocation );
     121                 :          0 :             }
     122                 :            : 
     123                 :            :             // delete unused entries
     124 [ #  # ][ #  # ]:          0 :             Sequence< ::rtl::OUString > aRegistrationNames = xRegistrations->getRegistrationNames();
     125                 :          0 :             const ::rtl::OUString* pRegistrationName = aRegistrationNames.getConstArray();
     126                 :          0 :             const ::rtl::OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength();
     127         [ #  # ]:          0 :             for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName )
     128                 :            :             {
     129 [ #  # ][ #  # ]:          0 :                 if ( rNewRegistrations.find( *pRegistrationName ) == rNewRegistrations.end() )
     130 [ #  # ][ #  # ]:          0 :                     xRegistrations->revokeDatabaseLocation( *pRegistrationName );
     131 [ #  # ][ #  # ]:          0 :             }
                 [ #  # ]
     132                 :            :         }
     133                 :          0 :         catch( const Exception& )
     134                 :            :         {
     135                 :            :                         //DBG_UNHANDLED_EXCEPTION();
     136                 :            :         }
     137                 :            :     }
     138                 :            : 
     139                 :            : //........................................................................
     140                 :            : }   // namespace svx
     141                 :            : //........................................................................
     142                 :            : 
     143                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10