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>
34#include <tools/diagnose_ex.h>
35
36#include <utility>
38#include <xmloff/xmlprmap.hxx>
39#include <xmloff/txtimp.hxx>
40#include <xmloff/xmlimp.hxx>
42#include <xmloff/xmlstyle.hxx>
43#include <xmloff/prstylei.hxx>
44
46#include <xmloff/xmluconv.hxx>
47#include "table.hxx"
48
49#include <sal/log.hxx>
50
51#include <memory>
52
53using namespace ::xmloff::token;
54using namespace ::com::sun::star::beans;
55using namespace ::com::sun::star::uno;
56using namespace ::com::sun::star::table;
57using namespace ::com::sun::star::xml::sax;
58using namespace ::com::sun::star::text;
59using namespace ::com::sun::star::style;
60using namespace ::com::sun::star::lang;
61using namespace ::com::sun::star::container;
62
63namespace {
64
65struct ColumnInfo
66{
67 OUString msStyleName;
68 OUString msDefaultCellStyleName;
69};
70
71class XMLProxyContext : public SvXMLImportContext
72{
73public:
74 XMLProxyContext( SvXMLImport& rImport, SvXMLImportContextRef xParent );
75
76 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
77 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
78
79private:
81};
82
83struct MergeInfo
84{
85 sal_Int32 mnStartColumn;
86 sal_Int32 mnStartRow;
87 sal_Int32 mnEndColumn;
88 sal_Int32 mnEndRow;
89
90 MergeInfo( sal_Int32 nStartColumn, sal_Int32 nStartRow, sal_Int32 nColumnSpan, sal_Int32 nRowSpan )
91 : mnStartColumn( nStartColumn ), mnStartRow( nStartRow ), mnEndColumn( nStartColumn + nColumnSpan - 1 ), mnEndRow( nStartRow + nRowSpan - 1 ) {};
92};
93
94}
95
97{
98public:
99 XMLTableImportContext( const rtl::Reference< XMLTableImport >& xThis, Reference< XColumnRowRange > const & xColumnRowRange );
100
101 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
102 sal_Int32 nElement,
103 const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
104
105 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
106
107 void InitColumns();
108
109 SvXMLImportContextRef ImportColumn( const Reference< XFastAttributeList >& xAttrList );
110 SvXMLImportContext * ImportRow( const Reference< XFastAttributeList >& xAttrList );
111 SvXMLImportContextRef ImportCell( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList );
112
113 OUString GetDefaultCellStyleName() const;
114
115 css::uno::Reference< css::table::XTable > mxTable;
116 Reference< XTableColumns > mxColumns;
117 Reference< XTableRows > mxRows;
118
119 std::vector< std::shared_ptr< ColumnInfo > > maColumnInfos;
120 sal_Int32 mnCurrentRow;
122
123 // default cell style name for the current row
125
126 std::vector< std::shared_ptr< MergeInfo > > maMergeInfos;
127};
128
129namespace {
130
131class XMLCellImportContext : public SvXMLImportContext
132{
133public:
134 XMLCellImportContext( SvXMLImport& rImport,
135 const Reference< XMergeableCell >& xCell,
136 const OUString& sDefaultCellStyleName,
137 sal_Int32 nElement,
138 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList );
139
140 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
141 sal_Int32 nElement,
142 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
143
144 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
145
146 sal_Int32 getColumnSpan() const { return mnColSpan; }
147 sal_Int32 getRowSpan() const { return mnRowSpan; }
148 sal_Int32 getRepeated() const { return mnRepeated; }
149
150 Reference< XMergeableCell > mxCell;
151 Reference< XTextCursor > mxCursor;
152 Reference< XTextCursor > mxOldCursor;
153 bool mbListContextPushed;
154
155 sal_Int32 mnColSpan, mnRowSpan, mnRepeated;
156};
157
158class XMLTableTemplateContext : public SvXMLStyleContext
159{
160public:
161 XMLTableTemplateContext( SvXMLImport& rImport );
162
163 // Create child element.
164 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
165 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
166
167 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
168
169 virtual void CreateAndInsert( bool bOverwrite ) override;
170protected:
171 virtual void SetAttribute( sal_Int32 nElement,
172 const OUString& rValue ) override;
173private:
174 XMLTableTemplate maTableTemplate;
175 OUString msTemplateStyleName;
176};
177
178}
179
180
181XMLProxyContext::XMLProxyContext( SvXMLImport& rImport, SvXMLImportContextRef xParent )
182: SvXMLImportContext( rImport )
183, mxParent(std::move( xParent ))
184{
185}
186
187css::uno::Reference< css::xml::sax::XFastContextHandler > XMLProxyContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList )
188{
189 if( mxParent.is() )
190 return mxParent->createFastChildContext( nElement, xAttrList );
191 return nullptr;
192}
193
194
196: mrImport( rImport )
197{
198 bool bWriter = false;
199 // check if called by Writer
200 Reference<XMultiServiceFactory> xFac(rImport.GetModel(), UNO_QUERY);
201 if (xFac.is()) try
202 {
203 Sequence<OUString> sSNS = xFac->getAvailableServiceNames();
204 bWriter = comphelper::findValue(sSNS, "com.sun.star.style.TableStyle") != -1;
205 }
206 catch(const Exception&)
207 {
208 SAL_WARN("xmloff.table", "Error while checking available service names");
209 }
210
211 if (bWriter)
212 {
214 }
215 else
216 {
217 mxCellImportPropertySetMapper = new SvXMLImportPropertyMapper( xCellPropertySetMapper, rImport );
219 mxCellImportPropertySetMapper->ChainImportMapper(new SvXMLImportPropertyMapper(new XMLPropertySetMapper(getCellPropertiesMap(), xFactoryRef, true), rImport));
220 }
221
223 mxRowImportPropertySetMapper = new SvXMLImportPropertyMapper( xRowMapper, rImport );
224
227}
228
230{
231}
232
233SvXMLImportContext* XMLTableImport::CreateTableContext( Reference< XColumnRowRange > const & xColumnRowRange )
234{
236 return new XMLTableImportContext( xThis, xColumnRowRange );
237}
238
239SvXMLStyleContext* XMLTableImport::CreateTableTemplateContext( sal_Int32 /*nElement*/, const Reference< XFastAttributeList >& /*xAttrList*/ )
240{
241 return new XMLTableTemplateContext( mrImport );
242}
243
244void XMLTableImport::addTableTemplate( const OUString& rsStyleName, XMLTableTemplate& xTableTemplate )
245{
246 auto xPtr = std::make_shared<XMLTableTemplate>();
247 xPtr->swap( xTableTemplate );
248 maTableTemplates[rsStyleName] = xPtr;
249}
250
251void XMLTableImport::insertTabletemplate(const OUString& rsStyleName, bool bOverwrite)
252{
253 XMLTableTemplateMap::iterator it = maTableTemplates.find(rsStyleName);
254 if (it == maTableTemplates.end())
255 return;
256
257 try
258 {
259 Reference<XStyleFamiliesSupplier> xFamiliesSupp(mrImport.GetModel(), UNO_QUERY_THROW);
260 Reference<XNameAccess> xFamilies(xFamiliesSupp->getStyleFamilies());
261
262 Reference<XNameContainer> xTableFamily(xFamilies->getByName("TableStyles"), UNO_QUERY_THROW);
263 Reference<XIndexAccess> xCellFamily(xFamilies->getByName("CellStyles"), UNO_QUERY_THROW);
264
265 const OUString sTemplateName(it->first);
266 Reference<XMultiServiceFactory> xFactory(mrImport.GetModel(), UNO_QUERY_THROW);
267 Reference<XNameReplace> xTemplate(xFactory->createInstance("com.sun.star.style.TableStyle"), UNO_QUERY_THROW);
268
269 std::shared_ptr<XMLTableTemplate> xT(it->second);
270
271 for (const auto& rStyle : *xT) try
272 {
273 const OUString sPropName(rStyle.first);
274 const OUString sStyleName(rStyle.second);
275 // Internally unassigned cell styles are stored by display name.
276 // However table-template elements reference cell styles by its encoded name.
277 // This loop is looking for cell style by their encoded names.
278 sal_Int32 nCount = xCellFamily->getCount();
279 for (sal_Int32 i=0; i < nCount; ++i)
280 {
281 Any xCellStyle = xCellFamily->getByIndex(i);
282 OUString sEncodedStyleName = mrImport.GetMM100UnitConverter().encodeStyleName(
283 xCellStyle.get<Reference<XStyle>>()->getName());
284 if (sEncodedStyleName == sStyleName)
285 {
286 xTemplate->replaceByName(sPropName, xCellStyle);
287 break;
288 }
289 }
290 }
291 catch (Exception const &)
292 {
293 TOOLS_WARN_EXCEPTION("xmloff.table", "XMLTableImport::insertTabletemplate()");
294 }
295
296 if (xTemplate.is())
297 {
298 if (xTableFamily->hasByName(sTemplateName) && bOverwrite)
299 xTableFamily->replaceByName(sTemplateName, Any(xTemplate));
300 else
301 xTableFamily->insertByName(sTemplateName, Any(xTemplate));
302 }
303 }
304 catch (Exception&)
305 {
306 TOOLS_WARN_EXCEPTION("xmloff.table", "XMLTableImport::insertTabletemplate()");
307 }
308}
309
311{
312 if( maTableTemplates.empty() )
313 return;
314
315 try
316 {
317 Reference< XStyleFamiliesSupplier > xFamiliesSupp( mrImport.GetModel(), UNO_QUERY_THROW );
318 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
319
320 Reference< XNameContainer > xTableFamily( xFamilies->getByName( "table" ), UNO_QUERY_THROW );
321 Reference< XNameAccess > xCellFamily( xFamilies->getByName( "cell" ), UNO_QUERY_THROW );
322
323 Reference< XSingleServiceFactory > xFactory( xTableFamily, UNO_QUERY_THROW );
324
325 for( const auto& rTemplate : maTableTemplates ) try
326 {
327 const OUString sTemplateName( rTemplate.first );
328 Reference< XNameReplace > xTemplate( xFactory->createInstance(), UNO_QUERY_THROW );
329
330 std::shared_ptr< XMLTableTemplate > xT( rTemplate.second );
331
332 for( const auto& rStyle : *xT ) try
333 {
334 const OUString sPropName( rStyle.first );
335 const OUString sStyleName( rStyle.second );
336 xTemplate->replaceByName( sPropName, xCellFamily->getByName( sStyleName ) );
337 }
338 catch( Exception& )
339 {
340 TOOLS_WARN_EXCEPTION("xmloff.table", "");
341 }
342
343 if( xTemplate.is() )
344 {
345 if( xTableFamily->hasByName( sTemplateName ) )
346 xTableFamily->replaceByName( sTemplateName, Any( xTemplate ) );
347 else
348 xTableFamily->insertByName( sTemplateName, Any( xTemplate ) );
349 }
350
351 }
352 catch( Exception& )
353 {
354 TOOLS_WARN_EXCEPTION("xmloff.table", "");
355 }
356 }
357 catch( Exception& )
358 {
359 TOOLS_WARN_EXCEPTION("xmloff.table", "");
360 }
361}
362
363
364XMLTableImportContext::XMLTableImportContext( const rtl::Reference< XMLTableImport >& xImporter, Reference< XColumnRowRange > const & xColumnRowRange )
365: SvXMLImportContext( xImporter->mrImport )
366, mxTable( xColumnRowRange, UNO_QUERY )
367, mxColumns( xColumnRowRange->getColumns() )
368, mxRows( xColumnRowRange->getRows() )
369, mnCurrentRow( -1 )
370, mnCurrentColumn( -1 )
371{
372}
373
374SvXMLImportContextRef XMLTableImportContext::ImportColumn( const Reference< XFastAttributeList >& xAttrList )
375{
376 if( mxColumns.is() && (mnCurrentRow == -1) ) try
377 {
378 auto xInfo = std::make_shared<ColumnInfo>();
379
380 sal_Int32 nRepeated = 1;
381
382 // read attributes for the table-column
383 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
384 {
385 switch (aIter.getToken())
386 {
388 nRepeated = aIter.toInt32();
389 break;
391 xInfo->msStyleName = aIter.toString();
392 break;
394 xInfo->msDefaultCellStyleName = aIter.toString();
395 break;
396 case XML_ELEMENT(XML, XML_ID):
397 //FIXME: TODO
398 break;
399 }
400 }
401
402 if( nRepeated <= 1 )
403 {
404 maColumnInfos.push_back( xInfo );
405 }
406 else
407 {
408 maColumnInfos.insert( maColumnInfos.end(), nRepeated, xInfo );
409 }
410 }
411 catch( Exception& )
412 {
413 TOOLS_WARN_EXCEPTION("xmloff.table", "");
414 }
415
416 return nullptr;
417}
418
420{
421 if( !mxColumns.is() )
422 return;
423
424 try
425 {
426 const sal_Int32 nCount1 = mxColumns->getCount();
427 const sal_Int32 nCount2 = sal::static_int_cast< sal_Int32 >( maColumnInfos.size() );
428 if( nCount1 < nCount2 )
429 mxColumns->insertByIndex( nCount1, nCount2 - nCount1 );
430
431 SvXMLStylesContext * pAutoStyles = GetImport().GetShapeImport()->GetAutoStylesContext();
432
433 for( sal_Int32 nCol = 0; nCol < nCount2; nCol++ )
434 {
435 std::shared_ptr< ColumnInfo > xInfo( maColumnInfos[nCol] );
436
437 if( pAutoStyles && !xInfo->msStyleName.isEmpty() )
438 {
439 const XMLPropStyleContext* pStyle =
440 dynamic_cast< const XMLPropStyleContext* >(
441 pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_COLUMN, xInfo->msStyleName) );
442
443 if( pStyle )
444 {
445 Reference< XPropertySet > xColProps( mxColumns->getByIndex(nCol), UNO_QUERY_THROW );
446 const_cast< XMLPropStyleContext* >( pStyle )->FillPropertySet( xColProps );
447 }
448 }
449
450 }
451 }
452 catch( Exception& )
453 {
454 TOOLS_WARN_EXCEPTION("xmloff.table", "");
455 }
456}
457
458SvXMLImportContext * XMLTableImportContext::ImportRow( const Reference< XFastAttributeList >& xAttrList )
459{
460 if( mxRows.is() )
461 {
462 mnCurrentRow++;
463 if( mnCurrentRow == 0 )
464 InitColumns(); // first init columns
465
466 mnCurrentColumn = -1;
467
468 const sal_Int32 nRowCount = mxRows->getCount();
469 if( ( nRowCount - 1) < mnCurrentRow )
470 {
471 const sal_Int32 nCount = mnCurrentRow - nRowCount + 1;
472 mxRows->insertByIndex( nRowCount, nCount );
473 }
474
475 Reference< XPropertySet > xRowSet( mxRows->getByIndex(mnCurrentRow), UNO_QUERY );
476
477 OUString sStyleName;
478
479 // read attributes for the table-row
480 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
481 {
482 switch(aIter.getToken())
483 {
485 sStyleName = aIter.toString();
486 break;
488 msDefaultCellStyleName = aIter.toString();
489 break;
490 case XML_ELEMENT(XML, XML_ID):
491 //FIXME: TODO
492 break;
493 }
494 }
495
496 if( !sStyleName.isEmpty() )
497 {
498 SvXMLStylesContext * pAutoStyles = GetImport().GetShapeImport()->GetAutoStylesContext();
499 if( pAutoStyles )
500 {
501 const XMLPropStyleContext* pStyle =
502 dynamic_cast< const XMLPropStyleContext* >(
503 pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_ROW, sStyleName) );
504
505 if( pStyle )
506 {
507 const_cast< XMLPropStyleContext* >( pStyle )->FillPropertySet( xRowSet );
508 }
509 }
510 }
511 }
512
513 SvXMLImportContextRef xThis( this );
514 return new XMLProxyContext( GetImport(), xThis );
515}
516
517SvXMLImportContextRef XMLTableImportContext::ImportCell( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList )
518{
520 if( mxColumns.is() ) try
521 {
522 if( mxColumns->getCount() <= mnCurrentColumn )
523 mxColumns->insertByIndex( mxColumns->getCount(), mnCurrentColumn - mxColumns->getCount() + 1 );
524
525 Reference< XMergeableCell > xCell( mxTable->getCellByPosition( mnCurrentColumn, mnCurrentRow ), UNO_QUERY_THROW );
526 XMLCellImportContext* pCellContext = new XMLCellImportContext( GetImport(), xCell, GetDefaultCellStyleName(), nElement, xAttrList );
527
528 const sal_Int32 nColumnSpan = pCellContext->getColumnSpan();
529 const sal_Int32 nRowSpan = pCellContext->getRowSpan();
530 if( (nColumnSpan > 1) || (nRowSpan > 1) )
531 maMergeInfos.push_back( std::make_shared< MergeInfo >( mnCurrentColumn, mnCurrentRow, nColumnSpan, nRowSpan ) );
532
533 const sal_Int32 nRepeated = pCellContext->getRepeated();
534 if( nRepeated > 1 )
535 {
536 OSL_FAIL("xmloff::XMLTableImportContext::ImportCell(), import of repeated Cells not implemented (TODO)");
537 mnCurrentColumn += nRepeated - 1;
538 }
539
540 return pCellContext;
541 }
542 catch( Exception& )
543 {
544 TOOLS_WARN_EXCEPTION("xmloff.table", "");
545 }
546
547 return nullptr;
548}
549
550css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTableImportContext::createFastChildContext(
551 sal_Int32 nElement,
552 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
553{
554 switch (nElement)
555 {
558 return ImportCell( nElement, xAttrList );
560 return ImportColumn( xAttrList );
562 return ImportRow( xAttrList );
565 {
566 SvXMLImportContextRef xThis( this );
567 return new XMLProxyContext( GetImport(), xThis );
568 }
569 }
570 SAL_WARN("xmloff", "unknown element");
571 return nullptr;
572}
573
575{
576 for( const std::shared_ptr< MergeInfo >& xInfo : maMergeInfos )
577 {
578 if( xInfo ) try
579 {
580 Reference< XCellRange > xRange( mxTable->getCellRangeByPosition( xInfo->mnStartColumn, xInfo->mnStartRow, xInfo->mnEndColumn, xInfo->mnEndRow ) );
581 Reference< XMergeableCellRange > xCursor( mxTable->createCursorByRange( xRange ), UNO_QUERY_THROW );
582 xCursor->merge();
583 }
584 catch( Exception& )
585 {
586 TOOLS_WARN_EXCEPTION("xmloff.table", "");
587 }
588 }
589}
590
592{
593 OUString sStyleName( msDefaultCellStyleName );
594
595 // if there is still no style name, try default style name from column
596 if( (sStyleName.isEmpty()) && (mnCurrentColumn < sal::static_int_cast<sal_Int32>(maColumnInfos.size())) )
597 sStyleName = maColumnInfos[mnCurrentColumn]->msDefaultCellStyleName;
598
599 return sStyleName;
600}
601
602// XMLCellImportContext
603
604XMLCellImportContext::XMLCellImportContext( SvXMLImport& rImport,
605 const Reference< XMergeableCell >& xCell,
606 const OUString& sDefaultCellStyleName,
607 sal_Int32 /*nElement*/,
608 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
609: SvXMLImportContext( rImport )
610, mxCell( xCell )
611, mbListContextPushed( false )
612, mnColSpan( 1 )
613, mnRowSpan( 1 )
614, mnRepeated( 1 )
615{
616 OUString sStyleName;
617
618 // read attributes for the table-cell
619 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
620 {
621 switch (aIter.getToken())
622 {
624 mnRepeated = aIter.toInt32();
625 break;
627 mnColSpan = aIter.toInt32();
628 break;
630 mnRowSpan = aIter.toInt32();
631 break;
632 case XML_ELEMENT(TABLE, XML_STYLE_NAME):
633 sStyleName = aIter.toString();
634 break;
635 case XML_ELEMENT(XML, XML_ID):
636//FIXME: TODO
637 break;
638//FIXME: RDFa (table:table-cell)
639 default:
640 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
641 }
642 }
643
644 // if there is no style name at the cell, try default style name from row
645 if( sStyleName.isEmpty() )
646 sStyleName = sDefaultCellStyleName;
647
648 if( sStyleName.isEmpty() )
649 return;
650
651 SvXMLStylesContext * pAutoStyles = GetImport().GetShapeImport()->GetAutoStylesContext();
652 if( !pAutoStyles )
653 return;
654
655 const XMLPropStyleContext* pStyle =
656 dynamic_cast< const XMLPropStyleContext* >(
657 pAutoStyles->FindStyleChildContext(XmlStyleFamily::TABLE_CELL, sStyleName) );
658
659 if( pStyle )
660 {
661 Reference< XPropertySet > xCellSet( mxCell, UNO_QUERY );
662 if( xCellSet.is() )
663 const_cast< XMLPropStyleContext* >( pStyle )->FillPropertySet( xCellSet );
664 }
665}
666
667css::uno::Reference< css::xml::sax::XFastContextHandler > XMLCellImportContext::createFastChildContext(
668 sal_Int32 nElement,
669 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
670{
671 // create text cursor on demand
672 if( !mxCursor.is() )
673 {
674 Reference< XText > xText( mxCell, UNO_QUERY );
675 if( xText.is() )
676 {
677 rtl::Reference < XMLTextImportHelper > xTxtImport( GetImport().GetTextImport() );
678 mxOldCursor = xTxtImport->GetCursor();
679 mxCursor = xText->createTextCursor();
680 if( mxCursor.is() )
681 xTxtImport->SetCursor( mxCursor );
682
683 // remember old list item and block (#91964#) and reset them
684 // for the text frame
685 xTxtImport->PushListContext();
686 mbListContextPushed = true;
687 }
688 }
689
690 SvXMLImportContext * pContext = nullptr;
691
692 // if we have a text cursor, lets try to import some text
693 if( mxCursor.is() )
694 {
695 pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nElement, xAttrList );
696 }
697
698 if (!pContext)
699 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
700 return pContext;
701}
702
703void XMLCellImportContext::endFastElement(sal_Int32 )
704{
705 if(mxCursor.is())
706 {
707 // delete addition newline
708 mxCursor->gotoEnd( false );
709 mxCursor->goLeft( 1, true );
710 mxCursor->setString( "" );
711
712 // reset cursor
713 GetImport().GetTextImport()->ResetCursor();
714 }
715
716 if(mxOldCursor.is())
717 GetImport().GetTextImport()->SetCursor( mxOldCursor );
718
719 // reinstall old list item (if necessary) #91964#
720 if (mbListContextPushed) {
721 GetImport().GetTextImport()->PopListContext();
722 }
723}
724
725
726XMLTableTemplateContext::XMLTableTemplateContext( SvXMLImport& rImport )
728{
729}
730
731void XMLTableTemplateContext::SetAttribute( sal_Int32 nElement,
732 const OUString& rValue )
733{
734 if( nElement == XML_ELEMENT(TEXT, XML_STYLE_NAME)
735 // Writer specific: according to oasis odf 1.2 prefix should be "table" and element name should be "name"
736 || nElement == XML_ELEMENT(TABLE, XML_NAME) )
737 {
738 msTemplateStyleName = rValue;
739 }
740}
741
742void XMLTableTemplateContext::endFastElement(sal_Int32 )
743{
744 rtl::Reference< XMLTableImport > xTableImport( GetImport().GetShapeImport()->GetShapeTableImport() );
745 if( xTableImport.is() )
746 xTableImport->addTableTemplate( msTemplateStyleName, maTableTemplate );
747}
748
749void XMLTableTemplateContext::CreateAndInsert(bool bOverwrite)
750{
751 rtl::Reference<XMLTableImport> xTableImport(GetImport().GetShapeImport()->GetShapeTableImport());
752 if(xTableImport.is())
753 xTableImport->insertTabletemplate(msTemplateStyleName, bOverwrite);
754}
755
756css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTableTemplateContext::createFastChildContext(
757 sal_Int32 nElement,
758 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
759{
761 {
762 const TableStyleElement* pElements = getTableStyleMap();
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 } else if (IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT)) // Writer specific cell styles
783 {
785 sal_Int32 nLocalName = nElement & TOKEN_MASK;
786 while( (pElements->meElement != XML_TOKEN_END) && pElements->meElement != nLocalName)
787 pElements++;
788
789 if (pElements->meElement != XML_TOKEN_END)
790 {
791 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
792 {
793 switch (aIter.getToken())
794 {
795 case XML_ELEMENT(TEXT, XML_STYLE_NAME):
797 maTableTemplate[pElements->msStyleName] = aIter.toString();
798 break;
799 default:
800 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
801 }
802 }
803 }
804 }
805
806 return nullptr;
807}
808
809/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString msStyleName
std::map< OUString, OUString > XMLTableTemplate
WeakReference< XInterface > 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
rtl::Reference< XMLShapeImportHelper > const & GetShapeImport()
Definition: xmlimp.hxx:610
const SvXMLUnitConverter & GetMM100UnitConverter() const
Definition: xmlimp.hxx:401
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlimp.hxx:405
virtual void SetAttribute(sal_Int32 nElement, const OUString &rValue)
Definition: xmlstyle.cxx:69
virtual void CreateAndInsert(bool bOverwrite)
Definition: xmlstyle.cxx:135
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
Definition: xmlstyle.cxx:799
OUString encodeStyleName(const OUString &rName, bool *pEncoded=nullptr) const
Definition: xmluconv.cxx:819
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)
void insertTabletemplate(const OUString &rsStyleName, bool bOverwrite)
Inserts to the doc template with given name.
SvXMLImport & mrImport
rtl::Reference< SvXMLImportPropertyMapper > mxRowImportPropertySetMapper
static SvXMLImportPropertyMapper * CreateParaExtPropMapper(SvXMLImport &)
Definition: txtimp.cxx:560
static SvXMLImportPropertyMapper * CreateTableCellExtPropMapper(SvXMLImport &)
Definition: txtimp.cxx:599
int nCount
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XSingleServiceFactory > xFactory
XmlStyleFamily
Definition: families.hxx:50
#define SAL_WARN(area, stream)
@ Exception
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
int i
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:649
@ XML_NUMBER_COLUMNS_SPANNED
Definition: xmltoken.hxx:1407
@ XML_NUMBER_ROWS_SPANNED
Definition: xmltoken.hxx:1413
@ XML_NUMBER_COLUMNS_REPEATED
Definition: xmltoken.hxx:1406
sal_Int32 toInt32(OUString const &rStr)
::xmloff::token::XMLTokenEnum meElement
Definition: table.hxx:28
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:98
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
Definition: xmlimp.hxx:105
constexpr sal_Int32 TOKEN_MASK
Definition: xmlimp.hxx:95
constexpr sal_uInt16 XML_NAMESPACE_TABLE
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT