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

Generated by: LCOV version 1.10