LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - DbAdminImpl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 3 489 0.6 %
Date: 2015-06-13 12:38:46 Functions: 1 34 2.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11