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 OUString& _rDatasource
51 : ,const OUString& _rConnectionResource
52 : ,const sal_Int32 _nCommandType
53 : ,const OUString& _rCommand
54 : ,const 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 : 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 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 : OUString sCommand;
98 0 : sal_Int32 nCommandType = CommandType::TABLE;
99 0 : 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("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< 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(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 OUString& _rDatasource
169 : ,const OUString& _rConnectionResource
170 : ,const sal_Int32 _nCommandType
171 : ,const OUString& _rCommand
172 : , const OUString& _rFieldName)
173 : {
174 0 : const sal_Unicode cSeparator = sal_Unicode(11);
175 0 : const OUString sSeparator(&cSeparator, 1);
176 :
177 0 : m_sCompatibleFormat = 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 += 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 : 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 false;
240 : }
241 :
242 :
243 0 : bool OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector& _rFlavors, sal_Int32 _nFormats)
244 : {
245 0 : bool bFieldFormat = 0 != (_nFormats & CTF_FIELD_DESCRIPTOR);
246 0 : bool bControlFormat = 0 != (_nFormats & CTF_CONTROL_EXCHANGE);
247 0 : 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 true;
255 0 : if (bControlFormat && (SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == aCheck->mnSotId))
256 0 : return true;
257 0 : if (bDescriptorFormat && (getDescriptorFormatId() == aCheck->mnSotId))
258 0 : return true;
259 : }
260 :
261 0 : return 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 : 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 : bool OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData
317 : ,OUString& _rDatasource
318 : ,OUString& _rDatabaseLocation
319 : ,OUString& _rConnectionResource
320 : ,sal_Int32& _nCommandType
321 : ,OUString& _rCommand
322 : ,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 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 false;
348 :
349 0 : OUString 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 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 OUString& _rDatasource
388 : ,const OUString& _rConnectionResource
389 : ,const sal_Int32 _nCommandType
390 : ,const 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 OUString& _rDatasource
398 : ,const OUString& _rConnectionResource
399 : ,const sal_Int32 _nCommandType
400 : ,const 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 : OUString sDatasourceName,sConnectionResource;
412 0 : sal_Int32 nObjectType = CommandType::COMMAND;
413 0 : 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 0 : return;
427 : }
428 :
429 : // check if the SQL-statement is modified
430 0 : 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 0 : 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 : if (!m_sCompatibleObjectDescription.isEmpty())
468 0 : AddFormat(SOT_FORMATSTR_ID_SBA_DATAEXCHANGE);
469 0 : }
470 :
471 :
472 0 : bool ODataAccessObjectTransferable::GetData( const DataFlavor& rFlavor )
473 : {
474 0 : sal_uIntPtr nFormat = SotExchange::GetFormat(rFlavor);
475 0 : switch (nFormat)
476 : {
477 : case SOT_FORMATSTR_ID_DBACCESS_TABLE:
478 : case SOT_FORMATSTR_ID_DBACCESS_QUERY:
479 : case SOT_FORMATSTR_ID_DBACCESS_COMMAND:
480 0 : return SetAny( makeAny(m_aDescriptor.createPropertyValueSequence()), rFlavor );
481 :
482 : case SOT_FORMATSTR_ID_SBA_DATAEXCHANGE:
483 0 : return SetString(m_sCompatibleObjectDescription, rFlavor);
484 : }
485 0 : return false;
486 : }
487 :
488 :
489 0 : bool ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector& _rFlavors)
490 : {
491 0 : for ( DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
492 0 : aCheck != _rFlavors.end();
493 : ++aCheck
494 : )
495 : {
496 0 : if (SOT_FORMATSTR_ID_DBACCESS_TABLE == aCheck->mnSotId)
497 0 : return true;
498 0 : if (SOT_FORMATSTR_ID_DBACCESS_QUERY == aCheck->mnSotId)
499 0 : return true;
500 0 : if (SOT_FORMATSTR_ID_DBACCESS_COMMAND == aCheck->mnSotId)
501 0 : return true;
502 : }
503 0 : return false;
504 : }
505 :
506 :
507 0 : ODataAccessDescriptor ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper& _rData)
508 : {
509 0 : sal_Int32 nKnownFormatId = 0;
510 0 : if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_TABLE ) )
511 0 : nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_TABLE;
512 0 : if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_QUERY ) )
513 0 : nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_QUERY;
514 0 : if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_COMMAND ) )
515 0 : nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_COMMAND;
516 :
517 0 : if (0 != nKnownFormatId)
518 : {
519 : // extract the any from the transferable
520 0 : DataFlavor aFlavor;
521 : #if OSL_DEBUG_LEVEL > 0
522 : sal_Bool bSuccess =
523 : #endif
524 0 : SotExchange::GetFormatDataFlavor(nKnownFormatId, aFlavor);
525 : OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
526 :
527 0 : Any aDescriptor = _rData.GetAny(aFlavor);
528 :
529 : // extract the property value sequence
530 0 : Sequence< PropertyValue > aDescriptorProps;
531 : #if OSL_DEBUG_LEVEL > 0
532 : bSuccess =
533 : #endif
534 0 : aDescriptor >>= aDescriptorProps;
535 : OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
536 :
537 : // build the real descriptor
538 0 : return ODataAccessDescriptor(aDescriptorProps);
539 : }
540 :
541 : OSL_FAIL( "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
542 0 : return ODataAccessDescriptor();
543 : }
544 :
545 :
546 0 : void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence< Any >& _rSelRows )
547 : {
548 0 : const sal_Unicode cSeparator(11);
549 0 : const OUString sSeparator(&cSeparator, 1);
550 :
551 0 : const Any* pSelRows = _rSelRows.getConstArray();
552 0 : const Any* pSelRowsEnd = pSelRows + _rSelRows.getLength();
553 0 : for ( ; pSelRows < pSelRowsEnd; ++pSelRows )
554 : {
555 0 : sal_Int32 nSelectedRow( 0 );
556 0 : OSL_VERIFY( *pSelRows >>= nSelectedRow );
557 :
558 0 : m_sCompatibleObjectDescription += OUString::number(nSelectedRow);
559 0 : m_sCompatibleObjectDescription += sSeparator;
560 0 : }
561 0 : }
562 :
563 :
564 0 : void ODataAccessObjectTransferable::ObjectReleased()
565 : {
566 0 : m_aDescriptor.clear();
567 0 : }
568 :
569 0 : void ODataAccessObjectTransferable::construct( const OUString& _rDatasource
570 : ,const OUString& _rConnectionResource
571 : ,const sal_Int32 _nCommandType
572 : ,const OUString& _rCommand
573 : ,const Reference< XConnection >& _rxConnection
574 : ,bool _bAddCommand
575 : ,const OUString& _sActiveCommand)
576 : {
577 0 : m_aDescriptor.setDataSource(_rDatasource);
578 : // build the descriptor (the property sequence)
579 0 : if ( !_rConnectionResource.isEmpty() )
580 0 : m_aDescriptor[daConnectionResource] <<= _rConnectionResource;
581 0 : if ( _rxConnection.is() )
582 0 : m_aDescriptor[daConnection] <<= _rxConnection;
583 0 : m_aDescriptor[daCommand] <<= _rCommand;
584 0 : m_aDescriptor[daCommandType] <<= _nCommandType;
585 :
586 : // extract the single values from the sequence
587 :
588 0 : OUString sObjectName;
589 0 : OUString sDatasourceName = _rDatasource;
590 0 : sObjectName = _rCommand;
591 :
592 : // for compatibility: create a string which can be used for the SOT_FORMATSTR_ID_SBA_DATAEXCHANGE format
593 :
594 0 : sal_Bool bTreatAsStatement = (CommandType::COMMAND == _nCommandType);
595 : // statements are - in this old and ugly format - described as queries
596 :
597 0 : const sal_Unicode cSeparator = sal_Unicode(11);
598 0 : const OUString sSeparator(&cSeparator, 1);
599 :
600 0 : const sal_Unicode cTableMark = '1';
601 0 : const sal_Unicode cQueryMark = '0';
602 :
603 : // build the descriptor string
604 0 : m_sCompatibleObjectDescription += sDatasourceName;
605 0 : m_sCompatibleObjectDescription += sSeparator;
606 0 : m_sCompatibleObjectDescription += bTreatAsStatement ? OUString() : sObjectName;
607 0 : m_sCompatibleObjectDescription += sSeparator;
608 0 : switch (_nCommandType)
609 : {
610 : case CommandType::TABLE:
611 0 : m_sCompatibleObjectDescription += OUString(&cTableMark, 1);
612 0 : break;
613 : case CommandType::QUERY:
614 0 : m_sCompatibleObjectDescription += OUString(&cQueryMark, 1);
615 0 : break;
616 : case CommandType::COMMAND:
617 0 : m_sCompatibleObjectDescription += OUString(&cQueryMark, 1);
618 : // think of it as a query
619 0 : break;
620 : }
621 0 : m_sCompatibleObjectDescription += sSeparator;
622 0 : m_sCompatibleObjectDescription += _bAddCommand ? _sActiveCommand : OUString();
623 0 : m_sCompatibleObjectDescription += sSeparator;
624 0 : }
625 :
626 :
627 0 : OMultiColumnTransferable::OMultiColumnTransferable(const Sequence< PropertyValue >& _aDescriptors) : m_aDescriptors(_aDescriptors)
628 : {
629 0 : }
630 :
631 0 : sal_uInt32 OMultiColumnTransferable::getDescriptorFormatId()
632 : {
633 : static sal_uInt32 s_nFormat = (sal_uInt32)-1;
634 0 : if ((sal_uInt32)-1 == s_nFormat)
635 : {
636 0 : s_nFormat = SotExchange::RegisterFormatName(OUString("application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\""));
637 : OSL_ENSURE((sal_uInt32)-1 != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
638 : }
639 0 : return s_nFormat;
640 : }
641 :
642 0 : void OMultiColumnTransferable::AddSupportedFormats()
643 : {
644 0 : AddFormat(getDescriptorFormatId());
645 0 : }
646 :
647 0 : bool OMultiColumnTransferable::GetData( const DataFlavor& _rFlavor )
648 : {
649 0 : const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
650 0 : if (nFormatId == getDescriptorFormatId())
651 : {
652 0 : return SetAny( makeAny( m_aDescriptors ), _rFlavor );
653 : }
654 :
655 0 : return false;
656 : }
657 :
658 :
659 0 : bool OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector& _rFlavors)
660 : {
661 0 : DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
662 0 : for ( ;
663 0 : aCheck != _rFlavors.end() && getDescriptorFormatId() == aCheck->mnSotId;
664 : ++aCheck
665 : )
666 : ;
667 :
668 0 : return aCheck == _rFlavors.end();
669 : }
670 :
671 :
672 0 : Sequence< PropertyValue > OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper& _rData)
673 : {
674 0 : Sequence< PropertyValue > aList;
675 0 : if (_rData.HasFormat(getDescriptorFormatId()))
676 : {
677 : // extract the any from the transferable
678 0 : DataFlavor aFlavor;
679 : #if OSL_DEBUG_LEVEL > 0
680 : sal_Bool bSuccess =
681 : #endif
682 0 : SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor);
683 : OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
684 :
685 0 : _rData.GetAny(aFlavor) >>= aList;
686 : } // if (_rData.HasFormat(getDescriptorFormatId()))
687 0 : return aList;
688 : }
689 :
690 0 : void OMultiColumnTransferable::ObjectReleased()
691 : {
692 0 : m_aDescriptors.realloc(0);
693 0 : }
694 :
695 :
696 : } // namespace svx
697 :
698 :
699 :
700 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|