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

Generated by: LCOV version 1.10