xref: /aoo41x/main/svx/source/fmcomp/dbaobjectex.cxx (revision f6e50924)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <svx/dbaobjectex.hxx>
27cdf0e10cSrcweir #include <osl/diagnose.h>
28cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
29cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
31cdf0e10cSrcweir #ifndef _SVX_FMPROP_HRC
32cdf0e10cSrcweir #include "fmprop.hrc"
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include <comphelper/extract.hxx>
35cdf0e10cSrcweir #include <sot/formats.hxx>
36cdf0e10cSrcweir #include <sot/exchange.hxx>
37cdf0e10cSrcweir #include <comphelper/propertysetinfo.hxx>
38cdf0e10cSrcweir #ifndef _SVX_FMPROP_HRC
39cdf0e10cSrcweir #include "fmprop.hrc"
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //........................................................................
43cdf0e10cSrcweir namespace svx
44cdf0e10cSrcweir {
45cdf0e10cSrcweir //........................................................................
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
49cdf0e10cSrcweir 	using namespace ::com::sun::star::sdb;
50cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
51cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
52cdf0e10cSrcweir 	using namespace ::com::sun::star::ucb;
53cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbcx;
54cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
55cdf0e10cSrcweir 	using namespace ::com::sun::star::datatransfer;
56cdf0e10cSrcweir 	using namespace ::comphelper;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	//====================================================================
59cdf0e10cSrcweir 	//= OComponentTransferable
60cdf0e10cSrcweir 	//====================================================================
61cdf0e10cSrcweir 	//--------------------------------------------------------------------
OComponentTransferable(const::rtl::OUString & _rDatasourceOrLocation,const Reference<XContent> & _xContent)62cdf0e10cSrcweir 	OComponentTransferable::OComponentTransferable(const ::rtl::OUString& _rDatasourceOrLocation
63cdf0e10cSrcweir 			,const Reference< XContent>& _xContent)
64cdf0e10cSrcweir 	{
65cdf0e10cSrcweir 		m_aDescriptor.setDataSource(_rDatasourceOrLocation);
66cdf0e10cSrcweir 		m_aDescriptor[daComponent] <<= _xContent;
67cdf0e10cSrcweir 	}
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	//--------------------------------------------------------------------
getDescriptorFormatId(sal_Bool _bExtractForm)71cdf0e10cSrcweir 	sal_uInt32 OComponentTransferable::getDescriptorFormatId(sal_Bool _bExtractForm)
72cdf0e10cSrcweir 	{
73cdf0e10cSrcweir 		static sal_uInt32 s_nReportFormat = (sal_uInt32)-1;
74cdf0e10cSrcweir 		static sal_uInt32 s_nFormFormat = (sal_uInt32)-1;
75cdf0e10cSrcweir 		if ( _bExtractForm && (sal_uInt32)-1 == s_nFormFormat )
76cdf0e10cSrcweir 		{
77cdf0e10cSrcweir 			s_nFormFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"" ));
78cdf0e10cSrcweir 			OSL_ENSURE((sal_uInt32)-1 != s_nFormFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
79cdf0e10cSrcweir 		}
80cdf0e10cSrcweir 		else if ( !_bExtractForm && (sal_uInt32)-1 == s_nReportFormat)
81cdf0e10cSrcweir 		{
82cdf0e10cSrcweir 			s_nReportFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\""));
83cdf0e10cSrcweir 			OSL_ENSURE((sal_uInt32)-1 != s_nReportFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
84cdf0e10cSrcweir 		}
85cdf0e10cSrcweir 		return _bExtractForm ? s_nFormFormat : s_nReportFormat;
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	//--------------------------------------------------------------------
AddSupportedFormats()89cdf0e10cSrcweir 	void OComponentTransferable::AddSupportedFormats()
90cdf0e10cSrcweir 	{
91cdf0e10cSrcweir 		sal_Bool bForm = sal_True;
92cdf0e10cSrcweir 		try
93cdf0e10cSrcweir 		{
94cdf0e10cSrcweir 			Reference<XPropertySet> xProp;
95cdf0e10cSrcweir 			m_aDescriptor[daComponent] >>= xProp;
96cdf0e10cSrcweir 			if ( xProp.is() )
97cdf0e10cSrcweir 				xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm"))) >>= bForm;
98cdf0e10cSrcweir 		}
99cdf0e10cSrcweir 		catch(Exception)
100cdf0e10cSrcweir 		{}
101cdf0e10cSrcweir 		AddFormat(getDescriptorFormatId(bForm));
102cdf0e10cSrcweir 	}
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	//--------------------------------------------------------------------
GetData(const DataFlavor & _rFlavor)105cdf0e10cSrcweir 	sal_Bool OComponentTransferable::GetData( const DataFlavor& _rFlavor )
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
108cdf0e10cSrcweir 		if ( nFormatId == getDescriptorFormatId(sal_True) || nFormatId == getDescriptorFormatId(sal_False) )
109cdf0e10cSrcweir 			return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		return sal_False;
112cdf0e10cSrcweir 	}
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	//--------------------------------------------------------------------
canExtractComponentDescriptor(const DataFlavorExVector & _rFlavors,sal_Bool _bForm)115cdf0e10cSrcweir 	sal_Bool OComponentTransferable::canExtractComponentDescriptor(const DataFlavorExVector& _rFlavors,sal_Bool _bForm )
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		DataFlavorExVector::const_iterator aEnd = _rFlavors.end();
118cdf0e10cSrcweir 		for (	DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
119cdf0e10cSrcweir 				aCheck != aEnd;
120cdf0e10cSrcweir 				++aCheck
121cdf0e10cSrcweir 			)
122cdf0e10cSrcweir 		{
123cdf0e10cSrcweir 			if ( getDescriptorFormatId(_bForm) == aCheck->mnSotId )
124cdf0e10cSrcweir 				return sal_True;
125cdf0e10cSrcweir 		}
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 		return sal_False;
128cdf0e10cSrcweir 	}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	//--------------------------------------------------------------------
extractComponentDescriptor(const TransferableDataHelper & _rData)131cdf0e10cSrcweir 	ODataAccessDescriptor OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData)
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		sal_Bool bForm = _rData.HasFormat(getDescriptorFormatId(sal_True));
134cdf0e10cSrcweir 		if ( bForm || _rData.HasFormat(getDescriptorFormatId(sal_False)) )
135cdf0e10cSrcweir 		{
136cdf0e10cSrcweir 			// the object has a real descriptor object (not just the old compatible format)
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 			// extract the any from the transferable
139cdf0e10cSrcweir 			DataFlavor aFlavor;
140cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
141cdf0e10cSrcweir 			sal_Bool bSuccess =
142cdf0e10cSrcweir #endif
143cdf0e10cSrcweir 			SotExchange::GetFormatDataFlavor(getDescriptorFormatId(bForm), aFlavor);
144cdf0e10cSrcweir 			OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 			Any aDescriptor = _rData.GetAny(aFlavor);
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 			// extract the property value sequence
149cdf0e10cSrcweir 			Sequence< PropertyValue > aDescriptorProps;
150cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
151cdf0e10cSrcweir 			bSuccess =
152cdf0e10cSrcweir #endif
153cdf0e10cSrcweir 			aDescriptor >>= aDescriptorProps;
154cdf0e10cSrcweir 			OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!");
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 			// build the real descriptor
157cdf0e10cSrcweir 			return ODataAccessDescriptor(aDescriptorProps);
158cdf0e10cSrcweir 		}
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 		return ODataAccessDescriptor();
161cdf0e10cSrcweir 	}
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	//--------------------------------------------------------------------
extractComponentDescriptor(const TransferableDataHelper & _rData,sal_Bool _bExtractForm,::rtl::OUString & _rDatasourceOrLocation,::com::sun::star::uno::Reference<XContent> & _xContent)164cdf0e10cSrcweir 	sal_Bool OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData
165cdf0e10cSrcweir 		,sal_Bool _bExtractForm
166cdf0e10cSrcweir 		, ::rtl::OUString&	_rDatasourceOrLocation
167cdf0e10cSrcweir 		, ::com::sun::star::uno::Reference< XContent>& _xContent)
168cdf0e10cSrcweir 	{
169cdf0e10cSrcweir 		if ( _rData.HasFormat( getDescriptorFormatId(_bExtractForm)) )
170cdf0e10cSrcweir 		{
171cdf0e10cSrcweir 			ODataAccessDescriptor aDescriptor = extractComponentDescriptor(_rData);
172cdf0e10cSrcweir 			_rDatasourceOrLocation = aDescriptor.getDataSource();
173cdf0e10cSrcweir 			aDescriptor[daComponent]			>>= _xContent;
174cdf0e10cSrcweir 			return sal_True;
175cdf0e10cSrcweir 		}
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 		return sal_False;
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir //........................................................................
180cdf0e10cSrcweir }	// namespace svx
181cdf0e10cSrcweir //........................................................................
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 
184