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

Generated by: LCOV version 1.11