xref: /aoo41x/main/svx/source/fmcomp/dbaobjectex.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include <svx/dbaobjectex.hxx>
31 #include <osl/diagnose.h>
32 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
33 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
34 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
35 #ifndef _SVX_FMPROP_HRC
36 #include "fmprop.hrc"
37 #endif
38 #include <comphelper/extract.hxx>
39 #include <sot/formats.hxx>
40 #include <sot/exchange.hxx>
41 #include <comphelper/propertysetinfo.hxx>
42 #ifndef _SVX_FMPROP_HRC
43 #include "fmprop.hrc"
44 #endif
45 
46 //........................................................................
47 namespace svx
48 {
49 //........................................................................
50 
51 	using namespace ::com::sun::star::uno;
52 	using namespace ::com::sun::star::beans;
53 	using namespace ::com::sun::star::sdb;
54 	using namespace ::com::sun::star::sdbc;
55 	using namespace ::com::sun::star::lang;
56 	using namespace ::com::sun::star::ucb;
57 	using namespace ::com::sun::star::sdbcx;
58 	using namespace ::com::sun::star::container;
59 	using namespace ::com::sun::star::datatransfer;
60 	using namespace ::comphelper;
61 
62 	//====================================================================
63 	//= OComponentTransferable
64 	//====================================================================
65 	//--------------------------------------------------------------------
66 	OComponentTransferable::OComponentTransferable(const ::rtl::OUString& _rDatasourceOrLocation
67 			,const Reference< XContent>& _xContent)
68 	{
69 		m_aDescriptor.setDataSource(_rDatasourceOrLocation);
70 		m_aDescriptor[daComponent] <<= _xContent;
71 	}
72 
73 
74 	//--------------------------------------------------------------------
75 	sal_uInt32 OComponentTransferable::getDescriptorFormatId(sal_Bool _bExtractForm)
76 	{
77 		static sal_uInt32 s_nReportFormat = (sal_uInt32)-1;
78 		static sal_uInt32 s_nFormFormat = (sal_uInt32)-1;
79 		if ( _bExtractForm && (sal_uInt32)-1 == s_nFormFormat )
80 		{
81 			s_nFormFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.FormComponentDescriptorTransfer\"" ));
82 			OSL_ENSURE((sal_uInt32)-1 != s_nFormFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
83 		}
84 		else if ( !_bExtractForm && (sal_uInt32)-1 == s_nReportFormat)
85 		{
86 			s_nReportFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.ReportComponentDescriptorTransfer\""));
87 			OSL_ENSURE((sal_uInt32)-1 != s_nReportFormat, "OComponentTransferable::getDescriptorFormatId: bad exchange id!");
88 		}
89 		return _bExtractForm ? s_nFormFormat : s_nReportFormat;
90 	}
91 
92 	//--------------------------------------------------------------------
93 	void OComponentTransferable::AddSupportedFormats()
94 	{
95 		sal_Bool bForm = sal_True;
96 		try
97 		{
98 			Reference<XPropertySet> xProp;
99 			m_aDescriptor[daComponent] >>= xProp;
100 			if ( xProp.is() )
101 				xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsForm"))) >>= bForm;
102 		}
103 		catch(Exception)
104 		{}
105 		AddFormat(getDescriptorFormatId(bForm));
106 	}
107 
108 	//--------------------------------------------------------------------
109 	sal_Bool OComponentTransferable::GetData( const DataFlavor& _rFlavor )
110 	{
111 		const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
112 		if ( nFormatId == getDescriptorFormatId(sal_True) || nFormatId == getDescriptorFormatId(sal_False) )
113 			return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor );
114 
115 		return sal_False;
116 	}
117 
118 	//--------------------------------------------------------------------
119 	sal_Bool OComponentTransferable::canExtractComponentDescriptor(const DataFlavorExVector& _rFlavors,sal_Bool _bForm )
120 	{
121 		DataFlavorExVector::const_iterator aEnd = _rFlavors.end();
122 		for (	DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
123 				aCheck != aEnd;
124 				++aCheck
125 			)
126 		{
127 			if ( getDescriptorFormatId(_bForm) == aCheck->mnSotId )
128 				return sal_True;
129 		}
130 
131 		return sal_False;
132 	}
133 
134 	//--------------------------------------------------------------------
135 	ODataAccessDescriptor OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData)
136 	{
137 		sal_Bool bForm = _rData.HasFormat(getDescriptorFormatId(sal_True));
138 		if ( bForm || _rData.HasFormat(getDescriptorFormatId(sal_False)) )
139 		{
140 			// the object has a real descriptor object (not just the old compatible format)
141 
142 			// extract the any from the transferable
143 			DataFlavor aFlavor;
144 #if OSL_DEBUG_LEVEL > 0
145 			sal_Bool bSuccess =
146 #endif
147 			SotExchange::GetFormatDataFlavor(getDescriptorFormatId(bForm), aFlavor);
148 			OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
149 
150 			Any aDescriptor = _rData.GetAny(aFlavor);
151 
152 			// extract the property value sequence
153 			Sequence< PropertyValue > aDescriptorProps;
154 #if OSL_DEBUG_LEVEL > 0
155 			bSuccess =
156 #endif
157 			aDescriptor >>= aDescriptorProps;
158 			OSL_ENSURE(bSuccess, "OComponentTransferable::extractColumnDescriptor: invalid clipboard format!");
159 
160 			// build the real descriptor
161 			return ODataAccessDescriptor(aDescriptorProps);
162 		}
163 
164 		return ODataAccessDescriptor();
165 	}
166 
167 	//--------------------------------------------------------------------
168 	sal_Bool OComponentTransferable::extractComponentDescriptor(const TransferableDataHelper& _rData
169 		,sal_Bool _bExtractForm
170 		, ::rtl::OUString&	_rDatasourceOrLocation
171 		, ::com::sun::star::uno::Reference< XContent>& _xContent)
172 	{
173 		if ( _rData.HasFormat( getDescriptorFormatId(_bExtractForm)) )
174 		{
175 			ODataAccessDescriptor aDescriptor = extractComponentDescriptor(_rData);
176 			_rDatasourceOrLocation = aDescriptor.getDataSource();
177 			aDescriptor[daComponent]			>>= _xContent;
178 			return sal_True;
179 		}
180 
181 		return sal_False;
182 	}
183 //........................................................................
184 }	// namespace svx
185 //........................................................................
186 
187 
188