LibreOffice Module xmloff (master) 1
XMLTableImport.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
20#include <sal/config.h>
21
22#include <com/sun/star/frame/XModel.hpp>
23#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
24#include <com/sun/star/table/XTableRows.hpp>
25#include <com/sun/star/table/XMergeableCell.hpp>
26#include <com/sun/star/table/XMergeableCellRange.hpp>
27#include <com/sun/star/table/XTable.hpp>
28#include <com/sun/star/text/XText.hpp>
29#include <com/sun/star/container/XNameContainer.hpp>
30#include <com/sun/star/lang/XMultiServiceFactory.hpp>
31#include <com/sun/star/lang/XSingleServiceFactory.hpp>
32#include <com/sun/star/style/XStyle.hpp>
35
36#include <utility>
38#include <xmloff/xmltypes.hxx>
39#include <xmloff/maptype.hxx>
40#include <xmloff/xmlprmap.hxx>
41#include <xmloff/txtimp.hxx>
42#include <xmloff/xmlimp.hxx>
44#include <xmloff/xmlstyle.hxx>
45#include <xmloff/prstylei.hxx>
46
48#include <xmloff/xmluconv.hxx>
49#include "table.hxx"
50
51#include <sal/log.hxx>
52
53#include <memory>
54
55using namespace ::xmloff::token;
56using namespace ::com::sun::star::beans;
57using namespace ::com::sun::star::uno;
58using namespace ::com::sun::star::table;
59using namespace ::com::sun::star::xml::sax;
60using namespace ::com::sun::star::text;
61using namespace ::com::sun::star::style;
62using namespace ::com::sun::star::lang;
63using namespace ::com::sun::star::container;
64
65namespace {
66
67struct ColumnInfo
68{
69 OUString msStyleName;
70 OUString msDefaultCellStyleName;
71};
72
73class XMLProxyContext : public SvXMLImportContext
74{
75public:
76 XMLProxyContext( SvXMLImport& rImport, SvXMLImportContextRef xParent );
77
78 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
79 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
80
81private:
83};
84
85struct MergeInfo
86{
87 sal_Int32 mnStartColumn;
88 sal_Int32 mnStartRow;
89 sal_Int32 mnEndColumn;
90 sal_Int32 mnEndRow;
91
92 MergeInfo( sal_Int32 nStartColumn, sal_Int32 nStartRow, sal_Int32 nColumnSpan, sal_Int32 nRowSpan )
93 : mnStartColumn( nStartColumn ), mnStartRow( nStartRow ), mnEndColumn( nStartColumn + nColumnSpan - 1 ), mnEndRow( nStartRow + nRowSpan - 1 ) {};
94};
95
96class XMLCellImportPropertyMapper : public SvXMLImportPropertyMapper
97{
98public:
100
102 XMLPropertyState& rProperty,
103 std::vector< XMLPropertyState >& rProperties,
104 const OUString& rValue,
105 const SvXMLUnitConverter& rUnitConverter,
106 const SvXMLNamespaceMap& /*rNamespaceMap*/) const override
107 {
108 assert(getPropertySetMapper()->GetEntryXMLName(rProperty.mnIndex) == GetXMLToken(XML_BACKGROUND_COLOR));
109 (void)rProperty;
110
112 XMLPropertyState aFillProperty(nIndex);
113
114 if (IsXMLToken(rValue, XML_TRANSPARENT))
115 {
116 getPropertySetMapper()->importXML(GetXMLToken(XML_NONE), aFillProperty, rUnitConverter);
117 rProperties.push_back(aFillProperty);
118 }
119 else
120 {
121 getPropertySetMapper()->importXML(GetXMLToken(XML_SOLID), aFillProperty, rUnitConverter);
122 rProperties.push_back(aFillProperty);
123
125 XMLPropertyState aColorProperty(nIndex);
126 getPropertySetMapper()->importXML(rValue, aColorProperty, rUnitConverter);
127 rProperties.push_back(aColorProperty);
128 }
129
130 return false;
131 }
132};
133
134}
135
137{
138public:
139 XMLTableImportContext( const rtl::Reference< XMLTableImport >& xThis, Reference< XColumnRowRange > const & xColumnRowRange );
140
141 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
142 sal_Int32 nElement,
143 const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
144
145 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
146
147 void InitColumns();
148
149 SvXMLImportContextRef ImportColumn( const Reference< XFastAttributeList >& xAttrList );
150 SvXMLImportContext * ImportRow( const Reference< XFastAttributeList >& xAttrList );
151 SvXMLImportContextRef ImportCell( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList );
152
153 OUString GetDefaultCellStyleName() const;
154
155 css::uno::Reference< css::table::XTable > mxTable;
156 Reference< XTableColumns > mxColumns;
157 Reference< XTableRows > mxRows;
158
159 std::vector< std::shared_ptr< ColumnInfo > > maColumnInfos;
160 sal_Int32 mnCurrentRow;
162
163 // default cell style name for the current row
165
166 std::vector< std::shared_ptr< MergeInfo > > maMergeInfos;
167};
168
169namespace {
170
171class XMLCellImportContext : public SvXMLImportContext
172{
173public:
174 XMLCellImportContext( SvXMLImport& rImport,
175 const Reference< XMergeableCell >& xCell,
176 const OUString& sDefaultCellStyleName,
177 sal_Int32 nElement,
178 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList );
179
180 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
181 sal_Int32 nElement,
182 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
183
184 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
185
186 sal_Int32 getColumnSpan() const { return mnColSpan; }
187 sal_Int32 getRowSpan() const { return mnRowSpan; }
188 sal_Int32 getRepeated() const { return mnRepeated; }
189
190 Reference< XMergeableCell > mxCell;
191 Reference< XTextCursor > mxCursor;
192 Reference< XTextCursor > mxOldCursor;
193 bool mbListContextPushed;
194
195 sal_Int32 mnColSpan, mnRowSpan, mnRepeated;
196};
197
198class XMLTableTemplateContext : public SvXMLStyleContext
199{
200public:
201 XMLTableTemplateContext( SvXMLImport& rImport );
202
203 // Create child element.
204 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
205 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
206
207 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
208
209protected:
210 virtual void SetAttribute( sal_Int32 nElement,
211 const OUString& rValue ) override;
212private:
213 XMLTableTemplate maTableTemplate;
214 OUString msTemplateStyleName;
215};
216
217}
218
219
220XMLProxyContext::XMLProxyContext( SvXMLImport& rImport, SvXMLImportContextRef xParent )
221: SvXMLImportContext( rImport )
222, mxParent(std::move( xParent ))
223{
224}
225
226css::uno::Reference< css::xml::sax::XFastContextHandler > XMLProxyContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList )
227{
228 if( mxParent.is() )
229 return mxParent->createFastChildContext( nElement, xAttrList );
230 return nullptr;
231}
232
233
234XMLTableImport::XMLTableImport( SvXMLImport& rImport, const rtl::Reference< XMLPropertySetMapper >& xCellPropertySetMapper, const rtl::Reference< XMLPropertyHandlerFactory >& xFactoryRef )
235: mrImport( rImport )
236, mbWriter( false )
237{
238 // check if called by Writer
239 Reference<XMultiServiceFactory> xFac(rImport.GetModel(), UNO_QUERY);
240 if (xFac.is()) try
241 {
242 Sequence<OUString> sSNS = xFac->getAvailableServiceNames();
243 mbWriter = comphelper::findValue(sSNS, "com.sun.star.style.TableStyle") != -1;
244 }
245 catch(const Exception&)
246 {
247 SAL_WARN("xmloff.table", "Error while checking available service names");
248 }
249
250 if (mbWriter)
251 {
253 }
254 else
255 {
256 mxCellImportPropertySetMapper = new SvXMLImportPropertyMapper( xCellPropertySetMapper, rImport );
258 mxCellImportPropertySetMapper->ChainImportMapper(new XMLCellImportPropertyMapper(new XMLPropertySetMapper(getCellPropertiesMap(), xFactoryRef, true), rImport));
259 }
260
262 mxRowImportPropertySetMapper = new SvXMLImportPropertyMapper( xRowMapper, rImport );
263
266}
267
269{
270}
271
272SvXMLImportContext* XMLTableImport::CreateTableContext( Reference< XColumnRowRange > const & xColumnRowRange )
273{
275 return new XMLTableImportContext( xThis, xColumnRowRange );
276}
277
278SvXMLStyleContext* XMLTableImport::CreateTableTemplateContext( sal_Int32 /*nElement*/, const Reference< XFastAttributeList >& /*xAttrList*/ )
279{
280 return new XMLTableTemplateContext( mrImport );
281}
282
283void XMLTableImport::addTableTemplate( const OUString& rsStyleName, XMLTableTemplate& xTableTemplate )
284{
285 auto xPtr = std::make_shared<XMLTableTemplate>();
286 xPtr->swap( xTableTemplate );
287 maTableTemplates.emplace_back(rsStyleName, xPtr);
288}
289
291{
292 if( maTableTemplates.empty() )
293 return;
294
295 try
296 {
297 Reference< XStyleFamiliesSupplier > xFamiliesSupp( mrImport.GetModel(), UNO_QUERY_THROW );
298 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
299
300 const OUString aTableFamily(mbWriter ? u"TableStyles" : u"table");
301 const OUString aCellFamily(mbWriter ? u"CellStyles" : u"cell");
302 Reference< XNameContainer > xTableFamily( xFamilies->getByName( aTableFamily ), UNO_QUERY_THROW );
303 Reference< XNameAccess > xCellFamily( xFamilies->getByName( aCellFamily ), UNO_QUERY_THROW );
304
305 Reference< XSingleServiceFactory > xFactory( xTableFamily, UNO_QUERY );
306 assert(xFactory.is() != mbWriter);
307 Reference< XMultiServiceFactory > xMultiFactory( mrImport.GetModel(), UNO_QUERY_THROW );
308
309 for( const auto& rTemplate : maTableTemplates ) try
310 {
311 const OUString sTemplateName( rTemplate.first );
312 Reference< XNameReplace > xTemplate(xFactory ? xFactory->createInstance() :
313 xMultiFactory->createInstance("com.sun.star.style.TableStyle"), UNO_QUERY_THROW);
314
315 std::shared_ptr< XMLTableTemplate > xT( rTemplate.second );
316
317 for( const auto& rStyle : *xT ) try
318 {
319 const OUString sPropName( rStyle.first );
320 const OUString sStyleName( mrImport.GetStyleDisplayName(XmlStyleFamily::TABLE_CELL, rStyle.second) );
321 xTemplate->replaceByName( sPropName, xCellFamily->getByName( sStyleName ) );
322 }
323 catch( Exception& )
324 {
325 TOOLS_WARN_EXCEPTION("xmloff.table", "");
326 }
327
328 if( xTemplate.is() )
329 {
330 if( xTableFamily->hasByName( sTemplateName ) )
331 xTableFamily->replaceByName( sTemplateName, Any( xTemplate ) );
332 else
333 xTableFamily->insertByName( sTemplateName, Any( xTemplate ) );
334 }
335
336 }
337 catch( Exception& )
338 {
339 TOOLS_WARN_EXCEPTION("xmloff.table", "");
340 }
341 }
342 catch( Exception& )
343 {
344 TOOLS_WARN_EXCEPTION("xmloff.table", "");
345 }
346}
347
348
349XMLTableImportContext::XMLTableImportContext( const rtl::Reference< XMLTableImport >& xImporter, Reference< XColumnRowRange > const & xColumnRowRange )
350: SvXMLImportContext( xImporter->mrImport )
351, mxTable( xColumnRowRange, UNO_QUERY )
352, mxColumns( xColumnRowRange->getColumns() )
353, mxRows( xColumnRowRange->getRows() )
354, mnCurrentRow( -1 )
355, mnCurrentColumn( -1 )
356{
357}
358
359SvXMLImportContextRef XMLTableImportContext::ImportColumn( const Reference< XFastAttributeList >& xAttrList )
360{
361 if( mxColumns.is() && (mnCurrentRow == -1) ) try
362 {
363 auto xInfo = std::make_shared<ColumnInfo>();
364
365 sal_Int32 nRepeated = 1;
366
367 // read attributes for the table-column
368 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
369 {
370 switch (aIter.getToken())
371 {
373 nRepeated = aIter.toInt32();
374 break;
376 xInfo->msStyleName = aIter.toString();
377 break;
379 xInfo->msDefaultCellStyleName = aIter.toString();
380 break;
381 case XML_ELEMENT(XML, XML_ID):
382 //FIXME: TODO
383 break;
384 }
385 }
386
387 if( nRepeated <= 1 )
388 {
389 maColumnInfos.push_back( xInfo );
390 }
391 else
392 {
393 maColumnInfos.insert( maColumnInfos.end(), nRepeated, xInfo );
394 }
395 }
396 catch( Exception& )
397 {
398 TOOLS_WARN_EXCEPTION("xmloff.table", "");
399 }
400
401 return nullptr;
402}
403
405{
406 if( !mxColumns.is() )
407 return;
408
409 try
410 {
411 const sal_Int32 nCount1 = mxColumns->getCount();
412 const sal_Int32 nCount2 = sal::static_int_cast< sal_Int32 >( maColumnInfos.size() );
413 if( nCount1 < nCount2 )
414 mxColumns->insertByIndex( nCount1, nCount2 - nCount1 );
415
416 SvXMLStylesContext * pAutoStyles = GetImport().GetShapeImport()->GetAutoStylesContext();
417
418 for( sal_Int32 nCol = 0; nCol < nCount2; nCol++ )
419 {
420 std::shared_ptr< ColumnInfo > xInfo( maColumnInfos[nCol] );
421
422 if( pAutoStyles && !xInfo->msStyleName.isEmpty() )
423 {
424 const XMLPropStyleContext* pStyle =
425 dynamic_cast< const XMLPropStyleContext* >(
426 pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_COLUMN, xInfo->msStyleName) );
427
428 if( pStyle )
429 {
430 Reference< XPropertySet > xColProps( mxColumns->getByIndex(nCol), UNO_QUERY_THROW );
431 const_cast< XMLPropStyleContext* >( pStyle )->FillPropertySet( xColProps );
432 }
433 }
434
435 }
436 }
437 catch( Exception& )
438 {
439 TOOLS_WARN_EXCEPTION("xmloff.table", "");
440 }
441}
442
443SvXMLImportContext * XMLTableImportContext::ImportRow( const Reference< XFastAttributeList >& xAttrList )
444{
445 if( mxRows.is() )
446 {
447 mnCurrentRow++;
448 if( mnCurrentRow == 0 )
449 InitColumns(); // first init columns
450
451 mnCurrentColumn = -1;
452
453 const sal_Int32 nRowCount = mxRows->getCount();
454 if( ( nRowCount - 1) < mnCurrentRow )
455 {
456 const sal_Int32 nCount = mnCurrentRow - nRowCount + 1;
457 mxRows->insertByIndex( nRowCount, nCount );
458 }
459
460 Reference< XPropertySet > xRowSet( mxRows->getByIndex(mnCurrentRow), UNO_QUERY );
461
462 OUString sStyleName;
463
464 // read attributes for the table-row
465 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
466 {
467 switch(aIter.getToken())
468 {
470 sStyleName = aIter.toString();
471 break;
473 msDefaultCellStyleName = aIter.toString();
474 break;
475 case XML_ELEMENT(XML, XML_ID):
476 //FIXME: TODO
477 break;
478 }
479 }
480
481 if( !sStyleName.isEmpty() )
482 {
483 SvXMLStylesContext * pAutoStyles = GetImport().GetShapeImport()->GetAutoStylesContext();
484 if( pAutoStyles )
485 {
486 const XMLPropStyleContext* pStyle =
487 dynamic_cast< const XMLPropStyleContext* >(
488 pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_ROW, sStyleName) );
489
490 if( pStyle )
491 {
492 const_cast< XMLPropStyleContext* >( pStyle )->FillPropertySet( xRowSet );
493 }
494 }
495 }
496 }
497
498 SvXMLImportContextRef xThis( this );
499 return new XMLProxyContext( GetImport(), xThis );
500}
501
502SvXMLImportContextRef XMLTableImportContext::ImportCell( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList )
503{
505 if( mxColumns.is() ) try
506 {
507 if( mxColumns->getCount() <= mnCurrentColumn )
508 mxColumns->insertByIndex( mxColumns->getCount(), mnCurrentColumn - mxColumns->getCount() + 1 );
509
510 Reference< XMergeableCell > xCell( mxTable->getCellByPosition( mnCurrentColumn, mnCurrentRow ), UNO_QUERY_THROW );
511 XMLCellImportContext* pCellContext = new XMLCellImportContext( GetImport(), xCell, GetDefaultCellStyleName(), nElement, xAttrList );
512
513 const sal_Int32 nColumnSpan = pCellContext->getColumnSpan();
514 const sal_Int32 nRowSpan = pCellContext->getRowSpan();
515 if( (nColumnSpan > 1) || (nRowSpan > 1) )
516 maMergeInfos.push_back( std::make_shared< MergeInfo >( mnCurrentColumn, mnCurrentRow, nColumnSpan, nRowSpan ) );
517
518 const sal_Int32 nRepeated = pCellContext->getRepeated();
519 if( nRepeated > 1 )
520 {
521 OSL_FAIL("xmloff::XMLTableImportContext::ImportCell(), import of repeated Cells not implemented (TODO)");
522 mnCurrentColumn += nRepeated - 1;
523 }
524
525 return pCellContext;
526 }
527 catch( Exception& )
528 {
529 TOOLS_WARN_EXCEPTION("xmloff.table", "");
530 }
531
532 return nullptr;
533}
534
535css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTableImportContext::createFastChildContext(
536 sal_Int32 nElement,
537 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
538{
539 switch (nElement)
540 {
543 return ImportCell( nElement, xAttrList );
545 return ImportColumn( xAttrList );
547 return ImportRow( xAttrList );
550 {
551 SvXMLImportContextRef xThis( this );
552 return new XMLProxyContext( GetImport(), xThis );
553 }
554 }
555 SAL_WARN("xmloff", "unknown element");
556 return nullptr;
557}
558
560{
561 for( const std::shared_ptr< MergeInfo >& xInfo : maMergeInfos )
562 {
563 if( xInfo ) try
564 {
565 Reference< XCellRange > xRange( mxTable->getCellRangeByPosition( xInfo->mnStartColumn, xInfo->mnStartRow, xInfo->mnEndColumn, xInfo->mnEndRow ) );
566 Reference< XMergeableCellRange > xCursor( mxTable->createCursorByRange( xRange ), UNO_QUERY_THROW );
567 xCursor->merge();
568 }
569 catch( Exception& )
570 {
571 TOOLS_WARN_EXCEPTION("xmloff.table", "");
572 }
573 }
574}
575
577{
578 OUString sStyleName( msDefaultCellStyleName );
579
580 // if there is still no style name, try default style name from column
581 if( (sStyleName.isEmpty()) && (mnCurrentColumn < sal::static_int_cast<sal_Int32>(maColumnInfos.size())) )
582 sStyleName = maColumnInfos[mnCurrentColumn]->msDefaultCellStyleName;
583
584 return sStyleName;
585}
586
587// XMLCellImportContext
588
589XMLCellImportContext::XMLCellImportContext( SvXMLImport& rImport,
590 const Reference< XMergeableCell >& xCell,
591 const OUString& sDefaultCellStyleName,
592 sal_Int32 /*nElement*/,
593 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
594: SvXMLImportContext( rImport )
595, mxCell( xCell )
596, mbListContextPushed( false )
597, mnColSpan( 1 )
598, mnRowSpan( 1 )
599, mnRepeated( 1 )
600{
601 OUString sStyleName;
602
603 // read attributes for the table-cell
604 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
605 {
606 switch (aIter.getToken())
607 {
609 mnRepeated = aIter.toInt32();
610 break;
612 mnColSpan = aIter.toInt32();
613 break;
615 mnRowSpan = aIter.toInt32();
616 break;
617 case XML_ELEMENT(TABLE, XML_STYLE_NAME):
618 sStyleName = aIter.toString();
619 break;
620 case XML_ELEMENT(XML, XML_ID):
621//FIXME: TODO
622 break;
623//FIXME: RDFa (table:table-cell)
624 default:
625 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
626 }
627 }
628
629 // if there is no style name at the cell, try default style name from row
630 if( sStyleName.isEmpty() )
631 sStyleName = sDefaultCellStyleName;
632
633 if( sStyleName.isEmpty() )
634 return;
635
636 SvXMLStylesContext * pAutoStyles = GetImport().GetShapeImport()->GetAutoStylesContext();
637 if( !pAutoStyles )
638 return;
639
640 const XMLPropStyleContext* pStyle =
641 dynamic_cast< const XMLPropStyleContext* >(
642 pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL, sStyleName) );
643
644 if( pStyle )
645 {
646 Reference< XPropertySet > xCellSet( mxCell, UNO_QUERY );
647 if( xCellSet.is() )
648 const_cast< XMLPropStyleContext* >( pStyle )->FillPropertySet( xCellSet );
649 }
650}
651
652css::uno::Reference< css::xml::sax::XFastContextHandler > XMLCellImportContext::createFastChildContext(
653 sal_Int32 nElement,
654 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
655{
656 // create text cursor on demand
657 if( !mxCursor.is() )
658 {
659 Reference< XText > xText( mxCell, UNO_QUERY );
660 if( xText.is() )
661 {
662 rtl::Reference < XMLTextImportHelper > xTxtImport( GetImport().GetTextImport() );
663 mxOldCursor = xTxtImport->GetCursor();
664 mxCursor = xText->createTextCursor();
665 if( mxCursor.is() )
666 xTxtImport->SetCursor( mxCursor );
667
668 // remember old list item and block (#91964#) and reset them
669 // for the text frame
670 xTxtImport->PushListContext();
671 mbListContextPushed = true;
672 }
673 }
674
675 SvXMLImportContext * pContext = nullptr;
676
677 // if we have a text cursor, lets try to import some text
678 if( mxCursor.is() )
679 {
680 pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nElement, xAttrList );
681 }
682
683 if (!pContext)
684 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
685 return pContext;
686}
687
688void XMLCellImportContext::endFastElement(sal_Int32 )
689{
690 if(mxCursor.is())
691 {
692 // delete addition newline
693 mxCursor->gotoEnd( false );
694 mxCursor->goLeft( 1, true );
695 mxCursor->setString( "" );
696
697 // reset cursor
698 GetImport().GetTextImport()->ResetCursor();
699 }
700
701 if(mxOldCursor.is())
702 GetImport().GetTextImport()->SetCursor( mxOldCursor );
703
704 // reinstall old list item (if necessary) #91964#
705 if (mbListContextPushed) {
706 GetImport().GetTextImport()->PopListContext();
707 }
708}
709
710
711XMLTableTemplateContext::XMLTableTemplateContext( SvXMLImport& rImport )
713{
714}
715
716void XMLTableTemplateContext::SetAttribute( sal_Int32 nElement,
717 const OUString& rValue )
718{
719 if( nElement == XML_ELEMENT(TEXT, XML_STYLE_NAME)
720 // Writer specific: according to oasis odf 1.2 prefix should be "table" and element name should be "name"
721 || nElement == XML_ELEMENT(TABLE, XML_NAME) )
722 {
723 msTemplateStyleName = rValue;
724 }
725}
726
727void XMLTableTemplateContext::endFastElement(sal_Int32 )
728{
729 rtl::Reference< XMLTableImport > xTableImport( GetImport().GetShapeImport()->GetShapeTableImport() );
730 if( xTableImport.is() )
731 xTableImport->addTableTemplate( msTemplateStyleName, maTableTemplate );
732}
733
734css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTableTemplateContext::createFastChildContext(
735 sal_Int32 nElement,
736 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
737{
739 {
740 const TableStyleElement* pElements = getTableStyleMap();
741 sal_Int32 nLocalName = nElement & TOKEN_MASK;
742 while( (pElements->meElement != XML_TOKEN_END) && pElements->meElement != nLocalName)
743 pElements++;
744
745 if( pElements->meElement != XML_TOKEN_END )
746 {
747 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
748 {
749 switch (aIter.getToken())
750 {
751 case XML_ELEMENT(TEXT, XML_STYLE_NAME):
753 maTableTemplate[pElements->msStyleName] = aIter.toString();
754 break;
755 default:
756 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
757 }
758 }
759 }
760 } else if (IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT)) // Writer specific cell styles
761 {
763 sal_Int32 nLocalName = nElement & TOKEN_MASK;
764 while( (pElements->meElement != XML_TOKEN_END) && pElements->meElement != nLocalName)
765 pElements++;
766
767 if (pElements->meElement != XML_TOKEN_END)
768 {
769 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
770 {
771 switch (aIter.getToken())
772 {
773 case XML_ELEMENT(TEXT, XML_STYLE_NAME):
775 maTableTemplate[pElements->msStyleName] = aIter.toString();
776 break;
777 default:
778 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
779 }
780 }
781 }
782 }
783
784 return nullptr;
785}
786
787/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString msStyleName
std::map< OUString, OUString > XMLTableTemplate
unotools::WeakReference< AnimationNode > mxParent
constexpr OUStringLiteral sTemplateName
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
Definition: xmlictxt.cxx:40
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
Definition: xmlictxt.cxx:59
virtual bool handleSpecialItem(XMLPropertyState &rProperty, ::std::vector< XMLPropertyState > &rProperties, const OUString &rValue, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap) const
this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set
Definition: xmlimppr.cxx:346
const rtl::Reference< XMLPropertySetMapper > & getPropertySetMapper() const
Definition: xmlimppr.hxx:197
SvXMLImportPropertyMapper(SvXMLImportPropertyMapper const &)=delete
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue)
Definition: xmlstyle.cxx:71
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
Definition: xmlstyle.cxx:810
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
SvXMLImportContext * ImportRow(const Reference< XFastAttributeList > &xAttrList)
Reference< XTableRows > mxRows
XMLTableImportContext(const rtl::Reference< XMLTableImport > &xThis, Reference< XColumnRowRange > const &xColumnRowRange)
SvXMLImportContextRef ImportColumn(const Reference< XFastAttributeList > &xAttrList)
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
OUString GetDefaultCellStyleName() const
css::uno::Reference< css::table::XTable > mxTable
std::vector< std::shared_ptr< ColumnInfo > > maColumnInfos
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
std::vector< std::shared_ptr< MergeInfo > > maMergeInfos
Reference< XTableColumns > mxColumns
SvXMLImportContextRef ImportCell(sal_Int32 nElement, const Reference< XFastAttributeList > &xAttrList)
virtual ~XMLTableImport() override
void finishStyles()
Inserts all table templates.
friend class XMLTableImportContext
SvXMLImportContext * CreateTableContext(css::uno::Reference< css::table::XColumnRowRange > const &xColumnRowRange)
XMLTableImport(SvXMLImport &rImport, const rtl::Reference< XMLPropertySetMapper > &xCellPropertySetMapper, const rtl::Reference< XMLPropertyHandlerFactory > &xFactoryRef)
XMLTableTemplateMap maTableTemplates
rtl::Reference< SvXMLImportPropertyMapper > mxCellImportPropertySetMapper
rtl::Reference< SvXMLImportPropertyMapper > mxColumnImportPropertySetMapper
SvXMLStyleContext * CreateTableTemplateContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
void addTableTemplate(const OUString &rsStyleName, XMLTableTemplate &xTableTemplate)
SvXMLImport & mrImport
rtl::Reference< SvXMLImportPropertyMapper > mxRowImportPropertySetMapper
static SvXMLImportPropertyMapper * CreateParaExtPropMapper(SvXMLImport &)
Definition: txtimp.cxx:559
static SvXMLImportPropertyMapper * CreateTableCellExtPropMapper(SvXMLImport &)
Definition: txtimp.cxx:598
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
float u
Reference< XSingleServiceFactory > xFactory
XmlStyleFamily
Definition: families.hxx:50
sal_Int32 nIndex
#define SAL_WARN(area, stream)
@ Exception
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString toString(OptionInfo const *info)
Handling of tokens in XML:
@ XML_COVERED_TABLE_CELL
Definition: xmltoken.hxx:539
@ XML_DEFAULT_CELL_STYLE_NAME
Definition: xmltoken.hxx:650
@ XML_NUMBER_COLUMNS_SPANNED
Definition: xmltoken.hxx:1409
@ XML_NUMBER_ROWS_SPANNED
Definition: xmltoken.hxx:1415
@ XML_NUMBER_COLUMNS_REPEATED
Definition: xmltoken.hxx:1408
@ XML_BACKGROUND_COLOR
Definition: xmltoken.hxx:312
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3585
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3529
sal_Int32 toInt32(std::u16string_view rStr)
::xmloff::token::XMLTokenEnum meElement
Definition: table.hxx:28
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:140
sal_Int32 mnIndex
Definition: maptype.hxx:141
const XMLPropertyMapEntry * getColumnPropertiesMap()
const TableStyleElement * getTableStyleMap()
const TableStyleElement * getWriterSpecificTableStyleMap()
const XMLPropertyMapEntry * getRowPropertiesMap()
const XMLPropertyMapEntry * getCellPropertiesMap()
sal_Int32 mnColSpan
sal_Int32 mnRowSpan
TABLE
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
Definition: xmlictxt.hxx:120
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
Definition: xmlimp.hxx:104
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:94
constexpr sal_uInt16 XML_NAMESPACE_DRAW
constexpr sal_uInt16 XML_NAMESPACE_TABLE
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT