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