1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _DBACCESS_DSNTYPES_HXX_ 25 #define _DBACCESS_DSNTYPES_HXX_ 26 27 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 28 29 #include <comphelper/stl_types.hxx> 30 #include "dbadllapi.hxx" 31 #include <tools/string.hxx> 32 #include <connectivity/DriversConfig.hxx> 33 34 //......................................................................... 35 namespace dbaccess 36 { 37 //......................................................................... 38 39 //========================================================================= 40 //= DATASOURCE_TYPE 41 //========================================================================= 42 /// known datasource types 43 enum DATASOURCE_TYPE 44 { 45 DST_MSACCESS = 1, 46 DST_MYSQL_ODBC = 2, 47 DST_MYSQL_JDBC = 3, 48 DST_ORACLE_JDBC = 4, 49 DST_ADABAS = 5, 50 DST_CALC = 6, 51 DST_DBASE = 7, 52 DST_FLAT = 8, 53 DST_JDBC = 9, 54 DST_ODBC = 10, 55 DST_ADO = 11, 56 DST_MOZILLA = 12, 57 DST_THUNDERBIRD = 13, 58 DST_LDAP = 14, 59 DST_OUTLOOK = 15, 60 DST_OUTLOOKEXP = 16, 61 DST_EVOLUTION = 17, 62 DST_EVOLUTION_GROUPWISE = 18, 63 DST_EVOLUTION_LDAP = 19, 64 DST_KAB = 20, 65 DST_MACAB = 21, 66 DST_MSACCESS_2007 = 22, 67 DST_EMBEDDED_HSQLDB = 23, 68 DST_MYSQL_NATIVE = 24, 69 DST_MYSQL_NATIVE_DIRECT = 25, 70 DST_POSTGRESQL_JDBC = 26, 71 72 DST_USERDEFINE1, /// first user defined driver 73 DST_USERDEFINE2, 74 DST_USERDEFINE3, 75 DST_USERDEFINE4, 76 DST_USERDEFINE5, 77 DST_USERDEFINE6, 78 DST_USERDEFINE7, 79 DST_USERDEFINE8, 80 DST_USERDEFINE9, 81 DST_USERDEFINE10, 82 83 84 DST_UNKNOWN /// unrecognized type 85 }; 86 87 #define PAGE_DBSETUPWIZARD_INTRO 0 88 #define PAGE_DBSETUPWIZARD_DBASE 1 89 #define PAGE_DBSETUPWIZARD_TEXT 2 90 #define PAGE_DBSETUPWIZARD_MSACCESS 3 91 #define PAGE_DBSETUPWIZARD_LDAP 4 92 #define PAGE_DBSETUPWIZARD_ADABAS 5 93 #define PAGE_DBSETUPWIZARD_MYSQL_INTRO 6 94 #define PAGE_DBSETUPWIZARD_MYSQL_JDBC 7 95 #define PAGE_DBSETUPWIZARD_MYSQL_ODBC 8 96 #define PAGE_DBSETUPWIZARD_ORACLE 9 97 #define PAGE_DBSETUPWIZARD_JDBC 10 98 #define PAGE_DBSETUPWIZARD_ADO 11 99 #define PAGE_DBSETUPWIZARD_ODBC 12 100 #define PAGE_DBSETUPWIZARD_SPREADSHEET 13 101 #define PAGE_DBSETUPWIZARD_AUTHENTIFICATION 14 102 #define PAGE_DBSETUPWIZARD_MOZILLA 15 103 #define PAGE_DBSETUPWIZARD_FINAL 16 104 #define PAGE_DBSETUPWIZARD_USERDEFINED 17 105 #define PAGE_DBSETUPWIZARD_MYSQL_NATIVE 18 106 107 108 //========================================================================= 109 //= ODsnTypeCollection 110 //========================================================================= 111 class OOO_DLLPUBLIC_DBA ODsnTypeCollection 112 { 113 protected: 114 DECLARE_STL_VECTOR(String, StringVector); 115 116 StringVector m_aDsnTypesDisplayNames; /// user readable names for the datasource types 117 StringVector m_aDsnPrefixes; /// DSN prefixes which determine the type of a datasource 118 ::connectivity::DriversConfig m_aDriverConfig; 119 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; 120 121 #ifdef DBG_UTIL 122 sal_Int32 m_nLivingIterators; /// just for debugging reasons, counts the living iterators 123 #endif 124 125 public: 126 class TypeIterator; 127 friend class ODsnTypeCollection::TypeIterator; 128 129 ODsnTypeCollection(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xFactory); 130 ~ODsnTypeCollection(); 131 132 /// get the datasource type display name from a DSN string 133 String getTypeDisplayName(const ::rtl::OUString& _sURL) const; 134 135 /// on a given string, cut the type prefix and return the result 136 String cutPrefix(const ::rtl::OUString& _sURL) const; 137 138 /// on a given string, return the type prefix 139 String getPrefix(const ::rtl::OUString& _sURL) const; 140 141 /// determines whether there is a driver for the given URL prefix/pattern 142 bool hasDriver( const sal_Char* _pAsciiPattern ) const; 143 144 /// on a given string, return the Java Driver Class 145 String getJavaDriverClass(const ::rtl::OUString& _sURL) const; 146 147 /// returns the media type of a file based database 148 String getMediaType(const ::rtl::OUString& _sURL) const; 149 150 /// returns the dsn prefix for a given media type 151 String getDatasourcePrefixFromMediaType(const ::rtl::OUString& _sMediaType,const ::rtl::OUString& _sExtension = ::rtl::OUString() ); 152 153 void extractHostNamePort(const ::rtl::OUString& _rDsn,String& _sDatabaseName,String& _rHostname,sal_Int32& _nPortNumber) const; 154 155 /// check if the given data source allows creation of tables 156 sal_Bool supportsTableCreation(const ::rtl::OUString& _sURL) const; 157 158 /// check if the given data source allows to show column description. 159 sal_Bool supportsColumnDescription(const ::rtl::OUString& _sURL) const; 160 161 // check if a Browse button may be shown to insert connection url 162 sal_Bool supportsBrowsing(const ::rtl::OUString& _sURL) const; 163 164 /// check if the given data source tyoe is based on the file system - i.e. the URL is a prefix plus a file URL 165 sal_Bool isFileSystemBased(const ::rtl::OUString& _sURL) const; 166 167 bool isConnectionUrlRequired(const ::rtl::OUString& _sURL) const; 168 169 /// checks if the given data source type embeds its data into the database document 170 bool isEmbeddedDatabase( const ::rtl::OUString& _sURL ) const; 171 172 ::rtl::OUString getEmbeddedDatabase() const; 173 174 // returns true when the properties dialog can be shown, otherwise false. 175 bool isShowPropertiesEnabled( const ::rtl::OUString& _sURL ) const; 176 177 /** returns default settings for newly created databases of the given type. 178 */ 179 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> 180 getDefaultDBSettings( const ::rtl::OUString& _sURL ) const; 181 182 /// get access to the first element of the types collection 183 TypeIterator begin() const; 184 /// get access to the (last + 1st) element of the types collection 185 TypeIterator end() const; 186 187 void fillPageIds(const ::rtl::OUString& _sURL,::std::vector<sal_Int16>& _rOutPathIds) const; 188 189 DATASOURCE_TYPE determineType(const String& _rDsn) const; 190 191 bool needsJVM(const String& _rDsn) const; 192 193 sal_Int32 getIndexOf(const ::rtl::OUString& _sURL) const; 194 sal_Int32 size() const; 195 ::rtl::OUString getType(const ::rtl::OUString& _sURL) const; 196 }; 197 198 //------------------------------------------------------------------------- 199 //- ODsnTypeCollection::TypeIterator 200 //------------------------------------------------------------------------- 201 class OOO_DLLPUBLIC_DBA ODsnTypeCollection::TypeIterator 202 { 203 friend class ODsnTypeCollection; 204 205 friend bool OOO_DLLPUBLIC_DBA operator==(const TypeIterator& lhs, const TypeIterator& rhs); operator !=(const TypeIterator & lhs,const TypeIterator & rhs)206 friend bool OOO_DLLPUBLIC_DBA operator!=(const TypeIterator& lhs, const TypeIterator& rhs) { return !(lhs == rhs); } 207 208 protected: 209 const ODsnTypeCollection* m_pContainer; 210 sal_Int32 m_nPosition; 211 212 public: 213 TypeIterator(const TypeIterator& _rSource); 214 ~TypeIterator(); 215 216 ::rtl::OUString getURLPrefix() const; 217 String getDisplayName() const; 218 219 /// prefix increment 220 const TypeIterator& operator++(); 221 /// postfix increment operator ++(int)222 const TypeIterator operator++(int) { TypeIterator hold(*this); ++*this; return hold; } 223 224 /// prefix decrement 225 const TypeIterator& operator--(); 226 /// postfix decrement operator --(int)227 const TypeIterator operator--(int) { TypeIterator hold(*this); --*this; return hold; } 228 229 protected: 230 TypeIterator(const ODsnTypeCollection* _pContainer, sal_Int32 _nInitialPos = 0); 231 }; 232 233 //......................................................................... 234 } // namespace dbaccess 235 //......................................................................... 236 237 #endif // _DBACCESS_DSNTYPES_HXX_ 238 239