Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "connpooloptions.hxx"
21 : #include "dbregisterednamesconfig.hxx"
22 : #include "dbregistersettings.hxx"
23 : #include "svx/svxids.hrc"
24 : #include <com/sun/star/container/XNameAccess.hpp>
25 : #include <com/sun/star/sdb/DatabaseContext.hpp>
26 : #include <comphelper/componentcontext.hxx>
27 : #include <comphelper/extract.hxx>
28 : #include <comphelper/processfactory.hxx>
29 : #include <svl/eitem.hxx>
30 : #include <svl/itemset.hxx>
31 : #include <unotools/pathoptions.hxx>
32 : #include <unotools/confignode.hxx>
33 : #include <tools/diagnose_ex.h>
34 :
35 : //........................................................................
36 : namespace svx
37 : {
38 : //........................................................................
39 :
40 : using namespace ::utl;
41 : using namespace ::com::sun::star::uno;
42 : using namespace ::com::sun::star::sdb;
43 : using namespace ::com::sun::star::container;
44 :
45 : //====================================================================
46 : //= DbRegisteredNamesConfig
47 : //====================================================================
48 : //--------------------------------------------------------------------
49 0 : void DbRegisteredNamesConfig::GetOptions( SfxItemSet& _rFillItems )
50 : {
51 0 : DatabaseRegistrations aSettings;
52 :
53 : try
54 : {
55 0 : Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
56 : Reference< XDatabaseContext > xRegistrations(
57 0 : DatabaseContext::create(xContext) );
58 :
59 0 : Sequence< ::rtl::OUString > aRegistrationNames( xRegistrations->getRegistrationNames() );
60 0 : const ::rtl::OUString* pRegistrationName = aRegistrationNames.getConstArray();
61 0 : const ::rtl::OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength();
62 0 : for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName )
63 : {
64 0 : ::rtl::OUString sLocation( xRegistrations->getDatabaseLocation( *pRegistrationName ) );
65 0 : aSettings[ *pRegistrationName ] =
66 0 : DatabaseRegistration( sLocation, xRegistrations->isDatabaseRegistrationReadOnly( *pRegistrationName ) );
67 0 : }
68 : }
69 0 : catch( const Exception& )
70 : {
71 : DBG_UNHANDLED_EXCEPTION();
72 : }
73 :
74 0 : _rFillItems.Put( DatabaseMapItem( SID_SB_DB_REGISTER, aSettings ) );
75 0 : }
76 :
77 : //--------------------------------------------------------------------
78 0 : void DbRegisteredNamesConfig::SetOptions(const SfxItemSet& _rSourceItems)
79 : {
80 : // the settings for the single drivers
81 0 : SFX_ITEMSET_GET( _rSourceItems, pRegistrations, DatabaseMapItem, SID_SB_DB_REGISTER, sal_True );
82 0 : if ( !pRegistrations )
83 0 : return;
84 :
85 : try
86 : {
87 : Reference< XDatabaseContext > xRegistrations(
88 : DatabaseContext::create(
89 0 : comphelper::getProcessComponentContext()));
90 :
91 0 : const DatabaseRegistrations& rNewRegistrations = pRegistrations->getRegistrations();
92 0 : for ( DatabaseRegistrations::const_iterator reg = rNewRegistrations.begin();
93 0 : reg != rNewRegistrations.end();
94 : ++reg
95 : )
96 : {
97 0 : const ::rtl::OUString sName = reg->first;
98 0 : const ::rtl::OUString sLocation = reg->second.sLocation;
99 :
100 0 : if ( xRegistrations->hasRegisteredDatabase( sName ) )
101 : {
102 0 : if ( !xRegistrations->isDatabaseRegistrationReadOnly( sName ) )
103 0 : xRegistrations->changeDatabaseLocation( sName, sLocation );
104 : else
105 : {
106 : OSL_ENSURE( xRegistrations->getDatabaseLocation( sName ) == sLocation,
107 : "DbRegisteredNamesConfig::SetOptions: somebody changed a read-only registration. How unrespectful." );
108 : }
109 : }
110 : else
111 0 : xRegistrations->registerDatabaseLocation( sName, sLocation );
112 0 : }
113 :
114 : // delete unused entries
115 0 : Sequence< ::rtl::OUString > aRegistrationNames = xRegistrations->getRegistrationNames();
116 0 : const ::rtl::OUString* pRegistrationName = aRegistrationNames.getConstArray();
117 0 : const ::rtl::OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength();
118 0 : for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName )
119 : {
120 0 : if ( rNewRegistrations.find( *pRegistrationName ) == rNewRegistrations.end() )
121 0 : xRegistrations->revokeDatabaseLocation( *pRegistrationName );
122 0 : }
123 : }
124 0 : catch( const Exception& )
125 : {
126 : //DBG_UNHANDLED_EXCEPTION();
127 : }
128 : }
129 :
130 : //........................................................................
131 3 : } // namespace svx
132 : //........................................................................
133 :
134 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|