1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
30 #include "connpooloptions.hxx"
31 #include "dbregisterednamesconfig.hxx"
32 #include "dbregistersettings.hxx"
33 #include "svx/svxids.hrc"
34 #include <com/sun/star/container/XNameAccess.hpp>
35 #include <com/sun/star/sdb/XDatabaseRegistrations.hpp>
36 #include <comphelper/componentcontext.hxx>
37 #include <comphelper/extract.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <svl/eitem.hxx>
40 #include <svl/itemset.hxx>
41 #include <unotools/pathoptions.hxx>
42 #include <unotools/confignode.hxx>
43 #include <tools/diagnose_ex.h>
45 //........................................................................
48 //........................................................................
50 using namespace ::utl
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::sdb
;
53 using namespace ::com::sun::star::container
;
55 //====================================================================
56 //= DbRegisteredNamesConfig
57 //====================================================================
58 //--------------------------------------------------------------------
59 void DbRegisteredNamesConfig::GetOptions( SfxItemSet
& _rFillItems
)
61 DatabaseRegistrations aSettings
;
65 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
66 Reference
< XDatabaseRegistrations
> xRegistrations(
67 aContext
.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW
);
69 Sequence
< ::rtl::OUString
> aRegistrationNames( xRegistrations
->getRegistrationNames() );
70 const ::rtl::OUString
* pRegistrationName
= aRegistrationNames
.getConstArray();
71 const ::rtl::OUString
* pRegistrationNamesEnd
= pRegistrationName
+ aRegistrationNames
.getLength();
72 for ( ; pRegistrationName
!= pRegistrationNamesEnd
; ++pRegistrationName
)
74 ::rtl::OUString
sLocation( xRegistrations
->getDatabaseLocation( *pRegistrationName
) );
75 aSettings
[ *pRegistrationName
] =
76 DatabaseRegistration( sLocation
, xRegistrations
->isDatabaseRegistrationReadOnly( *pRegistrationName
) );
79 catch( const Exception
& )
81 DBG_UNHANDLED_EXCEPTION();
84 _rFillItems
.Put( DatabaseMapItem( SID_SB_DB_REGISTER
, aSettings
) );
87 //--------------------------------------------------------------------
88 void DbRegisteredNamesConfig::SetOptions(const SfxItemSet
& _rSourceItems
)
90 // the settings for the single drivers
91 SFX_ITEMSET_GET( _rSourceItems
, pRegistrations
, DatabaseMapItem
, SID_SB_DB_REGISTER
, sal_True
);
92 if ( !pRegistrations
)
97 ::comphelper::ComponentContext
aContext( ::comphelper::getProcessServiceFactory() );
98 Reference
< XDatabaseRegistrations
> xRegistrations(
99 aContext
.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW
);
101 const DatabaseRegistrations
& rNewRegistrations
= pRegistrations
->getRegistrations();
102 for ( DatabaseRegistrations::const_iterator reg
= rNewRegistrations
.begin();
103 reg
!= rNewRegistrations
.end();
107 const ::rtl::OUString sName
= reg
->first
;
108 const ::rtl::OUString sLocation
= reg
->second
.sLocation
;
110 if ( xRegistrations
->hasRegisteredDatabase( sName
) )
112 if ( !xRegistrations
->isDatabaseRegistrationReadOnly( sName
) )
113 xRegistrations
->changeDatabaseLocation( sName
, sLocation
);
116 OSL_ENSURE( xRegistrations
->getDatabaseLocation( sName
) == sLocation
,
117 "DbRegisteredNamesConfig::SetOptions: somebody changed a read-only registration. How unrespectful." );
121 xRegistrations
->registerDatabaseLocation( sName
, sLocation
);
124 // delete unused entries
125 Sequence
< ::rtl::OUString
> aRegistrationNames
= xRegistrations
->getRegistrationNames();
126 const ::rtl::OUString
* pRegistrationName
= aRegistrationNames
.getConstArray();
127 const ::rtl::OUString
* pRegistrationNamesEnd
= pRegistrationName
+ aRegistrationNames
.getLength();
128 for ( ; pRegistrationName
!= pRegistrationNamesEnd
; ++pRegistrationName
)
130 if ( rNewRegistrations
.find( *pRegistrationName
) == rNewRegistrations
.end() )
131 xRegistrations
->revokeDatabaseLocation( *pRegistrationName
);
134 catch( const Exception
& )
136 DBG_UNHANDLED_EXCEPTION();
140 //........................................................................
142 //........................................................................