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