Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
31 : : #include <com/sun/star/table/XTableRows.hpp>
32 : : #include <com/sun/star/table/XMergeableCell.hpp>
33 : : #include <com/sun/star/table/XMergeableCellRange.hpp>
34 : : #include <com/sun/star/table/XTable.hpp>
35 : : #include <com/sun/star/text/XText.hpp>
36 : : #include <com/sun/star/container/XNameContainer.hpp>
37 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 : :
39 : : #include "xmloff/table/XMLTableImport.hxx"
40 : : #include "xmloff/xmltkmap.hxx"
41 : : #include "xmloff/maptype.hxx"
42 : : #include "xmloff/xmlprmap.hxx"
43 : : #include "xmloff/txtimp.hxx"
44 : : #include "xmloff/xmlimp.hxx"
45 : : #include "xmloff/nmspmap.hxx"
46 : : #include "xmloff/xmlstyle.hxx"
47 : : #include "xmloff/prstylei.hxx"
48 : :
49 : : #include "xmloff/xmlnmspe.hxx"
50 : : #include "table.hxx"
51 : :
52 : : #include <boost/shared_ptr.hpp>
53 : :
54 : : // --------------------------------------------------------------------
55 : :
56 : : using ::rtl::OUString;
57 : : using namespace ::xmloff::token;
58 : : using namespace ::com::sun::star::beans;
59 : : using namespace ::com::sun::star::uno;
60 : : using namespace ::com::sun::star::table;
61 : : using namespace ::com::sun::star::xml::sax;
62 : : using namespace ::com::sun::star::text;
63 : : using namespace ::com::sun::star::style;
64 : : using namespace ::com::sun::star::lang;
65 : : using namespace ::com::sun::star::container;
66 : :
67 : : // --------------------------------------------------------------------
68 : :
69 : 48 : struct ColumnInfo
70 : : {
71 : : OUString msStyleName;
72 : : sal_Bool mbVisibility;
73 : : OUString msDefaultCellStyleName;
74 : : };
75 : :
76 : : // --------------------------------------------------------------------
77 : :
78 [ + - ][ - + ]: 60 : class XMLProxyContext : public SvXMLImportContext
79 : : {
80 : : public:
81 : : XMLProxyContext( SvXMLImport& rImport, const SvXMLImportContextRef& xParent, sal_uInt16 nPrfx, const OUString& rLName );
82 : :
83 : : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
84 : :
85 : : private:
86 : : SvXMLImportContextRef mxParent;
87 : : };
88 : :
89 : : // --------------------------------------------------------------------
90 : :
91 : : struct MergeInfo
92 : : {
93 : : sal_Int32 mnStartColumn;
94 : : sal_Int32 mnStartRow;
95 : : sal_Int32 mnEndColumn;
96 : : sal_Int32 mnEndRow;
97 : :
98 : 0 : MergeInfo( sal_Int32 nStartColumn, sal_Int32 nStartRow, sal_Int32 nColumnSpan, sal_Int32 nRowSpan )
99 : 0 : : mnStartColumn( nStartColumn ), mnStartRow( nStartRow ), mnEndColumn( nStartColumn + nColumnSpan - 1 ), mnEndRow( nStartRow + nRowSpan - 1 ) {};
100 : : };
101 : :
102 : : typedef std::vector< boost::shared_ptr< MergeInfo > > MergeInfoVector;
103 : :
104 : : // --------------------------------------------------------------------
105 : :
106 : : class XMLTableImportContext : public SvXMLImportContext
107 : : {
108 : : public:
109 : : XMLTableImportContext( const rtl::Reference< XMLTableImport >& xThis, sal_uInt16 nPrfx, const OUString& rLName, Reference< XColumnRowRange >& xColumnRowRange );
110 : : virtual ~XMLTableImportContext();
111 : :
112 : : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
113 : :
114 : : virtual void StartElement( const Reference< XAttributeList >& xAttrList );
115 : :
116 : : virtual void EndElement();
117 : :
118 : : void InitColumns();
119 : :
120 : : SvXMLImportContext * ImportColumn( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
121 : : SvXMLImportContext * ImportRow( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
122 : : SvXMLImportContext * ImportCell( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
123 : :
124 : : OUString GetDefaultCellStyleName() const;
125 : :
126 : : rtl::Reference< XMLTableImport > mxTableImporter;
127 : : ::com::sun::star::uno::Reference< ::com::sun::star::table::XTable > mxTable;
128 : : Reference< XTableColumns > mxColumns;
129 : : Reference< XTableRows > mxRows;
130 : :
131 : : std::vector< boost::shared_ptr< ColumnInfo > > maColumnInfos;
132 : : sal_Int32 mnCurrentRow;
133 : : sal_Int32 mnCurrentColumn;
134 : :
135 : : // default cell style name for the current row
136 : : OUString msDefaultCellStyleName;
137 : :
138 : : MergeInfoVector maMergeInfos;
139 : : };
140 : :
141 : : // --------------------------------------------------------------------
142 : :
143 : : class XMLCellImportContext : public SvXMLImportContext
144 : : {
145 : : public:
146 : : XMLCellImportContext( SvXMLImport& rImport,
147 : : const Reference< XMergeableCell >& xCell,
148 : : const OUString& sDefaultCellStyleName,
149 : : sal_uInt16 nPrfx, const OUString& rLName,
150 : : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
151 : :
152 : : virtual ~XMLCellImportContext();
153 : :
154 : : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
155 : :
156 : : virtual void EndElement();
157 : :
158 : 48 : sal_Int32 getColumnSpan() const { return mnColSpan; }
159 : 48 : sal_Int32 getRowSpan() const { return mnRowSpan; }
160 : 48 : sal_Int32 getRepeated() const { return mnRepeated; }
161 : :
162 : : Reference< XMergeableCell > mxCell;
163 : : Reference< XTextCursor > mxCursor;
164 : : Reference< XTextCursor > mxOldCursor;
165 : : bool mbListContextPushed;
166 : :
167 : : sal_Int32 mnColSpan, mnRowSpan, mnRepeated;
168 : : };
169 : :
170 : : // --------------------------------------------------------------------
171 : :
172 [ - + ]: 6 : class XMLTableTemplateContext : public SvXMLStyleContext
173 : : {
174 : : public:
175 : : XMLTableTemplateContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const Reference< XAttributeList >& xAttrList );
176 : :
177 : : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
178 : :
179 : : virtual void StartElement( const Reference< XAttributeList >& xAttrList );
180 : :
181 : : virtual void EndElement();
182 : :
183 : : private:
184 : : XMLTableTemplate maTableTemplate;
185 : : OUString msTemplateStyleName;
186 : : };
187 : :
188 : : // --------------------------------------------------------------------
189 : : // class XMLProxyContext
190 : : // --------------------------------------------------------------------
191 : :
192 : 30 : XMLProxyContext::XMLProxyContext( SvXMLImport& rImport, const SvXMLImportContextRef& xParent, sal_uInt16 nPrfx, const OUString& rLName )
193 : : : SvXMLImportContext( rImport, nPrfx, rLName )
194 : 30 : , mxParent( xParent )
195 : : {
196 : 30 : }
197 : :
198 : : // --------------------------------------------------------------------
199 : :
200 : 48 : SvXMLImportContext * XMLProxyContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
201 : : {
202 [ + - ]: 48 : if( mxParent.Is() )
203 : 48 : return mxParent->CreateChildContext( nPrefix, rLocalName, xAttrList );
204 : : else
205 : 48 : return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
206 : : }
207 : :
208 : : // --------------------------------------------------------------------
209 : : // class XMLTableImport
210 : : // --------------------------------------------------------------------
211 : :
212 : 14 : XMLTableImport::XMLTableImport( SvXMLImport& rImport, const rtl::Reference< XMLPropertySetMapper >& xCellPropertySetMapper, const rtl::Reference< XMLPropertyHandlerFactory >& xFactoryRef )
213 [ + - ]: 14 : : mrImport( rImport )
214 : : {
215 [ + - ][ + - ]: 14 : mxCellImportPropertySetMapper = new SvXMLImportPropertyMapper( xCellPropertySetMapper.get(), rImport );
[ + - ][ + - ]
[ + - ]
216 [ + - ][ + - ]: 14 : mxCellImportPropertySetMapper->ChainImportMapper(XMLTextImportHelper::CreateParaExtPropMapper(rImport));
[ + - ][ + - ]
217 : :
218 : :
219 [ + - ][ + - ]: 14 : UniReference < XMLPropertySetMapper > xRowMapper( new XMLPropertySetMapper( getRowPropertiesMap(), xFactoryRef.get() ) );
[ + - ][ + - ]
[ + - ][ + - ]
220 [ + - ][ + - ]: 14 : mxRowImportPropertySetMapper = new SvXMLImportPropertyMapper( xRowMapper, rImport );
[ + - ]
221 : :
222 [ + - ][ + - ]: 14 : UniReference < XMLPropertySetMapper > xColMapper( new XMLPropertySetMapper( getColumnPropertiesMap(), xFactoryRef.get() ) );
[ + - ][ + - ]
[ + - ][ + - ]
223 [ + - ][ + - ]: 14 : mxColumnImportPropertySetMapper = new SvXMLImportPropertyMapper( xColMapper, rImport );
[ + - ][ + - ]
[ + - ]
224 : 14 : }
225 : :
226 : : // --------------------------------------------------------------------
227 : :
228 [ + - ][ + - ]: 14 : XMLTableImport::~XMLTableImport()
[ + - ]
229 : : {
230 [ - + ]: 28 : }
231 : :
232 : : // --------------------------------------------------------------------
233 : :
234 : 6 : SvXMLImportContext* XMLTableImport::CreateTableContext( sal_uInt16 nPrfx, const OUString& rLName, Reference< XColumnRowRange >& xColumnRowRange )
235 : : {
236 [ + - ]: 6 : rtl::Reference< XMLTableImport > xThis( this );
237 [ + - ][ + - ]: 6 : return new XMLTableImportContext( xThis, nPrfx, rLName, xColumnRowRange );
[ + - ]
238 : : }
239 : :
240 : : // --------------------------------------------------------------------
241 : :
242 : 3 : SvXMLStyleContext* XMLTableImport::CreateTableTemplateContext( sal_uInt16 nPrfx, const OUString& rLName, const Reference< XAttributeList >& xAttrList )
243 : : {
244 [ + - ]: 3 : return new XMLTableTemplateContext( mrImport, nPrfx, rLName, xAttrList );
245 : : }
246 : :
247 : : // --------------------------------------------------------------------
248 : :
249 : 3 : void XMLTableImport::addTableTemplate( const rtl::OUString& rsStyleName, XMLTableTemplate& xTableTemplate )
250 : : {
251 [ + - ][ + - ]: 3 : boost::shared_ptr< XMLTableTemplate > xPtr( new XMLTableTemplate );
[ + - ]
252 [ + - ]: 3 : xPtr->swap( xTableTemplate );
253 [ + - ][ + - ]: 3 : maTableTemplates[rsStyleName] = xPtr;
[ + - ]
254 : 3 : }
255 : :
256 : : // --------------------------------------------------------------------
257 : :
258 : 11 : void XMLTableImport::finishStyles()
259 : : {
260 [ + + ]: 11 : if( !maTableTemplates.empty() ) try
261 : : {
262 [ + - ]: 3 : Reference< XStyleFamiliesSupplier > xFamiliesSupp( mrImport.GetModel(), UNO_QUERY_THROW );
263 [ + - ][ + - ]: 3 : Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
264 [ + - ]: 3 : const OUString sFamilyName( RTL_CONSTASCII_USTRINGPARAM("table" ) );
265 [ + - ]: 3 : const OUString sCellFamilyName( RTL_CONSTASCII_USTRINGPARAM("cell") );
266 : :
267 [ + - ][ + - ]: 3 : Reference< XNameContainer > xTableFamily( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
[ + - ]
268 [ + - ][ + - ]: 3 : Reference< XNameAccess > xCellFamily( xFamilies->getByName( sCellFamilyName ), UNO_QUERY_THROW );
[ + - ]
269 : :
270 [ + - ]: 3 : Reference< XSingleServiceFactory > xFactory( xTableFamily, UNO_QUERY_THROW );
271 : :
272 [ + + ]: 6 : for( XMLTableTemplateMap::iterator aTemplateIter( maTableTemplates.begin() ); aTemplateIter != maTableTemplates.end(); ++aTemplateIter ) try
273 : : {
274 : 3 : const OUString sTemplateName( (*aTemplateIter).first );
275 [ + - ][ + - ]: 3 : Reference< XNameReplace > xTemplate( xFactory->createInstance(), UNO_QUERY_THROW );
[ + - ]
276 : :
277 [ + - ]: 3 : boost::shared_ptr< XMLTableTemplate > xT( (*aTemplateIter).second );
278 : :
279 [ + + ]: 24 : for( XMLTableTemplate::iterator aStyleIter( xT->begin() ); aStyleIter != xT->end(); ++aStyleIter ) try
280 : : {
281 : 21 : const OUString sPropName( (*aStyleIter).first );
282 : 21 : const OUString sStyleName( (*aStyleIter).second );
283 [ + - ][ + - ]: 21 : xTemplate->replaceByName( sPropName, xCellFamily->getByName( sStyleName ) );
[ + - ][ # # ]
[ + - ]
284 : : }
285 [ # # ]: 0 : catch( Exception& )
286 : : {
287 : : OSL_FAIL("xmloff::XMLTableImport::finishStyles(), exception caught!");
288 : : }
289 : :
290 [ + - ]: 3 : if( xTemplate.is() )
291 : : {
292 [ + - ][ + - ]: 3 : if( xTableFamily->hasByName( sTemplateName ) )
[ + - ]
293 [ + - ][ + - ]: 3 : xTableFamily->replaceByName( sTemplateName, Any( xTemplate ) );
[ + - ]
294 : : else
295 [ # # ][ # # ]: 0 : xTableFamily->insertByName( sTemplateName, Any( xTemplate ) );
[ # # ]
296 [ + - ][ # # ]: 3 : }
297 : :
298 : : }
299 [ # # ]: 0 : catch( Exception& )
300 : : {
301 : : OSL_FAIL("xmloff::XMLTableImport::finishStyles(), exception caught!");
302 [ # # ]: 3 : }
303 : : }
304 : 0 : catch( Exception& )
305 : : {
306 : : OSL_FAIL("xmloff::XMLTableImport::finishStyles(), exception caught!");
307 : : }
308 : 11 : }
309 : :
310 : : // --------------------------------------------------------------------
311 : : // class XMLTableImport
312 : : // --------------------------------------------------------------------
313 : :
314 : :
315 : 6 : XMLTableImportContext::XMLTableImportContext( const rtl::Reference< XMLTableImport >& xImporter, sal_uInt16 nPrfx, const OUString& rLName, Reference< XColumnRowRange >& xColumnRowRange )
316 : 6 : : SvXMLImportContext( xImporter->mrImport, nPrfx, rLName )
317 : : , mxTableImporter( xImporter )
318 : : , mxTable( xColumnRowRange, UNO_QUERY )
319 [ + - ]: 6 : , mxColumns( xColumnRowRange->getColumns() )
320 [ + - ]: 6 : , mxRows( xColumnRowRange->getRows() )
321 : : , mnCurrentRow( -1 )
322 [ + - ][ + - ]: 18 : , mnCurrentColumn( -1 )
[ + - ][ + - ]
[ + - ][ + - ]
323 : : {
324 : 6 : }
325 : :
326 : : // --------------------------------------------------------------------
327 : :
328 [ + - ]: 6 : XMLTableImportContext::~XMLTableImportContext()
329 : : {
330 [ - + ]: 12 : }
331 : :
332 : : // --------------------------------------------------------------------
333 : :
334 : 24 : SvXMLImportContext * XMLTableImportContext::ImportColumn( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
335 : : {
336 [ + - ][ + - ]: 24 : if( mxColumns.is() && (mnCurrentRow == -1) ) try
[ + - ]
337 : : {
338 [ + - ][ + - ]: 24 : boost::shared_ptr< ColumnInfo > xInfo ( new ColumnInfo );
339 : :
340 : 24 : sal_Int32 nRepeated = 1;
341 : :
342 : : // read attributes for the table-column
343 [ + - ][ + - ]: 24 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
344 [ + + ]: 48 : for(sal_Int16 i=0; i < nAttrCount; i++)
345 : : {
346 [ + - ][ + - ]: 24 : const OUString sAttrName( xAttrList->getNameByIndex( i ) );
347 [ + - ][ + - ]: 24 : const OUString sValue( xAttrList->getValueByIndex( i ) );
348 : 24 : OUString aLocalName;
349 : :
350 [ + - ]: 24 : sal_uInt16 nPrefix2 = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
351 [ + - ]: 24 : if( XML_NAMESPACE_TABLE == nPrefix2 )
352 : : {
353 [ + - ][ - + ]: 24 : if( IsXMLToken( aLocalName, XML_NUMBER_COLUMNS_REPEATED ) )
354 : : {
355 : 0 : nRepeated = sValue.toInt32();
356 : : }
357 [ + - ][ + - ]: 24 : else if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
358 : : {
359 : 24 : xInfo->msStyleName = sValue;
360 : : }
361 [ # # ][ # # ]: 0 : else if( IsXMLToken( aLocalName, XML_DEFAULT_CELL_STYLE_NAME ) )
362 : : {
363 : 0 : xInfo->msDefaultCellStyleName = sValue;
364 : : }
365 [ # # ][ # # ]: 0 : else if( IsXMLToken( aLocalName, XML_VISIBILITY ) )
366 : : {
367 [ # # ]: 0 : xInfo->mbVisibility = IsXMLToken( sValue, XML_VISIBLE );
368 : : }
369 : : }
370 [ # # ][ # # ]: 0 : else if ( (XML_NAMESPACE_XML == nPrefix2) &&
371 [ # # ]: 0 : IsXMLToken(aLocalName, XML_ID) )
372 : : {
373 : : (void) sValue;
374 : : //FIXME: TODO
375 : : }
376 : 24 : }
377 : :
378 [ + - ]: 24 : if( nRepeated <= 1 )
379 : : {
380 [ + - ]: 24 : maColumnInfos.push_back( xInfo );
381 : : }
382 : : else
383 : : {
384 [ # # ]: 0 : maColumnInfos.insert( maColumnInfos.end(), nRepeated, xInfo );
385 [ + - ][ # # ]: 24 : }
386 : : }
387 : 0 : catch( Exception& )
388 : : {
389 : : OSL_FAIL("xmloff::XMLTableImportContext::ImportTableColumn(), exception caught!");
390 : : }
391 : :
392 : 24 : return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList);
393 : : }
394 : :
395 : : // --------------------------------------------------------------------
396 : :
397 : 6 : void XMLTableImportContext::InitColumns()
398 : : {
399 [ + - ]: 6 : if( mxColumns.is() ) try
400 : : {
401 [ + - ][ + - ]: 6 : const sal_Int32 nCount1 = mxColumns->getCount();
402 : 6 : const sal_Int32 nCount2 = sal::static_int_cast< sal_Int32 >( maColumnInfos.size() );
403 [ + + ]: 6 : if( nCount1 < nCount2 )
404 [ + - ][ + - ]: 3 : mxColumns->insertByIndex( nCount1, nCount2 - nCount1 );
405 : :
406 [ + - ][ + - ]: 6 : SvXMLStylesContext * pAutoStyles = GetImport().GetShapeImport()->GetAutoStylesContext();
[ + - ]
407 : :
408 [ + + ]: 30 : for( sal_Int32 nCol = 0; nCol < nCount2; nCol++ )
409 : : {
410 [ + - ]: 24 : boost::shared_ptr< ColumnInfo > xInfo( maColumnInfos[nCol] );
411 : :
412 [ + - ][ + - ]: 24 : if( pAutoStyles && !xInfo->msStyleName.isEmpty() )
[ + - ]
413 : : {
414 : : const XMLPropStyleContext* pStyle =
415 : : dynamic_cast< const XMLPropStyleContext* >(
416 [ + - ][ - + ]: 24 : pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN, xInfo->msStyleName) );
417 : :
418 [ + - ]: 24 : if( pStyle )
419 : : {
420 [ + - ][ + - ]: 24 : Reference< XPropertySet > xColProps( mxColumns->getByIndex(nCol), UNO_QUERY_THROW );
[ + - ]
421 [ + - ]: 24 : const_cast< XMLPropStyleContext* >( pStyle )->FillPropertySet( xColProps );
422 : : }
423 : : }
424 : :
425 [ + - # # ]: 24 : }
426 : : }
427 : 0 : catch( Exception& )
428 : : {
429 : : OSL_FAIL("xmloff::XMLTableImportContext::ImportTableColumn(), exception caught!");
430 : : }
431 : 6 : }
432 : :
433 : : // --------------------------------------------------------------------
434 : :
435 : 30 : SvXMLImportContext * XMLTableImportContext::ImportRow( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
436 : : {
437 [ + - ]: 30 : if( mxRows.is() )
438 : : {
439 : 30 : mnCurrentRow++;
440 [ + + ]: 30 : if( mnCurrentRow == 0 )
441 [ + - ]: 6 : InitColumns(); // first init columns
442 : :
443 : 30 : mnCurrentColumn = -1;
444 : :
445 [ + - ][ + - ]: 30 : const sal_Int32 nRowCount = mxRows->getCount();
446 [ + + ]: 30 : if( ( nRowCount - 1) < mnCurrentRow )
447 : : {
448 : 24 : const sal_Int32 nCount = mnCurrentRow - nRowCount + 1;
449 [ + - ][ + - ]: 24 : mxRows->insertByIndex( nRowCount, nCount );
450 : : }
451 : :
452 [ + - ][ + - ]: 30 : Reference< XPropertySet > xRowSet( mxRows->getByIndex(mnCurrentRow), UNO_QUERY );
[ + - ]
453 : :
454 : 30 : OUString sStyleName;
455 : :
456 : : // read attributes for the table-row
457 [ + - ][ + - ]: 30 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
458 [ + + ]: 63 : for(sal_Int16 i=0; i < nAttrCount; i++)
459 : : {
460 [ + - ][ + - ]: 33 : const OUString sAttrName( xAttrList->getNameByIndex( i ) );
461 [ + - ][ + - ]: 33 : const OUString sValue( xAttrList->getValueByIndex( i ) );
462 : 33 : OUString aLocalName;
463 : :
464 [ + - ]: 33 : sal_uInt16 nPrefix2 = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
465 [ + - ]: 33 : if( nPrefix2 == XML_NAMESPACE_TABLE )
466 : : {
467 [ + - ][ + + ]: 33 : if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
468 : : {
469 : 30 : sStyleName = sValue;
470 : : }
471 [ + - ][ + - ]: 3 : else if( IsXMLToken( aLocalName, XML_DEFAULT_CELL_STYLE_NAME ) )
472 : : {
473 : 3 : msDefaultCellStyleName = sValue;
474 : : }
475 : : #if 0
476 : : else if( IsXMLToken( aLocalName, XML_VISIBILITY ) )
477 : : {
478 : : bVisibility = IsXMLToken( sValue, XML_VISIBLE );
479 : : }
480 : : else if( IsXMLToken( aLocalName, XML_NUMBER_ROWS_REPEATED ) )
481 : : {
482 : : nRepeated = sValue.toInt32();
483 : : }
484 : : #endif
485 : : }
486 [ # # ][ # # ]: 0 : else if ( (XML_NAMESPACE_XML == nPrefix2) &&
487 [ # # ]: 0 : IsXMLToken(aLocalName, XML_ID) )
488 : : {
489 : : (void) sValue;
490 : : //FIXME: TODO
491 : : }
492 : 33 : }
493 : :
494 [ + - ]: 30 : if( !sStyleName.isEmpty() )
495 : : {
496 [ + - ][ + - ]: 30 : SvXMLStylesContext * pAutoStyles = GetImport().GetShapeImport()->GetAutoStylesContext();
[ + - ]
497 [ + - ]: 30 : if( pAutoStyles )
498 : : {
499 : : const XMLPropStyleContext* pStyle =
500 : : dynamic_cast< const XMLPropStyleContext* >(
501 [ + - ][ - + ]: 30 : pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_ROW, sStyleName) );
502 : :
503 [ + - ]: 30 : if( pStyle )
504 : : {
505 [ + - ]: 30 : const_cast< XMLPropStyleContext* >( pStyle )->FillPropertySet( xRowSet );
506 : : }
507 : : }
508 : 30 : }
509 : : }
510 : :
511 : 30 : SvXMLImportContextRef xThis( this );
512 [ + - ][ + - ]: 30 : return new XMLProxyContext( GetImport(), xThis, nPrefix, rLocalName );
[ + - ]
513 : : }
514 : :
515 : : // --------------------------------------------------------------------
516 : :
517 : 48 : SvXMLImportContext * XMLTableImportContext::ImportCell( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
518 : : {
519 : 48 : mnCurrentColumn++;
520 [ + - ]: 48 : if( mxColumns.is() ) try
521 : : {
522 [ + - ][ + - ]: 48 : if( mxColumns->getCount() <= mnCurrentColumn )
[ - + ]
523 [ # # ][ # # ]: 0 : mxColumns->insertByIndex( mxColumns->getCount(), mnCurrentColumn - mxColumns->getCount() + 1 );
[ # # ][ # # ]
[ # # ][ # # ]
524 : :
525 [ + - ][ + - ]: 48 : Reference< XMergeableCell > xCell( mxTable->getCellByPosition( mnCurrentColumn, mnCurrentRow ), UNO_QUERY_THROW );
[ + - ]
526 [ + - ][ + - ]: 48 : XMLCellImportContext* pCellContext = new XMLCellImportContext( GetImport(), xCell, GetDefaultCellStyleName(), nPrefix, rLocalName, xAttrList );
[ + - ]
527 : :
528 : 48 : const sal_Int32 nColumnSpan = pCellContext->getColumnSpan();
529 : 48 : const sal_Int32 nRowSpan = pCellContext->getRowSpan();
530 [ - + ][ + - ]: 48 : if( (nColumnSpan > 1) || (nRowSpan > 1) )
531 [ # # ][ # # ]: 0 : maMergeInfos.push_back( boost::shared_ptr< MergeInfo >( new MergeInfo( mnCurrentColumn, mnCurrentRow, nColumnSpan, nRowSpan ) ) );
[ # # ][ # # ]
532 : :
533 : 48 : const sal_Int32 nRepeated = pCellContext->getRepeated();
534 [ - + ]: 48 : if( nRepeated > 1 )
535 : : {
536 : : OSL_FAIL("xmloff::XMLTableImportContext::ImportCell(), import of repeated Cells not implemented (TODO)");
537 : 0 : mnCurrentColumn += nRepeated - 1;
538 : : }
539 : :
540 [ # # ]: 48 : return pCellContext;
541 : : }
542 : 0 : catch( Exception& )
543 : : {
544 : : OSL_FAIL("xmloff::XMLTableImportContext::ImportCell(), exception caught!");
545 : : }
546 : :
547 : 48 : return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList);
548 : : }
549 : :
550 : : // --------------------------------------------------------------------
551 : :
552 : 102 : SvXMLImportContext *XMLTableImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
553 : : {
554 [ + - ]: 102 : if( nPrefix == XML_NAMESPACE_TABLE )
555 : : {
556 [ + + ]: 102 : if( IsXMLToken( rLocalName, XML_TABLE_COLUMN ) )
557 : 24 : return ImportColumn( nPrefix, rLocalName, xAttrList );
558 [ + + ]: 78 : else if( IsXMLToken( rLocalName, XML_TABLE_ROW ) )
559 : 30 : return ImportRow( nPrefix, rLocalName, xAttrList );
560 [ - + ][ # # ]: 48 : else if( IsXMLToken( rLocalName, XML_TABLE_CELL ) || IsXMLToken( rLocalName, XML_COVERED_TABLE_CELL ) )
[ + - ]
561 : 48 : return ImportCell( nPrefix, rLocalName, xAttrList );
562 [ # # ][ # # ]: 0 : else if( IsXMLToken( rLocalName, XML_TABLE_COLUMNS ) || IsXMLToken( rLocalName, XML_TABLE_ROWS ) )
[ # # ]
563 : : {
564 : 0 : SvXMLImportContextRef xThis( this );
565 [ # # ][ # # ]: 0 : return new XMLProxyContext( GetImport(), xThis, nPrefix, rLocalName );
[ # # ]
566 : : }
567 : : }
568 : :
569 : 102 : return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList);
570 : : }
571 : :
572 : : // --------------------------------------------------------------------
573 : :
574 : 6 : void XMLTableImportContext::StartElement( const Reference< XAttributeList >& /*xAttrList*/ )
575 : : {
576 : 6 : }
577 : :
578 : : // --------------------------------------------------------------------
579 : :
580 : 6 : void XMLTableImportContext::EndElement()
581 : : {
582 [ - + ]: 6 : if( !maMergeInfos.empty() )
583 : : {
584 : 0 : MergeInfoVector::iterator aIter( maMergeInfos.begin() );
585 [ # # ][ # # ]: 0 : while( aIter != maMergeInfos.end() )
586 : : {
587 [ # # ][ # # ]: 0 : boost::shared_ptr< MergeInfo > xInfo( (*aIter++) );
588 : :
589 [ # # ]: 0 : if( xInfo.get() ) try
590 : : {
591 [ # # ][ # # ]: 0 : Reference< XCellRange > xRange( mxTable->getCellRangeByPosition( xInfo->mnStartColumn, xInfo->mnStartRow, xInfo->mnEndColumn, xInfo->mnEndRow ) );
592 [ # # ][ # # ]: 0 : Reference< XMergeableCellRange > xCursor( mxTable->createCursorByRange( xRange ), UNO_QUERY_THROW );
[ # # ]
593 [ # # ][ # # ]: 0 : xCursor->merge();
[ # # ]
594 : : }
595 [ # # ]: 0 : catch( Exception& )
596 : : {
597 : : OSL_FAIL("XMLTableImportContext::EndElement(), exception caught while merging cells!");
598 : : }
599 [ # # ]: 0 : }
600 : : }
601 : 6 : }
602 : :
603 : : // --------------------------------------------------------------------
604 : :
605 : 48 : OUString XMLTableImportContext::GetDefaultCellStyleName() const
606 : : {
607 : 48 : OUString sStyleName( msDefaultCellStyleName );
608 : :
609 : : // if there is still no style name, try default style name from column
610 [ + - ][ + + ]: 48 : if( (sStyleName.isEmpty()) && (mnCurrentColumn < sal::static_int_cast<sal_Int32>(maColumnInfos.size())) )
[ + + ]
611 : 27 : sStyleName = maColumnInfos[mnCurrentColumn]->msDefaultCellStyleName;
612 : :
613 : 48 : return sStyleName;
614 : : }
615 : :
616 : : // --------------------------------------------------------------------
617 : : // XMLCellImportContext
618 : : // --------------------------------------------------------------------
619 : :
620 : 48 : XMLCellImportContext::XMLCellImportContext( SvXMLImport& rImport, const Reference< XMergeableCell >& xCell, const OUString& sDefaultCellStyleName, sal_uInt16 nPrfx, const OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
621 : : : SvXMLImportContext( rImport, nPrfx, rLName )
622 : : , mxCell( xCell )
623 : : , mbListContextPushed( false )
624 : : , mnColSpan( 1 )
625 : : , mnRowSpan( 1 )
626 : 48 : , mnRepeated( 1 )
627 : : {
628 : 48 : OUString sStyleName;
629 : :
630 : : // read attributes for the table-cell
631 [ + - ][ + - ]: 48 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
632 [ + + ]: 75 : for(sal_Int16 i=0; i < nAttrCount; i++)
633 : : {
634 [ + - ][ + - ]: 27 : const OUString sAttrName( xAttrList->getNameByIndex( i ) );
635 [ + - ][ + - ]: 27 : const OUString sValue( xAttrList->getValueByIndex( i ) );
636 : 27 : OUString aLocalName;
637 : :
638 [ + - ]: 27 : sal_uInt16 nPrefix2 = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
639 [ + - ]: 27 : if( XML_NAMESPACE_TABLE == nPrefix2 )
640 : : {
641 [ + - ][ - + ]: 27 : if( IsXMLToken( aLocalName, XML_NUMBER_COLUMNS_REPEATED ) )
642 : : {
643 : 0 : mnRepeated = sValue.toInt32();
644 : : }
645 [ + - ][ - + ]: 27 : else if( IsXMLToken( aLocalName, XML_NUMBER_COLUMNS_SPANNED ) )
646 : : {
647 : 0 : mnColSpan = sValue.toInt32();
648 : : }
649 [ + - ][ - + ]: 27 : else if( IsXMLToken( aLocalName, XML_NUMBER_ROWS_SPANNED ) )
650 : : {
651 : 0 : mnRowSpan = sValue.toInt32();
652 : : }
653 [ + - ][ + - ]: 27 : else if( IsXMLToken( aLocalName, XML_STYLE_NAME ) )
654 : : {
655 : 27 : sStyleName = sValue;
656 : : }
657 : : }
658 [ # # ][ # # ]: 0 : else if ( (XML_NAMESPACE_XML == nPrefix2) &&
659 [ # # ]: 0 : IsXMLToken(aLocalName, XML_ID) )
660 : : {
661 : : (void) sValue;
662 : : //FIXME: TODO
663 : : }
664 : : //FIXME: RDFa (table:table-cell)
665 : 27 : }
666 : :
667 : : // if there is no style name at the cell, try default style name from row
668 [ + + ]: 48 : if( sStyleName.isEmpty() )
669 : 21 : sStyleName = sDefaultCellStyleName;
670 : :
671 [ + - ]: 48 : if( !sStyleName.isEmpty() )
672 : : {
673 [ + - ][ + - ]: 48 : SvXMLStylesContext * pAutoStyles = GetImport().GetShapeImport()->GetAutoStylesContext();
[ + - ]
674 [ + - ]: 48 : if( pAutoStyles )
675 : : {
676 : : const XMLPropStyleContext* pStyle =
677 : : dynamic_cast< const XMLPropStyleContext* >(
678 [ + - ][ - + ]: 48 : pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL, sStyleName) );
679 : :
680 [ + - ]: 48 : if( pStyle )
681 : : {
682 [ + - ]: 48 : Reference< XPropertySet > xCellSet( mxCell, UNO_QUERY );
683 [ + - ]: 48 : if( xCellSet.is() )
684 [ + - ]: 48 : const_cast< XMLPropStyleContext* >( pStyle )->FillPropertySet( xCellSet );
685 : : }
686 : : }
687 : 48 : }
688 : 48 : }
689 : :
690 : : // --------------------------------------------------------------------
691 : :
692 : 48 : XMLCellImportContext::~XMLCellImportContext()
693 : : {
694 [ - + ]: 96 : }
695 : :
696 : : // --------------------------------------------------------------------
697 : :
698 : 0 : SvXMLImportContext * XMLCellImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
699 : : {
700 : : // create text cursor on demand
701 [ # # ]: 0 : if( !mxCursor.is() )
702 : : {
703 [ # # ]: 0 : Reference< XText > xText( mxCell, UNO_QUERY );
704 [ # # ]: 0 : if( xText.is() )
705 : : {
706 [ # # ]: 0 : UniReference < XMLTextImportHelper > xTxtImport( GetImport().GetTextImport() );
707 [ # # ][ # # ]: 0 : mxOldCursor = xTxtImport->GetCursor();
[ # # ]
708 [ # # ][ # # ]: 0 : mxCursor = xText->createTextCursor();
[ # # ]
709 [ # # ]: 0 : if( mxCursor.is() )
710 [ # # ][ # # ]: 0 : xTxtImport->SetCursor( mxCursor );
711 : :
712 : : // remember old list item and block (#91964#) and reset them
713 : : // for the text frame
714 [ # # ][ # # ]: 0 : xTxtImport->PushListContext();
715 [ # # ]: 0 : mbListContextPushed = true;
716 : 0 : }
717 : : }
718 : :
719 : 0 : SvXMLImportContext * pContext = 0;
720 : :
721 : : // if we have a text cursor, lets try to import some text
722 [ # # ]: 0 : if( mxCursor.is() )
723 : : {
724 [ # # ][ # # ]: 0 : pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
725 : : }
726 : :
727 [ # # ]: 0 : if( pContext )
728 : 0 : return pContext;
729 : : else
730 : 0 : return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList);
731 : : }
732 : :
733 : : // --------------------------------------------------------------------
734 : :
735 : : // --------------------------------------------------------------------
736 : :
737 : 48 : void XMLCellImportContext::EndElement()
738 : : {
739 [ - + ]: 48 : if(mxCursor.is())
740 : : {
741 : : // delete addition newline
742 : 0 : const OUString aEmpty;
743 [ # # ][ # # ]: 0 : mxCursor->gotoEnd( sal_False );
744 [ # # ][ # # ]: 0 : mxCursor->goLeft( 1, sal_True );
745 [ # # ][ # # ]: 0 : mxCursor->setString( aEmpty );
746 : :
747 : : // reset cursor
748 [ # # ][ # # ]: 0 : GetImport().GetTextImport()->ResetCursor();
[ # # ][ # # ]
749 : : }
750 : :
751 [ - + ]: 48 : if(mxOldCursor.is())
752 [ # # ][ # # ]: 0 : GetImport().GetTextImport()->SetCursor( mxOldCursor );
753 : :
754 : : // reinstall old list item (if necessary) #91964#
755 [ - + ]: 48 : if (mbListContextPushed) {
756 [ # # ][ # # ]: 0 : GetImport().GetTextImport()->PopListContext();
757 : : }
758 : 48 : }
759 : :
760 : : // --------------------------------------------------------------------
761 : : // class XMLTableTemplateContext
762 : : // --------------------------------------------------------------------
763 : :
764 : 3 : XMLTableTemplateContext::XMLTableTemplateContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const Reference< XAttributeList >& xAttrList )
765 [ + - ]: 3 : : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_TABLE_TEMPLATE_ID, sal_False )
766 : : {
767 : 3 : }
768 : :
769 : : // --------------------------------------------------------------------
770 : :
771 : 3 : void XMLTableTemplateContext::StartElement( const Reference< XAttributeList >& xAttrList )
772 : : {
773 [ + - ]: 3 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
774 [ + - ]: 6 : for(sal_Int16 i=0; i < nAttrCount; i++)
775 : : {
776 : 3 : OUString sAttrName;
777 [ + - ][ + - ]: 3 : sal_uInt16 nAttrPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( i ), &sAttrName );
[ + - ]
778 [ + - ][ + - ]: 3 : if( (nAttrPrefix == XML_NAMESPACE_TEXT ) && IsXMLToken( sAttrName, XML_STYLE_NAME ) )
[ + - ][ + - ]
779 : : {
780 [ + - ][ + - ]: 3 : msTemplateStyleName = xAttrList->getValueByIndex( i );
781 : : break;
782 : : }
783 [ - + ]: 3 : }
784 : 3 : }
785 : :
786 : : // --------------------------------------------------------------------
787 : :
788 : 3 : void XMLTableTemplateContext::EndElement()
789 : : {
790 [ + - ][ + - ]: 3 : rtl::Reference< XMLTableImport > xTableImport( GetImport().GetShapeImport()->GetShapeTableImport() );
[ + - ][ + - ]
[ + - ]
791 [ + - ]: 3 : if( xTableImport.is() )
792 [ + - ][ + - ]: 3 : xTableImport->addTableTemplate( msTemplateStyleName, maTableTemplate );
793 : 3 : }
794 : :
795 : : // --------------------------------------------------------------------
796 : :
797 : 21 : SvXMLImportContext * XMLTableTemplateContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
798 : : {
799 [ + - ]: 21 : if( nPrefix == XML_NAMESPACE_TABLE )
800 : : {
801 : 21 : const TableStyleElement* pElements = getTableStyleMap();
802 [ + - ][ + + ]: 99 : while( (pElements->meElement != XML_TOKEN_END) && !IsXMLToken( rLocalName, pElements->meElement ) )
[ + + ]
803 : 78 : pElements++;
804 : :
805 [ + - ]: 21 : if( pElements->meElement != XML_TOKEN_END )
806 : : {
807 [ + - ]: 21 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
808 [ + - ]: 42 : for(sal_Int16 i=0; i < nAttrCount; i++)
809 : : {
810 : 21 : OUString sAttrName;
811 [ + - ][ + - ]: 21 : sal_uInt16 nAttrPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( i ), &sAttrName );
[ + - ]
812 [ + - ][ + - ]: 42 : if( (nAttrPrefix == XML_NAMESPACE_TEXT || nAttrPrefix == XML_NAMESPACE_TABLE) &&
[ + - ][ + - ]
813 [ + - ]: 21 : IsXMLToken( sAttrName, XML_STYLE_NAME ) )
814 : : {
815 [ + - ][ + - ]: 21 : maTableTemplate[pElements->msStyleName] = xAttrList->getValueByIndex( i );
[ + - ]
816 : : break;
817 : : }
818 [ - + ]: 21 : }
819 : : }
820 : : }
821 : :
822 : 21 : return SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
823 : : }
824 : :
825 : : // --------------------------------------------------------------------
826 : :
827 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|