Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include "SchXMLPropertyMappingContext.hxx"
11 : #include "PropertyMap.hxx"
12 : #include "SchXMLTools.hxx"
13 : #include <xmloff/xmlnmspe.hxx>
14 : #include <xmloff/xmlimp.hxx>
15 : #include <xmloff/nmspmap.hxx>
16 : #include <xmloff/SchXMLSeriesHelper.hxx>
17 : #include "SchXMLImport.hxx"
18 :
19 : #include <com/sun/star/chart2/data/XLabeledDataSequence2.hpp>
20 : #include <com/sun/star/chart2/data/XDataSource.hpp>
21 : #include <com/sun/star/chart2/data/XDataSink.hpp>
22 :
23 : using namespace com::sun::star;
24 : using namespace com::sun::star::uno;
25 :
26 : namespace {
27 :
28 0 : Reference< chart2::data::XLabeledDataSequence2 > createAndAddSequenceToSeries( const OUString& rRole
29 : , const OUString& rRange
30 : , const Reference< chart2::XChartDocument >& xChartDoc
31 : , const Reference< chart2::XDataSeries >& xSeries )
32 : {
33 0 : Reference< chart2::data::XLabeledDataSequence2 > xLabeledSeq;
34 :
35 0 : Reference< chart2::data::XDataSource > xSeriesSource( xSeries,uno::UNO_QUERY );
36 :
37 0 : if( !(!rRange.isEmpty() && xChartDoc.is() && xSeriesSource.is()) )
38 0 : return xLabeledSeq;
39 :
40 : // create a new sequence
41 0 : xLabeledSeq = SchXMLTools::GetNewLabeledDataSequence();
42 :
43 : // set values at the new sequence
44 0 : Reference< chart2::data::XDataSequence > xSeq = SchXMLTools::CreateDataSequence( rRange, xChartDoc );
45 0 : Reference< beans::XPropertySet > xSeqProp( xSeq, uno::UNO_QUERY );
46 0 : if( xSeqProp.is())
47 0 : xSeqProp->setPropertyValue("Role", uno::makeAny( rRole));
48 0 : xLabeledSeq->setValues( xSeq );
49 :
50 0 : return xLabeledSeq;
51 : }
52 :
53 : }
54 :
55 0 : SchXMLPropertyMappingContext::SchXMLPropertyMappingContext( SchXMLImportHelper& rImpHelper,
56 : SvXMLImport& rImport, const OUString& rLocalName,
57 : tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
58 : uno::Reference<
59 : chart2::XDataSeries > xSeries ):
60 : SvXMLImportContext( rImport, XML_NAMESPACE_LO_EXT, rLocalName ),
61 : mrImportHelper( rImpHelper ),
62 : mxDataSeries(xSeries),
63 0 : mrLSequencesPerIndex(rLSequencesPerIndex)
64 : {
65 :
66 0 : }
67 :
68 0 : SchXMLPropertyMappingContext::~SchXMLPropertyMappingContext()
69 : {
70 0 : }
71 :
72 0 : void SchXMLPropertyMappingContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList )
73 : {
74 0 : OUString aRange;
75 0 : OUString aRole;
76 : // parse attributes
77 0 : sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
78 0 : const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetPropMappingAttrTokenMap();
79 :
80 0 : for( sal_Int16 i = 0; i < nAttrCount; i++ )
81 : {
82 0 : OUString sAttrName = xAttrList->getNameByIndex( i );
83 0 : OUString aLocalName;
84 0 : OUString aValue = xAttrList->getValueByIndex( i );
85 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
86 :
87 0 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
88 : {
89 : case XML_TOK_PROPERTY_MAPPING_PROPERTY:
90 0 : aRole = aValue;
91 0 : break;
92 : case XML_TOK_PROPERTY_MAPPING_RANGE:
93 0 : aRange = aValue;
94 0 : break;
95 : }
96 0 : }
97 :
98 0 : if( !aRange.isEmpty() && !aRole.isEmpty() )
99 : {
100 0 : Reference< chart2::XChartDocument > xChartDoc( GetImport().GetModel(), uno::UNO_QUERY );
101 : Reference< chart2::data::XLabeledDataSequence2 > xSeq =
102 0 : createAndAddSequenceToSeries(aRole, aRange, xChartDoc, mxDataSeries);
103 : mrLSequencesPerIndex.insert(
104 : tSchXMLLSequencesPerIndex::value_type(
105 : tSchXMLIndexWithPart( 0, SCH_XML_PART_VALUES),
106 0 : Reference< chart2::data::XLabeledDataSequence >( xSeq, UNO_QUERY )));
107 0 : }
108 0 : }
109 :
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|