1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLTableImport.cxx,v $
10 * $Revision: 1.4.2.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
35 #include <com/sun/star/table/XTableRows.hpp>
36 #include <com/sun/star/table/XMergeableCell.hpp>
37 #include <com/sun/star/table/XMergeableCellRange.hpp>
38 #include <com/sun/star/table/XTable.hpp>
39 #include <com/sun/star/text/XText.hpp>
40 #include <com/sun/star/container/XNameContainer.hpp>
41 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
43 #include "xmloff/table/XMLTableImport.hxx"
44 #include "xmloff/xmltkmap.hxx"
45 #include "xmloff/maptype.hxx"
46 #include "xmloff/xmlprmap.hxx"
47 #include "xmloff/txtimp.hxx"
48 #include "xmloff/xmlimp.hxx"
49 #include "xmloff/nmspmap.hxx"
50 #include "xmloff/xmlstyle.hxx"
51 #include "xmloff/prstylei.hxx"
52 #include "xmloff/xmlimp.hxx"
54 #include "xmlnmspe.hxx"
57 #include <boost/shared_ptr.hpp>
59 // --------------------------------------------------------------------
61 using ::rtl::OUString
;
62 using namespace ::xmloff::token
;
63 using namespace ::com::sun::star::beans
;
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::table
;
66 using namespace ::com::sun::star::xml::sax
;
67 using namespace ::com::sun::star::text
;
68 using namespace ::com::sun::star::style
;
69 using namespace ::com::sun::star::lang
;
70 using namespace ::com::sun::star::container
;
72 // --------------------------------------------------------------------
77 sal_Bool mbVisibility
;
78 OUString msDefaultCellStyleName
;
81 // --------------------------------------------------------------------
83 class XMLProxyContext
: public SvXMLImportContext
86 XMLProxyContext( SvXMLImport
& rImport
, const SvXMLImportContextRef
& xParent
, USHORT nPrfx
, const OUString
& rLName
);
88 virtual SvXMLImportContext
*CreateChildContext( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
);
91 SvXMLImportContextRef mxParent
;
94 // --------------------------------------------------------------------
98 sal_Int32 mnStartColumn
;
100 sal_Int32 mnEndColumn
;
103 MergeInfo( sal_Int32 nStartColumn
, sal_Int32 nStartRow
, sal_Int32 nColumnSpan
, sal_Int32 nRowSpan
)
104 : mnStartColumn( nStartColumn
), mnStartRow( nStartRow
), mnEndColumn( nStartColumn
+ nColumnSpan
- 1 ), mnEndRow( nStartRow
+ nRowSpan
- 1 ) {};
107 typedef std::vector
< boost::shared_ptr
< MergeInfo
> > MergeInfoVector
;
109 // --------------------------------------------------------------------
111 class XMLTableImportContext
: public SvXMLImportContext
114 XMLTableImportContext( const rtl::Reference
< XMLTableImport
>& xThis
, USHORT nPrfx
, const OUString
& rLName
, Reference
< XColumnRowRange
>& xColumnRowRange
);
115 virtual ~XMLTableImportContext();
117 virtual SvXMLImportContext
*CreateChildContext( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
);
119 virtual void StartElement( const Reference
< XAttributeList
>& xAttrList
);
121 virtual void EndElement();
125 SvXMLImportContext
* ImportColumn( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
);
126 SvXMLImportContext
* ImportRow( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
);
127 SvXMLImportContext
* ImportCell( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
);
129 OUString
GetDefaultCellStyleName() const;
131 rtl::Reference
< XMLTableImport
> mxTableImporter
;
132 ::com::sun::star::uno::Reference
< ::com::sun::star::table::XTable
> mxTable
;
133 Reference
< XTableColumns
> mxColumns
;
134 Reference
< XTableRows
> mxRows
;
136 std::vector
< boost::shared_ptr
< ColumnInfo
> > maColumnInfos
;
137 sal_Int32 mnCurrentRow
;
138 sal_Int32 mnCurrentColumn
;
140 // default cell style name for the current row
141 OUString msDefaultCellStyleName
;
143 MergeInfoVector maMergeInfos
;
146 // --------------------------------------------------------------------
148 class XMLCellImportContext
: public SvXMLImportContext
151 XMLCellImportContext( SvXMLImport
& rImport
,
152 const Reference
< XMergeableCell
>& xCell
,
153 const OUString
& sDefaultCellStyleName
,
154 USHORT nPrfx
, const OUString
& rLName
,
155 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
);
157 virtual ~XMLCellImportContext();
159 virtual SvXMLImportContext
*CreateChildContext( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
);
161 virtual void EndElement();
163 sal_Int32
getColumnSpan() const { return mnColSpan
; }
164 sal_Int32
getRowSpan() const { return mnRowSpan
; }
165 sal_Int32
getRepeated() const { return mnRepeated
; }
167 Reference
< XMergeableCell
> mxCell
;
168 Reference
< XTextCursor
> mxCursor
;
169 Reference
< XTextCursor
> mxOldCursor
;
170 bool mbListContextPushed
;
172 sal_Int32 mnColSpan
, mnRowSpan
, mnRepeated
;
175 // --------------------------------------------------------------------
177 class XMLTableTemplateContext
: public SvXMLStyleContext
180 XMLTableTemplateContext( SvXMLImport
& rImport
, USHORT nPrfx
, const OUString
& rLName
, const Reference
< XAttributeList
>& xAttrList
);
182 virtual SvXMLImportContext
*CreateChildContext( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
);
184 virtual void StartElement( const Reference
< XAttributeList
>& xAttrList
);
186 virtual void EndElement();
189 XMLTableTemplate maTableTemplate
;
190 OUString msTemplateStyleName
;
193 // --------------------------------------------------------------------
194 // class XMLProxyContext
195 // --------------------------------------------------------------------
197 XMLProxyContext::XMLProxyContext( SvXMLImport
& rImport
, const SvXMLImportContextRef
& xParent
, USHORT nPrfx
, const OUString
& rLName
)
198 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
199 , mxParent( xParent
)
203 // --------------------------------------------------------------------
205 SvXMLImportContext
* XMLProxyContext::CreateChildContext( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
)
208 return mxParent
->CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
210 return SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
213 // --------------------------------------------------------------------
214 // class XMLTableImport
215 // --------------------------------------------------------------------
217 XMLTableImport::XMLTableImport( SvXMLImport
& rImport
, const rtl::Reference
< XMLPropertySetMapper
>& xCellPropertySetMapper
, const rtl::Reference
< XMLPropertyHandlerFactory
>& xFactoryRef
)
218 : mrImport( rImport
)
220 mxCellImportPropertySetMapper
= new SvXMLImportPropertyMapper( xCellPropertySetMapper
.get(), rImport
);
221 mxCellImportPropertySetMapper
->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(rImport
));
224 UniReference
< XMLPropertySetMapper
> xRowMapper( new XMLPropertySetMapper( getRowPropertiesMap(), xFactoryRef
.get() ) );
225 mxRowImportPropertySetMapper
= new SvXMLImportPropertyMapper( xRowMapper
, rImport
);
227 UniReference
< XMLPropertySetMapper
> xColMapper( new XMLPropertySetMapper( getColumnPropertiesMap(), xFactoryRef
.get() ) );
228 mxColumnImportPropertySetMapper
= new SvXMLImportPropertyMapper( xColMapper
, rImport
);
231 // --------------------------------------------------------------------
233 XMLTableImport::~XMLTableImport()
237 // --------------------------------------------------------------------
239 SvXMLImportContext
* XMLTableImport::CreateTableContext( USHORT nPrfx
, const OUString
& rLName
, Reference
< XColumnRowRange
>& xColumnRowRange
)
241 rtl::Reference
< XMLTableImport
> xThis( this );
242 return new XMLTableImportContext( xThis
, nPrfx
, rLName
, xColumnRowRange
);
245 // --------------------------------------------------------------------
247 SvXMLStyleContext
* XMLTableImport::CreateTableTemplateContext( USHORT nPrfx
, const OUString
& rLName
, const Reference
< XAttributeList
>& xAttrList
)
249 return new XMLTableTemplateContext( mrImport
, nPrfx
, rLName
, xAttrList
);
252 // --------------------------------------------------------------------
254 void XMLTableImport::addTableTemplate( const rtl::OUString
& rsStyleName
, XMLTableTemplate
& xTableTemplate
)
256 boost::shared_ptr
< XMLTableTemplate
> xPtr( new XMLTableTemplate
);
257 xPtr
->swap( xTableTemplate
);
258 maTableTemplates
[rsStyleName
] = xPtr
;
261 // --------------------------------------------------------------------
263 void XMLTableImport::finishStyles()
265 if( !maTableTemplates
.empty() ) try
267 Reference
< XStyleFamiliesSupplier
> xFamiliesSupp( mrImport
.GetModel(), UNO_QUERY_THROW
);
268 Reference
< XNameAccess
> xFamilies( xFamiliesSupp
->getStyleFamilies() );
269 const OUString
sFamilyName( RTL_CONSTASCII_USTRINGPARAM("table" ) );
270 const OUString
sCellFamilyName( RTL_CONSTASCII_USTRINGPARAM("cell") );
272 Reference
< XNameContainer
> xTableFamily( xFamilies
->getByName( sFamilyName
), UNO_QUERY_THROW
);
273 Reference
< XNameAccess
> xCellFamily( xFamilies
->getByName( sCellFamilyName
), UNO_QUERY_THROW
);
275 Reference
< XSingleServiceFactory
> xFactory( xTableFamily
, UNO_QUERY_THROW
);
277 for( XMLTableTemplateMap::iterator
aTemplateIter( maTableTemplates
.begin() ); aTemplateIter
!= maTableTemplates
.end(); aTemplateIter
++ ) try
279 const OUString
sTemplateName( (*aTemplateIter
).first
);
280 Reference
< XNameReplace
> xTemplate( xFactory
->createInstance(), UNO_QUERY_THROW
);
282 boost::shared_ptr
< XMLTableTemplate
> xT( (*aTemplateIter
).second
);
284 for( XMLTableTemplate::iterator
aStyleIter( xT
->begin() ); aStyleIter
!= xT
->end(); aStyleIter
++ ) try
286 const OUString
sPropName( (*aStyleIter
).first
);
287 const OUString
sStyleName( (*aStyleIter
).second
);
288 xTemplate
->replaceByName( sPropName
, xCellFamily
->getByName( sStyleName
) );
292 DBG_ERROR("xmloff::XMLTableImport::finishStyles(), exception caught!");
297 if( xTableFamily
->hasByName( sTemplateName
) )
298 xTableFamily
->replaceByName( sTemplateName
, Any( xTemplate
) );
300 xTableFamily
->insertByName( sTemplateName
, Any( xTemplate
) );
306 DBG_ERROR("xmloff::XMLTableImport::finishStyles(), exception caught!");
311 DBG_ERROR("xmloff::XMLTableImport::finishStyles(), exception caught!");
315 // --------------------------------------------------------------------
316 // class XMLTableImport
317 // --------------------------------------------------------------------
320 XMLTableImportContext::XMLTableImportContext( const rtl::Reference
< XMLTableImport
>& xImporter
, USHORT nPrfx
, const OUString
& rLName
, Reference
< XColumnRowRange
>& xColumnRowRange
)
321 : SvXMLImportContext( xImporter
->mrImport
, nPrfx
, rLName
)
322 , mxTableImporter( xImporter
)
323 , mxTable( xColumnRowRange
, UNO_QUERY
)
324 , mxColumns( xColumnRowRange
->getColumns() )
325 , mxRows( xColumnRowRange
->getRows() )
327 , mnCurrentColumn( -1 )
331 // --------------------------------------------------------------------
333 XMLTableImportContext::~XMLTableImportContext()
337 // --------------------------------------------------------------------
339 SvXMLImportContext
* XMLTableImportContext::ImportColumn( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
)
341 if( mxColumns
.is() && (mnCurrentRow
== -1) ) try
343 boost::shared_ptr
< ColumnInfo
> xInfo ( new ColumnInfo
);
345 sal_Int32 nRepeated
= 1;
347 // read attributes for the table-column
348 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
349 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
351 const OUString
sAttrName( xAttrList
->getNameByIndex( i
) );
352 const OUString
sValue( xAttrList
->getValueByIndex( i
) );
355 sal_uInt16 nPrefix2
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
356 if( XML_NAMESPACE_TABLE
== nPrefix2
)
358 if( IsXMLToken( aLocalName
, XML_NUMBER_COLUMNS_REPEATED
) )
360 nRepeated
= sValue
.toInt32();
362 else if( IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
364 xInfo
->msStyleName
= sValue
;
366 else if( IsXMLToken( aLocalName
, XML_DEFAULT_CELL_STYLE_NAME
) )
368 xInfo
->msDefaultCellStyleName
= sValue
;
370 else if( IsXMLToken( aLocalName
, XML_VISIBILITY
) )
372 xInfo
->mbVisibility
= IsXMLToken( sValue
, XML_VISIBLE
);
375 else if ( (XML_NAMESPACE_XML
== nPrefix2
) &&
376 IsXMLToken(aLocalName
, XML_ID
) )
385 maColumnInfos
.push_back( xInfo
);
389 maColumnInfos
.insert( maColumnInfos
.end(), nRepeated
, xInfo
);
394 DBG_ERROR("xmloff::XMLTableImportContext::ImportTableColumn(), exception caught!");
397 return SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
400 // --------------------------------------------------------------------
402 void XMLTableImportContext::InitColumns()
404 if( mxColumns
.is() ) try
406 const sal_Int32 nCount1
= mxColumns
->getCount();
407 const sal_Int32 nCount2
= sal::static_int_cast
< sal_Int32
>( maColumnInfos
.size() );
408 if( nCount1
< nCount2
)
409 mxColumns
->insertByIndex( nCount1
, nCount2
- nCount1
);
411 SvXMLStylesContext
* pAutoStyles
= GetImport().GetShapeImport()->GetAutoStylesContext();
413 for( sal_Int32 nCol
= 0; nCol
< nCount2
; nCol
++ )
415 boost::shared_ptr
< ColumnInfo
> xInfo( maColumnInfos
[nCol
] );
417 if( pAutoStyles
&& xInfo
->msStyleName
.getLength() )
419 const XMLPropStyleContext
* pStyle
=
420 dynamic_cast< const XMLPropStyleContext
* >(
421 pAutoStyles
->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN
, xInfo
->msStyleName
) );
425 Reference
< XPropertySet
> xColProps( mxColumns
->getByIndex(nCol
), UNO_QUERY_THROW
);
426 const_cast< XMLPropStyleContext
* >( pStyle
)->FillPropertySet( xColProps
);
434 DBG_ERROR("xmloff::XMLTableImportContext::ImportTableColumn(), exception caught!");
438 // --------------------------------------------------------------------
440 SvXMLImportContext
* XMLTableImportContext::ImportRow( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
)
445 if( mnCurrentRow
== 0 )
446 InitColumns(); // first init columns
448 mnCurrentColumn
= -1;
450 const sal_Int32 nRowCount
= mxRows
->getCount();
451 if( ( nRowCount
- 1) < mnCurrentRow
)
453 const sal_Int32 nCount
= mnCurrentRow
- nRowCount
+ 1;
454 mxRows
->insertByIndex( nRowCount
, nCount
);
457 Reference
< XPropertySet
> xRowSet( mxRows
->getByIndex(mnCurrentRow
), UNO_QUERY
);
459 sal_Int32 nRepeated
= 1;
461 sal_Bool bVisibility
= sal_True
;
463 // read attributes for the table-row
464 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
465 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
467 const OUString
sAttrName( xAttrList
->getNameByIndex( i
) );
468 const OUString
sValue( xAttrList
->getValueByIndex( i
) );
471 sal_uInt16 nPrefix2
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
472 if( nPrefix2
== XML_NAMESPACE_TABLE
)
474 if( IsXMLToken( aLocalName
, XML_NUMBER_ROWS_REPEATED
) )
476 nRepeated
= sValue
.toInt32();
478 else if( IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
482 else if( IsXMLToken( aLocalName
, XML_DEFAULT_CELL_STYLE_NAME
) )
484 msDefaultCellStyleName
= sValue
;
486 else if( IsXMLToken( aLocalName
, XML_VISIBILITY
) )
488 bVisibility
= IsXMLToken( sValue
, XML_VISIBLE
);
491 else if ( (XML_NAMESPACE_XML
== nPrefix2
) &&
492 IsXMLToken(aLocalName
, XML_ID
) )
499 if( sStyleName
.getLength() )
501 SvXMLStylesContext
* pAutoStyles
= GetImport().GetShapeImport()->GetAutoStylesContext();
504 const XMLPropStyleContext
* pStyle
=
505 dynamic_cast< const XMLPropStyleContext
* >(
506 pAutoStyles
->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_ROW
, sStyleName
) );
510 const_cast< XMLPropStyleContext
* >( pStyle
)->FillPropertySet( xRowSet
);
516 SvXMLImportContextRef
xThis( this );
517 return new XMLProxyContext( GetImport(), xThis
, nPrefix
, rLocalName
);
520 // --------------------------------------------------------------------
522 SvXMLImportContext
* XMLTableImportContext::ImportCell( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
)
525 if( mxColumns
.is() ) try
527 if( mxColumns
->getCount() <= mnCurrentColumn
)
528 mxColumns
->insertByIndex( mxColumns
->getCount(), mnCurrentColumn
- mxColumns
->getCount() + 1 );
530 Reference
< XMergeableCell
> xCell( mxTable
->getCellByPosition( mnCurrentColumn
, mnCurrentRow
), UNO_QUERY_THROW
);
531 XMLCellImportContext
* pCellContext
= new XMLCellImportContext( GetImport(), xCell
, GetDefaultCellStyleName(), nPrefix
, rLocalName
, xAttrList
);
533 const sal_Int32 nColumnSpan
= pCellContext
->getColumnSpan();
534 const sal_Int32 nRowSpan
= pCellContext
->getRowSpan();
535 if( (nColumnSpan
> 1) || (nRowSpan
> 1) )
536 maMergeInfos
.push_back( boost::shared_ptr
< MergeInfo
>( new MergeInfo( mnCurrentColumn
, mnCurrentRow
, nColumnSpan
, nRowSpan
) ) );
538 const sal_Int32 nRepeated
= pCellContext
->getRepeated();
541 DBG_ERROR("xmloff::XMLTableImportContext::ImportCell(), import of repeated Cells not implemented (TODO)");
542 mnCurrentColumn
+= nRepeated
- 1;
549 DBG_ERROR("xmloff::XMLTableImportContext::ImportCell(), exception caught!");
552 return SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
555 // --------------------------------------------------------------------
557 SvXMLImportContext
*XMLTableImportContext::CreateChildContext( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
)
559 if( nPrefix
== XML_NAMESPACE_TABLE
)
561 if( IsXMLToken( rLocalName
, XML_TABLE_COLUMN
) )
562 return ImportColumn( nPrefix
, rLocalName
, xAttrList
);
563 else if( IsXMLToken( rLocalName
, XML_TABLE_ROW
) )
564 return ImportRow( nPrefix
, rLocalName
, xAttrList
);
565 else if( IsXMLToken( rLocalName
, XML_TABLE_CELL
) || IsXMLToken( rLocalName
, XML_COVERED_TABLE_CELL
) )
566 return ImportCell( nPrefix
, rLocalName
, xAttrList
);
567 else if( IsXMLToken( rLocalName
, XML_TABLE_COLUMNS
) || IsXMLToken( rLocalName
, XML_TABLE_ROWS
) )
569 SvXMLImportContextRef
xThis( this );
570 return new XMLProxyContext( GetImport(), xThis
, nPrefix
, rLocalName
);
574 return SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
577 // --------------------------------------------------------------------
579 void XMLTableImportContext::StartElement( const Reference
< XAttributeList
>& /*xAttrList*/ )
583 // --------------------------------------------------------------------
585 void XMLTableImportContext::EndElement()
587 if( !maMergeInfos
.empty() )
589 MergeInfoVector::iterator
aIter( maMergeInfos
.begin() );
590 while( aIter
!= maMergeInfos
.end() )
592 boost::shared_ptr
< MergeInfo
> xInfo( (*aIter
++) );
594 if( xInfo
.get() ) try
596 Reference
< XCellRange
> xRange( mxTable
->getCellRangeByPosition( xInfo
->mnStartColumn
, xInfo
->mnStartRow
, xInfo
->mnEndColumn
, xInfo
->mnEndRow
) );
597 Reference
< XMergeableCellRange
> xCursor( mxTable
->createCursorByRange( xRange
), UNO_QUERY_THROW
);
602 DBG_ERROR("XMLTableImportContext::EndElement(), exception caught while merging cells!");
608 // --------------------------------------------------------------------
610 OUString
XMLTableImportContext::GetDefaultCellStyleName() const
612 OUString
sStyleName( msDefaultCellStyleName
);
614 // if there is still no style name, try default style name from column
615 if( (sStyleName
.getLength() == 0) && (mnCurrentColumn
< sal::static_int_cast
<sal_Int32
>(maColumnInfos
.size())) )
616 sStyleName
= maColumnInfos
[mnCurrentColumn
]->msDefaultCellStyleName
;
621 // --------------------------------------------------------------------
622 // XMLCellImportContext
623 // --------------------------------------------------------------------
625 XMLCellImportContext::XMLCellImportContext( SvXMLImport
& rImport
, const Reference
< XMergeableCell
>& xCell
, const OUString
& sDefaultCellStyleName
, USHORT nPrfx
, const OUString
& rLName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
)
626 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
628 , mbListContextPushed( false )
635 // read attributes for the table-cell
636 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
637 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
639 const OUString
sAttrName( xAttrList
->getNameByIndex( i
) );
640 const OUString
sValue( xAttrList
->getValueByIndex( i
) );
643 sal_uInt16 nPrefix2
= GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName
, &aLocalName
);
644 if( XML_NAMESPACE_TABLE
== nPrefix2
)
646 if( IsXMLToken( aLocalName
, XML_NUMBER_COLUMNS_REPEATED
) )
648 mnRepeated
= sValue
.toInt32();
650 else if( IsXMLToken( aLocalName
, XML_NUMBER_COLUMNS_SPANNED
) )
652 mnColSpan
= sValue
.toInt32();
654 else if( IsXMLToken( aLocalName
, XML_NUMBER_ROWS_SPANNED
) )
656 mnRowSpan
= sValue
.toInt32();
658 else if( IsXMLToken( aLocalName
, XML_STYLE_NAME
) )
663 else if ( (XML_NAMESPACE_XML
== nPrefix2
) &&
664 IsXMLToken(aLocalName
, XML_ID
) )
669 //FIXME: RDFa (table:table-cell)
672 // if there is no style name at the cell, try default style name from row
673 if( sStyleName
.getLength() == 0 )
674 sStyleName
= sDefaultCellStyleName
;
676 if( sStyleName
.getLength() )
678 SvXMLStylesContext
* pAutoStyles
= GetImport().GetShapeImport()->GetAutoStylesContext();
681 const XMLPropStyleContext
* pStyle
=
682 dynamic_cast< const XMLPropStyleContext
* >(
683 pAutoStyles
->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL
, sStyleName
) );
687 Reference
< XPropertySet
> xCellSet( mxCell
, UNO_QUERY
);
689 const_cast< XMLPropStyleContext
* >( pStyle
)->FillPropertySet( xCellSet
);
695 // --------------------------------------------------------------------
697 XMLCellImportContext::~XMLCellImportContext()
701 // --------------------------------------------------------------------
703 SvXMLImportContext
* XMLCellImportContext::CreateChildContext( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
)
705 // create text cursor on demand
708 Reference
< XText
> xText( mxCell
, UNO_QUERY
);
711 UniReference
< XMLTextImportHelper
> xTxtImport( GetImport().GetTextImport() );
712 mxOldCursor
= xTxtImport
->GetCursor();
713 mxCursor
= xText
->createTextCursor();
715 xTxtImport
->SetCursor( mxCursor
);
717 // remember old list item and block (#91964#) and reset them
718 // for the text frame
719 xTxtImport
->PushListContext();
720 mbListContextPushed
= true;
724 SvXMLImportContext
* pContext
= 0;
726 // if we have a text cursor, lets try to import some text
729 pContext
= GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nPrefix
, rLocalName
, xAttrList
);
735 return SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
738 // --------------------------------------------------------------------
740 // --------------------------------------------------------------------
742 void XMLCellImportContext::EndElement()
746 // delete addition newline
747 const OUString aEmpty
;
748 mxCursor
->gotoEnd( sal_False
);
749 mxCursor
->goLeft( 1, sal_True
);
750 mxCursor
->setString( aEmpty
);
753 GetImport().GetTextImport()->ResetCursor();
757 GetImport().GetTextImport()->SetCursor( mxOldCursor
);
759 // reinstall old list item (if necessary) #91964#
760 if (mbListContextPushed
) {
761 GetImport().GetTextImport()->PopListContext();
765 // --------------------------------------------------------------------
766 // class XMLTableTemplateContext
767 // --------------------------------------------------------------------
769 XMLTableTemplateContext::XMLTableTemplateContext( SvXMLImport
& rImport
, USHORT nPrfx
, const OUString
& rLName
, const Reference
< XAttributeList
>& xAttrList
)
770 : SvXMLStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, XML_STYLE_FAMILY_TABLE_TEMPLATE_ID
, sal_False
)
774 // --------------------------------------------------------------------
776 void XMLTableTemplateContext::StartElement( const Reference
< XAttributeList
>& xAttrList
)
778 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
779 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
782 USHORT nAttrPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList
->getNameByIndex( i
), &sAttrName
);
783 if( (nAttrPrefix
== XML_NAMESPACE_TEXT
) && IsXMLToken( sAttrName
, XML_STYLE_NAME
) )
785 msTemplateStyleName
= xAttrList
->getValueByIndex( i
);
791 // --------------------------------------------------------------------
793 void XMLTableTemplateContext::EndElement()
795 rtl::Reference
< XMLTableImport
> xTableImport( GetImport().GetShapeImport()->GetShapeTableImport() );
796 if( xTableImport
.is() )
797 xTableImport
->addTableTemplate( msTemplateStyleName
, maTableTemplate
);
800 // --------------------------------------------------------------------
802 SvXMLImportContext
* XMLTableTemplateContext::CreateChildContext( USHORT nPrefix
, const OUString
& rLocalName
, const Reference
< XAttributeList
>& xAttrList
)
804 if( nPrefix
== XML_NAMESPACE_TABLE
)
806 const TableStyleElement
* pElements
= getTableStyleMap();
807 while( (pElements
->meElement
!= XML_TOKEN_END
) && !IsXMLToken( rLocalName
, pElements
->meElement
) )
810 if( pElements
->meElement
!= XML_TOKEN_END
)
812 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
813 for(sal_Int16 i
=0; i
< nAttrCount
; i
++)
816 USHORT nAttrPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList
->getNameByIndex( i
), &sAttrName
);
817 if( (nAttrPrefix
== XML_NAMESPACE_TEXT
) && IsXMLToken( sAttrName
, XML_STYLE_NAME
) )
819 maTableTemplate
[pElements
->msStyleName
] = xAttrList
->getValueByIndex( i
);
826 return SvXMLImportContext::CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
829 // --------------------------------------------------------------------