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

Generated by: LCOV version 1.10