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