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