Branch data 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 : :
21 : : #include "DbAdminImpl.hxx"
22 : : #include "dsmeta.hxx"
23 : :
24 : : #include <svl/poolitem.hxx>
25 : : #include <svl/itempool.hxx>
26 : : #include <svl/stritem.hxx>
27 : : #include <svl/intitem.hxx>
28 : : #include <svl/eitem.hxx>
29 : : #include "DriverSettings.hxx"
30 : : #include "IItemSetHelper.hxx"
31 : : #include "UITools.hxx"
32 : : #include "dbu_dlg.hrc"
33 : : #include "dbustrings.hrc"
34 : : #include "dsitems.hxx"
35 : : #include "dsnItem.hxx"
36 : : #include "moduledbu.hxx"
37 : : #include "optionalboolitem.hxx"
38 : : #include "propertysetitem.hxx"
39 : : #include "stringlistitem.hxx"
40 : : #include "OAuthenticationContinuation.hxx"
41 : :
42 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
43 : : #include <com/sun/star/frame/XStorable.hpp>
44 : : #include <com/sun/star/sdb/SQLContext.hpp>
45 : : #include <com/sun/star/sdbc/XDriver.hpp>
46 : : #include <com/sun/star/sdbc/XDriverAccess.hpp>
47 : : #include <com/sun/star/task/XInteractionHandler.hpp>
48 : : #include <com/sun/star/task/XInteractionRequest.hpp>
49 : : #include <com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp>
50 : : #include <com/sun/star/ucb/AuthenticationRequest.hpp>
51 : :
52 : : #include <comphelper/guarding.hxx>
53 : : #include <comphelper/interaction.hxx>
54 : : #include <comphelper/property.hxx>
55 : : #include <comphelper/sequence.hxx>
56 : : #include <comphelper/string.hxx>
57 : : #include <connectivity/DriversConfig.hxx>
58 : : #include <connectivity/dbexception.hxx>
59 : : #include <osl/file.hxx>
60 : : #include <tools/diagnose_ex.h>
61 : : #include <osl/diagnose.h>
62 : : #include <typelib/typedescription.hxx>
63 : : #include <vcl/svapp.hxx>
64 : : #include <vcl/msgbox.hxx>
65 : : #include <vcl/stdtext.hxx>
66 : : #include <vcl/waitobj.hxx>
67 : : #include <osl/mutex.hxx>
68 : :
69 : : #include <algorithm>
70 : : #include <functional>
71 : : #include <o3tl/compat_functional.hxx>
72 : :
73 : : //.........................................................................
74 : : namespace dbaui
75 : : {
76 : : //.........................................................................
77 : : using namespace ::dbtools;
78 : : using namespace com::sun::star::uno;
79 : : using namespace com::sun::star;
80 : : using namespace com::sun::star::ucb;
81 : : using namespace com::sun::star::task;
82 : : using namespace com::sun::star::sdbc;
83 : : using namespace com::sun::star::sdb;
84 : : using namespace com::sun::star::lang;
85 : : using namespace com::sun::star::beans;
86 : : using namespace com::sun::star::util;
87 : : using namespace com::sun::star::container;
88 : : using namespace com::sun::star::frame;
89 : :
90 : : //-------------------------------------------------------------------------
91 : : namespace
92 : : {
93 : 0 : sal_Bool implCheckItemType( SfxItemSet& _rSet, const sal_uInt16 _nId, const TypeId _nExpectedItemType )
94 : : {
95 : 0 : sal_Bool bCorrectType = sal_False;
96 : :
97 : 0 : SfxItemPool* pPool = _rSet.GetPool();
98 : : OSL_ENSURE( pPool, "implCheckItemType: invalid item pool!" );
99 [ # # ]: 0 : if ( pPool )
100 : : {
101 : 0 : const SfxPoolItem& rDefItem = pPool->GetDefaultItem( _nId );
102 : 0 : bCorrectType = rDefItem.IsA( _nExpectedItemType );
103 : : }
104 : 0 : return bCorrectType;
105 : : }
106 : :
107 : 0 : void lcl_putProperty(const Reference< XPropertySet >& _rxSet, const ::rtl::OUString& _rName, const Any& _rValue)
108 : : {
109 : : try
110 : : {
111 [ # # ]: 0 : if ( _rxSet.is() )
112 [ # # ][ # # ]: 0 : _rxSet->setPropertyValue(_rName, _rValue);
113 : : }
114 : 0 : catch(Exception&)
115 : : {
116 : : #if OSL_DEBUG_LEVEL > 0
117 : : ::rtl::OString sMessage("ODbAdminDialog::implTranslateProperty: could not set the property ");
118 : : sMessage += ::rtl::OString(_rName.getStr(), _rName.getLength(), RTL_TEXTENCODING_ASCII_US);
119 : : sMessage += ::rtl::OString("!");
120 : : OSL_FAIL(sMessage.getStr());
121 : : #endif
122 : : }
123 : :
124 [ # # ]: 0 : }
125 : :
126 : 0 : String lcl_createHostWithPort(const SfxStringItem* _pHostName,const SfxInt32Item* _pPortNumber)
127 : : {
128 : 0 : String sNewUrl;
129 : :
130 [ # # ][ # # ]: 0 : if ( _pHostName && _pHostName->GetValue().Len() )
[ # # ]
131 [ # # ]: 0 : sNewUrl = _pHostName->GetValue();
132 : :
133 [ # # ]: 0 : if ( _pPortNumber )
134 : : {
135 [ # # ]: 0 : sNewUrl += rtl::OUString::createFromAscii(":");
136 [ # # ][ # # ]: 0 : sNewUrl += String::CreateFromInt32(_pPortNumber->GetValue());
[ # # ]
137 : : }
138 : :
139 : 0 : return sNewUrl;
140 : : }
141 : : }
142 : :
143 : : //========================================================================
144 : : //= ODbDataSourceAdministrationHelper
145 : : //========================================================================
146 : 0 : ODbDataSourceAdministrationHelper::ODbDataSourceAdministrationHelper(const Reference< XMultiServiceFactory >& _xORB,Window* _pParent,IItemSetHelper* _pItemSetHelper)
147 : : : m_xORB(_xORB)
148 : : , m_pParent(_pParent)
149 [ # # ][ # # ]: 0 : , m_pItemSetHelper(_pItemSetHelper)
150 : : {
151 : : /// initialize the property translation map
152 : : // direct properties of a data source
153 [ # # ][ # # ]: 0 : m_aDirectPropTranslator.insert(MapInt2String::value_type(DSID_CONNECTURL, PROPERTY_URL));
154 [ # # ][ # # ]: 0 : m_aDirectPropTranslator.insert(MapInt2String::value_type(DSID_NAME, PROPERTY_NAME));
155 [ # # ][ # # ]: 0 : m_aDirectPropTranslator.insert(MapInt2String::value_type(DSID_USER, PROPERTY_USER));
156 [ # # ][ # # ]: 0 : m_aDirectPropTranslator.insert(MapInt2String::value_type(DSID_PASSWORD, PROPERTY_PASSWORD));
157 [ # # ][ # # ]: 0 : m_aDirectPropTranslator.insert(MapInt2String::value_type(DSID_PASSWORDREQUIRED, PROPERTY_ISPASSWORDREQUIRED));
158 [ # # ][ # # ]: 0 : m_aDirectPropTranslator.insert(MapInt2String::value_type(DSID_TABLEFILTER, PROPERTY_TABLEFILTER));
159 [ # # ][ # # ]: 0 : m_aDirectPropTranslator.insert(MapInt2String::value_type(DSID_READONLY, PROPERTY_ISREADONLY));
160 [ # # ][ # # ]: 0 : m_aDirectPropTranslator.insert(MapInt2String::value_type(DSID_SUPPRESSVERSIONCL, PROPERTY_SUPPRESSVERSIONCL));
161 : :
162 : : // implicit properties, to be found in the direct property "Info"
163 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_JDBCDRIVERCLASS, INFO_JDBCDRIVERCLASS));
164 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_TEXTFILEEXTENSION, INFO_TEXTFILEEXTENSION));
165 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_CHARSET, INFO_CHARSET));
166 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_TEXTFILEHEADER, INFO_TEXTFILEHEADER));
167 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_FIELDDELIMITER, INFO_FIELDDELIMITER));
168 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_TEXTDELIMITER, INFO_TEXTDELIMITER));
169 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_DECIMALDELIMITER, INFO_DECIMALDELIMITER));
170 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_THOUSANDSDELIMITER, INFO_THOUSANDSDELIMITER));
171 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_SHOWDELETEDROWS, INFO_SHOWDELETEDROWS));
172 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_ALLOWLONGTABLENAMES, INFO_ALLOWLONGTABLENAMES));
173 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_ADDITIONALOPTIONS, INFO_ADDITIONALOPTIONS));
174 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_SQL92CHECK, PROPERTY_ENABLESQL92CHECK));
175 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_AUTOINCREMENTVALUE, PROPERTY_AUTOINCREMENTCREATION));
176 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_AUTORETRIEVEVALUE, INFO_AUTORETRIEVEVALUE));
177 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_AUTORETRIEVEENABLED, INFO_AUTORETRIEVEENABLED));
178 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_APPEND_TABLE_ALIAS, INFO_APPEND_TABLE_ALIAS));
179 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_AS_BEFORE_CORRNAME, INFO_AS_BEFORE_CORRELATION_NAME ) );
180 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_CHECK_REQUIRED_FIELDS, INFO_FORMS_CHECK_REQUIRED_FIELDS ) );
181 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_ESCAPE_DATETIME, INFO_ESCAPE_DATETIME ) );
182 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_PRIMARY_KEY_SUPPORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrimaryKeySupport" ) ) ) );
183 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_PARAMETERNAMESUBST, INFO_PARAMETERNAMESUBST));
184 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_IGNOREDRIVER_PRIV, INFO_IGNOREDRIVER_PRIV));
185 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_BOOLEANCOMPARISON, PROPERTY_BOOLEANCOMPARISONMODE));
186 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_ENABLEOUTERJOIN, PROPERTY_ENABLEOUTERJOIN));
187 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_CATALOG, PROPERTY_USECATALOGINSELECT));
188 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_SCHEMA, PROPERTY_USESCHEMAINSELECT));
189 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_INDEXAPPENDIX, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AddIndexAppendix"))));
190 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_DOSLINEENDS, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PreferDosLikeLineEnds" ) ) ) );
191 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_CONN_SOCKET, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LocalSocket" ) ) ) );
192 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_NAMED_PIPE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NamedPipe" ) ) ) );
193 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_RESPECTRESULTSETTYPE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RespectDriverResultSetType" ) ) ) );
194 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_MAX_ROW_SCAN, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxRowScan" ) ) ) );
195 : :
196 : : // extra settings for odbc
197 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_USECATALOG, INFO_USECATALOG));
198 : : // extra settings for a ldap address book
199 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_CONN_LDAP_BASEDN, INFO_CONN_LDAP_BASEDN));
200 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_CONN_LDAP_ROWCOUNT, INFO_CONN_LDAP_ROWCOUNT));
201 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_CONN_LDAP_USESSL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseSSL"))));
202 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_DOCUMENT_URL, PROPERTY_URL));
203 : :
204 : : // oracle
205 [ # # ][ # # ]: 0 : m_aIndirectPropTranslator.insert(MapInt2String::value_type(DSID_IGNORECURRENCY, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreCurrency"))));
206 : :
207 : : try
208 : : {
209 [ # # ][ # # ]: 0 : m_xDatabaseContext = Reference< XNameAccess >(m_xORB->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
[ # # ][ # # ]
[ # # ][ # # ]
210 [ # # ]: 0 : m_xDynamicContext.set(m_xDatabaseContext,UNO_QUERY);
211 : : }
212 [ # # ]: 0 : catch(Exception&)
213 : : {
214 : : }
215 : :
216 [ # # ]: 0 : if ( !m_xDatabaseContext.is() )
217 : : {
218 [ # # ][ # # ]: 0 : ShowServiceNotAvailableError(_pParent->GetParent(), String(SERVICE_SDB_DATABASECONTEXT), sal_True);
[ # # ][ # # ]
[ # # ]
219 : : }
220 : :
221 : : OSL_ENSURE(m_xDynamicContext.is(), "ODbAdminDialog::ODbAdminDialog : no XNamingService interface !");
222 : 0 : }
223 : : //-------------------------------------------------------------------------
224 : 0 : sal_Bool ODbDataSourceAdministrationHelper::getCurrentSettings(Sequence< PropertyValue >& _rDriverParam)
225 : : {
226 : : OSL_ENSURE(m_pItemSetHelper->getOutputSet(), "ODbDataSourceAdministrationHelper::getCurrentSettings : not to be called without an example set!");
227 [ # # ][ # # ]: 0 : if (!m_pItemSetHelper->getOutputSet())
228 : 0 : return sal_False;
229 : :
230 [ # # ]: 0 : ::std::vector< PropertyValue > aReturn;
231 : : // collecting this in a vector because it has a push_back, in opposite to sequences
232 : :
233 : : // user: DSID_USER -> "user"
234 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pUser, SfxStringItem, DSID_USER, sal_True);
[ # # ]
235 [ # # ][ # # ]: 0 : if (pUser && pUser->GetValue().Len())
[ # # ]
236 : : aReturn.push_back(
237 : : PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("user")), 0,
238 [ # # ][ # # ]: 0 : makeAny(::rtl::OUString(pUser->GetValue())), PropertyState_DIRECT_VALUE));
[ # # ][ # # ]
239 : :
240 : : // check if the connection type requires a password
241 [ # # ][ # # ]: 0 : if (hasAuthentication(*m_pItemSetHelper->getOutputSet()))
[ # # ]
242 : : {
243 : : // password: DSID_PASSWORD -> "password"
244 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pPassword, SfxStringItem, DSID_PASSWORD, sal_True);
[ # # ]
245 [ # # ][ # # ]: 0 : String sPassword = pPassword ? pPassword->GetValue() : String();
[ # # ]
246 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pPasswordRequired, SfxBoolItem, DSID_PASSWORDREQUIRED, sal_True);
[ # # ]
247 : : // if the set does not contain a password, but the item set says it requires one, ask the user
248 [ # # ][ # # ]: 0 : if ((!pPassword || !pPassword->GetValue().Len()) && (pPasswordRequired && pPasswordRequired->GetValue()))
[ # # ][ # # ]
[ # # ]
249 : : {
250 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pName, SfxStringItem, DSID_NAME, sal_True);
[ # # ]
251 : :
252 [ # # ][ # # ]: 0 : Reference< XModel > xModel( getDataSourceOrModel( m_xDatasource ), UNO_QUERY_THROW );
253 [ # # ][ # # ]: 0 : ::comphelper::NamedValueCollection aArgs( xModel->getArgs() );
[ # # ][ # # ]
254 [ # # ]: 0 : Reference< XInteractionHandler > xHandler( aArgs.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ) );
255 : :
256 [ # # ]: 0 : if ( !xHandler.is() )
257 : : {
258 : : // instantiate the default SDB interaction handler
259 [ # # ][ # # ]: 0 : xHandler = Reference< XInteractionHandler >( m_xORB->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY );
[ # # ][ # # ]
[ # # ]
260 [ # # ]: 0 : if ( !xHandler.is() )
261 [ # # ][ # # ]: 0 : ShowServiceNotAvailableError(m_pParent->GetParent(), String(SERVICE_TASK_INTERACTION_HANDLER), sal_True);
[ # # ][ # # ]
[ # # ]
262 : : }
263 : :
264 [ # # ][ # # ]: 0 : String sName = pName ? pName->GetValue() : String();
[ # # ]
265 [ # # ][ # # ]: 0 : String sLoginRequest(ModuleRes(STR_ENTER_CONNECTION_PASSWORD));
266 [ # # ]: 0 : ::rtl::OUString sTemp = sName;
267 [ # # ][ # # ]: 0 : sName = ::dbaui::getStrippedDatabaseName(NULL,sTemp);
[ # # ]
268 [ # # ]: 0 : if ( sName.Len() )
269 [ # # ]: 0 : sLoginRequest.SearchAndReplaceAscii("$name$", sName);
270 : : else
271 : : {
272 [ # # ][ # # ]: 0 : sLoginRequest.SearchAndReplaceAscii("\"$name$\"", String());
[ # # ]
273 [ # # ][ # # ]: 0 : sLoginRequest.SearchAndReplaceAscii("$name$", String()); // just to be sure that in other languages the string will be deleted
[ # # ]
274 : : }
275 : :
276 : : // the request
277 [ # # ]: 0 : AuthenticationRequest aRequest;
278 [ # # ]: 0 : aRequest.ServerName = sName;
279 [ # # ]: 0 : aRequest.Diagnostic = sLoginRequest;
280 : 0 : aRequest.HasRealm = aRequest.HasAccount = sal_False;
281 : : // aRequest.Realm
282 : 0 : aRequest.HasUserName = pUser != 0;
283 [ # # ][ # # ]: 0 : aRequest.UserName = pUser ? rtl::OUString(pUser->GetValue()) : ::rtl::OUString();
284 : 0 : aRequest.HasPassword = sal_True;
285 : : //aRequest.Password
286 : 0 : aRequest.HasAccount = sal_False;
287 : : // aRequest.Account
288 : :
289 [ # # ][ # # ]: 0 : comphelper::OInteractionRequest* pRequest = new comphelper::OInteractionRequest(makeAny(aRequest));
290 [ # # ][ # # ]: 0 : uno::Reference< XInteractionRequest > xRequest(pRequest);
291 : :
292 : : // build an interaction request
293 : : // two continuations (Ok and Cancel)
294 [ # # ]: 0 : ::rtl::Reference< comphelper::OInteractionAbort > pAbort = new comphelper::OInteractionAbort;
295 [ # # ]: 0 : ::rtl::Reference< dbaccess::OAuthenticationContinuation > pAuthenticate = new dbaccess::OAuthenticationContinuation;
296 : 0 : pAuthenticate->setCanChangeUserName( sal_False );
297 [ # # ]: 0 : pAuthenticate->setRememberPassword( RememberAuthentication_SESSION );
298 : :
299 : : // some knittings
300 [ # # ][ # # ]: 0 : pRequest->addContinuation(pAbort.get());
[ # # ]
301 [ # # ][ # # ]: 0 : pRequest->addContinuation(pAuthenticate.get());
[ # # ]
302 : :
303 : : // handle the request
304 : : try
305 : : {
306 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
307 : : // release the mutex when calling the handler, it may need to lock the SolarMutex
308 [ # # ][ # # ]: 0 : xHandler->handle(xRequest);
[ # # ][ # # ]
309 : : }
310 [ # # ]: 0 : catch(Exception&)
311 : : {
312 : : DBG_UNHANDLED_EXCEPTION();
313 : : }
314 [ # # ]: 0 : if (!pAuthenticate->wasSelected())
315 : 0 : return sal_False;
316 : :
317 [ # # ]: 0 : sPassword = pAuthenticate->getPassword();
318 [ # # ]: 0 : if (pAuthenticate->getRememberPassword())
319 [ # # ][ # # ]: 0 : m_pItemSetHelper->getWriteOutputSet()->Put(SfxStringItem(DSID_PASSWORD, sPassword));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
320 : : }
321 : :
322 [ # # ]: 0 : if (sPassword.Len())
323 : : aReturn.push_back(
324 : : PropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("password")), 0,
325 [ # # ][ # # ]: 0 : makeAny(::rtl::OUString(sPassword)), PropertyState_DIRECT_VALUE));
[ # # ][ # # ]
[ # # ][ # # ]
326 : : }
327 : :
328 [ # # ]: 0 : if ( !aReturn.empty() )
329 [ # # ][ # # ]: 0 : _rDriverParam = Sequence< PropertyValue >(&(*aReturn.begin()), aReturn.size());
[ # # ]
330 : :
331 : : // append all the other stuff (charset etc.)
332 [ # # ][ # # ]: 0 : fillDatasourceInfo(*m_pItemSetHelper->getOutputSet(), _rDriverParam);
333 : :
334 : 0 : return sal_True;
335 : : }
336 : : //-------------------------------------------------------------------------
337 : 0 : void ODbDataSourceAdministrationHelper::successfullyConnected()
338 : : {
339 : : OSL_ENSURE(m_pItemSetHelper->getOutputSet(), "ODbDataSourceAdministrationHelper::successfullyConnected: not to be called without an example set!");
340 [ # # ]: 0 : if (!m_pItemSetHelper->getOutputSet())
341 : 0 : return;
342 : :
343 [ # # ]: 0 : if (hasAuthentication(*m_pItemSetHelper->getOutputSet()))
344 : : {
345 : 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pPassword, SfxStringItem, DSID_PASSWORD, sal_True);
346 [ # # ][ # # ]: 0 : if (pPassword && (0 != pPassword->GetValue().Len()))
[ # # ]
347 : : {
348 [ # # ]: 0 : ::rtl::OUString sPassword = pPassword->GetValue();
349 : :
350 [ # # ]: 0 : Reference< XPropertySet > xCurrentDatasource = getCurrentDataSource();
351 [ # # ][ # # ]: 0 : lcl_putProperty(xCurrentDatasource,m_aDirectPropTranslator[DSID_PASSWORD], makeAny(sPassword));
[ # # ]
352 : : }
353 : : }
354 : : }
355 : : //-------------------------------------------------------------------------
356 : 0 : void ODbDataSourceAdministrationHelper::clearPassword()
357 : : {
358 [ # # ]: 0 : if (m_pItemSetHelper->getWriteOutputSet())
359 : 0 : m_pItemSetHelper->getWriteOutputSet()->ClearItem(DSID_PASSWORD);
360 : 0 : }
361 : : // -----------------------------------------------------------------------------
362 : 0 : ::std::pair< Reference<XConnection>,sal_Bool> ODbDataSourceAdministrationHelper::createConnection()
363 : : {
364 [ # # ]: 0 : ::std::pair< Reference<XConnection>,sal_Bool> aRet;
365 : 0 : aRet.second = sal_False;
366 [ # # ]: 0 : Sequence< PropertyValue > aConnectionParams;
367 [ # # ][ # # ]: 0 : if ( getCurrentSettings(aConnectionParams) )
368 : : {
369 : : // the current DSN
370 : : // fill the table list with this connection information
371 [ # # ]: 0 : SQLExceptionInfo aErrorInfo;
372 : : try
373 : : {
374 [ # # ]: 0 : WaitObject aWaitCursor(m_pParent);
375 [ # # ][ # # ]: 0 : aRet.first = getDriver()->connect(getConnectionURL(), aConnectionParams);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
376 [ # # ]: 0 : aRet.second = sal_True;
377 : : }
378 [ # # # # : 0 : catch (const SQLContext& e) { aErrorInfo = SQLExceptionInfo(e); }
# # # # ]
379 [ # # # # : 0 : catch (const SQLWarning& e) { aErrorInfo = SQLExceptionInfo(e); }
# # # # ]
380 [ # # # # : 0 : catch (const SQLException& e) { aErrorInfo = SQLExceptionInfo(e); }
# # # # #
# # # ]
381 : :
382 [ # # ][ # # ]: 0 : showError(aErrorInfo,m_pParent,getORB());
[ # # ]
383 : : }
384 [ # # ]: 0 : if ( aRet.first.is() )
385 [ # # ]: 0 : successfullyConnected();// notify the admindlg to save the password
386 : :
387 [ # # ]: 0 : return aRet;
388 : : }
389 : : // -----------------------------------------------------------------------------
390 : 0 : Reference< XDriver > ODbDataSourceAdministrationHelper::getDriver()
391 : : {
392 [ # # ][ # # ]: 0 : return getDriver(getConnectionURL());
393 : : }
394 : : // -----------------------------------------------------------------------------
395 : 0 : Reference< XDriver > ODbDataSourceAdministrationHelper::getDriver(const ::rtl::OUString& _sURL)
396 : : {
397 : : // get the global DriverManager
398 : 0 : Reference< XDriverAccess > xDriverManager;
399 [ # # ][ # # ]: 0 : String sCurrentActionError = String(ModuleRes(STR_COULDNOTCREATE_DRIVERMANAGER));
400 : : // in case an error occures
401 [ # # ][ # # ]: 0 : sCurrentActionError.SearchAndReplaceAscii("#servicename#", (::rtl::OUString)SERVICE_SDBC_CONNECTIONPOOL);
[ # # ][ # # ]
402 : : try
403 : : {
404 [ # # ][ # # ]: 0 : xDriverManager = Reference< XDriverAccess >(getORB()->createInstance(SERVICE_SDBC_CONNECTIONPOOL), UNO_QUERY);
[ # # ][ # # ]
[ # # ][ # # ]
405 : : OSL_ENSURE(xDriverManager.is(), "ODbDataSourceAdministrationHelper::getDriver: could not instantiate the driver manager, or it does not provide the necessary interface!");
406 : : }
407 [ # # ]: 0 : catch (const Exception& e)
408 : : {
409 : : // wrap the exception into an SQLException
410 [ # # # # : 0 : SQLException aSQLWrapper(e.Message, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
# # ]
411 [ # # # # : 0 : throw SQLException(sCurrentActionError, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, makeAny(aSQLWrapper));
# # # # #
# ]
412 : : }
413 [ # # ]: 0 : if (!xDriverManager.is())
414 [ # # ][ # # ]: 0 : throw SQLException(sCurrentActionError, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
[ # # ][ # # ]
415 : :
416 : :
417 [ # # ][ # # ]: 0 : Reference< XDriver > xDriver = xDriverManager->getDriverByURL(_sURL);
418 [ # # ]: 0 : if (!xDriver.is())
419 : : {
420 [ # # ][ # # ]: 0 : sCurrentActionError = String(ModuleRes(STR_NOREGISTEREDDRIVER));
[ # # ][ # # ]
421 [ # # ][ # # ]: 0 : sCurrentActionError.SearchAndReplaceAscii("#connurl#", _sURL);
[ # # ]
422 : : // will be caught and translated into an SQLContext exception
423 [ # # ][ # # ]: 0 : throw SQLException(sCurrentActionError, getORB(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")), 0, Any());
[ # # ][ # # ]
424 : : }
425 [ # # ]: 0 : return xDriver;
426 : : }
427 : :
428 : : // -----------------------------------------------------------------------------
429 : 0 : Reference< XPropertySet > ODbDataSourceAdministrationHelper::getCurrentDataSource()
430 : : {
431 [ # # ]: 0 : if ( !m_xDatasource.is() )
432 : : {
433 [ # # ]: 0 : Reference<XInterface> xIn(m_aDataSourceOrName,UNO_QUERY);
434 [ # # ]: 0 : if ( !xIn.is() )
435 : : {
436 : 0 : ::rtl::OUString sCurrentDatasource;
437 : 0 : m_aDataSourceOrName >>= sCurrentDatasource;
438 : : OSL_ENSURE(!sCurrentDatasource.isEmpty(),"No datasource name given!");
439 : : try
440 : : {
441 [ # # ]: 0 : if ( m_xDatabaseContext.is() )
442 [ # # ][ # # ]: 0 : m_xDatasource.set(m_xDatabaseContext->getByName(sCurrentDatasource),UNO_QUERY);
[ # # ][ # # ]
443 [ # # ]: 0 : xIn = m_xDatasource;
444 : : }
445 [ # # ]: 0 : catch(const Exception&)
446 : : {
447 : 0 : }
448 : : }
449 [ # # ][ # # ]: 0 : m_xModel.set(getDataSourceOrModel(xIn),UNO_QUERY);
450 [ # # ]: 0 : if ( m_xModel.is() )
451 [ # # ]: 0 : m_xDatasource.set(xIn,UNO_QUERY);
452 : : else
453 : : {
454 [ # # ][ # # ]: 0 : m_xDatasource.set(getDataSourceOrModel(xIn),UNO_QUERY);
455 [ # # ]: 0 : m_xModel.set(xIn,UNO_QUERY);
456 : 0 : }
457 : : }
458 : :
459 : :
460 : : OSL_ENSURE(m_xDatasource.is(), "ODbDataSourceAdministrationHelper::getCurrentDataSource: no data source!");
461 : 0 : return m_xDatasource;
462 : : }
463 : : //-------------------------------------------------------------------------
464 : 0 : ::rtl::OUString ODbDataSourceAdministrationHelper::getDatasourceType( const SfxItemSet& _rSet )
465 : : {
466 : 0 : SFX_ITEMSET_GET( _rSet, pConnectURL, SfxStringItem, DSID_CONNECTURL, sal_True );
467 : : OSL_ENSURE( pConnectURL , "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!" );
468 : 0 : SFX_ITEMSET_GET(_rSet, pTypeCollection, DbuTypeCollectionItem, DSID_TYPECOLLECTION, sal_True);
469 : : OSL_ENSURE(pTypeCollection, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!");
470 : 0 : ::dbaccess::ODsnTypeCollection* pCollection = pTypeCollection->getCollection();
471 [ # # ]: 0 : return pCollection->getType(pConnectURL->GetValue());
472 : : }
473 : :
474 : : //-------------------------------------------------------------------------
475 : 0 : sal_Bool ODbDataSourceAdministrationHelper::hasAuthentication(const SfxItemSet& _rSet) const
476 : : {
477 [ # # ]: 0 : return DataSourceMetaData::getAuthentication( getDatasourceType( _rSet ) ) != AuthNone;
478 : : }
479 : : // -----------------------------------------------------------------------------
480 : 0 : String ODbDataSourceAdministrationHelper::getConnectionURL() const
481 : : {
482 [ # # ]: 0 : String sNewUrl;
483 : :
484 [ # # ][ # # ]: 0 : ::rtl::OUString eType = getDatasourceType(*m_pItemSetHelper->getOutputSet());
485 : :
486 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True);
[ # # ]
487 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pTypeCollection, DbuTypeCollectionItem, DSID_TYPECOLLECTION, sal_True);
488 : :
489 : : OSL_ENSURE(pUrlItem,"Connection URL is NULL. -> GPF!");
490 : : OSL_ENSURE(pTypeCollection, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid items in the source set!");
491 : 0 : ::dbaccess::ODsnTypeCollection* pCollection = pTypeCollection->getCollection();
492 : : OSL_ENSURE(pCollection, "ODbDataSourceAdministrationHelper::getDatasourceType: invalid type collection!");
493 : :
494 [ # # ][ # # ]: 0 : switch( pCollection->determineType(eType) )
[ # # # #
# # ][ # # ]
495 : : {
496 : : case ::dbaccess::DST_DBASE:
497 : : case ::dbaccess::DST_FLAT:
498 : : case ::dbaccess::DST_CALC:
499 : 0 : break;
500 : : case ::dbaccess::DST_MSACCESS:
501 : : case ::dbaccess::DST_MSACCESS_2007:
502 : : {
503 [ # # ][ # # ]: 0 : ::rtl::OUString sFileName = pCollection->cutPrefix(pUrlItem->GetValue());
[ # # ][ # # ]
504 : 0 : ::rtl::OUString sNewFileName;
505 [ # # ][ # # ]: 0 : if ( ::osl::FileBase::getSystemPathFromFileURL( sFileName, sNewFileName ) == ::osl::FileBase::E_None )
506 : : {
507 [ # # ][ # # ]: 0 : sNewUrl += String(sNewFileName);
[ # # ]
508 : 0 : }
509 : : }
510 : 0 : break;
511 : : case ::dbaccess::DST_MYSQL_NATIVE:
512 : : case ::dbaccess::DST_MYSQL_JDBC:
513 : : {
514 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pHostName, SfxStringItem, DSID_CONN_HOSTNAME, sal_True);
[ # # ]
515 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pPortNumber, SfxInt32Item, DSID_MYSQL_PORTNUMBER, sal_True);
[ # # ]
516 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pDatabaseName, SfxStringItem, DSID_DATABASENAME, sal_True);
[ # # ]
517 [ # # ][ # # ]: 0 : sNewUrl = lcl_createHostWithPort(pHostName,pPortNumber);
[ # # ]
518 [ # # ][ # # ]: 0 : String sDatabaseName = pDatabaseName ? pDatabaseName->GetValue() : String();
[ # # ]
519 [ # # ][ # # ]: 0 : if ( !sDatabaseName.Len() && pUrlItem )
[ # # ]
520 [ # # ][ # # ]: 0 : sDatabaseName = pCollection->cutPrefix( pUrlItem->GetValue() );
[ # # ][ # # ]
521 : : // TODO: what's that? Why is the database name transported via the URL Item?
522 : : // Huh? Anybody there?
523 : : // OJ: It is needed when the connection properties are changed. There the URL is used for every type.
524 : :
525 [ # # ]: 0 : if ( sDatabaseName.Len() )
526 : : {
527 [ # # ]: 0 : sNewUrl += rtl::OUString::createFromAscii("/");
528 [ # # ]: 0 : sNewUrl += sDatabaseName;
529 [ # # ]: 0 : }
530 : : }
531 : 0 : break;
532 : : case ::dbaccess::DST_ORACLE_JDBC:
533 : : {
534 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pHostName, SfxStringItem, DSID_CONN_HOSTNAME, sal_True);
[ # # ]
535 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pPortNumber, SfxInt32Item, DSID_ORACLE_PORTNUMBER, sal_True);
[ # # ]
536 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pDatabaseName, SfxStringItem, DSID_DATABASENAME, sal_True);
[ # # ]
537 [ # # ][ # # ]: 0 : if ( pHostName && pHostName->GetValue().Len() )
[ # # ]
538 : : {
539 [ # # ][ # # ]: 0 : sNewUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("@"));
540 [ # # ][ # # ]: 0 : sNewUrl += lcl_createHostWithPort(pHostName,pPortNumber);
[ # # ]
541 [ # # ][ # # ]: 0 : String sDatabaseName = pDatabaseName ? pDatabaseName->GetValue() : String();
[ # # ]
542 [ # # ][ # # ]: 0 : if ( !sDatabaseName.Len() && pUrlItem )
[ # # ]
543 [ # # ][ # # ]: 0 : sDatabaseName = pCollection->cutPrefix( pUrlItem->GetValue() );
[ # # ][ # # ]
544 [ # # ]: 0 : if ( sDatabaseName.Len() )
545 : : {
546 [ # # ]: 0 : sNewUrl += rtl::OUString::createFromAscii(":");
547 [ # # ]: 0 : sNewUrl += sDatabaseName;
548 [ # # ]: 0 : }
549 : : }
550 : : else
551 : : { // here someone entered a JDBC url which looks like oracle, so we have to use the url property
552 : :
553 : : }
554 : : }
555 : 0 : break;
556 : : case ::dbaccess::DST_LDAP:
557 : : {
558 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*m_pItemSetHelper->getOutputSet(), pPortNumber, SfxInt32Item, DSID_CONN_LDAP_PORTNUMBER, sal_True);
[ # # ]
559 [ # # ][ # # ]: 0 : sNewUrl = pCollection->cutPrefix(pUrlItem->GetValue());
[ # # ][ # # ]
560 [ # # ][ # # ]: 0 : sNewUrl += lcl_createHostWithPort(NULL,pPortNumber);
[ # # ]
561 : : }
562 : 0 : break;
563 : : case ::dbaccess::DST_JDBC:
564 : : // run through
565 : : default:
566 : 0 : break;
567 : : }
568 [ # # ]: 0 : if ( sNewUrl.Len() )
569 : : {
570 [ # # ]: 0 : String sUrl = pCollection->getPrefix(eType);
571 [ # # ]: 0 : sUrl += sNewUrl;
572 [ # # ][ # # ]: 0 : sNewUrl = sUrl;
573 : : }
574 : : else
575 [ # # ]: 0 : sNewUrl = pUrlItem->GetValue();
576 : :
577 : 0 : return sNewUrl;
578 : : }
579 : : //-------------------------------------------------------------------------
580 : : struct PropertyValueLess
581 : : {
582 : 0 : bool operator() (const PropertyValue& x, const PropertyValue& y) const
583 : 0 : { return x.Name < y.Name ? true : false; } // construct prevents a MSVC6 warning
584 : : };
585 : : DECLARE_STL_SET( PropertyValue, PropertyValueLess, PropertyValueSet);
586 : :
587 : : //........................................................................
588 : 0 : void ODbDataSourceAdministrationHelper::translateProperties(const Reference< XPropertySet >& _rxSource, SfxItemSet& _rDest)
589 : : {
590 [ # # ]: 0 : Sequence< ::rtl::OUString > aTableFitler;
591 : :
592 [ # # ]: 0 : if (_rxSource.is())
593 : : {
594 [ # # ]: 0 : for ( ConstMapInt2StringIterator aDirect = m_aDirectPropTranslator.begin();
595 : 0 : aDirect != m_aDirectPropTranslator.end();
596 : : ++aDirect
597 : : )
598 : : {
599 : : // get the property value
600 : 0 : Any aValue;
601 : : try
602 : : {
603 [ # # ][ # # ]: 0 : aValue = _rxSource->getPropertyValue(aDirect->second);
604 : : }
605 [ # # ]: 0 : catch(Exception&)
606 : : {
607 : : #if OSL_DEBUG_LEVEL > 0
608 : : ::rtl::OString aMessage("ODbDataSourceAdministrationHelper::translateProperties: could not extract the property ");
609 : : aMessage += ::rtl::OString(aDirect->second.getStr(), aDirect->second.getLength(), RTL_TEXTENCODING_ASCII_US);
610 : : aMessage += ::rtl::OString("!");
611 : : OSL_FAIL(aMessage.getStr());
612 : : #endif
613 : : }
614 : : // transfer it into an item
615 [ # # ]: 0 : implTranslateProperty(_rDest, aDirect->first, aValue);
616 : 0 : }
617 : :
618 : : // get the additional informations
619 [ # # ]: 0 : Sequence< PropertyValue > aAdditionalInfo;
620 : : try
621 : : {
622 [ # # ][ # # ]: 0 : _rxSource->getPropertyValue(PROPERTY_INFO) >>= aAdditionalInfo;
[ # # ][ # # ]
[ # # ]
623 : : }
624 [ # # ]: 0 : catch(Exception&) { }
625 : :
626 : : // collect the names of the additional settings
627 : 0 : const PropertyValue* pAdditionalInfo = aAdditionalInfo.getConstArray();
628 [ # # ]: 0 : PropertyValueSet aInfos;
629 [ # # ]: 0 : for (sal_Int32 i=0; i<aAdditionalInfo.getLength(); ++i, ++pAdditionalInfo)
630 : : {
631 [ # # ]: 0 : if (0 == pAdditionalInfo->Name.compareToAscii("JDBCDRV"))
632 : : { // compatibility
633 : 0 : PropertyValue aCompatibility(*pAdditionalInfo);
634 [ # # ]: 0 : aCompatibility.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass"));
635 [ # # ]: 0 : aInfos.insert(aCompatibility);
636 : : }
637 : : else
638 [ # # ]: 0 : aInfos.insert(*pAdditionalInfo);
639 : : }
640 : :
641 : : // go through all known translations and check if we have such a setting
642 [ # # ]: 0 : if ( !aInfos.empty() )
643 : : {
644 : 0 : PropertyValue aSearchFor;
645 : 0 : ConstMapInt2StringIterator aEnd = m_aIndirectPropTranslator.end();
646 [ # # ]: 0 : for ( ConstMapInt2StringIterator aIndirect = m_aIndirectPropTranslator.begin();
647 : : aIndirect != aEnd;
648 : : ++aIndirect)
649 : : {
650 : 0 : aSearchFor.Name = aIndirect->second;
651 [ # # ]: 0 : ConstPropertyValueSetIterator aInfoPos = aInfos.find(aSearchFor);
652 [ # # ]: 0 : if (aInfos.end() != aInfoPos)
653 : : // the property is contained in the info sequence
654 : : // -> transfer it into an item
655 [ # # ]: 0 : implTranslateProperty(_rDest, aIndirect->first, aInfoPos->Value);
656 : 0 : }
657 : : }
658 : :
659 [ # # ][ # # ]: 0 : convertUrl(_rDest);
660 : : }
661 : :
662 : : try
663 : : {
664 [ # # ][ # # ]: 0 : _rDest.Put(OPropertySetItem(DSID_DATASOURCE_UNO, _rxSource));
[ # # ]
665 [ # # ][ # # ]: 0 : Reference<XStorable> xStore(getDataSourceOrModel(_rxSource),UNO_QUERY);
666 [ # # ][ # # ]: 0 : _rDest.Put(SfxBoolItem(DSID_READONLY, !xStore.is() || xStore->isReadonly() ));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
667 : : }
668 [ # # ]: 0 : catch(Exception&)
669 : : {
670 : : OSL_FAIL("IsReadOnly throws an exception!");
671 [ # # ]: 0 : }
672 [ # # ]: 0 : }
673 : :
674 : : //-------------------------------------------------------------------------
675 : 0 : void ODbDataSourceAdministrationHelper::translateProperties(const SfxItemSet& _rSource, const Reference< XPropertySet >& _rxDest)
676 : : {
677 : : OSL_ENSURE(_rxDest.is(), "ODbDataSourceAdministrationHelper::translateProperties: invalid property set!");
678 [ # # ]: 0 : if (!_rxDest.is())
679 : 0 : return;
680 : :
681 : : // the property set info
682 : 0 : Reference< XPropertySetInfo > xInfo;
683 [ # # ][ # # ]: 0 : try { xInfo = _rxDest->getPropertySetInfo(); }
[ # # ][ # # ]
684 [ # # # # ]: 0 : catch(Exception&) { }
685 : :
686 [ # # ]: 0 : const ::rtl::OUString sUrlProp(RTL_CONSTASCII_USTRINGPARAM("URL"));
687 : : // -----------------------------
688 : : // transfer the direct properties
689 [ # # ]: 0 : for ( ConstMapInt2StringIterator aDirect = m_aDirectPropTranslator.begin();
690 : 0 : aDirect != m_aDirectPropTranslator.end();
691 : : ++aDirect
692 : : )
693 : : {
694 [ # # ]: 0 : const SfxPoolItem* pCurrentItem = _rSource.GetItem((sal_uInt16)aDirect->first);
695 [ # # ]: 0 : if (pCurrentItem)
696 : : {
697 : 0 : sal_Int16 nAttributes = PropertyAttribute::READONLY;
698 [ # # ]: 0 : if (xInfo.is())
699 : : {
700 [ # # ][ # # ]: 0 : try { nAttributes = xInfo->getPropertyByName(aDirect->second).Attributes; }
701 [ # # ]: 0 : catch(Exception&) { }
702 : : }
703 [ # # ]: 0 : if ((nAttributes & PropertyAttribute::READONLY) == 0)
704 : : {
705 [ # # ]: 0 : if ( sUrlProp == aDirect->second )
706 : : {
707 [ # # ][ # # ]: 0 : Any aValue(makeAny(::rtl::OUString(getConnectionURL())));
[ # # ][ # # ]
708 : : // aValue <<= ::rtl::OUString();
709 [ # # ]: 0 : lcl_putProperty(_rxDest, aDirect->second,aValue);
710 : : }
711 : : else
712 [ # # ]: 0 : implTranslateProperty(_rxDest, aDirect->second, pCurrentItem);
713 : : }
714 : : }
715 : : }
716 : :
717 : : // -------------------------------
718 : : // now for the indirect properties
719 : :
720 [ # # ]: 0 : Sequence< PropertyValue > aInfo;
721 : : // the original properties
722 : : try
723 : : {
724 [ # # ][ # # ]: 0 : _rxDest->getPropertyValue(PROPERTY_INFO) >>= aInfo;
[ # # ][ # # ]
[ # # ]
725 : : }
726 [ # # ]: 0 : catch(Exception&) { }
727 : :
728 : : // overwrite and extend them
729 [ # # ]: 0 : fillDatasourceInfo(_rSource, aInfo);
730 : : // and propagate the (newly composed) sequence to the set
731 [ # # ][ # # ]: 0 : lcl_putProperty(_rxDest,PROPERTY_INFO, makeAny(aInfo));
[ # # ][ # # ]
732 : : }
733 : :
734 : :
735 : : //-------------------------------------------------------------------------
736 : 0 : void ODbDataSourceAdministrationHelper::fillDatasourceInfo(const SfxItemSet& _rSource, Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo)
737 : : {
738 : : // within the current "Info" sequence, replace the ones we can examine from the item set
739 : : // (we don't just fill a completely new sequence with our own items, but we preserve any properties unknown to
740 : : // us)
741 : :
742 : : // first determine which of all the items are relevant for the data source (depends on the connection url)
743 [ # # ]: 0 : ::rtl::OUString eType = getDatasourceType(_rSource);
744 [ # # ]: 0 : ::std::vector< sal_Int32> aDetailIds;
745 [ # # ][ # # ]: 0 : ODriversSettings::getSupportedIndirectSettings(eType,getORB(),aDetailIds);
746 : :
747 : : // collect the translated property values for the relevant items
748 [ # # ]: 0 : PropertyValueSet aRelevantSettings;
749 : 0 : ConstMapInt2StringIterator aTranslation;
750 : 0 : ::std::vector< sal_Int32>::iterator aDetailsEnd = aDetailIds.end();
751 [ # # ][ # # ]: 0 : for (::std::vector< sal_Int32>::iterator aIter = aDetailIds.begin();aIter != aDetailsEnd ; ++aIter)
[ # # ]
752 : : {
753 [ # # ][ # # ]: 0 : const SfxPoolItem* pCurrent = _rSource.GetItem((sal_uInt16)*aIter);
754 [ # # ][ # # ]: 0 : aTranslation = m_aIndirectPropTranslator.find(*aIter);
755 [ # # ][ # # ]: 0 : if ( pCurrent && (m_aIndirectPropTranslator.end() != aTranslation) )
[ # # ][ # # ]
756 : : {
757 [ # # ][ # # ]: 0 : if ( aTranslation->second == INFO_CHARSET )
758 : : {
759 : 0 : ::rtl::OUString sCharSet;
760 [ # # ]: 0 : implTranslateProperty(pCurrent) >>= sCharSet;
761 [ # # ]: 0 : if ( !sCharSet.isEmpty() )
762 [ # # ][ # # ]: 0 : aRelevantSettings.insert(PropertyValue(aTranslation->second, 0, makeAny(sCharSet), PropertyState_DIRECT_VALUE));
763 : : }
764 : : else
765 [ # # ][ # # ]: 0 : aRelevantSettings.insert(PropertyValue(aTranslation->second, 0, implTranslateProperty(pCurrent), PropertyState_DIRECT_VALUE));
766 : : }
767 : : }
768 : :
769 : : // settings to preserve
770 [ # # ]: 0 : MapInt2String aPreservedSettings;
771 : :
772 : : // now aRelevantSettings contains all the property values relevant for the current data source type,
773 : : // check the original sequence if it already contains any of these values (which have to be overwritten, then)
774 [ # # ]: 0 : PropertyValue* pInfo = _rInfo.getArray();
775 : 0 : PropertyValue aSearchFor;
776 : 0 : sal_Int32 nObsoleteSetting = -1;
777 : 0 : sal_Int32 nCount = _rInfo.getLength();
778 [ # # ]: 0 : for (sal_Int32 i = 0; i < nCount; ++i, ++pInfo)
779 : : {
780 : 0 : aSearchFor.Name = pInfo->Name;
781 [ # # ]: 0 : PropertyValueSetIterator aOverwrittenSetting = aRelevantSettings.find(aSearchFor);
782 [ # # ]: 0 : if (aRelevantSettings.end() != aOverwrittenSetting)
783 : : { // the setting was present in the original sequence, and it is to be overwritten -> replace it
784 [ # # ][ # # ]: 0 : if ( !::comphelper::compare(pInfo->Value,aOverwrittenSetting->Value) )
785 : 0 : *pInfo = *aOverwrittenSetting;
786 [ # # ]: 0 : aRelevantSettings.erase(aOverwrittenSetting);
787 : : }
788 [ # # ]: 0 : else if (0 == pInfo->Name.compareToAscii("JDBCDRV"))
789 : : { // this is a compatibility setting, remove it from the sequence (it's replaced by JavaDriverClass)
790 : 0 : nObsoleteSetting = i;
791 : : }
792 : : else
793 [ # # ]: 0 : aPreservedSettings[i] = pInfo->Name;
794 : : }
795 [ # # ]: 0 : if (-1 != nObsoleteSetting)
796 [ # # ]: 0 : ::comphelper::removeElementAt(_rInfo, nObsoleteSetting);
797 : :
798 [ # # ]: 0 : if ( !aPreservedSettings.empty() )
799 : : { // check if there are settings which
800 : : // * are known as indirect properties
801 : : // * but not relevant for the current data source type
802 : : // These settings have to be removed: If they're not relevant, we have no UI for changing them.
803 : :
804 : : // for this, we need a string-controlled quick access to m_aIndirectPropTranslator
805 [ # # ]: 0 : StringSet aIndirectProps;
806 : : ::std::transform(m_aIndirectPropTranslator.begin(),
807 : : m_aIndirectPropTranslator.end(),
808 : : ::std::insert_iterator<StringSet>(aIndirectProps,aIndirectProps.begin()),
809 [ # # ]: 0 : ::o3tl::select2nd<MapInt2String::value_type>());
810 : :
811 : : // now check the to-be-preserved props
812 [ # # ]: 0 : ::std::vector< sal_Int32 > aRemoveIndexes;
813 : 0 : sal_Int32 nPositionCorrector = 0;
814 : 0 : ConstMapInt2StringIterator aPreservedEnd = aPreservedSettings.end();
815 [ # # ]: 0 : for ( ConstMapInt2StringIterator aPreserved = aPreservedSettings.begin();
816 : : aPreserved != aPreservedEnd;
817 : : ++aPreserved
818 : : )
819 : : {
820 [ # # ][ # # ]: 0 : if (aIndirectProps.end() != aIndirectProps.find(aPreserved->second))
821 : : {
822 : : #if OSL_DEBUG_LEVEL > 0
823 : : const ::rtl::OUString sName = aPreserved->second;
824 : : #endif
825 [ # # ]: 0 : aRemoveIndexes.push_back(aPreserved->first - nPositionCorrector);
826 : 0 : ++nPositionCorrector;
827 : : }
828 : : }
829 : : // now finally remove all such props
830 [ # # ]: 0 : ::std::vector< sal_Int32 >::const_iterator aRemoveEnd = aRemoveIndexes.end();
831 [ # # ][ # # ]: 0 : for ( ::std::vector< sal_Int32 >::const_iterator aRemoveIndex = aRemoveIndexes.begin();
[ # # ][ # # ]
832 : : aRemoveIndex != aRemoveEnd;
833 : : ++aRemoveIndex
834 : : )
835 [ # # ][ # # ]: 0 : ::comphelper::removeElementAt(_rInfo, *aRemoveIndex);
836 : : #if OSL_DEBUG_LEVEL > 0
837 : : const PropertyValue* pWhatsLeft = _rInfo.getConstArray();
838 : : const PropertyValue* pWhatsLeftEnd = pWhatsLeft + _rInfo.getLength();
839 : : for (; pWhatsLeft != pWhatsLeftEnd; ++pWhatsLeft)
840 : : {
841 : : ::rtl::OUString sLookAtIt = pWhatsLeft->Name;
842 : : }
843 : : #endif
844 : : }
845 : :
846 [ # # ][ # # ]: 0 : ::connectivity::DriversConfig aDriverConfig(getORB());
847 [ # # ]: 0 : const ::comphelper::NamedValueCollection& aProperties = aDriverConfig.getProperties(eType);
848 [ # # ]: 0 : Sequence< Any> aTypeSettings;
849 [ # # ][ # # ]: 0 : aTypeSettings = aProperties.getOrDefault("TypeInfoSettings",aTypeSettings);
[ # # ]
850 : : // here we have a special entry for types from oracle
851 [ # # ]: 0 : if ( aTypeSettings.getLength() )
852 : : {
853 [ # # ][ # # ]: 0 : aRelevantSettings.insert(PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings")), 0, makeAny(aTypeSettings), PropertyState_DIRECT_VALUE));
[ # # ]
854 : : }
855 : :
856 : : // check which values are still left ('cause they were not present in the original sequence, but are to be set)
857 [ # # ]: 0 : if ( !aRelevantSettings.empty() )
858 : : {
859 : 0 : sal_Int32 nOldLength = _rInfo.getLength();
860 [ # # ]: 0 : _rInfo.realloc(nOldLength + aRelevantSettings.size());
861 [ # # ]: 0 : PropertyValue* pAppendValues = _rInfo.getArray() + nOldLength;
862 : 0 : ConstPropertyValueSetIterator aRelevantEnd = aRelevantSettings.end();
863 [ # # ]: 0 : for ( ConstPropertyValueSetIterator aLoop = aRelevantSettings.begin();
864 : : aLoop != aRelevantEnd;
865 : : ++aLoop, ++pAppendValues
866 : : )
867 : : {
868 [ # # ][ # # ]: 0 : if ( aLoop->Name == INFO_CHARSET )
869 : : {
870 : 0 : ::rtl::OUString sCharSet;
871 : 0 : aLoop->Value >>= sCharSet;
872 [ # # ]: 0 : if ( !sCharSet.isEmpty() )
873 : 0 : *pAppendValues = *aLoop;
874 : : }
875 : : else
876 : 0 : *pAppendValues = *aLoop;
877 : : }
878 [ # # ][ # # ]: 0 : }
879 : 0 : }
880 : : //-------------------------------------------------------------------------
881 : 0 : Any ODbDataSourceAdministrationHelper::implTranslateProperty(const SfxPoolItem* _pItem)
882 : : {
883 : : // translate the SfxPoolItem
884 : 0 : Any aValue;
885 : :
886 [ # # ][ # # ]: 0 : const SfxStringItem* pStringItem = PTR_CAST( SfxStringItem, _pItem );
[ # # ][ # # ]
887 [ # # ][ # # ]: 0 : const SfxBoolItem* pBoolItem = PTR_CAST( SfxBoolItem, _pItem );
[ # # ][ # # ]
888 [ # # ][ # # ]: 0 : const OptionalBoolItem* pOptBoolItem = PTR_CAST( OptionalBoolItem, _pItem );
[ # # ][ # # ]
889 [ # # ][ # # ]: 0 : const SfxInt32Item* pInt32Item = PTR_CAST( SfxInt32Item, _pItem );
[ # # ][ # # ]
890 [ # # ][ # # ]: 0 : const OStringListItem* pStringListItem = PTR_CAST( OStringListItem, _pItem );
[ # # ][ # # ]
891 : :
892 [ # # ]: 0 : if ( pStringItem )
893 : : {
894 [ # # ]: 0 : aValue <<= ::rtl::OUString( pStringItem->GetValue().GetBuffer() );
895 : : }
896 [ # # ]: 0 : else if ( pBoolItem )
897 : : {
898 [ # # ]: 0 : aValue <<= pBoolItem->GetValue();
899 : : }
900 [ # # ]: 0 : else if ( pOptBoolItem )
901 : : {
902 [ # # ][ # # ]: 0 : if ( !pOptBoolItem->HasValue() )
903 : 0 : aValue.clear();
904 : : else
905 [ # # ][ # # ]: 0 : aValue <<= (sal_Bool)pOptBoolItem->GetValue();
906 : : }
907 [ # # ]: 0 : else if ( pInt32Item )
908 : : {
909 [ # # ]: 0 : aValue <<= pInt32Item->GetValue();
910 : : }
911 [ # # ]: 0 : else if ( pStringListItem )
912 : : {
913 [ # # ][ # # ]: 0 : aValue <<= pStringListItem->getList();
[ # # ]
914 : : }
915 : : else
916 : : {
917 : : OSL_FAIL("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported item type!");
918 : 0 : return aValue;
919 : : }
920 : :
921 : 0 : return aValue;
922 : : }
923 : : //-------------------------------------------------------------------------
924 : 0 : void ODbDataSourceAdministrationHelper::implTranslateProperty(const Reference< XPropertySet >& _rxSet, const ::rtl::OUString& _rName, const SfxPoolItem* _pItem)
925 : : {
926 [ # # ]: 0 : Any aValue = implTranslateProperty(_pItem);
927 [ # # ]: 0 : lcl_putProperty(_rxSet, _rName,aValue);
928 : 0 : }
929 : :
930 : : #if OSL_DEBUG_LEVEL > 0
931 : : //-------------------------------------------------------------------------
932 : : ::rtl::OString ODbDataSourceAdministrationHelper::translatePropertyId( sal_Int32 _nId )
933 : : {
934 : : ::rtl::OUString aString;
935 : :
936 : : MapInt2String::const_iterator aPos = m_aDirectPropTranslator.find( _nId );
937 : : if ( m_aDirectPropTranslator.end() != aPos )
938 : : {
939 : : aString = aPos->second;
940 : : }
941 : : else
942 : : {
943 : : MapInt2String::const_iterator indirectPos = m_aIndirectPropTranslator.find( _nId );
944 : : if ( m_aIndirectPropTranslator.end() != indirectPos )
945 : : aString = indirectPos->second;
946 : : }
947 : :
948 : : ::rtl::OString aReturn( aString.getStr(), aString.getLength(), RTL_TEXTENCODING_ASCII_US );
949 : : return aReturn;
950 : : }
951 : : #endif
952 : :
953 : : //-------------------------------------------------------------------------
954 : 0 : void ODbDataSourceAdministrationHelper::implTranslateProperty( SfxItemSet& _rSet, sal_Int32 _nId, const Any& _rValue )
955 : : {
956 [ # # # # : 0 : switch ( _rValue.getValueType().getTypeClass() )
# # ]
957 : : {
958 : : case TypeClass_STRING:
959 [ # # ]: 0 : if ( implCheckItemType( _rSet, _nId, SfxStringItem::StaticType() ) )
960 : : {
961 : 0 : ::rtl::OUString sValue;
962 : 0 : _rValue >>= sValue;
963 [ # # ][ # # ]: 0 : _rSet.Put(SfxStringItem(_nId, sValue));
[ # # ][ # # ]
[ # # ]
964 : : }
965 : : else {
966 : : OSL_FAIL(
967 : : ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
968 : : += ::rtl::OString( translatePropertyId( _nId ) )
969 : : += ::rtl::OString( " should be no string)!" )
970 : : ).getStr()
971 : : );
972 : : }
973 : 0 : break;
974 : :
975 : : case TypeClass_BOOLEAN:
976 [ # # ]: 0 : if ( implCheckItemType( _rSet, _nId, SfxBoolItem::StaticType() ) )
977 : : {
978 : 0 : sal_Bool bVal = sal_False;
979 : 0 : _rValue >>= bVal;
980 [ # # ][ # # ]: 0 : _rSet.Put(SfxBoolItem(_nId, bVal));
[ # # ]
981 : : }
982 [ # # ]: 0 : else if ( implCheckItemType( _rSet, _nId, OptionalBoolItem::StaticType() ) )
983 : : {
984 [ # # ]: 0 : OptionalBoolItem aItem( _nId );
985 [ # # ]: 0 : if ( _rValue.hasValue() )
986 : : {
987 : 0 : sal_Bool bValue = sal_False;
988 : 0 : _rValue >>= bValue;
989 [ # # ]: 0 : aItem.SetValue( bValue );
990 : : }
991 : : else
992 [ # # ]: 0 : aItem.ClearValue();
993 [ # # ][ # # ]: 0 : _rSet.Put( aItem );
994 : : }
995 : : else {
996 : : OSL_FAIL(
997 : : ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
998 : : += ::rtl::OString( translatePropertyId( _nId ) )
999 : : += ::rtl::OString( " should be no boolean)!" )
1000 : : ).getStr()
1001 : : );
1002 : : }
1003 : 0 : break;
1004 : :
1005 : : case TypeClass_LONG:
1006 [ # # ]: 0 : if ( implCheckItemType( _rSet, _nId, SfxInt32Item::StaticType() ) )
1007 : : {
1008 : 0 : sal_Int32 nValue = 0;
1009 : 0 : _rValue >>= nValue;
1010 [ # # ][ # # ]: 0 : _rSet.Put( SfxInt32Item( _nId, nValue ) );
[ # # ]
1011 : : }
1012 : : else {
1013 : : OSL_FAIL(
1014 : : ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
1015 : : += ::rtl::OString( translatePropertyId( _nId ) )
1016 : : += ::rtl::OString( " should be no int)!" )
1017 : : ).getStr()
1018 : : );
1019 : : }
1020 : 0 : break;
1021 : :
1022 : : case TypeClass_SEQUENCE:
1023 [ # # ]: 0 : if ( implCheckItemType( _rSet, _nId, OStringListItem::StaticType() ) )
1024 : : {
1025 : : // determine the element type
1026 : 0 : TypeDescription aTD(_rValue.getValueType());
1027 : : typelib_IndirectTypeDescription* pSequenceTD =
1028 : 0 : reinterpret_cast< typelib_IndirectTypeDescription* >(aTD.get());
1029 : : OSL_ENSURE(pSequenceTD && pSequenceTD->pType, "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid sequence type!");
1030 : :
1031 : 0 : Type aElementType(pSequenceTD->pType);
1032 [ # # ]: 0 : switch (aElementType.getTypeClass())
1033 : : {
1034 : : case TypeClass_STRING:
1035 : : {
1036 [ # # ]: 0 : Sequence< ::rtl::OUString > aStringList;
1037 [ # # ]: 0 : _rValue >>= aStringList;
1038 [ # # ][ # # ]: 0 : _rSet.Put(OStringListItem(_nId, aStringList));
[ # # ][ # # ]
1039 : : }
1040 : 0 : break;
1041 : : default:
1042 : : OSL_FAIL("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported property value type!");
1043 : 0 : }
1044 : : }
1045 : : else {
1046 : : OSL_FAIL(
1047 : : ( ::rtl::OString( "ODbDataSourceAdministrationHelper::implTranslateProperty: invalid property value (" )
1048 : : += ::rtl::OString( translatePropertyId( _nId ) )
1049 : : += ::rtl::OString( " should be no string sequence)!" )
1050 : : ).getStr()
1051 : : );
1052 : : }
1053 : 0 : break;
1054 : :
1055 : : case TypeClass_VOID:
1056 : 0 : _rSet.ClearItem(_nId);
1057 : 0 : break;
1058 : :
1059 : : default:
1060 : : OSL_FAIL("ODbDataSourceAdministrationHelper::implTranslateProperty: unsupported property value type!");
1061 : : }
1062 : 0 : }
1063 : :
1064 : :
1065 : 0 : String ODbDataSourceAdministrationHelper::getDocumentUrl(SfxItemSet& _rDest)
1066 : : {
1067 : 0 : SFX_ITEMSET_GET(_rDest, pUrlItem, SfxStringItem, DSID_DOCUMENT_URL, sal_True);
1068 : : OSL_ENSURE(pUrlItem,"Document URL is NULL. -> GPF!");
1069 : 0 : return pUrlItem->GetValue();
1070 : : }
1071 : :
1072 : :
1073 : : // -----------------------------------------------------------------------------
1074 : 0 : void ODbDataSourceAdministrationHelper::convertUrl(SfxItemSet& _rDest)
1075 : : {
1076 [ # # ]: 0 : ::rtl::OUString eType = getDatasourceType(_rDest);
1077 : :
1078 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(_rDest, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True);
1079 [ # # ]: 0 : SFX_ITEMSET_GET(_rDest, pTypeCollection, DbuTypeCollectionItem, DSID_TYPECOLLECTION, sal_True);
1080 : :
1081 : : OSL_ENSURE(pUrlItem,"Connection URL is NULL. -> GPF!");
1082 : : OSL_ENSURE(pTypeCollection, "ODbAdminDialog::getDatasourceType: invalid items in the source set!");
1083 : 0 : ::dbaccess::ODsnTypeCollection* pCollection = pTypeCollection->getCollection();
1084 : : OSL_ENSURE(pCollection, "ODbAdminDialog::getDatasourceType: invalid type collection!");
1085 : :
1086 : 0 : sal_uInt16 nPortNumberId = 0;
1087 : 0 : sal_Int32 nPortNumber = -1;
1088 [ # # ]: 0 : String sNewHostName;
1089 [ # # ]: 0 : String sUrlPart;
1090 : :
1091 [ # # ][ # # ]: 0 : pCollection->extractHostNamePort(pUrlItem->GetValue(),sUrlPart,sNewHostName,nPortNumber);
1092 [ # # ][ # # ]: 0 : const ::dbaccess::DATASOURCE_TYPE eTy = pCollection->determineType(eType);
[ # # ]
1093 : :
1094 [ # # # # ]: 0 : switch( eTy )
1095 : : {
1096 : : case ::dbaccess::DST_MYSQL_NATIVE:
1097 : : case ::dbaccess::DST_MYSQL_JDBC:
1098 : 0 : nPortNumberId = DSID_MYSQL_PORTNUMBER;
1099 : 0 : break;
1100 : : case ::dbaccess::DST_ORACLE_JDBC:
1101 : 0 : nPortNumberId = DSID_ORACLE_PORTNUMBER;
1102 : 0 : break;
1103 : : case ::dbaccess::DST_LDAP:
1104 : 0 : nPortNumberId = DSID_CONN_LDAP_PORTNUMBER;
1105 : 0 : break;
1106 : : default:
1107 : 0 : break;
1108 : : }
1109 : :
1110 [ # # ]: 0 : if ( sUrlPart.Len() )
1111 : : {
1112 [ # # ]: 0 : if ( eTy == ::dbaccess::DST_MYSQL_NATIVE )
1113 : : {
1114 [ # # ][ # # ]: 0 : _rDest.Put( SfxStringItem( DSID_DATABASENAME, sUrlPart ) );
[ # # ]
1115 : : }
1116 : : else
1117 : : {
1118 [ # # ]: 0 : String sNewUrl = pCollection->getPrefix(eType);
1119 [ # # ]: 0 : sNewUrl += sUrlPart;
1120 [ # # ][ # # ]: 0 : _rDest.Put( SfxStringItem( DSID_CONNECTURL, sNewUrl ) );
[ # # ][ # # ]
1121 : : }
1122 : : }
1123 : :
1124 [ # # ]: 0 : if ( sNewHostName.Len() )
1125 [ # # ][ # # ]: 0 : _rDest.Put(SfxStringItem(DSID_CONN_HOSTNAME, sNewHostName));
[ # # ]
1126 : :
1127 [ # # ][ # # ]: 0 : if ( nPortNumber != -1 && nPortNumberId != 0 )
1128 [ # # ][ # # ]: 0 : _rDest.Put(SfxInt32Item(nPortNumberId, nPortNumber));
[ # # ][ # # ]
[ # # ]
1129 : :
1130 : 0 : }
1131 : : // -----------------------------------------------------------------------------
1132 : 0 : sal_Bool ODbDataSourceAdministrationHelper::saveChanges(const SfxItemSet& _rSource)
1133 : : {
1134 : : // put the remembered settings into the property set
1135 [ # # ]: 0 : Reference<XPropertySet> xDatasource = getCurrentDataSource();
1136 [ # # ]: 0 : if ( !xDatasource.is() )
1137 : 0 : return sal_False;
1138 : :
1139 [ # # ]: 0 : translateProperties(_rSource,xDatasource );
1140 : :
1141 : 0 : return sal_True;
1142 : : }
1143 : : // -----------------------------------------------------------------------------
1144 : 0 : void ODbDataSourceAdministrationHelper::setDataSourceOrName( const Any& _rDataSourceOrName )
1145 : : {
1146 : : OSL_ENSURE( !m_aDataSourceOrName.hasValue(), "ODbDataSourceAdministrationHelper::setDataSourceOrName: already have one!" );
1147 : : // hmm. We could reset m_xDatasource/m_xModel, probably, and continue working
1148 : 0 : m_aDataSourceOrName = _rDataSourceOrName;
1149 : 0 : }
1150 : : //=========================================================================
1151 : : //= DbuTypeCollectionItem
1152 : : //=========================================================================
1153 [ # # ][ # # ]: 0 : TYPEINIT1(DbuTypeCollectionItem, SfxPoolItem);
1154 : : //-------------------------------------------------------------------------
1155 : 4 : DbuTypeCollectionItem::DbuTypeCollectionItem(sal_Int16 _nWhich, ::dbaccess::ODsnTypeCollection* _pCollection)
1156 : : :SfxPoolItem(_nWhich)
1157 : 4 : ,m_pCollection(_pCollection)
1158 : : {
1159 : 4 : }
1160 : :
1161 : : //-------------------------------------------------------------------------
1162 : 0 : DbuTypeCollectionItem::DbuTypeCollectionItem(const DbuTypeCollectionItem& _rSource)
1163 : : :SfxPoolItem(_rSource)
1164 : 0 : ,m_pCollection(_rSource.getCollection())
1165 : : {
1166 : 0 : }
1167 : :
1168 : : //-------------------------------------------------------------------------
1169 : 0 : int DbuTypeCollectionItem::operator==(const SfxPoolItem& _rItem) const
1170 : : {
1171 [ # # ][ # # ]: 0 : DbuTypeCollectionItem* pCompare = PTR_CAST(DbuTypeCollectionItem, &_rItem);
1172 [ # # ][ # # ]: 0 : return pCompare && (pCompare->getCollection() == getCollection());
1173 : : }
1174 : :
1175 : : //-------------------------------------------------------------------------
1176 : 0 : SfxPoolItem* DbuTypeCollectionItem::Clone(SfxItemPool* /*_pPool*/) const
1177 : : {
1178 [ # # ]: 0 : return new DbuTypeCollectionItem(*this);
1179 : : }
1180 : :
1181 : : //.........................................................................
1182 : : } // namespace dbaui
1183 : : //.........................................................................
1184 : :
1185 : :
1186 : :
1187 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|