xref: /AOO41X/main/xmloff/source/chart/SchXMLImport.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 "SchXMLImport.hxx"
32*cdf0e10cSrcweir #include "SchXMLChartContext.hxx"
33*cdf0e10cSrcweir #include "contexts.hxx"
34*cdf0e10cSrcweir #include "XMLChartPropertySetMapper.hxx"
35*cdf0e10cSrcweir #include "SchXMLTools.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <tools/debug.hxx>
38*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
39*cdf0e10cSrcweir // header for class ByteString
40*cdf0e10cSrcweir #include <tools/string.hxx>
41*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
42*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
43*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
44*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
45*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
46*cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx>
47*cdf0e10cSrcweir #include <xmloff/xmlstyle.hxx>
48*cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/chart/XChartDocument.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/chart/ChartDataRowSource.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataReceiver.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataProvider.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp>
56*cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
57*cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir #include <typeinfo>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir using namespace com::sun::star;
66*cdf0e10cSrcweir using namespace ::xmloff::token;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir using ::rtl::OUString;
69*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
70*cdf0e10cSrcweir using ::rtl::OUStringToOString;
71*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
72*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir namespace
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir Reference< uno::XComponentContext > lcl_getComponentContext()
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     Reference< uno::XComponentContext > xContext;
79*cdf0e10cSrcweir     try
80*cdf0e10cSrcweir     {
81*cdf0e10cSrcweir         Reference< beans::XPropertySet > xFactProp( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
82*cdf0e10cSrcweir         if( xFactProp.is())
83*cdf0e10cSrcweir             xFactProp->getPropertyValue(OUString::createFromAscii("DefaultContext")) >>= xContext;
84*cdf0e10cSrcweir     }
85*cdf0e10cSrcweir     catch( uno::Exception& )
86*cdf0e10cSrcweir     {}
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     return xContext;
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir class lcl_MatchesChartType : public ::std::unary_function< Reference< chart2::XChartType >, bool >
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir public:
94*cdf0e10cSrcweir     explicit lcl_MatchesChartType( const OUString & aChartTypeName ) :
95*cdf0e10cSrcweir             m_aChartTypeName( aChartTypeName )
96*cdf0e10cSrcweir     {}
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     bool operator () ( const Reference< chart2::XChartType > & xChartType ) const
99*cdf0e10cSrcweir     {
100*cdf0e10cSrcweir         return (xChartType.is() &&
101*cdf0e10cSrcweir                 xChartType->getChartType().equals( m_aChartTypeName ));
102*cdf0e10cSrcweir     }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir private:
105*cdf0e10cSrcweir     OUString m_aChartTypeName;
106*cdf0e10cSrcweir };
107*cdf0e10cSrcweir } // anonymous namespace
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir /* ----------------------------------------
110*cdf0e10cSrcweir    TokenMaps for distinguishing different
111*cdf0e10cSrcweir    tokens in different contexts
112*cdf0e10cSrcweir    ----------------------------------------*/
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir // ----------------------------------------
115*cdf0e10cSrcweir // element maps
116*cdf0e10cSrcweir // ----------------------------------------
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir // ----------------------------------------
125*cdf0e10cSrcweir // attribute maps
126*cdf0e10cSrcweir // ----------------------------------------
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir // ========================================
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir SchXMLImportHelper::SchXMLImportHelper() :
139*cdf0e10cSrcweir 		mpAutoStyles( 0 ),
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 		mpChartDocElemTokenMap( 0 ),
142*cdf0e10cSrcweir 		mpTableElemTokenMap( 0 ),
143*cdf0e10cSrcweir 		mpChartElemTokenMap( 0 ),
144*cdf0e10cSrcweir 		mpPlotAreaElemTokenMap( 0 ),
145*cdf0e10cSrcweir 		mpSeriesElemTokenMap( 0 ),
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 		mpChartAttrTokenMap( 0 ),
148*cdf0e10cSrcweir 		mpPlotAreaAttrTokenMap( 0 ),
149*cdf0e10cSrcweir 		mpAutoStyleAttrTokenMap( 0 ),
150*cdf0e10cSrcweir 		mpCellAttrTokenMap( 0 ),
151*cdf0e10cSrcweir 		mpSeriesAttrTokenMap( 0 ),
152*cdf0e10cSrcweir         mpRegEquationAttrTokenMap( 0 )
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir SchXMLImportHelper::~SchXMLImportHelper()
157*cdf0e10cSrcweir {
158*cdf0e10cSrcweir 		// delete token maps
159*cdf0e10cSrcweir 	if( mpChartDocElemTokenMap )
160*cdf0e10cSrcweir 		delete mpChartDocElemTokenMap;
161*cdf0e10cSrcweir 	if( mpTableElemTokenMap )
162*cdf0e10cSrcweir 		delete mpTableElemTokenMap;
163*cdf0e10cSrcweir 	if( mpChartElemTokenMap )
164*cdf0e10cSrcweir 		delete mpChartElemTokenMap;
165*cdf0e10cSrcweir 	if( mpPlotAreaElemTokenMap )
166*cdf0e10cSrcweir 		delete mpPlotAreaElemTokenMap;
167*cdf0e10cSrcweir 	if( mpSeriesElemTokenMap )
168*cdf0e10cSrcweir 		delete mpSeriesElemTokenMap;
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	if( mpChartAttrTokenMap )
171*cdf0e10cSrcweir 		delete mpChartAttrTokenMap;
172*cdf0e10cSrcweir 	if( mpPlotAreaAttrTokenMap )
173*cdf0e10cSrcweir 		delete mpPlotAreaAttrTokenMap;
174*cdf0e10cSrcweir 	if( mpAutoStyleAttrTokenMap )
175*cdf0e10cSrcweir 		delete mpAutoStyleAttrTokenMap;
176*cdf0e10cSrcweir 	if( mpCellAttrTokenMap )
177*cdf0e10cSrcweir 		delete mpCellAttrTokenMap;
178*cdf0e10cSrcweir 	if( mpSeriesAttrTokenMap )
179*cdf0e10cSrcweir 		delete mpSeriesAttrTokenMap;
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir SvXMLImportContext* SchXMLImportHelper::CreateChartContext(
183*cdf0e10cSrcweir 	SvXMLImport& rImport,
184*cdf0e10cSrcweir 	sal_uInt16 nPrefix, const OUString& rLocalName,
185*cdf0e10cSrcweir 	const Reference< frame::XModel > xChartModel,
186*cdf0e10cSrcweir 	const Reference< xml::sax::XAttributeList >& )
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir 	SvXMLImportContext* pContext = 0;
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	Reference< chart::XChartDocument > xDoc( xChartModel, uno::UNO_QUERY );
191*cdf0e10cSrcweir 	if( xDoc.is())
192*cdf0e10cSrcweir 	{
193*cdf0e10cSrcweir 		mxChartDoc = xDoc;
194*cdf0e10cSrcweir 		pContext = new SchXMLChartContext( *this, rImport, rLocalName );
195*cdf0e10cSrcweir 	}
196*cdf0e10cSrcweir 	else
197*cdf0e10cSrcweir 	{
198*cdf0e10cSrcweir 		DBG_ERROR( "No valid XChartDocument given as XModel" );
199*cdf0e10cSrcweir 		pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName );
200*cdf0e10cSrcweir 	}
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 	return pContext;
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir /* ----------------------------------------
206*cdf0e10cSrcweir    get various token maps
207*cdf0e10cSrcweir    ----------------------------------------*/
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetDocElemTokenMap()
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir 	if( ! mpChartDocElemTokenMap )
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aDocElemTokenMap[] =
214*cdf0e10cSrcweir         {
215*cdf0e10cSrcweir 	        { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES,	XML_TOK_DOC_AUTOSTYLES	},
216*cdf0e10cSrcweir 	        { XML_NAMESPACE_OFFICE, XML_STYLES,			    XML_TOK_DOC_STYLES	},
217*cdf0e10cSrcweir 	        { XML_NAMESPACE_OFFICE, XML_META, 				XML_TOK_DOC_META	},
218*cdf0e10cSrcweir 	        { XML_NAMESPACE_OFFICE, XML_BODY, 				XML_TOK_DOC_BODY	},
219*cdf0e10cSrcweir 	        XML_TOKEN_MAP_END
220*cdf0e10cSrcweir         };
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 		mpChartDocElemTokenMap = new SvXMLTokenMap( aDocElemTokenMap );
223*cdf0e10cSrcweir     } // if( ! mpChartDocElemTokenMap )
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 	return *mpChartDocElemTokenMap;
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetTableElemTokenMap()
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir 	if( ! mpTableElemTokenMap )
231*cdf0e10cSrcweir     {
232*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aTableElemTokenMap[] =
233*cdf0e10cSrcweir     {
234*cdf0e10cSrcweir 	    { XML_NAMESPACE_TABLE,	XML_TABLE_HEADER_COLUMNS,	XML_TOK_TABLE_HEADER_COLS	},
235*cdf0e10cSrcweir 	    { XML_NAMESPACE_TABLE,	XML_TABLE_COLUMNS,			XML_TOK_TABLE_COLUMNS		},
236*cdf0e10cSrcweir 	    { XML_NAMESPACE_TABLE,	XML_TABLE_COLUMN,			XML_TOK_TABLE_COLUMN		},
237*cdf0e10cSrcweir 	    { XML_NAMESPACE_TABLE,	XML_TABLE_HEADER_ROWS,		XML_TOK_TABLE_HEADER_ROWS	},
238*cdf0e10cSrcweir 	    { XML_NAMESPACE_TABLE,	XML_TABLE_ROWS,			    XML_TOK_TABLE_ROWS 			},
239*cdf0e10cSrcweir 	    { XML_NAMESPACE_TABLE,	XML_TABLE_ROW,				XML_TOK_TABLE_ROW 			},
240*cdf0e10cSrcweir 	    XML_TOKEN_MAP_END
241*cdf0e10cSrcweir     };
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 		mpTableElemTokenMap = new SvXMLTokenMap( aTableElemTokenMap );
244*cdf0e10cSrcweir     } // if( ! mpTableElemTokenMap )
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 	return *mpTableElemTokenMap;
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetChartElemTokenMap()
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir 	if( ! mpChartElemTokenMap )
252*cdf0e10cSrcweir     {
253*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aChartElemTokenMap[] =
254*cdf0e10cSrcweir         {
255*cdf0e10cSrcweir 	        { XML_NAMESPACE_CHART,	XML_PLOT_AREA,				XML_TOK_CHART_PLOT_AREA		},
256*cdf0e10cSrcweir 	        { XML_NAMESPACE_CHART,	XML_TITLE,					XML_TOK_CHART_TITLE			},
257*cdf0e10cSrcweir 	        { XML_NAMESPACE_CHART,	XML_SUBTITLE,				XML_TOK_CHART_SUBTITLE		},
258*cdf0e10cSrcweir 	        { XML_NAMESPACE_CHART,	XML_LEGEND,				XML_TOK_CHART_LEGEND		},
259*cdf0e10cSrcweir 	        { XML_NAMESPACE_TABLE,	XML_TABLE,					XML_TOK_CHART_TABLE			},
260*cdf0e10cSrcweir 	        XML_TOKEN_MAP_END
261*cdf0e10cSrcweir         };
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 		mpChartElemTokenMap = new SvXMLTokenMap( aChartElemTokenMap );
264*cdf0e10cSrcweir     } // if( ! mpChartElemTokenMap )
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir 	return *mpChartElemTokenMap;
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetPlotAreaElemTokenMap()
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir 	if( ! mpPlotAreaElemTokenMap )
272*cdf0e10cSrcweir     {
273*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aPlotAreaElemTokenMap[] =
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir     { XML_NAMESPACE_CHART_EXT,	XML_COORDINATE_REGION,		XML_TOK_PA_COORDINATE_REGION_EXT },
276*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,	XML_COORDINATE_REGION,		XML_TOK_PA_COORDINATE_REGION },
277*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_AXIS,					XML_TOK_PA_AXIS				},
278*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_SERIES,				    XML_TOK_PA_SERIES			},
279*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_WALL,					XML_TOK_PA_WALL				},
280*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_FLOOR,					XML_TOK_PA_FLOOR			},
281*cdf0e10cSrcweir 	{ XML_NAMESPACE_DR3D,	XML_LIGHT,					XML_TOK_PA_LIGHT_SOURCE		},
282*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,  XML_STOCK_GAIN_MARKER,      XML_TOK_PA_STOCK_GAIN       },
283*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,  XML_STOCK_LOSS_MARKER,      XML_TOK_PA_STOCK_LOSS       },
284*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,  XML_STOCK_RANGE_LINE,       XML_TOK_PA_STOCK_RANGE      },
285*cdf0e10cSrcweir 	XML_TOKEN_MAP_END
286*cdf0e10cSrcweir };
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 		mpPlotAreaElemTokenMap = new SvXMLTokenMap( aPlotAreaElemTokenMap );
289*cdf0e10cSrcweir     } // if( ! mpPlotAreaElemTokenMap )
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 	return *mpPlotAreaElemTokenMap;
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetSeriesElemTokenMap()
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir 	if( ! mpSeriesElemTokenMap )
297*cdf0e10cSrcweir     {
298*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aSeriesElemTokenMap[] =
299*cdf0e10cSrcweir {
300*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_DATA_POINT,	      XML_TOK_SERIES_DATA_POINT       },
301*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_DOMAIN,		      XML_TOK_SERIES_DOMAIN	          },
302*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,	XML_MEAN_VALUE,       XML_TOK_SERIES_MEAN_VALUE_LINE  },
303*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,	XML_REGRESSION_CURVE, XML_TOK_SERIES_REGRESSION_CURVE },
304*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,	XML_ERROR_INDICATOR,  XML_TOK_SERIES_ERROR_INDICATOR  },
305*cdf0e10cSrcweir 	XML_TOKEN_MAP_END
306*cdf0e10cSrcweir };
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir 		mpSeriesElemTokenMap = new SvXMLTokenMap( aSeriesElemTokenMap );
309*cdf0e10cSrcweir     } // if( ! mpSeriesElemTokenMap )
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 	return *mpSeriesElemTokenMap;
312*cdf0e10cSrcweir }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir // ----------------------------------------
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetChartAttrTokenMap()
317*cdf0e10cSrcweir {
318*cdf0e10cSrcweir 	if( ! mpChartAttrTokenMap )
319*cdf0e10cSrcweir     {
320*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aChartAttrTokenMap[] =
321*cdf0e10cSrcweir {
322*cdf0e10cSrcweir     { XML_NAMESPACE_XLINK,  XML_HREF,                   XML_TOK_CHART_HREF          },
323*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_CLASS,					XML_TOK_CHART_CLASS			},
324*cdf0e10cSrcweir 	{ XML_NAMESPACE_SVG,	XML_WIDTH,					XML_TOK_CHART_WIDTH			},
325*cdf0e10cSrcweir 	{ XML_NAMESPACE_SVG,	XML_HEIGHT,				    XML_TOK_CHART_HEIGHT		},
326*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_STYLE_NAME,			    XML_TOK_CHART_STYLE_NAME	},
327*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,  XML_COLUMN_MAPPING,         XML_TOK_CHART_COL_MAPPING   },
328*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,  XML_ROW_MAPPING,            XML_TOK_CHART_ROW_MAPPING   },
329*cdf0e10cSrcweir 	XML_TOKEN_MAP_END
330*cdf0e10cSrcweir };
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 		mpChartAttrTokenMap = new SvXMLTokenMap( aChartAttrTokenMap );
333*cdf0e10cSrcweir     } // if( ! mpChartAttrTokenMap )
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 	return *mpChartAttrTokenMap;
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetPlotAreaAttrTokenMap()
339*cdf0e10cSrcweir {
340*cdf0e10cSrcweir 	if( ! mpPlotAreaAttrTokenMap )
341*cdf0e10cSrcweir     {
342*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aPlotAreaAttrTokenMap[] =
343*cdf0e10cSrcweir {
344*cdf0e10cSrcweir     { XML_NAMESPACE_SVG,    XML_X,                      XML_TOK_PA_X                 },
345*cdf0e10cSrcweir     { XML_NAMESPACE_SVG,    XML_Y,                      XML_TOK_PA_Y                 },
346*cdf0e10cSrcweir     { XML_NAMESPACE_SVG,    XML_WIDTH,                  XML_TOK_PA_WIDTH             },
347*cdf0e10cSrcweir     { XML_NAMESPACE_SVG,    XML_HEIGHT,                 XML_TOK_PA_HEIGHT            },
348*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,  XML_STYLE_NAME,             XML_TOK_PA_STYLE_NAME        },
349*cdf0e10cSrcweir     { XML_NAMESPACE_TABLE,  XML_CELL_RANGE_ADDRESS,     XML_TOK_PA_CHART_ADDRESS     },
350*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,  XML_DATA_SOURCE_HAS_LABELS, XML_TOK_PA_DS_HAS_LABELS     },
351*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_TRANSFORM,              XML_TOK_PA_TRANSFORM         },
352*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_VRP,                    XML_TOK_PA_VRP               },
353*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_VPN,                    XML_TOK_PA_VPN               },
354*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_VUP,                    XML_TOK_PA_VUP               },
355*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_PROJECTION,             XML_TOK_PA_PROJECTION        },
356*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_DISTANCE,               XML_TOK_PA_DISTANCE          },
357*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_FOCAL_LENGTH,           XML_TOK_PA_FOCAL_LENGTH      },
358*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_SHADOW_SLANT,           XML_TOK_PA_SHADOW_SLANT      },
359*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_SHADE_MODE,             XML_TOK_PA_SHADE_MODE        },
360*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_AMBIENT_COLOR,          XML_TOK_PA_AMBIENT_COLOR     },
361*cdf0e10cSrcweir     { XML_NAMESPACE_DR3D,   XML_LIGHTING_MODE,          XML_TOK_PA_LIGHTING_MODE     },
362*cdf0e10cSrcweir     XML_TOKEN_MAP_END
363*cdf0e10cSrcweir };
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 		mpPlotAreaAttrTokenMap = new SvXMLTokenMap( aPlotAreaAttrTokenMap );
366*cdf0e10cSrcweir     } // if( ! mpPlotAreaAttrTokenMap )
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir 	return *mpPlotAreaAttrTokenMap;
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetAutoStyleAttrTokenMap()
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir 	if( ! mpAutoStyleAttrTokenMap )
374*cdf0e10cSrcweir     {
375*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aAutoStyleAttrTokenMap[] =
376*cdf0e10cSrcweir {
377*cdf0e10cSrcweir 	{ XML_NAMESPACE_STYLE,	XML_FAMILY,				    XML_TOK_AS_FAMILY			},
378*cdf0e10cSrcweir 	{ XML_NAMESPACE_STYLE,	XML_NAME,					XML_TOK_AS_NAME				},
379*cdf0e10cSrcweir 	XML_TOKEN_MAP_END
380*cdf0e10cSrcweir };
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 		mpAutoStyleAttrTokenMap = new SvXMLTokenMap( aAutoStyleAttrTokenMap );
383*cdf0e10cSrcweir     } // if( ! mpAutoStyleAttrTokenMap )
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir 	return *mpAutoStyleAttrTokenMap;
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetCellAttrTokenMap()
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir 	if( ! mpCellAttrTokenMap )
391*cdf0e10cSrcweir     {
392*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aCellAttrTokenMap[] =
393*cdf0e10cSrcweir {
394*cdf0e10cSrcweir 	{ XML_NAMESPACE_OFFICE,	XML_VALUE_TYPE,			    XML_TOK_CELL_VAL_TYPE		},
395*cdf0e10cSrcweir 	{ XML_NAMESPACE_OFFICE,	XML_VALUE,					XML_TOK_CELL_VALUE			},
396*cdf0e10cSrcweir 	XML_TOKEN_MAP_END
397*cdf0e10cSrcweir };
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 		mpCellAttrTokenMap = new SvXMLTokenMap( aCellAttrTokenMap );
400*cdf0e10cSrcweir     } // if( ! mpCellAttrTokenMap )
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 	return *mpCellAttrTokenMap;
403*cdf0e10cSrcweir }
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetSeriesAttrTokenMap()
406*cdf0e10cSrcweir {
407*cdf0e10cSrcweir 	if( ! mpSeriesAttrTokenMap )
408*cdf0e10cSrcweir     {
409*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aSeriesAttrTokenMap[] =
410*cdf0e10cSrcweir {
411*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_VALUES_CELL_RANGE_ADDRESS,	XML_TOK_SERIES_CELL_RANGE	 },
412*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_LABEL_CELL_ADDRESS,         XML_TOK_SERIES_LABEL_ADDRESS },
413*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_ATTACHED_AXIS,				XML_TOK_SERIES_ATTACHED_AXIS },
414*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_STYLE_NAME, 				XML_TOK_SERIES_STYLE_NAME	 },
415*cdf0e10cSrcweir 	{ XML_NAMESPACE_CHART,	XML_CLASS, 					    XML_TOK_SERIES_CHART_CLASS	 },
416*cdf0e10cSrcweir 	XML_TOKEN_MAP_END
417*cdf0e10cSrcweir };
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir 		mpSeriesAttrTokenMap = new SvXMLTokenMap( aSeriesAttrTokenMap );
420*cdf0e10cSrcweir     } // if( ! mpSeriesAttrTokenMap )
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir 	return *mpSeriesAttrTokenMap;
423*cdf0e10cSrcweir }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir const SvXMLTokenMap& SchXMLImportHelper::GetRegEquationAttrTokenMap()
426*cdf0e10cSrcweir {
427*cdf0e10cSrcweir 	if( ! mpRegEquationAttrTokenMap )
428*cdf0e10cSrcweir     {
429*cdf0e10cSrcweir         static __FAR_DATA SvXMLTokenMapEntry aRegressionEquationAttrTokenMap[] =
430*cdf0e10cSrcweir {
431*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,  XML_STYLE_NAME,             XML_TOK_REGEQ_STYLE_NAME         },
432*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,  XML_DISPLAY_EQUATION,       XML_TOK_REGEQ_DISPLAY_EQUATION   },
433*cdf0e10cSrcweir     { XML_NAMESPACE_CHART,  XML_DISPLAY_R_SQUARE,       XML_TOK_REGEQ_DISPLAY_R_SQUARE   },
434*cdf0e10cSrcweir     { XML_NAMESPACE_SVG,    XML_X,                      XML_TOK_REGEQ_POS_X              },
435*cdf0e10cSrcweir     { XML_NAMESPACE_SVG,    XML_Y,                      XML_TOK_REGEQ_POS_Y              },
436*cdf0e10cSrcweir     XML_TOKEN_MAP_END
437*cdf0e10cSrcweir };
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 		mpRegEquationAttrTokenMap = new SvXMLTokenMap( aRegressionEquationAttrTokenMap );
440*cdf0e10cSrcweir     } // if( ! mpRegEquationAttrTokenMap )
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 	return *mpRegEquationAttrTokenMap;
443*cdf0e10cSrcweir }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir // ----------------------------------------
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir //static
448*cdf0e10cSrcweir void SchXMLImportHelper::DeleteDataSeries(
449*cdf0e10cSrcweir                     const Reference< chart2::XDataSeries > & xSeries,
450*cdf0e10cSrcweir                     const Reference< chart2::XChartDocument > & xDoc )
451*cdf0e10cSrcweir {
452*cdf0e10cSrcweir     if( xDoc.is() )
453*cdf0e10cSrcweir     try
454*cdf0e10cSrcweir     {
455*cdf0e10cSrcweir         Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
456*cdf0e10cSrcweir             xDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
457*cdf0e10cSrcweir         Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
458*cdf0e10cSrcweir             xCooSysCnt->getCoordinateSystems());
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir         sal_Int32 nCooSysIndex = 0;
461*cdf0e10cSrcweir         for( nCooSysIndex=0; nCooSysIndex<aCooSysSeq.getLength(); nCooSysIndex++ )
462*cdf0e10cSrcweir         {
463*cdf0e10cSrcweir             Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[ nCooSysIndex ], uno::UNO_QUERY_THROW );
464*cdf0e10cSrcweir             Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes());
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir             sal_Int32 nChartTypeIndex = 0;
467*cdf0e10cSrcweir             for( nChartTypeIndex=0; nChartTypeIndex<aChartTypes.getLength(); nChartTypeIndex++ )
468*cdf0e10cSrcweir             {
469*cdf0e10cSrcweir                 Reference< chart2::XDataSeriesContainer > xSeriesCnt( aChartTypes[nChartTypeIndex], uno::UNO_QUERY_THROW );
470*cdf0e10cSrcweir                 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesCnt->getDataSeries());
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir                 sal_Int32 nSeriesIndex = 0;
473*cdf0e10cSrcweir                 for( nSeriesIndex=0; nSeriesIndex<aSeriesSeq.getLength(); nSeriesIndex++ )
474*cdf0e10cSrcweir                 {
475*cdf0e10cSrcweir                     if( xSeries==aSeriesSeq[nSeriesIndex] )
476*cdf0e10cSrcweir                     {
477*cdf0e10cSrcweir                         xSeriesCnt->removeDataSeries(xSeries);
478*cdf0e10cSrcweir                         return;
479*cdf0e10cSrcweir                     }
480*cdf0e10cSrcweir                 }
481*cdf0e10cSrcweir             }
482*cdf0e10cSrcweir         }
483*cdf0e10cSrcweir     }
484*cdf0e10cSrcweir     catch( uno::Exception & ex )
485*cdf0e10cSrcweir     {
486*cdf0e10cSrcweir         (void)ex; // avoid warning for pro build
487*cdf0e10cSrcweir         OSL_ENSURE( false, OUStringToOString(
488*cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM( "Exception caught. Type: " )) +
489*cdf0e10cSrcweir                         OUString::createFromAscii( typeid( ex ).name()) +
490*cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM( ", Message: " )) +
491*cdf0e10cSrcweir                         ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
492*cdf0e10cSrcweir     }
493*cdf0e10cSrcweir }
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir // static
496*cdf0e10cSrcweir Reference< chart2::XDataSeries > SchXMLImportHelper::GetNewDataSeries(
497*cdf0e10cSrcweir     const Reference< chart2::XChartDocument > & xDoc,
498*cdf0e10cSrcweir     sal_Int32 nCoordinateSystemIndex,
499*cdf0e10cSrcweir     const OUString & rChartTypeName,
500*cdf0e10cSrcweir     bool bPushLastChartType /* = false */ )
501*cdf0e10cSrcweir {
502*cdf0e10cSrcweir     Reference< chart2::XDataSeries > xResult;
503*cdf0e10cSrcweir     if(!xDoc.is())
504*cdf0e10cSrcweir         return xResult;
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir     try
507*cdf0e10cSrcweir     {
508*cdf0e10cSrcweir         Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
509*cdf0e10cSrcweir             xDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
510*cdf0e10cSrcweir         Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
511*cdf0e10cSrcweir             xCooSysCnt->getCoordinateSystems());
512*cdf0e10cSrcweir         Reference< uno::XComponentContext > xContext( lcl_getComponentContext());
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir         if( nCoordinateSystemIndex < aCooSysSeq.getLength())
515*cdf0e10cSrcweir         {
516*cdf0e10cSrcweir             Reference< chart2::XChartType > xCurrentType;
517*cdf0e10cSrcweir             {
518*cdf0e10cSrcweir                 Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[ nCoordinateSystemIndex ], uno::UNO_QUERY_THROW );
519*cdf0e10cSrcweir                 Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes());
520*cdf0e10cSrcweir                 // find matching chart type group
521*cdf0e10cSrcweir                 const Reference< chart2::XChartType > * pBegin = aChartTypes.getConstArray();
522*cdf0e10cSrcweir                 const Reference< chart2::XChartType > * pEnd = pBegin + aChartTypes.getLength();
523*cdf0e10cSrcweir                 const Reference< chart2::XChartType > * pIt =
524*cdf0e10cSrcweir                     ::std::find_if( pBegin, pEnd, lcl_MatchesChartType( rChartTypeName ));
525*cdf0e10cSrcweir                 if( pIt != pEnd )
526*cdf0e10cSrcweir                     xCurrentType.set( *pIt );
527*cdf0e10cSrcweir                 // if chart type is set at series and differs from current one,
528*cdf0e10cSrcweir                 // create a new chart type
529*cdf0e10cSrcweir                 if( !xCurrentType.is())
530*cdf0e10cSrcweir                 {
531*cdf0e10cSrcweir                     xCurrentType.set(
532*cdf0e10cSrcweir                         xContext->getServiceManager()->createInstanceWithContext( rChartTypeName, xContext ),
533*cdf0e10cSrcweir                         uno::UNO_QUERY );
534*cdf0e10cSrcweir                     if( xCurrentType.is())
535*cdf0e10cSrcweir                     {
536*cdf0e10cSrcweir                         if( bPushLastChartType && aChartTypes.getLength())
537*cdf0e10cSrcweir                         {
538*cdf0e10cSrcweir                             sal_Int32 nIndex( aChartTypes.getLength() - 1 );
539*cdf0e10cSrcweir                             aChartTypes.realloc( aChartTypes.getLength() + 1 );
540*cdf0e10cSrcweir                             aChartTypes[ nIndex + 1 ] = aChartTypes[ nIndex ];
541*cdf0e10cSrcweir                             aChartTypes[ nIndex ] = xCurrentType;
542*cdf0e10cSrcweir                             xCTCnt->setChartTypes( aChartTypes );
543*cdf0e10cSrcweir                         }
544*cdf0e10cSrcweir                         else
545*cdf0e10cSrcweir                             xCTCnt->addChartType( xCurrentType );
546*cdf0e10cSrcweir                     }
547*cdf0e10cSrcweir                 }
548*cdf0e10cSrcweir             }
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir             if( xCurrentType.is())
551*cdf0e10cSrcweir             {
552*cdf0e10cSrcweir                 Reference< chart2::XDataSeriesContainer > xSeriesCnt( xCurrentType, uno::UNO_QUERY_THROW );
553*cdf0e10cSrcweir                 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesCnt->getDataSeries());
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir                 if( xContext.is() )
556*cdf0e10cSrcweir                 {
557*cdf0e10cSrcweir                     xResult.set(
558*cdf0e10cSrcweir                         xContext->getServiceManager()->createInstanceWithContext(
559*cdf0e10cSrcweir                             OUString::createFromAscii("com.sun.star.chart2.DataSeries"),
560*cdf0e10cSrcweir                             xContext ), uno::UNO_QUERY_THROW );
561*cdf0e10cSrcweir                 }
562*cdf0e10cSrcweir                 if( xResult.is() )
563*cdf0e10cSrcweir                     xSeriesCnt->addDataSeries( xResult );
564*cdf0e10cSrcweir             }
565*cdf0e10cSrcweir         }
566*cdf0e10cSrcweir     }
567*cdf0e10cSrcweir     catch( uno::Exception & ex )
568*cdf0e10cSrcweir     {
569*cdf0e10cSrcweir         (void)ex; // avoid warning for pro build
570*cdf0e10cSrcweir         OSL_ENSURE( false, OUStringToOString(
571*cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM( "Exception caught. Type: " )) +
572*cdf0e10cSrcweir                         OUString::createFromAscii( typeid( ex ).name()) +
573*cdf0e10cSrcweir                         OUString( RTL_CONSTASCII_USTRINGPARAM( ", Message: " )) +
574*cdf0e10cSrcweir                         ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
575*cdf0e10cSrcweir     }
576*cdf0e10cSrcweir     return xResult;
577*cdf0e10cSrcweir }
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir // static
580*cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > SchXMLImportHelper::GetNewLabeledDataSequence()
581*cdf0e10cSrcweir {
582*cdf0e10cSrcweir     // @todo: remove this asap
583*cdf0e10cSrcweir     OSL_ENSURE( false, "Do not call this method" );
584*cdf0e10cSrcweir     Reference< chart2::data::XLabeledDataSequence >  xResult;
585*cdf0e10cSrcweir     // DO NOT USED -- DEPRECATED. Use SchXMLTools::GetNewLabeledDataSequence() instead
586*cdf0e10cSrcweir     return xResult;
587*cdf0e10cSrcweir }
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir // ========================================
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir // #110680#
592*cdf0e10cSrcweir SchXMLImport::SchXMLImport(
593*cdf0e10cSrcweir 	const Reference< lang::XMultiServiceFactory >& xServiceFactory,
594*cdf0e10cSrcweir 	sal_uInt16 nImportFlags ) :
595*cdf0e10cSrcweir         SvXMLImport( xServiceFactory, nImportFlags )
596*cdf0e10cSrcweir {
597*cdf0e10cSrcweir     GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
598*cdf0e10cSrcweir     GetNamespaceMap().Add( GetXMLToken(XML_NP_CHART_EXT), GetXMLToken(XML_N_CHART_EXT), XML_NAMESPACE_CHART_EXT);
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir     mbIsGraphicLoadOnDemandSupported = false;
601*cdf0e10cSrcweir }
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir // #110680#
604*cdf0e10cSrcweir SchXMLImport::SchXMLImport(
605*cdf0e10cSrcweir 	const Reference< lang::XMultiServiceFactory >& xServiceFactory,
606*cdf0e10cSrcweir 	Reference< frame::XModel > xModel,
607*cdf0e10cSrcweir 	Reference< document::XGraphicObjectResolver >& rGrfContainer,
608*cdf0e10cSrcweir 	sal_Bool /*bLoadDoc*/, sal_Bool bShowProgress )
609*cdf0e10cSrcweir :	SvXMLImport( xServiceFactory, xModel, rGrfContainer )
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir     GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
612*cdf0e10cSrcweir     GetNamespaceMap().Add( GetXMLToken(XML_NP_CHART_EXT), GetXMLToken(XML_N_CHART_EXT), XML_NAMESPACE_CHART_EXT);
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir 	// get status indicator (if requested)
615*cdf0e10cSrcweir 	if( bShowProgress )
616*cdf0e10cSrcweir 	{
617*cdf0e10cSrcweir 		Reference< frame::XController > xController( xModel->getCurrentController());
618*cdf0e10cSrcweir 		if( xController.is())
619*cdf0e10cSrcweir 		{
620*cdf0e10cSrcweir 			Reference< frame::XFrame > xFrame( xController->getFrame());
621*cdf0e10cSrcweir 			if( xFrame.is())
622*cdf0e10cSrcweir 			{
623*cdf0e10cSrcweir 				Reference< task::XStatusIndicatorSupplier > xFactory( xFrame, uno::UNO_QUERY );
624*cdf0e10cSrcweir 				if( xFactory.is())
625*cdf0e10cSrcweir 				{
626*cdf0e10cSrcweir 					mxStatusIndicator = xFactory->getStatusIndicator();
627*cdf0e10cSrcweir 				}
628*cdf0e10cSrcweir 			}
629*cdf0e10cSrcweir 		}
630*cdf0e10cSrcweir 	}
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir 	// add progress view
633*cdf0e10cSrcweir 	if( mxStatusIndicator.is())
634*cdf0e10cSrcweir 	{
635*cdf0e10cSrcweir 		const OUString aText( RTL_CONSTASCII_USTRINGPARAM( "XML Import" ));
636*cdf0e10cSrcweir 		mxStatusIndicator->start( aText, 100 );		// use percentage as values
637*cdf0e10cSrcweir 	}
638*cdf0e10cSrcweir }
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir SchXMLImport::~SchXMLImport() throw ()
641*cdf0e10cSrcweir {
642*cdf0e10cSrcweir 	// stop progress view
643*cdf0e10cSrcweir 	if( mxStatusIndicator.is())
644*cdf0e10cSrcweir 	{
645*cdf0e10cSrcweir 		mxStatusIndicator->end();
646*cdf0e10cSrcweir 		mxStatusIndicator->reset();
647*cdf0e10cSrcweir 	}
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir     uno::Reference< chart2::XChartDocument > xChartDoc( GetModel(), uno::UNO_QUERY );
650*cdf0e10cSrcweir     if( xChartDoc.is() && xChartDoc->hasControllersLocked() )
651*cdf0e10cSrcweir         xChartDoc->unlockControllers();
652*cdf0e10cSrcweir }
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir // create the main context (subcontexts are created
655*cdf0e10cSrcweir // by the one created here)
656*cdf0e10cSrcweir SvXMLImportContext *SchXMLImport::CreateContext( sal_uInt16 nPrefix, const OUString& rLocalName,
657*cdf0e10cSrcweir 	const Reference< xml::sax::XAttributeList >& xAttrList )
658*cdf0e10cSrcweir {
659*cdf0e10cSrcweir 	SvXMLImportContext* pContext = 0;
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir 	// accept <office:document>
662*cdf0e10cSrcweir 	if( XML_NAMESPACE_OFFICE == nPrefix &&
663*cdf0e10cSrcweir 		( IsXMLToken( rLocalName, XML_DOCUMENT_STYLES) ||
664*cdf0e10cSrcweir           IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT) ))
665*cdf0e10cSrcweir 	{
666*cdf0e10cSrcweir 		pContext = new SchXMLDocContext( maImportHelper, *this, nPrefix, rLocalName );
667*cdf0e10cSrcweir 	} else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
668*cdf0e10cSrcweir 		        ( IsXMLToken(rLocalName, XML_DOCUMENT) ||
669*cdf0e10cSrcweir 		          (IsXMLToken(rLocalName, XML_DOCUMENT_META)
670*cdf0e10cSrcweir                    && (getImportFlags() & IMPORT_META) )) )
671*cdf0e10cSrcweir     {
672*cdf0e10cSrcweir         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
673*cdf0e10cSrcweir             GetModel(), uno::UNO_QUERY);
674*cdf0e10cSrcweir         // mst@: right now, this seems to be not supported, so it is untested
675*cdf0e10cSrcweir         if (xDPS.is()) {
676*cdf0e10cSrcweir             uno::Reference<xml::sax::XDocumentHandler> xDocBuilder(
677*cdf0e10cSrcweir                 mxServiceFactory->createInstance(
678*cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii(
679*cdf0e10cSrcweir                         "com.sun.star.xml.dom.SAXDocumentBuilder")),
680*cdf0e10cSrcweir                     uno::UNO_QUERY_THROW);
681*cdf0e10cSrcweir             pContext = (IsXMLToken(rLocalName, XML_DOCUMENT_META))
682*cdf0e10cSrcweir                 ? new SvXMLMetaDocumentContext(*this,
683*cdf0e10cSrcweir                             XML_NAMESPACE_OFFICE, rLocalName,
684*cdf0e10cSrcweir                             xDPS->getDocumentProperties(), xDocBuilder)
685*cdf0e10cSrcweir                 // flat OpenDocument file format
686*cdf0e10cSrcweir                 : new SchXMLFlatDocContext_Impl(
687*cdf0e10cSrcweir                             maImportHelper, *this, nPrefix, rLocalName,
688*cdf0e10cSrcweir                             xDPS->getDocumentProperties(), xDocBuilder);
689*cdf0e10cSrcweir         } else {
690*cdf0e10cSrcweir             pContext = (IsXMLToken(rLocalName, XML_DOCUMENT_META))
691*cdf0e10cSrcweir 		        ? SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList )
692*cdf0e10cSrcweir                 : new SchXMLDocContext( maImportHelper, *this,
693*cdf0e10cSrcweir                                         nPrefix, rLocalName );
694*cdf0e10cSrcweir         }
695*cdf0e10cSrcweir 	} else {
696*cdf0e10cSrcweir 		pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
697*cdf0e10cSrcweir 	}
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir 	return pContext;
700*cdf0e10cSrcweir }
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir SvXMLImportContext* SchXMLImport::CreateStylesContext(
703*cdf0e10cSrcweir     const OUString& rLocalName,
704*cdf0e10cSrcweir     const Reference<xml::sax::XAttributeList>& xAttrList )
705*cdf0e10cSrcweir {
706*cdf0e10cSrcweir     //#i103287# make sure that the version information is set before importing all the properties (especially stroke-opacity!)
707*cdf0e10cSrcweir     SchXMLTools::setBuildIDAtImportInfo( GetModel(), getImportInfo() );
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir     SvXMLStylesContext* pStylesCtxt =
710*cdf0e10cSrcweir         new SvXMLStylesContext( *(this), XML_NAMESPACE_OFFICE, rLocalName, xAttrList );
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir     // set context at base class, so that all auto-style classes are imported
713*cdf0e10cSrcweir     SetAutoStyles( pStylesCtxt );
714*cdf0e10cSrcweir     maImportHelper.SetAutoStylesContext( pStylesCtxt );
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir     return pStylesCtxt;
717*cdf0e10cSrcweir }
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir void SAL_CALL SchXMLImport::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
720*cdf0e10cSrcweir 	throw(lang::IllegalArgumentException, uno::RuntimeException)
721*cdf0e10cSrcweir {
722*cdf0e10cSrcweir     uno::Reference< chart2::XChartDocument > xOldDoc( GetModel(), uno::UNO_QUERY );
723*cdf0e10cSrcweir     if( xOldDoc.is() && xOldDoc->hasControllersLocked() )
724*cdf0e10cSrcweir         xOldDoc->unlockControllers();
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir     SvXMLImport::setTargetDocument( xDoc );
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir     //set data provider and number formatter
729*cdf0e10cSrcweir     // try to get an XDataProvider and set it
730*cdf0e10cSrcweir     // @todo: if we have our own data, we must not use the parent as data provider
731*cdf0e10cSrcweir     uno::Reference< chart2::XChartDocument > xChartDoc( GetModel(), uno::UNO_QUERY );
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir     if( xChartDoc.is() )
734*cdf0e10cSrcweir     try
735*cdf0e10cSrcweir     {
736*cdf0e10cSrcweir         //prevent rebuild of view during load ( necesarry especially if loaded not via load api, which is the case for example if binary files are loaded )
737*cdf0e10cSrcweir         xChartDoc->lockControllers();
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir         uno::Reference< container::XChild > xChild( xChartDoc, uno::UNO_QUERY );
740*cdf0e10cSrcweir         uno::Reference< chart2::data::XDataReceiver > xDataReceiver( xChartDoc, uno::UNO_QUERY );
741*cdf0e10cSrcweir         bool bHasOwnData = true;
742*cdf0e10cSrcweir         if( xChild.is() && xDataReceiver.is())
743*cdf0e10cSrcweir         {
744*cdf0e10cSrcweir             Reference< lang::XMultiServiceFactory > xFact( xChild->getParent(), uno::UNO_QUERY );
745*cdf0e10cSrcweir             if( xFact.is() )
746*cdf0e10cSrcweir             {
747*cdf0e10cSrcweir                 //if the parent has a number formatter we will use the numberformatter of the parent
748*cdf0e10cSrcweir                 Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xFact, uno::UNO_QUERY );
749*cdf0e10cSrcweir                 xDataReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir                 if ( !xChartDoc->getDataProvider().is() )
752*cdf0e10cSrcweir                 {
753*cdf0e10cSrcweir                     const OUString aDataProviderServiceName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.data.DataProvider"));
754*cdf0e10cSrcweir                     const uno::Sequence< OUString > aServiceNames( xFact->getAvailableServiceNames());
755*cdf0e10cSrcweir                     const OUString * pBegin = aServiceNames.getConstArray();
756*cdf0e10cSrcweir                     const OUString * pEnd = pBegin + aServiceNames.getLength();
757*cdf0e10cSrcweir                     if( ::std::find( pBegin, pEnd, aDataProviderServiceName ) != pEnd )
758*cdf0e10cSrcweir                     {
759*cdf0e10cSrcweir                         Reference< chart2::data::XDataProvider > xProvider(
760*cdf0e10cSrcweir                             xFact->createInstance( aDataProviderServiceName ), uno::UNO_QUERY );
761*cdf0e10cSrcweir                         if( xProvider.is())
762*cdf0e10cSrcweir                         {
763*cdf0e10cSrcweir                             xDataReceiver->attachDataProvider( xProvider );
764*cdf0e10cSrcweir                             bHasOwnData = false;
765*cdf0e10cSrcweir                         }
766*cdf0e10cSrcweir                     }
767*cdf0e10cSrcweir                 }
768*cdf0e10cSrcweir                 else
769*cdf0e10cSrcweir                     bHasOwnData = false;
770*cdf0e10cSrcweir             }
771*cdf0e10cSrcweir //             else we have no parent => we have our own data
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir             if( bHasOwnData && ! xChartDoc->hasInternalDataProvider() )
774*cdf0e10cSrcweir                 xChartDoc->createInternalDataProvider( sal_False );
775*cdf0e10cSrcweir         }
776*cdf0e10cSrcweir     }
777*cdf0e10cSrcweir     catch( uno::Exception & rEx )
778*cdf0e10cSrcweir     {
779*cdf0e10cSrcweir #ifdef DBG_UTIL
780*cdf0e10cSrcweir 		String aStr( rEx.Message );
781*cdf0e10cSrcweir 		ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
782*cdf0e10cSrcweir 		DBG_ERROR1( "SchXMLChartContext::StartElement(): Exception caught: %s", aBStr.GetBuffer());
783*cdf0e10cSrcweir #else
784*cdf0e10cSrcweir         (void)rEx; // avoid warning for pro build
785*cdf0e10cSrcweir #endif
786*cdf0e10cSrcweir     }
787*cdf0e10cSrcweir }
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir // export components ========================================
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir // first version: everything comes from one storage
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir Sequence< OUString > SAL_CALL SchXMLImport_getSupportedServiceNames() throw()
794*cdf0e10cSrcweir {
795*cdf0e10cSrcweir 	const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisImporter" ) );
796*cdf0e10cSrcweir 	const Sequence< OUString > aSeq( &aServiceName, 1 );
797*cdf0e10cSrcweir 	return aSeq;
798*cdf0e10cSrcweir }
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir OUString SAL_CALL SchXMLImport_getImplementationName() throw()
801*cdf0e10cSrcweir {
802*cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLImport" ) );
803*cdf0e10cSrcweir }
804*cdf0e10cSrcweir 
805*cdf0e10cSrcweir Reference< uno::XInterface > SAL_CALL SchXMLImport_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )
806*cdf0e10cSrcweir {
807*cdf0e10cSrcweir 	// #110680#
808*cdf0e10cSrcweir 	// return (cppu::OWeakObject*)new SchXMLImport();
809*cdf0e10cSrcweir 	return (cppu::OWeakObject*)new SchXMLImport(rSMgr);
810*cdf0e10cSrcweir }
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir // ============================================================
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir // multiple storage version: one for content / styles / meta
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir Sequence< OUString > SAL_CALL SchXMLImport_Styles_getSupportedServiceNames() throw()
817*cdf0e10cSrcweir {
818*cdf0e10cSrcweir 	const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisStylesImporter" ) );
819*cdf0e10cSrcweir 	const Sequence< OUString > aSeq( &aServiceName, 1 );
820*cdf0e10cSrcweir 	return aSeq;
821*cdf0e10cSrcweir }
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir OUString SAL_CALL SchXMLImport_Styles_getImplementationName() throw()
824*cdf0e10cSrcweir {
825*cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLImport.Styles" ) );
826*cdf0e10cSrcweir }
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir Reference< uno::XInterface > SAL_CALL SchXMLImport_Styles_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )
829*cdf0e10cSrcweir {
830*cdf0e10cSrcweir 	// #110680#
831*cdf0e10cSrcweir 	// return (cppu::OWeakObject*)new SchXMLImport( IMPORT_STYLES );
832*cdf0e10cSrcweir 	return (cppu::OWeakObject*)new SchXMLImport( rSMgr, IMPORT_STYLES );
833*cdf0e10cSrcweir }
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir // ------------------------------------------------------------
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir Sequence< OUString > SAL_CALL SchXMLImport_Content_getSupportedServiceNames() throw()
838*cdf0e10cSrcweir {
839*cdf0e10cSrcweir 	const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisContentImporter" ) );
840*cdf0e10cSrcweir 	const Sequence< OUString > aSeq( &aServiceName, 1 );
841*cdf0e10cSrcweir 	return aSeq;
842*cdf0e10cSrcweir }
843*cdf0e10cSrcweir 
844*cdf0e10cSrcweir OUString SAL_CALL SchXMLImport_Content_getImplementationName() throw()
845*cdf0e10cSrcweir {
846*cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLImport.Content" ) );
847*cdf0e10cSrcweir }
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir Reference< uno::XInterface > SAL_CALL SchXMLImport_Content_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )
850*cdf0e10cSrcweir {
851*cdf0e10cSrcweir 	// #110680#
852*cdf0e10cSrcweir 	// return (cppu::OWeakObject*)new SchXMLImport( IMPORT_CONTENT | IMPORT_AUTOSTYLES | IMPORT_FONTDECLS );
853*cdf0e10cSrcweir 	return (cppu::OWeakObject*)new SchXMLImport( rSMgr, IMPORT_CONTENT | IMPORT_AUTOSTYLES | IMPORT_FONTDECLS );
854*cdf0e10cSrcweir }
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir // ------------------------------------------------------------
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir Sequence< OUString > SAL_CALL SchXMLImport_Meta_getSupportedServiceNames() throw()
859*cdf0e10cSrcweir {
860*cdf0e10cSrcweir 	const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisMetaImporter" ) );
861*cdf0e10cSrcweir 	const Sequence< OUString > aSeq( &aServiceName, 1 );
862*cdf0e10cSrcweir 	return aSeq;
863*cdf0e10cSrcweir }
864*cdf0e10cSrcweir 
865*cdf0e10cSrcweir OUString SAL_CALL SchXMLImport_Meta_getImplementationName() throw()
866*cdf0e10cSrcweir {
867*cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLImport.Meta" ) );
868*cdf0e10cSrcweir }
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir Reference< uno::XInterface > SAL_CALL SchXMLImport_Meta_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )
871*cdf0e10cSrcweir {
872*cdf0e10cSrcweir 	// #110680#
873*cdf0e10cSrcweir 	// return (cppu::OWeakObject*)new SchXMLImport( IMPORT_META );
874*cdf0e10cSrcweir 	return (cppu::OWeakObject*)new SchXMLImport( rSMgr, IMPORT_META );
875*cdf0e10cSrcweir }
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir // XServiceInfo
878*cdf0e10cSrcweir OUString SAL_CALL SchXMLImport::getImplementationName() throw( uno::RuntimeException )
879*cdf0e10cSrcweir {
880*cdf0e10cSrcweir     switch( getImportFlags())
881*cdf0e10cSrcweir     {
882*cdf0e10cSrcweir         case IMPORT_ALL:
883*cdf0e10cSrcweir             return SchXMLImport_getImplementationName();
884*cdf0e10cSrcweir         case IMPORT_STYLES:
885*cdf0e10cSrcweir             return SchXMLImport_Styles_getImplementationName();
886*cdf0e10cSrcweir         case ( IMPORT_CONTENT | IMPORT_AUTOSTYLES | IMPORT_FONTDECLS ):
887*cdf0e10cSrcweir             return SchXMLImport_Content_getImplementationName();
888*cdf0e10cSrcweir         case IMPORT_META:
889*cdf0e10cSrcweir             return SchXMLImport_Meta_getImplementationName();
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir         case IMPORT_SETTINGS:
892*cdf0e10cSrcweir         // there is no settings component in chart
893*cdf0e10cSrcweir         default:
894*cdf0e10cSrcweir             return OUString::createFromAscii( "SchXMLImport" );
895*cdf0e10cSrcweir     }
896*cdf0e10cSrcweir }
897