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