xref: /aoo4110/main/dbaccess/source/inc/dsntypes.hxx (revision b1cdbd2c)
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 
71     DST_USERDEFINE1,	/// first user defined driver
72 	DST_USERDEFINE2,
73 	DST_USERDEFINE3,
74 	DST_USERDEFINE4,
75 	DST_USERDEFINE5,
76 	DST_USERDEFINE6,
77 	DST_USERDEFINE7,
78 	DST_USERDEFINE8,
79 	DST_USERDEFINE9,
80 	DST_USERDEFINE10,
81 
82 
83 	DST_UNKNOWN			/// unrecognized type
84 };
85 
86 #define PAGE_DBSETUPWIZARD_INTRO                     0
87 #define PAGE_DBSETUPWIZARD_DBASE     		         1
88 #define PAGE_DBSETUPWIZARD_TEXT                      2
89 #define PAGE_DBSETUPWIZARD_MSACCESS                  3
90 #define PAGE_DBSETUPWIZARD_LDAP                      4
91 #define PAGE_DBSETUPWIZARD_ADABAS                    5
92 #define PAGE_DBSETUPWIZARD_MYSQL_INTRO               6
93 #define PAGE_DBSETUPWIZARD_MYSQL_JDBC                7
94 #define PAGE_DBSETUPWIZARD_MYSQL_ODBC	             8
95 #define PAGE_DBSETUPWIZARD_ORACLE                    9
96 #define PAGE_DBSETUPWIZARD_JDBC                      10
97 #define PAGE_DBSETUPWIZARD_ADO                       11
98 #define PAGE_DBSETUPWIZARD_ODBC                      12
99 #define PAGE_DBSETUPWIZARD_SPREADSHEET               13
100 #define PAGE_DBSETUPWIZARD_AUTHENTIFICATION          14
101 #define PAGE_DBSETUPWIZARD_MOZILLA                   15
102 #define PAGE_DBSETUPWIZARD_FINAL                     16
103 #define PAGE_DBSETUPWIZARD_USERDEFINED               17
104 #define PAGE_DBSETUPWIZARD_MYSQL_NATIVE              18
105 
106 
107 //=========================================================================
108 //= ODsnTypeCollection
109 //=========================================================================
110 class OOO_DLLPUBLIC_DBA ODsnTypeCollection
111 {
112 protected:
113 	DECLARE_STL_VECTOR(String, StringVector);
114 
115 	StringVector	m_aDsnTypesDisplayNames;	/// user readable names for the datasource types
116 	StringVector	m_aDsnPrefixes;				/// DSN prefixes which determine the type of a datasource
117     ::connectivity::DriversConfig m_aDriverConfig;
118     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory;
119 
120 #ifdef DBG_UTIL
121 	sal_Int32		m_nLivingIterators;			/// just for debugging reasons, counts the living iterators
122 #endif
123 
124 public:
125 	class TypeIterator;
126 	friend class ODsnTypeCollection::TypeIterator;
127 
128 	ODsnTypeCollection(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xFactory);
129 	~ODsnTypeCollection();
130 
131 	/// get the datasource type display name from a DSN string
132 	String getTypeDisplayName(const ::rtl::OUString& _sURL) const;
133 
134 	/// on a given string, cut the type prefix and return the result
135 	String cutPrefix(const ::rtl::OUString& _sURL) const;
136 
137     /// on a given string, return the type prefix
138 	String getPrefix(const ::rtl::OUString& _sURL) const;
139 
140     /// determines whether there is a driver for the given URL prefix/pattern
141     bool    hasDriver( const sal_Char* _pAsciiPattern ) const;
142 
143     /// on a given string, return the Java Driver Class
144 	String getJavaDriverClass(const ::rtl::OUString& _sURL) const;
145 
146     /// returns the media type of a file based database
147     String getMediaType(const ::rtl::OUString& _sURL) const;
148 
149     /// returns the dsn prefix for a given media type
150     String getDatasourcePrefixFromMediaType(const ::rtl::OUString& _sMediaType,const ::rtl::OUString& _sExtension = ::rtl::OUString() );
151 
152 	void extractHostNamePort(const ::rtl::OUString& _rDsn,String& _sDatabaseName,String& _rHostname,sal_Int32& _nPortNumber) const;
153 
154 	/// check if the given data source allows creation of tables
155     sal_Bool supportsTableCreation(const ::rtl::OUString& _sURL) const;
156 
157     /// check if the given data source allows to show column description.
158     sal_Bool supportsColumnDescription(const ::rtl::OUString& _sURL) const;
159 
160     // check if a Browse button may be shown to insert connection url
161     sal_Bool supportsBrowsing(const ::rtl::OUString& _sURL) const;
162 
163 	/// check if the given data source tyoe is based on the file system - i.e. the URL is a prefix plus a file URL
164 	sal_Bool isFileSystemBased(const ::rtl::OUString& _sURL) const;
165 
166     bool isConnectionUrlRequired(const ::rtl::OUString& _sURL) const;
167 
168     /// checks if the given data source type embeds its data into the database document
169     bool isEmbeddedDatabase( const ::rtl::OUString& _sURL ) const;
170 
171     ::rtl::OUString getEmbeddedDatabase() const;
172 
173     // returns true when the properties dialog can be shown, otherwise false.
174     bool isShowPropertiesEnabled( const ::rtl::OUString& _sURL ) const;
175 
176 	/** returns default settings for newly created databases of the given type.
177     */
178 	::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>
179             getDefaultDBSettings( const ::rtl::OUString& _sURL ) const;
180 
181 	/// get access to the first element of the types collection
182 	TypeIterator	begin() const;
183 	/// get access to the (last + 1st) element of the types collection
184 	TypeIterator	end() const;
185 
186     void fillPageIds(const ::rtl::OUString& _sURL,::std::vector<sal_Int16>& _rOutPathIds) const;
187 
188     DATASOURCE_TYPE determineType(const String& _rDsn) const;
189 
190     bool needsJVM(const String& _rDsn) const;
191 
192     sal_Int32 getIndexOf(const ::rtl::OUString& _sURL) const;
193     sal_Int32 size() const;
194     ::rtl::OUString getType(const ::rtl::OUString& _sURL) const;
195 };
196 
197 //-------------------------------------------------------------------------
198 //- ODsnTypeCollection::TypeIterator
199 //-------------------------------------------------------------------------
200 class OOO_DLLPUBLIC_DBA ODsnTypeCollection::TypeIterator
201 {
202 	friend class ODsnTypeCollection;
203 
204 	friend bool OOO_DLLPUBLIC_DBA operator==(const TypeIterator& lhs, const TypeIterator& rhs);
operator !=(const TypeIterator & lhs,const TypeIterator & rhs)205 	friend bool OOO_DLLPUBLIC_DBA operator!=(const TypeIterator& lhs, const TypeIterator& rhs) { return !(lhs == rhs); }
206 
207 protected:
208 	const ODsnTypeCollection*	m_pContainer;
209 	sal_Int32					m_nPosition;
210 
211 public:
212 	TypeIterator(const TypeIterator& _rSource);
213 	~TypeIterator();
214 
215     ::rtl::OUString getURLPrefix() const;
216 	String			getDisplayName() const;
217 
218 	/// prefix increment
219 	const TypeIterator&	operator++();
220 	/// postfix increment
operator ++(int)221 	const TypeIterator	operator++(int) { TypeIterator hold(*this); ++*this; return hold; }
222 
223 	/// prefix decrement
224 	const TypeIterator&	operator--();
225 	/// postfix decrement
operator --(int)226 	const TypeIterator	operator--(int) { TypeIterator hold(*this); --*this; return hold; }
227 
228 protected:
229 	TypeIterator(const ODsnTypeCollection* _pContainer, sal_Int32 _nInitialPos = 0);
230 };
231 
232 //.........................................................................
233 }	// namespace dbaccess
234 //.........................................................................
235 
236 #endif // _DBACCESS_DSNTYPES_HXX_
237 
238