1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "oox/drawingml/chart/datasourcecontext.hxx"
25 
26 #include "oox/drawingml/chart/datasourcemodel.hxx"
27 
28 namespace oox {
29 namespace drawingml {
30 namespace chart {
31 
32 // ============================================================================
33 
34 using ::oox::core::ContextHandler2Helper;
35 using ::oox::core::ContextHandlerRef;
36 using ::rtl::OUString;
37 
38 // ============================================================================
39 
DoubleSequenceContext(ContextHandler2Helper & rParent,DataSequenceModel & rModel)40 DoubleSequenceContext::DoubleSequenceContext( ContextHandler2Helper& rParent, DataSequenceModel& rModel ) :
41     DataSequenceContextBase( rParent, rModel ),
42     mnPtIndex( -1 )
43 {
44 }
45 
~DoubleSequenceContext()46 DoubleSequenceContext::~DoubleSequenceContext()
47 {
48 }
49 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)50 ContextHandlerRef DoubleSequenceContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
51 {
52     switch( getCurrentElement() )
53     {
54         case C_TOKEN( numRef ):
55             switch( nElement )
56             {
57                 case C_TOKEN( f ):
58                 case C_TOKEN( numCache ):
59                     return this;
60             }
61         break;
62 
63         case C_TOKEN( numCache ):
64         case C_TOKEN( numLit ):
65             switch( nElement )
66             {
67                 case C_TOKEN( formatCode ):
68                     return this;
69                 case C_TOKEN( ptCount ):
70                     mrModel.mnPointCount = rAttribs.getInteger( XML_val, -1 );
71                     return 0;
72                 case C_TOKEN( pt ):
73                     mnPtIndex = rAttribs.getInteger( XML_idx, -1 );
74                     return this;
75             }
76         break;
77 
78         case C_TOKEN( pt ):
79             switch( nElement )
80             {
81                 case C_TOKEN( v ):
82                     return this;
83             }
84         break;
85     }
86     return 0;
87 }
88 
onCharacters(const OUString & rChars)89 void DoubleSequenceContext::onCharacters( const OUString& rChars )
90 {
91     switch( getCurrentElement() )
92     {
93         case C_TOKEN( f ):
94             mrModel.maFormula = rChars;
95         break;
96         case C_TOKEN( formatCode ):
97             mrModel.maFormatCode = rChars;
98         break;
99         case C_TOKEN( v ):
100             if( mnPtIndex >= 0 )
101                 mrModel.maData[ mnPtIndex ] <<= rChars.toDouble();
102         break;
103     }
104 }
105 
106 // ============================================================================
107 
StringSequenceContext(ContextHandler2Helper & rParent,DataSequenceModel & rModel)108 StringSequenceContext::StringSequenceContext( ContextHandler2Helper& rParent, DataSequenceModel& rModel ) :
109     DataSequenceContextBase( rParent, rModel )
110 {
111 }
112 
~StringSequenceContext()113 StringSequenceContext::~StringSequenceContext()
114 {
115 }
116 
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)117 ContextHandlerRef StringSequenceContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
118 {
119     switch( getCurrentElement() )
120     {
121         case C_TOKEN( multiLvlStrRef ):
122             switch( nElement )
123             {
124                 case C_TOKEN( f ):
125                     return this;
126             }
127         break;
128 
129         case C_TOKEN( strRef ):
130             switch( nElement )
131             {
132                 case C_TOKEN( f ):
133                 case C_TOKEN( strCache ):
134                     return this;
135             }
136         break;
137 
138         case C_TOKEN( strCache ):
139         case C_TOKEN( strLit ):
140             switch( nElement )
141             {
142                 case C_TOKEN( ptCount ):
143                     mrModel.mnPointCount = rAttribs.getInteger( XML_val, -1 );
144                     return 0;
145                 case C_TOKEN( pt ):
146                     mnPtIndex = rAttribs.getInteger( XML_idx, -1 );
147                     return this;
148             }
149         break;
150 
151         case C_TOKEN( pt ):
152             switch( nElement )
153             {
154                 case C_TOKEN( v ):
155                     return this;
156             }
157         break;
158     }
159     return 0;
160 }
161 
onCharacters(const OUString & rChars)162 void StringSequenceContext::onCharacters( const OUString& rChars )
163 {
164     switch( getCurrentElement() )
165     {
166         case C_TOKEN( f ):
167             mrModel.maFormula = rChars;
168         break;
169         case C_TOKEN( v ):
170             if( mnPtIndex >= 0 )
171                 mrModel.maData[ mnPtIndex ] <<= rChars;
172         break;
173     }
174 }
175 
176 // ============================================================================
177 
DataSourceContext(ContextHandler2Helper & rParent,DataSourceModel & rModel)178 DataSourceContext::DataSourceContext( ContextHandler2Helper& rParent, DataSourceModel& rModel ) :
179     ContextBase< DataSourceModel >( rParent, rModel )
180 {
181 }
182 
~DataSourceContext()183 DataSourceContext::~DataSourceContext()
184 {
185 }
186 
onCreateContext(sal_Int32 nElement,const AttributeList &)187 ContextHandlerRef DataSourceContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
188 {
189     switch( getCurrentElement() )
190     {
191         case C_TOKEN( cat ):
192         case C_TOKEN( xVal ):
193             switch( nElement )
194             {
195                 case C_TOKEN( multiLvlStrRef ):
196                 case C_TOKEN( strLit ):
197                 case C_TOKEN( strRef ):
198                     OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" );
199                     return new StringSequenceContext( *this, mrModel.mxDataSeq.create() );
200 
201                 case C_TOKEN( numLit ):
202                 case C_TOKEN( numRef ):
203                     OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" );
204                     return new DoubleSequenceContext( *this, mrModel.mxDataSeq.create() );
205             }
206         break;
207 
208         case C_TOKEN( plus ):
209         case C_TOKEN( minus ):
210         case C_TOKEN( val ):
211         case C_TOKEN( yVal ):
212         case C_TOKEN( bubbleSize ):
213             switch( nElement )
214             {
215                 case C_TOKEN( numLit ):
216                 case C_TOKEN( numRef ):
217                     OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" );
218                     return new DoubleSequenceContext( *this, mrModel.mxDataSeq.create() );
219             }
220         break;
221     }
222     return 0;
223 }
224 
225 // ============================================================================
226 
227 } // namespace chart
228 } // namespace drawingml
229 } // namespace oox
230