LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - dsmeta.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 59 0.0 %
Date: 2014-04-14 Functions: 0 12 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 "dsmeta.hxx"
      21             : #include <connectivity/DriversConfig.hxx>
      22             : #include "dsntypes.hxx"
      23             : #include <comphelper/processfactory.hxx>
      24             : 
      25             : #include <map>
      26             : #include <utility>
      27             : 
      28             : namespace dbaui
      29             : {
      30             : 
      31             :     using namespace dbaccess;
      32             :     using namespace ::com::sun::star;
      33             : 
      34             :     struct FeatureSupport
      35             :     {
      36             :         // authentication mode of the data source
      37             :         AuthenticationMode      eAuthentication;
      38             : 
      39           0 :         FeatureSupport()
      40           0 :             :eAuthentication( AuthUserPwd )
      41             :         {
      42           0 :         }
      43             : 
      44           0 :         FeatureSupport( AuthenticationMode _Auth )
      45           0 :             :eAuthentication( _Auth )
      46             :         {
      47           0 :         }
      48             :     };
      49             : 
      50             :     struct FeatureMapping
      51             :     {
      52             :         /// one of the items from dsitems.hxx
      53             :         ItemID          nItemID;
      54             :         const sal_Char* pAsciiFeatureName;
      55             :     };
      56             : 
      57             :     // global tables
      58           0 :     static const FeatureMapping* lcl_getFeatureMappings()
      59             :     {
      60             :         static const FeatureMapping s_aMappings[] = {
      61             :             { DSID_AUTORETRIEVEENABLED,     "GeneratedValues" },
      62             :             { DSID_AUTOINCREMENTVALUE,      "GeneratedValues" },
      63             :             { DSID_AUTORETRIEVEVALUE,       "GeneratedValues" },
      64             :             { DSID_SQL92CHECK,              "UseSQL92NamingConstraints" },
      65             :             { DSID_APPEND_TABLE_ALIAS,      "AppendTableAliasInSelect" },
      66             :             { DSID_AS_BEFORE_CORRNAME,      "UseKeywordAsBeforeAlias" },
      67             :             { DSID_ENABLEOUTERJOIN,         "UseBracketedOuterJoinSyntax" },
      68             :             { DSID_IGNOREDRIVER_PRIV,       "IgnoreDriverPrivileges" },
      69             :             { DSID_PARAMETERNAMESUBST,      "ParameterNameSubstitution" },
      70             :             { DSID_SUPPRESSVERSIONCL,       "DisplayVersionColumns" },
      71             :             { DSID_CATALOG,                 "UseCatalogInSelect" },
      72             :             { DSID_SCHEMA,                  "UseSchemaInSelect" },
      73             :             { DSID_INDEXAPPENDIX,           "UseIndexDirectionKeyword" },
      74             :             { DSID_DOSLINEENDS,             "UseDOSLineEnds" },
      75             :             { DSID_BOOLEANCOMPARISON,       "BooleanComparisonMode" },
      76             :             { DSID_CHECK_REQUIRED_FIELDS,   "FormsCheckRequiredFields" },
      77             :             { DSID_IGNORECURRENCY,          "IgnoreCurrency" },
      78             :             { DSID_ESCAPE_DATETIME,         "EscapeDateTime" },
      79             :             { DSID_PRIMARY_KEY_SUPPORT,     "PrimaryKeySupport" },
      80             :             { DSID_RESPECTRESULTSETTYPE,    "RespectDriverResultSetType" },
      81             :             { DSID_MAX_ROW_SCAN,            "MaxRowScan" },
      82             :             { 0, NULL }
      83             :         };
      84           0 :         return s_aMappings;
      85             :     }
      86             : 
      87           0 :     static const FeatureSet& lcl_getFeatureSet( const OUString& _rURL )
      88             :     {
      89             :         typedef ::std::map< OUString, FeatureSet > FeatureSets;
      90           0 :         static FeatureSets s_aFeatureSets;
      91           0 :         if ( s_aFeatureSets.empty() )
      92             :         {
      93           0 :             ::connectivity::DriversConfig aDriverConfig( ::comphelper::getProcessComponentContext() );
      94           0 :             const uno::Sequence< OUString > aPatterns = aDriverConfig.getURLs();
      95           0 :             for (   const OUString* pattern = aPatterns.getConstArray();
      96           0 :                     pattern != aPatterns.getConstArray() + aPatterns.getLength();
      97             :                     ++pattern
      98             :                 )
      99             :             {
     100           0 :                 FeatureSet aCurrentSet;
     101           0 :                 const ::comphelper::NamedValueCollection aCurrentFeatures( aDriverConfig.getFeatures( *pattern ).getNamedValues() );
     102             : 
     103           0 :                 const FeatureMapping* pFeatureMapping = lcl_getFeatureMappings();
     104           0 :                 while ( pFeatureMapping->pAsciiFeatureName )
     105             :                 {
     106           0 :                     if ( aCurrentFeatures.has( pFeatureMapping->pAsciiFeatureName ) )
     107           0 :                         aCurrentSet.put( pFeatureMapping->nItemID );
     108           0 :                     ++pFeatureMapping;
     109             :                 }
     110             : 
     111           0 :                 s_aFeatureSets[ *pattern ] = aCurrentSet;
     112           0 :             }
     113             :         }
     114             : 
     115             :         OSL_ENSURE( s_aFeatureSets.find( _rURL ) != s_aFeatureSets.end(), "invalid URL/pattern!" );
     116           0 :         return s_aFeatureSets[ _rURL ];
     117             :     }
     118             : 
     119           0 :     static AuthenticationMode getAuthenticationMode( const OUString& _sURL )
     120             :     {
     121           0 :         static std::map< OUString, FeatureSupport > s_aSupport;
     122           0 :         if ( s_aSupport.empty() )
     123             :         {
     124           0 :             ::connectivity::DriversConfig aDriverConfig(::comphelper::getProcessComponentContext());
     125           0 :             const uno::Sequence< OUString > aURLs = aDriverConfig.getURLs();
     126           0 :             const OUString* pIter = aURLs.getConstArray();
     127           0 :             const OUString* pEnd = pIter + aURLs.getLength();
     128           0 :             for(;pIter != pEnd;++pIter)
     129             :             {
     130           0 :                 FeatureSupport aInit( AuthNone );
     131           0 :                 const ::comphelper::NamedValueCollection& aMetaData = aDriverConfig.getMetaData(*pIter);
     132           0 :                 if ( aMetaData.has("Authentication") )
     133             :                 {
     134           0 :                     OUString sAuth;
     135           0 :                     aMetaData.get("Authentication") >>= sAuth;
     136           0 :                     if ( sAuth == "UserPassword" )
     137           0 :                         aInit = AuthUserPwd;
     138           0 :                     else if ( sAuth == "Password" )
     139           0 :                         aInit = AuthPwd;
     140             :                 }
     141           0 :                 s_aSupport.insert(std::make_pair(*pIter,aInit));
     142           0 :             }
     143             :         }
     144             :         OSL_ENSURE(s_aSupport.find(_sURL) != s_aSupport.end(),"Illegal URL!");
     145           0 :         return s_aSupport[ _sURL ].eAuthentication;
     146             :     }
     147             : 
     148             :     // DataSourceMetaData_Impl
     149           0 :     class DataSourceMetaData_Impl
     150             :     {
     151             :     public:
     152             :         DataSourceMetaData_Impl( const OUString& _sURL );
     153             : 
     154           0 :         inline OUString getType() const { return m_sURL; }
     155             : 
     156             :     private:
     157             :         const OUString m_sURL;
     158             :     };
     159             : 
     160           0 :     DataSourceMetaData_Impl::DataSourceMetaData_Impl( const OUString& _sURL )
     161           0 :         :m_sURL( _sURL )
     162             :     {
     163           0 :     }
     164             : 
     165             :     // DataSourceMetaData
     166           0 :     DataSourceMetaData::DataSourceMetaData( const OUString& _sURL )
     167           0 :         :m_pImpl( new DataSourceMetaData_Impl( _sURL ) )
     168             :     {
     169           0 :     }
     170             : 
     171           0 :     DataSourceMetaData::~DataSourceMetaData()
     172             :     {
     173           0 :     }
     174             : 
     175           0 :     const FeatureSet& DataSourceMetaData::getFeatureSet() const
     176             :     {
     177           0 :         return lcl_getFeatureSet( m_pImpl->getType() );
     178             :     }
     179             : 
     180           0 :     AuthenticationMode  DataSourceMetaData::getAuthentication( const OUString& _sURL )
     181             :     {
     182           0 :         return getAuthenticationMode( _sURL );
     183             :     }
     184             : 
     185             : } // namespace dbaui
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10