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

Generated by: LCOV version 1.10