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