merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / chart / SchXMLImport.cxx
blob9a8779630c82154b8a1dd95cc49bfc04e1e89a5a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SchXMLImport.cxx,v $
10 * $Revision: 1.41 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include "SchXMLImport.hxx"
35 #include "SchXMLChartContext.hxx"
36 #include "contexts.hxx"
37 #include "XMLChartPropertySetMapper.hxx"
38 #include "SchXMLTools.hxx"
40 #include <tools/debug.hxx>
41 #include <rtl/ustrbuf.hxx>
42 // header for class ByteString
43 #include <tools/string.hxx>
44 #include <comphelper/processfactory.hxx>
45 #include "xmlnmspe.hxx"
46 #include <xmloff/xmltoken.hxx>
47 #include <xmloff/xmluconv.hxx>
48 #include <xmloff/nmspmap.hxx>
49 #include <xmloff/xmlictxt.hxx>
50 #include <xmloff/xmlstyle.hxx>
51 #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
52 #include <com/sun/star/chart/XChartDocument.hpp>
53 #include <com/sun/star/chart/XChartDataArray.hpp>
54 #include <com/sun/star/chart/ChartDataRowSource.hpp>
55 #include <com/sun/star/container/XChild.hpp>
56 #include <com/sun/star/uno/XComponentContext.hpp>
57 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
58 #include <com/sun/star/chart2/data/XDataProvider.hpp>
59 #include <com/sun/star/chart2/XChartDocument.hpp>
60 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
61 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
62 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
64 #include <com/sun/star/document/XDocumentProperties.hpp>
65 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
67 #include <typeinfo>
69 using namespace com::sun::star;
70 using namespace ::xmloff::token;
72 using ::rtl::OUString;
73 using ::rtl::OUStringBuffer;
74 using ::rtl::OUStringToOString;
75 using ::com::sun::star::uno::Reference;
76 using ::com::sun::star::uno::Sequence;
78 namespace
80 Reference< uno::XComponentContext > lcl_getComponentContext()
82 Reference< uno::XComponentContext > xContext;
83 try
85 Reference< beans::XPropertySet > xFactProp( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
86 if( xFactProp.is())
87 xFactProp->getPropertyValue(OUString::createFromAscii("DefaultContext")) >>= xContext;
89 catch( uno::Exception& )
92 return xContext;
95 class lcl_MatchesChartType : public ::std::unary_function< Reference< chart2::XChartType >, bool >
97 public:
98 explicit lcl_MatchesChartType( const OUString & aChartTypeName ) :
99 m_aChartTypeName( aChartTypeName )
102 bool operator () ( const Reference< chart2::XChartType > & xChartType ) const
104 return (xChartType.is() &&
105 xChartType->getChartType().equals( m_aChartTypeName ));
108 private:
109 OUString m_aChartTypeName;
111 } // anonymous namespace
113 /* ----------------------------------------
114 TokenMaps for distinguishing different
115 tokens in different contexts
116 ----------------------------------------*/
118 // ----------------------------------------
119 // element maps
120 // ----------------------------------------
128 // ----------------------------------------
129 // attribute maps
130 // ----------------------------------------
140 // ========================================
142 SchXMLImportHelper::SchXMLImportHelper() :
143 mpAutoStyles( 0 ),
145 mpChartDocElemTokenMap( 0 ),
146 mpTableElemTokenMap( 0 ),
147 mpChartElemTokenMap( 0 ),
148 mpPlotAreaElemTokenMap( 0 ),
149 mpSeriesElemTokenMap( 0 ),
150 mpAxisElemTokenMap( 0 ),
152 mpChartAttrTokenMap( 0 ),
153 mpPlotAreaAttrTokenMap( 0 ),
154 mpAxisAttrTokenMap( 0 ),
155 mpLegendAttrTokenMap( 0 ),
156 mpAutoStyleAttrTokenMap( 0 ),
157 mpCellAttrTokenMap( 0 ),
158 mpSeriesAttrTokenMap( 0 ),
159 mpRegEquationAttrTokenMap( 0 )
163 SchXMLImportHelper::~SchXMLImportHelper()
165 // delete token maps
166 if( mpChartDocElemTokenMap )
167 delete mpChartDocElemTokenMap;
168 if( mpTableElemTokenMap )
169 delete mpTableElemTokenMap;
170 if( mpChartElemTokenMap )
171 delete mpChartElemTokenMap;
172 if( mpPlotAreaElemTokenMap )
173 delete mpPlotAreaElemTokenMap;
174 if( mpSeriesElemTokenMap )
175 delete mpSeriesElemTokenMap;
176 if( mpAxisElemTokenMap )
177 delete mpAxisElemTokenMap;
179 if( mpChartAttrTokenMap )
180 delete mpChartAttrTokenMap;
181 if( mpPlotAreaAttrTokenMap )
182 delete mpPlotAreaAttrTokenMap;
183 if( mpAxisAttrTokenMap )
184 delete mpAxisAttrTokenMap;
185 if( mpLegendAttrTokenMap )
186 delete mpLegendAttrTokenMap;
187 if( mpAutoStyleAttrTokenMap )
188 delete mpAutoStyleAttrTokenMap;
189 if( mpCellAttrTokenMap )
190 delete mpCellAttrTokenMap;
191 if( mpSeriesAttrTokenMap )
192 delete mpSeriesAttrTokenMap;
195 SvXMLImportContext* SchXMLImportHelper::CreateChartContext(
196 SvXMLImport& rImport,
197 sal_uInt16 nPrefix, const OUString& rLocalName,
198 const Reference< frame::XModel > xChartModel,
199 const Reference< xml::sax::XAttributeList >& )
201 SvXMLImportContext* pContext = 0;
203 Reference< chart::XChartDocument > xDoc( xChartModel, uno::UNO_QUERY );
204 if( xDoc.is())
206 mxChartDoc = xDoc;
207 pContext = new SchXMLChartContext( *this, rImport, rLocalName );
209 else
211 DBG_ERROR( "No valid XChartDocument given as XModel" );
212 pContext = new SvXMLImportContext( rImport, nPrefix, rLocalName );
215 return pContext;
218 /* ----------------------------------------
219 get various token maps
220 ----------------------------------------*/
222 const SvXMLTokenMap& SchXMLImportHelper::GetDocElemTokenMap()
224 if( ! mpChartDocElemTokenMap )
226 static __FAR_DATA SvXMLTokenMapEntry aDocElemTokenMap[] =
228 { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_STYLES, XML_TOK_DOC_AUTOSTYLES },
229 { XML_NAMESPACE_OFFICE, XML_STYLES, XML_TOK_DOC_STYLES },
230 { XML_NAMESPACE_OFFICE, XML_META, XML_TOK_DOC_META },
231 { XML_NAMESPACE_OFFICE, XML_BODY, XML_TOK_DOC_BODY },
232 XML_TOKEN_MAP_END
235 mpChartDocElemTokenMap = new SvXMLTokenMap( aDocElemTokenMap );
236 } // if( ! mpChartDocElemTokenMap )
238 return *mpChartDocElemTokenMap;
241 const SvXMLTokenMap& SchXMLImportHelper::GetTableElemTokenMap()
243 if( ! mpTableElemTokenMap )
245 static __FAR_DATA SvXMLTokenMapEntry aTableElemTokenMap[] =
247 { XML_NAMESPACE_TABLE, XML_TABLE_HEADER_COLUMNS, XML_TOK_TABLE_HEADER_COLS },
248 { XML_NAMESPACE_TABLE, XML_TABLE_COLUMNS, XML_TOK_TABLE_COLUMNS },
249 { XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, XML_TOK_TABLE_COLUMN },
250 { XML_NAMESPACE_TABLE, XML_TABLE_HEADER_ROWS, XML_TOK_TABLE_HEADER_ROWS },
251 { XML_NAMESPACE_TABLE, XML_TABLE_ROWS, XML_TOK_TABLE_ROWS },
252 { XML_NAMESPACE_TABLE, XML_TABLE_ROW, XML_TOK_TABLE_ROW },
253 XML_TOKEN_MAP_END
256 mpTableElemTokenMap = new SvXMLTokenMap( aTableElemTokenMap );
257 } // if( ! mpTableElemTokenMap )
259 return *mpTableElemTokenMap;
262 const SvXMLTokenMap& SchXMLImportHelper::GetChartElemTokenMap()
264 if( ! mpChartElemTokenMap )
266 static __FAR_DATA SvXMLTokenMapEntry aChartElemTokenMap[] =
268 { XML_NAMESPACE_CHART, XML_PLOT_AREA, XML_TOK_CHART_PLOT_AREA },
269 { XML_NAMESPACE_CHART, XML_TITLE, XML_TOK_CHART_TITLE },
270 { XML_NAMESPACE_CHART, XML_SUBTITLE, XML_TOK_CHART_SUBTITLE },
271 { XML_NAMESPACE_CHART, XML_LEGEND, XML_TOK_CHART_LEGEND },
272 { XML_NAMESPACE_TABLE, XML_TABLE, XML_TOK_CHART_TABLE },
273 XML_TOKEN_MAP_END
276 mpChartElemTokenMap = new SvXMLTokenMap( aChartElemTokenMap );
277 } // if( ! mpChartElemTokenMap )
279 return *mpChartElemTokenMap;
282 const SvXMLTokenMap& SchXMLImportHelper::GetPlotAreaElemTokenMap()
284 if( ! mpPlotAreaElemTokenMap )
286 static __FAR_DATA SvXMLTokenMapEntry aPlotAreaElemTokenMap[] =
288 { XML_NAMESPACE_CHART, XML_AXIS, XML_TOK_PA_AXIS },
289 { XML_NAMESPACE_CHART, XML_SERIES, XML_TOK_PA_SERIES },
290 { XML_NAMESPACE_CHART, XML_WALL, XML_TOK_PA_WALL },
291 { XML_NAMESPACE_CHART, XML_FLOOR, XML_TOK_PA_FLOOR },
292 { XML_NAMESPACE_DR3D, XML_LIGHT, XML_TOK_PA_LIGHT_SOURCE },
293 { XML_NAMESPACE_CHART, XML_STOCK_GAIN_MARKER, XML_TOK_PA_STOCK_GAIN },
294 { XML_NAMESPACE_CHART, XML_STOCK_LOSS_MARKER, XML_TOK_PA_STOCK_LOSS },
295 { XML_NAMESPACE_CHART, XML_STOCK_RANGE_LINE, XML_TOK_PA_STOCK_RANGE },
296 XML_TOKEN_MAP_END
299 mpPlotAreaElemTokenMap = new SvXMLTokenMap( aPlotAreaElemTokenMap );
300 } // if( ! mpPlotAreaElemTokenMap )
302 return *mpPlotAreaElemTokenMap;
305 const SvXMLTokenMap& SchXMLImportHelper::GetSeriesElemTokenMap()
307 if( ! mpSeriesElemTokenMap )
309 static __FAR_DATA SvXMLTokenMapEntry aSeriesElemTokenMap[] =
311 { XML_NAMESPACE_CHART, XML_DATA_POINT, XML_TOK_SERIES_DATA_POINT },
312 { XML_NAMESPACE_CHART, XML_DOMAIN, XML_TOK_SERIES_DOMAIN },
313 { XML_NAMESPACE_CHART, XML_MEAN_VALUE, XML_TOK_SERIES_MEAN_VALUE_LINE },
314 { XML_NAMESPACE_CHART, XML_REGRESSION_CURVE, XML_TOK_SERIES_REGRESSION_CURVE },
315 { XML_NAMESPACE_CHART, XML_ERROR_INDICATOR, XML_TOK_SERIES_ERROR_INDICATOR },
316 XML_TOKEN_MAP_END
319 mpSeriesElemTokenMap = new SvXMLTokenMap( aSeriesElemTokenMap );
320 } // if( ! mpSeriesElemTokenMap )
322 return *mpSeriesElemTokenMap;
325 const SvXMLTokenMap& SchXMLImportHelper::GetAxisElemTokenMap()
327 if( ! mpAxisElemTokenMap )
329 static __FAR_DATA SvXMLTokenMapEntry aAxisElemTokenMap[] =
331 { XML_NAMESPACE_CHART, XML_TITLE, XML_TOK_AXIS_TITLE },
332 { XML_NAMESPACE_CHART, XML_CATEGORIES, XML_TOK_AXIS_CATEGORIES },
333 { XML_NAMESPACE_CHART, XML_GRID, XML_TOK_AXIS_GRID },
334 XML_TOKEN_MAP_END
337 mpAxisElemTokenMap = new SvXMLTokenMap( aAxisElemTokenMap );
338 } // if( ! mpAxisElemTokenMap )
340 return *mpAxisElemTokenMap;
343 // ----------------------------------------
345 const SvXMLTokenMap& SchXMLImportHelper::GetChartAttrTokenMap()
347 if( ! mpChartAttrTokenMap )
349 static __FAR_DATA SvXMLTokenMapEntry aChartAttrTokenMap[] =
351 { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_CHART_HREF },
352 { XML_NAMESPACE_CHART, XML_CLASS, XML_TOK_CHART_CLASS },
353 { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_CHART_WIDTH },
354 { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_CHART_HEIGHT },
355 { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_CHART_STYLE_NAME },
356 { XML_NAMESPACE_CHART, XML_COLUMN_MAPPING, XML_TOK_CHART_COL_MAPPING },
357 { XML_NAMESPACE_CHART, XML_ROW_MAPPING, XML_TOK_CHART_ROW_MAPPING },
358 XML_TOKEN_MAP_END
361 mpChartAttrTokenMap = new SvXMLTokenMap( aChartAttrTokenMap );
362 } // if( ! mpChartAttrTokenMap )
364 return *mpChartAttrTokenMap;
367 const SvXMLTokenMap& SchXMLImportHelper::GetPlotAreaAttrTokenMap()
369 if( ! mpPlotAreaAttrTokenMap )
371 static __FAR_DATA SvXMLTokenMapEntry aPlotAreaAttrTokenMap[] =
373 { XML_NAMESPACE_SVG, XML_X, XML_TOK_PA_X },
374 { XML_NAMESPACE_SVG, XML_Y, XML_TOK_PA_Y },
375 { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_PA_WIDTH },
376 { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_PA_HEIGHT },
377 { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_PA_STYLE_NAME },
378 { XML_NAMESPACE_TABLE, XML_CELL_RANGE_ADDRESS, XML_TOK_PA_CHART_ADDRESS },
379 { XML_NAMESPACE_CHART, XML_DATA_SOURCE_HAS_LABELS, XML_TOK_PA_DS_HAS_LABELS },
380 { XML_NAMESPACE_DR3D, XML_TRANSFORM, XML_TOK_PA_TRANSFORM },
381 { XML_NAMESPACE_DR3D, XML_VRP, XML_TOK_PA_VRP },
382 { XML_NAMESPACE_DR3D, XML_VPN, XML_TOK_PA_VPN },
383 { XML_NAMESPACE_DR3D, XML_VUP, XML_TOK_PA_VUP },
384 { XML_NAMESPACE_DR3D, XML_PROJECTION, XML_TOK_PA_PROJECTION },
385 { XML_NAMESPACE_DR3D, XML_DISTANCE, XML_TOK_PA_DISTANCE },
386 { XML_NAMESPACE_DR3D, XML_FOCAL_LENGTH, XML_TOK_PA_FOCAL_LENGTH },
387 { XML_NAMESPACE_DR3D, XML_SHADOW_SLANT, XML_TOK_PA_SHADOW_SLANT },
388 { XML_NAMESPACE_DR3D, XML_SHADE_MODE, XML_TOK_PA_SHADE_MODE },
389 { XML_NAMESPACE_DR3D, XML_AMBIENT_COLOR, XML_TOK_PA_AMBIENT_COLOR },
390 { XML_NAMESPACE_DR3D, XML_LIGHTING_MODE, XML_TOK_PA_LIGHTING_MODE },
391 XML_TOKEN_MAP_END
394 mpPlotAreaAttrTokenMap = new SvXMLTokenMap( aPlotAreaAttrTokenMap );
395 } // if( ! mpPlotAreaAttrTokenMap )
397 return *mpPlotAreaAttrTokenMap;
400 const SvXMLTokenMap& SchXMLImportHelper::GetAxisAttrTokenMap()
402 if( ! mpAxisAttrTokenMap )
404 static __FAR_DATA SvXMLTokenMapEntry aAxisAttrTokenMap[] =
406 { XML_NAMESPACE_CHART, XML_DIMENSION, XML_TOK_AXIS_DIMENSION },
407 { XML_NAMESPACE_CHART, XML_NAME, XML_TOK_AXIS_NAME },
408 { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_AXIS_STYLE_NAME },
409 XML_TOKEN_MAP_END
412 mpAxisAttrTokenMap = new SvXMLTokenMap( aAxisAttrTokenMap );
413 } // if( ! mpAxisAttrTokenMap )
415 return *mpAxisAttrTokenMap;
418 const SvXMLTokenMap& SchXMLImportHelper::GetLegendAttrTokenMap()
420 if( ! mpLegendAttrTokenMap )
422 static __FAR_DATA SvXMLTokenMapEntry aLegendAttrTokenMap[] =
424 { XML_NAMESPACE_CHART, XML_LEGEND_POSITION, XML_TOK_LEGEND_POSITION },
425 { XML_NAMESPACE_SVG, XML_X, XML_TOK_LEGEND_X },
426 { XML_NAMESPACE_SVG, XML_Y, XML_TOK_LEGEND_Y },
427 { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_LEGEND_STYLE_NAME },
428 XML_TOKEN_MAP_END
431 mpLegendAttrTokenMap = new SvXMLTokenMap( aLegendAttrTokenMap );
432 } // if( ! mpLegendAttrTokenMap )
434 return *mpLegendAttrTokenMap;
437 const SvXMLTokenMap& SchXMLImportHelper::GetAutoStyleAttrTokenMap()
439 if( ! mpAutoStyleAttrTokenMap )
441 static __FAR_DATA SvXMLTokenMapEntry aAutoStyleAttrTokenMap[] =
443 { XML_NAMESPACE_STYLE, XML_FAMILY, XML_TOK_AS_FAMILY },
444 { XML_NAMESPACE_STYLE, XML_NAME, XML_TOK_AS_NAME },
445 XML_TOKEN_MAP_END
448 mpAutoStyleAttrTokenMap = new SvXMLTokenMap( aAutoStyleAttrTokenMap );
449 } // if( ! mpAutoStyleAttrTokenMap )
451 return *mpAutoStyleAttrTokenMap;
454 const SvXMLTokenMap& SchXMLImportHelper::GetCellAttrTokenMap()
456 if( ! mpCellAttrTokenMap )
458 static __FAR_DATA SvXMLTokenMapEntry aCellAttrTokenMap[] =
460 { XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_TOK_CELL_VAL_TYPE },
461 { XML_NAMESPACE_OFFICE, XML_VALUE, XML_TOK_CELL_VALUE },
462 XML_TOKEN_MAP_END
465 mpCellAttrTokenMap = new SvXMLTokenMap( aCellAttrTokenMap );
466 } // if( ! mpCellAttrTokenMap )
468 return *mpCellAttrTokenMap;
471 const SvXMLTokenMap& SchXMLImportHelper::GetSeriesAttrTokenMap()
473 if( ! mpSeriesAttrTokenMap )
475 static __FAR_DATA SvXMLTokenMapEntry aSeriesAttrTokenMap[] =
477 { XML_NAMESPACE_CHART, XML_VALUES_CELL_RANGE_ADDRESS, XML_TOK_SERIES_CELL_RANGE },
478 { XML_NAMESPACE_CHART, XML_LABEL_CELL_ADDRESS, XML_TOK_SERIES_LABEL_ADDRESS },
479 { XML_NAMESPACE_CHART, XML_ATTACHED_AXIS, XML_TOK_SERIES_ATTACHED_AXIS },
480 { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_SERIES_STYLE_NAME },
481 { XML_NAMESPACE_CHART, XML_CLASS, XML_TOK_SERIES_CHART_CLASS },
482 XML_TOKEN_MAP_END
485 mpSeriesAttrTokenMap = new SvXMLTokenMap( aSeriesAttrTokenMap );
486 } // if( ! mpSeriesAttrTokenMap )
488 return *mpSeriesAttrTokenMap;
491 const SvXMLTokenMap& SchXMLImportHelper::GetRegEquationAttrTokenMap()
493 if( ! mpRegEquationAttrTokenMap )
495 static __FAR_DATA SvXMLTokenMapEntry aRegressionEquationAttrTokenMap[] =
497 { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_REGEQ_STYLE_NAME },
498 { XML_NAMESPACE_CHART, XML_DISPLAY_EQUATION, XML_TOK_REGEQ_DISPLAY_EQUATION },
499 { XML_NAMESPACE_CHART, XML_DISPLAY_R_SQUARE, XML_TOK_REGEQ_DISPLAY_R_SQUARE },
500 { XML_NAMESPACE_SVG, XML_X, XML_TOK_REGEQ_POS_X },
501 { XML_NAMESPACE_SVG, XML_Y, XML_TOK_REGEQ_POS_Y },
502 XML_TOKEN_MAP_END
505 mpRegEquationAttrTokenMap = new SvXMLTokenMap( aRegressionEquationAttrTokenMap );
506 } // if( ! mpRegEquationAttrTokenMap )
508 return *mpRegEquationAttrTokenMap;
511 // ----------------------------------------
513 sal_Int32 SchXMLImportHelper::GetNumberOfSeries()
515 if( mxChartDoc.is())
517 Reference< chart::XChartDataArray > xData( mxChartDoc->getData(), uno::UNO_QUERY );
518 if( xData.is())
520 Sequence< Sequence< double > > xArray = xData->getData();
522 if( xArray.getLength())
523 return xArray[ 0 ].getLength();
527 return 0;
530 sal_Int32 SchXMLImportHelper::GetLengthOfSeries()
532 if( mxChartDoc.is())
534 Reference< chart::XChartDataArray > xData( mxChartDoc->getData(), uno::UNO_QUERY );
535 if( xData.is())
537 Sequence< Sequence< double > > xArray = xData->getData();
539 return xArray.getLength();
543 return 0;
546 // -1 means don't change
547 void SchXMLImportHelper::ResizeChartData( sal_Int32 nSeries, sal_Int32 nDataPoints )
549 if( mxChartDoc.is())
551 sal_Bool bWasChanged = sal_False;
553 sal_Bool bDataInColumns = sal_True;
554 Reference< beans::XPropertySet > xDiaProp( mxChartDoc->getDiagram(), uno::UNO_QUERY );
555 if( xDiaProp.is())
557 chart::ChartDataRowSource eRowSource;
558 xDiaProp->getPropertyValue( OUString::createFromAscii( "DataRowSource" )) >>= eRowSource;
559 bDataInColumns = ( eRowSource == chart::ChartDataRowSource_COLUMNS );
561 // the chart core treats donut chart with interchanged rows/columns
562 Reference< chart::XDiagram > xDiagram( xDiaProp, uno::UNO_QUERY );
563 if( xDiagram.is())
565 OUString sChartType = xDiagram->getDiagramType();
566 if( 0 == sChartType.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart.DonutDiagram" )))
568 bDataInColumns = ! bDataInColumns;
572 sal_Int32 nColCount = bDataInColumns ? nSeries : nDataPoints;
573 sal_Int32 nRowCount = bDataInColumns ? nDataPoints : nSeries;
575 Reference< chart::XChartDataArray > xData( mxChartDoc->getData(), uno::UNO_QUERY );
576 if( xData.is())
578 Sequence< Sequence< double > > xArray = xData->getData();
580 // increase number of rows
581 if( xArray.getLength() < nRowCount )
583 sal_Int32 nOldLen = xArray.getLength();
584 xArray.realloc( nRowCount );
585 if( nColCount == -1 )
587 sal_Int32 nSize = xArray[ 0 ].getLength();
588 for( sal_Int32 i = nOldLen; i < nRowCount; i++ )
589 xArray[ i ].realloc( nSize );
591 bWasChanged = sal_True;
594 if( nSeries == -1 &&
595 nRowCount > 0 )
596 nColCount = xArray[ 0 ].getLength();
598 // columns
599 if( nColCount > 0 &&
600 xArray[ 0 ].getLength() < nColCount )
602 if( nDataPoints == -1 )
603 nRowCount = xArray.getLength();
605 for( sal_Int32 i = 0; i < nRowCount; i++ )
606 xArray[ i ].realloc( nColCount );
607 bWasChanged = sal_True;
610 if( bWasChanged )
612 xData->setData( xArray );
613 mxChartDoc->attachData(
614 Reference< chart::XChartData >( xData, uno::UNO_QUERY ));
620 //static
621 void SchXMLImportHelper::DeleteDataSeries(
622 const Reference< chart2::XDataSeries > & xSeries,
623 const Reference< chart2::XChartDocument > & xDoc )
625 if( xDoc.is() )
628 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
629 xDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
630 Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
631 xCooSysCnt->getCoordinateSystems());
633 sal_Int32 nCooSysIndex = 0;
634 for( nCooSysIndex=0; nCooSysIndex<aCooSysSeq.getLength(); nCooSysIndex++ )
636 Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[ nCooSysIndex ], uno::UNO_QUERY_THROW );
637 Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes());
639 sal_Int32 nChartTypeIndex = 0;
640 for( nChartTypeIndex=0; nChartTypeIndex<aChartTypes.getLength(); nChartTypeIndex++ )
642 Reference< chart2::XDataSeriesContainer > xSeriesCnt( aChartTypes[nChartTypeIndex], uno::UNO_QUERY_THROW );
643 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesCnt->getDataSeries());
645 sal_Int32 nSeriesIndex = 0;
646 for( nSeriesIndex=0; nSeriesIndex<aSeriesSeq.getLength(); nSeriesIndex++ )
648 if( xSeries==aSeriesSeq[nSeriesIndex] )
650 xSeriesCnt->removeDataSeries(xSeries);
651 return;
657 catch( uno::Exception & ex )
659 (void)ex; // avoid warning for pro build
660 OSL_ENSURE( false, OUStringToOString(
661 OUString( RTL_CONSTASCII_USTRINGPARAM( "Exception caught. Type: " )) +
662 OUString::createFromAscii( typeid( ex ).name()) +
663 OUString( RTL_CONSTASCII_USTRINGPARAM( ", Message: " )) +
664 ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
668 // static
669 Reference< chart2::XDataSeries > SchXMLImportHelper::GetNewDataSeries(
670 const Reference< chart2::XChartDocument > & xDoc,
671 sal_Int32 nCoordinateSystemIndex,
672 const OUString & rChartTypeName,
673 bool bPushLastChartType /* = false */ )
675 Reference< chart2::XDataSeries > xResult;
676 if(!xDoc.is())
677 return xResult;
681 Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
682 xDoc->getFirstDiagram(), uno::UNO_QUERY_THROW );
683 Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
684 xCooSysCnt->getCoordinateSystems());
685 Reference< uno::XComponentContext > xContext( lcl_getComponentContext());
687 if( nCoordinateSystemIndex < aCooSysSeq.getLength())
689 Reference< chart2::XChartType > xCurrentType;
691 Reference< chart2::XChartTypeContainer > xCTCnt( aCooSysSeq[ nCoordinateSystemIndex ], uno::UNO_QUERY_THROW );
692 Sequence< Reference< chart2::XChartType > > aChartTypes( xCTCnt->getChartTypes());
693 // find matching chart type group
694 const Reference< chart2::XChartType > * pBegin = aChartTypes.getConstArray();
695 const Reference< chart2::XChartType > * pEnd = pBegin + aChartTypes.getLength();
696 const Reference< chart2::XChartType > * pIt =
697 ::std::find_if( pBegin, pEnd, lcl_MatchesChartType( rChartTypeName ));
698 if( pIt != pEnd )
699 xCurrentType.set( *pIt );
700 // if chart type is set at series and differs from current one,
701 // create a new chart type
702 if( !xCurrentType.is())
704 xCurrentType.set(
705 xContext->getServiceManager()->createInstanceWithContext( rChartTypeName, xContext ),
706 uno::UNO_QUERY );
707 if( xCurrentType.is())
709 if( bPushLastChartType && aChartTypes.getLength())
711 sal_Int32 nIndex( aChartTypes.getLength() - 1 );
712 aChartTypes.realloc( aChartTypes.getLength() + 1 );
713 aChartTypes[ nIndex + 1 ] = aChartTypes[ nIndex ];
714 aChartTypes[ nIndex ] = xCurrentType;
715 xCTCnt->setChartTypes( aChartTypes );
717 else
718 xCTCnt->addChartType( xCurrentType );
723 if( xCurrentType.is())
725 Reference< chart2::XDataSeriesContainer > xSeriesCnt( xCurrentType, uno::UNO_QUERY_THROW );
726 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesCnt->getDataSeries());
728 if( xContext.is() )
730 xResult.set(
731 xContext->getServiceManager()->createInstanceWithContext(
732 OUString::createFromAscii("com.sun.star.chart2.DataSeries"),
733 xContext ), uno::UNO_QUERY_THROW );
735 if( xResult.is() )
736 xSeriesCnt->addDataSeries( xResult );
740 catch( uno::Exception & ex )
742 (void)ex; // avoid warning for pro build
743 OSL_ENSURE( false, OUStringToOString(
744 OUString( RTL_CONSTASCII_USTRINGPARAM( "Exception caught. Type: " )) +
745 OUString::createFromAscii( typeid( ex ).name()) +
746 OUString( RTL_CONSTASCII_USTRINGPARAM( ", Message: " )) +
747 ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
749 return xResult;
752 // static
753 Reference< chart2::data::XLabeledDataSequence > SchXMLImportHelper::GetNewLabeledDataSequence()
755 // @todo: remove this asap
756 OSL_ENSURE( false, "Do not call this method" );
757 Reference< chart2::data::XLabeledDataSequence > xResult;
758 // DO NOT USED -- DEPRECATED. Use SchXMLTools::GetNewLabeledDataSequence() instead
759 return xResult;
762 // ========================================
764 // #110680#
765 SchXMLImport::SchXMLImport(
766 const Reference< lang::XMultiServiceFactory >& xServiceFactory,
767 sal_uInt16 nImportFlags ) :
768 SvXMLImport( xServiceFactory, nImportFlags )
770 GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
772 mbIsGraphicLoadOnDemandSupported = false;
775 // #110680#
776 SchXMLImport::SchXMLImport(
777 const Reference< lang::XMultiServiceFactory >& xServiceFactory,
778 Reference< frame::XModel > xModel,
779 Reference< document::XGraphicObjectResolver >& rGrfContainer,
780 sal_Bool /*bLoadDoc*/, sal_Bool bShowProgress )
781 : SvXMLImport( xServiceFactory, xModel, rGrfContainer )
783 GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
785 // get status indicator (if requested)
786 if( bShowProgress )
788 Reference< frame::XController > xController( xModel->getCurrentController());
789 if( xController.is())
791 Reference< frame::XFrame > xFrame( xController->getFrame());
792 if( xFrame.is())
794 Reference< task::XStatusIndicatorSupplier > xFactory( xFrame, uno::UNO_QUERY );
795 if( xFactory.is())
797 mxStatusIndicator = xFactory->getStatusIndicator();
803 // add progress view
804 if( mxStatusIndicator.is())
806 const OUString aText( RTL_CONSTASCII_USTRINGPARAM( "XML Import" ));
807 mxStatusIndicator->start( aText, 100 ); // use percentage as values
811 SchXMLImport::~SchXMLImport() throw ()
813 // stop progress view
814 if( mxStatusIndicator.is())
816 mxStatusIndicator->end();
817 mxStatusIndicator->reset();
820 uno::Reference< chart2::XChartDocument > xChartDoc( GetModel(), uno::UNO_QUERY );
821 if( xChartDoc.is() && xChartDoc->hasControllersLocked() )
822 xChartDoc->unlockControllers();
825 // create the main context (subcontexts are created
826 // by the one created here)
827 SvXMLImportContext *SchXMLImport::CreateContext( USHORT nPrefix, const OUString& rLocalName,
828 const Reference< xml::sax::XAttributeList >& xAttrList )
830 SvXMLImportContext* pContext = 0;
832 // accept <office:document>
833 if( XML_NAMESPACE_OFFICE == nPrefix &&
834 ( IsXMLToken( rLocalName, XML_DOCUMENT_STYLES) ||
835 IsXMLToken( rLocalName, XML_DOCUMENT_CONTENT) ))
837 pContext = new SchXMLDocContext( maImportHelper, *this, nPrefix, rLocalName );
838 } else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
839 ( IsXMLToken(rLocalName, XML_DOCUMENT) ||
840 (IsXMLToken(rLocalName, XML_DOCUMENT_META)
841 && (getImportFlags() & IMPORT_META) )) )
843 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
844 GetModel(), uno::UNO_QUERY);
845 // mst@: right now, this seems to be not supported, so it is untested
846 if (xDPS.is()) {
847 uno::Reference<xml::sax::XDocumentHandler> xDocBuilder(
848 mxServiceFactory->createInstance(
849 ::rtl::OUString::createFromAscii(
850 "com.sun.star.xml.dom.SAXDocumentBuilder")),
851 uno::UNO_QUERY_THROW);
852 pContext = (IsXMLToken(rLocalName, XML_DOCUMENT_META))
853 ? new SvXMLMetaDocumentContext(*this,
854 XML_NAMESPACE_OFFICE, rLocalName,
855 xDPS->getDocumentProperties(), xDocBuilder)
856 // flat OpenDocument file format
857 : new SchXMLFlatDocContext_Impl(
858 maImportHelper, *this, nPrefix, rLocalName,
859 xDPS->getDocumentProperties(), xDocBuilder);
860 } else {
861 pContext = (IsXMLToken(rLocalName, XML_DOCUMENT_META))
862 ? SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList )
863 : new SchXMLDocContext( maImportHelper, *this,
864 nPrefix, rLocalName );
866 } else {
867 pContext = SvXMLImport::CreateContext( nPrefix, rLocalName, xAttrList );
870 return pContext;
873 SvXMLImportContext* SchXMLImport::CreateStylesContext(
874 const OUString& rLocalName,
875 const Reference<xml::sax::XAttributeList>& xAttrList )
877 //#i103287# make sure that the version information is set before importing all the properties (especially stroke-opacity!)
878 SchXMLTools::setBuildIDAtImportInfo( GetModel(), getImportInfo() );
880 SvXMLStylesContext* pStylesCtxt =
881 new SvXMLStylesContext( *(this), XML_NAMESPACE_OFFICE, rLocalName, xAttrList );
883 // set context at base class, so that all auto-style classes are imported
884 SetAutoStyles( pStylesCtxt );
885 maImportHelper.SetAutoStylesContext( pStylesCtxt );
887 return pStylesCtxt;
890 void SAL_CALL SchXMLImport::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
891 throw(lang::IllegalArgumentException, uno::RuntimeException)
893 uno::Reference< chart2::XChartDocument > xOldDoc( GetModel(), uno::UNO_QUERY );
894 if( xOldDoc.is() && xOldDoc->hasControllersLocked() )
895 xOldDoc->unlockControllers();
897 SvXMLImport::setTargetDocument( xDoc );
899 //set data provider and number formatter
900 // try to get an XDataProvider and set it
901 // @todo: if we have our own data, we must not use the parent as data provider
902 uno::Reference< chart2::XChartDocument > xChartDoc( GetModel(), uno::UNO_QUERY );
904 if( xChartDoc.is() )
907 //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 )
908 xChartDoc->lockControllers();
910 uno::Reference< container::XChild > xChild( xChartDoc, uno::UNO_QUERY );
911 uno::Reference< chart2::data::XDataReceiver > xDataReceiver( xChartDoc, uno::UNO_QUERY );
912 bool bHasOwnData = true;
913 if( xChild.is() && xDataReceiver.is())
915 Reference< lang::XMultiServiceFactory > xFact( xChild->getParent(), uno::UNO_QUERY );
916 if( xFact.is() )
918 //if the parent has a number formatter we will use the numberformatter of the parent
919 Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xFact, uno::UNO_QUERY );
920 xDataReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
922 if ( !xChartDoc->getDataProvider().is() )
924 const OUString aDataProviderServiceName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.data.DataProvider"));
925 const uno::Sequence< OUString > aServiceNames( xFact->getAvailableServiceNames());
926 const OUString * pBegin = aServiceNames.getConstArray();
927 const OUString * pEnd = pBegin + aServiceNames.getLength();
928 if( ::std::find( pBegin, pEnd, aDataProviderServiceName ) != pEnd )
930 Reference< chart2::data::XDataProvider > xProvider(
931 xFact->createInstance( aDataProviderServiceName ), uno::UNO_QUERY );
932 if( xProvider.is())
934 xDataReceiver->attachDataProvider( xProvider );
935 bHasOwnData = false;
939 else
940 bHasOwnData = false;
942 // else we have no parent => we have our own data
944 if( bHasOwnData && ! xChartDoc->hasInternalDataProvider() )
945 xChartDoc->createInternalDataProvider( sal_False );
948 catch( uno::Exception & rEx )
950 #ifdef DBG_UTIL
951 String aStr( rEx.Message );
952 ByteString aBStr( aStr, RTL_TEXTENCODING_ASCII_US );
953 DBG_ERROR1( "SchXMLChartContext::StartElement(): Exception caught: %s", aBStr.GetBuffer());
954 #else
955 (void)rEx; // avoid warning for pro build
956 #endif
960 // export components ========================================
962 // first version: everything comes from one storage
964 Sequence< OUString > SAL_CALL SchXMLImport_getSupportedServiceNames() throw()
966 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisImporter" ) );
967 const Sequence< OUString > aSeq( &aServiceName, 1 );
968 return aSeq;
971 OUString SAL_CALL SchXMLImport_getImplementationName() throw()
973 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLImport" ) );
976 Reference< uno::XInterface > SAL_CALL SchXMLImport_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )
978 // #110680#
979 // return (cppu::OWeakObject*)new SchXMLImport();
980 return (cppu::OWeakObject*)new SchXMLImport(rSMgr);
983 // ============================================================
985 // multiple storage version: one for content / styles / meta
987 Sequence< OUString > SAL_CALL SchXMLImport_Styles_getSupportedServiceNames() throw()
989 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisStylesImporter" ) );
990 const Sequence< OUString > aSeq( &aServiceName, 1 );
991 return aSeq;
994 OUString SAL_CALL SchXMLImport_Styles_getImplementationName() throw()
996 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLImport.Styles" ) );
999 Reference< uno::XInterface > SAL_CALL SchXMLImport_Styles_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )
1001 // #110680#
1002 // return (cppu::OWeakObject*)new SchXMLImport( IMPORT_STYLES );
1003 return (cppu::OWeakObject*)new SchXMLImport( rSMgr, IMPORT_STYLES );
1006 // ------------------------------------------------------------
1008 Sequence< OUString > SAL_CALL SchXMLImport_Content_getSupportedServiceNames() throw()
1010 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisContentImporter" ) );
1011 const Sequence< OUString > aSeq( &aServiceName, 1 );
1012 return aSeq;
1015 OUString SAL_CALL SchXMLImport_Content_getImplementationName() throw()
1017 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLImport.Content" ) );
1020 Reference< uno::XInterface > SAL_CALL SchXMLImport_Content_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )
1022 // #110680#
1023 // return (cppu::OWeakObject*)new SchXMLImport( IMPORT_CONTENT | IMPORT_AUTOSTYLES | IMPORT_FONTDECLS );
1024 return (cppu::OWeakObject*)new SchXMLImport( rSMgr, IMPORT_CONTENT | IMPORT_AUTOSTYLES | IMPORT_FONTDECLS );
1027 // ------------------------------------------------------------
1029 Sequence< OUString > SAL_CALL SchXMLImport_Meta_getSupportedServiceNames() throw()
1031 const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Chart.XMLOasisMetaImporter" ) );
1032 const Sequence< OUString > aSeq( &aServiceName, 1 );
1033 return aSeq;
1036 OUString SAL_CALL SchXMLImport_Meta_getImplementationName() throw()
1038 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SchXMLImport.Meta" ) );
1041 Reference< uno::XInterface > SAL_CALL SchXMLImport_Meta_createInstance(const Reference< lang::XMultiServiceFactory > & rSMgr) throw( uno::Exception )
1043 // #110680#
1044 // return (cppu::OWeakObject*)new SchXMLImport( IMPORT_META );
1045 return (cppu::OWeakObject*)new SchXMLImport( rSMgr, IMPORT_META );
1048 // XServiceInfo
1049 OUString SAL_CALL SchXMLImport::getImplementationName() throw( uno::RuntimeException )
1051 switch( getImportFlags())
1053 case IMPORT_ALL:
1054 return SchXMLImport_getImplementationName();
1055 case IMPORT_STYLES:
1056 return SchXMLImport_Styles_getImplementationName();
1057 case ( IMPORT_CONTENT | IMPORT_AUTOSTYLES | IMPORT_FONTDECLS ):
1058 return SchXMLImport_Content_getImplementationName();
1059 case IMPORT_META:
1060 return SchXMLImport_Meta_getImplementationName();
1062 case IMPORT_SETTINGS:
1063 // there is no settings component in chart
1064 default:
1065 return OUString::createFromAscii( "SchXMLImport" );