1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
|
/*************************************************************************
*
* $RCSfile: ConnectionHelper.cxx,v $
*
* $Revision: 1.4 $
*
* last change: $Author: kz $ $Date: 2005-01-21 17:11:18 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc..
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): Ocke Janssen
*
*
************************************************************************/
#ifndef DBAUI_CONNECTIONHELPER_HXX
#include "ConnectionHelper.hxx"
#endif
#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
#endif
#ifndef _DBAUI_AUTOCONTROLS_HRC_
#include "AutoControls.hrc"
#endif
#ifndef _DBU_DLG_HRC_
#include "dbu_dlg.hrc"
#endif
#ifndef _DBU_MISC_HRC_
#include "dbu_misc.hrc"
#endif
#ifndef _SFXITEMSET_HXX
#include <svtools/itemset.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX
#include <svtools/moduleoptions.hxx>
#endif
#ifndef _SFX_FCONTNR_HXX
#include <sfx2/fcontnr.hxx>
#endif
#ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX
#include <svtools/pathoptions.hxx>
#endif
#ifndef _SFXSTRITEM_HXX
#include <svtools/stritem.hxx>
#endif
#ifndef _SFXENUMITEM_HXX
#include <svtools/eitem.hxx>
#endif
#ifndef _SFXINTITEM_HXX
#include <svtools/intitem.hxx>
#endif
#ifndef _DBAUI_DATASOURCEITEMS_HXX_
#include "dsitems.hxx"
#endif
#ifndef _DBA_DBACCESS_HELPID_HRC_
#include "dbaccess_helpid.hrc"
#endif
#ifndef _DBAUI_LOCALRESACCESS_HXX_
#include "localresaccess.hxx"
#endif
#ifndef _OSL_PROCESS_H_
#include <osl/process.h>
#endif
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef _FILEDLGHELPER_HXX
#include <sfx2/filedlghelper.hxx>
#endif
#ifndef _DBAUI_DBADMIN_HXX_
#include "dbadmin.hxx"
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#ifndef _VCL_STDTEXT_HXX
#include <vcl/stdtext.hxx>
#endif
#ifndef _DBAUI_SQLMESSAGE_HXX_
#include "sqlmessage.hxx"
#endif
#ifndef _DBAUI_ODBC_CONFIG_HXX_
#include "odbcconfig.hxx"
#endif
#ifndef _DBAUI_DSSELECT_HXX_
#include "dsselect.hxx"
#endif
#ifndef SVTOOLS_FILENOTATION_HXX_
#include <svtools/filenotation.hxx>
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_XFOLDERPICKER_HPP_
#include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
#include <com/sun/star/sdbc/XRow.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
#include <com/sun/star/awt/XWindow.hpp>
#endif
// #106016# ------------------------------------
#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
#include <com/sun/star/task/XInteractionHandler.hpp>
#endif
#ifndef _COM_SUN_STAR_TASK_XPROGRESSHANDLER_HPP_
#include <com/sun/star/ucb/XProgressHandler.hpp>
#endif
#ifndef DBAUI_TOOLS_HXX
#include "UITools.hxx"
#endif
#ifndef _UNOTOOLS_LOCALFILEHELPER_HXX
#include <unotools/localfilehelper.hxx>
#endif
#ifndef _UNOTOOLS_UCBHELPER_HXX
#include <unotools/ucbhelper.hxx>
#endif
#ifndef _UCBHELPER_COMMANDENVIRONMENT_HXX
#include <ucbhelper/commandenvironment.hxx>
#endif
#ifndef DBAUI_FILEPICKER_INTERACTION_HXX
#include "finteraction.hxx"
#endif
#ifndef _CONNECTIVITY_COMMONTOOLS_HXX_
#include <connectivity/CommonTools.hxx>
#endif
#ifndef _URLOBJ_HXX
#include <tools/urlobj.hxx>
#endif
#ifndef _SFX_DOCFILT_HACK_HXX
#include <sfx2/docfilt.hxx>
#endif
#if defined(WIN) || defined(WNT)
#define _ADO_DATALINK_BROWSE_
#endif
#ifdef _ADO_DATALINK_BROWSE_
typedef void* HWND;
typedef void* HMENU;
typedef void* HDC;
#ifndef _SV_SYSDATA_HXX
#include <vcl/sysdata.hxx>
#endif
#ifndef _DBAUI_ADO_DATALINK_HXX_
#include "adodatalinks.hxx"
#endif
#endif //_ADO_DATALINK_BROWSE_
//.........................................................................
namespace dbaui
{
//.........................................................................
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::container;
using namespace ::dbtools;
using namespace ::svt;
OConnectionHelper::OConnectionHelper( Window* pParent, const ResId& _rId, const SfxItemSet& _rCoreAttrs)
:OGenericAdministrationPage(pParent, _rId, _rCoreAttrs)
,m_aFT_Connection(this, ResId(FT_AUTOBROWSEURL))
,m_aET_Connection(this, ResId(ET_AUTOBROWSEURL))
,m_aPB_Connection(this, ResId(PB_AUTOBROWSEURL))
{
// extract the datasource type collection from the item set
DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _rCoreAttrs.GetItem(DSID_TYPECOLLECTION));
if (pCollectionItem)
m_pCollection = pCollectionItem->getCollection();
m_aPB_Connection.SetClickHdl(LINK(this, OConnectionHelper, OnBrowseConnections));
DBG_ASSERT(m_pCollection, "OConnectionHelper::OConnectionHelper : really need a DSN type collection !");
}
OConnectionHelper::~OConnectionHelper()
{
}
// -----------------------------------------------------------------------
void OConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
{
// check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
sal_Bool bValid, bReadonly;
getFlags(_rSet, bValid, bReadonly);
m_eType = m_pAdminDialog->getDatasourceType(_rSet);
BOOL bEnableBrowseButton = m_pCollection->supportsBrowsing(m_eType);
m_aFT_Connection.Show();
m_aET_Connection.Show();
m_aET_Connection.ShowPrefix(FALSE);
m_aPB_Connection.Show(sal_True);
m_aET_Connection.ShowPrefix(FALSE);
OLocalResourceAccess aLocRes( PAGE_CONNECTION, RSC_TABPAGE );
m_aPB_Connection.Show(bEnableBrowseButton);
SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True);
// forward the values to the controls
if ( bValid )
{
String sUrl = pUrlItem->GetValue();
setURL( sUrl );
checkTestConnection();
m_aET_Connection.ClearModifyFlag();
}
OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
}
// -----------------------------------------------------------------------
IMPL_LINK(OConnectionHelper, OnBrowseConnections, PushButton*, _pButton)
{
OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
switch ( m_eType )
{
case DST_DBASE:
case DST_FLAT:
{
try
{
::rtl::OUString sFolderPickerService = ::rtl::OUString::createFromAscii(SERVICE_UI_FOLDERPICKER);
Reference< XFolderPicker > xFolderPicker(m_xORB->createInstance(sFolderPickerService), UNO_QUERY);
if (!xFolderPicker.is())
{
ShowServiceNotAvailableError(GetParent(), sFolderPickerService, sal_True);
break;
}
sal_Bool bDoBrowse = sal_False;
String sOldPath = getURLNoPrefix();
do
{
if (sOldPath.Len())
xFolderPicker->setDisplayDirectory(sOldPath);
if (0 == xFolderPicker->execute())
// cancelled by the user
return 0L;
sOldPath = xFolderPicker->getDirectory();
switch (checkPathExistence(sOldPath))
{
case RET_RETRY:
bDoBrowse = sal_True;
break;
case RET_CANCEL:
return 0L;
default:
break;
}
}
while (bDoBrowse);
String sSelectedDirectory = xFolderPicker->getDirectory();
INetURLObject aSelectedDirectory( sSelectedDirectory, INetURLObject::WAS_ENCODED, RTL_TEXTENCODING_UTF8 );
// for UI purpose, we don't want to have the path encoded
sSelectedDirectory = aSelectedDirectory.GetMainURL( INetURLObject::DECODE_WITH_CHARSET, RTL_TEXTENCODING_UTF8 );
setURLNoPrefix( sSelectedDirectory );
SetRoadmapStateValue(sal_True);
callModifiedHdl();
}
catch(const Exception&)
{
DBG_ERROR("OConnectionHelper::OnBrowseConnections: caught an exception while browsing for the path!");
}
}
break;
case DST_CALC:
{
::sfx2::FileDialogHelper aFileDlg(WB_3DLOOK | WB_STDMODAL | WB_OPEN
,SvtModuleOptions().GetFactoryEmptyDocumentURL(SvtModuleOptions::E_CALC)
,SFX_FILTER_IMPORT);
askForFileName(aFileDlg);
}
break;
case DST_MSACCESS:
{
::rtl::OUString sExt(RTL_CONSTASCII_USTRINGPARAM("*.mdb"));
String sFilterName(ModuleRes (STR_MSACCESS_FILTERNAME));
::sfx2::FileDialogHelper aFileDlg(WB_3DLOOK | WB_STDMODAL | WB_OPEN);
aFileDlg.AddFilter(sFilterName,sExt);
aFileDlg.SetCurrentFilter(sFilterName);
askForFileName(aFileDlg);
}
break;
case DST_ADABAS:
{
// collect all names from the config dir
// and all dir's of the DBWORK/wrk or DBROOT/wrk dir
// compare the names
// collect the names of the installed databases
StringBag aInstalledDBs;
::rtl::OUString sAdabasConfigDir,sAdabasWorkDir,sRootDir;
::rtl::OUString sTemp(RTL_CONSTASCII_USTRINGPARAM("DBWORK"));
rtl_uString* pDbVar = NULL;
if(osl_getEnvironment(sTemp.pData,&pDbVar) == osl_Process_E_None && pDbVar)
{
sAdabasWorkDir = pDbVar;
String sTemp;
sal_Bool bOk = utl::LocalFileHelper::ConvertPhysicalNameToURL(sAdabasWorkDir,sTemp);
sAdabasWorkDir = sTemp;
rtl_uString_release(pDbVar);
pDbVar = NULL;
}
sTemp = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DBCONFIG"));
if(osl_getEnvironment(sTemp.pData,&pDbVar) == osl_Process_E_None && pDbVar)
{
sAdabasConfigDir = pDbVar;
String sTemp;
sal_Bool bOk = utl::LocalFileHelper::ConvertPhysicalNameToURL(sAdabasConfigDir,sTemp);
sAdabasConfigDir = sTemp;
rtl_uString_release(pDbVar);
pDbVar = NULL;
}
sTemp = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DBROOT"));
if(osl_getEnvironment(sTemp.pData,&pDbVar) == osl_Process_E_None && pDbVar)
{
sRootDir = pDbVar;
String sTemp;
sal_Bool bOk = utl::LocalFileHelper::ConvertPhysicalNameToURL(sRootDir,sTemp);
sRootDir = sTemp;
rtl_uString_release(pDbVar);
pDbVar = NULL;
}
sal_Bool bOldFashion = sAdabasConfigDir.getLength() && sAdabasWorkDir.getLength();
if(!bOldFashion) // we have a normal adabas installation
{ // so we check the local database names in $DBROOT/config
sAdabasConfigDir = sRootDir;
sAdabasWorkDir = sRootDir;
}
if(sAdabasConfigDir.getLength() && sAdabasWorkDir.getLength() && sRootDir.getLength())
{
aInstalledDBs = getInstalledAdabasDBs(sAdabasConfigDir,sAdabasWorkDir);
if(!aInstalledDBs.size() && bOldFashion)
{
sAdabasConfigDir = sRootDir;
sAdabasWorkDir = sRootDir;
aInstalledDBs = getInstalledAdabasDBs(sAdabasConfigDir,sAdabasWorkDir);
}
ODatasourceSelectDialog aSelector(GetParent(), aInstalledDBs, m_eType,m_pItemSetHelper->getWriteOutputSet());
if (RET_OK == aSelector.Execute())
{
setURLNoPrefix(aSelector.GetSelected());
// checkCreateDatabase(DST_ADABAS);
SetRoadmapStateValue(sal_True);
callModifiedHdl();
}
}
else
{
OLocalResourceAccess aLocRes( PAGE_CONNECTION, RSC_TABPAGE );
String sError = String(ResId(STR_NO_ADABASE_DATASOURCES));
ErrorBox aBox(this, WB_OK, sError);
aBox.Execute();
}
}
break;
case DST_MYSQL_ODBC:
case DST_ODBC:
{
// collect all ODBC data source names
::rtl::OUString sDataSource;
if ( getSelectedDataSource(m_eType,sDataSource) && sDataSource.getLength() )
{
setURLNoPrefix(sDataSource);
SetRoadmapStateValue(sal_True);
callModifiedHdl();
}
else
return 1L;
}
break;
#ifdef _ADO_DATALINK_BROWSE_
case DST_ADO:
{
::rtl::OUString sOldDataSource=getURLNoPrefix();
::rtl::OUString sNewDataSource;
HWND hWnd = GetParent()->GetSystemData()->hWnd;
sNewDataSource = getAdoDatalink((long)hWnd,sOldDataSource);
if ( sNewDataSource.getLength() )
{
setURLNoPrefix(sNewDataSource);
SetRoadmapStateValue(sal_True);
callModifiedHdl();
}
else
return 1L;
}
break;
#endif
}
checkTestConnection();
return 0L;
}
//-------------------------------------------------------------------------
bool OConnectionHelper::checkTestConnection()
{
return true;
}
//-------------------------------------------------------------------------
void OConnectionHelper::implSetURL( const String& _rURL, sal_Bool _bPrefix )
{
String sURL( _rURL );
DBG_ASSERT( m_pCollection, "OConnectionHelper::setURL: have no interpreter for the URLs!" );
if ( m_pCollection && sURL.Len() )
{
if ( m_pCollection->isFileSystemBased( m_eType ) )
{
// get the tow parts: prefix and file URL
String sTypePrefix, sFileURLEncoded;
if ( _bPrefix )
{
sTypePrefix = m_pCollection->getDatasourcePrefix( m_eType );
sFileURLEncoded = m_pCollection->cutPrefix( sURL );
}
else
{
sFileURLEncoded = sURL;
}
// substitute any variables
sFileURLEncoded = SvtPathOptions().SubstituteVariable( sFileURLEncoded );
// decode the URL
sURL = sTypePrefix;
if ( sFileURLEncoded.Len() )
{
OFileNotation aFileNotation(sFileURLEncoded);
// set this decoded URL as text
sURL += String(aFileNotation.get(OFileNotation::N_SYSTEM));
}
}
}
if ( _bPrefix )
m_aET_Connection.SetText( sURL );
else
m_aET_Connection.SetTextNoPrefix( sURL );
}
//-------------------------------------------------------------------------
String OConnectionHelper::implGetURL( sal_Bool _bPrefix ) const
{
// get the pure text
String sURL = _bPrefix ? m_aET_Connection.GetText() : m_aET_Connection.GetTextNoPrefix();
DBG_ASSERT( m_pCollection, "OConnectionHelper::implGetURL: have no interpreter for the URLs!" );
if ( m_pCollection && sURL.Len() )
{
if ( m_pCollection->isFileSystemBased( m_eType ) )
{
// get the tow parts: prefix and file URL
String sTypePrefix, sFileURLDecoded;
if ( _bPrefix )
{
sTypePrefix = m_pCollection->getDatasourcePrefix( m_eType );
sFileURLDecoded = m_pCollection->cutPrefix( sURL );
}
else
{
sFileURLDecoded = sURL;
}
// encode the URL
INetURLObject aFileURL( sFileURLDecoded, INetURLObject::ENCODE_ALL, RTL_TEXTENCODING_UTF8 );
sFileURLDecoded = aFileURL.GetMainURL( INetURLObject::NO_DECODE );
sURL = sTypePrefix;
if ( sFileURLDecoded.Len() )
{
OFileNotation aFileNotation(sFileURLDecoded,OFileNotation::N_SYSTEM);
// set this decoded URL as text
sURL += String(aFileNotation.get(OFileNotation::N_URL));
}
}
}
return sURL;
}
//-------------------------------------------------------------------------
String OConnectionHelper::getURL( ) const
{
return implGetURL( sal_True );
}
//-------------------------------------------------------------------------
void OConnectionHelper::setURL( const String& _rURL )
{
implSetURL( _rURL, sal_True );
}
//-------------------------------------------------------------------------
String OConnectionHelper::getURLNoPrefix( ) const
{
return implGetURL( sal_False );
}
//-------------------------------------------------------------------------
void OConnectionHelper::setURLNoPrefix( const String& _rURL )
{
implSetURL( _rURL, sal_False );
}
//-------------------------------------------------------------------------
String OConnectionHelper::getConnectionURL( ) const
{
return getURL( );
}
//-------------------------------------------------------------------------
void OConnectionHelper::changeConnectionURL( const String& _rNewDSN )
{
setURL( _rNewDSN );
}
//-------------------------------------------------------------------------
sal_Int32 OConnectionHelper::checkPathExistence(const String& _rURL)
{
IS_PATH_EXIST e_exists = pathExists(_rURL, sal_False);
if (( e_exists == PATH_NOT_EXIST) || ( e_exists == PATH_NOT_KNOWN))
{
String sQuery(ModuleRes(STR_ASK_FOR_DIRECTORY_CREATION));
OFileNotation aTransformer(_rURL);
sQuery.SearchAndReplaceAscii("$path$", aTransformer.get(OFileNotation::N_SYSTEM));
m_bUserGrabFocus = sal_False;
QueryBox aQuery(GetParent(), WB_YES_NO | WB_DEF_YES, sQuery);
sal_Int32 nQueryResult = aQuery.Execute();
m_bUserGrabFocus = sal_True;
switch (nQueryResult)
{
case RET_YES:
{
sal_Bool bTryCreate = sal_False;
do
{
if ( !createDirectoryDeep(_rURL) )
{ // could not create the directory
sQuery = String(ModuleRes(STR_COULD_NOT_CREATE_DIRECTORY));
sQuery.SearchAndReplaceAscii("$name$", aTransformer.get(OFileNotation::N_SYSTEM));
m_bUserGrabFocus = sal_False;
QueryBox aWhatToDo(GetParent(), WB_RETRY_CANCEL | WB_DEF_RETRY, sQuery);
nQueryResult = aWhatToDo.Execute();
m_bUserGrabFocus = sal_True;
if (RET_RETRY == nQueryResult)
bTryCreate = sal_True;
else
{
SetRoadmapStateValue(sal_False);
callModifiedHdl();
return RET_RETRY;
}
}
}
while (bTryCreate);
}
break;
case RET_NO:
SetRoadmapStateValue(sal_False);
callModifiedHdl();
return RET_OK;
default:
// cancelled
SetRoadmapStateValue(sal_False);
callModifiedHdl();
return RET_CANCEL;
}
}
/* else
{
// TODO: error msg
return RET_CANCEL;
} */
SetRoadmapStateValue(sal_True);
callModifiedHdl();
return RET_OK;
}
//-------------------------------------------------------------------------
StringBag OConnectionHelper::getInstalledAdabasDBDirs(const String& _rPath,const ::ucb::ResultSetInclude& _reResultSetInclude)
{
INetURLObject aNormalizer;
aNormalizer.SetSmartProtocol(INET_PROT_FILE);
aNormalizer.SetSmartURL(_rPath);
String sAdabasConfigDir = aNormalizer.GetMainURL(INetURLObject::NO_DECODE);
::ucb::Content aAdabasConfigDir;
try
{
aAdabasConfigDir = ::ucb::Content(sAdabasConfigDir, Reference< ::com::sun::star::ucb::XCommandEnvironment >());
}
catch(::com::sun::star::ucb::ContentCreationException&)
{
return StringBag();
}
StringBag aInstalledDBs;
sal_Bool bIsFolder = sal_False;
try
{
bIsFolder = aAdabasConfigDir.isFolder();
}
catch(Exception&) // the exception is thrown when the path doesn't exists
{
}
if (bIsFolder && aAdabasConfigDir.get().is())
{ // we have a content for the directory, loop through all entries
Sequence< ::rtl::OUString > aProperties(1);
aProperties[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title"));
try
{
Reference< XResultSet > xFiles = aAdabasConfigDir.createCursor(aProperties, _reResultSetInclude);
Reference< XRow > xRow(xFiles, UNO_QUERY);
xFiles->beforeFirst();
while (xFiles->next())
{
#ifdef DBG_UTIL
::rtl::OUString sName = xRow->getString(1);
#endif
aInstalledDBs.insert(xRow->getString(1));
}
}
catch(Exception&)
{
DBG_ERROR("OConnectionHelper::getInstalledAdabasDBDirs: could not enumerate the adabas config files!");
}
}
return aInstalledDBs;
}
// -----------------------------------------------------------------------------
StringBag OConnectionHelper::getInstalledAdabasDBs(const String &_rConfigDir,const String &_rWorkDir)
{
String sAdabasConfigDir(_rConfigDir),sAdabasWorkDir(_rWorkDir);
if (sAdabasConfigDir.Len() && ('/' == sAdabasConfigDir.GetBuffer()[sAdabasConfigDir.Len() - 1]))
sAdabasConfigDir.AppendAscii("config");
else
sAdabasConfigDir.AppendAscii("/config");
if (sAdabasWorkDir.Len() && ('/' == sAdabasWorkDir.GetBuffer()[sAdabasWorkDir.Len() - 1]))
sAdabasWorkDir.AppendAscii("wrk");
else
sAdabasWorkDir.AppendAscii("/wrk");
// collect the names of the installed databases
StringBag aInstalledDBs;
// collect the names of the installed databases
StringBag aConfigDBs,aWrkDBs;
aConfigDBs = getInstalledAdabasDBDirs(sAdabasConfigDir,::ucb::INCLUDE_DOCUMENTS_ONLY);
aWrkDBs = getInstalledAdabasDBDirs(sAdabasWorkDir,::ucb::INCLUDE_FOLDERS_ONLY);
ConstStringBagIterator aOuter = aConfigDBs.begin();
for(;aOuter != aConfigDBs.end();++aOuter)
{
ConstStringBagIterator aInner = aWrkDBs.begin();
for (;aInner != aWrkDBs.end(); ++aInner)
{
if (aInner->equalsIgnoreAsciiCase(*aOuter))
{
aInstalledDBs.insert(*aInner);
break;
}
}
}
return aInstalledDBs;
}
// #106016# -------------------------------------------------------------------
IS_PATH_EXIST OConnectionHelper::pathExists(const ::rtl::OUString& _rURL, sal_Bool bIsFile) const
{
::ucb::Content aCheckExistence;
sal_Bool bExists = sal_False;
IS_PATH_EXIST eExists = PATH_NOT_EXIST;
Reference< ::com::sun::star::task::XInteractionHandler > xInteractionHandler = Reference< ::com::sun::star::task::XInteractionHandler >(
m_xORB->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler") ) ), UNO_QUERY );
OFilePickerInteractionHandler* pHandler = new OFilePickerInteractionHandler(xInteractionHandler);
xInteractionHandler = pHandler;
Reference< XCommandEnvironment > xCmdEnv = new ::ucb::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
try
{
aCheckExistence = ::ucb::Content(_rURL, xCmdEnv );
bExists = bIsFile? aCheckExistence.isDocument(): aCheckExistence.isFolder();
eExists = bExists? PATH_EXIST: PATH_NOT_EXIST;
}
catch(const Exception&)
{
eExists = ( pHandler && pHandler->isDoesNotExist() ) ? PATH_NOT_EXIST: (bIsFile ? PATH_NOT_EXIST : PATH_NOT_KNOWN);
}
return eExists;
}
//-------------------------------------------------------------------------
long OConnectionHelper::PreNotify( NotifyEvent& _rNEvt )
{
if ( (DST_DBASE == m_eType)
|| (DST_FLAT == m_eType)
|| (DST_MSACCESS == m_eType)
|| (DST_CALC == m_eType) )
switch (_rNEvt.GetType())
{
case EVENT_GETFOCUS:
if (m_aET_Connection.IsWindowOrChild(_rNEvt.GetWindow()) && m_bUserGrabFocus)
{ // a descendant of the URL edit field got the focus
m_aET_Connection.SaveValueNoPrefix();
}
break;
case EVENT_LOSEFOCUS:
//if (m_aET_Connection.IsWindowOrChild(_rNEvt.GetWindow()) && m_bUserGrabFocus)
//{ // a descendant of the URL edit field lost the focus
// if (!commitURL())
// return 1L; // handled
//}
break;
}
return OGenericAdministrationPage::PreNotify( _rNEvt );
}
//-------------------------------------------------------------------------
sal_Bool OConnectionHelper::createDirectoryDeep(const String& _rPathURL)
{
::rtl::OUString sPath(_rPathURL);
// get an URL object analyzing the URL for us ...
INetURLObject aParser;
aParser.SetURL(_rPathURL);
INetProtocol eProtocol = aParser.GetProtocol();
::std::vector< ::rtl::OUString > aToBeCreated; // the to-be-created levels
// search a level which exists
// #106016# ---------------------
IS_PATH_EXIST eParentExists = PATH_NOT_EXIST;
while ( eParentExists == PATH_NOT_EXIST && aParser.getSegmentCount())
{
aToBeCreated.push_back(aParser.getName()); // remember the local name for creation
aParser.removeSegment(); // cut the local name
eParentExists = pathExists(aParser.GetMainURL(INetURLObject::NO_DECODE), sal_False);
}
if (!aParser.getSegmentCount())
return sal_False;
// create all the missing levels
try
{
// the parent content
Reference< XCommandEnvironment > xEmptyEnv;
::ucb::Content aParent(aParser.GetMainURL(INetURLObject::NO_DECODE), xEmptyEnv);
::rtl::OUString sContentType;
if ( INET_PROT_FILE == eProtocol )
{
sContentType = ::rtl::OUString::createFromAscii( "application/vnd.sun.staroffice.fsys-folder" );
// the file UCP currently does not support the ContentType property
}
else
{
Any aContentType = aParent.getPropertyValue( ::rtl::OUString::createFromAscii( "ContentType" ) );
aContentType >>= sContentType;
}
// the properties which need to be set on the new content
Sequence< ::rtl::OUString > aNewDirectoryProperties(1);
aNewDirectoryProperties[0] = ::rtl::OUString::createFromAscii("Title");
// the values to be set
Sequence< Any > aNewDirectoryAttributes(1);
// loop
for ( ::std::vector< ::rtl::OUString >::reverse_iterator aLocalName = aToBeCreated.rbegin();
aLocalName != aToBeCreated.rend();
++aLocalName
)
{
aNewDirectoryAttributes[0] <<= *aLocalName;
if (!aParent.insertNewContent(sContentType, aNewDirectoryProperties, aNewDirectoryAttributes, aParent))
return sal_False;
}
}
catch (const Exception& e)
{
OSL_ENSURE( sal_False, "" );
e; // make compiler happy
return sal_False;
}
return sal_True;
}
// -----------------------------------------------------------------------
void OConnectionHelper::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
{
_rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFT_Connection));
_rControlList.push_back(new ODisableWrapper<PushButton>(&m_aPB_Connection));
}
// -----------------------------------------------------------------------
void OConnectionHelper::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
{
_rControlList.push_back(new OSaveValueWrapper<Edit>(&m_aET_Connection));
}
//-------------------------------------------------------------------------
sal_Bool OConnectionHelper::commitURL()
{
String sURL;
String sOldPath;
sOldPath = m_aET_Connection.GetSavedValueNoPrefix();
sURL = m_aET_Connection.GetTextNoPrefix();
if ( (DST_DBASE == m_eType)
|| (DST_FLAT == m_eType)
|| (DST_MSACCESS == m_eType)
|| (DST_CALC == m_eType) )
{
if ((sURL != sOldPath) && (0 != sURL.Len()))
{ // the text changed since entering the control
// the path may be in system notation ....
OFileNotation aTransformer(sURL);
sURL = aTransformer.get(OFileNotation::N_URL);
if ( (DST_CALC == m_eType) || (DST_MSACCESS == m_eType) )
{ // #106016# --------------------------
if( pathExists(sURL, sal_True) == PATH_NOT_EXIST )
{
String sFile = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) );
sFile.SearchAndReplaceAscii("$file$", aTransformer.get(OFileNotation::N_SYSTEM));
OSQLMessageBox(this,String(ModuleRes(STR_STAT_WARNING)),sFile).Execute();
setURLNoPrefix(sOldPath);
SetRoadmapStateValue(sal_False);
callModifiedHdl();
return sal_False;
}
else
{
// setURLNoPrefix(sURL);
// m_aET_Connection.SaveValueNoPrefix();
}
}
else
{
switch (checkPathExistence(sURL))
{
case RET_RETRY:
m_bUserGrabFocus = sal_False;
m_aET_Connection.GrabFocus();
m_bUserGrabFocus = sal_True;
return sal_False;
case RET_CANCEL:
setURLNoPrefix(sOldPath);
return sal_False;
default:
// accept the input
// setURLNoPrefix(sURL);
// m_aET_Connection.SaveValueNoPrefix();
break;
}
}
}
}
setURLNoPrefix(sURL);
m_aET_Connection.SaveValueNoPrefix();
return sal_True;
}
//-------------------------------------------------------------------------
void OConnectionHelper::askForFileName(::sfx2::FileDialogHelper& _aFileOpen)
{
String sOldPath = getURLNoPrefix();
if ( sOldPath.Len() )
_aFileOpen.SetDisplayDirectory(sOldPath);
else
_aFileOpen.SetDisplayDirectory( SvtPathOptions().GetWorkPath() );
if (0 == _aFileOpen.Execute())
{
setURLNoPrefix(_aFileOpen.GetPath());
SetRoadmapStateValue(checkTestConnection());
callModifiedHdl();
}
}
//.........................................................................
} // namespace dbaui
//.........................................................................
|