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