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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #include "dbwizsetup.hxx"
32 #include "dsmeta.hxx"
33 #include "DBSetupConnectionPages.hxx"
34 #include "dbadminsetup.hrc"
35 #include "dbu_dlg.hrc"
36 #include "dsitems.hxx"
37 #include "dsnItem.hxx"
38 
39 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
40 #include <unotools/pathoptions.hxx>
41 #endif
42 #ifndef _SFXSTRITEM_HXX
43 #include <svl/stritem.hxx>
44 #endif
45 #ifndef _SFXENUMITEM_HXX
46 #include <svl/eitem.hxx>
47 #endif
48 #ifndef _SFXINTITEM_HXX
49 #include <svl/intitem.hxx>
50 #endif
51 #ifndef _SV_MSGBOX_HXX
52 #include <vcl/msgbox.hxx>
53 #endif
54 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
55 #include "dbustrings.hrc"
56 #endif
57 #ifndef _DBAUI_ADMINPAGES_HXX_
58 #include "adminpages.hxx"
59 #endif
60 #ifndef _SFX_DOCFILT_HACK_HXX
61 #include <sfx2/docfilt.hxx>
62 #endif
63 #ifndef _UNOTOOLS_UCBHELPER_HXX
64 #include <unotools/ucbhelper.hxx>
65 #endif
66 #ifndef _DBAUI_GENERALPAGE_HXX_
67 #include "generalpage.hxx"
68 #endif
69 #ifndef _DBAUI_LOCALRESACCESS_HXX_
70 #include "localresaccess.hxx"
71 #endif
72 #ifndef _DBAUI_STRINGLISTITEM_HXX_
73 #include "stringlistitem.hxx"
74 #endif
75 #ifndef _DBAUI_PROPERTYSETITEM_HXX_
76 #include "propertysetitem.hxx"
77 #endif
78 #ifndef _UNOTOOLS_CONFIGNODE_HXX_
79 #include <unotools/confignode.hxx>
80 #endif
81 #ifndef _DBAUI_DBADMINIMPL_HXX_
82 #include "DbAdminImpl.hxx"
83 #endif
84 #ifndef _DBA_DBACCESS_HELPID_HRC_
85 #include "dbaccess_helpid.hrc"
86 #endif
87 #ifndef DBAUI_CONNECTIONPAGESETUP_HXX
88 #include "ConnectionPageSetup.hxx"
89 #endif
90 #ifndef DBAUI_TOOLS_HXX
91 #include "UITools.hxx"
92 #endif
93 #ifndef _DBAUI_DBADMIN_HRC_
94 #include "dbadmin.hrc"
95 #endif
96 #ifndef DBAUI_ASYNCRONOUSLINK_HXX
97 #include "AsyncronousLink.hxx"
98 #endif
99 #ifndef _FILEDLGHELPER_HXX
100 #include <sfx2/filedlghelper.hxx>
101 #endif
102 #include <cppuhelper/exc_hlp.hxx>
103 
104 /** === begin UNO includes === **/
105 #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
106 #include <com/sun/star/frame/XStorable.hpp>
107 #endif
108 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_
109 #include <com/sun/star/uno/XNamingService.hpp>
110 #endif
111 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
112 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
113 #endif
114 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
115 #include <com/sun/star/sdbc/XDataSource.hpp>
116 #endif
117 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
118 #include <com/sun/star/container/XNameAccess.hpp>
119 #endif
120 #ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_
121 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
122 #endif
123 #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
124 #include <com/sun/star/frame/FrameSearchFlag.hpp>
125 #endif
126 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
127 #include <com/sun/star/frame/XComponentLoader.hpp>
128 #endif
129 #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_
130 #include <com/sun/star/frame/XModel.hpp>
131 #endif
132 #ifndef _COM_SUN_STAR_UCB_XSIMPLEFILEACCESS_HPP_
133 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
134 #endif
135 #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_
136 #include <com/sun/star/task/XJobExecutor.hpp>
137 #endif
138 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
139 #include <com/sun/star/lang/XInitialization.hpp>
140 #endif
141 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
142 #include <com/sun/star/sdb/CommandType.hpp>
143 #endif
144 #ifndef _COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP_
145 #include <com/sun/star/ucb/InteractiveIOException.hpp>
146 #endif
147 #ifndef _COM_SUN_STAR_IO_IOEXCEPTION_HPP_
148 #include <com/sun/star/io/IOException.hpp>
149 #endif
150 #ifndef _COM_SUN_STAR_FRAME_XTERMINATELISTENER_HPP_
151 #include <com/sun/star/frame/XTerminateListener.hpp>
152 #endif
153 #ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_
154 #include <com/sun/star/frame/XDesktop.hpp>
155 #endif
156 #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
157 #include <com/sun/star/sdbc/XDriverAccess.hpp>
158 #endif
159 #ifndef _COM_SUN_STAR_DOCUMENT_MACROEXECMODE_HPP_
160 #include <com/sun/star/document/MacroExecMode.hpp>
161 #endif
162 #include <com/sun/star/ucb/IOErrorCode.hpp>
163 #include <com/sun/star/task/XInteractionHandler2.hpp>
164 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
165 
166 
167 /** === end UNO includes === **/
168 
169 #include <svl/filenotation.hxx>
170 #include <comphelper/interaction.hxx>
171 #include <comphelper/namedvaluecollection.hxx>
172 #include <comphelper/sequenceashashmap.hxx>
173 #include <tools/diagnose_ex.h>
174 #include <connectivity/DriversConfig.hxx>
175 
176 #include <memory>
177 
178 
179 //.........................................................................
180 namespace dbaui
181 {
182 //.........................................................................
183 using namespace dbtools;
184 using namespace svt;
185 using namespace com::sun::star;
186 using namespace com::sun::star::uno;
187 using namespace com::sun::star::sdbc;
188 using namespace com::sun::star::sdbcx;
189 using namespace com::sun::star::task;
190 using namespace com::sun::star::lang;
191 using namespace com::sun::star::io;
192 using namespace com::sun::star::util;
193 using namespace com::sun::star::beans;
194 using namespace com::sun::star::container;
195 using namespace com::sun::star::frame;
196 using namespace com::sun::star::ucb;
197 using namespace ::com::sun::star::sdb;
198 using namespace ::com::sun::star::document;
199 using namespace ::comphelper;
200 using namespace ::cppu;
201 
202 #define START_PAGE		0
203 #define CONNECTION_PAGE	1
204 
205 
206 
207 
208 //#define DBASE_PATH               1
209 //#define TEXT_PATH                2
210 //#define MSACCESS_PATH            3
211 //#define LDAP_PATH                4
212 //#define ADABAS_PATH              5
213 //#define ADO_PATH                 6
214 //#define JDBC_PATH                7
215 //#define ORACLE_PATH              8
216 //#define MYSQL_JDBC_PATH          9
217 //#define MYSQL_ODBC_PATH          10
218 //#define ODBC_PATH                11
219 //#define SPREADSHEET_PATH         12
220 //#define OUTLOOKEXP_PATH          13
221 //#define OUTLOOK_PATH             14
222 //#define MOZILLA_PATH             15
223 //#define EVOLUTION_PATH           16
224 //#define EVOLUTION_PATH_GROUPWISE 17
225 //#define EVOLUTION_PATH_LDAP      18
226 //#define KAB_PATH                 19
227 //#define MACAB_PATH            	 20
228 //#define THUNDERBIRD_PATH         21
229 //#define CREATENEW_PATH           22
230 //#define USERDEFINED_PATH         23
231 //#define OPEN_DOC_PATH            24
232 //#define MSACCESS2007_PATH        25
233 //#define MYSQL_NATIVE_PATH        26
234 
235 OFinalDBPageSetup*          pFinalPage;
236 
237 
238 
239 DBG_NAME(ODbTypeWizDialogSetup)
240 //=========================================================================
241 //= ODbTypeWizDialogSetup
242 //=========================================================================
243 //-------------------------------------------------------------------------
244 ODbTypeWizDialogSetup::ODbTypeWizDialogSetup(Window* _pParent
245 							   ,SfxItemSet* _pItems
246 							   ,const Reference< XMultiServiceFactory >& _rxORB
247 							   ,const ::com::sun::star::uno::Any& _aDataSourceName
248 							   )
249 	:svt::RoadmapWizard( _pParent, ModuleRes(DLG_DATABASE_WIZARD),
250                         WZB_NEXT | WZB_PREVIOUS | WZB_FINISH | WZB_CANCEL | WZB_HELP )
251 
252     , m_pOutSet(NULL)
253     , m_bResetting(sal_False)
254 	, m_bApplied(sal_False)
255 	, m_bUIEnabled( sal_True )
256     , m_bIsConnectable( sal_False)
257     , m_sRM_IntroText(ModuleRes(STR_PAGETITLE_INTROPAGE))
258     , m_sRM_dBaseText(ModuleRes(STR_PAGETITLE_DBASE))
259     , m_sRM_TextText(ModuleRes(STR_PAGETITLE_TEXT))
260     , m_sRM_MSAccessText(ModuleRes(STR_PAGETITLE_MSACCESS))
261     , m_sRM_LDAPText(ModuleRes(STR_PAGETITLE_LDAP))
262     , m_sRM_ADABASText(ModuleRes(STR_PAGETITLE_ADABAS))
263     , m_sRM_ADOText(ModuleRes(STR_PAGETITLE_ADO))
264     , m_sRM_JDBCText(ModuleRes(STR_PAGETITLE_JDBC))
265     , m_sRM_MySQLNativePageTitle(ModuleRes(STR_PAGETITLE_MYSQL_NATIVE))
266     , m_pGeneralPage( NULL )
267 	, m_pMySQLIntroPage(NULL)
268     , m_pCollection( NULL )
269 {
270 	DBG_CTOR(ODbTypeWizDialogSetup,NULL);
271     // no local resources needed anymore
272     m_sRM_MySQLText = String(ModuleRes(STR_PAGETITLE_MYSQL));
273     m_sRM_OracleText = String(ModuleRes(STR_PAGETITLE_ORACLE));
274     m_sRM_ODBCText = String(ModuleRes(STR_PAGETITLE_ODBC));
275     m_sRM_SpreadSheetText = String(ModuleRes(STR_PAGETITLE_SPREADSHEET));
276     m_sRM_AuthentificationText = String(ModuleRes(STR_PAGETITLE_AUTHENTIFICATION));
277     m_sRM_FinalText = String(ModuleRes(STR_PAGETITLE_FINAL));
278     m_sWorkPath = SvtPathOptions().GetWorkPath();
279     pFinalPage = NULL;
280 	// extract the datasource type collection from the item set
281 	DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION));
282 	if (pCollectionItem)
283 		m_pCollection = pCollectionItem->getCollection();
284 
285 	DBG_ASSERT(m_pCollection, "ODbTypeWizDialogSetup::ODbTypeWizDialogSetup : really need a DSN type collection !");
286 
287 	FreeResource();
288 
289 	m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,this,this));
290 	m_pImpl->setDataSourceOrName(_aDataSourceName);
291 	Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
292 	m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() );
293 
294 	m_pImpl->translateProperties(xDatasource, *m_pOutSet);
295 //	eType = m_pImpl->getDatasourceType(*m_pOutSet);
296 
297 	SetPageSizePixel(LogicToPixel(::Size(WIZARD_PAGE_X, WIZARD_PAGE_Y), MAP_APPFONT));
298 	ShowButtonFixedLine(sal_True);
299 	defaultButton(WZB_NEXT);
300 	enableButtons(WZB_FINISH, sal_True);
301     enableAutomaticNextButtonState();
302 
303     ::dbaccess::ODsnTypeCollection::TypeIterator aIter = m_pCollection->begin();
304     ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
305     for(PathId i = 1;aIter != aEnd;++aIter,++i)
306     {
307         const ::rtl::OUString sURLPrefix = aIter.getURLPrefix();
308         svt::RoadmapWizardTypes::WizardPath aPath;
309         aPath.push_back(PAGE_DBSETUPWIZARD_INTRO);
310         m_pCollection->fillPageIds(sURLPrefix,aPath);
311         aPath.push_back(PAGE_DBSETUPWIZARD_AUTHENTIFICATION);
312         aPath.push_back(PAGE_DBSETUPWIZARD_FINAL);
313 
314         declareAuthDepPath(sURLPrefix,i,aPath);
315     }
316 
317     svt::RoadmapWizardTypes::WizardPath aPath;
318     aPath.push_back(PAGE_DBSETUPWIZARD_INTRO);
319     declarePath( static_cast<PathId>(m_pCollection->size()+1), aPath);
320 
321     m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS);
322 	m_pNextPage->SetHelpId(HID_DBWIZ_NEXT);
323 	m_pCancel->SetHelpId(HID_DBWIZ_CANCEL);
324 	m_pFinish->SetHelpId(HID_DBWIZ_FINISH);
325 	m_pHelp->SetUniqueId(UID_DBWIZ_HELP);
326     SetRoadmapInteractive( sal_True );
327 	ActivatePage();
328 }
329 
330 void ODbTypeWizDialogSetup::declareAuthDepPath( const ::rtl::OUString& _sURL, PathId _nPathId, const svt::RoadmapWizardTypes::WizardPath& _rPaths)
331 {
332     bool bHasAuthentication = DataSourceMetaData::getAuthentication( _sURL ) != AuthNone;
333 
334     // collect the elements of the path
335     WizardPath aPath;
336 
337     svt::RoadmapWizardTypes::WizardPath::const_iterator aIter = _rPaths.begin();
338     svt::RoadmapWizardTypes::WizardPath::const_iterator aEnd = _rPaths.end();
339     for(;aIter != aEnd;++aIter)
340     {
341         if ( bHasAuthentication || ( *aIter != PAGE_DBSETUPWIZARD_AUTHENTIFICATION ) )
342             aPath.push_back( *aIter );
343     } // for(;aIter != aEnd;++aIter)
344 
345     // call base method
346     ::svt::RoadmapWizard::declarePath( _nPathId, aPath );
347 }
348 
349 String ODbTypeWizDialogSetup::getStateDisplayName( WizardState _nState ) const
350 {
351     String sRoadmapItem;
352     switch( _nState )
353     {
354         case PAGE_DBSETUPWIZARD_INTRO:
355             sRoadmapItem = m_sRM_IntroText;
356             break;
357 
358         case PAGE_DBSETUPWIZARD_DBASE:
359             sRoadmapItem = m_sRM_dBaseText;
360             break;
361         case PAGE_DBSETUPWIZARD_ADO:
362             sRoadmapItem = m_sRM_ADOText;
363             break;
364         case PAGE_DBSETUPWIZARD_TEXT:
365             sRoadmapItem = m_sRM_TextText;
366             break;
367         case PAGE_DBSETUPWIZARD_MSACCESS:
368             sRoadmapItem = m_sRM_MSAccessText;
369             break;
370         case PAGE_DBSETUPWIZARD_LDAP:
371             sRoadmapItem = m_sRM_LDAPText;
372             break;
373         case PAGE_DBSETUPWIZARD_ADABAS:
374             sRoadmapItem = m_sRM_ADABASText;
375             break;
376         case PAGE_DBSETUPWIZARD_JDBC:
377             sRoadmapItem = m_sRM_JDBCText;
378             break;
379         case PAGE_DBSETUPWIZARD_ORACLE:
380             sRoadmapItem = m_sRM_OracleText;
381             break;
382         case PAGE_DBSETUPWIZARD_MYSQL_INTRO:
383             sRoadmapItem = m_sRM_MySQLText;
384             break;
385         case PAGE_DBSETUPWIZARD_MYSQL_JDBC:
386             sRoadmapItem = m_sRM_JDBCText;
387             break;
388         case PAGE_DBSETUPWIZARD_MYSQL_NATIVE:
389             sRoadmapItem = m_sRM_MySQLNativePageTitle;
390             break;
391         case PAGE_DBSETUPWIZARD_MYSQL_ODBC:
392             sRoadmapItem = m_sRM_ODBCText;
393             break;
394         case PAGE_DBSETUPWIZARD_ODBC:
395             sRoadmapItem = m_sRM_ODBCText;
396             break;
397         case PAGE_DBSETUPWIZARD_SPREADSHEET:
398             sRoadmapItem = m_sRM_SpreadSheetText;
399             break;
400         case PAGE_DBSETUPWIZARD_AUTHENTIFICATION:
401             sRoadmapItem = m_sRM_AuthentificationText;
402             break;
403 		case PAGE_DBSETUPWIZARD_USERDEFINED:
404 			{
405 				LocalResourceAccess aDummy(DLG_DATABASE_ADMINISTRATION, RSC_TABDIALOG);
406 				sRoadmapItem = String(ModuleRes(STR_PAGETITLE_CONNECTION));
407 			}
408 			break;
409         case PAGE_DBSETUPWIZARD_FINAL:
410             sRoadmapItem = m_sRM_FinalText;
411             break;
412         default:
413             break;
414     }
415     return sRoadmapItem;
416 }
417 
418 //-------------------------------------------------------------------------
419 ODbTypeWizDialogSetup::~ODbTypeWizDialogSetup()
420 {
421 	delete m_pOutSet;
422 	DBG_DTOR(ODbTypeWizDialogSetup,NULL);
423 }
424 
425 //-------------------------------------------------------------------------
426 IMPL_LINK(ODbTypeWizDialogSetup, OnTypeSelected, OGeneralPage*, /*_pTabPage*/)
427 {
428     activateDatabasePath();
429 	return 1L;
430 }
431 
432 void lcl_removeUnused(const ::comphelper::NamedValueCollection& _aOld,const ::comphelper::NamedValueCollection& _aNew,::comphelper::NamedValueCollection& _rDSInfo)
433 {
434     _rDSInfo.merge(_aNew,true);
435     uno::Sequence< beans::NamedValue > aOldValues = _aOld.getNamedValues();
436     const beans::NamedValue* pIter = aOldValues.getConstArray();
437     const beans::NamedValue* pEnd  = pIter + aOldValues.getLength();
438     for(;pIter != pEnd;++pIter)
439     {
440         if ( !_aNew.has(pIter->Name) )
441         {
442             _rDSInfo.remove(pIter->Name);
443         }
444     }
445 }
446 // -----------------------------------------------------------------------------
447 void DataSourceInfoConverter::convert(const ::dbaccess::ODsnTypeCollection* _pCollection,const ::rtl::OUString& _sOldURLPrefix,const ::rtl::OUString& _sNewURLPrefix,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDatasource)
448 {
449     if ( _pCollection->getPrefix(_sOldURLPrefix) == _pCollection->getPrefix(_sNewURLPrefix) )
450         return ;
451     uno::Sequence< beans::PropertyValue> aInfo;
452     _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
453     ::comphelper::NamedValueCollection aDS(aInfo);
454 
455     ::connectivity::DriversConfig aDriverConfig(m_xFactory);
456 
457     const ::comphelper::NamedValueCollection&  aOldProperties   = aDriverConfig.getProperties(_sOldURLPrefix);
458     const ::comphelper::NamedValueCollection&  aNewProperties   = aDriverConfig.getProperties(_sNewURLPrefix);
459     lcl_removeUnused(aOldProperties,aNewProperties,aDS);
460 
461     aDS >>= aInfo;
462     _xDatasource->setPropertyValue(PROPERTY_INFO,uno::makeAny(aInfo));
463 }
464 //-------------------------------------------------------------------------
465 void ODbTypeWizDialogSetup::activateDatabasePath()
466 {
467     switch ( m_pGeneralPage->GetDatabaseCreationMode() )
468     {
469     case OGeneralPage::eCreateNew:
470     {
471         sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( m_pCollection->getEmbeddedDatabase() );
472         if ( nCreateNewDBIndex == -1 )
473             nCreateNewDBIndex = m_pCollection->getIndexOf( ::rtl::OUString::createFromAscii( "sdbc:dbase:" ) );
474         OSL_ENSURE( nCreateNewDBIndex != -1, "ODbTypeWizDialogSetup::activateDatabasePath: the GeneralPage should have prevented this!" );
475         activatePath( static_cast< PathId >( nCreateNewDBIndex + 1 ), sal_True );
476 
477         enableState(PAGE_DBSETUPWIZARD_FINAL, sal_True );
478 		enableButtons( WZB_FINISH, sal_True);
479     }
480     break;
481     case OGeneralPage::eConnectExternal:
482     {
483         ::rtl::OUString sOld = m_sURL;
484         DataSourceInfoConverter aConverter(getORB());
485         m_sURL = m_pGeneralPage->GetSelectedType();
486         aConverter.convert(m_pCollection,sOld,m_sURL,m_pImpl->getCurrentDataSource());
487 		::dbaccess::DATASOURCE_TYPE eType = VerifyDataSourceType(m_pCollection->determineType(m_sURL));
488         if (eType ==  ::dbaccess::DST_UNKNOWN)
489             eType = m_pCollection->determineType(m_sOldURL);
490 
491 		activatePath( static_cast<PathId>(m_pCollection->getIndexOf(m_sURL) + 1), sal_True);
492         updateTypeDependentStates();
493     }
494     break;
495     case OGeneralPage::eOpenExisting:
496     {
497         activatePath( static_cast<PathId>(m_pCollection->size() + 1), sal_True );
498         enableButtons( WZB_FINISH, m_pGeneralPage->GetSelectedDocument().sURL.Len() != 0 );
499     }
500     break;
501     default:
502         DBG_ERROR( "ODbTypeWizDialogSetup::activateDatabasePath: unknown creation mode!" );
503     }
504 
505     enableButtons( WZB_NEXT, m_pGeneralPage->GetDatabaseCreationMode() != OGeneralPage::eOpenExisting );
506         // TODO: this should go into the base class. Point is, we activate a path whose *last*
507         // step is also the current one. The base class should automatically disable
508         // the Next button in such a case. However, not for this patch ...
509 }
510 
511 //-------------------------------------------------------------------------
512 void ODbTypeWizDialogSetup::updateTypeDependentStates()
513 {
514     sal_Bool bDoEnable = sal_False;
515     sal_Bool bIsConnectionRequired = IsConnectionUrlRequired();
516     if (!bIsConnectionRequired)
517     {
518         bDoEnable = sal_True;
519     }
520     else if ( m_sURL == m_sOldURL )
521     {
522         bDoEnable = m_bIsConnectable;
523     }
524     enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, bDoEnable);
525     enableState(PAGE_DBSETUPWIZARD_FINAL, bDoEnable );
526 	enableButtons( WZB_FINISH, bDoEnable);
527 }
528 
529 
530 //-------------------------------------------------------------------------
531 sal_Bool ODbTypeWizDialogSetup::IsConnectionUrlRequired()
532 {
533 	return m_pCollection->isConnectionUrlRequired(m_sURL);
534 }
535 
536 //-------------------------------------------------------------------------
537 void ODbTypeWizDialogSetup::resetPages(const Reference< XPropertySet >& _rxDatasource)
538 {
539 	// remove all items which relate to indirect properties from the input set
540 	// (without this, the following may happen: select an arbitrary data source where some indirect properties
541 	// are set. Select another data source of the same type, where the indirect props are not set (yet). Then,
542 	// the indirect property values of the first ds are shown in the second ds ...)
543 	const ODbDataSourceAdministrationHelper::MapInt2String& rMap = m_pImpl->getIndirectProperties();
544 	for	(	ODbDataSourceAdministrationHelper::ConstMapInt2StringIterator aIndirect = rMap.begin();
545 			aIndirect != rMap.end();
546 			++aIndirect
547 		)
548 		getWriteOutputSet()->ClearItem( (sal_uInt16)aIndirect->first );
549 
550 	// extract all relevant data from the property set of the data source
551 	m_pImpl->translateProperties(_rxDatasource, *getWriteOutputSet());
552 }
553 // -----------------------------------------------------------------------------
554 const SfxItemSet* ODbTypeWizDialogSetup::getOutputSet() const
555 {
556 	return m_pOutSet;
557 }
558 // -----------------------------------------------------------------------------
559 SfxItemSet* ODbTypeWizDialogSetup::getWriteOutputSet()
560 {
561 	return m_pOutSet;
562 }
563 // -----------------------------------------------------------------------------
564 ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialogSetup::createConnection()
565 {
566 	return m_pImpl->createConnection();
567 }
568 // -----------------------------------------------------------------------------
569 Reference< XMultiServiceFactory > ODbTypeWizDialogSetup::getORB() const
570 {
571 	return m_pImpl->getORB();
572 }
573 // -----------------------------------------------------------------------------
574 Reference< XDriver > ODbTypeWizDialogSetup::getDriver()
575 {
576 	return m_pImpl->getDriver();
577 }
578 
579 
580 ::dbaccess::DATASOURCE_TYPE ODbTypeWizDialogSetup::VerifyDataSourceType(const ::dbaccess::DATASOURCE_TYPE _DatabaseType) const
581 {
582 	::dbaccess::DATASOURCE_TYPE LocDatabaseType = _DatabaseType;
583 	if ((LocDatabaseType ==  ::dbaccess::DST_MYSQL_JDBC) || (LocDatabaseType ==  ::dbaccess::DST_MYSQL_ODBC) || (LocDatabaseType ==  ::dbaccess::DST_MYSQL_NATIVE))
584 	{
585 		if (m_pMySQLIntroPage != NULL)
586 		{
587 			switch( m_pMySQLIntroPage->getMySQLMode() )
588             {
589                 case OMySQLIntroPageSetup::VIA_JDBC:
590 				    return  ::dbaccess::DST_MYSQL_JDBC;
591                 case OMySQLIntroPageSetup::VIA_NATIVE:
592 				    return  ::dbaccess::DST_MYSQL_NATIVE;
593                 case OMySQLIntroPageSetup::VIA_ODBC:
594 				    return  ::dbaccess::DST_MYSQL_ODBC;
595             }
596 		}
597 	}
598 	return LocDatabaseType;
599 }
600 
601 
602 
603 // -----------------------------------------------------------------------------
604 ::rtl::OUString	ODbTypeWizDialogSetup::getDatasourceType(const SfxItemSet& _rSet) const
605 {
606     ::rtl::OUString sRet = m_pImpl->getDatasourceType(_rSet);
607     if (m_pMySQLIntroPage != NULL && m_pMySQLIntroPage->IsVisible() )
608 	{
609 		switch( m_pMySQLIntroPage->getMySQLMode() )
610         {
611             case OMySQLIntroPageSetup::VIA_JDBC:
612                 sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"));
613                 break;
614             case OMySQLIntroPageSetup::VIA_NATIVE:
615 			    sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"));
616                 break;
617             case OMySQLIntroPageSetup::VIA_ODBC:
618 			    sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"));
619                 break;
620         }
621 	}
622 	return sRet;
623 }
624 
625 // -----------------------------------------------------------------------------
626 void ODbTypeWizDialogSetup::clearPassword()
627 {
628 	m_pImpl->clearPassword();
629 }
630 
631 // -----------------------------------------------------------------------------
632 TabPage* ODbTypeWizDialogSetup::createPage(WizardState _nState)
633 {
634     SfxTabPage* pFirstPage;
635 	OGenericAdministrationPage* pPage = NULL;
636 	switch(_nState)
637 	{
638         case PAGE_DBSETUPWIZARD_INTRO:
639 			pFirstPage = OGeneralPage::Create(this,*m_pOutSet, sal_True);
640 			pPage = static_cast<OGenericAdministrationPage*> (pFirstPage);
641 			m_pGeneralPage = static_cast<OGeneralPage*>(pFirstPage);
642             m_pGeneralPage->SetTypeSelectHandler(LINK(this, ODbTypeWizDialogSetup, OnTypeSelected));
643             m_pGeneralPage->SetCreationModeHandler(LINK( this, ODbTypeWizDialogSetup, OnChangeCreationMode ) );
644             m_pGeneralPage->SetDocumentSelectionHandler(LINK( this, ODbTypeWizDialogSetup, OnRecentDocumentSelected ) );
645             m_pGeneralPage->SetChooseDocumentHandler(LINK( this, ODbTypeWizDialogSetup, OnSingleDocumentChosen ) );
646 			break;
647 
648 		case PAGE_DBSETUPWIZARD_DBASE:
649 			pPage = OConnectionTabPageSetup::CreateDbaseTabPage(this,*m_pOutSet);
650 			break;
651 
652 		case PAGE_DBSETUPWIZARD_ADO:
653 			pPage = OConnectionTabPageSetup::CreateADOTabPage( this, *m_pOutSet);
654 			break;
655 
656 		case PAGE_DBSETUPWIZARD_TEXT:
657             pPage = OTextConnectionPageSetup::CreateTextTabPage(this,*m_pOutSet);
658 			break;
659 
660 		case PAGE_DBSETUPWIZARD_ODBC:
661 			pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet);
662 			break;
663 
664         case PAGE_DBSETUPWIZARD_JDBC:
665 			pPage = OJDBCConnectionPageSetup::CreateJDBCTabPage( this, *m_pOutSet);
666 			break;
667 
668 		case PAGE_DBSETUPWIZARD_MYSQL_ODBC:
669 			m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:")))));
670 			pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet);
671             break;
672 
673 		case PAGE_DBSETUPWIZARD_MYSQL_JDBC:
674 			m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:")))));
675             pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateMySQLJDBCTabPage( this, *m_pOutSet);
676 			break;
677         case PAGE_DBSETUPWIZARD_MYSQL_NATIVE:
678 			m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:")))));
679             pPage = MySQLNativeSetupPage::Create( this, *m_pOutSet);
680 			break;
681 
682 		case PAGE_DBSETUPWIZARD_ORACLE:
683 			pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateOracleJDBCTabPage( this, *m_pOutSet);
684 			break;
685 
686 		case PAGE_DBSETUPWIZARD_ADABAS:
687 			pPage = OConnectionTabPageSetup::CreateAdabasTabPage( this, *m_pOutSet);
688 			break;
689 
690 		case PAGE_DBSETUPWIZARD_LDAP	:
691 			pPage = OLDAPConnectionPageSetup::CreateLDAPTabPage(this,*m_pOutSet);
692             break;
693 
694         case PAGE_DBSETUPWIZARD_SPREADSHEET:	/// first user defined driver
695 			pPage = OSpreadSheetConnectionPageSetup::CreateSpreadSheetTabPage(this,*m_pOutSet);
696             break;
697 
698         case PAGE_DBSETUPWIZARD_MSACCESS:
699             pPage  = OConnectionTabPageSetup::CreateMSAccessTabPage(this,*m_pOutSet);
700             break;
701         case PAGE_DBSETUPWIZARD_MYSQL_INTRO:
702             m_pMySQLIntroPage = OMySQLIntroPageSetup::CreateMySQLIntroTabPage(this,*m_pOutSet);
703             m_pMySQLIntroPage->SetClickHdl(LINK( this, ODbTypeWizDialogSetup, ImplClickHdl ) );
704             pPage = m_pMySQLIntroPage;
705             break;
706 
707         case PAGE_DBSETUPWIZARD_AUTHENTIFICATION:
708             pPage = OAuthentificationPageSetup::CreateAuthentificationTabPage(this,*m_pOutSet);
709             break;
710 
711 		case PAGE_DBSETUPWIZARD_USERDEFINED:
712 			pPage = OConnectionTabPageSetup::CreateUserDefinedTabPage(this,*m_pOutSet);
713 			break;
714 
715         case PAGE_DBSETUPWIZARD_FINAL:
716             pPage = OFinalDBPageSetup::CreateFinalDBTabPageSetup(this,*m_pOutSet);
717             pFinalPage = static_cast<OFinalDBPageSetup*> (pPage);
718             break;
719 	}
720 
721     if ((_nState != PAGE_DBSETUPWIZARD_INTRO) && (_nState != PAGE_DBSETUPWIZARD_AUTHENTIFICATION))
722     {
723         pPage->SetModifiedHandler(LINK( this, ODbTypeWizDialogSetup, ImplModifiedHdl ) );
724     }
725 
726     if ( pPage )
727 	{
728 		pPage->SetServiceFactory(m_pImpl->getORB());
729 		pPage->SetAdminDialog(this, this);
730 
731         defaultButton( _nState == PAGE_DBSETUPWIZARD_FINAL ? WZB_FINISH : WZB_NEXT );
732 		enableButtons( WZB_FINISH, _nState == PAGE_DBSETUPWIZARD_FINAL );
733 		enableButtons( WZB_NEXT, _nState == PAGE_DBSETUPWIZARD_FINAL ? sal_False : sal_True);
734         pPage->Show();
735 	}
736 	return pPage;
737 }
738 
739 
740 IMPL_LINK(ODbTypeWizDialogSetup, ImplModifiedHdl, OGenericAdministrationPage*, _pConnectionPageSetup)
741 {
742     m_bIsConnectable = _pConnectionPageSetup->GetRoadmapStateValue( );
743     enableState(PAGE_DBSETUPWIZARD_FINAL, m_bIsConnectable);
744     enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, m_bIsConnectable);
745 	if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL)
746 		enableButtons( WZB_FINISH, sal_True);
747 	else
748 		enableButtons( WZB_FINISH, m_bIsConnectable);
749 	enableButtons( WZB_NEXT, m_bIsConnectable  && (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL));
750     return sal_True;
751 }
752 
753 
754 // -----------------------------------------------------------------------------
755 IMPL_LINK(ODbTypeWizDialogSetup, ImplClickHdl, OMySQLIntroPageSetup*, _pMySQLIntroPageSetup)
756 {
757     ::rtl::OUString sURLPrefix;
758     switch( _pMySQLIntroPageSetup->getMySQLMode() )
759     {
760         case  OMySQLIntroPageSetup::VIA_ODBC:
761             sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"));
762             break;
763         case  OMySQLIntroPageSetup::VIA_JDBC:
764             sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"));
765             break;
766         case  OMySQLIntroPageSetup::VIA_NATIVE:
767     		sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"));
768             break;
769     } // switch( _pMySQLIntroPageSetup->getMySQLMode() )
770     activatePath( static_cast<PathId>(m_pCollection->getIndexOf(sURLPrefix) + 1), sal_True);
771     return sal_True;
772 }
773 
774 // -----------------------------------------------------------------------------
775 IMPL_LINK(ODbTypeWizDialogSetup, OnChangeCreationMode, OGeneralPage*, /*_pGeneralPage*/)
776 {
777     activateDatabasePath();
778     return sal_True;
779 }
780 
781 // -----------------------------------------------------------------------------
782 IMPL_LINK(ODbTypeWizDialogSetup, OnRecentDocumentSelected, OGeneralPage*, /*_pGeneralPage*/)
783 {
784     enableButtons( WZB_FINISH, m_pGeneralPage->GetSelectedDocument().sURL.Len() != 0 );
785     return 0L;
786 }
787 
788 // -----------------------------------------------------------------------------
789 IMPL_LINK(ODbTypeWizDialogSetup, OnSingleDocumentChosen, OGeneralPage*, /*_pGeneralPage*/)
790 {
791     if ( prepareLeaveCurrentState( eFinish ) )
792         onFinish();
793     return 0L;
794 }
795 
796 // -----------------------------------------------------------------------------
797 void ODbTypeWizDialogSetup::enterState(WizardState _nState)
798 {
799     m_sURL = m_pImpl->getDatasourceType(*m_pOutSet);
800     RoadmapWizard::enterState(_nState);
801 	switch(_nState)
802 	{
803 		case PAGE_DBSETUPWIZARD_INTRO:
804 			m_sOldURL = m_sURL;
805 			break;
806         case PAGE_DBSETUPWIZARD_FINAL:
807             enableButtons( WZB_FINISH, sal_True);
808             if ( pFinalPage )
809                 pFinalPage->enableTableWizardCheckBox(m_pCollection->supportsTableCreation(m_sURL));
810             break;
811     }
812 }
813 
814 //-------------------------------------------------------------------------
815 sal_Bool ODbTypeWizDialogSetup::saveDatasource()
816 {
817 	SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState()));
818 	if ( pPage )
819 		pPage->FillItemSet(*m_pOutSet);
820 	return sal_True;
821 }
822 
823 
824 // -----------------------------------------------------------------------------
825 sal_Bool ODbTypeWizDialogSetup::leaveState(WizardState _nState)
826 {
827     if (_nState == PAGE_DBSETUPWIZARD_MYSQL_INTRO)
828         return sal_True;
829     if ( _nState == PAGE_DBSETUPWIZARD_INTRO && m_sURL != m_sOldURL )
830     {
831         resetPages(m_pImpl->getCurrentDataSource());
832     }
833 	SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState));
834 	return pPage && pPage->DeactivatePage(m_pOutSet) != 0;
835 }
836 
837 // -----------------------------------------------------------------------------
838 void ODbTypeWizDialogSetup::setTitle(const ::rtl::OUString& /*_sTitle*/)
839 {
840     DBG_ERROR( "ODbTypeWizDialogSetup::setTitle: not implemented!" );
841         // why?
842 }
843 
844 //-------------------------------------------------------------------------
845 void ODbTypeWizDialogSetup::enableConfirmSettings( bool _bEnable )
846 {
847     (void)_bEnable;
848 }
849 
850 //-------------------------------------------------------------------------
851 namespace
852 {
853     bool lcl_handle( const Reference< XInteractionHandler2 >& _rxHandler, const Any& _rRequest )
854     {
855 	    OInteractionRequest* pRequest = new OInteractionRequest( _rRequest );
856 	    Reference < XInteractionRequest > xRequest( pRequest );
857 	    OInteractionAbort* pAbort = new OInteractionAbort;
858 	    pRequest->addContinuation( pAbort );
859 
860         return _rxHandler->handleInteractionRequest( xRequest );
861     }
862 }
863 
864 //-------------------------------------------------------------------------
865 sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument()
866 {
867 	Reference< XInteractionHandler2 > xHandler( getORB()->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY );
868 	try
869 	{
870 		if (callSaveAsDialog() == sal_True)
871 		{
872 			m_pImpl->saveChanges(*m_pOutSet);
873 			Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
874             Reference< XModel > xModel( getDataSourceOrModel( xDatasource ), UNO_QUERY_THROW );
875             Reference< XStorable > xStore( xModel, UNO_QUERY_THROW );
876 
877             if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eCreateNew )
878 				CreateDatabase();
879 
880             ::comphelper::NamedValueCollection aArgs( xModel->getArgs() );
881             aArgs.put( "Overwrite", sal_Bool( sal_True ) );
882             aArgs.put( "InteractionHandler", xHandler );
883             aArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
884 
885             ::rtl::OUString sPath = m_pImpl->getDocumentUrl( *m_pOutSet );
886 			xStore->storeAsURL( sPath, aArgs.getPropertyValues() );
887 
888 			if ( !pFinalPage || pFinalPage->IsDatabaseDocumentToBeRegistered() )
889 				RegisterDataSourceByLocation( sPath );
890 
891             return sal_True;
892 		}
893 	}
894 	catch ( const Exception& e )
895 	{
896         Any aError = ::cppu::getCaughtException();
897 		if ( xHandler.is() )
898         {
899             if ( !lcl_handle( xHandler, aError ) )
900             {
901 	            InteractiveIOException aRequest;
902                 aRequest.Classification = InteractionClassification_ERROR;
903                 if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) )
904                     // assume savint the document faile
905 		            aRequest.Code = IOErrorCode_CANT_WRITE;
906                 else
907                     aRequest.Code = IOErrorCode_GENERAL;
908                 aRequest.Message = e.Message;
909                 aRequest.Context = e.Context;
910                 lcl_handle( xHandler, makeAny( aRequest ) );
911             }
912         }
913 	}
914     return sal_False;
915 }
916     // ------------------------------------------------------------------------
917     sal_Bool ODbTypeWizDialogSetup::IsDatabaseDocumentToBeOpened() const
918     {
919         if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
920             return sal_True;
921 
922         if ( pFinalPage != NULL )
923             return pFinalPage->IsDatabaseDocumentToBeOpened();
924 
925         return sal_True;
926     }
927 
928     // ------------------------------------------------------------------------
929     sal_Bool ODbTypeWizDialogSetup::IsTableWizardToBeStarted() const
930     {
931         if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
932             return sal_False;
933 
934         if ( pFinalPage != NULL )
935             return pFinalPage->IsTableWizardToBeStarted();
936 
937         return sal_False;
938     }
939 
940     //-------------------------------------------------------------------------
941     ::rtl::OUString ODbTypeWizDialogSetup::getDefaultDatabaseType() const
942     {
943         ::rtl::OUString sEmbeddedURL = m_pCollection->getEmbeddedDatabase();
944         ::connectivity::DriversConfig aDriverConfig(getORB());
945         try
946         {
947         if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() || !m_pImpl->getDriver(sEmbeddedURL).is() )
948             sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:"));
949         }
950         catch(const Exception&)
951         {
952             sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:"));
953         }
954 
955         return sEmbeddedURL;
956     }
957 
958     //-------------------------------------------------------------------------
959     void ODbTypeWizDialogSetup::CreateDatabase()
960     {
961 		::rtl::OUString sUrl;
962 		::rtl::OUString eType = getDefaultDatabaseType();
963 		if ( m_pCollection->isEmbeddedDatabase(eType) )
964 		{
965 			sUrl = eType;
966 			Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
967 			OSL_ENSURE(xDatasource.is(),"DataSource is null!");
968 			if ( xDatasource.is() )
969 				xDatasource->setPropertyValue( PROPERTY_INFO, makeAny( m_pCollection->getDefaultDBSettings( eType ) ) );
970 			m_pImpl->translateProperties(xDatasource,*m_pOutSet);
971 		}
972 		else if ( m_pCollection->isFileSystemBased(eType) )
973 		{
974 			Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
975 			INetURLObject aDBPathURL(m_sWorkPath);
976 			aDBPathURL.Append(m_aDocURL.getBase());
977 			createUniqueFolderName(&aDBPathURL);
978 			::rtl::OUString sPrefix = eType;
979 			sUrl = aDBPathURL.GetMainURL( INetURLObject::NO_DECODE);
980 			xSimpleFileAccess->createFolder(sUrl);
981 			//OFileNotation aFileNotation(sUrl);
982 			//sUrl = aFileNotation.get(OFileNotation::N_SYSTEM);
983  			sUrl = sPrefix.concat(sUrl);
984 		}
985 		m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, sUrl));
986 		m_pImpl->saveChanges(*m_pOutSet);
987     }
988 
989     //-------------------------------------------------------------------------
990     void ODbTypeWizDialogSetup::RegisterDataSourceByLocation(const ::rtl::OUString& _sPath)
991     {
992 	    Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
993         Reference< XNamingService > xDatabaseContext(getORB()->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
994         Reference< XNameAccess > xNameAccessDatabaseContext(xDatabaseContext, UNO_QUERY);
995 		INetURLObject aURL( _sPath );
996         ::rtl::OUString sFilename = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
997         ::rtl::OUString sDatabaseName = ::dbtools::createUniqueName(xNameAccessDatabaseContext, sFilename,sal_False);
998         xDatabaseContext->registerObject(sDatabaseName, xDatasource);
999     }
1000 
1001 
1002     //-------------------------------------------------------------------------
1003     sal_Bool ODbTypeWizDialogSetup::callSaveAsDialog()
1004     {
1005         sal_Bool bRet = sal_False;
1006 		WinBits nBits(WB_STDMODAL|WB_SAVEAS);
1007         ::sfx2::FileDialogHelper aFileDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION, static_cast<sal_uInt32>(nBits), this);
1008 		const SfxFilter* pFilter = getStandardDatabaseFilter();
1009 		if ( pFilter )
1010 		{
1011             INetURLObject aWorkURL( m_sWorkPath );
1012             aFileDlg.SetDisplayFolder( aWorkURL.GetMainURL( INetURLObject::NO_DECODE ));
1013 
1014             ::rtl::OUString sDefaultName = String( ModuleRes( STR_DATABASEDEFAULTNAME ) );
1015             ::rtl::OUString sExtension = pFilter->GetDefaultExtension();
1016             sDefaultName += sExtension.replaceAt( 0, 1, ::rtl::OUString() );
1017             aWorkURL.Append( sDefaultName );
1018 			sDefaultName = createUniqueFileName( aWorkURL );
1019             aFileDlg.SetFileName( sDefaultName );
1020 
1021             aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
1022 			aFileDlg.SetCurrentFilter(pFilter->GetUIName());
1023 		}
1024 		if ( aFileDlg.Execute() == ERRCODE_NONE )
1025 		{
1026             m_aDocURL = INetURLObject(aFileDlg.GetPath());
1027 
1028             if( m_aDocURL.GetProtocol() != INET_PROT_NOT_VALID )
1029 			{
1030 				::rtl::OUString sFileName = m_aDocURL.GetMainURL( INetURLObject::NO_DECODE );
1031 				if ( ::utl::UCBContentHelper::IsDocument(sFileName) )
1032 					::utl::UCBContentHelper::Kill(sFileName);
1033                 m_pOutSet->Put(SfxStringItem(DSID_DOCUMENT_URL, sFileName));
1034                 bRet = sal_True;
1035 			}
1036 		}
1037         return bRet;
1038     }
1039 
1040     //-------------------------------------------------------------------------
1041     void ODbTypeWizDialogSetup::createUniqueFolderName(INetURLObject* pURL)
1042     {
1043         Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
1044         :: rtl::OUString sLastSegmentName = pURL->getName();
1045         sal_Bool bFolderExists = sal_True;
1046 		sal_Int32 i = 1;
1047         while (bFolderExists == sal_True)
1048         {
1049             bFolderExists = xSimpleFileAccess->isFolder(pURL->GetMainURL( INetURLObject::NO_DECODE ));
1050 			if (bFolderExists == sal_True)
1051             {
1052 		        i++;
1053                 pURL->setName(sLastSegmentName.concat(::rtl::OUString::valueOf(i)));
1054 			}
1055         }
1056     }
1057 
1058     //-------------------------------------------------------------------------
1059     String ODbTypeWizDialogSetup::createUniqueFileName(const INetURLObject& _rURL)
1060     {
1061         Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY);
1062         :: rtl::OUString sFilename = _rURL.getName();
1063         ::rtl::OUString BaseName = _rURL.getBase();
1064         ::rtl::OUString sExtension = _rURL.getExtension();
1065 
1066         sal_Bool bElementExists = sal_True;
1067 
1068         INetURLObject aExistenceCheck( _rURL );
1069         for ( sal_Int32 i = 1; bElementExists; )
1070         {
1071             bElementExists = xSimpleFileAccess->exists( aExistenceCheck.GetMainURL( INetURLObject::NO_DECODE ) );
1072 			if ( bElementExists )
1073             {
1074                 aExistenceCheck.setBase( BaseName.concat( ::rtl::OUString::valueOf( i ) ) );
1075                 ++i;
1076 			}
1077         }
1078         return aExistenceCheck.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
1079     }
1080     // -----------------------------------------------------------------------------
1081 	IWizardPageController* ODbTypeWizDialogSetup::getPageController( TabPage* _pCurrentPage ) const
1082     {
1083 	    OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage);
1084 	    return pPage;
1085     }
1086 
1087     // -----------------------------------------------------------------------------
1088     namespace
1089     {
1090         // .............................................................................
1091         typedef ::cppu::WeakImplHelper1 <   XTerminateListener
1092                                         >   AsyncLoader_Base;
1093         class AsyncLoader : public AsyncLoader_Base
1094         {
1095         private:
1096             Reference< XComponentLoader >       m_xFrameLoader;
1097             Reference< XDesktop >               m_xDesktop;
1098             Reference< XInteractionHandler >    m_xInteractionHandler;
1099             ::rtl::OUString                     m_sURL;
1100             OAsyncronousLink                    m_aAsyncCaller;
1101 
1102         public:
1103             AsyncLoader( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rURL );
1104 
1105             void doLoadAsync();
1106 
1107             // XTerminateListener
1108             virtual void SAL_CALL queryTermination( const EventObject& Event ) throw (TerminationVetoException, RuntimeException);
1109             virtual void SAL_CALL notifyTermination( const EventObject& Event ) throw (RuntimeException);
1110             // XEventListener
1111             virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
1112 
1113         private:
1114             DECL_LINK( OnOpenDocument, void* );
1115         };
1116 
1117         // .............................................................................
1118         AsyncLoader::AsyncLoader( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rURL )
1119             :m_sURL( _rURL )
1120             ,m_aAsyncCaller( LINK( this, AsyncLoader, OnOpenDocument ) )
1121         {
1122             try
1123             {
1124                 m_xDesktop.set( _rxORB->createInstance( SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW );
1125                 m_xFrameLoader.set( m_xDesktop, UNO_QUERY_THROW );
1126                 m_xInteractionHandler.set(
1127                     _rxORB->createInstance(
1128                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) )
1129                     ),
1130                     UNO_QUERY_THROW );
1131             }
1132             catch( const Exception& )
1133             {
1134             	DBG_UNHANDLED_EXCEPTION();
1135             }
1136         }
1137 
1138         // .............................................................................
1139         void AsyncLoader::doLoadAsync()
1140         {
1141             OSL_ENSURE( !m_aAsyncCaller.IsRunning(), "AsyncLoader:doLoadAsync: already running!" );
1142 
1143             acquire();
1144             try
1145             {
1146                 if ( m_xDesktop.is() )
1147                     m_xDesktop->addTerminateListener( this );
1148             }
1149             catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1150 
1151             m_aAsyncCaller.Call( NULL );
1152         }
1153 
1154         // .............................................................................
1155         IMPL_LINK( AsyncLoader, OnOpenDocument, void*, /*_pEmptyArg*/ )
1156         {
1157             try
1158             {
1159                 if ( m_xFrameLoader.is() )
1160                 {
1161                     ::comphelper::NamedValueCollection aLoadArgs;
1162                     aLoadArgs.put( "InteractionHandler", m_xInteractionHandler );
1163                     aLoadArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
1164 
1165                     Sequence< PropertyValue > aLoadArgPV;
1166                     aLoadArgs >>= aLoadArgPV;
1167 
1168                     m_xFrameLoader->loadComponentFromURL( m_sURL,
1169                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ),
1170                         FrameSearchFlag::ALL,
1171                         aLoadArgPV
1172                     );
1173                 }
1174             }
1175             catch( const Exception& )
1176             {
1177                 // do not assert.
1178                 // Such an exception happens for instance of the to-be-loaded document does not exist anymore.
1179             }
1180 
1181             try
1182             {
1183                 if ( m_xDesktop.is() )
1184                     m_xDesktop->removeTerminateListener( this );
1185             }
1186             catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
1187 
1188             release();
1189             return 0L;
1190         }
1191 
1192         // .............................................................................
1193         void SAL_CALL AsyncLoader::queryTermination( const EventObject& /*Event*/ ) throw (TerminationVetoException, RuntimeException)
1194         {
1195             throw TerminationVetoException();
1196         }
1197 
1198         // .............................................................................
1199         void SAL_CALL AsyncLoader::notifyTermination( const EventObject& /*Event*/ ) throw (RuntimeException)
1200         {
1201         }
1202         // .............................................................................
1203         void SAL_CALL AsyncLoader::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
1204         {
1205         }
1206     }
1207 
1208     // -----------------------------------------------------------------------------
1209     sal_Bool ODbTypeWizDialogSetup::onFinish()
1210     {
1211         if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting )
1212         {
1213             // we're not going to re-use the XModel we have - since the document the user
1214             // wants us to load could be a non-database document. Instead, we asynchronously
1215             // open the selected document. Thus, the wizard's return value is RET_CANCEL,
1216             // which means to not continue loading the database document
1217             if ( !OWizardMachine::Finnish( RET_CANCEL ) )
1218                 return sal_False;
1219 
1220             Reference< XComponentLoader > xFrameLoader;
1221             try
1222             {
1223                 AsyncLoader* pAsyncLoader = new AsyncLoader( getORB(), m_pGeneralPage->GetSelectedDocument().sURL );
1224                 ::rtl::Reference< AsyncLoader > xKeepAlive( pAsyncLoader );
1225                 pAsyncLoader->doLoadAsync();
1226             }
1227             catch( const Exception& )
1228             {
1229                 DBG_UNHANDLED_EXCEPTION();
1230             }
1231 
1232             return sal_True;
1233         }
1234 
1235         if (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL)
1236         {
1237             skipUntil(PAGE_DBSETUPWIZARD_FINAL);
1238         }
1239         if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL)
1240 	        return SaveDatabaseDocument() ? OWizardMachine::onFinish() : sal_False;
1241         else
1242         {
1243        	    enableButtons( WZB_FINISH, sal_False );
1244             return sal_False;
1245         }
1246     }
1247 
1248 //.........................................................................
1249 }	// namespace dbaui
1250 //.........................................................................
1251 
1252