LCOV - code coverage report
Current view: top level - dbaccess/source/filter/xml - xmlExport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 502 772 65.0 %
Date: 2014-11-03 Functions: 54 68 79.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10