22#include <rtl/ustrbuf.hxx>
33#include <com/sun/star/beans/PropertyAttribute.hpp>
34#include <com/sun/star/uno/XComponentContext.hpp>
35#include <com/sun/star/chart2/data/LabeledDataSequence.hpp>
36#include <com/sun/star/chart2/data/XDataProvider.hpp>
37#include <com/sun/star/chart2/data/XDataReceiver.hpp>
38#include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
39#include <com/sun/star/chart2/data/XPivotTableDataProvider.hpp>
40#include <com/sun/star/chart2/XChartDocument.hpp>
41#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
42#include <com/sun/star/container/XChild.hpp>
43#include <com/sun/star/document/XDocumentProperties.hpp>
44#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
45#include <com/sun/star/lang/XMultiServiceFactory.hpp>
46#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
58using ::com::sun::star::uno::Reference;
59using ::com::sun::star::uno::Sequence;
64OUString lcl_getGeneratorFromModel(
const uno::Reference< frame::XModel >& xChartModel )
67 uno::Reference< document::XDocumentPropertiesSupplier> xChartDocumentPropertiesSupplier( xChartModel, uno::UNO_QUERY );
68 if( xChartDocumentPropertiesSupplier.is() )
70 uno::Reference< document::XDocumentProperties > xChartDocumentProperties(
71 xChartDocumentPropertiesSupplier->getDocumentProperties());
72 if( xChartDocumentProperties.is() )
73 aGenerator = xChartDocumentProperties->getGenerator();
78OUString lcl_getGeneratorFromModelOrItsParent(
const uno::Reference< frame::XModel >& xChartModel )
80 OUString aGenerator( lcl_getGeneratorFromModel(xChartModel) );
81 if( aGenerator.isEmpty() )
83 uno::Reference< container::XChild > xChild( xChartModel, uno::UNO_QUERY );
85 aGenerator = lcl_getGeneratorFromModel( uno::Reference< frame::XModel >( xChild->getParent(), uno::UNO_QUERY) );
90sal_Int32 lcl_getBuildIDFromGenerator( std::u16string_view rGenerator )
93 sal_Int32 nBuildId = -1;
94 static constexpr OUStringLiteral sBuildCompare( u
"$Build-" );
95 size_t nBegin = rGenerator.find( sBuildCompare );
96 if( nBegin != std::u16string_view::npos )
98 std::u16string_view sBuildId = rGenerator.substr( nBegin + sBuildCompare.getLength() );
104OUString lcl_ConvertRange(
const OUString & rRange,
const Reference< chart2::data::XDataProvider >& xDataProvider )
106 OUString aResult = rRange;
107 Reference< chart2::data::XRangeXMLConversion > xRangeConversion( xDataProvider, uno::UNO_QUERY );
108 if( xRangeConversion.is())
109 aResult = xRangeConversion->convertRangeFromXML( rRange );
113Reference< chart2::data::XDataSequence > lcl_createNewSequenceFromCachedXMLRange(
const Reference< chart2::data::XDataSequence >& xSeq,
const Reference< chart2::data::XDataProvider >& xDataProvider )
115 Reference< chart2::data::XDataSequence > xRet;
119 xRet.set( xDataProvider->createDataSequenceByRangeRepresentation(
120 lcl_ConvertRange( aRange, xDataProvider )) );
122 Reference< beans::XPropertySet >( xRet, uno::UNO_QUERY ));
162 {
"com.sun.star.chart.LineDiagram",
163 "com.sun.star.chart2.LineChartType"},
164 {
"com.sun.star.chart.AreaDiagram",
165 "com.sun.star.chart2.AreaChartType"},
166 {
"com.sun.star.chart.BarDiagram",
167 "com.sun.star.chart2.ColumnChartType"},
168 {
"com.sun.star.chart.PieDiagram",
169 "com.sun.star.chart2.PieChartType"},
170 {
"com.sun.star.chart.DonutDiagram",
171 "com.sun.star.chart2.DonutChartType"},
172 {
"com.sun.star.chart.XYDiagram",
173 "com.sun.star.chart2.ScatterChartType"},
174 {
"com.sun.star.chart.NetDiagram",
175 "com.sun.star.chart2.NetChartType"},
176 {
"com.sun.star.chart.FilledNetDiagram",
177 "com.sun.star.chart2.FilledNetChartType"},
178 {
"com.sun.star.chart.StockDiagram",
179 "com.sun.star.chart2.CandleStickChartType"},
180 {
"com.sun.star.chart.BubbleDiagram",
181 "com.sun.star.chart2.BubbleChartType"}};
182 return g_aChartTypeNameMap;
187 OUString aNew(rOldChartTypeName);
190 tMakeStringStringMap::const_iterator aIt( rMap.find( rOldChartTypeName ));
191 if( aIt != rMap.end())
199 std::u16string_view rClassName,
bool bUseOldNames )
201 OUStringBuffer aResultBuffer;
202 bool bInternalType =
false;
205 aResultBuffer.append(
"com.sun.star.chart.");
207 aResultBuffer.append(
"com.sun.star.chart2.");
209 bInternalType =
true;
212 aResultBuffer.append(
"Line");
214 aResultBuffer.append(
"Area");
218 aResultBuffer.append(
"Bar");
221 aResultBuffer.append(
"Column");
226 aResultBuffer.append(
"Pie");
228 aResultBuffer.append(
"Donut");
232 aResultBuffer.append(
"XY");
234 aResultBuffer.append(
"Scatter");
238 aResultBuffer.append(
"Bubble");
240 aResultBuffer.append(
"Net");
242 aResultBuffer.append(
"FilledNet");
246 aResultBuffer.append(
"Stock");
248 aResultBuffer.append(
"CandleStick");
254 aResultBuffer.append(
"Bar");
256 aResultBuffer.append(
"Column");
259 bInternalType =
false;
261 if( ! bInternalType )
265 aResultBuffer.append(
"Diagram");
267 aResultBuffer.append(
"ChartType");
269 return aResultBuffer.makeStringAndClear();
274 std::u16string_view rChartTypeService,
bool bUseOldNames )
277 OUString aPrefix, aPostfix;
281 aPrefix =
"com.sun.star.chart.";
282 aPostfix =
"Diagram";
286 aPrefix =
"com.sun.star.chart2.";
287 aPostfix =
"ChartType";
292 sal_Int32 nSkip = aPrefix.getLength();
293 SAL_WARN_IF(
static_cast<sal_Int32
>(rChartTypeService.size()) < nSkip,
"xmloff.chart",
"ChartTypeService.getLength() < nSkip" );
294 sal_Int32 nTypeLength = rChartTypeService.size() - nSkip - aPostfix.getLength();
296 if( nTypeLength > 0 &&
o3tl::starts_with(rChartTypeService.substr(nSkip + nTypeLength), aPostfix) )
298 std::u16string_view aServiceName( rChartTypeService.substr( nSkip, nTypeLength ));
300 if ( aServiceName ==
u"Line" )
302 else if ( aServiceName ==
u"Area" )
304 else if( aServiceName ==
u"Bar" ||
305 (!bUseOldNames && aServiceName ==
u"Column"))
307 else if ( aServiceName ==
u"Pie" )
309 else if ( aServiceName ==
u"Donut" )
311 else if( (bUseOldNames && aServiceName ==
u"XY") ||
312 (!bUseOldNames && aServiceName ==
u"Scatter"))
314 else if ( aServiceName ==
u"Bubble" )
316 else if ( aServiceName ==
u"Net" )
318 else if ( aServiceName ==
u"FilledNet" )
320 else if( (bUseOldNames && aServiceName ==
u"Stock") ||
321 (!bUseOldNames && aServiceName ==
u"CandleStick"))
335 Reference< chart2::data::XLabeledDataSequence2 > xResult = chart2::data::LabeledDataSequence::create(xContext);
340 const OUString & rRange,
341 const Reference< chart2::XChartDocument >& xChartDoc )
343 Reference< chart2::data::XDataSequence > xRet;
345 if( !xChartDoc.is() )
347 SAL_WARN(
"xmloff.chart",
"need a chart document" );
351 Reference< chart2::data::XDataProvider > xDataProvider( xChartDoc->getDataProvider() );
352 if( !xDataProvider.is() )
354 SAL_WARN(
"xmloff.chart",
"need a data provider" );
358 bool bUseInternal =
false;
359 uno::Reference<beans::XPropertySet> xPropSet(xDataProvider, uno::UNO_QUERY);
365 uno::Any any = xPropSet->getPropertyValue(
"UseInternalDataProvider");
369 catch (
const beans::UnknownPropertyException&)
379 xRet.set( xDataProvider->createDataSequenceByRangeRepresentation( lcl_ConvertRange( rRange, xDataProvider )));
382 catch(
const lang::IllegalArgumentException & )
384 SAL_WARN(
"xmloff.chart",
"could not create data sequence" );
388 if( !xRet.is() && !xChartDoc->hasInternalDataProvider() && !rRange.isEmpty() )
391 xChartDoc->createInternalDataProvider(
true );
392 xDataProvider = xChartDoc->getDataProvider();
395 xRet.set( xDataProvider->createDataSequenceByRangeRepresentation( lcl_ConvertRange( rRange, xDataProvider )));
398 catch(
const lang::IllegalArgumentException & )
400 SAL_WARN(
"xmloff.chart",
"could not create data sequence" );
407 const OUString & rRange,
408 const Reference< chart2::XChartDocument >& xChartDoc )
410 Reference< chart2::data::XDataSequence > xRet;
412 if( !xChartDoc.is() )
414 SAL_WARN(
"xmloff.chart",
"need a chart document" );
418 Reference< chart2::data::XDataProvider > xDataProvider( xChartDoc->getDataProvider() );
419 if( !xDataProvider.is() )
421 SAL_WARN(
"xmloff.chart",
"need a data provider" );
427 xRet.set( xDataProvider->createDataSequenceByRangeRepresentation( rRange ) );
430 catch(
const lang::IllegalArgumentException & )
432 SAL_WARN(
"xmloff.chart",
"could not create data sequence" );
439 const uno::Reference< chart2::data::XDataProvider > & xDataProvider,
440 const uno::Reference< chart2::XChartDocument > & xNewDoc,
441 const OUString & rRangeAddress,
442 sal_Int32 nCooSysIndex,
443 sal_Int32 nDimensionIndex,
448 if( xNewDoc.is() && !rRangeAddress.isEmpty())
450 if( xDataProvider.is())
452 uno::Reference< chart2::XDiagram > xDia( xNewDoc->getFirstDiagram());
456 uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDia, uno::UNO_QUERY_THROW );
457 uno::Sequence< uno::Reference< chart2::XCoordinateSystem > >
458 aCooSysSeq( xCooSysCnt->getCoordinateSystems());
459 if( nCooSysIndex < aCooSysSeq.getLength())
461 uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[nCooSysIndex] );
462 SAL_WARN_IF( !xCooSys.is(),
"xmloff.chart",
"xCooSys is NULL");
463 if( nDimensionIndex < xCooSys->getDimension() )
465 const sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
466 for(sal_Int32 nI=0; nI<=nMaxAxisIndex; ++nI)
468 uno::Reference< chart2::XAxis > xAxis( xCooSys->getAxisByDimension( nDimensionIndex, nI ));
471 chart2::ScaleData
aData( xAxis->getScaleData());
472 uno::Reference< chart2::data::XLabeledDataSequence > xLabeledSeq(
476 OUString aConvertedRange( rRangeAddress );
477 bool bRangeConverted =
false;
478 if( ! (xNewDoc->hasInternalDataProvider() && aConvertedRange ==
"categories"))
480 Reference< chart2::data::XRangeXMLConversion > xXMLConv( xDataProvider, uno::UNO_QUERY );
483 aConvertedRange = xXMLConv->convertRangeFromXML( rRangeAddress );
484 bRangeConverted =
true;
488 Reference<chart2::data::XDataSequence> xSequence;
489 Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider(xDataProvider, uno::UNO_QUERY);
490 if (xPivotTableDataProvider.is())
492 xSequence.set(xPivotTableDataProvider->createDataSequenceOfCategories());
496 xSequence.set(xDataProvider->createDataSequenceByRangeRepresentation(aConvertedRange));
500 xLabeledSeq->setValues(xSequence);
503 catch(
const lang::IllegalArgumentException & )
507 aData.Categories.set( xLabeledSeq );
508 if( pLSequencesPerIndex )
511 pLSequencesPerIndex->emplace(
514 xAxis->setScaleData(
aData );
522 catch( uno::Exception & )
531 if( !pPropStyleContext || !pStylesCtxt )
533 const ::std::vector< XMLPropertyState >& rProperties = pPropStyleContext->
GetProperties();
535 for(
const auto& rProp : rProperties )
537 sal_Int32 nIdx = rProp.mnIndex;
540 OUString
aPropName = rMapper->GetEntryAPIName( nIdx );
542 return rProp.maValue;
553 if( bConvertTabsLFs )
555 sal_Int32 nStartPos = 0;
556 sal_Int32 nEndPos = rText.getLength();
561 cChar = rText[
nPos ];
566 if(
nPos > nStartPos )
567 rExport.
GetDocHandler()->characters( rText.copy( nStartPos, (
nPos - nStartPos)) );
568 nStartPos =
nPos + 1;
578 if(
nPos > nStartPos )
579 rExport.
GetDocHandler()->characters( rText.copy( nStartPos, (
nPos - nStartPos)) );
580 nStartPos =
nPos + 1;
589 if( nEndPos > nStartPos )
594 rExport.
GetDocHandler()->characters( rText.copy( nStartPos, (nEndPos - nStartPos)) );
628 const Reference< chart2::data::XDataSequence > & xDataSequence,
629 const OUString & rXMLRange )
631 if( !xDataSequence.is())
635 static constexpr OUStringLiteral aXMLRangePropName(
u"CachedXMLRange" );
636 Reference< beans::XPropertySet > xProp( xDataSequence, uno::UNO_QUERY_THROW );
637 Reference< beans::XPropertySetInfo > xInfo( xProp->getPropertySetInfo());
638 if( xInfo.is() && xInfo->hasPropertyByName( aXMLRangePropName ))
639 xProp->setPropertyValue( aXMLRangePropName,
uno::Any( rXMLRange ));
641 catch(
const uno::Exception & )
648 const Reference< chart2::data::XDataSequence > & xDataSequence,
649 OUString & rOutXMLRange,
652 bool bResult =
false;
653 if( xDataSequence.is())
657 static constexpr OUStringLiteral aXMLRangePropName(
u"CachedXMLRange" );
658 Reference< beans::XPropertySet > xProp( xDataSequence, uno::UNO_QUERY_THROW );
659 Reference< beans::XPropertySetInfo > xInfo( xProp->getPropertySetInfo());
661 ( xInfo.is() && xInfo->hasPropertyByName( aXMLRangePropName ) &&
662 ( xProp->getPropertyValue( aXMLRangePropName ) >>= rOutXMLRange ) &&
663 !rOutXMLRange.isEmpty());
665 if( bClearProp && bResult )
666 xProp->setPropertyValue( aXMLRangePropName,
uno::Any( OUString()));
668 catch(
const uno::Exception & )
677 const Reference< beans::XPropertySet > & xSource,
678 const Reference< beans::XPropertySet > & xDestination )
680 if( ! (xSource.is() && xDestination.is()) )
685 Reference< beans::XPropertySetInfo > xSrcInfo( xSource->getPropertySetInfo(), uno::UNO_SET_THROW );
686 Reference< beans::XPropertySetInfo > xDestInfo( xDestination->getPropertySetInfo(), uno::UNO_SET_THROW );
687 const Sequence< beans::Property >
aProperties( xSrcInfo->getProperties());
690 OUString
aName( rProperty.Name);
691 if( xDestInfo->hasPropertyByName(
aName ))
693 beans::Property aProp( xDestInfo->getPropertyByName(
aName ));
694 if( (aProp.Attributes & beans::PropertyAttribute::READONLY) == 0 )
695 xDestination->setPropertyValue(
700 catch(
const uno::Exception & )
702 SAL_WARN(
"xmloff.chart",
"Copying property sets failed!" );
709 if( !xChartDoc.is() || !xChartDoc->hasInternalDataProvider() )
712 if( !xDataProviderFromParent.is() )
714 uno::Reference< chart2::data::XDataReceiver > xDataReceiver( xChartDoc, uno::UNO_QUERY );
715 if( !xDataReceiver.is() )
718 xDataReceiver->attachDataProvider( xDataProviderFromParent );
720 for(
const auto& rLSeq : rLSequencesPerIndex )
722 Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( rLSeq.second );
723 if( !xLabeledSeq.is() )
725 Reference< chart2::data::XDataSequence > xNewSeq;
726 xNewSeq = lcl_createNewSequenceFromCachedXMLRange( xLabeledSeq->getValues(), xDataProviderFromParent );
728 xLabeledSeq->setValues( xNewSeq );
729 xNewSeq = lcl_createNewSequenceFromCachedXMLRange( xLabeledSeq->getLabel(), xDataProviderFromParent );
731 xLabeledSeq->setLabel( xNewSeq );
736void setBuildIDAtImportInfo(
const uno::Reference< frame::XModel >& xModel,
const Reference< beans::XPropertySet >& xImportInfo )
738 OUString aGenerator( lcl_getGeneratorFromModelOrItsParent(
xModel) );
739 if( !aGenerator.isEmpty() )
748 OUString aGenerator( lcl_getGeneratorFromModel(xChartModel) );
749 if( aGenerator.indexOf(
"OpenOffice.org_project/3" ) != -1 )
751 if( aGenerator.indexOf(
"OpenOffice.org_project/300m" ) != -1 )
753 sal_Int32 nBuilId = lcl_getBuildIDFromGenerator( lcl_getGeneratorFromModel(xChartModel) );
754 if( nBuilId>0 && nBuilId<9491 )
757 else if( aGenerator.indexOf(
"OpenOffice.org_project/310m" ) != -1 )
759 else if( aGenerator.indexOf(
"OpenOffice.org_project/320m" ) != -1 )
771 OUString aGenerator( lcl_getGeneratorFromModel(xChartModel) );
772 if( aGenerator.indexOf(
"OpenOffice.org_project/680m" ) != -1 )
785 sal_Int32 nBuilId = lcl_getBuildIDFromGenerator( lcl_getGeneratorFromModel(xChartModel) );
786 if( nBuilId>0 && nBuilId<=9238 )
794 bool bResult =
false;
795 OUString aGenerator( lcl_getGeneratorFromModel(xChartModel) );
797 if( aGenerator.isEmpty() )
800 uno::Reference< container::XChild > xChild( xChartModel, uno::UNO_QUERY );
803 aGenerator = lcl_getGeneratorFromModel( uno::Reference< frame::XModel >( xChild->getParent(), uno::UNO_QUERY) );
804 if( aGenerator.indexOf(
"OpenOffice.org_project" ) != -1 )
808 if( aGenerator.indexOf(
"OpenOffice.org_project/31" ) != -1 )
822 bool bResult =
false;
823 OUString aGenerator( lcl_getGeneratorFromModelOrItsParent(xChartModel) );
824 if( aGenerator.startsWith(
"OpenOffice.org 1" )
825 || aGenerator.startsWith(
"StarOffice 6" )
826 || aGenerator.startsWith(
"StarOffice 7" )
827 || aGenerator.startsWith(
"StarSuite 6" )
828 || aGenerator.startsWith(
"StarSuite 7" )
836 Reference< chart2::data::XDataProvider > xRet;
837 uno::Reference< container::XChild > xChild( xChartDoc, uno::UNO_QUERY );
840 Reference< lang::XMultiServiceFactory > xFact( xChild->getParent(), uno::UNO_QUERY );
843 static constexpr OUStringLiteral aDataProviderServiceName(
u"com.sun.star.chart2.data.DataProvider");
844 const uno::Sequence< OUString >
aServiceNames( xFact->getAvailableServiceNames());
847 if( ::std::find( pBegin, pEnd, aDataProviderServiceName ) != pEnd )
849 xRet.set( xFact->createInstance( aDataProviderServiceName ), uno::UNO_QUERY );
PropertiesInfo aProperties
SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const
returns the deterministic version for odf export
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
static void setBuildId(std::u16string_view rGenerator, const css::uno::Reference< css::beans::XPropertySet > &xImportInfo)
XmlStyleFamily GetFamily() const
virtual rtl::Reference< SvXMLImportPropertyMapper > GetImportPropertyMapper(XmlStyleFamily nFamily) const
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
::std::vector< XMLPropertyState > & GetProperties()
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
Sequence< OUString > aServiceNames
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
constexpr OUStringLiteral aData
Reference< XComponentContext > getProcessComponentContext()
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Reference< XModel > xModel
::std::multimap< tSchXMLIndexWithPart, css::uno::Reference< css::chart2::data::XLabeledDataSequence > > tSchXMLLSequencesPerIndex
::std::pair< tSchXMLIndex, SchXMLLabeledSequencePart > tSchXMLIndexWithPart
#define SCH_XML_CATEGORIES_INDEX
constexpr sal_uInt16 XML_NAMESPACE_DRAW
constexpr sal_uInt16 XML_NAMESPACE_SVG
constexpr sal_uInt16 XML_NAMESPACE_TEXT