Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "xmlExport.hxx"
22 : #include "xmlAutoStyle.hxx"
23 : #include "flt_reghelper.hxx"
24 : #include <sax/tools/converter.hxx>
25 : #include <xmloff/ProgressBarHelper.hxx>
26 : #include <xmloff/xmltoken.hxx>
27 : #include <xmloff/txtimp.hxx>
28 : #include <xmloff/xmlnmspe.hxx>
29 : #include <xmloff/nmspmap.hxx>
30 : #include <comphelper/string.hxx>
31 : #include <comphelper/types.hxx>
32 : #include "xmlstrings.hrc"
33 : #include "xmlEnums.hxx"
34 : #include <com/sun/star/beans/XPropertyState.hpp>
35 : #include <com/sun/star/beans/PropertyAttribute.hpp>
36 : #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
37 : #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
38 : #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
39 : #include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
40 : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
41 : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
42 :
43 : #include <com/sun/star/awt/TextAlign.hpp>
44 : #include <xmloff/xmluconv.hxx>
45 : #include "xmlHelper.hxx"
46 : #include <com/sun/star/awt/FontDescriptor.hpp>
47 : #include <svl/filenotation.hxx>
48 : #include <unotools/pathoptions.hxx>
49 : #include <tools/diagnose_ex.h>
50 : #include <connectivity/DriversConfig.hxx>
51 : #include <connectivity/dbtools.hxx>
52 :
53 : #include <boost/optional.hpp>
54 :
55 : namespace dbaxml
56 : {
57 : using namespace comphelper;
58 : using namespace ::com::sun::star::sdb;
59 : using namespace ::com::sun::star::sdbcx;
60 : using namespace ::com::sun::star::util;
61 : using namespace ::com::sun::star;
62 :
63 : class ODBExportHelper
64 : {
65 : public:
66 : static ::rtl::OUString SAL_CALL getImplementationName_Static( ) throw (RuntimeException);
67 : static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static( ) throw(RuntimeException);
68 : static Reference< XInterface > SAL_CALL Create(const Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
69 : };
70 : class ODBFullExportHelper
71 : {
72 : public:
73 : static ::rtl::OUString SAL_CALL getImplementationName_Static( ) throw (RuntimeException);
74 : static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_Static( ) throw(RuntimeException);
75 : static Reference< XInterface > SAL_CALL Create(const Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
76 : };
77 : }
78 : // -----------------------------------------------------------------------------
79 0 : extern "C" void SAL_CALL createRegistryInfo_ODBFilterExport( )
80 : {
81 0 : static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::ODBExport > aAutoRegistration;
82 0 : }
83 : //--------------------------------------------------------------------------
84 0 : extern "C" void SAL_CALL createRegistryInfo_OSettingsExport( )
85 : {
86 0 : static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::ODBExportHelper > aAutoRegistration;
87 0 : }
88 : //--------------------------------------------------------------------------
89 0 : extern "C" void SAL_CALL createRegistryInfo_OFullExport( )
90 : {
91 0 : static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::ODBFullExportHelper > aAutoRegistration;
92 0 : }
93 : //--------------------------------------------------------------------------
94 : namespace dbaxml
95 : {
96 : using namespace comphelper;
97 : using namespace ::com::sun::star::sdb;
98 : using namespace ::com::sun::star::sdbcx;
99 : using namespace ::com::sun::star::util;
100 :
101 : //---------------------------------------------------------------------
102 0 : Reference< XInterface > SAL_CALL ODBExportHelper::Create(const Reference< XMultiServiceFactory >& _rxORB)
103 : {
104 0 : return static_cast< XServiceInfo* >(new ODBExport(_rxORB,EXPORT_SETTINGS | EXPORT_PRETTY ));
105 : }
106 : //---------------------------------------------------------------------
107 0 : ::rtl::OUString SAL_CALL ODBExportHelper::getImplementationName_Static( ) throw (RuntimeException)
108 : {
109 0 : return ::rtl::OUString("com.sun.star.comp.sdb.XMLSettingsExporter");
110 : }
111 : //---------------------------------------------------------------------
112 0 : Sequence< ::rtl::OUString > SAL_CALL ODBExportHelper::getSupportedServiceNames_Static( ) throw(RuntimeException)
113 : {
114 0 : Sequence< ::rtl::OUString > aSupported(1);
115 0 : aSupported[0] = ::rtl::OUString("com.sun.star.document.ExportFilter");
116 0 : return aSupported;
117 : }
118 :
119 :
120 : //---------------------------------------------------------------------
121 0 : Reference< XInterface > SAL_CALL ODBFullExportHelper::Create(const Reference< XMultiServiceFactory >& _rxORB)
122 : {
123 0 : return static_cast< XServiceInfo* >(new ODBExport(_rxORB,EXPORT_ALL));
124 : }
125 : //---------------------------------------------------------------------
126 0 : ::rtl::OUString SAL_CALL ODBFullExportHelper::getImplementationName_Static( ) throw (RuntimeException)
127 : {
128 0 : return ::rtl::OUString("com.sun.star.comp.sdb.XMLFullExporter");
129 : }
130 : //---------------------------------------------------------------------
131 0 : Sequence< ::rtl::OUString > SAL_CALL ODBFullExportHelper::getSupportedServiceNames_Static( ) throw(RuntimeException)
132 : {
133 0 : Sequence< ::rtl::OUString > aSupported(1);
134 0 : aSupported[0] = ::rtl::OUString("com.sun.star.document.ExportFilter");
135 0 : return aSupported;
136 : }
137 :
138 : //---------------------------------------------------------------------
139 0 : ::rtl::OUString lcl_implGetPropertyXMLType(const Type& _rType)
140 : {
141 : // possible types we can write (either because we recognize them directly or because we convert _rValue
142 : // into one of these types)
143 0 : static const ::rtl::OUString s_sTypeBoolean ("boolean");
144 0 : static const ::rtl::OUString s_sTypeShort ("short");
145 0 : static const ::rtl::OUString s_sTypeInteger ("int");
146 0 : static const ::rtl::OUString s_sTypeLong ("long");
147 0 : static const ::rtl::OUString s_sTypeDouble ("double");
148 0 : static const ::rtl::OUString s_sTypeString ("string");
149 :
150 : // handle the type description
151 0 : switch (_rType.getTypeClass())
152 : {
153 : case TypeClass_STRING:
154 0 : return s_sTypeString;
155 : case TypeClass_DOUBLE:
156 0 : return s_sTypeDouble;
157 : case TypeClass_BOOLEAN:
158 0 : return s_sTypeBoolean;
159 : case TypeClass_BYTE:
160 : case TypeClass_SHORT:
161 0 : return s_sTypeShort;
162 : case TypeClass_LONG:
163 0 : return s_sTypeInteger;
164 : case TypeClass_HYPER:
165 0 : return s_sTypeLong;
166 : case TypeClass_ENUM:
167 0 : return s_sTypeInteger;
168 :
169 : default:
170 : OSL_FAIL( "lcl_implGetPropertyXMLType: unsupported value type!" );
171 0 : return s_sTypeDouble;
172 : }
173 : }
174 :
175 0 : class OSpecialHanldeXMLExportPropertyMapper : public SvXMLExportPropertyMapper
176 : {
177 : public:
178 0 : OSpecialHanldeXMLExportPropertyMapper(const UniReference< XMLPropertySetMapper >& rMapper) : SvXMLExportPropertyMapper(rMapper )
179 : {
180 0 : }
181 : /** this method is called for every item that has the
182 : MID_FLAG_SPECIAL_ITEM_EXPORT flag set */
183 0 : virtual void handleSpecialItem(
184 : SvXMLAttributeList& /*rAttrList*/,
185 : const XMLPropertyState& /*rProperty*/,
186 : const SvXMLUnitConverter& /*rUnitConverter*/,
187 : const SvXMLNamespaceMap& /*rNamespaceMap*/,
188 : const ::std::vector< XMLPropertyState > * /*pProperties*/ ,
189 : sal_uInt32 /*nIdx*/ ) const
190 : {
191 : // nothing to do here
192 0 : }
193 : };
194 : // -----------------------------------------------------------------------------
195 0 : ODBExport::ODBExport(const Reference< XMultiServiceFactory >& _rxMSF,sal_uInt16 nExportFlag)
196 : : SvXMLExport( util::MeasureUnit::MM_10TH, _rxMSF, XML_DATABASE,
197 : EXPORT_OASIS | nExportFlag)
198 : ,m_aTypeCollection(_rxMSF)
199 0 : ,m_bAllreadyFilled(sal_False)
200 : {
201 0 : GetMM100UnitConverter().SetCoreMeasureUnit(util::MeasureUnit::MM_10TH);
202 0 : GetMM100UnitConverter().SetXMLMeasureUnit(util::MeasureUnit::CM);
203 :
204 0 : _GetNamespaceMap().Add( GetXMLToken(XML_NP_OFFICE), GetXMLToken(XML_N_OFFICE), XML_NAMESPACE_OFFICE );
205 0 : _GetNamespaceMap().Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
206 0 : _GetNamespaceMap().Add( GetXMLToken(XML_NP_SVG), GetXMLToken(XML_N_SVG), XML_NAMESPACE_SVG );
207 :
208 0 : _GetNamespaceMap().Add( GetXMLToken(XML_NP_DB), GetXMLToken(XML_N_DB_OASIS), XML_NAMESPACE_DB );
209 :
210 0 : if( (nExportFlag & (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_FONTDECLS) ) != 0 )
211 0 : _GetNamespaceMap().Add( GetXMLToken(XML_NP_FO), GetXMLToken(XML_N_FO_COMPAT), XML_NAMESPACE_FO );
212 :
213 0 : if( (nExportFlag & (EXPORT_META|EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_SCRIPTS|EXPORT_SETTINGS) ) != 0 )
214 : {
215 0 : _GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
216 : }
217 0 : if( (nExportFlag & EXPORT_SETTINGS) != 0 )
218 : {
219 0 : _GetNamespaceMap().Add( GetXMLToken(XML_NP_CONFIG), GetXMLToken(XML_N_CONFIG), XML_NAMESPACE_CONFIG );
220 : }
221 :
222 0 : if( (nExportFlag & (EXPORT_STYLES|EXPORT_MASTERSTYLES|EXPORT_AUTOSTYLES|EXPORT_CONTENT|EXPORT_FONTDECLS) ) != 0 )
223 : {
224 0 : _GetNamespaceMap().Add( GetXMLToken(XML_NP_STYLE), GetXMLToken(XML_N_STYLE), XML_NAMESPACE_STYLE );
225 : }
226 :
227 0 : _GetNamespaceMap().Add( GetXMLToken(XML_NP_TABLE), GetXMLToken(XML_N_TABLE), XML_NAMESPACE_TABLE );
228 0 : _GetNamespaceMap().Add( GetXMLToken(XML_NP_NUMBER), GetXMLToken(XML_N_NUMBER), XML_NAMESPACE_NUMBER );
229 :
230 0 : m_xExportHelper = new SvXMLExportPropertyMapper(GetTableStylesPropertySetMapper());
231 0 : m_xColumnExportHelper = new OSpecialHanldeXMLExportPropertyMapper(GetColumnStylesPropertySetMapper());
232 :
233 0 : m_xCellExportHelper = new OSpecialHanldeXMLExportPropertyMapper(GetCellStylesPropertySetMapper());
234 0 : m_xRowExportHelper = new OSpecialHanldeXMLExportPropertyMapper(OXMLHelper::GetRowStylesPropertySetMapper());
235 :
236 : GetAutoStylePool()->AddFamily(
237 : XML_STYLE_FAMILY_TABLE_TABLE,
238 : rtl::OUString(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME ),
239 : m_xExportHelper.get(),
240 0 : rtl::OUString(XML_STYLE_FAMILY_TABLE_TABLE_STYLES_PREFIX ));
241 :
242 : GetAutoStylePool()->AddFamily(
243 : XML_STYLE_FAMILY_TABLE_COLUMN,
244 : rtl::OUString(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME ),
245 : m_xColumnExportHelper.get(),
246 0 : rtl::OUString(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX ));
247 :
248 : GetAutoStylePool()->AddFamily(
249 : XML_STYLE_FAMILY_TABLE_CELL,
250 : rtl::OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME ),
251 : m_xCellExportHelper.get(),
252 0 : rtl::OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX ));
253 :
254 : GetAutoStylePool()->AddFamily(
255 : XML_STYLE_FAMILY_TABLE_ROW,
256 : rtl::OUString(XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME ),
257 : m_xRowExportHelper.get(),
258 0 : rtl::OUString(XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX ));
259 0 : }
260 : // -----------------------------------------------------------------------------
261 0 : IMPLEMENT_SERVICE_INFO1_STATIC( ODBExport, "com.sun.star.comp.sdb.DBExportFilter", "com.sun.star.document.ExportFilter")
262 : // -----------------------------------------------------------------------------
263 0 : void ODBExport::exportDataSource()
264 : {
265 : try
266 : {
267 0 : Reference<XPropertySet> xProp( getDataSource(), UNO_SET_THROW );
268 :
269 0 : sal_Bool bAutoIncrementEnabled = sal_True;
270 0 : TStringPair aAutoIncrement;
271 :
272 0 : Reference< XPropertySet > xDataSourceSettings;
273 0 : OSL_VERIFY( xProp->getPropertyValue( PROPERTY_SETTINGS ) >>= xDataSourceSettings );
274 0 : Reference< XPropertyState > xSettingsState( xDataSourceSettings, UNO_QUERY_THROW );
275 0 : Reference< XPropertySetInfo > xSettingsInfo( xDataSourceSettings->getPropertySetInfo(), UNO_SET_THROW );
276 :
277 0 : TDelimiter aDelimiter;
278 0 : xSettingsState->getPropertyDefault( INFO_TEXTDELIMITER ) >>= aDelimiter.sText;
279 0 : xSettingsState->getPropertyDefault( INFO_FIELDDELIMITER ) >>= aDelimiter.sField;
280 0 : xSettingsState->getPropertyDefault( INFO_DECIMALDELIMITER ) >>= aDelimiter.sDecimal;
281 0 : xSettingsState->getPropertyDefault( INFO_THOUSANDSDELIMITER ) >>= aDelimiter.sThousand;
282 :
283 0 : ::connectivity::DriversConfig aDriverConfig(getServiceFactory());
284 0 : const ::rtl::OUString sURL = ::comphelper::getString(xProp->getPropertyValue(PROPERTY_URL));
285 0 : ::comphelper::NamedValueCollection aDriverSupportedProperties( aDriverConfig.getProperties( sURL ) );
286 :
287 0 : static ::rtl::OUString s_sTrue(::xmloff::token::GetXMLToken( XML_TRUE ));
288 0 : static ::rtl::OUString s_sFalse(::xmloff::token::GetXMLToken( XML_FALSE ));
289 : // loop through the properties, and export only those which are not defaulted
290 0 : TSettingsMap aSettingsMap;
291 0 : Sequence< Property > aProperties = xSettingsInfo->getProperties();
292 0 : const Property* pProperties = aProperties.getConstArray();
293 0 : const Property* pPropertiesEnd = pProperties + aProperties.getLength();
294 0 : for ( ; pProperties != pPropertiesEnd; ++pProperties )
295 : {
296 0 : ::rtl::OUString sValue;
297 0 : Any aValue = xDataSourceSettings->getPropertyValue( pProperties->Name );
298 0 : switch ( aValue.getValueTypeClass() )
299 : {
300 : case TypeClass_STRING:
301 0 : aValue >>= sValue;
302 0 : break;
303 : case TypeClass_DOUBLE:
304 : // let the unit converter format is as string
305 0 : sValue = ::rtl::OUString::valueOf( getDouble( aValue ) );
306 0 : break;
307 : case TypeClass_BOOLEAN:
308 0 : sValue = ::xmloff::token::GetXMLToken( getBOOL( aValue ) ? XML_TRUE : XML_FALSE );
309 0 : break;
310 : case TypeClass_BYTE:
311 : case TypeClass_SHORT:
312 : case TypeClass_LONG:
313 : // let the unit converter format is as string
314 0 : sValue = ::rtl::OUString::valueOf( getINT32( aValue ) );
315 0 : break;
316 : default:
317 0 : break;
318 : }
319 :
320 0 : ::xmloff::token::XMLTokenEnum eToken = XML_TOKEN_INVALID;
321 :
322 0 : struct PropertyMap
323 : {
324 : const ::rtl::OUString sPropertyName;
325 : const XMLTokenEnum eAttributeToken;
326 : const ::boost::optional< ::rtl::OUString > aXMLDefault;
327 :
328 0 : PropertyMap( const ::rtl::OUString& _rPropertyName, const XMLTokenEnum _eToken )
329 : :sPropertyName( _rPropertyName )
330 : ,eAttributeToken( _eToken )
331 0 : ,aXMLDefault()
332 : {
333 0 : }
334 :
335 0 : PropertyMap( const ::rtl::OUString& _rPropertyName, const XMLTokenEnum _eToken, const ::rtl::OUString& _rDefault )
336 : :sPropertyName( _rPropertyName )
337 : ,eAttributeToken( _eToken )
338 0 : ,aXMLDefault( _rDefault )
339 : {
340 0 : }
341 : };
342 :
343 : PropertyMap aTokens[] =
344 : {
345 : PropertyMap( INFO_TEXTFILEHEADER, XML_IS_FIRST_ROW_HEADER_LINE, s_sTrue ),
346 : PropertyMap( INFO_SHOWDELETEDROWS, XML_SHOW_DELETED, s_sFalse ),
347 : PropertyMap( INFO_ALLOWLONGTABLENAMES, XML_IS_TABLE_NAME_LENGTH_LIMITED, s_sTrue ),
348 : PropertyMap( INFO_ADDITIONALOPTIONS, XML_SYSTEM_DRIVER_SETTINGS ),
349 : PropertyMap( PROPERTY_ENABLESQL92CHECK, XML_ENABLE_SQL92_CHECK, s_sFalse ),
350 : PropertyMap( INFO_APPEND_TABLE_ALIAS, XML_APPEND_TABLE_ALIAS_NAME, s_sTrue ),
351 : PropertyMap( INFO_PARAMETERNAMESUBST, XML_PARAMETER_NAME_SUBSTITUTION, s_sTrue ),
352 : PropertyMap( INFO_IGNOREDRIVER_PRIV, XML_IGNORE_DRIVER_PRIVILEGES, s_sTrue ),
353 : PropertyMap( INFO_USECATALOG, XML_USE_CATALOG, s_sFalse ),
354 : PropertyMap( PROPERTY_SUPPRESSVERSIONCL,XML_SUPPRESS_VERSION_COLUMNS, s_sTrue ),
355 : PropertyMap( INFO_CONN_LDAP_BASEDN, XML_BASE_DN ),
356 : PropertyMap( INFO_CONN_LDAP_ROWCOUNT, XML_MAX_ROW_COUNT )
357 0 : };
358 :
359 0 : bool bIsXMLDefault = false;
360 0 : for ( size_t i=0; i < sizeof( aTokens ) / sizeof( aTokens[0] ); ++i )
361 : {
362 0 : if ( pProperties->Name == aTokens[i].sPropertyName )
363 : {
364 0 : eToken = aTokens[i].eAttributeToken;
365 :
366 0 : if ( !!aTokens[i].aXMLDefault
367 0 : && ( sValue == *aTokens[i].aXMLDefault )
368 : )
369 : {
370 0 : bIsXMLDefault = true;
371 : }
372 0 : break;
373 : }
374 : }
375 :
376 0 : if ( bIsXMLDefault )
377 : // the property has the value which is specified as default in the XML schema -> no need to write it
378 0 : continue;
379 :
380 0 : if ( eToken == XML_TOKEN_INVALID )
381 : {
382 : // for properties which are not REMOVEABLE, we care for their state, and
383 : // only export them if they're not DEFAULTed
384 0 : if ( ( pProperties->Attributes & PropertyAttribute::REMOVEABLE ) == 0 )
385 : {
386 0 : PropertyState ePropertyState = xSettingsState->getPropertyState( pProperties->Name );
387 0 : if ( PropertyState_DEFAULT_VALUE == ePropertyState )
388 0 : continue;
389 : }
390 :
391 : // special handlings
392 0 : if ( pProperties->Name == PROPERTY_BOOLEANCOMPARISONMODE )
393 : {
394 0 : sal_Int32 nValue = 0;
395 0 : aValue >>= nValue;
396 0 : if ( sValue == "0" )
397 0 : sValue = ::rtl::OUString("equal-integer");
398 0 : else if ( sValue == "1" )
399 0 : sValue = ::rtl::OUString("is-boolean");
400 0 : else if ( sValue == "2" )
401 0 : sValue = ::rtl::OUString("equal-boolean");
402 0 : else if ( sValue == "3" )
403 0 : sValue = ::rtl::OUString("equal-use-only-zero");
404 0 : if ( sValue == "equal-integer" )
405 0 : continue;
406 0 : eToken = XML_BOOLEAN_COMPARISON_MODE;
407 : }
408 0 : else if ( pProperties->Name == INFO_AUTORETRIEVEENABLED )
409 : {
410 0 : aValue >>= bAutoIncrementEnabled;
411 0 : continue;
412 : }
413 0 : else if ( pProperties->Name == INFO_AUTORETRIEVEVALUE )
414 : {
415 0 : aAutoIncrement.first = sValue;
416 0 : continue;
417 : }
418 0 : else if ( pProperties->Name == PROPERTY_AUTOINCREMENTCREATION )
419 : {
420 0 : aAutoIncrement.second = sValue;
421 0 : continue;
422 : }
423 0 : else if ( pProperties->Name == INFO_TEXTDELIMITER )
424 : {
425 0 : aDelimiter.sText = sValue;
426 0 : aDelimiter.bUsed = true;
427 0 : continue;
428 : }
429 0 : else if ( pProperties->Name == INFO_FIELDDELIMITER )
430 : {
431 0 : aDelimiter.sField = sValue;
432 0 : aDelimiter.bUsed = true;
433 0 : continue;
434 : }
435 0 : else if ( pProperties->Name == INFO_DECIMALDELIMITER )
436 : {
437 0 : aDelimiter.sDecimal = sValue;
438 0 : aDelimiter.bUsed = true;
439 0 : continue;
440 : }
441 0 : else if ( pProperties->Name == INFO_THOUSANDSDELIMITER )
442 : {
443 0 : aDelimiter.sThousand = sValue;
444 0 : aDelimiter.bUsed = true;
445 0 : continue;
446 : }
447 0 : else if ( pProperties->Name == INFO_CHARSET )
448 : {
449 0 : m_sCharSet = sValue;
450 0 : continue;
451 : }
452 : else
453 : {
454 0 : if ( !aDriverSupportedProperties.has(pProperties->Name) || aDriverSupportedProperties.get(pProperties->Name) != aValue )
455 : {
456 : m_aDataSourceSettings.push_back( TypedPropertyValue(
457 0 : pProperties->Name, pProperties->Type, aValue ) );
458 : }
459 0 : continue;
460 : }
461 : }
462 :
463 0 : aSettingsMap.insert(TSettingsMap::value_type(eToken,sValue));
464 0 : }
465 0 : if ( bAutoIncrementEnabled && !(aAutoIncrement.first.isEmpty() && aAutoIncrement.second.isEmpty()) )
466 0 : m_aAutoIncrement.reset( new TStringPair(aAutoIncrement));
467 0 : if ( aDelimiter.bUsed )
468 0 : m_aDelimiter.reset( new TDelimiter( aDelimiter ) );
469 :
470 0 : SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_DATASOURCE, sal_True, sal_True);
471 :
472 0 : exportConnectionData();
473 0 : exportDriverSettings(aSettingsMap);
474 0 : exportApplicationConnectionSettings(aSettingsMap);
475 : }
476 0 : catch( const Exception& )
477 : {
478 : DBG_UNHANDLED_EXCEPTION();
479 : }
480 0 : }
481 : // -----------------------------------------------------------------------------
482 0 : void ODBExport::exportApplicationConnectionSettings(const TSettingsMap& _aSettings)
483 : {
484 : const ::xmloff::token::XMLTokenEnum pSettings[] = {
485 : XML_IS_TABLE_NAME_LENGTH_LIMITED
486 : ,XML_ENABLE_SQL92_CHECK
487 : ,XML_APPEND_TABLE_ALIAS_NAME
488 : ,XML_IGNORE_DRIVER_PRIVILEGES
489 : ,XML_BOOLEAN_COMPARISON_MODE
490 : ,XML_USE_CATALOG
491 : ,XML_MAX_ROW_COUNT
492 : ,XML_SUPPRESS_VERSION_COLUMNS
493 0 : };
494 0 : for (size_t i = 0; i< sizeof(pSettings)/sizeof(pSettings[0]); ++i)
495 : {
496 0 : TSettingsMap::const_iterator aFind = _aSettings.find(pSettings[i]);
497 0 : if ( aFind != _aSettings.end() )
498 0 : AddAttribute(XML_NAMESPACE_DB, aFind->first,aFind->second);
499 : }
500 0 : SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_APPLICATION_CONNECTION_SETTINGS, sal_True, sal_True);
501 :
502 0 : Reference<XPropertySet> xProp(getDataSource());
503 0 : Sequence< ::rtl::OUString> aValue;
504 0 : xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= aValue;
505 0 : if ( aValue.getLength() )
506 : {
507 0 : SvXMLElementExport aElem2(*this,XML_NAMESPACE_DB, XML_TABLE_FILTER, sal_True, sal_True);
508 0 : exportSequence(aValue,XML_TABLE_INCLUDE_FILTER,XML_TABLE_FILTER_PATTERN);
509 : }
510 :
511 0 : xProp->getPropertyValue(PROPERTY_TABLETYPEFILTER) >>= aValue;
512 0 : if ( aValue.getLength() )
513 0 : exportSequence(aValue,XML_TABLE_TYPE_FILTER,XML_TABLE_TYPE);
514 :
515 0 : exportDataSourceSettings();
516 0 : }
517 : // -----------------------------------------------------------------------------
518 0 : void ODBExport::exportDriverSettings(const TSettingsMap& _aSettings)
519 : {
520 : const ::xmloff::token::XMLTokenEnum pSettings[] = {
521 : XML_SHOW_DELETED
522 : ,XML_SYSTEM_DRIVER_SETTINGS
523 : ,XML_BASE_DN
524 : ,XML_IS_FIRST_ROW_HEADER_LINE
525 : ,XML_PARAMETER_NAME_SUBSTITUTION
526 0 : };
527 0 : for (size_t i = 0; i< sizeof(pSettings)/sizeof(pSettings[0]); ++i)
528 : {
529 0 : TSettingsMap::const_iterator aFind = _aSettings.find(pSettings[i]);
530 0 : if ( aFind != _aSettings.end() )
531 0 : AddAttribute(XML_NAMESPACE_DB, aFind->first,aFind->second);
532 : }
533 0 : SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_DRIVER_SETTINGS, sal_True, sal_True);
534 0 : exportAutoIncrement();
535 0 : exportDelimiter();
536 0 : exportCharSet();
537 0 : }
538 : // -----------------------------------------------------------------------------
539 0 : void ODBExport::exportConnectionData()
540 : {
541 0 : SvXMLElementExport aConnData(*this,XML_NAMESPACE_DB, XML_CONNECTION_DATA, sal_True, sal_True);
542 :
543 : {
544 0 : ::rtl::OUString sValue;
545 0 : Reference<XPropertySet> xProp(getDataSource());
546 0 : xProp->getPropertyValue(PROPERTY_URL) >>= sValue;
547 0 : if ( m_aTypeCollection.isFileSystemBased(sValue) )
548 : {
549 0 : SvXMLElementExport aDatabaseDescription(*this,XML_NAMESPACE_DB, XML_DATABASE_DESCRIPTION, sal_True, sal_True);
550 : {
551 0 : SvtPathOptions aPathOptions;
552 0 : const String sOrigUrl = m_aTypeCollection.cutPrefix(sValue);
553 0 : String sFileName = aPathOptions.SubstituteVariable(sOrigUrl);
554 0 : if ( sOrigUrl == sFileName )
555 : {
556 0 : ::svt::OFileNotation aTransformer( sFileName );
557 0 : ::rtl::OUStringBuffer sURL( aTransformer.get( ::svt::OFileNotation::N_URL ) );
558 0 : if (sURL.getLength() == 0 || sURL[sURL.getLength() - 1] != '/')
559 0 : sURL.append('/');
560 :
561 0 : AddAttribute(XML_NAMESPACE_XLINK,XML_HREF,GetRelativeReference(sURL.makeStringAndClear()));
562 : }
563 : else
564 0 : AddAttribute(XML_NAMESPACE_XLINK,XML_HREF,sOrigUrl);
565 0 : AddAttribute(XML_NAMESPACE_DB,XML_MEDIA_TYPE,m_aTypeCollection.getMediaType(sValue));
566 0 : const ::dbaccess::DATASOURCE_TYPE eType = m_aTypeCollection.determineType(sValue);
567 : try
568 : {
569 0 : ::rtl::OUString sExtension;
570 0 : if ( eType == dbaccess::DST_MSACCESS )
571 0 : sExtension = ::rtl::OUString("mdb");
572 : else
573 : {
574 0 : Reference< XPropertySet > xDataSourceSettings;
575 0 : OSL_VERIFY( xProp->getPropertyValue( PROPERTY_SETTINGS ) >>= xDataSourceSettings );
576 0 : xDataSourceSettings->getPropertyValue( INFO_TEXTFILEEXTENSION ) >>= sExtension;
577 : }
578 0 : if ( !sExtension.isEmpty() )
579 0 : AddAttribute(XML_NAMESPACE_DB,XML_EXTENSION,sExtension);
580 : }
581 0 : catch(const Exception&)
582 : {
583 : }
584 0 : SvXMLElementExport aFileBasedDB(*this,XML_NAMESPACE_DB, XML_FILE_BASED_DATABASE, sal_True, sal_True);
585 0 : }
586 : }
587 : else
588 : {
589 0 : String sDatabaseName,sHostName;
590 0 : sal_Int32 nPort = -1;
591 0 : m_aTypeCollection.extractHostNamePort(sValue,sDatabaseName,sHostName,nPort);
592 0 : if ( sHostName.Len() )
593 : {
594 0 : SvXMLElementExport aDatabaseDescription(*this,XML_NAMESPACE_DB, XML_DATABASE_DESCRIPTION, sal_True, sal_True);
595 : {
596 0 : String sType = comphelper::string::stripEnd(m_aTypeCollection.getPrefix(sValue), ':');
597 0 : AddAttribute(XML_NAMESPACE_DB,XML_TYPE,sType);
598 0 : AddAttribute(XML_NAMESPACE_DB,XML_HOSTNAME,sHostName);
599 0 : if ( nPort != -1 )
600 0 : AddAttribute(XML_NAMESPACE_DB,XML_PORT,::rtl::OUString::valueOf(nPort));
601 0 : if ( sDatabaseName.Len() )
602 0 : AddAttribute(XML_NAMESPACE_DB,XML_DATABASE_NAME,sDatabaseName);
603 :
604 : try
605 : {
606 0 : Reference< XPropertySet > xDataSourceSettings( xProp->getPropertyValue( PROPERTY_SETTINGS ), UNO_QUERY_THROW );
607 0 : Reference< XPropertySetInfo > xSettingsInfo( xDataSourceSettings->getPropertySetInfo(), UNO_SET_THROW );
608 :
609 : struct PropertyMap
610 : {
611 : const sal_Char* pAsciiPropertyName;
612 : sal_uInt16 nAttributeId;
613 :
614 : PropertyMap() :pAsciiPropertyName( NULL ), nAttributeId(0) { }
615 0 : PropertyMap( const sal_Char* _pAsciiPropertyName, const sal_uInt16 _nAttributeId )
616 : :pAsciiPropertyName( _pAsciiPropertyName )
617 0 : ,nAttributeId( _nAttributeId )
618 : {
619 0 : }
620 : };
621 : PropertyMap aProperties[] =
622 : {
623 : PropertyMap( "LocalSocket", XML_LOCAL_SOCKET )
624 : //PropertyMap( "NamedPipe", 0 /* TODO */ )
625 0 : };
626 :
627 0 : for ( size_t i=0;
628 : i < sizeof( aProperties ) / sizeof( aProperties[0] );
629 : ++i
630 : )
631 : {
632 0 : const ::rtl::OUString sPropertyName = ::rtl::OUString::createFromAscii( aProperties[i].pAsciiPropertyName );
633 0 : if ( xSettingsInfo->hasPropertyByName( sPropertyName ) )
634 : {
635 0 : ::rtl::OUString sPropertyValue;
636 0 : if ( ( xDataSourceSettings->getPropertyValue( sPropertyName ) >>= sPropertyValue ) && !sPropertyValue.isEmpty() )
637 0 : AddAttribute( XML_NAMESPACE_DB, XML_LOCAL_SOCKET, sPropertyValue );
638 :
639 : }
640 0 : }
641 : }
642 0 : catch( const Exception& )
643 : {
644 : DBG_UNHANDLED_EXCEPTION();
645 : }
646 :
647 0 : SvXMLElementExport aServerDB(*this,XML_NAMESPACE_DB, XML_SERVER_DATABASE, sal_True, sal_True);
648 0 : }
649 : }
650 : else
651 : {
652 0 : AddAttribute(XML_NAMESPACE_XLINK, XML_HREF,sValue);
653 0 : SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_CONNECTION_RESOURCE, sal_True, sal_True);
654 0 : }
655 0 : }
656 :
657 : }
658 :
659 0 : exportLogin();
660 0 : }
661 : // -----------------------------------------------------------------------------
662 0 : template< typename T > void ODBExport::exportDataSourceSettingsSequence(
663 : ::std::vector< TypedPropertyValue >::iterator const & in)
664 : {
665 0 : OSequenceIterator< T > i( in->Value );
666 0 : while (i.hasMoreElements())
667 : {
668 0 : SvXMLElementExport aDataValue(*this,XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_VALUE, sal_True, sal_False);
669 : // (no whitespace inside the tag)
670 0 : Characters(implConvertAny(i.nextElement()));
671 : }
672 0 : }
673 :
674 0 : void ODBExport::exportDataSourceSettings()
675 : {
676 0 : if ( m_aDataSourceSettings.empty() )
677 0 : return;
678 :
679 0 : SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTINGS, sal_True, sal_True);
680 0 : ::std::vector< TypedPropertyValue >::iterator aIter = m_aDataSourceSettings.begin();
681 0 : ::std::vector< TypedPropertyValue >::iterator aEnd = m_aDataSourceSettings.end();
682 0 : for ( ; aIter != aEnd; ++aIter )
683 : {
684 0 : sal_Bool bIsSequence = TypeClass_SEQUENCE == aIter->Type.getTypeClass();
685 :
686 0 : Type aSimpleType;
687 0 : if ( bIsSequence )
688 0 : aSimpleType = ::comphelper::getSequenceElementType( aIter->Value.getValueType() );
689 : else
690 0 : aSimpleType = aIter->Type;
691 :
692 0 : AddAttribute( XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_IS_LIST,bIsSequence ? XML_TRUE : XML_FALSE );
693 0 : AddAttribute( XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_NAME, aIter->Name );
694 :
695 0 : ::rtl::OUString sTypeName = lcl_implGetPropertyXMLType( aSimpleType );
696 0 : if ( bIsSequence && aSimpleType.getTypeClass() == TypeClass_ANY )
697 : {
698 0 : Sequence<Any> aSeq;
699 0 : aIter->Value >>= aSeq;
700 0 : if ( aSeq.getLength() )
701 0 : sTypeName = lcl_implGetPropertyXMLType(aSeq[0].getValueType());
702 : }
703 :
704 0 : AddAttribute( XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_TYPE, sTypeName );
705 :
706 0 : SvXMLElementExport aDataSourceSetting( *this, XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING, sal_True, sal_True );
707 :
708 0 : if ( !bIsSequence )
709 : {
710 0 : SvXMLElementExport aDataValue( *this, XML_NAMESPACE_DB, XML_DATA_SOURCE_SETTING_VALUE, sal_True, sal_False );
711 : // (no whitespace inside the tag)
712 0 : Characters( implConvertAny( aIter->Value ) );
713 : }
714 : else
715 : {
716 : // the not-that-simple case, we need to iterate through the sequence elements
717 0 : switch (aSimpleType.getTypeClass())
718 : {
719 : case TypeClass_STRING:
720 : exportDataSourceSettingsSequence< ::rtl::OUString >(
721 0 : aIter );
722 0 : break;
723 : case TypeClass_DOUBLE:
724 0 : exportDataSourceSettingsSequence< double >( aIter );
725 0 : break;
726 : case TypeClass_BOOLEAN:
727 0 : exportDataSourceSettingsSequence< sal_Bool >( aIter );
728 0 : break;
729 : case TypeClass_BYTE:
730 0 : exportDataSourceSettingsSequence< sal_Int8 >( aIter );
731 0 : break;
732 : case TypeClass_SHORT:
733 0 : exportDataSourceSettingsSequence< sal_Int16 >( aIter );
734 0 : break;
735 : case TypeClass_LONG:
736 0 : exportDataSourceSettingsSequence< sal_Int32 >( aIter );
737 0 : break;
738 : case TypeClass_ANY:
739 0 : exportDataSourceSettingsSequence< Any >( aIter );
740 0 : break;
741 : default:
742 : OSL_FAIL("unsupported sequence type !");
743 0 : break;
744 : }
745 : }
746 0 : }
747 : }
748 : // -----------------------------------------------------------------------------
749 0 : void ODBExport::exportCharSet()
750 : {
751 0 : if ( !m_sCharSet.isEmpty() )
752 : {
753 0 : AddAttribute(XML_NAMESPACE_DB, XML_ENCODING,m_sCharSet);
754 :
755 0 : SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_FONT_CHARSET, sal_True, sal_True);
756 : }
757 0 : }
758 : // -----------------------------------------------------------------------------
759 0 : void ODBExport::exportDelimiter()
760 : {
761 0 : if ( m_aDelimiter.get() && m_aDelimiter->bUsed )
762 : {
763 0 : AddAttribute(XML_NAMESPACE_DB, XML_FIELD,m_aDelimiter->sField);
764 0 : AddAttribute(XML_NAMESPACE_DB, XML_STRING,m_aDelimiter->sText);
765 0 : AddAttribute(XML_NAMESPACE_DB, XML_DECIMAL,m_aDelimiter->sDecimal);
766 0 : AddAttribute(XML_NAMESPACE_DB, XML_THOUSAND,m_aDelimiter->sThousand);
767 0 : SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_DELIMITER, sal_True, sal_True);
768 : }
769 0 : }
770 : // -----------------------------------------------------------------------------
771 0 : void ODBExport::exportAutoIncrement()
772 : {
773 0 : if ( m_aAutoIncrement.get() )
774 : {
775 0 : AddAttribute(XML_NAMESPACE_DB, XML_ADDITIONAL_COLUMN_STATEMENT,m_aAutoIncrement->second);
776 0 : AddAttribute(XML_NAMESPACE_DB, XML_ROW_RETRIEVING_STATEMENT,m_aAutoIncrement->first);
777 0 : SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_AUTO_INCREMENT, sal_True, sal_True);
778 : }
779 0 : }
780 : // -----------------------------------------------------------------------------
781 0 : void ODBExport::exportSequence(const Sequence< ::rtl::OUString>& _aValue
782 : ,::xmloff::token::XMLTokenEnum _eTokenFilter
783 : ,::xmloff::token::XMLTokenEnum _eTokenType)
784 : {
785 0 : Reference<XPropertySet> xProp(getDataSource());
786 0 : Sequence< ::rtl::OUString> aValue;
787 0 : if ( _aValue.getLength() )
788 : {
789 0 : SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, _eTokenFilter, sal_True, sal_True);
790 :
791 0 : const ::rtl::OUString* pIter = _aValue.getConstArray();
792 0 : const ::rtl::OUString* pEnd = pIter + _aValue.getLength();
793 0 : for(;pIter != pEnd;++pIter)
794 : {
795 0 : SvXMLElementExport aDataSource(*this,XML_NAMESPACE_DB, _eTokenType, sal_True, sal_False);
796 0 : Characters(*pIter);
797 0 : }
798 0 : }
799 0 : }
800 : // -----------------------------------------------------------------------------
801 0 : void ODBExport::exportLogin()
802 : {
803 0 : Reference<XPropertySet> xProp(getDataSource());
804 0 : ::rtl::OUString sValue;
805 0 : xProp->getPropertyValue(PROPERTY_USER) >>= sValue;
806 0 : sal_Bool bAddLogin = !sValue.isEmpty();
807 0 : if ( bAddLogin )
808 0 : AddAttribute(XML_NAMESPACE_DB, XML_USER_NAME,sValue);
809 0 : sal_Bool bValue = sal_False;
810 0 : if ( xProp->getPropertyValue(PROPERTY_ISPASSWORDREQUIRED) >>= bValue )
811 : {
812 0 : bAddLogin = sal_True;
813 0 : AddAttribute(XML_NAMESPACE_DB, XML_IS_PASSWORD_REQUIRED,bValue ? XML_TRUE : XML_FALSE);
814 : }
815 0 : if ( bAddLogin )
816 0 : SvXMLElementExport aElem(*this,XML_NAMESPACE_DB, XML_LOGIN, sal_True, sal_True);
817 0 : }
818 : // -----------------------------------------------------------------------------
819 0 : void ODBExport::exportCollection(const Reference< XNameAccess >& _xCollection
820 : ,enum ::xmloff::token::XMLTokenEnum _eComponents
821 : ,enum ::xmloff::token::XMLTokenEnum _eSubComponents
822 : ,sal_Bool _bExportContext
823 : ,const ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >& _aMemFunc
824 : )
825 : {
826 0 : if ( _xCollection.is() )
827 : {
828 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
829 0 : ::std::auto_ptr<SvXMLElementExport> pComponents;
830 : SAL_WNODEPRECATED_DECLARATIONS_POP
831 0 : if ( _bExportContext )
832 0 : pComponents.reset( new SvXMLElementExport(*this,XML_NAMESPACE_DB, _eComponents, sal_True, sal_True));
833 0 : Sequence< ::rtl::OUString> aSeq = _xCollection->getElementNames();
834 0 : const ::rtl::OUString* pIter = aSeq.getConstArray();
835 0 : const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
836 0 : for(;pIter != pEnd;++pIter)
837 : {
838 0 : Reference<XPropertySet> xProp(_xCollection->getByName(*pIter),UNO_QUERY);
839 0 : if ( _bExportContext && XML_TABLE_REPRESENTATIONS != _eComponents )
840 0 : AddAttribute(XML_NAMESPACE_DB, XML_NAME,*pIter);
841 0 : Reference< XNameAccess > xSub(xProp,UNO_QUERY);
842 0 : if ( xSub.is() )
843 : {
844 0 : exportCollection(xSub,_eSubComponents,_eSubComponents,_bExportContext,_aMemFunc);
845 : }
846 0 : else if ( xProp.is() )
847 0 : _aMemFunc(this,xProp.get());
848 0 : }
849 : }
850 0 : }
851 : // -----------------------------------------------------------------------------
852 0 : void ODBExport::exportComponent(XPropertySet* _xProp)
853 : {
854 0 : ::rtl::OUString sValue;
855 0 : _xProp->getPropertyValue(PROPERTY_PERSISTENT_NAME) >>= sValue;
856 0 : sal_Bool bIsForm = sal_True;
857 0 : _xProp->getPropertyValue(::rtl::OUString("IsForm")) >>= bIsForm;
858 0 : if ( bIsForm )
859 0 : sValue = ::rtl::OUString("forms/") + sValue;
860 : else
861 0 : sValue = ::rtl::OUString("reports/") + sValue;
862 :
863 0 : AddAttribute(XML_NAMESPACE_XLINK, XML_HREF,sValue);
864 0 : sal_Bool bAsTemplate = sal_False;
865 0 : _xProp->getPropertyValue(PROPERTY_AS_TEMPLATE) >>= bAsTemplate;
866 0 : AddAttribute(XML_NAMESPACE_DB, XML_AS_TEMPLATE,bAsTemplate ? XML_TRUE : XML_FALSE);
867 0 : SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_COMPONENT, sal_True, sal_True);
868 0 : }
869 : // -----------------------------------------------------------------------------
870 0 : void ODBExport::exportQuery(XPropertySet* _xProp)
871 : {
872 0 : AddAttribute(XML_NAMESPACE_DB, XML_COMMAND,getString(_xProp->getPropertyValue(PROPERTY_COMMAND)));
873 :
874 0 : if ( getBOOL(_xProp->getPropertyValue(PROPERTY_APPLYFILTER)) )
875 0 : AddAttribute(XML_NAMESPACE_DB, XML_APPLY_FILTER,XML_TRUE);
876 :
877 0 : if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER)
878 0 : && getBOOL(_xProp->getPropertyValue(PROPERTY_APPLYORDER)) )
879 0 : AddAttribute(XML_NAMESPACE_DB, XML_APPLY_ORDER,XML_TRUE);
880 :
881 0 : if ( ! getBOOL(_xProp->getPropertyValue(PROPERTY_ESCAPE_PROCESSING)) )
882 0 : AddAttribute(XML_NAMESPACE_DB, XML_ESCAPE_PROCESSING,XML_FALSE);
883 :
884 0 : exportStyleName(_xProp,GetAttrList());
885 :
886 0 : SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_QUERY, sal_True, sal_True);
887 0 : Reference<XColumnsSupplier> xCol(_xProp,UNO_QUERY);
888 0 : exportColumns(xCol);
889 0 : exportFilter(_xProp,PROPERTY_FILTER,XML_FILTER_STATEMENT);
890 0 : exportFilter(_xProp,PROPERTY_ORDER,XML_ORDER_STATEMENT);
891 0 : exportTableName(_xProp,sal_True);
892 0 : }
893 : // -----------------------------------------------------------------------------
894 0 : void ODBExport::exportTable(XPropertySet* _xProp)
895 : {
896 0 : exportTableName(_xProp,sal_False);
897 :
898 0 : if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_DESCRIPTION) )
899 0 : AddAttribute(XML_NAMESPACE_DB, XML_DESCRIPTION,getString(_xProp->getPropertyValue(PROPERTY_DESCRIPTION)));
900 :
901 0 : if ( getBOOL(_xProp->getPropertyValue(PROPERTY_APPLYFILTER)) )
902 0 : AddAttribute(XML_NAMESPACE_DB, XML_APPLY_FILTER,XML_TRUE);
903 :
904 0 : if ( _xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_APPLYORDER)
905 0 : && getBOOL(_xProp->getPropertyValue(PROPERTY_APPLYORDER)) )
906 0 : AddAttribute(XML_NAMESPACE_DB, XML_APPLY_ORDER,XML_TRUE);
907 :
908 0 : exportStyleName(_xProp,GetAttrList());
909 :
910 0 : SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_TABLE_REPRESENTATION, sal_True, sal_True);
911 0 : Reference<XColumnsSupplier> xCol(_xProp,UNO_QUERY);
912 0 : exportColumns(xCol);
913 0 : exportFilter(_xProp,PROPERTY_FILTER,XML_FILTER_STATEMENT);
914 0 : exportFilter(_xProp,PROPERTY_ORDER,XML_ORDER_STATEMENT);
915 0 : }
916 : // -----------------------------------------------------------------------------
917 0 : void ODBExport::exportStyleName(XPropertySet* _xProp,SvXMLAttributeList& _rAtt)
918 : {
919 0 : Reference<XPropertySet> xFind(_xProp);
920 0 : exportStyleName(XML_STYLE_NAME,xFind,_rAtt,m_aAutoStyleNames);
921 0 : exportStyleName(XML_DEFAULT_CELL_STYLE_NAME,xFind,_rAtt,m_aCellAutoStyleNames);
922 0 : exportStyleName(XML_DEFAULT_ROW_STYLE_NAME,xFind,_rAtt,m_aRowAutoStyleNames);
923 0 : }
924 : // -----------------------------------------------------------------------------
925 0 : void ODBExport::exportStyleName(const ::xmloff::token::XMLTokenEnum _eToken,const uno::Reference<beans::XPropertySet>& _xProp,SvXMLAttributeList& _rAtt,TPropertyStyleMap& _rMap)
926 : {
927 0 : TPropertyStyleMap::iterator aFind = _rMap.find(_xProp);
928 0 : if ( aFind != _rMap.end() )
929 : {
930 0 : _rAtt.AddAttribute( GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DB, GetXMLToken(_eToken) ),
931 0 : aFind->second );
932 0 : _rMap.erase(aFind);
933 : }
934 0 : }
935 : // -----------------------------------------------------------------------------
936 0 : void ODBExport::exportTableName(XPropertySet* _xProp,sal_Bool _bUpdate)
937 : {
938 0 : ::rtl::OUString sValue;
939 0 : _xProp->getPropertyValue(_bUpdate ? PROPERTY_UPDATE_TABLENAME : PROPERTY_NAME) >>= sValue;
940 0 : if ( !sValue.isEmpty() )
941 : {
942 0 : AddAttribute(XML_NAMESPACE_DB, XML_NAME,sValue);
943 0 : _xProp->getPropertyValue(_bUpdate ? PROPERTY_UPDATE_SCHEMANAME : PROPERTY_SCHEMANAME) >>= sValue;
944 0 : if ( !sValue.isEmpty() )
945 0 : AddAttribute(XML_NAMESPACE_DB, XML_SCHEMA_NAME,sValue);
946 0 : _xProp->getPropertyValue(_bUpdate ? PROPERTY_UPDATE_CATALOGNAME : PROPERTY_CATALOGNAME) >>= sValue;
947 0 : if ( !sValue.isEmpty() )
948 0 : AddAttribute(XML_NAMESPACE_DB, XML_CATALOG_NAME,sValue);
949 :
950 0 : if ( _bUpdate )
951 : {
952 0 : SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_UPDATE_TABLE, sal_True, sal_True);
953 : }
954 0 : }
955 0 : }
956 : // -----------------------------------------------------------------------------
957 0 : void ODBExport::exportFilter(XPropertySet* _xProp
958 : ,const ::rtl::OUString& _sProp
959 : ,enum ::xmloff::token::XMLTokenEnum _eStatementType)
960 : {
961 : OSL_PRECOND(!GetAttrList().getLength(),"Invalid attribute length!");
962 0 : ::rtl::OUString sCommand;
963 0 : _xProp->getPropertyValue(_sProp) >>= sCommand;
964 0 : if ( !sCommand.isEmpty() )
965 : {
966 0 : AddAttribute(XML_NAMESPACE_DB, XML_COMMAND,sCommand);
967 0 : SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, _eStatementType, sal_True, sal_True);
968 : }
969 0 : OSL_POSTCOND(!GetAttrList().getLength(),"Invalid attribute length!");
970 0 : }
971 : // -----------------------------------------------------------------------------
972 0 : void ODBExport::exportColumns(const Reference<XColumnsSupplier>& _xColSup)
973 : {
974 : OSL_PRECOND( _xColSup.is(), "ODBExport::exportColumns: invalid columns supplier!" );
975 0 : if ( !_xColSup.is() )
976 0 : return;
977 :
978 : try
979 : {
980 0 : Reference<XNameAccess> xNameAccess( _xColSup->getColumns(), UNO_SET_THROW );
981 0 : if ( !xNameAccess->hasElements() )
982 : {
983 0 : Reference< XPropertySet > xComponent(_xColSup,UNO_QUERY);
984 0 : TTableColumnMap::iterator aFind = m_aTableDummyColumns.find(xComponent);
985 0 : if ( aFind != m_aTableDummyColumns.end() )
986 : {
987 0 : SvXMLElementExport aColumns(*this,XML_NAMESPACE_DB, XML_COLUMNS, sal_True, sal_True);
988 0 : SvXMLAttributeList* pAtt = new SvXMLAttributeList;
989 0 : Reference<XAttributeList> xAtt = pAtt;
990 0 : exportStyleName(aFind->second.get(),*pAtt);
991 0 : AddAttributeList(xAtt);
992 0 : SvXMLElementExport aColumn(*this,XML_NAMESPACE_DB, XML_COLUMN, sal_True, sal_True);
993 :
994 : }
995 0 : return;
996 : }
997 :
998 0 : SvXMLElementExport aColumns(*this,XML_NAMESPACE_DB, XML_COLUMNS, sal_True, sal_True);
999 0 : Sequence< ::rtl::OUString> aSeq = xNameAccess->getElementNames();
1000 0 : const ::rtl::OUString* pIter = aSeq.getConstArray();
1001 0 : const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
1002 0 : for( ; pIter != pEnd ; ++pIter)
1003 : {
1004 0 : Reference<XPropertySet> xProp(xNameAccess->getByName(*pIter),UNO_QUERY);
1005 0 : if ( xProp.is() )
1006 : {
1007 0 : SvXMLAttributeList* pAtt = new SvXMLAttributeList;
1008 0 : Reference<XAttributeList> xAtt = pAtt;
1009 0 : exportStyleName(xProp.get(),*pAtt);
1010 :
1011 0 : sal_Bool bHidden = getBOOL(xProp->getPropertyValue(PROPERTY_HIDDEN));
1012 :
1013 0 : ::rtl::OUString sValue;
1014 0 : xProp->getPropertyValue(PROPERTY_HELPTEXT) >>= sValue;
1015 0 : Any aColumnDefault;
1016 0 : aColumnDefault = xProp->getPropertyValue(PROPERTY_CONTROLDEFAULT);
1017 :
1018 0 : if ( bHidden || !sValue.isEmpty() || aColumnDefault.hasValue() || pAtt->getLength() )
1019 : {
1020 0 : AddAttribute(XML_NAMESPACE_DB, XML_NAME,*pIter);
1021 0 : if ( bHidden )
1022 0 : AddAttribute(XML_NAMESPACE_DB, XML_VISIBLE,XML_FALSE);
1023 :
1024 0 : if ( !sValue.isEmpty() )
1025 0 : AddAttribute(XML_NAMESPACE_DB, XML_HELP_MESSAGE,sValue);
1026 :
1027 0 : if ( aColumnDefault.hasValue() )
1028 : {
1029 0 : ::rtl::OUStringBuffer sColumnDefaultString,sType;
1030 : ::sax::Converter::convertAny(
1031 0 : sColumnDefaultString, sType, aColumnDefault );
1032 0 : AddAttribute(XML_NAMESPACE_DB, XML_TYPE_NAME,sType.makeStringAndClear());
1033 0 : AddAttribute(XML_NAMESPACE_DB, XML_DEFAULT_VALUE,sColumnDefaultString.makeStringAndClear());
1034 : }
1035 :
1036 0 : if ( pAtt->getLength() )
1037 0 : AddAttributeList(xAtt);
1038 : }
1039 :
1040 0 : if ( GetAttrList().getLength() )
1041 : {
1042 0 : SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_COLUMN, sal_True, sal_True);
1043 0 : }
1044 : }
1045 0 : }
1046 : }
1047 0 : catch( const Exception& )
1048 : {
1049 : DBG_UNHANDLED_EXCEPTION();
1050 : }
1051 : }
1052 : // -----------------------------------------------------------------------------
1053 0 : void ODBExport::exportForms()
1054 : {
1055 0 : Any aValue;
1056 0 : ::rtl::OUString sService;
1057 0 : dbtools::getDataSourceSetting(getDataSource(),"Forms",aValue);
1058 0 : aValue >>= sService;
1059 0 : if ( sService.isEmpty() )
1060 : {
1061 0 : Reference<XFormDocumentsSupplier> xSup(GetModel(),UNO_QUERY);
1062 0 : if ( xSup.is() )
1063 : {
1064 0 : Reference< XNameAccess > xCollection = xSup->getFormDocuments();
1065 0 : if ( xCollection.is() && xCollection->hasElements() )
1066 : {
1067 0 : ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportComponent);
1068 0 : exportCollection(xCollection,XML_FORMS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc);
1069 0 : }
1070 0 : }
1071 0 : }
1072 0 : }
1073 : // -----------------------------------------------------------------------------
1074 0 : void ODBExport::exportReports()
1075 : {
1076 0 : Any aValue;
1077 0 : ::rtl::OUString sService;
1078 0 : dbtools::getDataSourceSetting(getDataSource(),"Reports",aValue);
1079 0 : aValue >>= sService;
1080 0 : if ( sService.isEmpty() )
1081 : {
1082 0 : Reference<XReportDocumentsSupplier> xSup(GetModel(),UNO_QUERY);
1083 0 : if ( xSup.is() )
1084 : {
1085 0 : Reference< XNameAccess > xCollection = xSup->getReportDocuments();
1086 0 : if ( xCollection.is() && xCollection->hasElements() )
1087 : {
1088 0 : ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportComponent);
1089 0 : exportCollection(xCollection,XML_REPORTS,XML_COMPONENT_COLLECTION,sal_True,aMemFunc);
1090 0 : }
1091 0 : }
1092 0 : }
1093 0 : }
1094 : // -----------------------------------------------------------------------------
1095 0 : void ODBExport::exportQueries(sal_Bool _bExportContext)
1096 : {
1097 0 : Any aValue;
1098 0 : ::rtl::OUString sService;
1099 0 : dbtools::getDataSourceSetting(getDataSource(),"CommandDefinitions",aValue);
1100 0 : aValue >>= sService;
1101 0 : if ( sService.isEmpty() )
1102 : {
1103 0 : Reference<XQueryDefinitionsSupplier> xSup(getDataSource(),UNO_QUERY);
1104 0 : if ( xSup.is() )
1105 : {
1106 0 : Reference< XNameAccess > xCollection = xSup->getQueryDefinitions();
1107 0 : if ( xCollection.is() && xCollection->hasElements() )
1108 : {
1109 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1110 0 : ::std::auto_ptr< ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > > pMemFunc;
1111 : SAL_WNODEPRECATED_DECLARATIONS_POP
1112 0 : if ( _bExportContext )
1113 0 : pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportQuery) );
1114 : else
1115 0 : pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportAutoStyle) );
1116 :
1117 0 : exportCollection(xCollection,XML_QUERIES,XML_QUERY_COLLECTION,_bExportContext,*pMemFunc);
1118 0 : }
1119 0 : }
1120 0 : }
1121 0 : }
1122 : // -----------------------------------------------------------------------------
1123 0 : void ODBExport::exportTables(sal_Bool _bExportContext)
1124 : {
1125 0 : Reference<XTablesSupplier> xSup(getDataSource(),UNO_QUERY);
1126 0 : if ( xSup.is() )
1127 : {
1128 0 : Reference< XNameAccess > xCollection = xSup->getTables();
1129 0 : if ( xCollection.is() && xCollection->hasElements() )
1130 : {
1131 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1132 0 : ::std::auto_ptr< ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > > pMemFunc;
1133 : SAL_WNODEPRECATED_DECLARATIONS_POP
1134 0 : if ( _bExportContext )
1135 0 : pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportTable) );
1136 : else
1137 0 : pMemFunc.reset( new ::comphelper::mem_fun1_t<ODBExport,XPropertySet* >(&ODBExport::exportAutoStyle) );
1138 0 : exportCollection(xCollection,XML_TABLE_REPRESENTATIONS,XML_TOKEN_INVALID,_bExportContext,*pMemFunc);
1139 0 : }
1140 0 : }
1141 0 : }
1142 : // -----------------------------------------------------------------------------
1143 0 : void ODBExport::exportAutoStyle(XPropertySet* _xProp)
1144 : {
1145 : typedef ::std::pair<TPropertyStyleMap*,sal_uInt16> TEnumMapperPair;
1146 : typedef ::std::pair< UniReference < SvXMLExportPropertyMapper> , TEnumMapperPair> TExportPropMapperPair;
1147 0 : Reference<XColumnsSupplier> xSup(_xProp,UNO_QUERY);
1148 0 : if ( xSup.is() )
1149 : {
1150 : const TExportPropMapperPair pExportHelper[] = {
1151 : TExportPropMapperPair(m_xExportHelper,TEnumMapperPair(&m_aAutoStyleNames,XML_STYLE_FAMILY_TABLE_TABLE ))
1152 : // ,TExportPropMapperPair(m_xCellExportHelper,TEnumMapperPair(&m_aCellAutoStyleNames,XML_STYLE_FAMILY_TABLE_CELL))
1153 : ,TExportPropMapperPair(m_xRowExportHelper,TEnumMapperPair(&m_aRowAutoStyleNames,XML_STYLE_FAMILY_TABLE_ROW))
1154 0 : };
1155 :
1156 0 : ::std::vector< XMLPropertyState > aPropertyStates;
1157 0 : for (size_t i = 0 ; i < sizeof(pExportHelper)/sizeof(pExportHelper[0]); ++i)
1158 : {
1159 0 : aPropertyStates = pExportHelper[i].first->Filter(_xProp);
1160 0 : if ( !aPropertyStates.empty() )
1161 0 : pExportHelper[i].second.first->insert( TPropertyStyleMap::value_type(_xProp,GetAutoStylePool()->Add( pExportHelper[i].second.second, aPropertyStates )));
1162 : }
1163 :
1164 0 : Reference< XNameAccess > xCollection;
1165 : try
1166 : {
1167 0 : xCollection.set( xSup->getColumns(), UNO_SET_THROW );
1168 0 : awt::FontDescriptor aFont;
1169 0 : _xProp->getPropertyValue(PROPERTY_FONT) >>= aFont;
1170 0 : GetFontAutoStylePool()->Add(aFont.Name,aFont.StyleName,aFont.Family,aFont.Pitch,aFont.CharSet );
1171 :
1172 0 : m_aCurrentPropertyStates = m_xCellExportHelper->Filter(_xProp);
1173 0 : if ( !m_aCurrentPropertyStates.empty() && !xCollection->hasElements() )
1174 : {
1175 0 : Reference< XDataDescriptorFactory> xFac(xCollection,UNO_QUERY);
1176 0 : if ( xFac.is() )
1177 : {
1178 0 : Reference< XPropertySet> xColumn = xFac->createDataDescriptor();
1179 0 : m_aTableDummyColumns.insert(TTableColumnMap::value_type(Reference< XPropertySet>(_xProp),xColumn));
1180 0 : exportAutoStyle(xColumn.get());
1181 0 : }
1182 : }
1183 : else
1184 : {
1185 0 : ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportAutoStyle);
1186 0 : exportCollection(xCollection,XML_TOKEN_INVALID,XML_TOKEN_INVALID,sal_False,aMemFunc);
1187 0 : }
1188 : }
1189 0 : catch(const Exception&)
1190 : {
1191 : DBG_UNHANDLED_EXCEPTION();
1192 : }
1193 0 : m_aCurrentPropertyStates.clear();
1194 : }
1195 : else
1196 : { // here I know I have a column
1197 : TExportPropMapperPair pExportHelper[] = {
1198 : TExportPropMapperPair(m_xColumnExportHelper,TEnumMapperPair(&m_aAutoStyleNames,XML_STYLE_FAMILY_TABLE_COLUMN ))
1199 : ,TExportPropMapperPair(m_xCellExportHelper,TEnumMapperPair(&m_aCellAutoStyleNames,XML_STYLE_FAMILY_TABLE_CELL))
1200 0 : };
1201 0 : for (size_t i = 0 ; i < sizeof(pExportHelper)/sizeof(pExportHelper[0]); ++i)
1202 : {
1203 0 : ::std::vector< XMLPropertyState > aPropStates = pExportHelper[i].first->Filter( _xProp );
1204 0 : if ( !aPropStates.empty() )
1205 : {
1206 0 : ::std::vector< XMLPropertyState >::iterator aItr = aPropStates.begin();
1207 0 : ::std::vector< XMLPropertyState >::iterator aEnd = aPropStates.end();
1208 0 : const UniReference < XMLPropertySetMapper >& pStyle = pExportHelper[i].first->getPropertySetMapper();
1209 0 : while ( aItr != aEnd )
1210 : {
1211 0 : if ( aItr->mnIndex != -1 )
1212 : {
1213 0 : switch ( pStyle->GetEntryContextId(aItr->mnIndex) )
1214 : {
1215 : case CTF_DB_NUMBERFORMAT:
1216 : {
1217 0 : sal_Int32 nNumberFormat = -1;
1218 0 : if ( aItr->maValue >>= nNumberFormat )
1219 0 : addDataStyle(nNumberFormat);
1220 : }
1221 0 : break;
1222 : case CTF_DB_COLUMN_TEXT_ALIGN:
1223 0 : if ( !aItr->maValue.hasValue() )
1224 0 : aItr->maValue <<= ::com::sun::star::awt::TextAlign::LEFT;
1225 0 : break;
1226 : }
1227 : }
1228 0 : ++aItr;
1229 : }
1230 :
1231 : }
1232 0 : if ( XML_STYLE_FAMILY_TABLE_CELL == pExportHelper[i].second.second )
1233 0 : ::std::copy( m_aCurrentPropertyStates.begin(), m_aCurrentPropertyStates.end(), ::std::back_inserter( aPropStates ));
1234 0 : if ( !aPropStates.empty() )
1235 0 : pExportHelper[i].second.first->insert( TPropertyStyleMap::value_type(_xProp,GetAutoStylePool()->Add( pExportHelper[i].second.second, aPropStates )));
1236 0 : }
1237 0 : }
1238 0 : }
1239 : // -----------------------------------------------------------------------------
1240 0 : void ODBExport::_ExportContent()
1241 : {
1242 0 : exportDataSource();
1243 0 : exportForms();
1244 0 : exportReports();
1245 0 : exportQueries(sal_True);
1246 0 : exportTables(sal_True);
1247 0 : }
1248 : // -----------------------------------------------------------------------------
1249 0 : void ODBExport::_ExportMasterStyles()
1250 : {
1251 0 : GetPageExport()->exportMasterStyles( sal_True );
1252 0 : }
1253 : // -----------------------------------------------------------------------------
1254 0 : void ODBExport::_ExportAutoStyles()
1255 : {
1256 : // there are no styles that require their own autostyles
1257 0 : if ( getExportFlags() & EXPORT_CONTENT )
1258 : {
1259 0 : collectComponentStyles();
1260 : GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_TABLE
1261 0 : ,GetDocHandler()
1262 0 : ,GetMM100UnitConverter()
1263 0 : ,GetNamespaceMap()
1264 0 : );
1265 : GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_COLUMN
1266 0 : ,GetDocHandler()
1267 0 : ,GetMM100UnitConverter()
1268 0 : ,GetNamespaceMap()
1269 0 : );
1270 : GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_CELL
1271 0 : ,GetDocHandler()
1272 0 : ,GetMM100UnitConverter()
1273 0 : ,GetNamespaceMap()
1274 0 : );
1275 : GetAutoStylePool()->exportXML(XML_STYLE_FAMILY_TABLE_ROW
1276 0 : ,GetDocHandler()
1277 0 : ,GetMM100UnitConverter()
1278 0 : ,GetNamespaceMap()
1279 0 : );
1280 0 : exportDataStyles();
1281 : }
1282 0 : }
1283 : // -----------------------------------------------------------------------------
1284 0 : void ODBExport::_ExportStyles(sal_Bool bUsed)
1285 : {
1286 0 : SvXMLExport::_ExportStyles(bUsed);
1287 0 : }
1288 : // -----------------------------------------------------------------------------
1289 0 : sal_uInt32 ODBExport::exportDoc(enum ::xmloff::token::XMLTokenEnum eClass)
1290 : {
1291 0 : return SvXMLExport::exportDoc( eClass );
1292 : }
1293 : // -----------------------------------------------------------------------------
1294 0 : void ODBExport::GetViewSettings(Sequence<PropertyValue>& aProps)
1295 : {
1296 0 : Reference<XQueryDefinitionsSupplier> xSup(getDataSource(),UNO_QUERY);
1297 0 : if ( xSup.is() )
1298 : {
1299 0 : Reference< XNameAccess > xCollection = xSup->getQueryDefinitions();
1300 0 : if ( xCollection.is() && xCollection->hasElements() )
1301 : {
1302 : try
1303 : {
1304 0 : sal_Int32 nLength = aProps.getLength();
1305 0 : aProps.realloc(nLength + 1);
1306 0 : aProps[nLength].Name = ::rtl::OUString("Queries");
1307 0 : Sequence< ::rtl::OUString> aSeq = xCollection->getElementNames();
1308 0 : const ::rtl::OUString* pIter = aSeq.getConstArray();
1309 0 : const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
1310 :
1311 0 : Sequence<PropertyValue> aQueries(aSeq.getLength());
1312 0 : for(sal_Int32 i = 0;pIter != pEnd;++pIter,++i)
1313 : {
1314 0 : Reference<XPropertySet> xProp(xCollection->getByName(*pIter),UNO_QUERY);
1315 0 : if ( xProp.is() )
1316 : {
1317 0 : aQueries[i].Name = *pIter;
1318 0 : aQueries[i].Value = xProp->getPropertyValue(PROPERTY_LAYOUTINFORMATION);
1319 : }
1320 0 : }
1321 0 : aProps[nLength].Value <<= aQueries;
1322 : }
1323 0 : catch(const Exception&)
1324 : {
1325 : OSL_FAIL("ODBExport::GetViewSettings: Exception caught!");
1326 : }
1327 0 : }
1328 0 : }
1329 :
1330 0 : }
1331 : // -----------------------------------------------------------------------------
1332 0 : void ODBExport::GetConfigurationSettings(Sequence<PropertyValue>& aProps)
1333 : {
1334 0 : Reference<XPropertySet> xProp(getDataSource());
1335 0 : if ( xProp.is() )
1336 : {
1337 0 : sal_Int32 nLength = aProps.getLength();
1338 : try
1339 : {
1340 0 : Any aValue = xProp->getPropertyValue(PROPERTY_LAYOUTINFORMATION);
1341 0 : Sequence< PropertyValue > aPropValues;
1342 0 : aValue >>= aPropValues;
1343 0 : if ( aPropValues.getLength() )
1344 : {
1345 0 : aProps.realloc(nLength + 1);
1346 0 : aProps[nLength].Name = ::rtl::OUString("layout-settings");
1347 0 : aProps[nLength].Value = aValue;
1348 0 : }
1349 : }
1350 0 : catch(const Exception&)
1351 : {
1352 : OSL_FAIL("Could not access layout information from the data source!");
1353 : }
1354 0 : }
1355 0 : }
1356 : // -----------------------------------------------------------------------------
1357 0 : ::rtl::OUString ODBExport::implConvertAny(const Any& _rValue)
1358 : {
1359 0 : ::rtl::OUStringBuffer aBuffer;
1360 0 : switch (_rValue.getValueTypeClass())
1361 : {
1362 : case TypeClass_STRING:
1363 : { // extract the string
1364 0 : ::rtl::OUString sCurrentValue;
1365 0 : _rValue >>= sCurrentValue;
1366 0 : aBuffer.append(sCurrentValue);
1367 : }
1368 0 : break;
1369 : case TypeClass_DOUBLE:
1370 : // let the unit converter format is as string
1371 0 : ::sax::Converter::convertDouble(aBuffer, getDouble(_rValue));
1372 0 : break;
1373 : case TypeClass_BOOLEAN:
1374 0 : aBuffer = getBOOL(_rValue) ? ::xmloff::token::GetXMLToken(XML_TRUE) : ::xmloff::token::GetXMLToken(XML_FALSE);
1375 0 : break;
1376 : case TypeClass_BYTE:
1377 : case TypeClass_SHORT:
1378 : case TypeClass_LONG:
1379 : // let the unit converter format is as string
1380 0 : ::sax::Converter::convertNumber(aBuffer, getINT32(_rValue));
1381 0 : break;
1382 : default:
1383 : OSL_FAIL("ODBExport::implConvertAny: Invalid type");
1384 : }
1385 :
1386 0 : return aBuffer.makeStringAndClear();
1387 : }
1388 : // -----------------------------------------------------------------------------
1389 0 : UniReference < XMLPropertySetMapper > ODBExport::GetTableStylesPropertySetMapper() const
1390 : {
1391 0 : if ( !m_xTableStylesPropertySetMapper.is() )
1392 : {
1393 0 : m_xTableStylesPropertySetMapper = OXMLHelper::GetTableStylesPropertySetMapper();
1394 : }
1395 0 : return m_xTableStylesPropertySetMapper;
1396 : }
1397 : // -----------------------------------------------------------------------------
1398 0 : UniReference < XMLPropertySetMapper > ODBExport::GetCellStylesPropertySetMapper() const
1399 : {
1400 0 : if ( !m_xCellStylesPropertySetMapper.is() )
1401 : {
1402 0 : m_xCellStylesPropertySetMapper = OXMLHelper::GetCellStylesPropertySetMapper();
1403 : }
1404 0 : return m_xCellStylesPropertySetMapper;
1405 : }
1406 : // -----------------------------------------------------------------------------
1407 0 : UniReference < XMLPropertySetMapper > ODBExport::GetColumnStylesPropertySetMapper() const
1408 : {
1409 0 : if ( !m_xColumnStylesPropertySetMapper.is() )
1410 : {
1411 0 : m_xColumnStylesPropertySetMapper = OXMLHelper::GetColumnStylesPropertySetMapper();
1412 : }
1413 0 : return m_xColumnStylesPropertySetMapper;
1414 : }
1415 : // -----------------------------------------------------------------------------
1416 0 : SvXMLAutoStylePoolP* ODBExport::CreateAutoStylePool()
1417 : {
1418 0 : return new OXMLAutoStylePoolP(*this);
1419 : }
1420 : // -----------------------------------------------------------------------------
1421 0 : void SAL_CALL ODBExport::setSourceDocument( const Reference< XComponent >& xDoc ) throw(IllegalArgumentException, RuntimeException)
1422 : {
1423 0 : Reference<XOfficeDatabaseDocument> xOfficeDoc(xDoc,UNO_QUERY_THROW);
1424 0 : m_xDataSource.set(xOfficeDoc->getDataSource(),UNO_QUERY_THROW);
1425 : OSL_ENSURE(m_xDataSource.is(),"DataSource is NULL!");
1426 0 : Reference< XNumberFormatsSupplier > xNum(m_xDataSource->getPropertyValue(PROPERTY_NUMBERFORMATSSUPPLIER),UNO_QUERY);
1427 0 : SetNumberFormatsSupplier(xNum);
1428 0 : SvXMLExport::setSourceDocument(xDoc);
1429 0 : }
1430 : // -----------------------------------------------------------------------------
1431 0 : void ODBExport::_ExportFontDecls()
1432 : {
1433 0 : GetFontAutoStylePool(); // make sure the pool is created
1434 0 : collectComponentStyles();
1435 0 : SvXMLExport::_ExportFontDecls();
1436 0 : }
1437 : // -----------------------------------------------------------------------------
1438 0 : void ODBExport::collectComponentStyles()
1439 : {
1440 0 : if ( m_bAllreadyFilled )
1441 0 : return;
1442 :
1443 0 : m_bAllreadyFilled = sal_True;
1444 0 : exportQueries(sal_False);
1445 0 : exportTables(sal_False);
1446 : }
1447 : // -----------------------------------------------------------------------------
1448 : }// dbaxml
1449 : // -----------------------------------------------------------------------------
1450 :
1451 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|