1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "SchXMLImport.hxx"
21 #include "SchXMLChartContext.hxx"
22 #include "contexts.hxx"
23 #include "XMLChartPropertySetMapper.hxx"
24 #include "SchXMLTools.hxx"
27 #include <o3tl/make_unique.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <comphelper/processfactory.hxx>
30 #include <xmloff/nmspmap.hxx>
31 #include <xmloff/prstylei.hxx>
32 #include <xmloff/xmlnmspe.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/xmluconv.hxx>
35 #include <xmloff/xmlictxt.hxx>
36 #include <xmloff/xmlstyle.hxx>
37 #include <com/sun/star/task/XStatusIndicatorSupplier.hpp>
38 #include <com/sun/star/chart/XChartDocument.hpp>
39 #include <com/sun/star/chart/ChartDataRowSource.hpp>
40 #include <com/sun/star/container/XChild.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/uno/XComponentContext.hpp>
43 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
44 #include <com/sun/star/chart2/data/XDataProvider.hpp>
45 #include <com/sun/star/chart2/XChartDocument.hpp>
46 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
47 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
48 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
50 #include <com/sun/star/document/XDocumentProperties.hpp>
51 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
55 using namespace com::sun::star
;
56 using namespace ::xmloff::token
;
58 using ::com::sun::star::uno::Reference
;
59 using ::com::sun::star::uno::Sequence
;
63 class lcl_MatchesChartType
: public ::std::unary_function
< Reference
< chart2::XChartType
>, bool >
66 explicit lcl_MatchesChartType( const OUString
& aChartTypeName
) :
67 m_aChartTypeName( aChartTypeName
)
70 bool operator () ( const Reference
< chart2::XChartType
> & xChartType
) const
72 return (xChartType
.is() &&
73 xChartType
->getChartType().equals( m_aChartTypeName
));
77 OUString m_aChartTypeName
;
79 } // anonymous namespace
81 // TokenMaps for distinguishing different
82 // tokens in different contexts
88 SchXMLImportHelper::SchXMLImportHelper() :
89 mpAutoStyles( nullptr )
93 SvXMLImportContext
* SchXMLImportHelper::CreateChartContext(
95 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
96 const Reference
< frame::XModel
>& rChartModel
,
97 const Reference
< xml::sax::XAttributeList
>& )
99 SvXMLImportContext
* pContext
= nullptr;
101 Reference
< chart::XChartDocument
> xDoc( rChartModel
, uno::UNO_QUERY
);
105 pContext
= new SchXMLChartContext( *this, rImport
, rLocalName
);
109 SAL_WARN("xmloff.chart", "No valid XChartDocument given as XModel" );
110 pContext
= new SvXMLImportContext( rImport
, nPrefix
, rLocalName
);
116 void SchXMLImportHelper::FillAutoStyle(const OUString
& rAutoStyleName
, const uno::Reference
<beans::XPropertySet
>& rProp
)
121 const SvXMLStylesContext
* pStylesCtxt
= GetAutoStylesContext();
124 SvXMLStyleContext
* pStyle
= const_cast<SvXMLStyleContext
*>(pStylesCtxt
->FindStyleChildContext(SchXMLImportHelper::GetChartFamilyID(), rAutoStyleName
));
126 if (XMLPropStyleContext
* pPropStyle
= dynamic_cast<XMLPropStyleContext
*>(pStyle
))
127 pPropStyle
->FillPropertySet(rProp
);
131 // get various token maps
133 const SvXMLTokenMap
& SchXMLImportHelper::GetDocElemTokenMap()
135 if( ! mpChartDocElemTokenMap
)
137 static const SvXMLTokenMapEntry aDocElemTokenMap
[] =
139 { XML_NAMESPACE_OFFICE
, XML_AUTOMATIC_STYLES
, XML_TOK_DOC_AUTOSTYLES
},
140 { XML_NAMESPACE_OFFICE
, XML_STYLES
, XML_TOK_DOC_STYLES
},
141 { XML_NAMESPACE_OFFICE
, XML_META
, XML_TOK_DOC_META
},
142 { XML_NAMESPACE_OFFICE
, XML_BODY
, XML_TOK_DOC_BODY
},
146 mpChartDocElemTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aDocElemTokenMap
);
147 } // if( ! mpChartDocElemTokenMap )
149 return *mpChartDocElemTokenMap
;
152 const SvXMLTokenMap
& SchXMLImportHelper::GetTableElemTokenMap()
154 if( ! mpTableElemTokenMap
)
156 static const SvXMLTokenMapEntry aTableElemTokenMap
[] =
158 { XML_NAMESPACE_TABLE
, XML_TABLE_HEADER_COLUMNS
, XML_TOK_TABLE_HEADER_COLS
},
159 { XML_NAMESPACE_TABLE
, XML_TABLE_COLUMNS
, XML_TOK_TABLE_COLUMNS
},
160 { XML_NAMESPACE_TABLE
, XML_TABLE_COLUMN
, XML_TOK_TABLE_COLUMN
},
161 { XML_NAMESPACE_TABLE
, XML_TABLE_HEADER_ROWS
, XML_TOK_TABLE_HEADER_ROWS
},
162 { XML_NAMESPACE_TABLE
, XML_TABLE_ROWS
, XML_TOK_TABLE_ROWS
},
163 { XML_NAMESPACE_TABLE
, XML_TABLE_ROW
, XML_TOK_TABLE_ROW
},
167 mpTableElemTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aTableElemTokenMap
);
168 } // if( ! mpTableElemTokenMap )
170 return *mpTableElemTokenMap
;
173 const SvXMLTokenMap
& SchXMLImportHelper::GetChartElemTokenMap()
175 if( ! mpChartElemTokenMap
)
177 static const SvXMLTokenMapEntry aChartElemTokenMap
[] =
179 { XML_NAMESPACE_CHART
, XML_PLOT_AREA
, XML_TOK_CHART_PLOT_AREA
},
180 { XML_NAMESPACE_CHART
, XML_TITLE
, XML_TOK_CHART_TITLE
},
181 { XML_NAMESPACE_CHART
, XML_SUBTITLE
, XML_TOK_CHART_SUBTITLE
},
182 { XML_NAMESPACE_CHART
, XML_LEGEND
, XML_TOK_CHART_LEGEND
},
183 { XML_NAMESPACE_TABLE
, XML_TABLE
, XML_TOK_CHART_TABLE
},
187 mpChartElemTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aChartElemTokenMap
);
188 } // if( ! mpChartElemTokenMap )
190 return *mpChartElemTokenMap
;
193 const SvXMLTokenMap
& SchXMLImportHelper::GetPlotAreaElemTokenMap()
195 if( ! mpPlotAreaElemTokenMap
)
197 static const SvXMLTokenMapEntry aPlotAreaElemTokenMap
[] =
199 { XML_NAMESPACE_CHART_EXT
, XML_COORDINATE_REGION
, XML_TOK_PA_COORDINATE_REGION_EXT
},
200 { XML_NAMESPACE_CHART
, XML_COORDINATE_REGION
, XML_TOK_PA_COORDINATE_REGION
},
201 { XML_NAMESPACE_CHART
, XML_AXIS
, XML_TOK_PA_AXIS
},
202 { XML_NAMESPACE_CHART
, XML_SERIES
, XML_TOK_PA_SERIES
},
203 { XML_NAMESPACE_CHART
, XML_WALL
, XML_TOK_PA_WALL
},
204 { XML_NAMESPACE_CHART
, XML_FLOOR
, XML_TOK_PA_FLOOR
},
205 { XML_NAMESPACE_DR3D
, XML_LIGHT
, XML_TOK_PA_LIGHT_SOURCE
},
206 { XML_NAMESPACE_CHART
, XML_STOCK_GAIN_MARKER
, XML_TOK_PA_STOCK_GAIN
},
207 { XML_NAMESPACE_CHART
, XML_STOCK_LOSS_MARKER
, XML_TOK_PA_STOCK_LOSS
},
208 { XML_NAMESPACE_CHART
, XML_STOCK_RANGE_LINE
, XML_TOK_PA_STOCK_RANGE
},
212 mpPlotAreaElemTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aPlotAreaElemTokenMap
);
213 } // if( ! mpPlotAreaElemTokenMap )
215 return *mpPlotAreaElemTokenMap
;
218 const SvXMLTokenMap
& SchXMLImportHelper::GetSeriesElemTokenMap()
220 if( ! mpSeriesElemTokenMap
)
222 static const SvXMLTokenMapEntry aSeriesElemTokenMap
[] =
224 { XML_NAMESPACE_CHART
, XML_DATA_POINT
, XML_TOK_SERIES_DATA_POINT
},
225 { XML_NAMESPACE_CHART
, XML_DOMAIN
, XML_TOK_SERIES_DOMAIN
},
226 { XML_NAMESPACE_CHART
, XML_MEAN_VALUE
, XML_TOK_SERIES_MEAN_VALUE_LINE
},
227 { XML_NAMESPACE_CHART
, XML_REGRESSION_CURVE
, XML_TOK_SERIES_REGRESSION_CURVE
},
228 { XML_NAMESPACE_CHART
, XML_ERROR_INDICATOR
, XML_TOK_SERIES_ERROR_INDICATOR
},
229 { XML_NAMESPACE_LO_EXT
, XML_PROPERTY_MAPPING
, XML_TOK_SERIES_PROPERTY_MAPPING
},
233 mpSeriesElemTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aSeriesElemTokenMap
);
234 } // if( ! mpSeriesElemTokenMap )
236 return *mpSeriesElemTokenMap
;
239 const SvXMLTokenMap
& SchXMLImportHelper::GetChartAttrTokenMap()
241 if( ! mpChartAttrTokenMap
)
243 static const SvXMLTokenMapEntry aChartAttrTokenMap
[] =
245 { XML_NAMESPACE_XLINK
, XML_HREF
, XML_TOK_CHART_HREF
},
246 { XML_NAMESPACE_CHART
, XML_CLASS
, XML_TOK_CHART_CLASS
},
247 { XML_NAMESPACE_SVG
, XML_WIDTH
, XML_TOK_CHART_WIDTH
},
248 { XML_NAMESPACE_SVG
, XML_HEIGHT
, XML_TOK_CHART_HEIGHT
},
249 { XML_NAMESPACE_CHART
, XML_STYLE_NAME
, XML_TOK_CHART_STYLE_NAME
},
250 { XML_NAMESPACE_CHART
, XML_COLUMN_MAPPING
, XML_TOK_CHART_COL_MAPPING
},
251 { XML_NAMESPACE_CHART
, XML_ROW_MAPPING
, XML_TOK_CHART_ROW_MAPPING
},
255 mpChartAttrTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aChartAttrTokenMap
);
256 } // if( ! mpChartAttrTokenMap )
258 return *mpChartAttrTokenMap
;
261 const SvXMLTokenMap
& SchXMLImportHelper::GetPlotAreaAttrTokenMap()
263 if( ! mpPlotAreaAttrTokenMap
)
265 static const SvXMLTokenMapEntry aPlotAreaAttrTokenMap
[] =
267 { XML_NAMESPACE_SVG
, XML_X
, XML_TOK_PA_X
},
268 { XML_NAMESPACE_SVG
, XML_Y
, XML_TOK_PA_Y
},
269 { XML_NAMESPACE_SVG
, XML_WIDTH
, XML_TOK_PA_WIDTH
},
270 { XML_NAMESPACE_SVG
, XML_HEIGHT
, XML_TOK_PA_HEIGHT
},
271 { XML_NAMESPACE_CHART
, XML_STYLE_NAME
, XML_TOK_PA_STYLE_NAME
},
272 { XML_NAMESPACE_TABLE
, XML_CELL_RANGE_ADDRESS
, XML_TOK_PA_CHART_ADDRESS
},
273 { XML_NAMESPACE_CHART
, XML_DATA_SOURCE_HAS_LABELS
, XML_TOK_PA_DS_HAS_LABELS
},
274 { XML_NAMESPACE_DR3D
, XML_TRANSFORM
, XML_TOK_PA_TRANSFORM
},
275 { XML_NAMESPACE_DR3D
, XML_VRP
, XML_TOK_PA_VRP
},
276 { XML_NAMESPACE_DR3D
, XML_VPN
, XML_TOK_PA_VPN
},
277 { XML_NAMESPACE_DR3D
, XML_VUP
, XML_TOK_PA_VUP
},
278 { XML_NAMESPACE_DR3D
, XML_PROJECTION
, XML_TOK_PA_PROJECTION
},
279 { XML_NAMESPACE_DR3D
, XML_DISTANCE
, XML_TOK_PA_DISTANCE
},
280 { XML_NAMESPACE_DR3D
, XML_FOCAL_LENGTH
, XML_TOK_PA_FOCAL_LENGTH
},
281 { XML_NAMESPACE_DR3D
, XML_SHADOW_SLANT
, XML_TOK_PA_SHADOW_SLANT
},
282 { XML_NAMESPACE_DR3D
, XML_SHADE_MODE
, XML_TOK_PA_SHADE_MODE
},
283 { XML_NAMESPACE_DR3D
, XML_AMBIENT_COLOR
, XML_TOK_PA_AMBIENT_COLOR
},
284 { XML_NAMESPACE_DR3D
, XML_LIGHTING_MODE
, XML_TOK_PA_LIGHTING_MODE
},
288 mpPlotAreaAttrTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aPlotAreaAttrTokenMap
);
289 } // if( ! mpPlotAreaAttrTokenMap )
291 return *mpPlotAreaAttrTokenMap
;
294 const SvXMLTokenMap
& SchXMLImportHelper::GetCellAttrTokenMap()
296 if( ! mpCellAttrTokenMap
)
298 static const SvXMLTokenMapEntry aCellAttrTokenMap
[] =
300 { XML_NAMESPACE_OFFICE
, XML_VALUE_TYPE
, XML_TOK_CELL_VAL_TYPE
},
301 { XML_NAMESPACE_OFFICE
, XML_VALUE
, XML_TOK_CELL_VALUE
},
305 mpCellAttrTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aCellAttrTokenMap
);
306 } // if( ! mpCellAttrTokenMap )
308 return *mpCellAttrTokenMap
;
311 const SvXMLTokenMap
& SchXMLImportHelper::GetSeriesAttrTokenMap()
313 if( ! mpSeriesAttrTokenMap
)
315 static const SvXMLTokenMapEntry aSeriesAttrTokenMap
[] =
317 { XML_NAMESPACE_CHART
, XML_VALUES_CELL_RANGE_ADDRESS
, XML_TOK_SERIES_CELL_RANGE
},
318 { XML_NAMESPACE_CHART
, XML_LABEL_CELL_ADDRESS
, XML_TOK_SERIES_LABEL_ADDRESS
},
319 { XML_NAMESPACE_LO_EXT
, XML_LABEL_STRING
, XML_TOK_SERIES_LABEL_STRING
},
320 { XML_NAMESPACE_CHART
, XML_ATTACHED_AXIS
, XML_TOK_SERIES_ATTACHED_AXIS
},
321 { XML_NAMESPACE_CHART
, XML_STYLE_NAME
, XML_TOK_SERIES_STYLE_NAME
},
322 { XML_NAMESPACE_CHART
, XML_CLASS
, XML_TOK_SERIES_CHART_CLASS
},
326 mpSeriesAttrTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aSeriesAttrTokenMap
);
327 } // if( ! mpSeriesAttrTokenMap )
329 return *mpSeriesAttrTokenMap
;
332 const SvXMLTokenMap
& SchXMLImportHelper::GetPropMappingAttrTokenMap()
334 if( !mpPropMappingAttrTokenMap
)
336 static const SvXMLTokenMapEntry aPropMappingAttrTokenMap
[] =
338 { XML_NAMESPACE_LO_EXT
, XML_PROPERTY
, XML_TOK_PROPERTY_MAPPING_PROPERTY
},
339 { XML_NAMESPACE_LO_EXT
, XML_CELL_RANGE_ADDRESS
, XML_TOK_PROPERTY_MAPPING_RANGE
},
343 mpPropMappingAttrTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aPropMappingAttrTokenMap
);
346 return *mpPropMappingAttrTokenMap
;
349 const SvXMLTokenMap
& SchXMLImportHelper::GetRegEquationAttrTokenMap()
351 if( ! mpRegEquationAttrTokenMap
)
353 static const SvXMLTokenMapEntry aRegressionEquationAttrTokenMap
[] =
355 { XML_NAMESPACE_CHART
, XML_STYLE_NAME
, XML_TOK_REGEQ_STYLE_NAME
},
356 { XML_NAMESPACE_CHART
, XML_DISPLAY_EQUATION
, XML_TOK_REGEQ_DISPLAY_EQUATION
},
357 { XML_NAMESPACE_CHART
, XML_DISPLAY_R_SQUARE
, XML_TOK_REGEQ_DISPLAY_R_SQUARE
},
358 { XML_NAMESPACE_SVG
, XML_X
, XML_TOK_REGEQ_POS_X
},
359 { XML_NAMESPACE_SVG
, XML_Y
, XML_TOK_REGEQ_POS_Y
},
363 mpRegEquationAttrTokenMap
= o3tl::make_unique
<SvXMLTokenMap
>( aRegressionEquationAttrTokenMap
);
364 } // if( ! mpRegEquationAttrTokenMap )
366 return *mpRegEquationAttrTokenMap
;
370 void SchXMLImportHelper::DeleteDataSeries(
371 const Reference
< chart2::XDataSeries
> & xSeries
,
372 const Reference
< chart2::XChartDocument
> & xDoc
)
377 Reference
< chart2::XCoordinateSystemContainer
> xCooSysCnt(
378 xDoc
->getFirstDiagram(), uno::UNO_QUERY_THROW
);
379 Sequence
< Reference
< chart2::XCoordinateSystem
> > aCooSysSeq(
380 xCooSysCnt
->getCoordinateSystems());
382 sal_Int32 nCooSysIndex
= 0;
383 for( nCooSysIndex
=0; nCooSysIndex
<aCooSysSeq
.getLength(); nCooSysIndex
++ )
385 Reference
< chart2::XChartTypeContainer
> xCTCnt( aCooSysSeq
[ nCooSysIndex
], uno::UNO_QUERY_THROW
);
386 Sequence
< Reference
< chart2::XChartType
> > aChartTypes( xCTCnt
->getChartTypes());
388 sal_Int32 nChartTypeIndex
= 0;
389 for( nChartTypeIndex
=0; nChartTypeIndex
<aChartTypes
.getLength(); nChartTypeIndex
++ )
391 Reference
< chart2::XDataSeriesContainer
> xSeriesCnt( aChartTypes
[nChartTypeIndex
], uno::UNO_QUERY_THROW
);
392 Sequence
< Reference
< chart2::XDataSeries
> > aSeriesSeq( xSeriesCnt
->getDataSeries());
394 sal_Int32 nSeriesIndex
= 0;
395 for( nSeriesIndex
=0; nSeriesIndex
<aSeriesSeq
.getLength(); nSeriesIndex
++ )
397 if( xSeries
==aSeriesSeq
[nSeriesIndex
] )
399 xSeriesCnt
->removeDataSeries(xSeries
);
406 catch( const uno::Exception
& ex
)
408 SAL_WARN("xmloff.chart", "Exception caught. Type: " << OUString::createFromAscii( typeid( ex
).name()) << ", Message: " << ex
.Message
);
413 Reference
< chart2::XDataSeries
> SchXMLImportHelper::GetNewDataSeries(
414 const Reference
< chart2::XChartDocument
> & xDoc
,
415 sal_Int32 nCoordinateSystemIndex
,
416 const OUString
& rChartTypeName
,
417 bool bPushLastChartType
/* = false */ )
419 Reference
< chart2::XDataSeries
> xResult
;
425 Reference
< chart2::XCoordinateSystemContainer
> xCooSysCnt(
426 xDoc
->getFirstDiagram(), uno::UNO_QUERY_THROW
);
427 Sequence
< Reference
< chart2::XCoordinateSystem
> > aCooSysSeq(
428 xCooSysCnt
->getCoordinateSystems());
429 Reference
< uno::XComponentContext
> xContext(
430 comphelper::getProcessComponentContext() );
432 if( nCoordinateSystemIndex
< aCooSysSeq
.getLength())
434 Reference
< chart2::XChartType
> xCurrentType
;
436 Reference
< chart2::XChartTypeContainer
> xCTCnt( aCooSysSeq
[ nCoordinateSystemIndex
], uno::UNO_QUERY_THROW
);
437 Sequence
< Reference
< chart2::XChartType
> > aChartTypes( xCTCnt
->getChartTypes());
438 // find matching chart type group
439 const Reference
< chart2::XChartType
> * pBegin
= aChartTypes
.getConstArray();
440 const Reference
< chart2::XChartType
> * pEnd
= pBegin
+ aChartTypes
.getLength();
441 const Reference
< chart2::XChartType
> * pIt
=
442 ::std::find_if( pBegin
, pEnd
, lcl_MatchesChartType( rChartTypeName
));
444 xCurrentType
.set( *pIt
);
445 // if chart type is set at series and differs from current one,
446 // create a new chart type
447 if( !xCurrentType
.is())
450 xContext
->getServiceManager()->createInstanceWithContext( rChartTypeName
, xContext
),
452 if( xCurrentType
.is())
454 if( bPushLastChartType
&& aChartTypes
.getLength())
456 sal_Int32
nIndex( aChartTypes
.getLength() - 1 );
457 aChartTypes
.realloc( aChartTypes
.getLength() + 1 );
458 aChartTypes
[ nIndex
+ 1 ] = aChartTypes
[ nIndex
];
459 aChartTypes
[ nIndex
] = xCurrentType
;
460 xCTCnt
->setChartTypes( aChartTypes
);
463 xCTCnt
->addChartType( xCurrentType
);
468 if( xCurrentType
.is())
470 Reference
< chart2::XDataSeriesContainer
> xSeriesCnt( xCurrentType
, uno::UNO_QUERY_THROW
);
475 xContext
->getServiceManager()->createInstanceWithContext(
476 "com.sun.star.chart2.DataSeries",
477 xContext
), uno::UNO_QUERY_THROW
);
480 xSeriesCnt
->addDataSeries( xResult
);
484 catch( const uno::Exception
& ex
)
486 SAL_WARN("xmloff.chart", "Exception caught. Type: " << OUString::createFromAscii( typeid( ex
).name()) << ", Message: " << ex
.Message
);
491 SchXMLImport::SchXMLImport(
492 const Reference
< uno::XComponentContext
>& xContext
,
493 OUString
const & implementationName
, SvXMLImportFlags nImportFlags
) :
494 SvXMLImport( xContext
, implementationName
, nImportFlags
),
495 maImportHelper(new SchXMLImportHelper
)
497 GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK
), GetXMLToken(XML_N_XLINK
), XML_NAMESPACE_XLINK
);
498 GetNamespaceMap().Add( GetXMLToken(XML_NP_CHART_EXT
), GetXMLToken(XML_N_CHART_EXT
), XML_NAMESPACE_CHART_EXT
);
500 mbIsGraphicLoadOnDemandSupported
= false;
503 SchXMLImport::~SchXMLImport() throw ()
505 // stop progress view
506 if( mxStatusIndicator
.is())
508 mxStatusIndicator
->end();
509 mxStatusIndicator
->reset();
512 uno::Reference
< chart2::XChartDocument
> xChartDoc( GetModel(), uno::UNO_QUERY
);
513 if( xChartDoc
.is() && xChartDoc
->hasControllersLocked() )
514 xChartDoc
->unlockControllers();
517 // create the main context (subcontexts are created
518 // by the one created here)
519 SvXMLImportContext
*SchXMLImport::CreateContext( sal_uInt16 nPrefix
, const OUString
& rLocalName
,
520 const Reference
< xml::sax::XAttributeList
>& xAttrList
)
522 SvXMLImportContext
* pContext
= nullptr;
524 // accept <office:document>
525 if( XML_NAMESPACE_OFFICE
== nPrefix
&&
526 ( IsXMLToken( rLocalName
, XML_DOCUMENT_STYLES
) ||
527 IsXMLToken( rLocalName
, XML_DOCUMENT_CONTENT
) ))
529 pContext
= new SchXMLDocContext( *maImportHelper
.get(), *this, nPrefix
, rLocalName
);
530 } else if ( (XML_NAMESPACE_OFFICE
== nPrefix
) &&
531 ( IsXMLToken(rLocalName
, XML_DOCUMENT
) ||
532 (IsXMLToken(rLocalName
, XML_DOCUMENT_META
)
533 && (getImportFlags() & SvXMLImportFlags::META
) )) )
535 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
536 GetModel(), uno::UNO_QUERY
);
537 // mst@: right now, this seems to be not supported, so it is untested
539 pContext
= (IsXMLToken(rLocalName
, XML_DOCUMENT_META
))
540 ? new SvXMLMetaDocumentContext(*this,
541 XML_NAMESPACE_OFFICE
, rLocalName
,
542 xDPS
->getDocumentProperties())
543 // flat OpenDocument file format
544 : new SchXMLFlatDocContext_Impl(
545 *maImportHelper
.get(), *this, nPrefix
, rLocalName
,
546 xDPS
->getDocumentProperties());
548 pContext
= (IsXMLToken(rLocalName
, XML_DOCUMENT_META
))
549 ? SvXMLImport::CreateContext( nPrefix
, rLocalName
, xAttrList
)
550 : new SchXMLDocContext( *maImportHelper
.get(), *this,
551 nPrefix
, rLocalName
);
554 pContext
= SvXMLImport::CreateContext( nPrefix
, rLocalName
, xAttrList
);
560 SvXMLImportContext
* SchXMLImport::CreateStylesContext(
561 const OUString
& rLocalName
,
562 const Reference
<xml::sax::XAttributeList
>& xAttrList
)
564 //#i103287# make sure that the version information is set before importing all the properties (especially stroke-opacity!)
565 SchXMLTools::setBuildIDAtImportInfo( GetModel(), getImportInfo() );
567 SvXMLStylesContext
* pStylesCtxt
=
568 new SvXMLStylesContext( *(this), XML_NAMESPACE_OFFICE
, rLocalName
, xAttrList
);
570 // set context at base class, so that all auto-style classes are imported
571 SetAutoStyles( pStylesCtxt
);
572 maImportHelper
->SetAutoStylesContext( pStylesCtxt
);
577 void SAL_CALL
SchXMLImport::setTargetDocument( const uno::Reference
< lang::XComponent
>& xDoc
)
578 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
580 uno::Reference
< chart2::XChartDocument
> xOldDoc( GetModel(), uno::UNO_QUERY
);
581 if( xOldDoc
.is() && xOldDoc
->hasControllersLocked() )
582 xOldDoc
->unlockControllers();
584 SvXMLImport::setTargetDocument( xDoc
);
586 //set data provider and number formatter
587 // try to get an XDataProvider and set it
588 // @todo: if we have our own data, we must not use the parent as data provider
589 uno::Reference
< chart2::XChartDocument
> xChartDoc( GetModel(), uno::UNO_QUERY
);
594 //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 )
595 xChartDoc
->lockControllers();
597 uno::Reference
< container::XChild
> xChild( xChartDoc
, uno::UNO_QUERY
);
598 uno::Reference
< chart2::data::XDataReceiver
> xDataReceiver( xChartDoc
, uno::UNO_QUERY
);
599 if( xChild
.is() && xDataReceiver
.is())
601 bool bHasOwnData
= true;
603 Reference
< lang::XMultiServiceFactory
> xFact( xChild
->getParent(), uno::UNO_QUERY
);
606 //if the parent has a number formatter we will use the numberformatter of the parent
607 Reference
< util::XNumberFormatsSupplier
> xNumberFormatsSupplier( xFact
, uno::UNO_QUERY
);
608 xDataReceiver
->attachNumberFormatsSupplier( xNumberFormatsSupplier
);
610 if ( !xChartDoc
->getDataProvider().is() )
612 const OUString
aDataProviderServiceName( "com.sun.star.chart2.data.DataProvider");
613 const uno::Sequence
< OUString
> aServiceNames( xFact
->getAvailableServiceNames());
614 const OUString
* pBegin
= aServiceNames
.getConstArray();
615 const OUString
* pEnd
= pBegin
+ aServiceNames
.getLength();
616 if( ::std::find( pBegin
, pEnd
, aDataProviderServiceName
) != pEnd
)
618 Reference
< chart2::data::XDataProvider
> xProvider(
619 xFact
->createInstance( aDataProviderServiceName
), uno::UNO_QUERY
);
622 xDataReceiver
->attachDataProvider( xProvider
);
630 // else we have no parent => we have our own data
632 if( bHasOwnData
&& ! xChartDoc
->hasInternalDataProvider() )
633 xChartDoc
->createInternalDataProvider( false );
636 catch( const uno::Exception
& rEx
)
638 OString
aBStr(OUStringToOString(rEx
.Message
, RTL_TEXTENCODING_ASCII_US
));
639 SAL_INFO("xmloff.chart", "SchXMLChartContext::StartElement(): Exception caught: " << aBStr
);
643 // first version: everything comes from one storage
645 Sequence
< OUString
> SAL_CALL
SchXMLImport_getSupportedServiceNames() throw()
647 return Sequence
< OUString
> { "com.sun.star.comp.Chart.XMLOasisImporter" };
650 OUString SAL_CALL
SchXMLImport_getImplementationName() throw()
652 return OUString( "SchXMLImport" );
655 Reference
< uno::XInterface
> SAL_CALL
SchXMLImport_createInstance(const Reference
< lang::XMultiServiceFactory
> & rSMgr
) throw( uno::Exception
)
657 return static_cast<cppu::OWeakObject
*>(new SchXMLImport( comphelper::getComponentContext(rSMgr
), SchXMLImport_getImplementationName(), SvXMLImportFlags::ALL
));
660 // multiple storage version: one for content / styles / meta
662 Sequence
< OUString
> SAL_CALL
SchXMLImport_Styles_getSupportedServiceNames() throw()
664 return Sequence
< OUString
> { "com.sun.star.comp.Chart.XMLOasisStylesImporter" };
667 OUString SAL_CALL
SchXMLImport_Styles_getImplementationName() throw()
669 return OUString( "SchXMLImport.Styles" );
672 Reference
< uno::XInterface
> SAL_CALL
SchXMLImport_Styles_createInstance(const Reference
< lang::XMultiServiceFactory
> & rSMgr
) throw( uno::Exception
)
674 return static_cast<cppu::OWeakObject
*>(new SchXMLImport( comphelper::getComponentContext(rSMgr
), SchXMLImport_Styles_getImplementationName(), SvXMLImportFlags::STYLES
));
677 Sequence
< OUString
> SAL_CALL
SchXMLImport_Content_getSupportedServiceNames() throw()
679 return Sequence
< OUString
> { "com.sun.star.comp.Chart.XMLOasisContentImporter" };
682 OUString SAL_CALL
SchXMLImport_Content_getImplementationName() throw()
684 return OUString( "SchXMLImport.Content" );
687 Reference
< uno::XInterface
> SAL_CALL
SchXMLImport_Content_createInstance(const Reference
< lang::XMultiServiceFactory
> & rSMgr
) throw( uno::Exception
)
689 return static_cast<cppu::OWeakObject
*>(new SchXMLImport( comphelper::getComponentContext(rSMgr
), SchXMLImport_Content_getImplementationName(), SvXMLImportFlags::CONTENT
| SvXMLImportFlags::AUTOSTYLES
| SvXMLImportFlags::FONTDECLS
));
692 Sequence
< OUString
> SAL_CALL
SchXMLImport_Meta_getSupportedServiceNames() throw()
694 return Sequence
< OUString
> { "com.sun.star.comp.Chart.XMLOasisMetaImporter" };
697 OUString SAL_CALL
SchXMLImport_Meta_getImplementationName() throw()
699 return OUString( "SchXMLImport.Meta" );
702 Reference
< uno::XInterface
> SAL_CALL
SchXMLImport_Meta_createInstance(const Reference
< lang::XMultiServiceFactory
> & rSMgr
) throw( uno::Exception
)
704 return static_cast<cppu::OWeakObject
*>(new SchXMLImport( comphelper::getComponentContext(rSMgr
), SchXMLImport_Meta_getImplementationName(), SvXMLImportFlags::META
));
707 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */