xref: /AOO41X/main/svx/source/fmcomp/dbaobjectex.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/dbaobjectex.hxx>
31*cdf0e10cSrcweir #include <osl/diagnose.h>
32*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
35*cdf0e10cSrcweir #ifndef _SVX_FMPROP_HRC
36*cdf0e10cSrcweir #include "fmprop.hrc"
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir #include <comphelper/extract.hxx>
39*cdf0e10cSrcweir #include <sot/formats.hxx>
40*cdf0e10cSrcweir #include <sot/exchange.hxx>
41*cdf0e10cSrcweir #include <comphelper/propertysetinfo.hxx>
42*cdf0e10cSrcweir #ifndef _SVX_FMPROP_HRC
43*cdf0e10cSrcweir #include "fmprop.hrc"
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir //........................................................................
47*cdf0e10cSrcweir namespace svx
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir //........................................................................
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
52*cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
53*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdb;
54*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
55*cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
56*cdf0e10cSrcweir 	using namespace ::com::sun::star::ucb;
57*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbcx;
58*cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
59*cdf0e10cSrcweir 	using namespace ::com::sun::star::datatransfer;
60*cdf0e10cSrcweir 	using namespace ::comphelper;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 	//====================================================================
63*cdf0e10cSrcweir 	//= OComponentTransferable
64*cdf0e10cSrcweir 	//====================================================================
65*cdf0e10cSrcweir 	//--------------------------------------------------------------------
66*cdf0e10cSrcweir 	OComponentTransferable::OComponentTransferable(const ::rtl::OUString& _rDatasourceOrLocation
67*cdf0e10cSrcweir 			,const Reference< XContent>& _xContent)
68*cdf0e10cSrcweir 	{
69*cdf0e10cSrcweir 		m_aDescriptor.setDataSource(_rDatasourceOrLocation);
70*cdf0e10cSrcweir 		m_aDescriptor[daComponent] <<= _xContent;
71*cdf0e10cSrcweir 	}
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 	//--------------------------------------------------------------------
75*cdf0e10cSrcweir 	sal_uInt32 OComponentTransferable::getDescriptorFormatId(sal_Bool _bExtractForm)
76*cdf0e10cSrcweir 	{
77*cdf0e10cSrcweir 		static sal_uInt32 s_nReportFormat = (sal_uInt32)-1;
78*cdf0e10cSrcweir 		static sal_uInt32 s_nFormFormat = (sal_uInt32)-1;
79*cdf0e10cSrcweir 		if ( _bExtractForm && (sal_uInt32)-1 == s_nFormFormat )
80*cdf0e10cSrcweir 		{
81*cdf0e10cSrcweir 			s_nFormFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"" ));
82*cdf0e10cSrcweir 			OSL_ENSURE((sal_uInt32)-1 != s_nFormFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
83*cdf0e10cSrcweir 		}
84*cdf0e10cSrcweir 		else if ( !_bExtractForm && (sal_uInt32)-1 == s_nReportFormat)
85*cdf0e10cSrcweir 		{
86*cdf0e10cSrcweir 			s_nReportFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\""));
87*cdf0e10cSrcweir 			OSL_ENSURE((sal_uInt32)-1 != s_nReportFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
88*cdf0e10cSrcweir 		}
89*cdf0e10cSrcweir 		return _bExtractForm ? s_nFormFormat : s_nReportFormat;
90*cdf0e10cSrcweir 	}
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	//--------------------------------------------------------------------
93*cdf0e10cSrcweir 	void OComponentTransferable::AddSupportedFormats()
94*cdf0e10cSrcweir 	{
95*cdf0e10cSrcweir 		sal_Bool bForm = sal_True;
96*cdf0e10cSrcweir 		try
97*cdf0e10cSrcweir 		{
98*cdf0e10cSrcweir 			Reference<XPropertySet> xProp;
99*cdf0e10cSrcweir 			m_aDescriptor[daComponent] >>= xProp;
100*cdf0e10cSrcweir 			if ( xProp.is() )
101*cdf0e10cSrcweir 				xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm"))) >>= bForm;
102*cdf0e10cSrcweir 		}
103*cdf0e10cSrcweir 		catch(Exception)
104*cdf0e10cSrcweir 		{}
105*cdf0e10cSrcweir 		AddFormat(getDescriptorFormatId(bForm));
106*cdf0e10cSrcweir 	}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	//--------------------------------------------------------------------
109*cdf0e10cSrcweir 	sal_Bool OComponentTransferable::GetData( const DataFlavor& _rFlavor )
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir 		const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
112*cdf0e10cSrcweir 		if ( nFormatId == getDescriptorFormatId(sal_True) || nFormatId == getDescriptorFormatId(sal_False) )
113*cdf0e10cSrcweir 			return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 		return sal_False;
116*cdf0e10cSrcweir 	}
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	//--------------------------------------------------------------------
119*cdf0e10cSrcweir 	sal_Bool OComponentTransferable::canExtractComponentDescriptor(const DataFlavorExVector& _rFlavors,sal_Bool _bForm )
120*cdf0e10cSrcweir 	{
121*cdf0e10cSrcweir 		DataFlavorExVector::const_iterator aEnd = _rFlavors.end();
122*cdf0e10cSrcweir 		for (	DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
123*cdf0e10cSrcweir 				aCheck != aEnd;
124*cdf0e10cSrcweir 				++aCheck
125*cdf0e10cSrcweir 			)
126*cdf0e10cSrcweir 		{
127*cdf0e10cSrcweir 			if ( getDescriptorFormatId(_bForm) == aCheck->mnSotId )
128*cdf0e10cSrcweir 				return sal_True;
129*cdf0e10cSrcweir 		}
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 		return sal_False;
132*cdf0e10cSrcweir 	}
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	//--------------------------------------------------------------------
135*cdf0e10cSrcweir 	ODataAccessDescriptor OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData)
136*cdf0e10cSrcweir 	{
137*cdf0e10cSrcweir 		sal_Bool bForm = _rData.HasFormat(getDescriptorFormatId(sal_True));
138*cdf0e10cSrcweir 		if ( bForm || _rData.HasFormat(getDescriptorFormatId(sal_False)) )
139*cdf0e10cSrcweir 		{
140*cdf0e10cSrcweir 			// the object has a real descriptor object (not just the old compatible format)
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 			// extract the any from the transferable
143*cdf0e10cSrcweir 			DataFlavor aFlavor;
144*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
145*cdf0e10cSrcweir 			sal_Bool bSuccess =
146*cdf0e10cSrcweir #endif
147*cdf0e10cSrcweir 			SotExchange::GetFormatDataFlavor(getDescriptorFormatId(bForm), aFlavor);
148*cdf0e10cSrcweir 			OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 			Any aDescriptor = _rData.GetAny(aFlavor);
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 			// extract the property value sequence
153*cdf0e10cSrcweir 			Sequence< PropertyValue > aDescriptorProps;
154*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
155*cdf0e10cSrcweir 			bSuccess =
156*cdf0e10cSrcweir #endif
157*cdf0e10cSrcweir 			aDescriptor >>= aDescriptorProps;
158*cdf0e10cSrcweir 			OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!");
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 			// build the real descriptor
161*cdf0e10cSrcweir 			return ODataAccessDescriptor(aDescriptorProps);
162*cdf0e10cSrcweir 		}
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 		return ODataAccessDescriptor();
165*cdf0e10cSrcweir 	}
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	//--------------------------------------------------------------------
168*cdf0e10cSrcweir 	sal_Bool OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData
169*cdf0e10cSrcweir 		,sal_Bool _bExtractForm
170*cdf0e10cSrcweir 		, ::rtl::OUString&	_rDatasourceOrLocation
171*cdf0e10cSrcweir 		, ::com::sun::star::uno::Reference< XContent>& _xContent)
172*cdf0e10cSrcweir 	{
173*cdf0e10cSrcweir 		if ( _rData.HasFormat( getDescriptorFormatId(_bExtractForm)) )
174*cdf0e10cSrcweir 		{
175*cdf0e10cSrcweir 			ODataAccessDescriptor aDescriptor = extractComponentDescriptor(_rData);
176*cdf0e10cSrcweir 			_rDatasourceOrLocation = aDescriptor.getDataSource();
177*cdf0e10cSrcweir 			aDescriptor[daComponent]			>>= _xContent;
178*cdf0e10cSrcweir 			return sal_True;
179*cdf0e10cSrcweir 		}
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 		return sal_False;
182*cdf0e10cSrcweir 	}
183*cdf0e10cSrcweir //........................................................................
184*cdf0e10cSrcweir }	// namespace svx
185*cdf0e10cSrcweir //........................................................................
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 
188