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 "SchXMLTools.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir /* 34*cdf0e10cSrcweir #include <tools/debug.hxx> 35*cdf0e10cSrcweir */ 36*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 37*cdf0e10cSrcweir #include <comphelper/InlineContainer.hxx> 38*cdf0e10cSrcweir // header for class SvXMLUnitConverter 39*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 40*cdf0e10cSrcweir // header for struct SvXMLEnumMapEntry 41*cdf0e10cSrcweir #include <xmloff/xmlement.hxx> 42*cdf0e10cSrcweir // header for define __FAR_DATA 43*cdf0e10cSrcweir #include <tools/solar.h> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir // header for class SvXMLImportPropertyMapper 46*cdf0e10cSrcweir #include <xmloff/xmlimppr.hxx> 47*cdf0e10cSrcweir // header for class XMLPropStyleContext 48*cdf0e10cSrcweir #include <xmloff/prstylei.hxx> 49*cdf0e10cSrcweir // header for class XMLPropertySetMapper 50*cdf0e10cSrcweir #include <xmloff/xmlprmap.hxx> 51*cdf0e10cSrcweir #include <xmloff/xmlexp.hxx> 52*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 53*cdf0e10cSrcweir #include <xmloff/xmlmetai.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 57*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataProvider.hpp> 58*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataReceiver.hpp> 59*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp> 60*cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp> 61*cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> 62*cdf0e10cSrcweir #include <com/sun/star/chart2/XRegressionCurveContainer.hpp> 63*cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 64*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp> 65*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> 66*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceName.hpp> 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir using namespace com::sun::star; 71*cdf0e10cSrcweir using namespace ::xmloff::token; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir using ::rtl::OUString; 74*cdf0e10cSrcweir using ::rtl::OUStringBuffer; 75*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 76*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir namespace 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir Reference< uno::XComponentContext > lcl_getComponentContext() 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir Reference< uno::XComponentContext > xContext; 83*cdf0e10cSrcweir try 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir Reference< beans::XPropertySet > xFactProp( comphelper::getProcessServiceFactory(), uno::UNO_QUERY ); 86*cdf0e10cSrcweir if( xFactProp.is()) 87*cdf0e10cSrcweir xFactProp->getPropertyValue(OUString::createFromAscii("DefaultContext")) >>= xContext; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir catch( uno::Exception& ) 90*cdf0e10cSrcweir {} 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir return xContext; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir rtl::OUString lcl_getGeneratorFromModel( const uno::Reference< frame::XModel >& xChartModel ) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir ::rtl::OUString aGenerator; 98*cdf0e10cSrcweir uno::Reference< document::XDocumentPropertiesSupplier> xChartDocumentPropertiesSupplier( xChartModel, uno::UNO_QUERY ); 99*cdf0e10cSrcweir if( xChartDocumentPropertiesSupplier.is() ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir uno::Reference< document::XDocumentProperties > xChartDocumentProperties( 102*cdf0e10cSrcweir xChartDocumentPropertiesSupplier->getDocumentProperties()); 103*cdf0e10cSrcweir if( xChartDocumentProperties.is() ) 104*cdf0e10cSrcweir aGenerator = xChartDocumentProperties->getGenerator(); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir return aGenerator; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir rtl::OUString lcl_getGeneratorFromModelOrItsParent( const uno::Reference< frame::XModel >& xChartModel ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir ::rtl::OUString aGenerator( lcl_getGeneratorFromModel(xChartModel) ); 112*cdf0e10cSrcweir if( !aGenerator.getLength() ) //try to get the missing info from the parent document 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir uno::Reference< container::XChild > xChild( xChartModel, uno::UNO_QUERY ); 115*cdf0e10cSrcweir if( xChild.is() ) 116*cdf0e10cSrcweir aGenerator = lcl_getGeneratorFromModel( uno::Reference< frame::XModel >( xChild->getParent(), uno::UNO_QUERY) ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir return aGenerator; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir sal_Int32 lcl_getBuildIDFromGenerator( const ::rtl::OUString& rGenerator ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir //returns -1 if nothing found 124*cdf0e10cSrcweir sal_Int32 nBuildId = -1; 125*cdf0e10cSrcweir const OUString sBuildCompare( RTL_CONSTASCII_USTRINGPARAM( "$Build-" ) ); 126*cdf0e10cSrcweir sal_Int32 nEnd = -1; 127*cdf0e10cSrcweir sal_Int32 nBegin = rGenerator.indexOf( sBuildCompare, nEnd ); 128*cdf0e10cSrcweir if( nBegin != -1 ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir OUString sBuildId( rGenerator.copy( nBegin + sBuildCompare.getLength() ) ); 131*cdf0e10cSrcweir nBuildId = sBuildId.toInt32(); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir return nBuildId; 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir OUString lcl_ConvertRange( const ::rtl::OUString & rRange, const Reference< chart2::data::XDataProvider >& xDataProvider ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir OUString aResult = rRange; 139*cdf0e10cSrcweir Reference< chart2::data::XRangeXMLConversion > xRangeConversion( xDataProvider, uno::UNO_QUERY ); 140*cdf0e10cSrcweir if( xRangeConversion.is()) 141*cdf0e10cSrcweir aResult = xRangeConversion->convertRangeFromXML( rRange ); 142*cdf0e10cSrcweir return aResult; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir Reference< chart2::data::XDataSequence > lcl_createNewSequenceFromCachedXMLRange( const Reference< chart2::data::XDataSequence >& xSeq, const Reference< chart2::data::XDataProvider >& xDataProvider ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xRet; 148*cdf0e10cSrcweir OUString aRange; 149*cdf0e10cSrcweir if( xSeq.is() && SchXMLTools::getXMLRangePropertyFromDataSequence( xSeq, aRange, /* bClearProp = */ true ) ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir xRet.set( xDataProvider->createDataSequenceByRangeRepresentation( 152*cdf0e10cSrcweir lcl_ConvertRange( aRange, xDataProvider )) ); 153*cdf0e10cSrcweir SchXMLTools::copyProperties( Reference< beans::XPropertySet >( xSeq, uno::UNO_QUERY ), 154*cdf0e10cSrcweir Reference< beans::XPropertySet >( xRet, uno::UNO_QUERY )); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir return xRet; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir } // anonymous namespace 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir // ---------------------------------------- 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir namespace SchXMLTools 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir static __FAR_DATA SvXMLEnumMapEntry aXMLChartClassMap[] = 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir { XML_LINE, XML_CHART_CLASS_LINE }, 169*cdf0e10cSrcweir { XML_AREA, XML_CHART_CLASS_AREA }, 170*cdf0e10cSrcweir { XML_CIRCLE, XML_CHART_CLASS_CIRCLE }, 171*cdf0e10cSrcweir { XML_RING, XML_CHART_CLASS_RING }, 172*cdf0e10cSrcweir { XML_SCATTER, XML_CHART_CLASS_SCATTER }, 173*cdf0e10cSrcweir { XML_RADAR, XML_CHART_CLASS_RADAR }, 174*cdf0e10cSrcweir { XML_FILLED_RADAR, XML_CHART_CLASS_FILLED_RADAR }, 175*cdf0e10cSrcweir { XML_BAR, XML_CHART_CLASS_BAR }, 176*cdf0e10cSrcweir { XML_STOCK, XML_CHART_CLASS_STOCK }, 177*cdf0e10cSrcweir { XML_BUBBLE, XML_CHART_CLASS_BUBBLE }, 178*cdf0e10cSrcweir { XML_SURFACE, XML_CHART_CLASS_BAR }, //@todo change this if a surface chart is available 179*cdf0e10cSrcweir { XML_ADD_IN, XML_CHART_CLASS_ADDIN }, 180*cdf0e10cSrcweir { XML_TOKEN_INVALID, XML_CHART_CLASS_UNKNOWN } 181*cdf0e10cSrcweir }; 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir SchXMLChartTypeEnum GetChartTypeEnum( const OUString& rClassName ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir sal_uInt16 nEnumVal = XML_CHART_CLASS_UNKNOWN; 186*cdf0e10cSrcweir if( !SvXMLUnitConverter::convertEnum( 187*cdf0e10cSrcweir nEnumVal, rClassName, aXMLChartClassMap ) ) 188*cdf0e10cSrcweir nEnumVal = XML_CHART_CLASS_UNKNOWN; 189*cdf0e10cSrcweir return SchXMLChartTypeEnum(nEnumVal); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir typedef ::comphelper::MakeMap< ::rtl::OUString, ::rtl::OUString > tMakeStringStringMap; 193*cdf0e10cSrcweir //static 194*cdf0e10cSrcweir const tMakeStringStringMap& lcl_getChartTypeNameMap() 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir //shape property -- chart model object property 197*cdf0e10cSrcweir static tMakeStringStringMap g_aChartTypeNameMap = 198*cdf0e10cSrcweir tMakeStringStringMap 199*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.LineDiagram" ) 200*cdf0e10cSrcweir , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.LineChartType" ) ) 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.AreaDiagram" ) 203*cdf0e10cSrcweir , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.AreaChartType" ) ) 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.BarDiagram" ) 206*cdf0e10cSrcweir , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.ColumnChartType" ) ) 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.PieDiagram" ) 209*cdf0e10cSrcweir , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.PieChartType" ) ) 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.DonutDiagram" ) 212*cdf0e10cSrcweir , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.DonutChartType" ) ) 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.XYDiagram" ) 215*cdf0e10cSrcweir , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.ScatterChartType" ) ) 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.NetDiagram" ) 218*cdf0e10cSrcweir , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.NetChartType" ) ) 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.FilledNetDiagram" ) 221*cdf0e10cSrcweir , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.FilledNetChartType" ) ) 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.StockDiagram" ) 224*cdf0e10cSrcweir , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.CandleStickChartType" ) ) 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir ( ::rtl::OUString::createFromAscii( "com.sun.star.chart.BubbleDiagram" ) 227*cdf0e10cSrcweir , ::rtl::OUString::createFromAscii( "com.sun.star.chart2.BubbleChartType" ) ) 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir ; 230*cdf0e10cSrcweir return g_aChartTypeNameMap; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir OUString GetNewChartTypeName( const OUString & rOldChartTypeName ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir OUString aNew(rOldChartTypeName); 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir const tMakeStringStringMap& rMap = lcl_getChartTypeNameMap(); 239*cdf0e10cSrcweir tMakeStringStringMap::const_iterator aIt( rMap.find( rOldChartTypeName )); 240*cdf0e10cSrcweir if( aIt != rMap.end()) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir aNew = aIt->second; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir return aNew; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir OUString GetChartTypeByClassName( 248*cdf0e10cSrcweir const OUString & rClassName, bool bUseOldNames ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir OUStringBuffer aResultBuffer; 251*cdf0e10cSrcweir bool bInternalType = false; 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir if( bUseOldNames ) 254*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart.")); 255*cdf0e10cSrcweir else 256*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.")); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir bInternalType = true; 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir if( IsXMLToken( rClassName, XML_LINE )) 261*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Line")); 262*cdf0e10cSrcweir else if( IsXMLToken( rClassName, XML_AREA )) 263*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Area")); 264*cdf0e10cSrcweir else if( IsXMLToken( rClassName, XML_BAR )) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir if( bUseOldNames ) 267*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Bar")); 268*cdf0e10cSrcweir else 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Column")); 271*cdf0e10cSrcweir // @todo: might be Bar 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir else if( IsXMLToken( rClassName, XML_CIRCLE )) 275*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Pie")); 276*cdf0e10cSrcweir else if( IsXMLToken( rClassName, XML_RING )) 277*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Donut")); 278*cdf0e10cSrcweir else if( IsXMLToken( rClassName, XML_SCATTER )) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir if( bUseOldNames ) 281*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("XY")); 282*cdf0e10cSrcweir else 283*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Scatter")); 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir else if( IsXMLToken( rClassName, XML_BUBBLE )) 287*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Bubble")); 288*cdf0e10cSrcweir else if( IsXMLToken( rClassName, XML_RADAR )) 289*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Net")); 290*cdf0e10cSrcweir else if( IsXMLToken( rClassName, XML_FILLED_RADAR )) 291*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("FilledNet")); 292*cdf0e10cSrcweir else if( IsXMLToken( rClassName, XML_STOCK )) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir if( bUseOldNames ) 295*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Stock")); 296*cdf0e10cSrcweir else 297*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("CandleStick")); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir else if( IsXMLToken( rClassName, XML_SURFACE )) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir //@todo change this if a surface chart is available 302*cdf0e10cSrcweir if( bUseOldNames ) 303*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Bar")); 304*cdf0e10cSrcweir else 305*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Column")); 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir else 308*cdf0e10cSrcweir bInternalType = false; 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir if( ! bInternalType ) 311*cdf0e10cSrcweir return OUString(); 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir if( bUseOldNames ) 314*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("Diagram")); 315*cdf0e10cSrcweir else 316*cdf0e10cSrcweir aResultBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM("ChartType")); 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir return aResultBuffer.makeStringAndClear(); 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir XMLTokenEnum getTokenByChartType( 323*cdf0e10cSrcweir const OUString & rChartTypeService, bool bUseOldNames ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir XMLTokenEnum eResult = XML_TOKEN_INVALID; 326*cdf0e10cSrcweir OUString aPrefix, aPostfix; 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir if( bUseOldNames ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.")); 331*cdf0e10cSrcweir aPostfix = OUString( RTL_CONSTASCII_USTRINGPARAM("Diagram")); 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir else 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir aPrefix = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.")); 336*cdf0e10cSrcweir aPostfix = OUString( RTL_CONSTASCII_USTRINGPARAM("ChartType")); 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir if( rChartTypeService.match( aPrefix )) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir sal_Int32 nSkip = aPrefix.getLength(); 342*cdf0e10cSrcweir OSL_ASSERT( rChartTypeService.getLength() >= nSkip ); 343*cdf0e10cSrcweir sal_Int32 nTypeLength = rChartTypeService.getLength() - nSkip - aPostfix.getLength(); 344*cdf0e10cSrcweir // if postfix matches and leaves a non-empty type 345*cdf0e10cSrcweir if( nTypeLength > 0 && rChartTypeService.match( aPostfix, nSkip + nTypeLength )) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir OUString aServiceName( rChartTypeService.copy( nSkip, nTypeLength )); 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir if( aServiceName.equalsAscii("Line")) 350*cdf0e10cSrcweir eResult = XML_LINE; 351*cdf0e10cSrcweir else if( aServiceName.equalsAscii("Area")) 352*cdf0e10cSrcweir eResult = XML_AREA; 353*cdf0e10cSrcweir else if( aServiceName.equalsAscii("Bar") || 354*cdf0e10cSrcweir (!bUseOldNames && aServiceName.equalsAscii("Column"))) 355*cdf0e10cSrcweir eResult = XML_BAR; 356*cdf0e10cSrcweir else if( aServiceName.equalsAscii("Pie")) 357*cdf0e10cSrcweir eResult = XML_CIRCLE; 358*cdf0e10cSrcweir else if( aServiceName.equalsAscii("Donut")) 359*cdf0e10cSrcweir eResult = XML_RING; 360*cdf0e10cSrcweir else if( (bUseOldNames && aServiceName.equalsAscii("XY")) || 361*cdf0e10cSrcweir (!bUseOldNames && aServiceName.equalsAscii("Scatter"))) 362*cdf0e10cSrcweir eResult = XML_SCATTER; 363*cdf0e10cSrcweir else if( aServiceName.equalsAscii("Bubble")) 364*cdf0e10cSrcweir eResult = XML_BUBBLE; 365*cdf0e10cSrcweir else if( aServiceName.equalsAscii("Net")) 366*cdf0e10cSrcweir eResult = XML_RADAR; 367*cdf0e10cSrcweir else if( aServiceName.equalsAscii("FilledNet")) 368*cdf0e10cSrcweir eResult = XML_FILLED_RADAR; 369*cdf0e10cSrcweir else if( (bUseOldNames && aServiceName.equalsAscii("Stock")) || 370*cdf0e10cSrcweir (!bUseOldNames && aServiceName.equalsAscii("CandleStick"))) 371*cdf0e10cSrcweir eResult = XML_STOCK; 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir if( eResult == XML_TOKEN_INVALID && rChartTypeService.getLength() > 0 ) 376*cdf0e10cSrcweir eResult = XML_ADD_IN; 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir return eResult; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > GetNewLabeledDataSequence() 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xResult; 384*cdf0e10cSrcweir Reference< uno::XComponentContext > xContext( lcl_getComponentContext()); 385*cdf0e10cSrcweir if( xContext.is() ) 386*cdf0e10cSrcweir xResult.set( 387*cdf0e10cSrcweir xContext->getServiceManager()->createInstanceWithContext( 388*cdf0e10cSrcweir OUString::createFromAscii("com.sun.star.chart2.data.LabeledDataSequence"), 389*cdf0e10cSrcweir xContext ), uno::UNO_QUERY_THROW ); 390*cdf0e10cSrcweir return xResult; 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir Reference< chart2::data::XDataSequence > CreateDataSequence( 394*cdf0e10cSrcweir const OUString & rRange, 395*cdf0e10cSrcweir const Reference< chart2::XChartDocument >& xChartDoc ) 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xRet; 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir if( !xChartDoc.is() ) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir DBG_ERROR( "need a chart document" ); 402*cdf0e10cSrcweir return xRet; 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir Reference< chart2::data::XDataProvider > xDataProvider( xChartDoc->getDataProvider() ); 406*cdf0e10cSrcweir if( !xDataProvider.is() ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir DBG_ERROR( "need a data provider" ); 409*cdf0e10cSrcweir return xRet; 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir try 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir xRet.set( xDataProvider->createDataSequenceByRangeRepresentation( lcl_ConvertRange( rRange, xDataProvider ))); 415*cdf0e10cSrcweir SchXMLTools::setXMLRangePropertyAtDataSequence( xRet, rRange ); 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir catch( const lang::IllegalArgumentException & ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir DBG_ERROR( "could not create data sequence" ); 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir if( !xRet.is() && !xChartDoc->hasInternalDataProvider() && rRange.getLength() ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir //#i103911# switch to internal data in case the parent cannot provide the requested data 425*cdf0e10cSrcweir xChartDoc->createInternalDataProvider( sal_True /* bCloneExistingData */ ); 426*cdf0e10cSrcweir xDataProvider = xChartDoc->getDataProvider(); 427*cdf0e10cSrcweir try 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir xRet.set( xDataProvider->createDataSequenceByRangeRepresentation( lcl_ConvertRange( rRange, xDataProvider ))); 430*cdf0e10cSrcweir SchXMLTools::setXMLRangePropertyAtDataSequence( xRet, rRange ); 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir catch( const lang::IllegalArgumentException & ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir DBG_ERROR( "could not create data sequence" ); 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir return xRet; 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir void CreateCategories( 441*cdf0e10cSrcweir const uno::Reference< chart2::data::XDataProvider > & xDataProvider, 442*cdf0e10cSrcweir const uno::Reference< chart2::XChartDocument > & xNewDoc, 443*cdf0e10cSrcweir const OUString & rRangeAddress, 444*cdf0e10cSrcweir sal_Int32 nCooSysIndex, 445*cdf0e10cSrcweir sal_Int32 nDimensionIndex, 446*cdf0e10cSrcweir tSchXMLLSequencesPerIndex * pLSequencesPerIndex ) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir try 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir if( xNewDoc.is() && rRangeAddress.getLength()) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir if( xDataProvider.is()) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir uno::Reference< chart2::XDiagram > xDia( xNewDoc->getFirstDiagram()); 455*cdf0e10cSrcweir if( !xDia.is()) 456*cdf0e10cSrcweir return; 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDia, uno::UNO_QUERY_THROW ); 459*cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > 460*cdf0e10cSrcweir aCooSysSeq( xCooSysCnt->getCoordinateSystems()); 461*cdf0e10cSrcweir if( nCooSysIndex < aCooSysSeq.getLength()) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir uno::Reference< chart2::XCoordinateSystem > xCooSys( aCooSysSeq[nCooSysIndex] ); 464*cdf0e10cSrcweir OSL_ASSERT( xCooSys.is()); 465*cdf0e10cSrcweir if( nDimensionIndex < xCooSys->getDimension() ) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir const sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex); 468*cdf0e10cSrcweir for(sal_Int32 nI=0; nI<=nMaxAxisIndex; ++nI) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir uno::Reference< chart2::XAxis > xAxis( xCooSys->getAxisByDimension( nDimensionIndex, nI )); 471*cdf0e10cSrcweir if( xAxis.is() ) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir chart2::ScaleData aData( xAxis->getScaleData()); 474*cdf0e10cSrcweir uno::Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( 475*cdf0e10cSrcweir GetNewLabeledDataSequence()); 476*cdf0e10cSrcweir try 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir OUString aConvertedRange( rRangeAddress ); 479*cdf0e10cSrcweir bool bRangeConverted = false; 480*cdf0e10cSrcweir if( ! (xNewDoc->hasInternalDataProvider() && 481*cdf0e10cSrcweir aConvertedRange.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("categories")))) 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir Reference< chart2::data::XRangeXMLConversion > xXMLConv( xDataProvider, uno::UNO_QUERY ); 484*cdf0e10cSrcweir if( xXMLConv.is()) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir aConvertedRange = xXMLConv->convertRangeFromXML( rRangeAddress ); 487*cdf0e10cSrcweir bRangeConverted = true; 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xSeq( 491*cdf0e10cSrcweir xDataProvider->createDataSequenceByRangeRepresentation( aConvertedRange )); 492*cdf0e10cSrcweir xLabeledSeq->setValues( xSeq ); 493*cdf0e10cSrcweir if( bRangeConverted ) 494*cdf0e10cSrcweir setXMLRangePropertyAtDataSequence( xSeq, rRangeAddress ); 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir catch( const lang::IllegalArgumentException & ex ) 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir (void)ex; // avoid warning for pro build 499*cdf0e10cSrcweir OSL_ENSURE( false, ::rtl::OUStringToOString( 500*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IllegalArgumentException caught, Message: " )) + 501*cdf0e10cSrcweir ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr()); 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir aData.Categories.set( xLabeledSeq ); 504*cdf0e10cSrcweir if( pLSequencesPerIndex ) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir // register for setting local data if external data provider is not present 507*cdf0e10cSrcweir pLSequencesPerIndex->insert( 508*cdf0e10cSrcweir tSchXMLLSequencesPerIndex::value_type( 509*cdf0e10cSrcweir tSchXMLIndexWithPart( SCH_XML_CATEGORIES_INDEX, SCH_XML_PART_VALUES ), xLabeledSeq )); 510*cdf0e10cSrcweir } 511*cdf0e10cSrcweir xAxis->setScaleData( aData ); 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir } 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir catch( uno::Exception & ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir OSL_ENSURE( false, "Exception caught while creating Categories" ); 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir uno::Any getPropertyFromContext( const rtl::OUString& rPropertyName, const XMLPropStyleContext* pPropStyleContext, const SvXMLStylesContext* pStylesCtxt ) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir uno::Any aRet; 529*cdf0e10cSrcweir if( !pPropStyleContext || !pStylesCtxt ) 530*cdf0e10cSrcweir return aRet; 531*cdf0e10cSrcweir const ::std::vector< XMLPropertyState >& rProperties = pPropStyleContext->GetProperties(); 532*cdf0e10cSrcweir const UniReference< XMLPropertySetMapper >& rMapper = pStylesCtxt->GetImportPropertyMapper( pPropStyleContext->GetFamily()/*XML_STYLE_FAMILY_SCH_CHART_ID*/ )->getPropertySetMapper(); 533*cdf0e10cSrcweir ::std::vector< XMLPropertyState >::const_iterator aEnd( rProperties.end() ); 534*cdf0e10cSrcweir ::std::vector< XMLPropertyState >::const_iterator aPropIter( rProperties.begin() ); 535*cdf0e10cSrcweir for( aPropIter = rProperties.begin(); aPropIter != aEnd; ++aPropIter ) 536*cdf0e10cSrcweir { 537*cdf0e10cSrcweir sal_Int32 nIdx = aPropIter->mnIndex; 538*cdf0e10cSrcweir if( nIdx == -1 ) 539*cdf0e10cSrcweir continue; 540*cdf0e10cSrcweir OUString aPropName = rMapper->GetEntryAPIName( nIdx ); 541*cdf0e10cSrcweir if(rPropertyName.equals(aPropName)) 542*cdf0e10cSrcweir return aPropIter->maValue; 543*cdf0e10cSrcweir } 544*cdf0e10cSrcweir return aRet; 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir void exportText( SvXMLExport& rExport, const OUString& rText, bool bConvertTabsLFs ) 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir SvXMLElementExport aPara( rExport, XML_NAMESPACE_TEXT, 550*cdf0e10cSrcweir ::xmloff::token::GetXMLToken( ::xmloff::token::XML_P ), 551*cdf0e10cSrcweir sal_True, sal_False ); 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir if( bConvertTabsLFs ) 554*cdf0e10cSrcweir { 555*cdf0e10cSrcweir sal_Int32 nStartPos = 0; 556*cdf0e10cSrcweir sal_Int32 nEndPos = rText.getLength(); 557*cdf0e10cSrcweir sal_Unicode cChar; 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir for( sal_Int32 nPos = 0; nPos < nEndPos; nPos++ ) 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir cChar = rText[ nPos ]; 562*cdf0e10cSrcweir switch( cChar ) 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir case 0x0009: // tabulator 565*cdf0e10cSrcweir { 566*cdf0e10cSrcweir if( nPos > nStartPos ) 567*cdf0e10cSrcweir rExport.GetDocHandler()->characters( rText.copy( nStartPos, (nPos - nStartPos)) ); 568*cdf0e10cSrcweir nStartPos = nPos + 1; 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir SvXMLElementExport aElem( rExport, XML_NAMESPACE_TEXT, 571*cdf0e10cSrcweir ::xmloff::token::GetXMLToken( ::xmloff::token::XML_TAB_STOP ), 572*cdf0e10cSrcweir sal_False, sal_False ); 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir break; 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir case 0x000A: // linefeed 577*cdf0e10cSrcweir { 578*cdf0e10cSrcweir if( nPos > nStartPos ) 579*cdf0e10cSrcweir rExport.GetDocHandler()->characters( rText.copy( nStartPos, (nPos - nStartPos)) ); 580*cdf0e10cSrcweir nStartPos = nPos + 1; 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir SvXMLElementExport aElem( rExport, XML_NAMESPACE_TEXT, 583*cdf0e10cSrcweir ::xmloff::token::GetXMLToken( ::xmloff::token::XML_LINE_BREAK ), 584*cdf0e10cSrcweir sal_False, sal_False ); 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir break; 587*cdf0e10cSrcweir } 588*cdf0e10cSrcweir } 589*cdf0e10cSrcweir if( nEndPos > nStartPos ) 590*cdf0e10cSrcweir { 591*cdf0e10cSrcweir if( nStartPos == 0 ) 592*cdf0e10cSrcweir rExport.GetDocHandler()->characters( rText ); 593*cdf0e10cSrcweir else 594*cdf0e10cSrcweir rExport.GetDocHandler()->characters( rText.copy( nStartPos, (nEndPos - nStartPos)) ); 595*cdf0e10cSrcweir } 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir else // do not convert tabs and linefeeds (eg for numbers coming from unit converter) 598*cdf0e10cSrcweir { 599*cdf0e10cSrcweir rExport.GetDocHandler()->characters( rText ); 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir void exportRangeToSomewhere( SvXMLExport& rExport, const ::rtl::OUString& rValue ) 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir //with issue #i366# and CWS chart20 ranges for error bars were introduced 606*cdf0e10cSrcweir //to keep them during copy paste from calc to impress for example it 607*cdf0e10cSrcweir //was necessary to introduce a mapping between the used ranges within calc and the data written to the local table 608*cdf0e10cSrcweir //this is why we write this ranges here 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir //#i113950# first the range was exported to attribute text:id, but that attribute does not allow arbitrary strings anymore within ODF 1.2 611*cdf0e10cSrcweir //as an alternative the range info is now saved into the description at an empty group element (not very nice, but ODF conform) 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() ); 614*cdf0e10cSrcweir if( nCurrentODFVersion == SvtSaveOptions::ODFVER_010 || nCurrentODFVersion == SvtSaveOptions::ODFVER_011 ) 615*cdf0e10cSrcweir return;//svg:desc is not allowed at draw:g in ODF1.0; but as the ranges for error bars are anyhow not allowed within ODF1.0 nor ODF1.1 we do not need the information 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir SvXMLElementExport aEmptyShapeGroup( rExport, XML_NAMESPACE_DRAW, 618*cdf0e10cSrcweir ::xmloff::token::GetXMLToken( ::xmloff::token::XML_G ), 619*cdf0e10cSrcweir sal_True, sal_False ); 620*cdf0e10cSrcweir SvXMLElementExport aDescription( rExport, XML_NAMESPACE_SVG, 621*cdf0e10cSrcweir ::xmloff::token::GetXMLToken( ::xmloff::token::XML_DESC ), 622*cdf0e10cSrcweir sal_True, sal_False ); 623*cdf0e10cSrcweir rExport.GetDocHandler()->characters( rValue ); 624*cdf0e10cSrcweir } 625*cdf0e10cSrcweir 626*cdf0e10cSrcweir Reference< chart2::XRegressionCurve > getRegressionCurve( 627*cdf0e10cSrcweir const Reference< chart2::XDataSeries > & xDataSeries ) 628*cdf0e10cSrcweir { 629*cdf0e10cSrcweir Reference< chart2::XRegressionCurve > xResult; 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( xDataSeries, uno::UNO_QUERY ); 632*cdf0e10cSrcweir if( xRegCurveCnt.is()) 633*cdf0e10cSrcweir { 634*cdf0e10cSrcweir // find equation properties of first regression curve 635*cdf0e10cSrcweir Sequence< Reference< chart2::XRegressionCurve > > aCurveSeq( 636*cdf0e10cSrcweir xRegCurveCnt->getRegressionCurves() ); 637*cdf0e10cSrcweir for( sal_Int32 nI=0; nI<aCurveSeq.getLength(); ++nI ) 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir // skip mean-value line 640*cdf0e10cSrcweir Reference< lang::XServiceName > xServiceName( aCurveSeq[nI], uno::UNO_QUERY ); 641*cdf0e10cSrcweir if( xServiceName.is()) 642*cdf0e10cSrcweir { 643*cdf0e10cSrcweir OUString aServiceName( xServiceName->getServiceName()); 644*cdf0e10cSrcweir if( aServiceName.equalsAsciiL( 645*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "com.sun.star.chart2.MeanValueRegressionCurve" ))) 646*cdf0e10cSrcweir continue; 647*cdf0e10cSrcweir } 648*cdf0e10cSrcweir // take first non-empty curve 649*cdf0e10cSrcweir if( aCurveSeq[nI].is()) 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir xResult.set( aCurveSeq[nI] ); 652*cdf0e10cSrcweir break; 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir } 656*cdf0e10cSrcweir return xResult; 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir void setXMLRangePropertyAtDataSequence( 660*cdf0e10cSrcweir const Reference< chart2::data::XDataSequence > & xDataSequence, 661*cdf0e10cSrcweir const OUString & rXMLRange ) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir if( !xDataSequence.is()) 664*cdf0e10cSrcweir return; 665*cdf0e10cSrcweir try 666*cdf0e10cSrcweir { 667*cdf0e10cSrcweir const OUString aXMLRangePropName( RTL_CONSTASCII_USTRINGPARAM( "CachedXMLRange" )); 668*cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xDataSequence, uno::UNO_QUERY_THROW ); 669*cdf0e10cSrcweir Reference< beans::XPropertySetInfo > xInfo( xProp->getPropertySetInfo()); 670*cdf0e10cSrcweir if( xInfo.is() && xInfo->hasPropertyByName( aXMLRangePropName )) 671*cdf0e10cSrcweir xProp->setPropertyValue( aXMLRangePropName, uno::makeAny( rXMLRange )); 672*cdf0e10cSrcweir } 673*cdf0e10cSrcweir catch( const uno::Exception & ex ) 674*cdf0e10cSrcweir { 675*cdf0e10cSrcweir (void)ex; // avoid warning for pro build 676*cdf0e10cSrcweir OSL_ENSURE( false, ::rtl::OUStringToOString( 677*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Exception caught, Message: " )) + 678*cdf0e10cSrcweir ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr()); 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir bool getXMLRangePropertyFromDataSequence( 683*cdf0e10cSrcweir const Reference< chart2::data::XDataSequence > & xDataSequence, 684*cdf0e10cSrcweir OUString & rOutXMLRange, 685*cdf0e10cSrcweir bool bClearProp /* = false */) 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir bool bResult = false; 688*cdf0e10cSrcweir if( xDataSequence.is()) 689*cdf0e10cSrcweir { 690*cdf0e10cSrcweir try 691*cdf0e10cSrcweir { 692*cdf0e10cSrcweir const OUString aXMLRangePropName( RTL_CONSTASCII_USTRINGPARAM( "CachedXMLRange" )); 693*cdf0e10cSrcweir Reference< beans::XPropertySet > xProp( xDataSequence, uno::UNO_QUERY_THROW ); 694*cdf0e10cSrcweir Reference< beans::XPropertySetInfo > xInfo( xProp->getPropertySetInfo()); 695*cdf0e10cSrcweir bResult = 696*cdf0e10cSrcweir ( xInfo.is() && xInfo->hasPropertyByName( aXMLRangePropName ) && 697*cdf0e10cSrcweir ( xProp->getPropertyValue( aXMLRangePropName ) >>= rOutXMLRange ) && 698*cdf0e10cSrcweir rOutXMLRange.getLength()); 699*cdf0e10cSrcweir // clear the property after usage 700*cdf0e10cSrcweir if( bClearProp && bResult ) 701*cdf0e10cSrcweir xProp->setPropertyValue( aXMLRangePropName, uno::Any( OUString())); 702*cdf0e10cSrcweir } 703*cdf0e10cSrcweir catch( const uno::Exception & ex ) 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir (void)ex; // avoid warning for pro build 706*cdf0e10cSrcweir OSL_ENSURE( false, ::rtl::OUStringToOString( 707*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Exception caught, Message: " )) + 708*cdf0e10cSrcweir ex.Message, RTL_TEXTENCODING_ASCII_US ).getStr()); 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir return bResult; 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir void copyProperties( 715*cdf0e10cSrcweir const Reference< beans::XPropertySet > & xSource, 716*cdf0e10cSrcweir const Reference< beans::XPropertySet > & xDestination ) 717*cdf0e10cSrcweir { 718*cdf0e10cSrcweir if( ! (xSource.is() && xDestination.is()) ) 719*cdf0e10cSrcweir return; 720*cdf0e10cSrcweir 721*cdf0e10cSrcweir try 722*cdf0e10cSrcweir { 723*cdf0e10cSrcweir Reference< beans::XPropertySetInfo > xSrcInfo( xSource->getPropertySetInfo(), uno::UNO_QUERY_THROW ); 724*cdf0e10cSrcweir Reference< beans::XPropertySetInfo > xDestInfo( xDestination->getPropertySetInfo(), uno::UNO_QUERY_THROW ); 725*cdf0e10cSrcweir Sequence< beans::Property > aProperties( xSrcInfo->getProperties()); 726*cdf0e10cSrcweir const sal_Int32 nLength = aProperties.getLength(); 727*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nLength; ++i ) 728*cdf0e10cSrcweir { 729*cdf0e10cSrcweir OUString aName( aProperties[i].Name); 730*cdf0e10cSrcweir if( xDestInfo->hasPropertyByName( aName )) 731*cdf0e10cSrcweir { 732*cdf0e10cSrcweir beans::Property aProp( xDestInfo->getPropertyByName( aName )); 733*cdf0e10cSrcweir if( (aProp.Attributes & beans::PropertyAttribute::READONLY) == 0 ) 734*cdf0e10cSrcweir xDestination->setPropertyValue( 735*cdf0e10cSrcweir aName, xSource->getPropertyValue( aName )); 736*cdf0e10cSrcweir } 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir } 739*cdf0e10cSrcweir catch( const uno::Exception & ) 740*cdf0e10cSrcweir { 741*cdf0e10cSrcweir OSL_ENSURE( false, "Copying property sets failed!" ); 742*cdf0e10cSrcweir } 743*cdf0e10cSrcweir } 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir bool switchBackToDataProviderFromParent( const Reference< chart2::XChartDocument >& xChartDoc, const tSchXMLLSequencesPerIndex & rLSequencesPerIndex ) 746*cdf0e10cSrcweir { 747*cdf0e10cSrcweir //return whether the switch is successful 748*cdf0e10cSrcweir if( !xChartDoc.is() || !xChartDoc->hasInternalDataProvider() ) 749*cdf0e10cSrcweir return false; 750*cdf0e10cSrcweir Reference< chart2::data::XDataProvider > xDataProviderFromParent( SchXMLTools::getDataProviderFromParent( xChartDoc ) ); 751*cdf0e10cSrcweir if( !xDataProviderFromParent.is() ) 752*cdf0e10cSrcweir return false; 753*cdf0e10cSrcweir uno::Reference< chart2::data::XDataReceiver > xDataReceiver( xChartDoc, uno::UNO_QUERY ); 754*cdf0e10cSrcweir if( !xDataReceiver.is() ) 755*cdf0e10cSrcweir return false; 756*cdf0e10cSrcweir 757*cdf0e10cSrcweir xDataReceiver->attachDataProvider( xDataProviderFromParent ); 758*cdf0e10cSrcweir 759*cdf0e10cSrcweir for( tSchXMLLSequencesPerIndex::const_iterator aLSeqIt( rLSequencesPerIndex.begin() ); 760*cdf0e10cSrcweir aLSeqIt != rLSequencesPerIndex.end(); ++aLSeqIt ) 761*cdf0e10cSrcweir { 762*cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( aLSeqIt->second ); 763*cdf0e10cSrcweir if( !xLabeledSeq.is() ) 764*cdf0e10cSrcweir continue; 765*cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xNewSeq; 766*cdf0e10cSrcweir xNewSeq = lcl_createNewSequenceFromCachedXMLRange( xLabeledSeq->getValues(), xDataProviderFromParent ); 767*cdf0e10cSrcweir if( xNewSeq.is() ) 768*cdf0e10cSrcweir xLabeledSeq->setValues( xNewSeq ); 769*cdf0e10cSrcweir xNewSeq = lcl_createNewSequenceFromCachedXMLRange( xLabeledSeq->getLabel(), xDataProviderFromParent ); 770*cdf0e10cSrcweir if( xNewSeq.is() ) 771*cdf0e10cSrcweir xLabeledSeq->setLabel( xNewSeq ); 772*cdf0e10cSrcweir } 773*cdf0e10cSrcweir return true; 774*cdf0e10cSrcweir } 775*cdf0e10cSrcweir 776*cdf0e10cSrcweir void setBuildIDAtImportInfo( uno::Reference< frame::XModel > xModel, Reference< beans::XPropertySet > xImportInfo ) 777*cdf0e10cSrcweir { 778*cdf0e10cSrcweir ::rtl::OUString aGenerator( lcl_getGeneratorFromModelOrItsParent(xModel) ); 779*cdf0e10cSrcweir if( aGenerator.getLength() ) 780*cdf0e10cSrcweir SvXMLMetaDocumentContext::setBuildId( aGenerator, xImportInfo ); 781*cdf0e10cSrcweir } 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir bool isDocumentGeneratedWithOpenOfficeOlderThan3_3( const uno::Reference< frame::XModel >& xChartModel ) 784*cdf0e10cSrcweir { 785*cdf0e10cSrcweir bool bResult = isDocumentGeneratedWithOpenOfficeOlderThan3_0( xChartModel ); 786*cdf0e10cSrcweir if( !bResult ) 787*cdf0e10cSrcweir { 788*cdf0e10cSrcweir ::rtl::OUString aGenerator( lcl_getGeneratorFromModel(xChartModel) ); 789*cdf0e10cSrcweir if( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OpenOffice.org_project/3") ) ) != -1 ) 790*cdf0e10cSrcweir { 791*cdf0e10cSrcweir if( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OpenOffice.org_project/300m") ) ) != -1 ) 792*cdf0e10cSrcweir { 793*cdf0e10cSrcweir sal_Int32 nBuilId = lcl_getBuildIDFromGenerator( lcl_getGeneratorFromModel(xChartModel) ); 794*cdf0e10cSrcweir if( nBuilId>0 && nBuilId<9491 ) //9491 is build id of dev300m76 795*cdf0e10cSrcweir bResult= true; 796*cdf0e10cSrcweir } 797*cdf0e10cSrcweir else if( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OpenOffice.org_project/310m") ) ) != -1 ) 798*cdf0e10cSrcweir bResult= true; 799*cdf0e10cSrcweir else if( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OpenOffice.org_project/320m") ) ) != -1 ) 800*cdf0e10cSrcweir bResult= true; 801*cdf0e10cSrcweir } 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir return bResult; 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir bool isDocumentGeneratedWithOpenOfficeOlderThan3_0( const uno::Reference< frame::XModel >& xChartModel ) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir bool bResult = isDocumentGeneratedWithOpenOfficeOlderThan2_3( xChartModel ); 809*cdf0e10cSrcweir if( !bResult ) 810*cdf0e10cSrcweir { 811*cdf0e10cSrcweir ::rtl::OUString aGenerator( lcl_getGeneratorFromModel(xChartModel) ); 812*cdf0e10cSrcweir if( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OpenOffice.org_project/680m") ) ) != -1 ) 813*cdf0e10cSrcweir bResult= true; 814*cdf0e10cSrcweir } 815*cdf0e10cSrcweir return bResult; 816*cdf0e10cSrcweir } 817*cdf0e10cSrcweir 818*cdf0e10cSrcweir bool isDocumentGeneratedWithOpenOfficeOlderThan2_4( const uno::Reference< frame::XModel >& xChartModel ) 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir if( isDocumentGeneratedWithOpenOfficeOlderThan2_3( xChartModel ) ) 821*cdf0e10cSrcweir return true; 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir if( isDocumentGeneratedWithOpenOfficeOlderThan3_0( xChartModel ) ) 824*cdf0e10cSrcweir { 825*cdf0e10cSrcweir sal_Int32 nBuilId = lcl_getBuildIDFromGenerator( lcl_getGeneratorFromModel(xChartModel) ); 826*cdf0e10cSrcweir if( nBuilId>0 && nBuilId<=9238 ) //9238 is build id of OpenOffice.org 2.3.1 827*cdf0e10cSrcweir return true; 828*cdf0e10cSrcweir } 829*cdf0e10cSrcweir return false; 830*cdf0e10cSrcweir } 831*cdf0e10cSrcweir 832*cdf0e10cSrcweir bool isDocumentGeneratedWithOpenOfficeOlderThan2_3( const uno::Reference< frame::XModel >& xChartModel ) 833*cdf0e10cSrcweir { 834*cdf0e10cSrcweir bool bResult = false; 835*cdf0e10cSrcweir ::rtl::OUString aGenerator( lcl_getGeneratorFromModel(xChartModel) ); 836*cdf0e10cSrcweir //if there is a meta stream at the chart object it was not written with an older OpenOffice version < 2.3 837*cdf0e10cSrcweir if( !aGenerator.getLength() ) 838*cdf0e10cSrcweir { 839*cdf0e10cSrcweir //if there is no meta stream at the chart object we need to check whether the parent document is OpenOffice at all 840*cdf0e10cSrcweir uno::Reference< container::XChild > xChild( xChartModel, uno::UNO_QUERY ); 841*cdf0e10cSrcweir if( xChild.is() ) 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir aGenerator = lcl_getGeneratorFromModel( uno::Reference< frame::XModel >( xChild->getParent(), uno::UNO_QUERY) ); 844*cdf0e10cSrcweir if( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OpenOffice.org_project") ) ) != -1 ) 845*cdf0e10cSrcweir { 846*cdf0e10cSrcweir //the chart application has not created files without a meta stream since OOo 2.3 (OOo 2.3 has written a metastream already) 847*cdf0e10cSrcweir //only the report builder extension has created some files with OOo 3.1 that do not have a meta stream 848*cdf0e10cSrcweir if( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OpenOffice.org_project/31") ) ) != -1 ) 849*cdf0e10cSrcweir bResult = false;//#i100102# probably generated with OOo 3.1 by the report designer 850*cdf0e10cSrcweir else 851*cdf0e10cSrcweir bResult= true; //in this case the OLE chart was created by an older version, as OLE objects are sometimes stream copied the version can differ from the parents version, so the parents version is not a reliable indicator 852*cdf0e10cSrcweir } 853*cdf0e10cSrcweir else if( isDocumentGeneratedWithOpenOfficeOlderThan2_0(xChartModel) ) 854*cdf0e10cSrcweir bResult= true; 855*cdf0e10cSrcweir } 856*cdf0e10cSrcweir } 857*cdf0e10cSrcweir return bResult; 858*cdf0e10cSrcweir } 859*cdf0e10cSrcweir 860*cdf0e10cSrcweir bool isDocumentGeneratedWithOpenOfficeOlderThan2_0( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel) 861*cdf0e10cSrcweir { 862*cdf0e10cSrcweir bool bResult = false; 863*cdf0e10cSrcweir ::rtl::OUString aGenerator( lcl_getGeneratorFromModelOrItsParent(xChartModel) ); 864*cdf0e10cSrcweir if( ( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("OpenOffice.org 1") ) ) == 0 ) 865*cdf0e10cSrcweir || ( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StarOffice 6") ) ) == 0 ) 866*cdf0e10cSrcweir || ( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StarOffice 7") ) ) == 0 ) 867*cdf0e10cSrcweir || ( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StarSuite 6") ) ) == 0 ) 868*cdf0e10cSrcweir || ( aGenerator.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StarSuite 7") ) ) == 0 ) 869*cdf0e10cSrcweir ) 870*cdf0e10cSrcweir bResult= true; 871*cdf0e10cSrcweir return bResult; 872*cdf0e10cSrcweir } 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir Reference< chart2::data::XDataProvider > getDataProviderFromParent( const Reference< chart2::XChartDocument >& xChartDoc ) 875*cdf0e10cSrcweir { 876*cdf0e10cSrcweir Reference< chart2::data::XDataProvider > xRet; 877*cdf0e10cSrcweir uno::Reference< container::XChild > xChild( xChartDoc, uno::UNO_QUERY ); 878*cdf0e10cSrcweir if( xChild.is() ) 879*cdf0e10cSrcweir { 880*cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xFact( xChild->getParent(), uno::UNO_QUERY ); 881*cdf0e10cSrcweir if( xFact.is() ) 882*cdf0e10cSrcweir { 883*cdf0e10cSrcweir const OUString aDataProviderServiceName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.data.DataProvider")); 884*cdf0e10cSrcweir const uno::Sequence< OUString > aServiceNames( xFact->getAvailableServiceNames()); 885*cdf0e10cSrcweir const OUString * pBegin = aServiceNames.getConstArray(); 886*cdf0e10cSrcweir const OUString * pEnd = pBegin + aServiceNames.getLength(); 887*cdf0e10cSrcweir if( ::std::find( pBegin, pEnd, aDataProviderServiceName ) != pEnd ) 888*cdf0e10cSrcweir { 889*cdf0e10cSrcweir xRet = Reference< chart2::data::XDataProvider >( 890*cdf0e10cSrcweir xFact->createInstance( aDataProviderServiceName ), uno::UNO_QUERY ); 891*cdf0e10cSrcweir } 892*cdf0e10cSrcweir } 893*cdf0e10cSrcweir } 894*cdf0e10cSrcweir return xRet; 895*cdf0e10cSrcweir } 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir } // namespace SchXMLTools 898