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