LCOV - code coverage report
Current view: top level - libreoffice/svx/source/fmcomp - dbaexchange.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 325 0.0 %
Date: 2012-12-27 Functions: 0 28 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             : #include <svx/dbaexchange.hxx>
      21             : #include <osl/diagnose.h>
      22             : #include <com/sun/star/sdb/CommandType.hpp>
      23             : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      24             : #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
      25             : #include "fmprop.hrc"
      26             : #include <comphelper/extract.hxx>
      27             : #include <sot/formats.hxx>
      28             : #include <sot/exchange.hxx>
      29             : #include <comphelper/propertysetinfo.hxx>
      30             : 
      31             : //........................................................................
      32             : namespace svx
      33             : {
      34             : //........................................................................
      35             : 
      36             :     using namespace ::com::sun::star::uno;
      37             :     using namespace ::com::sun::star::beans;
      38             :     using namespace ::com::sun::star::sdb;
      39             :     using namespace ::com::sun::star::sdbc;
      40             :     using namespace ::com::sun::star::lang;
      41             :     using namespace ::com::sun::star::sdbcx;
      42             :     using namespace ::com::sun::star::container;
      43             :     using namespace ::com::sun::star::datatransfer;
      44             :     using namespace ::comphelper;
      45             : 
      46             :     //====================================================================
      47             :     //= OColumnTransferable
      48             :     //====================================================================
      49             :     //--------------------------------------------------------------------
      50           0 :     OColumnTransferable::OColumnTransferable(const ::rtl::OUString& _rDatasource
      51             :                                             ,const ::rtl::OUString& _rConnectionResource
      52             :                                             ,const sal_Int32        _nCommandType
      53             :                                             ,const ::rtl::OUString& _rCommand
      54             :                                             ,const ::rtl::OUString& _rFieldName
      55             :                                             ,sal_Int32  _nFormats)
      56           0 :         :m_nFormatFlags(_nFormats)
      57             :     {
      58           0 :         implConstruct(_rDatasource,_rConnectionResource,_nCommandType, _rCommand, _rFieldName);
      59           0 :     }
      60             : 
      61             :     //--------------------------------------------------------------------
      62           0 :     OColumnTransferable::OColumnTransferable(const ODataAccessDescriptor& _rDescriptor, sal_Int32 _nFormats )
      63           0 :         :m_nFormatFlags(_nFormats)
      64             :     {
      65           0 :         ::rtl::OUString sDataSource, sDatabaseLocation, sConnectionResource, sCommand, sFieldName;
      66           0 :         if ( _rDescriptor.has( daDataSource ) )         _rDescriptor[ daDataSource ] >>= sDataSource;
      67           0 :         if ( _rDescriptor.has( daDatabaseLocation ) )   _rDescriptor[ daDatabaseLocation ] >>= sDatabaseLocation;
      68           0 :         if ( _rDescriptor.has( daConnectionResource ) ) _rDescriptor[ daConnectionResource ] >>= sConnectionResource;
      69           0 :         if ( _rDescriptor.has( daCommand ) )            _rDescriptor[ daCommand ] >>= sCommand;
      70           0 :         if ( _rDescriptor.has( daColumnName ) )         _rDescriptor[ daColumnName ] >>= sFieldName;
      71             : 
      72           0 :         sal_Int32 nCommandType = CommandType::TABLE;
      73           0 :         OSL_VERIFY( _rDescriptor[ daCommandType ] >>= nCommandType );
      74             : 
      75             : 
      76             :         implConstruct(
      77           0 :             sDataSource.isEmpty() ? sDatabaseLocation : sDataSource,
      78           0 :             sConnectionResource, nCommandType, sCommand, sFieldName );
      79             : 
      80           0 :         if ( m_nFormatFlags & CTF_COLUMN_DESCRIPTOR )
      81             :         {
      82           0 :             if ( _rDescriptor.has( daConnection ) )
      83           0 :                 m_aDescriptor[ daConnection ] = _rDescriptor[ daConnection ];
      84           0 :             if ( _rDescriptor.has( daColumnObject ) )
      85           0 :                 m_aDescriptor[ daColumnObject ] = _rDescriptor[ daColumnObject ];
      86           0 :         }
      87           0 :     }
      88             : 
      89             :     //--------------------------------------------------------------------
      90           0 :     OColumnTransferable::OColumnTransferable(const Reference< XPropertySet >& _rxForm,
      91             :             const ::rtl::OUString& _rFieldName, const Reference< XPropertySet >& _rxColumn,
      92             :             const Reference< XConnection >& _rxConnection, sal_Int32 _nFormats)
      93           0 :         :m_nFormatFlags(_nFormats)
      94             :     {
      95             :         OSL_ENSURE(_rxForm.is(), "OColumnTransferable::OColumnTransferable: invalid form!");
      96             :         // collect the necessary information from the form
      97           0 :         ::rtl::OUString sCommand;
      98           0 :         sal_Int32       nCommandType = CommandType::TABLE;
      99           0 :         ::rtl::OUString sDatasource,sURL;
     100             : 
     101           0 :         sal_Bool        bTryToParse = sal_True;
     102             :         try
     103             :         {
     104           0 :             _rxForm->getPropertyValue(FM_PROP_COMMANDTYPE)  >>= nCommandType;
     105           0 :             _rxForm->getPropertyValue(FM_PROP_COMMAND)      >>= sCommand;
     106           0 :             _rxForm->getPropertyValue(FM_PROP_DATASOURCE)   >>= sDatasource;
     107           0 :             _rxForm->getPropertyValue(FM_PROP_URL)          >>= sURL;
     108           0 :             bTryToParse = ::cppu::any2bool(_rxForm->getPropertyValue(FM_PROP_ESCAPE_PROCESSING));
     109             :         }
     110           0 :         catch(Exception&)
     111             :         {
     112             :             OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
     113             :         }
     114             : 
     115             :         // If the data source is an SQL-statement and simple enough (means "select <field list> from <table> where ....")
     116             :         // we are able to fake the drag information we are about to create.
     117           0 :         if (bTryToParse && (CommandType::COMMAND == nCommandType))
     118             :         {
     119             :             try
     120             :             {
     121           0 :                 Reference< XTablesSupplier > xSupTab;
     122           0 :                 _rxForm->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupTab;
     123             : 
     124           0 :                 if(xSupTab.is())
     125             :                 {
     126           0 :                     Reference< XNameAccess > xNames = xSupTab->getTables();
     127           0 :                     if (xNames.is())
     128             :                     {
     129           0 :                         Sequence< ::rtl::OUString > aTables = xNames->getElementNames();
     130           0 :                         if (1 == aTables.getLength())
     131             :                         {
     132           0 :                             sCommand        = aTables[0];
     133           0 :                             nCommandType    = CommandType::TABLE;
     134           0 :                         }
     135           0 :                     }
     136           0 :                 }
     137             :             }
     138           0 :             catch(Exception&)
     139             :             {
     140             :                 OSL_FAIL("OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
     141             :             }
     142             :         }
     143             : 
     144           0 :         implConstruct(sDatasource, sURL,nCommandType, sCommand, _rFieldName);
     145             : 
     146           0 :         if ((m_nFormatFlags & CTF_COLUMN_DESCRIPTOR) == CTF_COLUMN_DESCRIPTOR)
     147             :         {
     148           0 :             if (_rxColumn.is())
     149           0 :                 m_aDescriptor[daColumnObject] <<= _rxColumn;
     150           0 :             if (_rxConnection.is())
     151           0 :                 m_aDescriptor[daConnection] <<= _rxConnection;
     152           0 :         }
     153           0 :     }
     154             : 
     155             :     //--------------------------------------------------------------------
     156           0 :     sal_uInt32 OColumnTransferable::getDescriptorFormatId()
     157             :     {
     158             :         static sal_uInt32 s_nFormat = (sal_uInt32)-1;
     159           0 :         if ((sal_uInt32)-1 == s_nFormat)
     160             :         {
     161           0 :             s_nFormat = SotExchange::RegisterFormatName(rtl::OUString("application/x-openoffice;windows_formatname=\"dbaccess.ColumnDescriptorTransfer\""));
     162             :             OSL_ENSURE((sal_uInt32)-1 != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
     163             :         }
     164           0 :         return s_nFormat;
     165             :     }
     166             : 
     167             :     //--------------------------------------------------------------------
     168           0 :     void OColumnTransferable::implConstruct( const ::rtl::OUString& _rDatasource
     169             :                                             ,const ::rtl::OUString& _rConnectionResource
     170             :                                             ,const sal_Int32 _nCommandType
     171             :                                             ,const ::rtl::OUString& _rCommand
     172             :                                             , const ::rtl::OUString& _rFieldName)
     173             :     {
     174           0 :         const sal_Unicode       cSeparator = sal_Unicode(11);
     175           0 :         const ::rtl::OUString   sSeparator(&cSeparator, 1);
     176             : 
     177           0 :         m_sCompatibleFormat = ::rtl::OUString();
     178           0 :         m_sCompatibleFormat += _rDatasource;
     179           0 :         m_sCompatibleFormat += sSeparator;
     180           0 :         m_sCompatibleFormat += _rCommand;
     181           0 :         m_sCompatibleFormat += sSeparator;
     182             : 
     183             :         sal_Unicode cCommandType;
     184           0 :         switch (_nCommandType)
     185             :         {
     186             :             case CommandType::TABLE:
     187           0 :                 cCommandType = '0';
     188           0 :                 break;
     189             :             case CommandType::QUERY:
     190           0 :                 cCommandType = '1';
     191           0 :                 break;
     192             :             default:
     193           0 :                 cCommandType = '2';
     194           0 :                 break;
     195             :         }
     196           0 :         m_sCompatibleFormat += ::rtl::OUString(&cCommandType, 1);
     197           0 :         m_sCompatibleFormat += sSeparator;
     198           0 :         m_sCompatibleFormat += _rFieldName;
     199             : 
     200           0 :         m_aDescriptor.clear();
     201           0 :         if ((m_nFormatFlags & CTF_COLUMN_DESCRIPTOR) == CTF_COLUMN_DESCRIPTOR)
     202             :         {
     203           0 :             m_aDescriptor.setDataSource(_rDatasource);
     204           0 :             if ( !_rConnectionResource.isEmpty() )
     205           0 :                 m_aDescriptor[daConnectionResource] <<= _rConnectionResource;
     206             : 
     207           0 :             m_aDescriptor[daCommand]        <<= _rCommand;
     208           0 :             m_aDescriptor[daCommandType]    <<= _nCommandType;
     209           0 :             m_aDescriptor[daColumnName]     <<= _rFieldName;
     210           0 :         }
     211           0 :     }
     212             : 
     213             :     //--------------------------------------------------------------------
     214           0 :     void OColumnTransferable::AddSupportedFormats()
     215             :     {
     216           0 :         if (CTF_CONTROL_EXCHANGE & m_nFormatFlags)
     217           0 :             AddFormat(SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE);
     218             : 
     219           0 :         if (CTF_FIELD_DESCRIPTOR & m_nFormatFlags)
     220           0 :             AddFormat(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE);
     221             : 
     222           0 :         if (CTF_COLUMN_DESCRIPTOR & m_nFormatFlags)
     223           0 :             AddFormat(getDescriptorFormatId());
     224           0 :     }
     225             : 
     226             :     //--------------------------------------------------------------------
     227           0 :     sal_Bool OColumnTransferable::GetData( const DataFlavor& _rFlavor )
     228             :     {
     229           0 :         const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
     230           0 :         switch (nFormatId)
     231             :         {
     232             :             case SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE:
     233             :             case SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE:
     234           0 :                 return SetString(m_sCompatibleFormat, _rFlavor);
     235             :         }
     236           0 :         if (nFormatId == getDescriptorFormatId())
     237           0 :             return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor );
     238             : 
     239           0 :         return sal_False;
     240             :     }
     241             : 
     242             :     //--------------------------------------------------------------------
     243           0 :     sal_Bool OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector& _rFlavors, sal_Int32 _nFormats)
     244             :     {
     245           0 :         sal_Bool bFieldFormat       = 0 != (_nFormats & CTF_FIELD_DESCRIPTOR);
     246           0 :         sal_Bool bControlFormat     = 0 != (_nFormats & CTF_CONTROL_EXCHANGE);
     247           0 :         sal_Bool bDescriptorFormat  = 0 != (_nFormats & CTF_COLUMN_DESCRIPTOR);
     248           0 :         for (   DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
     249           0 :                 aCheck != _rFlavors.end();
     250             :                 ++aCheck
     251             :             )
     252             :         {
     253           0 :             if (bFieldFormat && (SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE == aCheck->mnSotId))
     254           0 :                 return sal_True;
     255           0 :             if (bControlFormat && (SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == aCheck->mnSotId))
     256           0 :                 return sal_True;
     257           0 :             if (bDescriptorFormat && (getDescriptorFormatId() == aCheck->mnSotId))
     258           0 :                 return sal_True;
     259             :         }
     260             : 
     261           0 :         return sal_False;
     262             :     }
     263             : 
     264             :     //--------------------------------------------------------------------
     265           0 :     ODataAccessDescriptor OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData)
     266             :     {
     267           0 :         if (_rData.HasFormat(getDescriptorFormatId()))
     268             :         {
     269             :             // the object has a real descriptor object (not just the old compatible format)
     270             : 
     271             :             // extract the any from the transferable
     272           0 :             DataFlavor aFlavor;
     273             : #if OSL_DEBUG_LEVEL > 0
     274             :             sal_Bool bSuccess =
     275             : #endif
     276           0 :             SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor);
     277             :             OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
     278             : 
     279           0 :             Any aDescriptor = _rData.GetAny(aFlavor);
     280             : 
     281             :             // extract the property value sequence
     282           0 :             Sequence< PropertyValue > aDescriptorProps;
     283             : #if OSL_DEBUG_LEVEL > 0
     284             :             bSuccess =
     285             : #endif
     286           0 :             aDescriptor >>= aDescriptorProps;
     287             :             OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
     288             : 
     289             :             // build the real descriptor
     290           0 :             return ODataAccessDescriptor(aDescriptorProps);
     291             :         }
     292             : 
     293             :         // only the old (compatible) format exists -> use the other extract method ...
     294           0 :         ::rtl::OUString sDatasource, sCommand, sFieldName,sDatabaseLocation,sConnectionResource;
     295           0 :         sal_Int32 nCommandType = CommandType::COMMAND;
     296             : 
     297           0 :         ODataAccessDescriptor aDescriptor;
     298           0 :         if (extractColumnDescriptor(_rData, sDatasource, sDatabaseLocation,sConnectionResource,nCommandType, sCommand, sFieldName))
     299             :         {
     300             :             // and build an own descriptor
     301           0 :             if ( !sDatasource.isEmpty() )
     302           0 :                 aDescriptor[daDataSource]   <<= sDatasource;
     303           0 :             if ( !sDatabaseLocation.isEmpty() )
     304           0 :                 aDescriptor[daDatabaseLocation] <<= sDatabaseLocation;
     305           0 :             if ( !sConnectionResource.isEmpty() )
     306           0 :                 aDescriptor[daConnectionResource]   <<= sConnectionResource;
     307             : 
     308           0 :             aDescriptor[daCommand]      <<= sCommand;
     309           0 :             aDescriptor[daCommandType]  <<= nCommandType;
     310           0 :             aDescriptor[daColumnName]   <<= sFieldName;
     311             :         }
     312           0 :         return aDescriptor;
     313             :     }
     314             : 
     315             :     //--------------------------------------------------------------------
     316           0 :     sal_Bool OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData
     317             :                                             ,::rtl::OUString& _rDatasource
     318             :                                             ,::rtl::OUString& _rDatabaseLocation
     319             :                                             ,::rtl::OUString& _rConnectionResource
     320             :                                             ,sal_Int32& _nCommandType
     321             :                                             ,::rtl::OUString& _rCommand
     322             :                                             ,::rtl::OUString& _rFieldName)
     323             :     {
     324           0 :         if ( _rData.HasFormat(getDescriptorFormatId()) )
     325             :         {
     326           0 :             ODataAccessDescriptor aDescriptor = extractColumnDescriptor(_rData);
     327           0 :             if ( aDescriptor.has(daDataSource) )
     328           0 :                 aDescriptor[daDataSource]           >>= _rDatasource;
     329           0 :             if ( aDescriptor.has(daDatabaseLocation) )
     330           0 :                 aDescriptor[daDatabaseLocation]     >>= _rDatabaseLocation;
     331           0 :             if ( aDescriptor.has(daConnectionResource) )
     332           0 :                 aDescriptor[daConnectionResource]   >>= _rConnectionResource;
     333             : 
     334           0 :             aDescriptor[daCommand]              >>= _rCommand;
     335           0 :             aDescriptor[daCommandType]          >>= _nCommandType;
     336           0 :             aDescriptor[daColumnName]           >>= _rFieldName;
     337           0 :             return sal_True;
     338             :         }
     339             : 
     340             :         // check if we have a (string) format we can use ....
     341           0 :         SotFormatStringId   nRecognizedFormat = 0;
     342           0 :         if (_rData.HasFormat(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE))
     343           0 :             nRecognizedFormat = SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE;
     344           0 :         if (_rData.HasFormat(SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE))
     345           0 :             nRecognizedFormat = SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE;
     346           0 :         if (!nRecognizedFormat)
     347           0 :             return sal_False;
     348             : 
     349           0 :         String sFieldDescription;
     350           0 :         const_cast<TransferableDataHelper&>(_rData).GetString(nRecognizedFormat, sFieldDescription);
     351             : 
     352           0 :         const sal_Unicode cSeparator = sal_Unicode(11);
     353           0 :         _rDatasource    = sFieldDescription.GetToken(0, cSeparator);
     354           0 :         _rCommand       = sFieldDescription.GetToken(1, cSeparator);
     355           0 :         _nCommandType   = sFieldDescription.GetToken(2, cSeparator).ToInt32();
     356           0 :         _rFieldName     = sFieldDescription.GetToken(3, cSeparator);
     357             : 
     358           0 :         return sal_True;
     359             :     }
     360             : 
     361             :     //--------------------------------------------------------------------
     362           0 :     void OColumnTransferable::addDataToContainer( TransferDataContainer* _pContainer )
     363             :     {
     364             :         OSL_ENSURE( _pContainer, "OColumnTransferable::addDataToContainer: invalid container!" );
     365           0 :         if ( _pContainer )
     366             :         {
     367           0 :             if ( m_nFormatFlags & CTF_FIELD_DESCRIPTOR )
     368           0 :                 _pContainer->CopyAny( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE, makeAny( m_sCompatibleFormat ) );
     369             : 
     370           0 :             if ( m_nFormatFlags & CTF_CONTROL_EXCHANGE )
     371           0 :                 _pContainer->CopyAny( SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE, makeAny( m_sCompatibleFormat ) );
     372             : 
     373           0 :             if ( m_nFormatFlags & CTF_COLUMN_DESCRIPTOR )
     374             :             {
     375           0 :                 Any aContent = makeAny( m_aDescriptor.createPropertyValueSequence() );
     376             :                 _pContainer->CopyAny(
     377           0 :                     sal::static_int_cast< sal_uInt16 >( getDescriptorFormatId() ),
     378           0 :                     aContent );
     379             :             }
     380             :         }
     381           0 :     }
     382             : 
     383             :     //====================================================================
     384             :     //= ODataAccessObjectTransferable
     385             :     //====================================================================
     386           0 :     ODataAccessObjectTransferable::ODataAccessObjectTransferable(
     387             :             const ::rtl::OUString&  _rDatasource
     388             :             ,const ::rtl::OUString& _rConnectionResource
     389             :             ,const sal_Int32        _nCommandType
     390             :             ,const ::rtl::OUString& _rCommand
     391           0 :         )
     392             :     {
     393           0 :         construct(_rDatasource,_rConnectionResource,_nCommandType,_rCommand,NULL,(CommandType::COMMAND == _nCommandType),_rCommand);
     394           0 :     }
     395             :     //--------------------------------------------------------------------
     396           0 :     ODataAccessObjectTransferable::ODataAccessObjectTransferable(
     397             :                     const ::rtl::OUString&  _rDatasource
     398             :                     ,const ::rtl::OUString& _rConnectionResource
     399             :                     ,const sal_Int32        _nCommandType
     400             :                     ,const ::rtl::OUString& _rCommand
     401           0 :                     ,const Reference< XConnection >& _rxConnection)
     402             :     {
     403             :         OSL_ENSURE(_rxConnection.is(),"Wrong ctor used.!");
     404           0 :         construct(_rDatasource,_rConnectionResource,_nCommandType,_rCommand,_rxConnection,(CommandType::COMMAND == _nCommandType),_rCommand);
     405           0 :     }
     406             : 
     407             :     // -----------------------------------------------------------------------------
     408           0 :     ODataAccessObjectTransferable::ODataAccessObjectTransferable(const Reference< XPropertySet >& _rxLivingForm)
     409             :     {
     410             :         // collect some properties of the form
     411           0 :         ::rtl::OUString sDatasourceName,sConnectionResource;
     412           0 :         sal_Int32       nObjectType = CommandType::COMMAND;
     413           0 :         ::rtl::OUString sObjectName;
     414           0 :         Reference< XConnection > xConnection;
     415             :         try
     416             :         {
     417           0 :             _rxLivingForm->getPropertyValue(FM_PROP_COMMANDTYPE) >>= nObjectType;
     418           0 :             _rxLivingForm->getPropertyValue(FM_PROP_COMMAND) >>= sObjectName;
     419           0 :             _rxLivingForm->getPropertyValue(FM_PROP_DATASOURCE) >>= sDatasourceName;
     420           0 :             _rxLivingForm->getPropertyValue(FM_PROP_URL) >>= sConnectionResource;
     421           0 :             _rxLivingForm->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xConnection;
     422             :         }
     423           0 :         catch(Exception&)
     424             :         {
     425             :             OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
     426             :             return;
     427             :         }
     428             : 
     429             :         // check if the SQL-statement is modified
     430           0 :         ::rtl::OUString sCompleteStatement;
     431             :         try
     432             :         {
     433           0 :             _rxLivingForm->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sCompleteStatement;
     434             :         }
     435           0 :         catch (const Exception&)
     436             :         {
     437             :             OSL_FAIL("ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
     438             :             return;
     439             :         }
     440             : 
     441             :         construct(  sDatasourceName
     442             :                     ,sConnectionResource
     443             :                     ,nObjectType
     444             :                     ,sObjectName,xConnection
     445             :                     ,!((CommandType::QUERY == nObjectType))
     446           0 :                     ,sCompleteStatement);
     447             :     }
     448             : 
     449             :     // -----------------------------------------------------------------------------
     450           0 :     void ODataAccessObjectTransferable::AddSupportedFormats()
     451             :     {
     452           0 :         sal_Int32 nObjectType = CommandType::COMMAND;
     453           0 :         m_aDescriptor[daCommandType] >>= nObjectType;
     454           0 :         switch (nObjectType)
     455             :         {
     456             :             case CommandType::TABLE:
     457           0 :                 AddFormat(SOT_FORMATSTR_ID_DBACCESS_TABLE);
     458           0 :                 break;
     459             :             case CommandType::QUERY:
     460           0 :                 AddFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY);
     461           0 :                 break;
     462             :             case CommandType::COMMAND:
     463           0 :                 AddFormat(SOT_FORMATSTR_ID_DBACCESS_COMMAND);
     464           0 :                 break;
     465             :         }
     466             : 
     467           0 :         sal_Int32 nDescriptorLen = m_sCompatibleObjectDescription.getLength();
     468           0 :         if (nDescriptorLen)
     469             :         {
     470           0 :             if (m_sCompatibleObjectDescription.getStr()[nDescriptorLen] == 11)
     471           0 :                 m_sCompatibleObjectDescription = m_sCompatibleObjectDescription.copy(0, nDescriptorLen - 1);
     472             : 
     473           0 :             if (nDescriptorLen)
     474           0 :                 AddFormat(SOT_FORMATSTR_ID_SBA_DATAEXCHANGE);
     475             :         }
     476           0 :     }
     477             : 
     478             :     // -----------------------------------------------------------------------------
     479           0 :     sal_Bool ODataAccessObjectTransferable::GetData( const DataFlavor& rFlavor )
     480             :     {
     481           0 :         sal_uIntPtr nFormat = SotExchange::GetFormat(rFlavor);
     482           0 :         switch (nFormat)
     483             :         {
     484             :             case SOT_FORMATSTR_ID_DBACCESS_TABLE:
     485             :             case SOT_FORMATSTR_ID_DBACCESS_QUERY:
     486             :             case SOT_FORMATSTR_ID_DBACCESS_COMMAND:
     487           0 :                 return SetAny( makeAny(m_aDescriptor.createPropertyValueSequence()), rFlavor );
     488             : 
     489             :             case SOT_FORMATSTR_ID_SBA_DATAEXCHANGE:
     490           0 :                 return SetString(m_sCompatibleObjectDescription, rFlavor);
     491             :         }
     492           0 :         return sal_False;
     493             :     }
     494             : 
     495             :     // -----------------------------------------------------------------------------
     496           0 :     sal_Bool ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector& _rFlavors)
     497             :     {
     498           0 :         for (   DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
     499           0 :                 aCheck != _rFlavors.end();
     500             :                 ++aCheck
     501             :             )
     502             :         {
     503           0 :             if (SOT_FORMATSTR_ID_DBACCESS_TABLE == aCheck->mnSotId)
     504           0 :                 return sal_True;
     505           0 :             if (SOT_FORMATSTR_ID_DBACCESS_QUERY == aCheck->mnSotId)
     506           0 :                 return sal_True;
     507           0 :             if (SOT_FORMATSTR_ID_DBACCESS_COMMAND == aCheck->mnSotId)
     508           0 :                 return sal_True;
     509             :         }
     510           0 :         return sal_False;
     511             :     }
     512             : 
     513             :     // -----------------------------------------------------------------------------
     514           0 :     ODataAccessDescriptor ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper& _rData)
     515             :     {
     516           0 :         sal_Int32 nKnownFormatId = 0;
     517           0 :         if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_TABLE ) )
     518           0 :             nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_TABLE;
     519           0 :         if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_QUERY ) )
     520           0 :             nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_QUERY;
     521           0 :         if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_COMMAND ) )
     522           0 :             nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_COMMAND;
     523             : 
     524           0 :         if (0 != nKnownFormatId)
     525             :         {
     526             :             // extract the any from the transferable
     527           0 :             DataFlavor aFlavor;
     528             : #if OSL_DEBUG_LEVEL > 0
     529             :             sal_Bool bSuccess =
     530             : #endif
     531           0 :             SotExchange::GetFormatDataFlavor(nKnownFormatId, aFlavor);
     532             :             OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
     533             : 
     534           0 :             Any aDescriptor = _rData.GetAny(aFlavor);
     535             : 
     536             :             // extract the property value sequence
     537           0 :             Sequence< PropertyValue > aDescriptorProps;
     538             : #if OSL_DEBUG_LEVEL > 0
     539             :             bSuccess =
     540             : #endif
     541           0 :             aDescriptor >>= aDescriptorProps;
     542             :             OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
     543             : 
     544             :             // build the real descriptor
     545           0 :             return ODataAccessDescriptor(aDescriptorProps);
     546             :         }
     547             : 
     548             :         OSL_FAIL( "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
     549           0 :         return ODataAccessDescriptor();
     550             :     }
     551             : 
     552             :     // -----------------------------------------------------------------------------
     553           0 :     void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence< Any >& _rSelRows )
     554             :     {
     555           0 :         const sal_Unicode       cSeparator(11);
     556           0 :         const ::rtl::OUString   sSeparator(&cSeparator, 1);
     557             : 
     558           0 :         const Any* pSelRows = _rSelRows.getConstArray();
     559           0 :         const Any* pSelRowsEnd = pSelRows + _rSelRows.getLength();
     560           0 :         for ( ; pSelRows < pSelRowsEnd; ++pSelRows )
     561             :         {
     562           0 :             sal_Int32 nSelectedRow( 0 );
     563           0 :             OSL_VERIFY( *pSelRows >>= nSelectedRow );
     564             : 
     565           0 :             m_sCompatibleObjectDescription += ::rtl::OUString::valueOf((sal_Int32)nSelectedRow);
     566           0 :             m_sCompatibleObjectDescription += sSeparator;
     567           0 :         }
     568           0 :     }
     569             : 
     570             :     // -----------------------------------------------------------------------------
     571           0 :     void ODataAccessObjectTransferable::ObjectReleased()
     572             :     {
     573           0 :         m_aDescriptor.clear();
     574           0 :     }
     575             :     // -----------------------------------------------------------------------------
     576           0 :     void ODataAccessObjectTransferable::construct(  const ::rtl::OUString&  _rDatasource
     577             :                                                     ,const ::rtl::OUString& _rConnectionResource
     578             :                                                     ,const sal_Int32        _nCommandType
     579             :                                                     ,const ::rtl::OUString& _rCommand
     580             :                                                     ,const Reference< XConnection >& _rxConnection
     581             :                                                     ,sal_Bool _bAddCommand
     582             :                                                     ,const ::rtl::OUString& _sActiveCommand)
     583             :     {
     584           0 :         m_aDescriptor.setDataSource(_rDatasource);
     585             :         // build the descriptor (the property sequence)
     586           0 :         if ( !_rConnectionResource.isEmpty() )
     587           0 :             m_aDescriptor[daConnectionResource] <<= _rConnectionResource;
     588           0 :         if ( _rxConnection.is() )
     589           0 :             m_aDescriptor[daConnection]     <<= _rxConnection;
     590           0 :         m_aDescriptor[daCommand]        <<= _rCommand;
     591           0 :         m_aDescriptor[daCommandType]    <<= _nCommandType;
     592             : 
     593             :         // extract the single values from the sequence
     594             : 
     595           0 :         ::rtl::OUString sObjectName;
     596           0 :         ::rtl::OUString sDatasourceName = _rDatasource;
     597           0 :         sObjectName = _rCommand;
     598             : 
     599             :         // for compatibility: create a string which can be used for the SOT_FORMATSTR_ID_SBA_DATAEXCHANGE format
     600             : 
     601           0 :         sal_Bool bTreatAsStatement = (CommandType::COMMAND == _nCommandType);
     602             :             // statements are - in this old and ugly format - described as queries
     603             : 
     604           0 :         const sal_Unicode       cSeparator = sal_Unicode(11);
     605           0 :         const ::rtl::OUString   sSeparator(&cSeparator, 1);
     606             : 
     607           0 :         const sal_Unicode       cTableMark = '1';
     608           0 :         const sal_Unicode       cQueryMark = '0';
     609             : 
     610             :         // build the descriptor string
     611           0 :         m_sCompatibleObjectDescription += sDatasourceName;
     612           0 :         m_sCompatibleObjectDescription += sSeparator;
     613           0 :         m_sCompatibleObjectDescription += bTreatAsStatement ? ::rtl::OUString() : sObjectName;
     614           0 :         m_sCompatibleObjectDescription += sSeparator;
     615           0 :         switch (_nCommandType)
     616             :         {
     617             :             case CommandType::TABLE:
     618           0 :                 m_sCompatibleObjectDescription += ::rtl::OUString(&cTableMark, 1);
     619           0 :                 break;
     620             :             case CommandType::QUERY:
     621           0 :                 m_sCompatibleObjectDescription += ::rtl::OUString(&cQueryMark, 1);
     622           0 :                 break;
     623             :             case CommandType::COMMAND:
     624           0 :                 m_sCompatibleObjectDescription += ::rtl::OUString(&cQueryMark, 1);
     625             :                 // think of it as a query
     626           0 :                 break;
     627             :         }
     628           0 :         m_sCompatibleObjectDescription += sSeparator;
     629           0 :         m_sCompatibleObjectDescription += _bAddCommand ? _sActiveCommand : ::rtl::OUString();
     630           0 :         m_sCompatibleObjectDescription += sSeparator;
     631           0 :     }
     632             : 
     633             :     //--------------------------------------------------------------------
     634           0 :     OMultiColumnTransferable::OMultiColumnTransferable(const Sequence< PropertyValue >& _aDescriptors) : m_aDescriptors(_aDescriptors)
     635             :     {
     636           0 :     }
     637             :     //--------------------------------------------------------------------
     638           0 :     sal_uInt32 OMultiColumnTransferable::getDescriptorFormatId()
     639             :     {
     640             :         static sal_uInt32 s_nFormat = (sal_uInt32)-1;
     641           0 :         if ((sal_uInt32)-1 == s_nFormat)
     642             :         {
     643           0 :             s_nFormat = SotExchange::RegisterFormatName(rtl::OUString("application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\""));
     644             :             OSL_ENSURE((sal_uInt32)-1 != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
     645             :         }
     646           0 :         return s_nFormat;
     647             :     }
     648             :     //--------------------------------------------------------------------
     649           0 :     void OMultiColumnTransferable::AddSupportedFormats()
     650             :     {
     651           0 :         AddFormat(getDescriptorFormatId());
     652           0 :     }
     653             :     //--------------------------------------------------------------------
     654           0 :     sal_Bool OMultiColumnTransferable::GetData( const DataFlavor& _rFlavor )
     655             :     {
     656           0 :         const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
     657           0 :         if (nFormatId == getDescriptorFormatId())
     658             :         {
     659           0 :             return SetAny( makeAny( m_aDescriptors ), _rFlavor );
     660             :         }
     661             : 
     662           0 :         return sal_False;
     663             :     }
     664             : 
     665             :     //--------------------------------------------------------------------
     666           0 :     sal_Bool OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector& _rFlavors)
     667             :     {
     668           0 :         DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
     669           0 :         for (   ;
     670           0 :                 aCheck != _rFlavors.end() && getDescriptorFormatId() == aCheck->mnSotId;
     671             :                 ++aCheck
     672             :             )
     673             :             ;
     674             : 
     675           0 :         return aCheck == _rFlavors.end();
     676             :     }
     677             : 
     678             :     //--------------------------------------------------------------------
     679           0 :     Sequence< PropertyValue > OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper& _rData)
     680             :     {
     681           0 :         Sequence< PropertyValue > aList;
     682           0 :         if (_rData.HasFormat(getDescriptorFormatId()))
     683             :         {
     684             :             // extract the any from the transferable
     685           0 :             DataFlavor aFlavor;
     686             : #if OSL_DEBUG_LEVEL > 0
     687             :             sal_Bool bSuccess =
     688             : #endif
     689           0 :             SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor);
     690             :             OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
     691             : 
     692           0 :             _rData.GetAny(aFlavor) >>= aList;
     693             :         } // if (_rData.HasFormat(getDescriptorFormatId()))
     694           0 :         return aList;
     695             :     }
     696             :     // -----------------------------------------------------------------------------
     697           0 :     void OMultiColumnTransferable::ObjectReleased()
     698             :     {
     699           0 :         m_aDescriptors.realloc(0);
     700           0 :     }
     701             : 
     702             : //........................................................................
     703             : }   // namespace svx
     704             : //........................................................................
     705             : 
     706             : 
     707             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10