LCOV - code coverage report
Current view: top level - connectivity/source/commontools - DriversConfig.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 135 137 98.5 %
Date: 2015-06-13 12:38:46 Functions: 16 16 100.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             : #include <connectivity/DriversConfig.hxx>
      20             : #include <tools/wldcrd.hxx>
      21             : #include <svtools/miscopt.hxx>
      22             : 
      23             : using namespace connectivity;
      24             : using namespace utl;
      25             : using namespace ::com::sun::star;
      26             : 
      27             : namespace
      28             : {
      29          78 :     void lcl_convert(const uno::Sequence< OUString >& _aSource,uno::Any& _rDest)
      30             :     {
      31          78 :         uno::Sequence<uno::Any> aRet(_aSource.getLength());
      32          78 :         uno::Any* pAny = aRet.getArray();
      33          78 :         const OUString* pIter = _aSource.getConstArray();
      34          78 :         const OUString* pEnd  = pIter + _aSource.getLength();
      35        1326 :         for (;pIter != pEnd ; ++pIter,++pAny)
      36             :         {
      37        1248 :             *pAny <<= *pIter;
      38             :         }
      39          78 :         _rDest <<= aRet;
      40          78 :     }
      41        2808 :     void lcl_fillValues(const ::utl::OConfigurationNode& _aURLPatternNode,const OUString& _sNode,::comphelper::NamedValueCollection& _rValues)
      42             :     {
      43        2808 :         const ::utl::OConfigurationNode aPropertiesNode = _aURLPatternNode.openNode(_sNode);
      44        2808 :         if ( aPropertiesNode.isValid() )
      45             :         {
      46        2808 :             uno::Sequence< OUString > aStringSeq;
      47             :             static const char s_sValue[] = "/Value";
      48        5616 :             const uno::Sequence< OUString > aProperties = aPropertiesNode.getNodeNames();
      49        2808 :             const OUString* pPropertiesIter = aProperties.getConstArray();
      50        2808 :             const OUString* pPropertiesEnd  = pPropertiesIter + aProperties.getLength();
      51       15366 :             for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter)
      52             :             {
      53       12558 :                 uno::Any aValue = aPropertiesNode.getNodeValue(*pPropertiesIter + s_sValue);
      54       12558 :                 if ( aValue >>= aStringSeq )
      55             :                 {
      56          78 :                     lcl_convert(aStringSeq,aValue);
      57             :                 }
      58       12558 :                 _rValues.put(*pPropertiesIter,aValue);
      59       15366 :             } // for (;pPropertiesIter != pPropertiesEnd ; ++pPropertiesIter,++pNamedIter)
      60        2808 :         } // if ( aPropertiesNode.isValid() )
      61        2808 :     }
      62         936 :     void lcl_readURLPatternNode(const ::utl::OConfigurationTreeRoot& _aInstalled,const OUString& _sEntry,TInstalledDriver& _rInstalledDriver)
      63             :     {
      64         936 :         const ::utl::OConfigurationNode aURLPatternNode = _aInstalled.openNode(_sEntry);
      65         936 :         if ( aURLPatternNode.isValid() )
      66             :         {
      67         936 :             OUString sParentURLPattern;
      68         936 :             aURLPatternNode.getNodeValue("ParentURLPattern") >>= sParentURLPattern;
      69         936 :             if ( !sParentURLPattern.isEmpty() )
      70          78 :                 lcl_readURLPatternNode(_aInstalled,sParentURLPattern,_rInstalledDriver);
      71             : 
      72        1872 :             OUString sDriverFactory;
      73         936 :             aURLPatternNode.getNodeValue("Driver") >>= sDriverFactory;
      74         936 :             if ( !sDriverFactory.isEmpty() )
      75         858 :                 _rInstalledDriver.sDriverFactory = sDriverFactory;
      76             : 
      77        1872 :             OUString sDriverTypeDisplayName;
      78         936 :             aURLPatternNode.getNodeValue("DriverTypeDisplayName") >>= sDriverTypeDisplayName;
      79             :             OSL_ENSURE(!sDriverTypeDisplayName.isEmpty(),"No valid DriverTypeDisplayName property!");
      80         936 :             if ( !sDriverTypeDisplayName.isEmpty() )
      81         936 :                 _rInstalledDriver.sDriverTypeDisplayName = sDriverTypeDisplayName;
      82             : 
      83         936 :             lcl_fillValues(aURLPatternNode,"Properties",_rInstalledDriver.aProperties);
      84         936 :             lcl_fillValues(aURLPatternNode,"Features",_rInstalledDriver.aFeatures);
      85        1872 :             lcl_fillValues(aURLPatternNode,"MetaData",_rInstalledDriver.aMetaData);
      86         936 :         }
      87         936 :     }
      88             : }
      89             : 
      90          80 : DriversConfigImpl::DriversConfigImpl()
      91             : {
      92          80 : }
      93             : 
      94        3136 : void DriversConfigImpl::Load(const uno::Reference< uno::XComponentContext >& _rxORB) const
      95             : {
      96        3136 :     if ( m_aDrivers.empty() )
      97             :     {
      98          78 :         if ( !m_aInstalled.isValid() )
      99             :         {
     100             :             static const char s_sNodeName[] = "org.openoffice.Office.DataAccess.Drivers/Installed"; ///Installed
     101          78 :             m_aInstalled = ::utl::OConfigurationTreeRoot::createWithComponentContext(_rxORB, s_sNodeName, -1, ::utl::OConfigurationTreeRoot::CM_READONLY);
     102             :         }
     103             : 
     104          78 :         if ( m_aInstalled.isValid() )
     105             :         {
     106          78 :             SvtMiscOptions aMiscOptions;
     107             : 
     108         156 :             const uno::Sequence< OUString > aURLPatterns = m_aInstalled.getNodeNames();
     109          78 :             const OUString* pPatternIter = aURLPatterns.getConstArray();
     110          78 :             const OUString* pPatternEnd  = pPatternIter + aURLPatterns.getLength();
     111         936 :             for (;pPatternIter != pPatternEnd ; ++pPatternIter)
     112             :             {
     113         858 :                 TInstalledDriver aInstalledDriver;
     114         858 :                 lcl_readURLPatternNode(m_aInstalled,*pPatternIter,aInstalledDriver);
     115        2574 :                 if ( !aInstalledDriver.sDriverFactory.isEmpty() &&
     116        1716 :                      ( aMiscOptions.IsExperimentalMode() ||
     117         858 :                        aInstalledDriver.sDriverFactory != "com.sun.star.comp.sdbc.firebird.Driver" ))
     118         858 :                     m_aDrivers.insert(TInstalledDrivers::value_type(*pPatternIter,aInstalledDriver));
     119         936 :             }
     120             :         } // if ( m_aInstalled.isValid() )
     121             :     }
     122        3136 : }
     123             : 
     124        3077 : DriversConfig::DriversConfig(const uno::Reference< uno::XComponentContext >& _rxORB)
     125        3077 : :m_xORB(_rxORB)
     126             : {
     127        3077 : }
     128             : 
     129             : 
     130       15570 : DriversConfig::~DriversConfig()
     131             : {
     132       15570 : }
     133             : 
     134             : 
     135       12510 : DriversConfig::DriversConfig( const DriversConfig& _rhs )
     136             : {
     137       12510 :     *this = _rhs;
     138       12510 : }
     139             : 
     140             : 
     141       12510 : DriversConfig& DriversConfig::operator=( const DriversConfig& _rhs )
     142             : {
     143             :     if ( this != &_rhs )
     144             :     {
     145             :         m_aNode = _rhs.m_aNode;
     146             :     }
     147       12510 :     return *this;
     148             : }
     149             : 
     150             : 
     151         146 : OUString DriversConfig::getDriverFactoryName(const OUString& _sURL) const
     152             : {
     153         146 :     const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
     154         146 :     OUString sRet;
     155         292 :     OUString sOldPattern;
     156         146 :     TInstalledDrivers::const_iterator aIter = rDrivers.begin();
     157         146 :     TInstalledDrivers::const_iterator aEnd = rDrivers.end();
     158        1752 :     for(;aIter != aEnd;++aIter)
     159             :     {
     160        1606 :         WildCard aWildCard(aIter->first);
     161        1606 :         if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
     162             :         {
     163         146 :             sRet = aIter->second.sDriverFactory;
     164         146 :             sOldPattern = aIter->first;
     165             :         }
     166        1606 :     }
     167             : 
     168         292 :     return sRet;
     169             : }
     170             : 
     171        2383 : OUString DriversConfig::getDriverTypeDisplayName(const OUString& _sURL) const
     172             : {
     173        2383 :     const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
     174        2383 :     OUString sRet;
     175        4766 :     OUString sOldPattern;
     176        2383 :     TInstalledDrivers::const_iterator aIter = rDrivers.begin();
     177        2383 :     TInstalledDrivers::const_iterator aEnd = rDrivers.end();
     178       28596 :     for(;aIter != aEnd;++aIter)
     179             :     {
     180       26213 :         WildCard aWildCard(aIter->first);
     181       26213 :         if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
     182             :         {
     183        2599 :             sRet = aIter->second.sDriverTypeDisplayName;
     184        2599 :             sOldPattern = aIter->first;
     185             :         }
     186       26213 :     }
     187             : 
     188        4766 :     return sRet;
     189             : }
     190             : 
     191         112 : const ::comphelper::NamedValueCollection& DriversConfig::getProperties(const OUString& _sURL) const
     192             : {
     193         112 :     return impl_get(_sURL,1);
     194             : }
     195             : 
     196          33 : const ::comphelper::NamedValueCollection& DriversConfig::getFeatures(const OUString& _sURL) const
     197             : {
     198          33 :     return impl_get(_sURL,0);
     199             : }
     200             : 
     201         234 : const ::comphelper::NamedValueCollection& DriversConfig::getMetaData(const OUString& _sURL) const
     202             : {
     203         234 :     return impl_get(_sURL,2);
     204             : }
     205             : 
     206         379 : const ::comphelper::NamedValueCollection& DriversConfig::impl_get(const OUString& _sURL,sal_Int32 _nProps) const
     207             : {
     208         379 :     const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
     209         379 :     const ::comphelper::NamedValueCollection* pRet = NULL;
     210         379 :     OUString sOldPattern;
     211         379 :     TInstalledDrivers::const_iterator aIter = rDrivers.begin();
     212         379 :     TInstalledDrivers::const_iterator aEnd = rDrivers.end();
     213        4548 :     for(;aIter != aEnd;++aIter)
     214             :     {
     215        4169 :         WildCard aWildCard(aIter->first);
     216        4169 :         if ( sOldPattern.getLength() < aIter->first.getLength() && aWildCard.Matches(_sURL) )
     217             :         {
     218         391 :             switch(_nProps)
     219             :             {
     220             :                 case 0:
     221          36 :                     pRet = &aIter->second.aFeatures;
     222          36 :                     break;
     223             :                 case 1:
     224         112 :                     pRet = &aIter->second.aProperties;
     225         112 :                     break;
     226             :                 case 2:
     227         243 :                     pRet = &aIter->second.aMetaData;
     228         243 :                     break;
     229             :             }
     230         391 :             sOldPattern = aIter->first;
     231             :         }
     232        4169 :     } // for(;aIter != aEnd;++aIter)
     233         379 :     if ( pRet == NULL )
     234             :     {
     235           0 :         static const ::comphelper::NamedValueCollection s_sEmpty;
     236           0 :         pRet = &s_sEmpty;
     237             :     }
     238         379 :     return *pRet;
     239             : }
     240             : 
     241         228 : uno::Sequence< OUString > DriversConfig::getURLs() const
     242             : {
     243         228 :     const TInstalledDrivers& rDrivers = m_aNode->getInstalledDrivers(m_xORB);
     244         228 :     uno::Sequence< OUString > aRet(rDrivers.size());
     245         228 :     OUString* pIter = aRet.getArray();
     246         228 :     TInstalledDrivers::const_iterator aIter = rDrivers.begin();
     247         228 :     TInstalledDrivers::const_iterator aEnd = rDrivers.end();
     248        2736 :     for(;aIter != aEnd;++aIter,++pIter)
     249             :     {
     250        2508 :         *pIter = aIter->first;
     251             :     }
     252         228 :     return aRet;
     253             : }
     254             : 
     255             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11