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