20#include <config_java.h>
25#include <osl/diagnose.h>
27#include <osl/file.hxx>
28#include <officecfg/Office/Common.hxx>
42 void lcl_extractHostAndPort(std::u16string_view _sUrl, OUString& _sHostname, sal_Int32& _nPortNumber)
55#
if OSL_DEBUG_LEVEL > 0
60 const OUString* pIter = aURLs.getConstArray();
61 const OUString* pEnd = pIter + aURLs.getLength();
62 for(;pIter != pEnd;++pIter )
69 "ODsnTypeCollection::ODsnTypeCollection : invalid resources !");
74#if OSL_DEBUG_LEVEL > 0
75 OSL_ENSURE(0 ==
m_nLivingIterators,
"ODsnTypeCollection::~ODsnTypeCollection : there are still living iterator objects!");
95 if ( sOldPattern.getLength() < dsnPrefix.getLength() && aWildCard.
Matches(sCleanURL) )
102 sRet = sCleanURL.substr(
prefix.getLength());
103 sOldPattern = dsnPrefix;
113 OUString sOldPattern;
117 if ( sOldPattern.getLength() < dsnPrefix.getLength() && aWildCard.
Matches(_sURL) )
123 OSL_ENSURE(sRet.getLength() <=
static_cast<sal_Int32
>(_sURL.size()),
"How can A match B when A shorter than B?");
124 sOldPattern = dsnPrefix;
133 OUString
sPrefix(
getPrefix( OUString::createFromAscii( _pAsciiPattern ) ) );
140 OUString sOldPattern;
144 if ( sOldPattern.getLength() < dsnPrefix.getLength() && aWildCard.
Matches(_sURL) )
147 sOldPattern = dsnPrefix;
150 return !sRet.isEmpty() && sRet[sRet.getLength()-1] ==
'*';
161 OUString sURL, sFallbackURL;
163 const OUString* pIter = aURLs.getConstArray();
164 const OUString* pEnd = pIter + aURLs.getLength();
165 for(;pIter != pEnd;++pIter )
168 if ( aFeatures.getOrDefault(
"MediaType",OUString()) == _sMediaType )
170 const OUString sFileExtension = aFeatures.
getOrDefault(
"Extension",OUString());
171 if ( _sExtension == sFileExtension )
176 if ( sFileExtension.isEmpty() && !_sExtension.empty() )
177 sFallbackURL = *pIter;
181 if ( sURL.isEmpty() && !sFallbackURL.isEmpty() )
190 return !( _sURL.startsWithIgnoreAsciiCase(
"sdbc:embedded:hsqldb")
191 || _sURL.startsWithIgnoreAsciiCase(
"sdbc:embedded:firebird")
192 || _sURL.startsWithIgnoreAsciiCase(
"sdbc:address:outlook")
193 || _sURL.startsWithIgnoreAsciiCase(
"sdbc:address:outlookexp")
194 || _sURL.startsWithIgnoreAsciiCase(
"sdbc:address:mozilla:")
195 || _sURL.startsWithIgnoreAsciiCase(
"sdbc:address:kab")
196 || _sURL.startsWithIgnoreAsciiCase(
"sdbc:address:evolution:local")
197 || _sURL.startsWithIgnoreAsciiCase(
"sdbc:address:evolution:groupwise")
198 || _sURL.startsWithIgnoreAsciiCase(
"sdbc:address:evolution:ldap")
199 || _sURL.startsWithIgnoreAsciiCase(
"sdbc:address:macab") );
205 if ( _rDsn.startsWithIgnoreAsciiCase(
"jdbc:oracle:thin:") )
207 lcl_extractHostAndPort(sUrl,_rsHostname,_nPortNumber);
209 if ( _rsHostname.isEmpty() && nUrlTokens == 2 )
212 _rsHostname = sUrl.getToken(0,
':');
214 if ( !_rsHostname.isEmpty() )
215 _rsHostname = _rsHostname.copy(_rsHostname.lastIndexOf(
'@')+1);
216 _sDatabaseName = sUrl.copy(sUrl.lastIndexOf(
':')+1);
218 else if ( _rDsn.startsWithIgnoreAsciiCase(
"sdbc:address:ldap:") )
220 lcl_extractHostAndPort(sUrl,_sDatabaseName,_nPortNumber);
222 else if ( _rDsn.startsWithIgnoreAsciiCase(
"sdbc:mysql:mysqlc:")
223 || _rDsn.startsWithIgnoreAsciiCase(
"sdbc:mysql:jdbc:") )
225 lcl_extractHostAndPort(sUrl,_rsHostname,_nPortNumber);
228 if ( _nPortNumber == -1 && _rsHostname.isEmpty() && nUrlTokens == 2 )
229 _rsHostname = sUrl.getToken(0,
'/');
230 _sDatabaseName = sUrl.copy(sUrl.lastIndexOf(
'/')+1);
232 else if ( _rDsn.startsWithIgnoreAsciiCase(
"sdbc:ado:access:Provider=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=")
233 || _rDsn.startsWithIgnoreAsciiCase(
"sdbc:ado:access:PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=") )
235 OUString sNewFileName;
236 if ( ::osl::FileBase::getFileURLFromSystemPath( sUrl, sNewFileName ) == ::osl::FileBase::E_None )
238 _sDatabaseName = sNewFileName;
246 return aFeatures.
getOrDefault(
"JavaDriverClass",OUString());
258 return aFeatures.
getOrDefault(
"SupportsTableCreation",
false);
264 return aFeatures.
getOrDefault(
"SupportsColumnDescription",
false);
270 return aFeatures.
getOrDefault(
"SupportsBrowsing",
false);
276 return aFeatures.
getOrDefault(
"SupportsDBCreation",
false);
292 if (!HAVE_FEATURE_JAVA || officecfg::Office::Common::Misc::ExperimentalMode::get())
293 return "sdbc:embedded:firebird";
295 return "sdbc:embedded:hsqldb";
302 sal_Int32 nSeparator = sDsn.indexOf(
u':');
303 if (-1 == nSeparator)
308 OSL_FAIL(
"ODsnTypeCollection::implDetermineType : missing the colon !");
315 if (sDsn.startsWithIgnoreAsciiCase(
"jdbc:oracle:thin:"))
318 if (sDsn.startsWithIgnoreAsciiCase(
"jdbc:"))
321 if (sDsn.equalsIgnoreAsciiCase(
"sdbc:embedded:hsqldb"))
324 if (sDsn.equalsIgnoreAsciiCase(
"sdbc:embedded:firebird"))
327 if (sDsn.startsWithIgnoreAsciiCase(
"sdbc:embedded:"))
331 nSeparator = sDsn.indexOf(
u':', nSeparator + 1);
332 if (-1 == nSeparator)
335 OSL_FAIL(
"ODsnTypeCollection::implDetermineType : missing the second colon !");
339 if (sDsn.startsWithIgnoreAsciiCase(
"sdbc:ado:"))
341 if (sDsn.startsWithIgnoreAsciiCase(
"sdbc:ado:access:"))
343 if (sDsn.startsWithIgnoreAsciiCase(
"sdbc:ado:access:Provider=Microsoft.ACE.OLEDB.12.0;"))
355 const bool bMatchComplete;
360 ,bMatchComplete( _m )
364 bool match(
const OUString &url)
const
368 return url.equalsIgnoreAsciiCase(
sPrefix);
372 return url.startsWithIgnoreAsciiCase(
sPrefix);
376 const KnownPrefix aKnowPrefixes[] =
378 KnownPrefix(
"sdbc:calc:",
DST_CALC,
false ),
379 KnownPrefix(
"sdbc:writer:",
DST_WRITER,
false ),
380 KnownPrefix(
"sdbc:flat:",
DST_FLAT,
false ),
381 KnownPrefix(
"sdbc:odbc:",
DST_ODBC,
false ),
382 KnownPrefix(
"sdbc:dbase:",
DST_DBASE,
false ),
390 KnownPrefix(
"sdbc:address:mozilla:",
DST_MOZILLA,
true ),
392 KnownPrefix(
"sdbc:address:ldap:",
DST_LDAP,
true ),
393 KnownPrefix(
"sdbc:address:outlook",
DST_OUTLOOK,
true ),
397 KnownPrefix(
"sdbc:address:evolution:local",
DST_EVOLUTION,
true ),
398 KnownPrefix(
"sdbc:address:kab",
DST_KAB,
true ),
399 KnownPrefix(
"sdbc:address:macab",
DST_MACAB,
true )
402 for (
const auto & aKnowPrefixe : aKnowPrefixes)
404 if( aKnowPrefixe.match(sDsn) )
406 return aKnowPrefixe.eType;
483 OUString sOldPattern;
487 if ( sOldPattern.getLength() < dsnPrefix.getLength() && aWildCard.
Matches(_sURL) )
489 sOldPattern = dsnPrefix;
498 OUString sOldPattern;
503 if ( sOldPattern.getLength() < dsnPrefix.getLength() && aWildCard.
Matches(_sURL) )
506 sOldPattern = dsnPrefix;
520ODsnTypeCollection::TypeIterator::TypeIterator(
const ODsnTypeCollection* _pContainer, sal_Int32 _nInitialPos)
521 :m_pContainer(_pContainer)
524 OSL_ENSURE(
m_pContainer,
"ODsnTypeCollection::TypeIterator::TypeIterator : invalid container!");
525#if OSL_DEBUG_LEVEL > 0
530ODsnTypeCollection::TypeIterator::TypeIterator(
const TypeIterator& _rSource)
531 :m_pContainer(_rSource.m_pContainer)
534#if OSL_DEBUG_LEVEL > 0
539ODsnTypeCollection::TypeIterator::~TypeIterator()
541#if OSL_DEBUG_LEVEL > 0
542 --
const_cast<ODsnTypeCollection*
>(m_pContainer)->m_nLivingIterators;
546OUString
const & ODsnTypeCollection::TypeIterator::getDisplayName()
const
548 OSL_ENSURE(m_nPosition <
static_cast<sal_Int32
>(m_pContainer->m_aDsnTypesDisplayNames.size()),
"ODsnTypeCollection::TypeIterator::getDisplayName : invalid position!");
549 return m_pContainer->m_aDsnTypesDisplayNames[
m_nPosition];
552OUString
const & ODsnTypeCollection::TypeIterator::getURLPrefix()
const
554 OSL_ENSURE(m_nPosition <
static_cast<sal_Int32
>(m_pContainer->m_aDsnPrefixes.size()),
"ODsnTypeCollection::TypeIterator::getDisplayName : invalid position!");
560 OSL_ENSURE(m_nPosition <
static_cast<sal_Int32
>(m_pContainer->m_aDsnTypesDisplayNames.size()),
"ODsnTypeCollection::TypeIterator::operator++ : invalid position!");
561 if (m_nPosition <
static_cast<sal_Int32
>(m_pContainer->m_aDsnTypesDisplayNames.size()))
568 return (lhs.m_pContainer == rhs.m_pContainer) && (lhs.m_nPosition == rhs.m_nPosition);
PropertiesInfo aProperties
bool Matches(std::u16string_view rStr) const
VALUE_TYPE getOrDefault(const OUString &_rValueName, const VALUE_TYPE &_rDefault) const
OUString getDriverTypeDisplayName(std::u16string_view _sUrl) const
css::uno::Sequence< OUString > getURLs() const
const ::comphelper::NamedValueCollection & getProperties(std::u16string_view _sURL) const
const ::comphelper::NamedValueCollection & getMetaData(std::u16string_view _sURL) const
std::vector< OUString > m_aDsnTypesDisplayNames
OUString getType(std::u16string_view _sURL) const
DATASOURCE_TYPE determineType(std::u16string_view _rDsn) const
OUString cutPrefix(std::u16string_view _sURL) const
on a given string, cut the type prefix and return the result
static OUString getEmbeddedDatabase()
bool supportsTableCreation(std::u16string_view _sURL) const
check if the given data source allows creation of tables
const ODsnTypeCollection * m_pContainer
bool hasDriver(const char *_pAsciiPattern) const
determines whether there is a driver for the given URL prefix/pattern
static bool isShowPropertiesEnabled(const OUString &_sURL)
bool isFileSystemBased(std::u16string_view _sURL) const
check if the given data source type is based on the file system - i.e. the URL is a prefix plus a fil...
OUString getMediaType(std::u16string_view _sURL) const
returns the media type of a file based database
static bool isEmbeddedDatabase(std::u16string_view _sURL)
checks if the given data source type embeds its data into the database document
OUString getPrefix(std::u16string_view _sURL) const
on a given string, return the type prefix
::connectivity::DriversConfig m_aDriverConfig
DSN prefixes which determine the type of a datasource.
bool supportsDBCreation(std::u16string_view _sURL) const
void fillPageIds(std::u16string_view _sURL, std::vector< sal_Int16 > &_rOutPathIds) const
friend class ODsnTypeCollection
OUString getTypeDisplayName(std::u16string_view _sURL) const
get the datasource type display name from a DSN string
sal_Int32 m_nLivingIterators
std::vector< OUString > m_aDsnPrefixes
user readable names for the datasource types
css::uno::Sequence< css::beans::PropertyValue > getDefaultDBSettings(std::u16string_view _sURL) const
returns default settings for newly created databases of the given type.
OUString getDatasourcePrefixFromMediaType(std::u16string_view _sMediaType, std::u16string_view _sExtension)
returns the dsn prefix for a given media type
void extractHostNamePort(const OUString &_rDsn, OUString &_sDatabaseName, OUString &_rHostname, sal_Int32 &_nPortNumber) const
bool supportsBrowsing(std::u16string_view _sURL) const
bool isConnectionUrlRequired(std::u16string_view _sURL) const
bool supportsColumnDescription(std::u16string_view _sURL) const
check if the given data source allows to show column description.
sal_Int32 getIndexOf(std::u16string_view _sURL) const
OUString getJavaDriverClass(std::u16string_view _sURL) const
on a given string, return the Java Driver Class
TypeIterator(const TypeIterator &_rSource)
#define PAGE_DBSETUPWIZARD_ADO
#define PAGE_DBSETUPWIZARD_MYSQL_INTRO
#define PAGE_DBSETUPWIZARD_MYSQL_NATIVE
#define PAGE_DBSETUPWIZARD_MSACCESS
#define PAGE_DBSETUPWIZARD_POSTGRES
#define PAGE_DBSETUPWIZARD_JDBC
#define PAGE_DBSETUPWIZARD_MYSQL_JDBC
#define PAGE_DBSETUPWIZARD_DOCUMENT_OR_SPREADSHEET
#define PAGE_DBSETUPWIZARD_LDAP
#define PAGE_DBSETUPWIZARD_DBASE
#define PAGE_DBSETUPWIZARD_MYSQL_ODBC
#define PAGE_DBSETUPWIZARD_USERDEFINED
#define PAGE_DBSETUPWIZARD_TEXT
#define PAGE_DBSETUPWIZARD_ODBC
#define PAGE_DBSETUPWIZARD_ORACLE
if(aStr !=aBuf) UpdateName_Impl(m_xFollowLb.get()
OString stripEnd(const OString &rIn, char c)
OString stripStart(const OString &rIn, char c)
sal_Int32 getTokenCount(std::string_view rIn, char cTok)
bool match(const sal_Unicode *pWild, const sal_Unicode *pStr, const sal_Unicode cEscape)
bool operator==(const ODsnTypeCollection::TypeIterator &lhs, const ODsnTypeCollection::TypeIterator &rhs)
DATASOURCE_TYPE
known datasource types
@ DST_EVOLUTION_GROUPWISE
@ DST_UNKNOWN
unrecognized type
@ DST_MYSQL_NATIVE_DIRECT
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
Reference< XComponentContext > _xContext