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