1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbaexchange.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/dbaexchange.hxx>
34 #include <osl/diagnose.h>
35 #include <com/sun/star/sdb/CommandType.hpp>
36 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
37 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
38 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
39 #ifndef _SVX_FMPROP_HRC
42 #include <comphelper/extract.hxx>
43 #include <sot/formats.hxx>
44 #include <sot/exchange.hxx>
45 #include <comphelper/propertysetinfo.hxx>
46 #ifndef _SVX_FMPROP_HRC
49 #include <tools/urlobj.hxx>
51 //........................................................................
54 //........................................................................
56 using namespace ::com::sun::star::uno
;
57 using namespace ::com::sun::star::beans
;
58 using namespace ::com::sun::star::sdb
;
59 using namespace ::com::sun::star::sdbc
;
60 using namespace ::com::sun::star::lang
;
61 using namespace ::com::sun::star::sdbcx
;
62 using namespace ::com::sun::star::container
;
63 using namespace ::com::sun::star::datatransfer
;
64 using namespace ::comphelper
;
66 //====================================================================
67 //= OColumnTransferable
68 //====================================================================
69 //--------------------------------------------------------------------
70 OColumnTransferable::OColumnTransferable(const ::rtl::OUString
& _rDatasource
71 ,const ::rtl::OUString
& _rConnectionResource
72 ,const sal_Int32 _nCommandType
73 ,const ::rtl::OUString
& _rCommand
74 ,const ::rtl::OUString
& _rFieldName
76 :m_nFormatFlags(_nFormats
)
78 implConstruct(_rDatasource
,_rConnectionResource
,_nCommandType
, _rCommand
, _rFieldName
);
81 //--------------------------------------------------------------------
82 OColumnTransferable::OColumnTransferable(const ODataAccessDescriptor
& _rDescriptor
, sal_Int32 _nFormats
)
83 :m_nFormatFlags(_nFormats
)
85 ::rtl::OUString sDataSource
, sDatabaseLocation
, sConnectionResource
, sCommand
, sFieldName
;
86 if ( _rDescriptor
.has( daDataSource
) ) _rDescriptor
[ daDataSource
] >>= sDataSource
;
87 if ( _rDescriptor
.has( daDatabaseLocation
) ) _rDescriptor
[ daDatabaseLocation
] >>= sDatabaseLocation
;
88 if ( _rDescriptor
.has( daConnectionResource
) ) _rDescriptor
[ daConnectionResource
] >>= sConnectionResource
;
89 if ( _rDescriptor
.has( daCommand
) ) _rDescriptor
[ daCommand
] >>= sCommand
;
90 if ( _rDescriptor
.has( daColumnName
) ) _rDescriptor
[ daColumnName
] >>= sFieldName
;
92 sal_Int32 nCommandType
= CommandType::TABLE
;
93 OSL_VERIFY( _rDescriptor
[ daCommandType
] >>= nCommandType
);
97 sDataSource
.getLength() ? sDataSource
: sDatabaseLocation
,
98 sConnectionResource
, nCommandType
, sCommand
, sFieldName
);
100 if ( m_nFormatFlags
& CTF_COLUMN_DESCRIPTOR
)
102 if ( _rDescriptor
.has( daConnection
) )
103 m_aDescriptor
[ daConnection
] = _rDescriptor
[ daConnection
];
104 if ( _rDescriptor
.has( daColumnObject
) )
105 m_aDescriptor
[ daColumnObject
] = _rDescriptor
[ daColumnObject
];
109 //--------------------------------------------------------------------
110 OColumnTransferable::OColumnTransferable(const Reference
< XPropertySet
>& _rxForm
,
111 const ::rtl::OUString
& _rFieldName
, const Reference
< XPropertySet
>& _rxColumn
,
112 const Reference
< XConnection
>& _rxConnection
, sal_Int32 _nFormats
)
113 :m_nFormatFlags(_nFormats
)
115 OSL_ENSURE(_rxForm
.is(), "OColumnTransferable::OColumnTransferable: invalid form!");
116 // collect the necessary information from the form
117 ::rtl::OUString sCommand
;
118 sal_Int32 nCommandType
= CommandType::TABLE
;
119 ::rtl::OUString sDatasource
,sURL
;
121 sal_Bool bTryToParse
= sal_True
;
124 _rxForm
->getPropertyValue(FM_PROP_COMMANDTYPE
) >>= nCommandType
;
125 _rxForm
->getPropertyValue(FM_PROP_COMMAND
) >>= sCommand
;
126 _rxForm
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sDatasource
;
127 _rxForm
->getPropertyValue(FM_PROP_URL
) >>= sURL
;
128 bTryToParse
= ::cppu::any2bool(_rxForm
->getPropertyValue(FM_PROP_ESCAPE_PROCESSING
));
132 OSL_ENSURE(sal_False
, "OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
135 // If the data source is an SQL-statement and simple enough (means "select <field list> from <table> where ....")
136 // we are able to fake the drag information we are about to create.
137 if (bTryToParse
&& (CommandType::COMMAND
== nCommandType
))
141 // need a query composer for this
142 Reference
< XSQLQueryComposerFactory
> xComposerFac
;
143 _rxForm
->getPropertyValue(FM_PROP_ACTIVE_CONNECTION
) >>= xComposerFac
;
144 Reference
< XSQLQueryComposer
> xComposer
;
145 if (xComposerFac
.is())
146 xComposer
= xComposerFac
->createQueryComposer();
150 ::rtl::OUString sActiveCommand
;
151 _rxForm
->getPropertyValue(FM_PROP_ACTIVECOMMAND
) >>= sActiveCommand
;
152 xComposer
->setQuery(sActiveCommand
);
153 Reference
< XTablesSupplier
> xSupTab(xComposer
, UNO_QUERY
);
156 Reference
< XNameAccess
> xNames
= xSupTab
->getTables();
159 Sequence
< ::rtl::OUString
> aTables
= xNames
->getElementNames();
160 if (1 == aTables
.getLength())
162 sCommand
= aTables
[0];
163 nCommandType
= CommandType::TABLE
;
171 OSL_ENSURE(sal_False
, "OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
175 implConstruct(sDatasource
, sURL
,nCommandType
, sCommand
, _rFieldName
);
177 if ((m_nFormatFlags
& CTF_COLUMN_DESCRIPTOR
) == CTF_COLUMN_DESCRIPTOR
)
180 m_aDescriptor
[daColumnObject
] <<= _rxColumn
;
181 if (_rxConnection
.is())
182 m_aDescriptor
[daConnection
] <<= _rxConnection
;
186 //--------------------------------------------------------------------
187 sal_uInt32
OColumnTransferable::getDescriptorFormatId()
189 static sal_uInt32 s_nFormat
= (sal_uInt32
)-1;
190 if ((sal_uInt32
)-1 == s_nFormat
)
192 s_nFormat
= SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.ColumnDescriptorTransfer\""));
193 OSL_ENSURE((sal_uInt32
)-1 != s_nFormat
, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
198 //--------------------------------------------------------------------
199 void OColumnTransferable::implConstruct( const ::rtl::OUString
& _rDatasource
200 ,const ::rtl::OUString
& _rConnectionResource
201 ,const sal_Int32 _nCommandType
202 ,const ::rtl::OUString
& _rCommand
203 , const ::rtl::OUString
& _rFieldName
)
205 const sal_Unicode cSeparator
= sal_Unicode(11);
206 const ::rtl::OUString
sSeparator(&cSeparator
, 1);
208 m_sCompatibleFormat
= ::rtl::OUString();
209 m_sCompatibleFormat
+= _rDatasource
;
210 m_sCompatibleFormat
+= sSeparator
;
211 m_sCompatibleFormat
+= _rCommand
;
212 m_sCompatibleFormat
+= sSeparator
;
214 sal_Unicode cCommandType
;
215 switch (_nCommandType
)
217 case CommandType::TABLE
:
220 case CommandType::QUERY
:
227 m_sCompatibleFormat
+= ::rtl::OUString(&cCommandType
, 1);
228 m_sCompatibleFormat
+= sSeparator
;
229 m_sCompatibleFormat
+= _rFieldName
;
231 m_aDescriptor
.clear();
232 if ((m_nFormatFlags
& CTF_COLUMN_DESCRIPTOR
) == CTF_COLUMN_DESCRIPTOR
)
234 m_aDescriptor
.setDataSource(_rDatasource
);
235 if ( _rConnectionResource
.getLength() )
236 m_aDescriptor
[daConnectionResource
] <<= _rConnectionResource
;
238 m_aDescriptor
[daCommand
] <<= _rCommand
;
239 m_aDescriptor
[daCommandType
] <<= _nCommandType
;
240 m_aDescriptor
[daColumnName
] <<= _rFieldName
;
244 //--------------------------------------------------------------------
245 void OColumnTransferable::AddSupportedFormats()
247 if (CTF_CONTROL_EXCHANGE
& m_nFormatFlags
)
248 AddFormat(SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE
);
250 if (CTF_FIELD_DESCRIPTOR
& m_nFormatFlags
)
251 AddFormat(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE
);
253 if (CTF_COLUMN_DESCRIPTOR
& m_nFormatFlags
)
254 AddFormat(getDescriptorFormatId());
257 //--------------------------------------------------------------------
258 sal_Bool
OColumnTransferable::GetData( const DataFlavor
& _rFlavor
)
260 const sal_uInt32 nFormatId
= SotExchange::GetFormat(_rFlavor
);
263 case SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE
:
264 case SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE
:
265 return SetString(m_sCompatibleFormat
, _rFlavor
);
267 if (nFormatId
== getDescriptorFormatId())
268 return SetAny( makeAny( m_aDescriptor
.createPropertyValueSequence() ), _rFlavor
);
273 //--------------------------------------------------------------------
274 sal_Bool
OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector
& _rFlavors
, sal_Int32 _nFormats
)
276 sal_Bool bFieldFormat
= 0 != (_nFormats
& CTF_FIELD_DESCRIPTOR
);
277 sal_Bool bControlFormat
= 0 != (_nFormats
& CTF_CONTROL_EXCHANGE
);
278 sal_Bool bDescriptorFormat
= 0 != (_nFormats
& CTF_COLUMN_DESCRIPTOR
);
279 for ( DataFlavorExVector::const_iterator aCheck
= _rFlavors
.begin();
280 aCheck
!= _rFlavors
.end();
284 if (bFieldFormat
&& (SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE
== aCheck
->mnSotId
))
286 if (bControlFormat
&& (SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE
== aCheck
->mnSotId
))
288 if (bDescriptorFormat
&& (getDescriptorFormatId() == aCheck
->mnSotId
))
295 //--------------------------------------------------------------------
296 ODataAccessDescriptor
OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper
& _rData
)
298 if (_rData
.HasFormat(getDescriptorFormatId()))
300 // the object has a real descriptor object (not just the old compatible format)
302 // extract the any from the transferable
304 #if OSL_DEBUG_LEVEL > 0
307 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor
);
308 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
310 Any aDescriptor
= _rData
.GetAny(aFlavor
);
312 // extract the property value sequence
313 Sequence
< PropertyValue
> aDescriptorProps
;
314 #if OSL_DEBUG_LEVEL > 0
317 aDescriptor
>>= aDescriptorProps
;
318 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
320 // build the real descriptor
321 return ODataAccessDescriptor(aDescriptorProps
);
324 // only the old (compatible) format exists -> use the other extract method ...
325 ::rtl::OUString sDatasource
, sCommand
, sFieldName
,sDatabaseLocation
,sConnectionResource
;
326 sal_Int32 nCommandType
= CommandType::COMMAND
;
328 ODataAccessDescriptor aDescriptor
;
329 if (extractColumnDescriptor(_rData
, sDatasource
, sDatabaseLocation
,sConnectionResource
,nCommandType
, sCommand
, sFieldName
))
331 // and build an own descriptor
332 if ( sDatasource
.getLength() )
333 aDescriptor
[daDataSource
] <<= sDatasource
;
334 if ( sDatabaseLocation
.getLength() )
335 aDescriptor
[daDatabaseLocation
] <<= sDatabaseLocation
;
336 if ( sConnectionResource
.getLength() )
337 aDescriptor
[daConnectionResource
] <<= sConnectionResource
;
339 aDescriptor
[daCommand
] <<= sCommand
;
340 aDescriptor
[daCommandType
] <<= nCommandType
;
341 aDescriptor
[daColumnName
] <<= sFieldName
;
346 //--------------------------------------------------------------------
347 sal_Bool
OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper
& _rData
348 ,::rtl::OUString
& _rDatasource
349 ,::rtl::OUString
& _rDatabaseLocation
350 ,::rtl::OUString
& _rConnectionResource
351 ,sal_Int32
& _nCommandType
352 ,::rtl::OUString
& _rCommand
353 ,::rtl::OUString
& _rFieldName
)
355 if ( _rData
.HasFormat(getDescriptorFormatId()) )
357 ODataAccessDescriptor aDescriptor
= extractColumnDescriptor(_rData
);
358 if ( aDescriptor
.has(daDataSource
) )
359 aDescriptor
[daDataSource
] >>= _rDatasource
;
360 if ( aDescriptor
.has(daDatabaseLocation
) )
361 aDescriptor
[daDatabaseLocation
] >>= _rDatabaseLocation
;
362 if ( aDescriptor
.has(daConnectionResource
) )
363 aDescriptor
[daConnectionResource
] >>= _rConnectionResource
;
365 aDescriptor
[daCommand
] >>= _rCommand
;
366 aDescriptor
[daCommandType
] >>= _nCommandType
;
367 aDescriptor
[daColumnName
] >>= _rFieldName
;
371 // check if we have a (string) format we can use ....
372 SotFormatStringId nRecognizedFormat
= 0;
373 if (_rData
.HasFormat(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE
))
374 nRecognizedFormat
= SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE
;
375 if (_rData
.HasFormat(SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE
))
376 nRecognizedFormat
= SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE
;
377 if (!nRecognizedFormat
)
380 String sFieldDescription
;
381 const_cast<TransferableDataHelper
&>(_rData
).GetString(nRecognizedFormat
, sFieldDescription
);
383 const sal_Unicode cSeparator
= sal_Unicode(11);
384 _rDatasource
= sFieldDescription
.GetToken(0, cSeparator
);
385 _rCommand
= sFieldDescription
.GetToken(1, cSeparator
);
386 _nCommandType
= sFieldDescription
.GetToken(2, cSeparator
).ToInt32();
387 _rFieldName
= sFieldDescription
.GetToken(3, cSeparator
);
392 //--------------------------------------------------------------------
393 void OColumnTransferable::addDataToContainer( TransferDataContainer
* _pContainer
)
395 OSL_ENSURE( _pContainer
, "OColumnTransferable::addDataToContainer: invalid container!" );
398 if ( m_nFormatFlags
& CTF_FIELD_DESCRIPTOR
)
399 _pContainer
->CopyAny( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE
, makeAny( m_sCompatibleFormat
) );
401 if ( m_nFormatFlags
& CTF_CONTROL_EXCHANGE
)
402 _pContainer
->CopyAny( SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE
, makeAny( m_sCompatibleFormat
) );
404 if ( m_nFormatFlags
& CTF_COLUMN_DESCRIPTOR
)
406 Any aContent
= makeAny( m_aDescriptor
.createPropertyValueSequence() );
407 _pContainer
->CopyAny(
408 sal::static_int_cast
< USHORT
>( getDescriptorFormatId() ),
414 //====================================================================
415 //= ODataAccessObjectTransferable
416 //====================================================================
417 ODataAccessObjectTransferable::ODataAccessObjectTransferable(
418 const ::rtl::OUString
& _rDatasource
419 ,const ::rtl::OUString
& _rConnectionResource
420 ,const sal_Int32 _nCommandType
421 ,const ::rtl::OUString
& _rCommand
424 construct(_rDatasource
,_rConnectionResource
,_nCommandType
,_rCommand
,NULL
,(CommandType::COMMAND
== _nCommandType
),_rCommand
);
426 //--------------------------------------------------------------------
427 ODataAccessObjectTransferable::ODataAccessObjectTransferable(
428 const ::rtl::OUString
& _rDatasource
429 ,const ::rtl::OUString
& _rConnectionResource
430 ,const sal_Int32 _nCommandType
431 ,const ::rtl::OUString
& _rCommand
432 ,const Reference
< XConnection
>& _rxConnection
)
434 OSL_ENSURE(_rxConnection
.is(),"Wrong ctor used.!");
435 construct(_rDatasource
,_rConnectionResource
,_nCommandType
,_rCommand
,_rxConnection
,(CommandType::COMMAND
== _nCommandType
),_rCommand
);
438 // -----------------------------------------------------------------------------
439 ODataAccessObjectTransferable::ODataAccessObjectTransferable(const Reference
< XPropertySet
>& _rxLivingForm
)
441 // collect some properties of the form
442 ::rtl::OUString sDatasourceName
,sConnectionResource
;
443 sal_Int32 nObjectType
= CommandType::COMMAND
;
444 ::rtl::OUString sObjectName
;
445 Reference
< XConnection
> xConnection
;
448 _rxLivingForm
->getPropertyValue(FM_PROP_COMMANDTYPE
) >>= nObjectType
;
449 _rxLivingForm
->getPropertyValue(FM_PROP_COMMAND
) >>= sObjectName
;
450 _rxLivingForm
->getPropertyValue(FM_PROP_DATASOURCE
) >>= sDatasourceName
;
451 _rxLivingForm
->getPropertyValue(FM_PROP_URL
) >>= sConnectionResource
;
452 _rxLivingForm
->getPropertyValue(FM_PROP_ACTIVE_CONNECTION
) >>= xConnection
;
456 OSL_ENSURE(sal_False
, "ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
460 String sObjectKind
= (CommandType::TABLE
== nObjectType
) ? String('1') : String('0');
462 // check if the SQL-statement is modified
463 sal_Bool
bHasFilterOrSort(sal_False
);
464 ::rtl::OUString sCompleteStatement
;
467 ::rtl::OUString sFilter
, sSort
;
468 if (::cppu::any2bool(_rxLivingForm
->getPropertyValue(FM_PROP_APPLYFILTER
)))
469 _rxLivingForm
->getPropertyValue(FM_PROP_FILTER
) >>= sFilter
;
470 _rxLivingForm
->getPropertyValue(FM_PROP_SORT
) >>= sSort
;
471 bHasFilterOrSort
= (sFilter
.getLength()>0) || (sSort
.getLength()>0);
473 _rxLivingForm
->getPropertyValue(FM_PROP_ACTIVECOMMAND
) >>= sCompleteStatement
;
476 Reference
< XSQLQueryComposerFactory
> xFactory( xConnection
, UNO_QUERY
);
477 Reference
< XSQLQueryComposer
> xComposer
;
479 xComposer
= xFactory
->createQueryComposer();
481 // let the composer compose
484 xComposer
->setQuery(sCompleteStatement
);
485 xComposer
->setFilter(sFilter
);
486 xComposer
->setOrder(sSort
);
487 sCompleteStatement
= xComposer
->getComposedQuery();
489 // Usually, I would expect the result of the composing to be the same as the ActiveCommand property
490 // But this code here is pretty old, and I don't know wha the side effects are if I remove it now ...
494 OSL_ENSURE(sal_False
, "ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
498 construct( sDatasourceName
501 ,sObjectName
,xConnection
502 ,!((CommandType::QUERY
== nObjectType
) && !bHasFilterOrSort
)
503 ,sCompleteStatement
);
506 // -----------------------------------------------------------------------------
507 void ODataAccessObjectTransferable::AddSupportedFormats()
509 sal_Int32 nObjectType
= CommandType::COMMAND
;
510 m_aDescriptor
[daCommandType
] >>= nObjectType
;
513 case CommandType::TABLE
:
514 AddFormat(SOT_FORMATSTR_ID_DBACCESS_TABLE
);
516 case CommandType::QUERY
:
517 AddFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY
);
519 case CommandType::COMMAND
:
520 AddFormat(SOT_FORMATSTR_ID_DBACCESS_COMMAND
);
524 sal_Int32 nDescriptorLen
= m_sCompatibleObjectDescription
.getLength();
527 if (m_sCompatibleObjectDescription
.getStr()[nDescriptorLen
] == 11)
528 m_sCompatibleObjectDescription
= m_sCompatibleObjectDescription
.copy(0, nDescriptorLen
- 1);
531 AddFormat(SOT_FORMATSTR_ID_SBA_DATAEXCHANGE
);
535 // -----------------------------------------------------------------------------
536 sal_Bool
ODataAccessObjectTransferable::GetData( const DataFlavor
& rFlavor
)
538 ULONG nFormat
= SotExchange::GetFormat(rFlavor
);
541 case SOT_FORMATSTR_ID_DBACCESS_TABLE
:
542 case SOT_FORMATSTR_ID_DBACCESS_QUERY
:
543 case SOT_FORMATSTR_ID_DBACCESS_COMMAND
:
544 return SetAny( makeAny(m_aDescriptor
.createPropertyValueSequence()), rFlavor
);
546 case SOT_FORMATSTR_ID_SBA_DATAEXCHANGE
:
547 return SetString(m_sCompatibleObjectDescription
, rFlavor
);
552 // -----------------------------------------------------------------------------
553 sal_Bool
ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector
& _rFlavors
)
555 for ( DataFlavorExVector::const_iterator aCheck
= _rFlavors
.begin();
556 aCheck
!= _rFlavors
.end();
560 if (SOT_FORMATSTR_ID_DBACCESS_TABLE
== aCheck
->mnSotId
)
562 if (SOT_FORMATSTR_ID_DBACCESS_QUERY
== aCheck
->mnSotId
)
564 if (SOT_FORMATSTR_ID_DBACCESS_COMMAND
== aCheck
->mnSotId
)
570 // -----------------------------------------------------------------------------
571 ODataAccessDescriptor
ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper
& _rData
)
573 sal_Int32 nKnownFormatId
= 0;
574 if ( _rData
.HasFormat( SOT_FORMATSTR_ID_DBACCESS_TABLE
) )
575 nKnownFormatId
= SOT_FORMATSTR_ID_DBACCESS_TABLE
;
576 if ( _rData
.HasFormat( SOT_FORMATSTR_ID_DBACCESS_QUERY
) )
577 nKnownFormatId
= SOT_FORMATSTR_ID_DBACCESS_QUERY
;
578 if ( _rData
.HasFormat( SOT_FORMATSTR_ID_DBACCESS_COMMAND
) )
579 nKnownFormatId
= SOT_FORMATSTR_ID_DBACCESS_COMMAND
;
581 if (0 != nKnownFormatId
)
583 // extract the any from the transferable
585 #if OSL_DEBUG_LEVEL > 0
588 SotExchange::GetFormatDataFlavor(nKnownFormatId
, aFlavor
);
589 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
591 Any aDescriptor
= _rData
.GetAny(aFlavor
);
593 // extract the property value sequence
594 Sequence
< PropertyValue
> aDescriptorProps
;
595 #if OSL_DEBUG_LEVEL > 0
598 aDescriptor
>>= aDescriptorProps
;
599 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
601 // build the real descriptor
602 return ODataAccessDescriptor(aDescriptorProps
);
605 OSL_ENSURE( sal_False
, "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
606 return ODataAccessDescriptor();
609 // -----------------------------------------------------------------------------
610 void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence
< Any
>& _rSelRows
)
612 const sal_Unicode
cSeparator(11);
613 const ::rtl::OUString
sSeparator(&cSeparator
, 1);
615 const Any
* pSelRows
= _rSelRows
.getConstArray();
616 const Any
* pSelRowsEnd
= pSelRows
+ _rSelRows
.getLength();
617 for ( ; pSelRows
< pSelRowsEnd
; ++pSelRows
)
619 sal_Int32
nSelectedRow( 0 );
620 OSL_VERIFY( *pSelRows
>>= nSelectedRow
);
622 m_sCompatibleObjectDescription
+= ::rtl::OUString::valueOf((sal_Int32
)nSelectedRow
);
623 m_sCompatibleObjectDescription
+= sSeparator
;
627 // -----------------------------------------------------------------------------
628 void ODataAccessObjectTransferable::ObjectReleased()
630 m_aDescriptor
.clear();
632 // -----------------------------------------------------------------------------
633 void ODataAccessObjectTransferable::construct( const ::rtl::OUString
& _rDatasource
634 ,const ::rtl::OUString
& _rConnectionResource
635 ,const sal_Int32 _nCommandType
636 ,const ::rtl::OUString
& _rCommand
637 ,const Reference
< XConnection
>& _rxConnection
638 ,sal_Bool _bAddCommand
639 ,const ::rtl::OUString
& _sActiveCommand
)
641 m_aDescriptor
.setDataSource(_rDatasource
);
642 // build the descriptor (the property sequence)
643 if ( _rConnectionResource
.getLength() )
644 m_aDescriptor
[daConnectionResource
] <<= _rConnectionResource
;
645 if ( _rxConnection
.is() )
646 m_aDescriptor
[daConnection
] <<= _rxConnection
;
647 m_aDescriptor
[daCommand
] <<= _rCommand
;
648 m_aDescriptor
[daCommandType
] <<= _nCommandType
;
650 // extract the single values from the sequence
652 ::rtl::OUString sObjectName
;
653 ::rtl::OUString sDatasourceName
= _rDatasource
;
654 sObjectName
= _rCommand
;
656 // for compatibility: create a string which can be used for the SOT_FORMATSTR_ID_SBA_DATAEXCHANGE format
658 sal_Bool bTreatAsStatement
= (CommandType::COMMAND
== _nCommandType
);
659 // statements are - in this old and ugly format - described as queries
661 const sal_Unicode cSeparator
= sal_Unicode(11);
662 const ::rtl::OUString
sSeparator(&cSeparator
, 1);
664 const sal_Unicode cTableMark
= '1';
665 const sal_Unicode cQueryMark
= '0';
667 // build the descriptor string
668 m_sCompatibleObjectDescription
+= sDatasourceName
;
669 m_sCompatibleObjectDescription
+= sSeparator
;
670 m_sCompatibleObjectDescription
+= bTreatAsStatement
? ::rtl::OUString() : sObjectName
;
671 m_sCompatibleObjectDescription
+= sSeparator
;
672 switch (_nCommandType
)
674 case CommandType::TABLE
:
675 m_sCompatibleObjectDescription
+= ::rtl::OUString(&cTableMark
, 1);
677 case CommandType::QUERY
:
678 m_sCompatibleObjectDescription
+= ::rtl::OUString(&cQueryMark
, 1);
680 case CommandType::COMMAND
:
681 m_sCompatibleObjectDescription
+= ::rtl::OUString(&cQueryMark
, 1);
682 // think of it as a query
685 m_sCompatibleObjectDescription
+= sSeparator
;
686 m_sCompatibleObjectDescription
+= _bAddCommand
? _sActiveCommand
: ::rtl::OUString();
687 m_sCompatibleObjectDescription
+= sSeparator
;
690 //--------------------------------------------------------------------
691 OMultiColumnTransferable::OMultiColumnTransferable(const Sequence
< PropertyValue
>& _aDescriptors
) : m_aDescriptors(_aDescriptors
)
694 //--------------------------------------------------------------------
695 sal_uInt32
OMultiColumnTransferable::getDescriptorFormatId()
697 static sal_uInt32 s_nFormat
= (sal_uInt32
)-1;
698 if ((sal_uInt32
)-1 == s_nFormat
)
700 s_nFormat
= SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\""));
701 OSL_ENSURE((sal_uInt32
)-1 != s_nFormat
, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
705 //--------------------------------------------------------------------
706 void OMultiColumnTransferable::AddSupportedFormats()
708 AddFormat(getDescriptorFormatId());
710 //--------------------------------------------------------------------
711 void OMultiColumnTransferable::push_back(ODataAccessDescriptor
& _aDescriptor
)
713 const sal_Int32 nCount
= m_aDescriptors
.getLength();
714 m_aDescriptors
.realloc(nCount
+1);
715 m_aDescriptors
[nCount
].Value
<<= _aDescriptor
.createPropertyValueSequence();
717 //--------------------------------------------------------------------
718 sal_Bool
OMultiColumnTransferable::GetData( const DataFlavor
& _rFlavor
)
720 const sal_uInt32 nFormatId
= SotExchange::GetFormat(_rFlavor
);
721 if (nFormatId
== getDescriptorFormatId())
723 return SetAny( makeAny( m_aDescriptors
), _rFlavor
);
729 //--------------------------------------------------------------------
730 sal_Bool
OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector
& _rFlavors
)
732 DataFlavorExVector::const_iterator aCheck
= _rFlavors
.begin();
734 aCheck
!= _rFlavors
.end() && getDescriptorFormatId() == aCheck
->mnSotId
;
739 return aCheck
== _rFlavors
.end();
742 //--------------------------------------------------------------------
743 Sequence
< PropertyValue
> OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper
& _rData
)
745 Sequence
< PropertyValue
> aList
;
746 if (_rData
.HasFormat(getDescriptorFormatId()))
748 // extract the any from the transferable
750 #if OSL_DEBUG_LEVEL > 0
753 SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor
);
754 OSL_ENSURE(bSuccess
, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
756 _rData
.GetAny(aFlavor
) >>= aList
;
757 } // if (_rData.HasFormat(getDescriptorFormatId()))
760 // -----------------------------------------------------------------------------
761 void OMultiColumnTransferable::ObjectReleased()
763 m_aDescriptors
.realloc(0);
766 //........................................................................
768 //........................................................................