1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "dsmeta.hxx" 29*cdf0e10cSrcweir #include <connectivity/DriversConfig.hxx> 30*cdf0e10cSrcweir #include "dsntypes.hxx" 31*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 32*cdf0e10cSrcweir /** === begin UNO includes === **/ 33*cdf0e10cSrcweir /** === end UNO includes === **/ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <map> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir //........................................................................ 38*cdf0e10cSrcweir namespace dbaui 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir //........................................................................ 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir /** === begin UNO using === **/ 43*cdf0e10cSrcweir using namespace dbaccess; 44*cdf0e10cSrcweir using namespace ::com::sun::star; 45*cdf0e10cSrcweir /** === end UNO using === **/ 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir struct FeatureSupport 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir // authentication mode of the data source 50*cdf0e10cSrcweir AuthenticationMode eAuthentication; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir FeatureSupport() 53*cdf0e10cSrcweir :eAuthentication( AuthUserPwd ) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir FeatureSupport( AuthenticationMode _Auth ) 58*cdf0e10cSrcweir :eAuthentication( _Auth ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir }; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir struct FeatureMapping 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir /// one of the items from dsitems.hxx 66*cdf0e10cSrcweir ItemID nItemID; 67*cdf0e10cSrcweir const sal_Char* pAsciiFeatureName; 68*cdf0e10cSrcweir }; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir //==================================================================== 71*cdf0e10cSrcweir //= global tables 72*cdf0e10cSrcweir //==================================================================== 73*cdf0e10cSrcweir //-------------------------------------------------------------------- 74*cdf0e10cSrcweir static const FeatureMapping* lcl_getFeatureMappings() 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir static const FeatureMapping s_aMappings[] = { 77*cdf0e10cSrcweir { DSID_AUTORETRIEVEENABLED, "GeneratedValues" }, 78*cdf0e10cSrcweir { DSID_AUTOINCREMENTVALUE, "GeneratedValues" }, 79*cdf0e10cSrcweir { DSID_AUTORETRIEVEVALUE, "GeneratedValues" }, 80*cdf0e10cSrcweir { DSID_SQL92CHECK, "UseSQL92NamingConstraints" }, 81*cdf0e10cSrcweir { DSID_APPEND_TABLE_ALIAS, "AppendTableAliasInSelect" }, 82*cdf0e10cSrcweir { DSID_AS_BEFORE_CORRNAME, "UseKeywordAsBeforeAlias" }, 83*cdf0e10cSrcweir { DSID_ENABLEOUTERJOIN, "UseBracketedOuterJoinSyntax" }, 84*cdf0e10cSrcweir { DSID_IGNOREDRIVER_PRIV, "IgnoreDriverPrivileges" }, 85*cdf0e10cSrcweir { DSID_PARAMETERNAMESUBST, "ParameterNameSubstitution" }, 86*cdf0e10cSrcweir { DSID_SUPPRESSVERSIONCL, "DisplayVersionColumns" }, 87*cdf0e10cSrcweir { DSID_CATALOG, "UseCatalogInSelect" }, 88*cdf0e10cSrcweir { DSID_SCHEMA, "UseSchemaInSelect" }, 89*cdf0e10cSrcweir { DSID_INDEXAPPENDIX, "UseIndexDirectionKeyword" }, 90*cdf0e10cSrcweir { DSID_DOSLINEENDS, "UseDOSLineEnds" }, 91*cdf0e10cSrcweir { DSID_BOOLEANCOMPARISON, "BooleanComparisonMode" }, 92*cdf0e10cSrcweir { DSID_CHECK_REQUIRED_FIELDS, "FormsCheckRequiredFields" }, 93*cdf0e10cSrcweir { DSID_IGNORECURRENCY, "IgnoreCurrency" }, 94*cdf0e10cSrcweir { DSID_ESCAPE_DATETIME, "EscapeDateTime" }, 95*cdf0e10cSrcweir { DSID_PRIMARY_KEY_SUPPORT, "PrimaryKeySupport" }, 96*cdf0e10cSrcweir { DSID_RESPECTRESULTSETTYPE, "RespectDriverResultSetType" }, 97*cdf0e10cSrcweir { DSID_MAX_ROW_SCAN, "MaxRowScan" }, 98*cdf0e10cSrcweir { 0, NULL } 99*cdf0e10cSrcweir }; 100*cdf0e10cSrcweir return s_aMappings; 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir //-------------------------------------------------------------------- 104*cdf0e10cSrcweir static const FeatureSet& lcl_getFeatureSet( const ::rtl::OUString _rURL ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir typedef ::std::map< ::rtl::OUString, FeatureSet, ::comphelper::UStringLess > FeatureSets; 107*cdf0e10cSrcweir static FeatureSets s_aFeatureSets; 108*cdf0e10cSrcweir if ( s_aFeatureSets.empty() ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir ::connectivity::DriversConfig aDriverConfig( ::comphelper::getProcessServiceFactory() ); 111*cdf0e10cSrcweir const uno::Sequence< ::rtl::OUString > aPatterns = aDriverConfig.getURLs(); 112*cdf0e10cSrcweir for ( const ::rtl::OUString* pattern = aPatterns.getConstArray(); 113*cdf0e10cSrcweir pattern != aPatterns.getConstArray() + aPatterns.getLength(); 114*cdf0e10cSrcweir ++pattern 115*cdf0e10cSrcweir ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir FeatureSet aCurrentSet; 118*cdf0e10cSrcweir const ::comphelper::NamedValueCollection aCurrentFeatures( aDriverConfig.getFeatures( *pattern ).getNamedValues() ); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir const FeatureMapping* pFeatureMapping = lcl_getFeatureMappings(); 121*cdf0e10cSrcweir while ( pFeatureMapping->pAsciiFeatureName ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir if ( aCurrentFeatures.has( pFeatureMapping->pAsciiFeatureName ) ) 124*cdf0e10cSrcweir aCurrentSet.put( pFeatureMapping->nItemID ); 125*cdf0e10cSrcweir ++pFeatureMapping; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir s_aFeatureSets[ *pattern ] = aCurrentSet; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir OSL_ENSURE( s_aFeatureSets.find( _rURL ) != s_aFeatureSets.end(), "invalid URL/pattern!" ); 133*cdf0e10cSrcweir return s_aFeatureSets[ _rURL ]; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //-------------------------------------------------------------------- 137*cdf0e10cSrcweir static AuthenticationMode getAuthenticationMode( const ::rtl::OUString& _sURL ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir DECLARE_STL_USTRINGACCESS_MAP( FeatureSupport, Supported); 140*cdf0e10cSrcweir static Supported s_aSupport; 141*cdf0e10cSrcweir if ( s_aSupport.empty() ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir ::connectivity::DriversConfig aDriverConfig(::comphelper::getProcessServiceFactory()); 144*cdf0e10cSrcweir const uno::Sequence< ::rtl::OUString > aURLs = aDriverConfig.getURLs(); 145*cdf0e10cSrcweir const ::rtl::OUString* pIter = aURLs.getConstArray(); 146*cdf0e10cSrcweir const ::rtl::OUString* pEnd = pIter + aURLs.getLength(); 147*cdf0e10cSrcweir for(;pIter != pEnd;++pIter) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir FeatureSupport aInit( AuthNone ); 150*cdf0e10cSrcweir const ::comphelper::NamedValueCollection& aMetaData = aDriverConfig.getMetaData(*pIter); 151*cdf0e10cSrcweir if ( aMetaData.has("Authentication") ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir ::rtl::OUString sAuth; 154*cdf0e10cSrcweir aMetaData.get("Authentication") >>= sAuth; 155*cdf0e10cSrcweir if ( sAuth.equalsAscii("UserPassword") ) 156*cdf0e10cSrcweir aInit = AuthUserPwd; 157*cdf0e10cSrcweir else if ( sAuth.equalsAscii("Password") ) 158*cdf0e10cSrcweir aInit = AuthPwd; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir s_aSupport.insert(Supported::value_type(*pIter,aInit)); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir OSL_ENSURE(s_aSupport.find(_sURL) != s_aSupport.end(),"Illegal URL!"); 164*cdf0e10cSrcweir return s_aSupport[ _sURL ].eAuthentication; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir //==================================================================== 168*cdf0e10cSrcweir //= DataSourceMetaData_Impl 169*cdf0e10cSrcweir //==================================================================== 170*cdf0e10cSrcweir class DataSourceMetaData_Impl 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir public: 173*cdf0e10cSrcweir DataSourceMetaData_Impl( const ::rtl::OUString& _sURL ); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir inline ::rtl::OUString getType() const { return m_sURL; } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir private: 178*cdf0e10cSrcweir const ::rtl::OUString m_sURL; 179*cdf0e10cSrcweir }; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir //-------------------------------------------------------------------- 182*cdf0e10cSrcweir DataSourceMetaData_Impl::DataSourceMetaData_Impl( const ::rtl::OUString& _sURL ) 183*cdf0e10cSrcweir :m_sURL( _sURL ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir //==================================================================== 188*cdf0e10cSrcweir //= DataSourceMetaData 189*cdf0e10cSrcweir //==================================================================== 190*cdf0e10cSrcweir //-------------------------------------------------------------------- 191*cdf0e10cSrcweir DataSourceMetaData::DataSourceMetaData( const ::rtl::OUString& _sURL ) 192*cdf0e10cSrcweir :m_pImpl( new DataSourceMetaData_Impl( _sURL ) ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir //-------------------------------------------------------------------- 197*cdf0e10cSrcweir DataSourceMetaData::~DataSourceMetaData() 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir //-------------------------------------------------------------------- 202*cdf0e10cSrcweir const FeatureSet& DataSourceMetaData::getFeatureSet() const 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir return lcl_getFeatureSet( m_pImpl->getType() ); 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir //-------------------------------------------------------------------- 208*cdf0e10cSrcweir AuthenticationMode DataSourceMetaData::getAuthentication( const ::rtl::OUString& _sURL ) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir return getAuthenticationMode( _sURL ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir //........................................................................ 214*cdf0e10cSrcweir } // namespace dbaui 215*cdf0e10cSrcweir //........................................................................ 216