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