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