LibreOffice Module xmloff (master)  1
XMLTableExport.cxx
Go to the documentation of this file.
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 
21 
22 #include <xmloff/dllapi.h>
23 
24 #include <sal/config.h>
25 #include <sal/log.hxx>
26 #include <osl/diagnose.h>
27 
28 #include <rtl/ustring.hxx>
29 #include <rtl/ustrbuf.hxx>
30 
31 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
32 #include <com/sun/star/text/XText.hpp>
33 #include <com/sun/star/container/XNamed.hpp>
34 #include <com/sun/star/container/XEnumerationAccess.hpp>
35 #include <com/sun/star/table/XCellRange.hpp>
36 #include <com/sun/star/table/XColumnRowRange.hpp>
37 #include <com/sun/star/table/CellContentType.hpp>
38 #include <com/sun/star/table/XMergeableCell.hpp>
39 #include <com/sun/star/style/XStyle.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/beans/XPropertySetInfo.hpp>
42 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
43 #include <tools/diagnose_ex.h>
44 
45 #include <xmloff/xmlnmspe.hxx>
46 #include <xmloff/xmlprmap.hxx>
47 #include <xmloff/xmlexppr.hxx>
48 #include <xmloff/xmlexp.hxx>
49 #include <xmloff/xmltypes.hxx>
50 #include <xmlsdtypes.hxx>
51 #include <xmloff/maptype.hxx>
52 #include <xmloff/prhdlfac.hxx>
53 #include <xmloff/txtprmap.hxx>
54 #include "table.hxx"
55 
56 using namespace ::xmloff::token;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::table;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::container;
62 using namespace ::com::sun::star::text;
63 using namespace ::com::sun::star::style;
64 
65 #define MAP_(name,prefix,token,type,context) { name, sizeof(name)-1, prefix, token, type, context, SvtSaveOptions::ODFVER_010, false }
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 CELLMAP(name,prefix,token,type,context) MAP_(name,prefix,token,type|XML_TYPE_PROP_TABLE_CELL,context)
69 #define MAP_END { nullptr, 0, 0, XML_EMPTY, 0, 0, SvtSaveOptions::ODFVER_010, false }
70 
72 {
73  static const XMLPropertyMapEntry aXMLColumnProperties[] =
74  {
75  CMAP( "Width", XML_NAMESPACE_STYLE, XML_COLUMN_WIDTH, XML_TYPE_MEASURE, 0 ),
76  CMAP( "OptimalWidth", XML_NAMESPACE_STYLE, XML_USE_OPTIMAL_COLUMN_WIDTH, XML_TYPE_BOOL, 0 ),
77  MAP_END
78  };
79 
80  return &aXMLColumnProperties[0];
81 }
82 
84 {
85  static const XMLPropertyMapEntry aXMLRowProperties[] =
86  {
87  RMAP( "Height", XML_NAMESPACE_STYLE, XML_ROW_HEIGHT, XML_TYPE_MEASURE, 0 ),
88  RMAP( "MinHeight", XML_NAMESPACE_STYLE, XML_MIN_ROW_HEIGHT, XML_TYPE_MEASURE, 0 ),
89  RMAP( "OptimalHeight", XML_NAMESPACE_STYLE, XML_USE_OPTIMAL_ROW_HEIGHT, XML_TYPE_BOOL, 0 ),
90  MAP_END
91  };
92 
93  return &aXMLRowProperties[0];
94 }
95 
97 {
98  static const XMLPropertyMapEntry aXMLCellProperties[] =
99  {
100  CELLMAP( "RotateAngle", XML_NAMESPACE_STYLE, XML_ROTATION_ANGLE, XML_SD_TYPE_CELL_ROTATION_ANGLE, 0),
101  MAP_END
102  };
103 
104  return &aXMLCellProperties[0];
105 }
106 
108 {
109 private:
110  std::map< OUString, sal_Int32 > mStats;
111 
112 public:
113  void add( const OUString& rStyleName );
114  void clear() { mStats.clear(); }
115 
116  sal_Int32 getModeString( /* out */ OUString& rModeString );
117 };
118 
119 void StringStatisticHelper::add( const OUString& rStyleName )
120 {
121  std::map< OUString, sal_Int32 >::iterator iter( mStats.find( rStyleName ) );
122  if( iter == mStats.end() )
123  {
124  mStats[rStyleName] = 1;
125  }
126  else
127  {
128  (*iter).second += 1;
129  }
130 }
131 
132 sal_Int32 StringStatisticHelper::getModeString( OUString& rStyleName )
133 {
134  sal_Int32 nMax = 0;
135  for( const auto& rStatsEntry : mStats )
136  {
137  if( rStatsEntry.second > nMax )
138  {
139  rStyleName = rStatsEntry.first;
140  nMax = rStatsEntry.second;
141  }
142  }
143 
144  return nMax;
145 }
146 
147 // class XMLTableExport
148 
150 : mrExport( rExp )
151 , mbExportTables( false )
152 , mbWriter( false )
153 {
154  Reference< XMultiServiceFactory > xFac( rExp.GetModel(), UNO_QUERY );
155  if( xFac.is() ) try
156  {
157  Sequence< OUString > sSNS( xFac->getAvailableServiceNames() );
158  const OUString* pSNS = std::find_if(sSNS.begin(), sSNS.end(),
159  [](const OUString& rSNS) {
160  return rSNS == "com.sun.star.drawing.TableShape"
161  || rSNS == "com.sun.star.style.TableStyle"; });
162  if (pSNS != sSNS.end())
163  {
164  mbExportTables = true;
165  mbWriter = (*pSNS == "com.sun.star.style.TableStyle");
166  }
167  }
168  catch(const Exception&)
169  {
170  }
171 
172  if (mbWriter)
173  {
175  }
176  else
177  {
178  mxCellExportPropertySetMapper = xExportPropertyMapper;
180  mxCellExportPropertySetMapper->ChainExportMapper(new SvXMLExportPropertyMapper(new XMLPropertySetMapper(getCellPropertiesMap(), xFactoryRef.get(), true)));
181  }
182 
185 
198 }
199 
201 {
202 }
203 
204 static bool has_states( const std::vector< XMLPropertyState >& xPropStates )
205 {
206  return std::any_of(xPropStates.cbegin(), xPropStates.cend(),
207  [](const XMLPropertyState& rPropertyState) { return rPropertyState.mnIndex != -1; });
208 }
209 
210  void XMLTableExport::collectTableAutoStyles(const Reference < XColumnRowRange >& xColumnRowRange)
211  {
212  if( !mbExportTables )
213  return;
214 
215  std::shared_ptr< XMLTableInfo > xTableInfo( new XMLTableInfo );
216  maTableInfoMap[xColumnRowRange] = xTableInfo;
217 
218  try
219  {
220  Reference< XIndexAccess > xIndexAccessCols( xColumnRowRange->getColumns(), UNO_QUERY_THROW );
221  const sal_Int32 nColumnCount = xIndexAccessCols->getCount();
222  for( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn ) try
223  {
224  Reference< XPropertySet > xPropSet( xIndexAccessCols->getByIndex(nColumn) , UNO_QUERY_THROW );
225  std::vector< XMLPropertyState > aPropStates( mxColumnExportPropertySetMapper->Filter( xPropSet ) );
226 
227  if( has_states( aPropStates ) )
228  {
229  const OUString sStyleName( mrExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_TABLE_COLUMN, aPropStates) );
230  Reference< XInterface > xKey( xPropSet, UNO_QUERY );
231  xTableInfo->maColumnStyleMap[xKey] = sStyleName;
232  }
233  }
234  catch(const Exception&)
235  {
236  OSL_FAIL("xmloff::XMLTableExport::collectTableAutoStyles(), exception during column style collection!");
237  }
238 
239  Reference< XIndexAccess > xIndexAccessRows( xColumnRowRange->getRows(), UNO_QUERY_THROW );
240  const sal_Int32 nRowCount = xIndexAccessRows->getCount();
241  xTableInfo->maDefaultRowCellStyles.resize(nRowCount);
242 
243  StringStatisticHelper aStringStatistic;
244 
245  for( sal_Int32 nRow = 0; nRow < nRowCount; ++nRow )
246  try
247  {
248  Reference< XPropertySet > xPropSet( xIndexAccessRows->getByIndex(nRow) , UNO_QUERY_THROW );
249  std::vector< XMLPropertyState > aRowPropStates( mxRowExportPropertySetMapper->Filter( xPropSet ) );
250 
251  if( has_states( aRowPropStates ) )
252  {
253  const OUString sStyleName( mrExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_TABLE_ROW, aRowPropStates) );
254  Reference< XInterface > xKey( xPropSet, UNO_QUERY );
255  xTableInfo->maRowStyleMap[xKey] = sStyleName;
256  }
257 
258  // get the current row
259  Reference< XCellRange > xCellRange( xPropSet, UNO_QUERY_THROW );
260  for ( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
261  {
262  // get current cell, remarks row index is 0, because we get the range for each row separate
263  Reference< XPropertySet > xCellSet( xCellRange->getCellByPosition(nColumn, 0), UNO_QUERY_THROW );
264 
265  // get style
266  OUString sParentStyleName;
267  Reference< XPropertySetInfo > xPropertySetInfo( xCellSet->getPropertySetInfo() );
268  if( xPropertySetInfo.is() && xPropertySetInfo->hasPropertyByName("Style") )
269  {
270  Reference< XStyle > xStyle( xCellSet->getPropertyValue("Style"), UNO_QUERY );
271  if( xStyle.is() )
272  sParentStyleName = xStyle->getName();
273  }
274 
275  // create auto style, if needed
276  OUString sStyleName;
277  std::vector< XMLPropertyState > aCellPropStates( mxCellExportPropertySetMapper->Filter( xCellSet ) );
278  if( has_states( aCellPropStates ) )
279  sStyleName = mrExport.GetAutoStylePool()->Add(XML_STYLE_FAMILY_TABLE_CELL, aCellPropStates);
280  else
281  sStyleName = sParentStyleName;
282 
283  if( !sStyleName.isEmpty() )
284  {
285  Reference< XInterface > xKey( xCellSet, UNO_QUERY );
286  xTableInfo->maCellStyleMap[xKey] = sStyleName;
287  }
288 
289  // create auto style for text
290  Reference< XText > xText(xCellSet, UNO_QUERY);
291  if(xText.is() && !xText->getString().isEmpty())
292  GetExport().GetTextParagraphExport()->collectTextAutoStyles( xText );
293 
294  aStringStatistic.add( sStyleName );
295  }
296 
297  OUString sDefaultCellStyle;
298  if( aStringStatistic.getModeString( sDefaultCellStyle ) > 1 )
299  xTableInfo->maDefaultRowCellStyles[nRow] = sDefaultCellStyle;
300 
301  aStringStatistic.clear();
302  }
303  catch(const Exception&)
304  {
305  OSL_FAIL("xmloff::XMLTableExport::collectTableAutoStyles(), exception during column style collection!");
306  }
307  }
308  catch(const Exception&)
309  {
310  OSL_FAIL("xmloff::XMLTableExport::collectTableAutoStyles(), exception caught!");
311  }
312  }
313 
314  void XMLTableExport::exportTable( const Reference < XColumnRowRange >& xColumnRowRange )
315  {
316  if( !mbExportTables )
317  return;
318 
319  try
320  {
321  std::shared_ptr< XMLTableInfo > xTableInfo( maTableInfoMap[xColumnRowRange] );
322 
323  // get row and column count
324  Reference< XIndexAccess > xIndexAccess( xColumnRowRange->getRows(), UNO_QUERY_THROW );
325  Reference< XIndexAccess > xIndexAccessCols( xColumnRowRange->getColumns(), UNO_QUERY_THROW );
326 
327  const sal_Int32 rowCount = xIndexAccess->getCount();
328  const sal_Int32 columnCount = xIndexAccessCols->getCount();
329 
330  SvXMLElementExport tableElement( mrExport, XML_NAMESPACE_TABLE, XML_TABLE, true, true );
331 
332  // export table columns
333  ExportTableColumns( xIndexAccessCols, xTableInfo );
334 
335  // start iterating rows and columns
336  for ( sal_Int32 rowIndex = 0; rowIndex < rowCount; rowIndex++ )
337  {
338  // get the current row
339  Reference< XCellRange > xCellRange( xIndexAccess->getByIndex(rowIndex), UNO_QUERY_THROW );
340 
341  OUString sDefaultCellStyle;
342 
343  // table:style-name
344  if( xTableInfo.get() )
345  {
346  Reference< XInterface > xKey( xCellRange, UNO_QUERY );
347  const OUString sStyleName( xTableInfo->maRowStyleMap[xKey] );
348  if( !sStyleName.isEmpty() )
349  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, sStyleName );
350 
351  sDefaultCellStyle = xTableInfo->maDefaultRowCellStyles[rowIndex];
352  if( !sDefaultCellStyle.isEmpty() )
353  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_DEFAULT_CELL_STYLE_NAME, sDefaultCellStyle );
354  }
355 
356  // write row element
357  SvXMLElementExport tableRowElement( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_ROW, true, true );
358 
359  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 separate
362  Reference< XCell > xCell( xCellRange->getCellByPosition(columnIndex, 0), UNO_SET_THROW );
363 
364  // use XMergeableCell interface from offapi
365  Reference< XMergeableCell > xMergeableCell( xCell, UNO_QUERY_THROW );
366 
367  // export cell
368  ExportCell( xCell, xTableInfo, sDefaultCellStyle );
369  }
370  }
371  }
372  catch(const Exception&)
373  {
374  OSL_FAIL( "XMLTableExport::exportTable(), exception caught!" );
375  }
376  }
377 
378 // Export the table columns
379 
380  void XMLTableExport::ExportTableColumns( const Reference < XIndexAccess >& xtableColumnsIndexAccess, const std::shared_ptr< XMLTableInfo >& rTableInfo )
381  {
382  const sal_Int32 nColumnCount = xtableColumnsIndexAccess->getCount();
383  for( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
384  {
385  Reference< XPropertySet > xColumnProperties( xtableColumnsIndexAccess->getByIndex(nColumn) , UNO_QUERY );
386  if ( xColumnProperties.is() )
387  {
388  // table:style-name
389  if( rTableInfo.get() )
390  {
391  Reference< XInterface > xKey( xColumnProperties, UNO_QUERY );
392  const OUString sStyleName( rTableInfo->maColumnStyleMap[xKey] );
393  if( !sStyleName.isEmpty() )
394  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, sStyleName );
395  }
396 
397  // TODO: all columns first have to be checked if someone
398  // have identical properties. If yes, attr table:number-columns-repeated
399  // has to be written.
400  SvXMLElementExport tableColumnElement( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, true, true );
401  }
402  }
403  }
404 
405 // ODF export for a table cell.
406 
407  void XMLTableExport::ExportCell( const Reference < XCell >& xCell, const std::shared_ptr< XMLTableInfo >& rTableInfo, const OUString& rDefaultCellStyle )
408  {
409  bool bIsMerged = false;
410  sal_Int32 nRowSpan = 0;
411  sal_Int32 nColSpan = 0;
412 
413  try
414  {
415  if( rTableInfo.get() )
416  {
417  // table:style-name
418  Reference< XInterface > xKey( xCell, UNO_QUERY );
419  const OUString sStyleName( rTableInfo->maCellStyleMap[xKey] );
420  if( !sStyleName.isEmpty() && (sStyleName != rDefaultCellStyle) )
421  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, sStyleName );
422  }
423 
424  Reference< XMergeableCell > xMerge( xCell, UNO_QUERY );
425  if( xMerge.is() )
426  {
427  bIsMerged = xMerge->isMerged();
428  nRowSpan = xMerge->getRowSpan();
429  nColSpan = xMerge->getColumnSpan();
430  }
431  SAL_WARN_IF( (nRowSpan < 1) || (nColSpan < 1), "xmloff", "xmloff::XMLTableExport::ExportCell(), illegal row or col span < 1?" );
432  }
433  catch (const Exception&)
434  {
435  OSL_FAIL( "exception while exporting a table cell" );
436  }
437 
438  // table:number-columns-repeated
439  // todo
440 
441  // table:number-columns-spanned
442  if( nColSpan > 1 )
443  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_SPANNED, OUString::number( nColSpan ) );
444 
445  // table:number-rows-spanned
446  if( nRowSpan > 1 )
447  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_SPANNED, OUString::number( nRowSpan ) );
448 
449  // <table:table-cell> or <table:covered-table-cell>
450  SvXMLElementExport tableCellElement( mrExport, XML_NAMESPACE_TABLE, bIsMerged ? XML_COVERED_TABLE_CELL : XML_TABLE_CELL, true, true );
451 
452  // export cells text content
453  ImpExportText( xCell );
454  }
455 
456 // ODF export of the text contents of a table cell.
457 // Remarks: Up to now we only export text contents!
458 // TODO: Check against nested tables...
459 
460  void XMLTableExport::ImpExportText( const Reference< XCell >& xCell )
461  {
462  Reference< XText > xText( xCell, UNO_QUERY );
463  if( xText.is() && !xText->getString().isEmpty())
464  mrExport.GetTextParagraphExport()->exportText( xText );
465  }
466 
468 {
469  if( !mbExportTables )
470  return;
471 
473  OUString sCellStyleName;
474  if (mbWriter)
475  {
476  sCellStyleName = "CellStyles";
477  aStEx.set(new XMLStyleExport(mrExport));
478  }
479  else
480  {
481  // write graphic family styles
482  sCellStyleName = "cell";
483  aStEx.set(new XMLStyleExport(mrExport, mrExport.GetAutoStylePool().get()));
484  }
485 
486  aStEx->exportStyleFamily(sCellStyleName, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME), mxCellExportPropertySetMapper.get(), true, XML_STYLE_FAMILY_TABLE_CELL);
487 
489 }
490 
491 // Export the collected automatic styles
492 
494 {
495  if( !mbExportTables )
496  return;
497 
501 }
502 
504 {
505  static const struct TableStyleElement gTableStyleElements[] =
506  {
507  { XML_FIRST_ROW, OUString("first-row") },
508  { XML_LAST_ROW, OUString("last-row") },
509  { XML_FIRST_COLUMN, OUString("first-column") },
510  { XML_LAST_COLUMN, OUString("last-column") },
511  { XML_BODY, OUString("body") },
512  { XML_EVEN_ROWS, OUString("even-rows") },
513  { XML_ODD_ROWS, OUString("odd-rows") },
514  { XML_EVEN_COLUMNS, OUString("even-columns") },
515  { XML_ODD_COLUMNS, OUString("odd-columns") },
516  { XML_BACKGROUND, OUString("background") },
517  { XML_TOKEN_END, OUString() }
518  };
519 
520  return &gTableStyleElements[0];
521 }
522 
524 {
525  static const struct TableStyleElement gWriterSpecificTableStyleElements[] =
526  {
527  { XML_FIRST_ROW_EVEN_COLUMN, OUString("first-row-even-column") },
528  { XML_LAST_ROW_EVEN_COLUMN, OUString("last-row-even-column") },
529  { XML_FIRST_ROW_END_COLUMN, OUString("first-row-end-column") },
530  { XML_FIRST_ROW_START_COLUMN, OUString("first-row-start-column") },
531  { XML_LAST_ROW_END_COLUMN, OUString("last-row-end-column") },
532  { XML_LAST_ROW_START_COLUMN, OUString("last-row-start-column") },
533  { XML_TOKEN_END, OUString() }
534  };
535 
536  return &gWriterSpecificTableStyleElements[0];
537 }
538 
540 {
541  static const struct TableStyleElement gWriterSpecifitTableStyleAttributes[] =
542  {
543  { XML_FIRST_ROW_END_COLUMN, OUString("FirstRowEndColumn") },
544  { XML_FIRST_ROW_START_COLUMN, OUString("FirstRowStartColumn") },
545  { XML_LAST_ROW_END_COLUMN, OUString("LastRowEndColumn") },
546  { XML_LAST_ROW_START_COLUMN, OUString("LastRowStartColumn") },
547  { XML_TOKEN_END, OUString() }
548  };
549 
550  return &gWriterSpecifitTableStyleAttributes[0];
551 }
552 
554 {
555  if( !mbExportTables )
556  return;
557 
558  try
559  {
560  Reference< XStyleFamiliesSupplier > xFamiliesSupp( mrExport.GetModel(), UNO_QUERY_THROW );
561  Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
562  OUString sFamilyName;
563  if (mbWriter)
564  sFamilyName = "TableStyles";
565  else
566  sFamilyName = "table";
567 
568  Reference< XIndexAccess > xTableFamily( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
569 
570  for( sal_Int32 nIndex = 0; nIndex < xTableFamily->getCount(); nIndex++ ) try
571  {
573 
574  Reference< XStyle > xTableStyle( xTableFamily->getByIndex( nIndex ), UNO_QUERY_THROW );
575  if( !xTableStyle->isInUse() )
576  continue;
577 
578  const TableStyleElement* pElements;
579  if (mbWriter)
580  {
581  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, xTableStyle->getName());
582  Reference<XPropertySet> xTableStylePropSet(xTableStyle, UNO_QUERY_THROW);
584  while(pElements->meElement != XML_TOKEN_END)
585  {
586  try
587  {
588  OUString sVal;
589  xTableStylePropSet->getPropertyValue(pElements->msStyleName) >>= sVal;
590  mrExport.AddAttribute(XML_NAMESPACE_TABLE, pElements->meElement, sVal);
591  }
592  catch(const Exception&)
593  {
594  TOOLS_WARN_EXCEPTION("xmloff", "XMLTableExport::exportTableTemplates(), export Writer specific attributes, exception caught!");
595  }
596  pElements++;
597  }
598  }
599  else
600  {
601  // checks if any of the extended version of ODF are set
602  if ((eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0)
603  {
604  // tdf#106780 historically this wrong attribute was used
605  // for the name; write it if extended because LO < 5.3 can
606  // read only text:style-name, not the correct table:name
607  mrExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( xTableStyle->getName() ) );
608  }
609  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, GetExport().EncodeStyleName(xTableStyle->getName()));
610  }
611 
612  SvXMLElementExport tableTemplate( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_TEMPLATE, true, true );
613 
614  Reference< XNameAccess > xStyleNames( xTableStyle, UNO_QUERY_THROW );
615  pElements = getTableStyleMap();
616  while( pElements->meElement != XML_TOKEN_END )
617  {
618  try
619  {
620  Reference< XStyle > xStyle( xStyleNames->getByName( pElements->msStyleName ), UNO_QUERY );
621  if( xStyle.is() )
622  {
623  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, GetExport().EncodeStyleName( xStyle->getName() ) );
624  SvXMLElementExport element( mrExport, XML_NAMESPACE_TABLE, pElements->meElement, true, true );
625  }
626  }
627  catch(const Exception&)
628  {
629  OSL_FAIL("xmloff::XMLTableExport::exportTableTemplates(), exception caught!");
630  }
631 
632  pElements++;
633  }
634 
635  if (mbWriter && ((eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0))
636  {
637  pElements = getWriterSpecificTableStyleMap();
638  while(pElements->meElement != XML_TOKEN_END)
639  {
640  try
641  {
642  Reference<XStyle> xStyle(xStyleNames->getByName(pElements->msStyleName), UNO_QUERY);
643  if(xStyle.is())
644  {
645  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, GetExport().EncodeStyleName(xStyle->getName()));
646  SvXMLElementExport element(mrExport, XML_NAMESPACE_LO_EXT, pElements->meElement, true, true);
647  }
648  }
649  catch(const Exception&)
650  {
651  TOOLS_WARN_EXCEPTION("xmloff", "XMLTableExport::exportTableTemplates(), export Writer specific styles, exception caught!");
652  }
653  pElements++;
654  }
655  }
656  }
657  catch(const Exception&)
658  {
659  TOOLS_WARN_EXCEPTION("xmloff", "XMLTableExport::exportTableDesigns(), exception caught while exporting a table design!");
660  }
661  }
662  catch(const Exception&)
663  {
664  TOOLS_WARN_EXCEPTION("xmloff", "XMLTableExport::exportTableDesigns()");
665  }
666 }
667 
668 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const XMLPropertyMapEntry * getRowPropertiesMap()
#define XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME
Definition: families.hxx:54
static bool has_states(const std::vector< XMLPropertyState > &xPropStates)
#define XML_SD_TYPE_CELL_ROTATION_ANGLE
Definition: xmlsdtypes.hxx:121
void exportTableTemplates()
::xmloff::token::XMLTokenEnum const meElement
Definition: table.hxx:29
void exportTable(const css::uno::Reference< css::table::XColumnRowRange > &xColumnRowRange)
rtl::Reference< XMLTextParagraphExport > const & GetTextParagraphExport()
Definition: xmlexp.hxx:560
rtl::Reference< SvXMLExportPropertyMapper > mxColumnExportPropertySetMapper
#define XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX
Definition: families.hxx:55
#define XML_STYLE_FAMILY_TABLE_CELL
Definition: families.hxx:59
XMLTableExport(SvXMLExport &rExp, const rtl::Reference< SvXMLExportPropertyMapper > &xCellExportPropertySetMapper, const rtl::Reference< XMLPropertyHandlerFactory > &xFactoryRef)
SvXMLExport & GetExport()
void AddAttribute(sal_uInt16 nPrefix, const sal_Char *pName, const OUString &rValue)
Definition: xmlexp.cxx:923
#define RMAP(name, prefix, token, type, context)
#define XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX
Definition: families.hxx:61
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlexp.hxx:414
void ExportCell(const css::uno::Reference< css::table::XCell > &xCell, const std::shared_ptr< XMLTableInfo > &pTableInfo, const OUString &sDefaultCellStyle)
SvXMLExport & mrExport
#define CMAP(name, prefix, token, type, context)
#define XML_STYLE_FAMILY_TABLE_ROW
Definition: families.hxx:56
#define XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME
Definition: families.hxx:60
void add(const OUString &rStyleName)
SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const
returns the deterministic version for odf export
Definition: xmlexp.cxx:2280
#define CELLMAP(name, prefix, token, type, context)
#define TOOLS_WARN_EXCEPTION(area, stream)
const TableStyleElement * getTableStyleMap()
#define MAP_END
Represents a property with its API-name, its XML-name and the type of its value.
Definition: maptype.hxx:31
OUString msStyleName
Definition: table.hxx:30
void collectTableAutoStyles(const css::uno::Reference< css::table::XColumnRowRange > &xColumnRowRange)
const TableStyleElement * getWriterSpecificTableStyleMap()
SAL_DLLPRIVATE void ImpExportText(const css::uno::Reference< css::table::XCell > &xCell)
std::map< const css::uno::Reference< css::table::XColumnRowRange >, std::shared_ptr< XMLTableInfo > > maTableInfoMap
#define SAL_WARN_IF(condition, area, stream)
static const TableStyleElement * getWriterSpecificTableStyleAttributes()
rtl::Reference< SvXMLExportPropertyMapper > mxRowExportPropertySetMapper
rtl::Reference< SvXMLAutoStylePoolP > const & GetAutoStylePool()
Definition: xmlexp.hxx:576
sal_Int32 getModeString(OUString &rModeString)
#define XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX
Definition: families.hxx:58
#define XML_STYLE_FAMILY_TABLE_COLUMN
Definition: families.hxx:53
#define XML_TYPE_MEASURE
Definition: xmltypes.hxx:126
const XMLPropertyMapEntry * getCellPropertiesMap()
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:104
const XMLPropertyMapEntry * getColumnPropertiesMap()
#define XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME
Definition: families.hxx:57
virtual ~XMLTableExport() override
static SvXMLExportPropertyMapper * CreateParaExtPropMapper(SvXMLExport &rExport)
Definition: txtparae.cxx:1352
#define XML_TYPE_BOOL
Definition: xmltypes.hxx:125
rtl::Reference< SvXMLExportPropertyMapper > mxCellExportPropertySetMapper
std::map< OUString, sal_Int32 > mStats
void ExportTableColumns(const css::uno::Reference< css::container::XIndexAccess > &xtableColumns, const std::shared_ptr< XMLTableInfo > &pTableInfo)