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