LCOV - code coverage report
Current view: top level - xmloff/source/table - XMLTableExport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 220 24.5 %
Date: 2012-08-25 Functions: 10 21 47.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 106 644 16.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "xmloff/dllapi.h"
      30                 :            : 
      31                 :            : #include "sal/config.h"
      32                 :            : #include <osl/diagnose.h>
      33                 :            : 
      34                 :            : #include <rtl/ustring.hxx>
      35                 :            : #include <rtl/ustrbuf.hxx>
      36                 :            : 
      37                 :            : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      38                 :            : #include <com/sun/star/text/XText.hpp>
      39                 :            : #include <com/sun/star/container/XNamed.hpp>
      40                 :            : #include <com/sun/star/container/XEnumerationAccess.hpp>
      41                 :            : #include <com/sun/star/table/XCellRange.hpp>
      42                 :            : #include <com/sun/star/table/XColumnRowRange.hpp>
      43                 :            : #include <com/sun/star/table/CellContentType.hpp>
      44                 :            : #include <com/sun/star/table/XMergeableCell.hpp>
      45                 :            : #include <com/sun/star/style/XStyle.hpp>
      46                 :            : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      47                 :            : 
      48                 :            : #include "xmloff/table/XMLTableExport.hxx"
      49                 :            : #include "xmloff/xmlnmspe.hxx"
      50                 :            : #include <xmloff/xmlprmap.hxx>
      51                 :            : #include <xmloff/xmlexppr.hxx>
      52                 :            : #include <xmloff/xmlexp.hxx>
      53                 :            : #include "table.hxx"
      54                 :            : 
      55                 :            : using ::rtl::OUString;
      56                 :            : using namespace ::xmloff::token;
      57                 :            : using namespace ::com::sun::star::uno;
      58                 :            : using namespace ::com::sun::star::lang;
      59                 :            : using namespace ::com::sun::star::table;
      60                 :            : using namespace ::com::sun::star::beans;
      61                 :            : using namespace ::com::sun::star::container;
      62                 :            : using namespace ::com::sun::star::text;
      63                 :            : using namespace ::com::sun::star::style;
      64                 :            : using namespace ::xmloff::token;
      65                 :            : 
      66                 :            : // --------------------------------------------------------------------
      67                 :            : 
      68                 :            : #define _MAP(name,prefix,token,type,context)  { name, sizeof(name)-1, prefix, token, type, context, SvtSaveOptions::ODFVER_010 }
      69                 :            : #define CMAP(name,prefix,token,type,context) _MAP(name,prefix,token,type|XML_TYPE_PROP_TABLE_COLUMN,context)
      70                 :            : #define RMAP(name,prefix,token,type,context) _MAP(name,prefix,token,type|XML_TYPE_PROP_TABLE_ROW,context)
      71                 :            : #define MAP_END { 0L, 0, 0, XML_EMPTY, 0, 0, SvtSaveOptions::ODFVER_010 }
      72                 :            : 
      73                 :            : // --------------------------------------------------------------------
      74                 :            : 
      75                 :        121 : const XMLPropertyMapEntry* getColumnPropertiesMap()
      76                 :            : {
      77                 :            :     static const XMLPropertyMapEntry aXMLColumnProperties[] =
      78                 :            :     {
      79                 :            :         CMAP( "Width",          XML_NAMESPACE_STYLE,    XML_COLUMN_WIDTH,               XML_TYPE_MEASURE,   0 ),
      80                 :            :         CMAP( "OptimalWidth",   XML_NAMESPACE_STYLE,    XML_USE_OPTIMAL_COLUMN_WIDTH,   XML_TYPE_BOOL, 0 ),
      81                 :            :         MAP_END
      82                 :            :     };
      83                 :            : 
      84                 :        121 :     return &aXMLColumnProperties[0];
      85                 :            : }
      86                 :            : 
      87                 :            : // --------------------------------------------------------------------
      88                 :            : 
      89                 :        121 : const XMLPropertyMapEntry* getRowPropertiesMap()
      90                 :            : {
      91                 :            :     static const XMLPropertyMapEntry aXMLRowProperties[] =
      92                 :            :     {
      93                 :            :         RMAP( "Height",         XML_NAMESPACE_STYLE, XML_ROW_HEIGHT,                    XML_TYPE_MEASURE,   0 ),
      94                 :            :         RMAP( "OptimalHeight",  XML_NAMESPACE_STYLE, XML_MIN_ROW_HEIGHT,                XML_TYPE_MEASURE,   0 ),
      95                 :            :         RMAP( "OptimalWidth",   XML_NAMESPACE_STYLE, XML_USE_OPTIMAL_ROW_HEIGHT,        XML_TYPE_BOOL, 0 ),
      96                 :            :         MAP_END
      97                 :            :     };
      98                 :            : 
      99                 :        121 :     return &aXMLRowProperties[0];
     100                 :            : }
     101                 :            : 
     102                 :            : // --------------------------------------------------------------------
     103                 :            : 
     104                 :          0 : class StringStatisticHelper : public std::map< OUString, sal_Int32 >
     105                 :            : {
     106                 :            : public:
     107                 :            :     void add( const OUString& rStyleName );
     108                 :          0 :     void clear() { std::map< OUString, sal_Int32 >::clear(); }
     109                 :            : 
     110                 :            :     sal_Int32 getModeString( /* out */ OUString& rModeString );
     111                 :            : };
     112                 :            : 
     113                 :            : // --------------------------------------------------------------------
     114                 :            : 
     115                 :          0 : void StringStatisticHelper::add( const OUString& rStyleName )
     116                 :            : {
     117         [ #  # ]:          0 :     std::map< OUString, sal_Int32 >::iterator iter( find( rStyleName ) );
     118         [ #  # ]:          0 :     if( iter == end() )
     119                 :            :     {
     120         [ #  # ]:          0 :         (*this)[rStyleName] = 1;
     121                 :            :     }
     122                 :            :     else
     123                 :            :     {
     124                 :          0 :         (*iter).second += 1;
     125                 :            :     }
     126                 :          0 : }
     127                 :            : 
     128                 :            : // --------------------------------------------------------------------
     129                 :            : 
     130                 :          0 : sal_Int32 StringStatisticHelper::getModeString( OUString& rStyleName )
     131                 :            : {
     132                 :          0 :     sal_Int32 nMax = 0;
     133         [ #  # ]:          0 :     for( std::map< OUString, sal_Int32 >::iterator iter( begin() ); iter != end(); iter++ )
     134                 :            :     {
     135         [ #  # ]:          0 :         if( (*iter).second > nMax )
     136                 :            :         {
     137                 :          0 :             rStyleName = (*iter).first;
     138                 :          0 :             nMax = (*iter).second;
     139                 :            :         }
     140                 :            :     }
     141                 :            : 
     142                 :          0 :     return nMax;
     143                 :            : }
     144                 :            : 
     145                 :            : // --------------------------------------------------------------------
     146                 :            : // class XMLTableExport
     147                 :            : // --------------------------------------------------------------------
     148                 :            : 
     149                 :        107 : XMLTableExport::XMLTableExport(SvXMLExport& rExp, const rtl::Reference< SvXMLExportPropertyMapper  >& xExportPropertyMapper, const rtl::Reference< XMLPropertyHandlerFactory >& xFactoryRef )
     150                 :            : : mrExport( rExp )
     151         [ +  - ]:        107 : , mbExportTables( false )
     152                 :            : {
     153         [ +  - ]:        107 :     Reference< XMultiServiceFactory > xFac( rExp.GetModel(), UNO_QUERY );
     154         [ +  - ]:        107 :     if( xFac.is() ) try
     155                 :            :     {
     156 [ +  - ][ +  - ]:        107 :         Sequence< OUString > sSNS( xFac->getAvailableServiceNames() );
     157                 :        107 :         sal_Int32 n = sSNS.getLength();
     158                 :        107 :         const OUString* pSNS( sSNS.getConstArray() );
     159         [ +  + ]:      12919 :         while( --n > 0 )
     160                 :            :         {
     161         [ +  + ]:      12860 :             if( (*pSNS++) == "com.sun.star.drawing.TableShape" )
     162                 :            :             {
     163                 :         48 :                 mbExportTables = true;
     164                 :         48 :                 break;
     165                 :            :             }
     166         [ +  - ]:        107 :         }
     167                 :            :     }
     168         [ #  # ]:          0 :     catch(const Exception&)
     169                 :            :     {
     170                 :            :     }
     171                 :            : 
     172         [ +  - ]:        107 :     mxCellExportPropertySetMapper = xExportPropertyMapper;
     173 [ +  - ][ +  - ]:        107 :     mxCellExportPropertySetMapper->ChainExportMapper(XMLTextParagraphExport::CreateParaExtPropMapper(rExp));
         [ +  - ][ +  - ]
     174                 :            : 
     175 [ +  - ][ +  - ]:        107 :     mxRowExportPropertySetMapper = new SvXMLExportPropertyMapper( new XMLPropertySetMapper( getRowPropertiesMap(), xFactoryRef.get() ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     176 [ +  - ][ +  - ]:        107 :     mxColumnExportPropertySetMapper = new SvXMLExportPropertyMapper( new XMLPropertySetMapper( getColumnPropertiesMap(), xFactoryRef.get() ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     177                 :            : 
     178                 :            :     mrExport.GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_COLUMN,
     179                 :            :         OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME)),
     180                 :            :         mxColumnExportPropertySetMapper.get(),
     181 [ +  - ][ +  - ]:        107 :         OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX)));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     182                 :            :     mrExport.GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_ROW,
     183                 :            :         OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME)),
     184                 :            :         mxRowExportPropertySetMapper.get(),
     185 [ +  - ][ +  - ]:        107 :         OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX)));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     186                 :            :     mrExport.GetAutoStylePool()->AddFamily(XML_STYLE_FAMILY_TABLE_CELL,
     187                 :            :         OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME)),
     188                 :            :         mxCellExportPropertySetMapper.get(),
     189 [ +  - ][ +  - ]:        107 :         OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX)));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     190         [ #  # ]:        107 : }
     191                 :            : 
     192                 :            : // --------------------------------------------------------------------
     193                 :            : 
     194 [ +  - ][ +  - ]:        107 : XMLTableExport::~XMLTableExport ()
                 [ +  - ]
     195                 :            : {
     196         [ -  + ]:        214 : }
     197                 :            : 
     198                 :            : // --------------------------------------------------------------------
     199                 :            : 
     200                 :          0 : static bool has_states( const std::vector< XMLPropertyState >& xPropStates )
     201                 :            : {
     202         [ #  # ]:          0 :     if( !xPropStates.empty() )
     203                 :            :     {
     204                 :          0 :         std::vector< XMLPropertyState >::const_iterator aIter( xPropStates.begin() );
     205                 :          0 :         std::vector< XMLPropertyState >::const_iterator aEnd( xPropStates.end() );
     206 [ #  # ][ #  # ]:          0 :         while( aIter != aEnd )
     207                 :            :         {
     208         [ #  # ]:          0 :             if( aIter->mnIndex != -1 )
     209                 :          0 :                 return true;
     210                 :          0 :             ++aIter;
     211                 :            :         }
     212                 :            :     }
     213                 :          0 :     return false;
     214                 :            : }
     215                 :            : 
     216                 :            : // --------------------------------------------------------------------
     217                 :            : 
     218                 :          0 :  void XMLTableExport::collectTableAutoStyles(const Reference < XColumnRowRange >& xColumnRowRange)
     219                 :            :  {
     220         [ #  # ]:          0 :      if( !mbExportTables )
     221                 :          0 :          return;
     222                 :            : 
     223 [ #  # ][ #  # ]:          0 :     boost::shared_ptr< XMLTableInfo > pTableInfo( new XMLTableInfo() );
                 [ #  # ]
     224 [ #  # ][ #  # ]:          0 :     maTableInfoMap[xColumnRowRange] = pTableInfo;
     225                 :            : 
     226                 :            :     try
     227                 :            :     {
     228 [ #  # ][ #  # ]:          0 :         Reference< XIndexAccess > xIndexAccessCols( xColumnRowRange->getColumns(), UNO_QUERY_THROW );
                 [ #  # ]
     229 [ #  # ][ #  # ]:          0 :         const sal_Int32 nColumnCount = xIndexAccessCols->getCount();
     230         [ #  # ]:          0 :          for( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn ) try
     231                 :            :         {
     232 [ #  # ][ #  # ]:          0 :              Reference< XPropertySet > xPropSet( xIndexAccessCols->getByIndex(nColumn) , UNO_QUERY_THROW );
                 [ #  # ]
     233         [ #  # ]:          0 :             std::vector< XMLPropertyState > xPropStates( mxColumnExportPropertySetMapper->Filter( xPropSet ) );
     234                 :            : 
     235 [ #  # ][ #  # ]:          0 :             if( has_states( xPropStates ) )
     236                 :            :             {
     237 [ #  # ][ #  # ]:          0 :                 const OUString sStyleName( mrExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_TABLE_COLUMN, xPropStates) );
         [ #  # ][ #  # ]
     238         [ #  # ]:          0 :                 Reference< XInterface > xKey( xPropSet, UNO_QUERY );
     239         [ #  # ]:          0 :                 pTableInfo->maColumnStyleMap[xKey] = sStyleName;
     240         [ #  # ]:          0 :             }
     241                 :            :         }
     242         [ #  # ]:          0 :         catch(const Exception&)
     243                 :            :         {
     244                 :            :             OSL_FAIL("xmloff::XMLTableExport::collectTableAutoStyles(), exception during column style collection!");
     245                 :            :         }
     246                 :            : 
     247 [ #  # ][ #  # ]:          0 :         Reference< XIndexAccess > xIndexAccessRows( xColumnRowRange->getRows(), UNO_QUERY_THROW );
                 [ #  # ]
     248 [ #  # ][ #  # ]:          0 :         const sal_Int32 nRowCount = xIndexAccessRows->getCount();
     249         [ #  # ]:          0 :         pTableInfo->maDefaultRowCellStyles.resize(nRowCount);
     250                 :            : 
     251         [ #  # ]:          0 :         StringStatisticHelper aStringStatistic;
     252                 :            : 
     253         [ #  # ]:          0 :          for( sal_Int32 nRow = 0; nRow < nRowCount; ++nRow ) try
     254                 :            :         {
     255 [ #  # ][ #  # ]:          0 :              Reference< XPropertySet > xPropSet( xIndexAccessRows->getByIndex(nRow) , UNO_QUERY_THROW );
                 [ #  # ]
     256         [ #  # ]:          0 :             std::vector< XMLPropertyState > xRowPropStates( mxRowExportPropertySetMapper->Filter( xPropSet ) );
     257                 :            : 
     258 [ #  # ][ #  # ]:          0 :             if( has_states( xRowPropStates ) )
     259                 :            :             {
     260 [ #  # ][ #  # ]:          0 :                 const OUString sStyleName( mrExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_TABLE_ROW, xRowPropStates) );
         [ #  # ][ #  # ]
     261         [ #  # ]:          0 :                 Reference< XInterface > xKey( xPropSet, UNO_QUERY );
     262         [ #  # ]:          0 :                 pTableInfo->maRowStyleMap[xKey] = sStyleName;
     263                 :            :             }
     264                 :            : 
     265                 :            :             // get the current row
     266         [ #  # ]:          0 :             Reference< XCellRange > xCellRange( xPropSet, UNO_QUERY_THROW );
     267         [ #  # ]:          0 :             for ( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
     268                 :            :             {
     269                 :            :                 // get current cell, remarks row index is 0, because we get the range for each row seperate
     270 [ #  # ][ #  # ]:          0 :                 Reference< XPropertySet > xCellSet( xCellRange->getCellByPosition(nColumn, 0), UNO_QUERY_THROW );
                 [ #  # ]
     271                 :            : 
     272                 :            :                 // get style
     273                 :          0 :                 OUString sParentStyleName;
     274 [ #  # ][ #  # ]:          0 :                 Reference< XPropertySetInfo > xPropertySetInfo( xCellSet->getPropertySetInfo() );
     275 [ #  # ][ #  # ]:          0 :                 if( xPropertySetInfo.is() && xPropertySetInfo->hasPropertyByName( OUString(RTL_CONSTASCII_USTRINGPARAM("Style"))) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     276                 :            :                 {
     277 [ #  # ][ #  # ]:          0 :                     Reference< XStyle > xStyle( xCellSet->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Style"))), UNO_QUERY );
         [ #  # ][ #  # ]
     278         [ #  # ]:          0 :                     if( xStyle.is() )
     279 [ #  # ][ #  # ]:          0 :                         sParentStyleName = xStyle->getName();
     280                 :            :                 }
     281                 :            : 
     282                 :            :                 // create auto style, if needed
     283                 :          0 :                 OUString sStyleName;
     284         [ #  # ]:          0 :                 std::vector< XMLPropertyState > xCellPropStates( mxCellExportPropertySetMapper->Filter( xCellSet ) );
     285 [ #  # ][ #  # ]:          0 :                 if( has_states( xCellPropStates ) )
     286 [ #  # ][ #  # ]:          0 :                     sStyleName = mrExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_TABLE_CELL, xCellPropStates);
         [ #  # ][ #  # ]
     287                 :            :                 else
     288                 :          0 :                     sStyleName = sParentStyleName;
     289                 :            : 
     290         [ #  # ]:          0 :                 if( !sStyleName.isEmpty() )
     291                 :            :                 {
     292         [ #  # ]:          0 :                     Reference< XInterface > xKey( xCellSet, UNO_QUERY );
     293         [ #  # ]:          0 :                     pTableInfo->maCellStyleMap[xKey] = sStyleName;
     294                 :            :                 }
     295                 :            : 
     296                 :            :                 // create auto style for text
     297         [ #  # ]:          0 :                 Reference< XText > xText(xCellSet, UNO_QUERY);
     298 [ #  # ][ #  # ]:          0 :                 if(xText.is() && !xText->getString().isEmpty())
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     299 [ #  # ][ #  # ]:          0 :                     GetExport().GetTextParagraphExport()->collectTextAutoStyles( xText );
         [ #  # ][ #  # ]
     300                 :            : 
     301         [ #  # ]:          0 :                 aStringStatistic.add( sStyleName );
     302                 :          0 :             }
     303                 :            : 
     304                 :          0 :             OUString sDefaultCellStyle;
     305 [ #  # ][ #  # ]:          0 :             if( aStringStatistic.getModeString( sDefaultCellStyle ) > 1 )
     306                 :          0 :                 pTableInfo->maDefaultRowCellStyles[nRow] = sDefaultCellStyle;
     307                 :            : 
     308         [ #  # ]:          0 :             aStringStatistic.clear();
     309                 :            :         }
     310         [ #  # ]:          0 :         catch(const Exception&)
     311                 :            :         {
     312                 :            :             OSL_FAIL("xmloff::XMLTableExport::collectTableAutoStyles(), exception during column style collection!");
     313         [ #  # ]:          0 :         }
     314                 :            :     }
     315         [ #  # ]:          0 :     catch(const Exception&)
     316                 :            :     {
     317                 :            :         OSL_FAIL("xmloff::XMLTableExport::collectTableAutoStyles(), exception caught!");
     318         [ #  # ]:          0 :     }
     319                 :            :  }
     320                 :            : 
     321                 :            :  // --------------------------------------------------------------------
     322                 :            : 
     323                 :          0 :  void XMLTableExport::exportTable( const Reference < XColumnRowRange >& xColumnRowRange )
     324                 :            :  {
     325         [ #  # ]:          0 :      if( !mbExportTables )
     326                 :          0 :          return;
     327                 :            : 
     328                 :            :      try
     329                 :            :     {
     330 [ #  # ][ #  # ]:          0 :         boost::shared_ptr< XMLTableInfo > pTableInfo( maTableInfoMap[xColumnRowRange] );
     331                 :            : 
     332                 :            :         // get row and column count
     333 [ #  # ][ #  # ]:          0 :         Reference< XIndexAccess > xIndexAccess( xColumnRowRange->getRows(), UNO_QUERY_THROW );
                 [ #  # ]
     334 [ #  # ][ #  # ]:          0 :         Reference< XIndexAccess > xIndexAccessCols( xColumnRowRange->getColumns(), UNO_QUERY_THROW );
                 [ #  # ]
     335                 :            : 
     336 [ #  # ][ #  # ]:          0 :         const sal_Int32 rowCount = xIndexAccess->getCount();
     337 [ #  # ][ #  # ]:          0 :         const sal_Int32 columnCount = xIndexAccessCols->getCount();
     338                 :            : 
     339         [ #  # ]:          0 :         SvXMLElementExport tableElement( mrExport, XML_NAMESPACE_TABLE, XML_TABLE, sal_True, sal_True );
     340                 :            : 
     341                 :            :         // export table columns
     342         [ #  # ]:          0 :         ExportTableColumns( xIndexAccessCols, pTableInfo );
     343                 :            : 
     344                 :            :         // start iterating rows and columns
     345         [ #  # ]:          0 :         for ( sal_Int32 rowIndex = 0; rowIndex < rowCount; rowIndex++ )
     346                 :            :         {
     347                 :            :             // get the current row
     348 [ #  # ][ #  # ]:          0 :             Reference< XCellRange > xCellRange( xIndexAccess->getByIndex(rowIndex), UNO_QUERY_THROW );
                 [ #  # ]
     349                 :            : 
     350                 :          0 :             OUString sDefaultCellStyle;
     351                 :            : 
     352                 :            :             // table:style-name
     353         [ #  # ]:          0 :             if( pTableInfo.get() )
     354                 :            :             {
     355         [ #  # ]:          0 :                 Reference< XInterface > xKey( xCellRange, UNO_QUERY );
     356         [ #  # ]:          0 :                 const OUString sStyleName( pTableInfo->maRowStyleMap[xKey] );
     357         [ #  # ]:          0 :                 if( !sStyleName.isEmpty() )
     358         [ #  # ]:          0 :                     mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, sStyleName );
     359                 :            : 
     360                 :          0 :                 sDefaultCellStyle = pTableInfo->maDefaultRowCellStyles[rowIndex];
     361         [ #  # ]:          0 :                 if( !sDefaultCellStyle.isEmpty() )
     362         [ #  # ]:          0 :                     mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DEFAULT_CELL_STYLE_NAME, sDefaultCellStyle );
     363                 :            :             }
     364                 :            : 
     365                 :            :             // write row element
     366         [ #  # ]:          0 :             SvXMLElementExport tableRowElement( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_ROW, sal_True, sal_True );
     367                 :            : 
     368         [ #  # ]:          0 :             for ( sal_Int32 columnIndex = 0; columnIndex < columnCount; columnIndex++ )
     369                 :            :             {
     370                 :            :                 // get current cell, remarks row index is 0, because we get the range for each row seperate
     371 [ #  # ][ #  # ]:          0 :                 Reference< XCell > xCell( xCellRange->getCellByPosition(columnIndex, 0), UNO_QUERY_THROW );
                 [ #  # ]
     372                 :            : 
     373                 :            :                 // use XMergeableCell interface from offapi
     374         [ #  # ]:          0 :                 Reference< XMergeableCell > xMergeableCell( xCell, UNO_QUERY_THROW );
     375                 :            : 
     376                 :            :                 // export cell
     377         [ #  # ]:          0 :                 ExportCell( xCell, pTableInfo, sDefaultCellStyle );
     378                 :          0 :             }
     379 [ #  # ][ #  # ]:          0 :         }
         [ #  # ][ #  # ]
     380                 :            :      }
     381                 :          0 :      catch(const Exception&)
     382                 :            :     {
     383                 :            :          OSL_FAIL( "XMLTableExport::exportTable(), exception cought!" );
     384                 :            :      }
     385                 :            :  }
     386                 :            : 
     387                 :            : // --------------------------------------------------------------------
     388                 :            : // Export the table columns
     389                 :            : // --------------------------------------------------------------------
     390                 :            : 
     391                 :          0 :  void XMLTableExport::ExportTableColumns( const Reference < XIndexAccess >& xtableColumnsIndexAccess, const boost::shared_ptr< XMLTableInfo >& pTableInfo )
     392                 :            :  {
     393                 :          0 :     const sal_Int32 nColumnCount = xtableColumnsIndexAccess->getCount();
     394         [ #  # ]:          0 :      for( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
     395                 :            :     {
     396 [ #  # ][ #  # ]:          0 :          Reference< XPropertySet > xColumnProperties( xtableColumnsIndexAccess->getByIndex(nColumn) , UNO_QUERY );
                 [ #  # ]
     397         [ #  # ]:          0 :          if ( xColumnProperties.is() )
     398                 :            :         {
     399                 :            :             // table:style-name
     400         [ #  # ]:          0 :             if( pTableInfo.get() )
     401                 :            :             {
     402         [ #  # ]:          0 :                 Reference< XInterface > xKey( xColumnProperties, UNO_QUERY );
     403         [ #  # ]:          0 :                 const OUString sStyleName( pTableInfo->maColumnStyleMap[xKey] );
     404         [ #  # ]:          0 :                 if( !sStyleName.isEmpty() )
     405         [ #  # ]:          0 :                     mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, sStyleName );
     406                 :            :             }
     407                 :            : 
     408                 :            :              // TODO: All columns first have to be checked if some ones
     409                 :            :              // have identical properties. If yes, attr table:number-columns-repeated
     410                 :            :              // has to be written.
     411 [ #  # ][ #  # ]:          0 :              SvXMLElementExport tableColumnElement( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, sal_True, sal_True );
     412                 :            :          }
     413                 :          0 :      }
     414                 :          0 :  }
     415                 :            : 
     416                 :            : // --------------------------------------------------------------------
     417                 :            : // ODF export for a table cell.
     418                 :            : // --------------------------------------------------------------------
     419                 :            : 
     420                 :          0 :  void XMLTableExport::ExportCell( const Reference < XCell >& xCell, const boost::shared_ptr< XMLTableInfo >& pTableInfo, const OUString& rDefaultCellStyle )
     421                 :            :  {
     422                 :          0 :     bool bIsMerged = false;
     423                 :          0 :     sal_Int32 nRowSpan = 0;
     424                 :          0 :     sal_Int32 nColSpan = 0;
     425                 :            : 
     426                 :            :      try
     427                 :            :     {
     428         [ #  # ]:          0 :         if( pTableInfo.get() )
     429                 :            :         {
     430                 :            :             // table:style-name
     431         [ #  # ]:          0 :             Reference< XInterface > xKey( xCell, UNO_QUERY );
     432         [ #  # ]:          0 :             const OUString sStyleName( pTableInfo->maCellStyleMap[xKey] );
     433 [ #  # ][ #  # ]:          0 :             if( !sStyleName.isEmpty() && (sStyleName != rDefaultCellStyle) )
                 [ #  # ]
     434         [ #  # ]:          0 :                 mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, sStyleName );
     435                 :            :         }
     436                 :            : 
     437         [ #  # ]:          0 :         Reference< XMergeableCell > xMerge( xCell, UNO_QUERY );
     438         [ #  # ]:          0 :         if( xMerge.is() )
     439                 :            :         {
     440 [ #  # ][ #  # ]:          0 :             bIsMerged = xMerge->isMerged();
     441 [ #  # ][ #  # ]:          0 :             nRowSpan = xMerge->getRowSpan();
     442 [ #  # ][ #  # ]:          0 :             nColSpan = xMerge->getColumnSpan();
     443                 :            :         }
     444         [ #  # ]:          0 :         DBG_ASSERT( (nRowSpan >= 1) && (nColSpan >= 1), "xmloff::XMLTableExport::ExportCell(), illegal row or col span < 1?" );
     445                 :            :     }
     446         [ #  # ]:          0 :     catch (const Exception&)
     447                 :            :     {
     448                 :            :         OSL_FAIL( "exception while exporting a table cell" );
     449                 :            :     }
     450                 :            : 
     451                 :            :     // table:number-columns-repeated
     452                 :            :     // todo
     453                 :            : 
     454                 :            :     // table:number-columns-spanned
     455         [ #  # ]:          0 :     if( nColSpan > 1 )
     456         [ #  # ]:          0 :         mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_SPANNED, OUString::valueOf( nColSpan ) );
     457                 :            : 
     458                 :            :     // table:number-rows-spanned
     459         [ #  # ]:          0 :     if( nRowSpan > 1 )
     460         [ #  # ]:          0 :         mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_SPANNED, OUString::valueOf( nRowSpan ) );
     461                 :            : 
     462                 :            :      // <table:table-cell> or <table:covered-table-cell>
     463 [ #  # ][ #  # ]:          0 :     SvXMLElementExport tableCellElement( mrExport, XML_NAMESPACE_TABLE, bIsMerged ? XML_COVERED_TABLE_CELL : XML_TABLE_CELL, sal_True, sal_True );
     464                 :            : 
     465                 :            :     // export cells text content
     466 [ #  # ][ #  # ]:          0 :     ImpExportText( xCell );
     467                 :          0 :  }
     468                 :            : 
     469                 :            : // --------------------------------------------------------------------
     470                 :            : // ODF export of the text contents of a table cell.
     471                 :            : // Remarks: Up to now we only export text contents!
     472                 :            : // TODO: Check against nested tables ....
     473                 :            : // --------------------------------------------------------------------
     474                 :            : 
     475                 :          0 :  void XMLTableExport::ImpExportText( const Reference< XCell >& xCell )
     476                 :            :  {
     477         [ #  # ]:          0 :     Reference< XText > xText( xCell, UNO_QUERY );
     478 [ #  # ][ #  # ]:          0 :     if( xText.is() && !xText->getString().isEmpty())
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     479 [ #  # ][ #  # ]:          0 :         mrExport.GetTextParagraphExport()->exportText( xText );
         [ #  # ][ #  # ]
     480                 :          0 :  }
     481                 :            : 
     482                 :            : // --------------------------------------------------------------------
     483                 :            : 
     484                 :         12 : void XMLTableExport::exportTableStyles()
     485                 :            : {
     486         [ +  - ]:         12 :      if( !mbExportTables )
     487                 :         12 :          return;
     488                 :            : 
     489 [ +  - ][ +  - ]:         12 :     XMLStyleExport aStEx(mrExport, OUString(), mrExport.GetAutoStylePool().get());
                 [ +  - ]
     490                 :            : 
     491                 :            :     // write graphic family styles
     492 [ +  - ][ +  - ]:         12 :     aStEx.exportStyleFamily("cell", OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME)), mxCellExportPropertySetMapper.get(), sal_True, XML_STYLE_FAMILY_TABLE_CELL);
         [ +  - ][ +  - ]
     493                 :            : 
     494 [ +  - ][ +  - ]:         12 :     exportTableTemplates();
     495                 :            : }
     496                 :            : 
     497                 :            : // --------------------------------------------------------------------
     498                 :            : // Export the collected automatic styles
     499                 :            : // --------------------------------------------------------------------
     500                 :            : 
     501                 :         75 : void XMLTableExport::exportAutoStyles()
     502                 :            : {
     503         [ +  + ]:         75 :      if( !mbExportTables )
     504                 :         75 :          return;
     505                 :            : 
     506 [ +  - ][ +  - ]:         20 :     mrExport.GetAutoStylePool()->exportXML( XML_STYLE_FAMILY_TABLE_COLUMN, mrExport.GetDocHandler(), mrExport.GetMM100UnitConverter(), mrExport.GetNamespaceMap() );
     507 [ +  - ][ +  - ]:         20 :     mrExport.GetAutoStylePool()->exportXML( XML_STYLE_FAMILY_TABLE_ROW, mrExport.GetDocHandler(), mrExport.GetMM100UnitConverter(), mrExport.GetNamespaceMap() );
     508 [ +  - ][ +  - ]:         20 :     mrExport.GetAutoStylePool()->exportXML( XML_STYLE_FAMILY_TABLE_CELL, mrExport.GetDocHandler(), mrExport.GetMM100UnitConverter(), mrExport.GetNamespaceMap() );
     509                 :            : }
     510                 :            : 
     511                 :            : // --------------------------------------------------------------------
     512                 :            : 
     513                 :         21 : const TableStyleElement* getTableStyleMap()
     514                 :            : {
     515                 :            :     static struct TableStyleElement gTableStyleElements[] =
     516                 :            :     {
     517                 :            :         { XML_FIRST_ROW, OUString( RTL_CONSTASCII_USTRINGPARAM( "first-row" ) ) },
     518                 :            :         { XML_LAST_ROW, OUString( RTL_CONSTASCII_USTRINGPARAM( "last-row" ) ) },
     519                 :            :         { XML_FIRST_COLUMN, OUString( RTL_CONSTASCII_USTRINGPARAM( "first-column" ) ) },
     520                 :            :         { XML_LAST_COLUMN, OUString( RTL_CONSTASCII_USTRINGPARAM( "last-column" ) ) },
     521                 :            :         { XML_EVEN_ROWS, OUString( RTL_CONSTASCII_USTRINGPARAM( "even-rows" ) ) },
     522                 :            :         { XML_ODD_ROWS, OUString( RTL_CONSTASCII_USTRINGPARAM( "odd-rows" ) ) },
     523                 :            :         { XML_EVEN_COLUMNS, OUString( RTL_CONSTASCII_USTRINGPARAM( "even-columns" ) ) },
     524                 :            :         { XML_ODD_COLUMNS, OUString( RTL_CONSTASCII_USTRINGPARAM( "odd-columns" ) ) },
     525                 :            :         { XML_BODY, OUString( RTL_CONSTASCII_USTRINGPARAM( "body" ) ) },
     526                 :            :         { XML_TOKEN_END, OUString() }
     527 [ +  + ][ +  - ]:         54 :     };
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ #  #  
             #  #  #  # ]
                 [ +  + ]
     528                 :            : 
     529                 :         21 :     return &gTableStyleElements[0];
     530                 :            : }
     531                 :            : 
     532                 :            : // --------------------------------------------------------------------
     533                 :            : 
     534                 :         12 : void XMLTableExport::exportTableTemplates()
     535                 :            : {
     536         [ -  + ]:         12 :      if( !mbExportTables )
     537                 :         12 :          return;
     538                 :            : 
     539                 :            :     try
     540                 :            :     {
     541         [ +  - ]:         12 :         Reference< XStyleFamiliesSupplier > xFamiliesSupp( mrExport.GetModel(), UNO_QUERY_THROW );
     542 [ +  - ][ +  - ]:         12 :         Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
     543         [ +  - ]:         12 :         const OUString sFamilyName( RTL_CONSTASCII_USTRINGPARAM("table" ) );
     544 [ +  - ][ +  - ]:         12 :         Reference< XIndexAccess > xTableFamily( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
                 [ +  - ]
     545                 :            : 
     546 [ +  - ][ +  - ]:        144 :         for( sal_Int32 nIndex = 0; nIndex < xTableFamily->getCount(); nIndex++ ) try
                 [ +  + ]
     547                 :            :         {
     548 [ +  - ][ +  - ]:        132 :             Reference< XStyle > xTableStyle( xTableFamily->getByIndex( nIndex ), UNO_QUERY_THROW );
                 [ +  - ]
     549 [ +  - ][ +  - ]:        132 :             if( !xTableStyle->isInUse() )
                 [ +  - ]
     550                 :        132 :                 continue;
     551                 :            : 
     552         [ #  # ]:          0 :             Reference< XNameAccess > xStyleNames( xTableStyle, UNO_QUERY_THROW );
     553                 :            : 
     554 [ #  # ][ #  # ]:          0 :             mrExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( xTableStyle->getName() ) );
         [ #  # ][ #  # ]
     555         [ #  # ]:          0 :              SvXMLElementExport tableTemplate( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_TEMPLATE, sal_True, sal_True );
     556                 :            : 
     557         [ #  # ]:          0 :             const TableStyleElement* pElements = getTableStyleMap();
     558         [ #  # ]:          0 :             while( pElements->meElement != XML_TOKEN_END )
     559                 :            :             {
     560                 :            :                 try
     561                 :            :                 {
     562 [ #  # ][ #  # ]:          0 :                     Reference< XStyle > xStyle( xStyleNames->getByName( pElements->msStyleName ), UNO_QUERY );
                 [ #  # ]
     563         [ #  # ]:          0 :                     if( xStyle.is() )
     564                 :            :                     {
     565 [ #  # ][ #  # ]:          0 :                         mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, GetExport().EncodeStyleName( xStyle->getName() ) );
         [ #  # ][ #  # ]
     566 [ #  # ][ #  # ]:          0 :                          SvXMLElementExport element( mrExport, XML_NAMESPACE_TABLE, pElements->meElement, sal_True, sal_True );
     567         [ #  # ]:          0 :                     }
     568                 :            :                 }
     569         [ #  # ]:          0 :                 catch(const Exception&)
     570                 :            :                 {
     571                 :            :                     OSL_FAIL("xmloff::XMLTableExport::exportTableTemplates(), exception caught!");
     572                 :            :                 }
     573                 :            : 
     574                 :          0 :                 pElements++;
     575 [ #  # ][ -  + ]:        132 :             }
                 [ #  # ]
     576                 :            :         }
     577         [ #  # ]:          0 :         catch(const Exception&)
     578                 :            :         {
     579                 :            :             OSL_FAIL("xmloff::XMLTableExport::exportTableDesigns(), exception caught while exporting a table design!");
     580         [ #  # ]:         12 :         }
     581                 :            :     }
     582                 :          0 :     catch(const Exception&)
     583                 :            :     {
     584                 :            :         OSL_FAIL("xmloff::XMLTableExport::exportTableDesigns(), exception caught!");
     585                 :            :     }
     586                 :            : }
     587                 :            : 
     588                 :            : // --------------------------------------------------------------------
     589                 :            : 
     590                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10