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

Generated by: LCOV version 1.10