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

Generated by: LCOV version 1.10