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/extract.hxx>
27 : #include <comphelper/processfactory.hxx>
28 : #include <svl/eitem.hxx>
29 : #include <svl/itemset.hxx>
30 : #include <unotools/pathoptions.hxx>
31 : #include <unotools/confignode.hxx>
32 : #include <tools/diagnose_ex.h>
33 :
34 :
35 : namespace svx
36 : {
37 :
38 :
39 : using namespace ::utl;
40 : using namespace ::com::sun::star::uno;
41 : using namespace ::com::sun::star::sdb;
42 : using namespace ::com::sun::star::container;
43 :
44 0 : void DbRegisteredNamesConfig::GetOptions( SfxItemSet& _rFillItems )
45 : {
46 0 : DatabaseRegistrations aSettings;
47 :
48 : try
49 : {
50 0 : Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
51 : Reference< XDatabaseContext > xRegistrations(
52 0 : DatabaseContext::create(xContext) );
53 :
54 0 : Sequence< OUString > aRegistrationNames( xRegistrations->getRegistrationNames() );
55 0 : const OUString* pRegistrationName = aRegistrationNames.getConstArray();
56 0 : const OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength();
57 0 : for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName )
58 : {
59 0 : OUString sLocation( xRegistrations->getDatabaseLocation( *pRegistrationName ) );
60 0 : aSettings[ *pRegistrationName ] =
61 0 : DatabaseRegistration( sLocation, xRegistrations->isDatabaseRegistrationReadOnly( *pRegistrationName ) );
62 0 : }
63 : }
64 0 : catch( const Exception& )
65 : {
66 : DBG_UNHANDLED_EXCEPTION();
67 : }
68 :
69 0 : _rFillItems.Put( DatabaseMapItem( SID_SB_DB_REGISTER, aSettings ) );
70 0 : }
71 :
72 :
73 0 : void DbRegisteredNamesConfig::SetOptions(const SfxItemSet& _rSourceItems)
74 : {
75 : // the settings for the single drivers
76 0 : SFX_ITEMSET_GET( _rSourceItems, pRegistrations, DatabaseMapItem, SID_SB_DB_REGISTER, true );
77 0 : if ( !pRegistrations )
78 0 : return;
79 :
80 : try
81 : {
82 : Reference< XDatabaseContext > xRegistrations(
83 : DatabaseContext::create(
84 0 : comphelper::getProcessComponentContext()));
85 :
86 0 : const DatabaseRegistrations& rNewRegistrations = pRegistrations->getRegistrations();
87 0 : for ( DatabaseRegistrations::const_iterator reg = rNewRegistrations.begin();
88 0 : reg != rNewRegistrations.end();
89 : ++reg
90 : )
91 : {
92 0 : const OUString sName = reg->first;
93 0 : const OUString sLocation = reg->second.sLocation;
94 :
95 0 : if ( xRegistrations->hasRegisteredDatabase( sName ) )
96 : {
97 0 : if ( !xRegistrations->isDatabaseRegistrationReadOnly( sName ) )
98 0 : xRegistrations->changeDatabaseLocation( sName, sLocation );
99 : else
100 : {
101 : OSL_ENSURE( xRegistrations->getDatabaseLocation( sName ) == sLocation,
102 : "DbRegisteredNamesConfig::SetOptions: somebody changed a read-only registration. How unrespectful." );
103 : }
104 : }
105 : else
106 0 : xRegistrations->registerDatabaseLocation( sName, sLocation );
107 0 : }
108 :
109 : // delete unused entries
110 0 : Sequence< OUString > aRegistrationNames = xRegistrations->getRegistrationNames();
111 0 : const OUString* pRegistrationName = aRegistrationNames.getConstArray();
112 0 : const OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength();
113 0 : for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName )
114 : {
115 0 : if ( rNewRegistrations.find( *pRegistrationName ) == rNewRegistrations.end() )
116 0 : xRegistrations->revokeDatabaseLocation( *pRegistrationName );
117 0 : }
118 : }
119 0 : catch( const Exception& )
120 : {
121 : //DBG_UNHANDLED_EXCEPTION();
122 : }
123 : }
124 :
125 :
126 0 : }
127 :
128 :
129 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|