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

Generated by: LCOV version 1.10