1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/drawingml/chart/datasourcecontext.hxx"
29 
30 #include "oox/drawingml/chart/datasourcemodel.hxx"
31 
32 namespace oox {
33 namespace drawingml {
34 namespace chart {
35 
36 // ============================================================================
37 
38 using ::oox::core::ContextHandler2Helper;
39 using ::oox::core::ContextHandlerRef;
40 using ::rtl::OUString;
41 
42 // ============================================================================
43 
44 DoubleSequenceContext::DoubleSequenceContext( ContextHandler2Helper& rParent, DataSequenceModel& rModel ) :
45     DataSequenceContextBase( rParent, rModel ),
46     mnPtIndex( -1 )
47 {
48 }
49 
50 DoubleSequenceContext::~DoubleSequenceContext()
51 {
52 }
53 
54 ContextHandlerRef DoubleSequenceContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
55 {
56     switch( getCurrentElement() )
57     {
58         case C_TOKEN( numRef ):
59             switch( nElement )
60             {
61                 case C_TOKEN( f ):
62                 case C_TOKEN( numCache ):
63                     return this;
64             }
65         break;
66 
67         case C_TOKEN( numCache ):
68         case C_TOKEN( numLit ):
69             switch( nElement )
70             {
71                 case C_TOKEN( formatCode ):
72                     return this;
73                 case C_TOKEN( ptCount ):
74                     mrModel.mnPointCount = rAttribs.getInteger( XML_val, -1 );
75                     return 0;
76                 case C_TOKEN( pt ):
77                     mnPtIndex = rAttribs.getInteger( XML_idx, -1 );
78                     return this;
79             }
80         break;
81 
82         case C_TOKEN( pt ):
83             switch( nElement )
84             {
85                 case C_TOKEN( v ):
86                     return this;
87             }
88         break;
89     }
90     return 0;
91 }
92 
93 void DoubleSequenceContext::onCharacters( const OUString& rChars )
94 {
95     switch( getCurrentElement() )
96     {
97         case C_TOKEN( f ):
98             mrModel.maFormula = rChars;
99         break;
100         case C_TOKEN( formatCode ):
101             mrModel.maFormatCode = rChars;
102         break;
103         case C_TOKEN( v ):
104             if( mnPtIndex >= 0 )
105                 mrModel.maData[ mnPtIndex ] <<= rChars.toDouble();
106         break;
107     }
108 }
109 
110 // ============================================================================
111 
112 StringSequenceContext::StringSequenceContext( ContextHandler2Helper& rParent, DataSequenceModel& rModel ) :
113     DataSequenceContextBase( rParent, rModel )
114 {
115 }
116 
117 StringSequenceContext::~StringSequenceContext()
118 {
119 }
120 
121 ContextHandlerRef StringSequenceContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
122 {
123     switch( getCurrentElement() )
124     {
125         case C_TOKEN( multiLvlStrRef ):
126             switch( nElement )
127             {
128                 case C_TOKEN( f ):
129                     return this;
130             }
131         break;
132 
133         case C_TOKEN( strRef ):
134             switch( nElement )
135             {
136                 case C_TOKEN( f ):
137                 case C_TOKEN( strCache ):
138                     return this;
139             }
140         break;
141 
142         case C_TOKEN( strCache ):
143         case C_TOKEN( strLit ):
144             switch( nElement )
145             {
146                 case C_TOKEN( ptCount ):
147                     mrModel.mnPointCount = rAttribs.getInteger( XML_val, -1 );
148                     return 0;
149                 case C_TOKEN( pt ):
150                     mnPtIndex = rAttribs.getInteger( XML_idx, -1 );
151                     return this;
152             }
153         break;
154 
155         case C_TOKEN( pt ):
156             switch( nElement )
157             {
158                 case C_TOKEN( v ):
159                     return this;
160             }
161         break;
162     }
163     return 0;
164 }
165 
166 void StringSequenceContext::onCharacters( const OUString& rChars )
167 {
168     switch( getCurrentElement() )
169     {
170         case C_TOKEN( f ):
171             mrModel.maFormula = rChars;
172         break;
173         case C_TOKEN( v ):
174             if( mnPtIndex >= 0 )
175                 mrModel.maData[ mnPtIndex ] <<= rChars;
176         break;
177     }
178 }
179 
180 // ============================================================================
181 
182 DataSourceContext::DataSourceContext( ContextHandler2Helper& rParent, DataSourceModel& rModel ) :
183     ContextBase< DataSourceModel >( rParent, rModel )
184 {
185 }
186 
187 DataSourceContext::~DataSourceContext()
188 {
189 }
190 
191 ContextHandlerRef DataSourceContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
192 {
193     switch( getCurrentElement() )
194     {
195         case C_TOKEN( cat ):
196         case C_TOKEN( xVal ):
197             switch( nElement )
198             {
199                 case C_TOKEN( multiLvlStrRef ):
200                 case C_TOKEN( strLit ):
201                 case C_TOKEN( strRef ):
202                     OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" );
203                     return new StringSequenceContext( *this, mrModel.mxDataSeq.create() );
204 
205                 case C_TOKEN( numLit ):
206                 case C_TOKEN( numRef ):
207                     OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" );
208                     return new DoubleSequenceContext( *this, mrModel.mxDataSeq.create() );
209             }
210         break;
211 
212         case C_TOKEN( plus ):
213         case C_TOKEN( minus ):
214         case C_TOKEN( val ):
215         case C_TOKEN( yVal ):
216         case C_TOKEN( bubbleSize ):
217             switch( nElement )
218             {
219                 case C_TOKEN( numLit ):
220                 case C_TOKEN( numRef ):
221                     OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" );
222                     return new DoubleSequenceContext( *this, mrModel.mxDataSeq.create() );
223             }
224         break;
225     }
226     return 0;
227 }
228 
229 // ============================================================================
230 
231 } // namespace chart
232 } // namespace drawingml
233 } // namespace oox
234