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 :
21 : #include "dsntypes.hxx"
22 : #include "dbamiscres.hrc"
23 : #include <unotools/confignode.hxx>
24 : #include <tools/debug.hxx>
25 : #include <osl/diagnose.h>
26 : #include <tools/wldcrd.hxx>
27 : #include <osl/file.hxx>
28 : #include "dbastrings.hrc"
29 : #include "core_resource.hxx"
30 : #include "core_resource.hrc"
31 : #include <comphelper/documentconstants.hxx>
32 : #include <comphelper/string.hxx>
33 :
34 : //.........................................................................
35 : namespace dbaccess
36 : {
37 : //.........................................................................
38 :
39 : using namespace ::com::sun::star;
40 : using namespace ::com::sun::star::uno;
41 : using namespace ::com::sun::star::beans;
42 : using namespace ::com::sun::star::lang;
43 :
44 : namespace
45 : {
46 0 : void lcl_extractHostAndPort(const String& _sUrl,String& _sHostname,sal_Int32& _nPortNumber)
47 : {
48 0 : if ( comphelper::string::getTokenCount(_sUrl, ':') >= 2 )
49 : {
50 0 : _sHostname = _sUrl.GetToken(0,':');
51 0 : _nPortNumber = _sUrl.GetToken(1,':').ToInt32();
52 : }
53 0 : }
54 : }
55 : //=========================================================================
56 : //= ODsnTypeCollection
57 : //=========================================================================
58 : DBG_NAME(ODsnTypeCollection)
59 : //-------------------------------------------------------------------------
60 0 : ODsnTypeCollection::ODsnTypeCollection(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xFactory)
61 : :m_aDriverConfig(_xFactory)
62 0 : ,m_xFactory(_xFactory)
63 : #if OSL_DEBUG_LEVEL > 0
64 : ,m_nLivingIterators(0)
65 : #endif
66 : {
67 : DBG_CTOR(ODsnTypeCollection,NULL);
68 0 : const uno::Sequence< ::rtl::OUString > aURLs = m_aDriverConfig.getURLs();
69 0 : const ::rtl::OUString* pIter = aURLs.getConstArray();
70 0 : const ::rtl::OUString* pEnd = pIter + aURLs.getLength();
71 0 : for(;pIter != pEnd;++pIter )
72 : {
73 0 : m_aDsnPrefixes.push_back(*pIter);
74 0 : m_aDsnTypesDisplayNames.push_back(m_aDriverConfig.getDriverTypeDisplayName(*pIter));
75 : }
76 :
77 : OSL_ENSURE(m_aDsnTypesDisplayNames.size() == m_aDsnPrefixes.size(),
78 0 : "ODsnTypeCollection::ODsnTypeCollection : invalid resources !");
79 0 : }
80 :
81 : //-------------------------------------------------------------------------
82 0 : ODsnTypeCollection::~ODsnTypeCollection()
83 : {
84 : DBG_DTOR(ODsnTypeCollection,NULL);
85 : OSL_ENSURE(0 == m_nLivingIterators, "ODsnTypeCollection::~ODsnTypeCollection : there are still living iterator objects!");
86 0 : }
87 : //-------------------------------------------------------------------------
88 0 : String ODsnTypeCollection::getTypeDisplayName(const ::rtl::OUString& _sURL) const
89 : {
90 0 : return m_aDriverConfig.getDriverTypeDisplayName(_sURL);
91 : }
92 : //-------------------------------------------------------------------------
93 0 : String ODsnTypeCollection::cutPrefix(const ::rtl::OUString& _sURL) const
94 : {
95 0 : String sURL( _sURL);
96 0 : String sRet;
97 0 : String sOldPattern;
98 0 : StringVector::const_iterator aIter = m_aDsnPrefixes.begin();
99 0 : StringVector::const_iterator aEnd = m_aDsnPrefixes.end();
100 0 : for(;aIter != aEnd;++aIter)
101 : {
102 0 : WildCard aWildCard(*aIter);
103 0 : if ( sOldPattern.Len() < aIter->Len() && aWildCard.Matches(_sURL) )
104 : {
105 0 : if ( aIter->Len() < sURL.Len() )
106 0 : sRet = sURL.Copy(sURL.Match(*aIter));
107 : else
108 0 : sRet = sURL.Copy(aIter->Match(sURL));
109 0 : sOldPattern = *aIter;
110 : }
111 0 : }
112 :
113 0 : return sRet;
114 : }
115 :
116 : //-------------------------------------------------------------------------
117 0 : String ODsnTypeCollection::getPrefix(const ::rtl::OUString& _sURL) const
118 : {
119 0 : String sURL( _sURL);
120 0 : String sRet;
121 0 : String sOldPattern;
122 0 : StringVector::const_iterator aIter = m_aDsnPrefixes.begin();
123 0 : StringVector::const_iterator aEnd = m_aDsnPrefixes.end();
124 0 : for(;aIter != aEnd;++aIter)
125 : {
126 0 : WildCard aWildCard(*aIter);
127 0 : if ( sOldPattern.Len() < aIter->Len() && aWildCard.Matches(sURL) )
128 : {
129 0 : if ( aIter->Len() < sURL.Len() )
130 0 : sRet = aIter->Copy(0,sURL.Match(*aIter));
131 : else
132 0 : sRet = sURL.Copy(0,aIter->Match(sURL));
133 0 : sRet = comphelper::string::stripEnd(sRet, '*');
134 0 : sOldPattern = *aIter;
135 : }
136 0 : }
137 :
138 0 : return sRet;
139 : }
140 :
141 : //-------------------------------------------------------------------------
142 0 : bool ODsnTypeCollection::hasDriver( const sal_Char* _pAsciiPattern ) const
143 : {
144 0 : String sPrefix( getPrefix( ::rtl::OUString::createFromAscii( _pAsciiPattern ) ) );
145 0 : return ( sPrefix.Len() > 0 );
146 : }
147 :
148 : // -----------------------------------------------------------------------------
149 0 : bool ODsnTypeCollection::isConnectionUrlRequired(const ::rtl::OUString& _sURL) const
150 : {
151 0 : String sURL( _sURL);
152 0 : String sRet;
153 0 : String sOldPattern;
154 0 : StringVector::const_iterator aIter = m_aDsnPrefixes.begin();
155 0 : StringVector::const_iterator aEnd = m_aDsnPrefixes.end();
156 0 : for(;aIter != aEnd;++aIter)
157 : {
158 0 : WildCard aWildCard(*aIter);
159 0 : if ( sOldPattern.Len() < aIter->Len() && aWildCard.Matches(sURL) )
160 : {
161 0 : sRet = *aIter;
162 0 : sOldPattern = *aIter;
163 : }
164 0 : }
165 0 : return sRet.Len() > 0 && sRet.GetChar(sRet.Len()-1) == '*';
166 : }
167 : // -----------------------------------------------------------------------------
168 0 : String ODsnTypeCollection::getMediaType(const ::rtl::OUString& _sURL) const
169 : {
170 0 : const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
171 0 : return aFeatures.getOrDefault("MediaType",::rtl::OUString());
172 : }
173 : // -----------------------------------------------------------------------------
174 0 : String ODsnTypeCollection::getDatasourcePrefixFromMediaType(const ::rtl::OUString& _sMediaType,const ::rtl::OUString& _sExtension)
175 : {
176 0 : String sURL, sFallbackURL;
177 0 : const uno::Sequence< ::rtl::OUString > aURLs = m_aDriverConfig.getURLs();
178 0 : const ::rtl::OUString* pIter = aURLs.getConstArray();
179 0 : const ::rtl::OUString* pEnd = pIter + aURLs.getLength();
180 0 : for(;pIter != pEnd;++pIter )
181 : {
182 0 : const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(*pIter);
183 0 : if ( aFeatures.getOrDefault("MediaType",::rtl::OUString()) == _sMediaType )
184 : {
185 0 : const ::rtl::OUString sFileExtension = aFeatures.getOrDefault("Extension",::rtl::OUString());
186 0 : if ( _sExtension == sFileExtension )
187 : {
188 0 : sURL = *pIter;
189 : break;
190 : }
191 0 : if ( sFileExtension.isEmpty() && !_sExtension.isEmpty() )
192 0 : sFallbackURL = *pIter;
193 : }
194 : }
195 :
196 0 : if ( !sURL.Len() && sFallbackURL.Len() )
197 0 : sURL = sFallbackURL;
198 :
199 0 : sURL = comphelper::string::stripEnd(sURL, '*');
200 0 : return sURL;
201 : }
202 : // -----------------------------------------------------------------------------
203 0 : bool ODsnTypeCollection::isShowPropertiesEnabled( const ::rtl::OUString& _sURL ) const
204 : {
205 0 : return !( _sURL.matchIgnoreAsciiCaseAsciiL("sdbc:embedded:hsqldb",sizeof("sdbc:embedded:hsqldb")-1)
206 0 : || _sURL.matchIgnoreAsciiCaseAsciiL("sdbc:address:outlook",sizeof("sdbc:address:outlook")-1)
207 0 : || _sURL.matchIgnoreAsciiCaseAsciiL("sdbc:address:outlookexp",sizeof("sdbc:address:outlookexp")-1)
208 0 : || _sURL.matchIgnoreAsciiCaseAsciiL("sdbc:address:mozilla:",sizeof("sdbc:address:mozilla:")-1)
209 0 : || _sURL.matchIgnoreAsciiCaseAsciiL("sdbc:address:kab",sizeof("sdbc:address:kab")-1)
210 0 : || _sURL.matchIgnoreAsciiCaseAsciiL("sdbc:address:evolution:local",sizeof("sdbc:address:evolution:local")-1)
211 0 : || _sURL.matchIgnoreAsciiCaseAsciiL("sdbc:address:evolution:groupwise",sizeof("sdbc:address:evolution:groupwise")-1)
212 0 : || _sURL.matchIgnoreAsciiCaseAsciiL("sdbc:address:evolution:ldap",sizeof("sdbc:address:evolution:ldap")-1)
213 0 : || _sURL.matchIgnoreAsciiCaseAsciiL("sdbc:address:macab",sizeof("sdbc:address:macab")-1) );
214 : }
215 : // -----------------------------------------------------------------------------
216 0 : void ODsnTypeCollection::extractHostNamePort(const ::rtl::OUString& _rDsn,String& _sDatabaseName,String& _rsHostname,sal_Int32& _nPortNumber) const
217 : {
218 0 : String sUrl = cutPrefix(_rDsn);
219 0 : if ( _rDsn.matchIgnoreAsciiCaseAsciiL("jdbc:oracle:thin:",sizeof("jdbc:oracle:thin:")-1) )
220 : {
221 0 : lcl_extractHostAndPort(sUrl,_rsHostname,_nPortNumber);
222 0 : if ( !_rsHostname.Len() && comphelper::string::getTokenCount(sUrl, ':') == 2 )
223 : {
224 0 : _nPortNumber = -1;
225 0 : _rsHostname = sUrl.GetToken(0,':');
226 : }
227 0 : if ( _rsHostname.Len() )
228 0 : _rsHostname = _rsHostname.GetToken(comphelper::string::getTokenCount(_rsHostname, '@') - 1, '@');
229 0 : _sDatabaseName = sUrl.GetToken(comphelper::string::getTokenCount(sUrl, ':') - 1, ':');
230 : }
231 0 : else if ( _rDsn.matchIgnoreAsciiCaseAsciiL("sdbc:address:ldap:",sizeof("sdbc:address:ldap:")-1) )
232 : {
233 0 : lcl_extractHostAndPort(sUrl,_sDatabaseName,_nPortNumber);
234 : }
235 0 : else if ( _rDsn.matchIgnoreAsciiCaseAsciiL("sdbc:mysql:mysqlc:",sizeof("sdbc:mysql:mysqlc:")-1) || _rDsn.matchIgnoreAsciiCaseAsciiL("sdbc:mysql:jdbc:",sizeof("sdbc:mysql:jdbc:")-1) )
236 : {
237 0 : lcl_extractHostAndPort(sUrl,_rsHostname,_nPortNumber);
238 :
239 0 : if ( _nPortNumber == -1 && !_rsHostname.Len() && comphelper::string::getTokenCount(sUrl, '/') == 2 )
240 0 : _rsHostname = sUrl.GetToken(0,'/');
241 0 : _sDatabaseName = sUrl.GetToken(comphelper::string::getTokenCount(sUrl, '/') - 1, '/');
242 : }
243 0 : else if ( _rDsn.matchIgnoreAsciiCaseAsciiL("sdbc:ado:access:Provider=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=",sizeof("sdbc:ado:access:Provider=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=")-1)
244 0 : || _rDsn.matchIgnoreAsciiCaseAsciiL("sdbc:ado:access:PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=",sizeof("sdbc:ado:access:PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=")-1))
245 : {
246 0 : ::rtl::OUString sNewFileName;
247 0 : if ( ::osl::FileBase::getFileURLFromSystemPath( sUrl, sNewFileName ) == ::osl::FileBase::E_None )
248 : {
249 0 : _sDatabaseName = sNewFileName;
250 0 : }
251 0 : }
252 0 : }
253 : // -----------------------------------------------------------------------------
254 0 : String ODsnTypeCollection::getJavaDriverClass(const ::rtl::OUString& _sURL) const
255 : {
256 0 : const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getProperties(_sURL);
257 0 : return aFeatures.getOrDefault("JavaDriverClass",::rtl::OUString());
258 : }
259 : //-------------------------------------------------------------------------
260 0 : sal_Bool ODsnTypeCollection::isFileSystemBased(const ::rtl::OUString& _sURL) const
261 : {
262 0 : const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
263 0 : return aFeatures.getOrDefault("FileSystemBased",sal_False);
264 : }
265 : // -----------------------------------------------------------------------------
266 0 : sal_Bool ODsnTypeCollection::supportsTableCreation(const ::rtl::OUString& _sURL) const
267 : {
268 0 : const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
269 0 : return aFeatures.getOrDefault("SupportsTableCreation",sal_False);
270 : }
271 : // -----------------------------------------------------------------------------
272 0 : sal_Bool ODsnTypeCollection::supportsColumnDescription(const ::rtl::OUString& _sURL) const
273 : {
274 0 : const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
275 0 : return aFeatures.getOrDefault("SupportsColumnDescription",sal_False);
276 : }
277 : // -----------------------------------------------------------------------------
278 0 : sal_Bool ODsnTypeCollection::supportsBrowsing(const ::rtl::OUString& _sURL) const
279 : {
280 0 : const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
281 0 : return aFeatures.getOrDefault("SupportsBrowsing",sal_False);
282 : }
283 : // -----------------------------------------------------------------------------
284 0 : bool ODsnTypeCollection::needsJVM(const String& _sURL) const
285 : {
286 0 : const ::comphelper::NamedValueCollection& aFeatures = m_aDriverConfig.getMetaData(_sURL);
287 0 : return aFeatures.getOrDefault("UseJava",sal_False);
288 : }
289 : // -----------------------------------------------------------------------------
290 0 : Sequence<PropertyValue> ODsnTypeCollection::getDefaultDBSettings( const ::rtl::OUString& _sURL ) const
291 : {
292 0 : const ::comphelper::NamedValueCollection& aProperties = m_aDriverConfig.getProperties(_sURL);
293 0 : return aProperties.getPropertyValues();
294 : }
295 :
296 : //-------------------------------------------------------------------------
297 0 : bool ODsnTypeCollection::isEmbeddedDatabase( const ::rtl::OUString& _sURL ) const
298 : {
299 0 : const ::rtl::OUString sEmbeddedDatabaseURL = getEmbeddedDatabase();
300 0 : WildCard aWildCard(sEmbeddedDatabaseURL);
301 0 : return aWildCard.Matches(_sURL);
302 : }
303 : // -----------------------------------------------------------------------------
304 0 : ::rtl::OUString ODsnTypeCollection::getEmbeddedDatabase() const
305 : {
306 0 : ::rtl::OUString sEmbeddedDatabaseURL;
307 0 : static const ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.DataAccess")); ///Installed
308 0 : const ::utl::OConfigurationTreeRoot aInstalled = ::utl::OConfigurationTreeRoot::createWithServiceFactory(m_xFactory, s_sNodeName, -1, ::utl::OConfigurationTreeRoot::CM_READONLY);
309 0 : if ( aInstalled.isValid() )
310 : {
311 0 : if ( aInstalled.hasByName("EmbeddedDatabases/DefaultEmbeddedDatabase/Value") )
312 : {
313 0 : static const ::rtl::OUString s_sValue(RTL_CONSTASCII_USTRINGPARAM("EmbeddedDatabases/DefaultEmbeddedDatabase/Value"));
314 :
315 0 : aInstalled.getNodeValue(s_sValue) >>= sEmbeddedDatabaseURL;
316 0 : if ( !sEmbeddedDatabaseURL.isEmpty() )
317 0 : aInstalled.getNodeValue(s_sValue + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sEmbeddedDatabaseURL + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/URL"))) >>= sEmbeddedDatabaseURL;
318 : }
319 : }
320 0 : if ( sEmbeddedDatabaseURL.isEmpty() )
321 0 : sEmbeddedDatabaseURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:embedded:hsqldb"));
322 0 : return sEmbeddedDatabaseURL;
323 : }
324 : //-------------------------------------------------------------------------
325 0 : ODsnTypeCollection::TypeIterator ODsnTypeCollection::begin() const
326 : {
327 0 : return TypeIterator(this, 0);
328 : }
329 :
330 : //-------------------------------------------------------------------------
331 0 : ODsnTypeCollection::TypeIterator ODsnTypeCollection::end() const
332 : {
333 0 : return TypeIterator(this, m_aDsnTypesDisplayNames.size());
334 : }
335 : //-------------------------------------------------------------------------
336 0 : DATASOURCE_TYPE ODsnTypeCollection::determineType(const String& _rDsn) const
337 : {
338 0 : String sDsn(comphelper::string::stripEnd(_rDsn, '*'));
339 0 : sal_uInt16 nSeparator = sDsn.Search((sal_Unicode)':');
340 0 : if (STRING_NOTFOUND == nSeparator)
341 : {
342 : // there should be at least one such separator
343 : OSL_FAIL("ODsnTypeCollection::implDetermineType : missing the colon !");
344 0 : return DST_UNKNOWN;
345 : }
346 : // find first :
347 0 : sal_uInt16 nOracleSeparator = sDsn.Search((sal_Unicode)':', nSeparator + 1);
348 0 : if ( nOracleSeparator != STRING_NOTFOUND )
349 : {
350 0 : nOracleSeparator = sDsn.Search((sal_Unicode)':', nOracleSeparator + 1);
351 0 : if (nOracleSeparator != STRING_NOTFOUND && sDsn.EqualsIgnoreCaseAscii("jdbc:oracle:thin", 0, nOracleSeparator))
352 0 : return DST_ORACLE_JDBC;
353 : }
354 :
355 0 : if (sDsn.EqualsIgnoreCaseAscii("jdbc", 0, nSeparator))
356 0 : return DST_JDBC;
357 :
358 0 : if (sDsn.EqualsIgnoreCaseAscii("sdbc:embedded:hsqldb", 0, sDsn.Len()))
359 0 : return DST_EMBEDDED_HSQLDB;
360 :
361 : // find second :
362 0 : nSeparator = sDsn.Search((sal_Unicode)':', nSeparator + 1);
363 0 : if (STRING_NOTFOUND == nSeparator)
364 : {
365 : // at the moment only jdbc is allowed to have just one separator
366 : OSL_FAIL("ODsnTypeCollection::implDetermineType : missing the second colon !");
367 0 : return DST_UNKNOWN;
368 : }
369 :
370 0 : if (sDsn.EqualsIgnoreCaseAscii("sdbc:ado:", 0, nSeparator))
371 : {
372 0 : nSeparator = sDsn.Search((sal_Unicode)':', nSeparator + 1);
373 0 : if (STRING_NOTFOUND != nSeparator && sDsn.EqualsIgnoreCaseAscii("sdbc:ado:access",0, nSeparator) )
374 : {
375 0 : nSeparator = sDsn.Search((sal_Unicode)';', nSeparator + 1);
376 0 : if (STRING_NOTFOUND != nSeparator && sDsn.EqualsIgnoreCaseAscii("sdbc:ado:access:Provider=Microsoft.ACE.OLEDB.12.0",0, nSeparator) )
377 0 : return DST_MSACCESS_2007;
378 :
379 0 : return DST_MSACCESS;
380 : }
381 0 : return DST_ADO;
382 : }
383 :
384 : struct KnownPrefix
385 : {
386 : const sal_Char* pAsciiPrefix;
387 : const DATASOURCE_TYPE eType;
388 : const bool bMatchComplete;
389 :
390 : KnownPrefix()
391 : :pAsciiPrefix( NULL )
392 : ,eType( DST_UNKNOWN )
393 : ,bMatchComplete( false )
394 : {
395 : }
396 0 : KnownPrefix( const sal_Char* _p, const DATASOURCE_TYPE _t, const bool _m )
397 : :pAsciiPrefix( _p )
398 : ,eType ( _t )
399 0 : ,bMatchComplete( _m )
400 : {
401 0 : }
402 : };
403 : KnownPrefix aKnowPrefixes[] =
404 : {
405 : KnownPrefix( "sdbc:calc:", DST_CALC, false ),
406 : KnownPrefix( "sdbc:flat:", DST_FLAT, false ),
407 : KnownPrefix( "sdbc:odbc:", DST_ODBC, false ),
408 : KnownPrefix( "sdbc:dbase:", DST_DBASE, false ),
409 : KnownPrefix( "sdbc:mysql:odbc:", DST_MYSQL_ODBC, false ),
410 : KnownPrefix( "sdbc:mysql:jdbc:", DST_MYSQL_JDBC, false ),
411 : KnownPrefix( "sdbc:mysql:mysqlc:", DST_MYSQL_NATIVE, false ),
412 : KnownPrefix( "sdbc:mysqlc:", DST_MYSQL_NATIVE_DIRECT,false ),
413 :
414 : KnownPrefix( "sdbc:address:mozilla:", DST_MOZILLA, true ),
415 : KnownPrefix( "sdbc:address:thunderbird:", DST_THUNDERBIRD, true ),
416 : KnownPrefix( "sdbc:address:ldap:", DST_LDAP, true ),
417 : KnownPrefix( "sdbc:address:outlook", DST_OUTLOOK, true ),
418 : KnownPrefix( "sdbc:address:outlookexp", DST_OUTLOOKEXP, true ),
419 : KnownPrefix( "sdbc:address:evolution:ldap", DST_EVOLUTION_LDAP, true ),
420 : KnownPrefix( "sdbc:address:evolution:groupwise",DST_EVOLUTION_GROUPWISE,true ),
421 : KnownPrefix( "sdbc:address:evolution:local", DST_EVOLUTION, true ),
422 : KnownPrefix( "sdbc:address:kab", DST_KAB, true ),
423 : KnownPrefix( "sdbc:address:macab", DST_MACAB, true )
424 0 : };
425 :
426 0 : for ( size_t i=0; i < sizeof( aKnowPrefixes ) / sizeof( aKnowPrefixes[0] ); ++i )
427 : {
428 0 : sal_uInt16 nMatchLen = aKnowPrefixes[i].bMatchComplete ? sDsn.Len() : (sal_uInt16)rtl_str_getLength( aKnowPrefixes[i].pAsciiPrefix );
429 0 : if ( sDsn.EqualsIgnoreCaseAscii( aKnowPrefixes[i].pAsciiPrefix, 0, nMatchLen ) )
430 0 : return aKnowPrefixes[i].eType;
431 : }
432 :
433 0 : return DST_UNKNOWN;
434 : }
435 : // -----------------------------------------------------------------------------
436 0 : void ODsnTypeCollection::fillPageIds(const ::rtl::OUString& _sURL,::std::vector<sal_Int16>& _rOutPathIds) const
437 : {
438 0 : DATASOURCE_TYPE eType = determineType(_sURL);
439 0 : switch(eType)
440 : {
441 : case DST_ADO:
442 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_ADO);
443 0 : break;
444 : case DST_DBASE:
445 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_DBASE);
446 0 : break;
447 : case DST_FLAT:
448 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_TEXT);
449 0 : break;
450 : case DST_CALC:
451 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_SPREADSHEET);
452 0 : break;
453 : case DST_ODBC:
454 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_ODBC);
455 0 : break;
456 : case DST_JDBC:
457 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_JDBC);
458 0 : break;
459 : case DST_MYSQL_ODBC:
460 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_INTRO);
461 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_ODBC);
462 0 : break;
463 : case DST_MYSQL_JDBC:
464 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_INTRO);
465 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_JDBC);
466 0 : break;
467 : case DST_MYSQL_NATIVE:
468 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_INTRO);
469 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MYSQL_NATIVE);
470 0 : break;
471 : case DST_ORACLE_JDBC:
472 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_ORACLE);
473 0 : break;
474 : case DST_LDAP:
475 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_LDAP);
476 0 : break;
477 : case DST_MSACCESS:
478 : case DST_MSACCESS_2007:
479 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_MSACCESS);
480 0 : break;
481 : case DST_OUTLOOKEXP:
482 : case DST_OUTLOOK:
483 : case DST_MOZILLA:
484 : case DST_THUNDERBIRD:
485 : case DST_EVOLUTION:
486 : case DST_EVOLUTION_GROUPWISE:
487 : case DST_EVOLUTION_LDAP:
488 : case DST_KAB:
489 : case DST_MACAB:
490 : case DST_EMBEDDED_HSQLDB:
491 0 : break;
492 : default:
493 0 : _rOutPathIds.push_back(PAGE_DBSETUPWIZARD_USERDEFINED);
494 0 : break;
495 : }
496 0 : }
497 : // -----------------------------------------------------------------------------
498 0 : ::rtl::OUString ODsnTypeCollection::getType(const ::rtl::OUString& _sURL) const
499 : {
500 0 : ::rtl::OUString sOldPattern;
501 0 : StringVector::const_iterator aIter = m_aDsnPrefixes.begin();
502 0 : StringVector::const_iterator aEnd = m_aDsnPrefixes.end();
503 0 : for(;aIter != aEnd;++aIter)
504 : {
505 0 : WildCard aWildCard(*aIter);
506 0 : if ( sOldPattern.getLength() < aIter->Len() && aWildCard.Matches(_sURL) )
507 : {
508 0 : sOldPattern = *aIter;
509 : }
510 0 : }
511 0 : return sOldPattern;
512 : }
513 : // -----------------------------------------------------------------------------
514 0 : sal_Int32 ODsnTypeCollection::getIndexOf(const ::rtl::OUString& _sURL) const
515 : {
516 0 : sal_Int32 nRet = -1;
517 0 : String sURL( _sURL);
518 0 : String sOldPattern;
519 0 : StringVector::const_iterator aIter = m_aDsnPrefixes.begin();
520 0 : StringVector::const_iterator aEnd = m_aDsnPrefixes.end();
521 0 : for(sal_Int32 i = 0;aIter != aEnd;++aIter,++i)
522 : {
523 0 : WildCard aWildCard(*aIter);
524 0 : if ( sOldPattern.Len() < aIter->Len() && aWildCard.Matches(sURL) )
525 : {
526 0 : nRet = i;
527 0 : sOldPattern = *aIter;
528 : }
529 0 : }
530 :
531 0 : return nRet;
532 : }
533 : // -----------------------------------------------------------------------------
534 0 : sal_Int32 ODsnTypeCollection::size() const
535 : {
536 0 : return m_aDsnPrefixes.size();
537 : }
538 : //=========================================================================
539 : //= ODsnTypeCollection::TypeIterator
540 : //=========================================================================
541 : //-------------------------------------------------------------------------
542 0 : ODsnTypeCollection::TypeIterator::TypeIterator(const ODsnTypeCollection* _pContainer, sal_Int32 _nInitialPos)
543 : :m_pContainer(_pContainer)
544 0 : ,m_nPosition(_nInitialPos)
545 : {
546 : OSL_ENSURE(m_pContainer, "ODsnTypeCollection::TypeIterator::TypeIterator : invalid container!");
547 : #if OSL_DEBUG_LEVEL > 0
548 : ++const_cast<ODsnTypeCollection*>(m_pContainer)->m_nLivingIterators;
549 : #endif
550 0 : }
551 :
552 : //-------------------------------------------------------------------------
553 0 : ODsnTypeCollection::TypeIterator::TypeIterator(const TypeIterator& _rSource)
554 : :m_pContainer(_rSource.m_pContainer)
555 0 : ,m_nPosition(_rSource.m_nPosition)
556 : {
557 : #if OSL_DEBUG_LEVEL > 0
558 : ++const_cast<ODsnTypeCollection*>(m_pContainer)->m_nLivingIterators;
559 : #endif
560 0 : }
561 :
562 : //-------------------------------------------------------------------------
563 0 : ODsnTypeCollection::TypeIterator::~TypeIterator()
564 : {
565 : #if OSL_DEBUG_LEVEL > 0
566 : --const_cast<ODsnTypeCollection*>(m_pContainer)->m_nLivingIterators;
567 : #endif
568 0 : }
569 :
570 : //-------------------------------------------------------------------------
571 0 : String ODsnTypeCollection::TypeIterator::getDisplayName() const
572 : {
573 : OSL_ENSURE(m_nPosition < (sal_Int32)m_pContainer->m_aDsnTypesDisplayNames.size(), "ODsnTypeCollection::TypeIterator::getDisplayName : invalid position!");
574 0 : return m_pContainer->m_aDsnTypesDisplayNames[m_nPosition];
575 : }
576 : // -----------------------------------------------------------------------------
577 0 : ::rtl::OUString ODsnTypeCollection::TypeIterator::getURLPrefix() const
578 : {
579 : OSL_ENSURE(m_nPosition < (sal_Int32)m_pContainer->m_aDsnPrefixes.size(), "ODsnTypeCollection::TypeIterator::getDisplayName : invalid position!");
580 0 : return m_pContainer->m_aDsnPrefixes[m_nPosition];
581 : }
582 : //-------------------------------------------------------------------------
583 0 : const ODsnTypeCollection::TypeIterator& ODsnTypeCollection::TypeIterator::operator++()
584 : {
585 : OSL_ENSURE(m_nPosition < (sal_Int32)m_pContainer->m_aDsnTypesDisplayNames.size(), "ODsnTypeCollection::TypeIterator::operator++ : invalid position!");
586 0 : if (m_nPosition < (sal_Int32)m_pContainer->m_aDsnTypesDisplayNames.size())
587 0 : ++m_nPosition;
588 0 : return *this;
589 : }
590 :
591 : //-------------------------------------------------------------------------
592 0 : const ODsnTypeCollection::TypeIterator& ODsnTypeCollection::TypeIterator::operator--()
593 : {
594 : OSL_ENSURE(m_nPosition >= 0, "ODsnTypeCollection::TypeIterator::operator-- : invalid position!");
595 0 : if (m_nPosition >= 0)
596 0 : --m_nPosition;
597 0 : return *this;
598 : }
599 :
600 : //-------------------------------------------------------------------------
601 0 : bool operator==(const ODsnTypeCollection::TypeIterator& lhs, const ODsnTypeCollection::TypeIterator& rhs)
602 : {
603 0 : return (lhs.m_pContainer == rhs.m_pContainer) && (lhs.m_nPosition == rhs.m_nPosition);
604 : }
605 :
606 : //.........................................................................
607 : } // namespace dbaccess
608 : //.........................................................................
609 :
610 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|