/src/libreoffice/oox/source/drawingml/chart/geographycontext.cxx
Line | Count | Source |
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 <drawingml/chart/geographycontext.hxx> |
11 | | #include <drawingml/chart/geographymodel.hxx> |
12 | | #include <oox/helper/attributelist.hxx> |
13 | | #include <oox/token/namespaces.hxx> |
14 | | #include <oox/token/tokens.hxx> |
15 | | |
16 | | namespace oox::drawingml::chart |
17 | | { |
18 | | using ::oox::core::ContextHandlerRef; |
19 | | |
20 | | GeographyContext::GeographyContext(::oox::core::ContextHandler2Helper& rParent, |
21 | | GeographyModel& rModel) |
22 | 0 | : ContextHandler2(rParent) |
23 | 0 | , mrModel(rModel) |
24 | 0 | { |
25 | 0 | } |
26 | | |
27 | | // Handle the CT_Geography complex type in the chartex schema |
28 | | ContextHandlerRef GeographyContext::onCreateContext(sal_Int32 nElement, |
29 | | const AttributeList& rAttribs) |
30 | 0 | { |
31 | 0 | switch (getCurrentElement()) |
32 | 0 | { |
33 | 0 | case CX_TOKEN(geography): |
34 | 0 | switch (nElement) |
35 | 0 | { |
36 | 0 | case CX_TOKEN(geoCache): |
37 | 0 | mrModel.mxGeoCache.emplace(); |
38 | 0 | mrModel.mxGeoCache->mosProvider = rAttribs.getString(XML_provider); |
39 | 0 | return this; |
40 | 0 | } |
41 | 0 | break; |
42 | | |
43 | 0 | case CX_TOKEN(geoCache): |
44 | 0 | switch (nElement) |
45 | 0 | { |
46 | 0 | case CX_TOKEN(binary): |
47 | 0 | return this; |
48 | 0 | case CX_TOKEN(clear): |
49 | 0 | mrModel.mxGeoCache->mxClear.emplace(); |
50 | 0 | return this; |
51 | 0 | } |
52 | 0 | break; |
53 | | |
54 | 0 | case CX_TOKEN(clear): |
55 | 0 | switch (nElement) |
56 | 0 | { |
57 | 0 | case CX_TOKEN(geoLocationQueryResults): |
58 | 0 | case CX_TOKEN(geoDataEntityQueryResults): |
59 | 0 | case CX_TOKEN(geoDataPointToEntityQueryResults): |
60 | 0 | case CX_TOKEN(geoChildEntitiesQueryResults): |
61 | 0 | case CX_TOKEN(geoParentEntitiesQueryResults): |
62 | 0 | return this; |
63 | 0 | } |
64 | 0 | break; |
65 | | |
66 | 0 | case CX_TOKEN(geoLocationQueryResults): |
67 | 0 | if (nElement == CX_TOKEN(geoLocationQueryResult)) |
68 | 0 | { |
69 | 0 | auto& rClear = *mrModel.mxGeoCache->mxClear; |
70 | 0 | rClear.maLocResults.emplace_back(); |
71 | 0 | mpCurLocResult = &rClear.maLocResults.back(); |
72 | 0 | return this; |
73 | 0 | } |
74 | 0 | break; |
75 | | |
76 | 0 | case CX_TOKEN(geoLocationQueryResult): |
77 | 0 | switch (nElement) |
78 | 0 | { |
79 | 0 | case CX_TOKEN(geoLocationQuery): |
80 | 0 | { |
81 | 0 | mpCurLocResult->mxQuery.emplace(); |
82 | 0 | auto& q = *mpCurLocResult->mxQuery; |
83 | 0 | q.mosCountryRegion = rAttribs.getString(XML_countryRegion); |
84 | 0 | q.mosAdminDistrict1 = rAttribs.getString(XML_adminDistrict1); |
85 | 0 | q.mosAdminDistrict2 = rAttribs.getString(XML_adminDistrict2); |
86 | 0 | q.mosPostalCode = rAttribs.getString(XML_postalCode); |
87 | 0 | q.mosEntityType = rAttribs.getString(XML_entityType); |
88 | 0 | return nullptr; |
89 | 0 | } |
90 | 0 | case CX_TOKEN(geoLocations): |
91 | 0 | return this; |
92 | 0 | } |
93 | 0 | break; |
94 | | |
95 | 0 | case CX_TOKEN(geoLocations): |
96 | 0 | if (nElement == CX_TOKEN(geoLocation)) |
97 | 0 | { |
98 | 0 | mpCurLocResult->maLocations.emplace_back(); |
99 | 0 | auto& loc = mpCurLocResult->maLocations.back(); |
100 | 0 | loc.mosLatitude = rAttribs.getString(XML_latitude); |
101 | 0 | loc.mosLongitude = rAttribs.getString(XML_longitude); |
102 | 0 | loc.mosEntityName = rAttribs.getString(XML_entityName); |
103 | 0 | loc.mosEntityType = rAttribs.getString(XML_entityType); |
104 | 0 | return this; |
105 | 0 | } |
106 | 0 | break; |
107 | | |
108 | 0 | case CX_TOKEN(geoLocation): |
109 | 0 | if (nElement == CX_TOKEN(address)) |
110 | 0 | { |
111 | 0 | auto& loc = mpCurLocResult->maLocations.back(); |
112 | 0 | loc.mxAddress.emplace(); |
113 | 0 | auto& a = *loc.mxAddress; |
114 | 0 | a.mosAddress1 = rAttribs.getString(XML_address1); |
115 | 0 | a.mosCountryRegion = rAttribs.getString(XML_countryRegion); |
116 | 0 | a.mosAdminDistrict1 = rAttribs.getString(XML_adminDistrict1); |
117 | 0 | a.mosAdminDistrict2 = rAttribs.getString(XML_adminDistrict2); |
118 | 0 | a.mosPostalCode = rAttribs.getString(XML_postalCode); |
119 | 0 | a.mosLocality = rAttribs.getString(XML_locality); |
120 | 0 | a.mosIsoCountryCode = rAttribs.getString(XML_isoCountryCode); |
121 | 0 | return nullptr; |
122 | 0 | } |
123 | 0 | break; |
124 | | |
125 | 0 | case CX_TOKEN(geoDataEntityQueryResults): |
126 | 0 | if (nElement == CX_TOKEN(geoDataEntityQueryResult)) |
127 | 0 | { |
128 | 0 | auto& rClear = *mrModel.mxGeoCache->mxClear; |
129 | 0 | rClear.maDataResults.emplace_back(); |
130 | 0 | mpCurDataResult = &rClear.maDataResults.back(); |
131 | 0 | return this; |
132 | 0 | } |
133 | 0 | break; |
134 | | |
135 | 0 | case CX_TOKEN(geoDataEntityQueryResult): |
136 | 0 | switch (nElement) |
137 | 0 | { |
138 | 0 | case CX_TOKEN(geoDataEntityQuery): |
139 | 0 | { |
140 | 0 | mpCurDataResult->mxQuery.emplace(); |
141 | 0 | auto& q = *mpCurDataResult->mxQuery; |
142 | 0 | q.mosEntityType = rAttribs.getString(XML_entityType); |
143 | 0 | q.mosEntityId = rAttribs.getString(XML_entityId); |
144 | 0 | return nullptr; |
145 | 0 | } |
146 | 0 | case CX_TOKEN(geoData): |
147 | 0 | { |
148 | 0 | mpCurDataResult->mxData.emplace(); |
149 | 0 | auto& d = *mpCurDataResult->mxData; |
150 | 0 | d.mosEntityName = rAttribs.getString(XML_entityName); |
151 | 0 | d.mosEntityId = rAttribs.getString(XML_entityId); |
152 | 0 | d.mosEast = rAttribs.getString(XML_east); |
153 | 0 | d.mosWest = rAttribs.getString(XML_west); |
154 | 0 | d.mosNorth = rAttribs.getString(XML_north); |
155 | 0 | d.mosSouth = rAttribs.getString(XML_south); |
156 | 0 | return this; |
157 | 0 | } |
158 | 0 | } |
159 | 0 | break; |
160 | | |
161 | 0 | case CX_TOKEN(geoData): |
162 | 0 | switch (nElement) |
163 | 0 | { |
164 | 0 | case CX_TOKEN(geoPolygons): |
165 | 0 | return this; |
166 | 0 | case CX_TOKEN(copyrights): |
167 | 0 | return this; |
168 | 0 | } |
169 | 0 | break; |
170 | | |
171 | 0 | case CX_TOKEN(geoPolygons): |
172 | 0 | if (nElement == CX_TOKEN(geoPolygon)) |
173 | 0 | { |
174 | 0 | auto& d = *mpCurDataResult->mxData; |
175 | 0 | d.maPolygons.emplace_back(); |
176 | 0 | auto& p = d.maPolygons.back(); |
177 | 0 | p.mosPolygonId = rAttribs.getString(XML_polygonId); |
178 | 0 | p.mosNumPoints = rAttribs.getString(XML_numPoints); |
179 | 0 | p.mosPcaRings = rAttribs.getString(XML_pcaRings); |
180 | 0 | return nullptr; |
181 | 0 | } |
182 | 0 | break; |
183 | | |
184 | 0 | case CX_TOKEN(copyrights): |
185 | 0 | if (nElement == CX_TOKEN(copyright)) |
186 | 0 | return this; |
187 | 0 | break; |
188 | | |
189 | 0 | case CX_TOKEN(geoDataPointToEntityQueryResults): |
190 | 0 | if (nElement == CX_TOKEN(geoDataPointToEntityQueryResult)) |
191 | 0 | { |
192 | 0 | auto& rClear = *mrModel.mxGeoCache->mxClear; |
193 | 0 | rClear.maPtResults.emplace_back(); |
194 | 0 | mpCurPtResult = &rClear.maPtResults.back(); |
195 | 0 | return this; |
196 | 0 | } |
197 | 0 | break; |
198 | | |
199 | 0 | case CX_TOKEN(geoDataPointToEntityQueryResult): |
200 | 0 | switch (nElement) |
201 | 0 | { |
202 | 0 | case CX_TOKEN(geoDataPointQuery): |
203 | 0 | { |
204 | 0 | mpCurPtResult->mxPointQuery.emplace(); |
205 | 0 | auto& q = *mpCurPtResult->mxPointQuery; |
206 | 0 | q.mosEntityType = rAttribs.getString(XML_entityType); |
207 | 0 | q.mosLatitude = rAttribs.getString(XML_latitude); |
208 | 0 | q.mosLongitude = rAttribs.getString(XML_longitude); |
209 | 0 | return nullptr; |
210 | 0 | } |
211 | 0 | case CX_TOKEN(geoDataPointToEntityQuery): |
212 | 0 | { |
213 | 0 | mpCurPtResult->mxEntityQuery.emplace(); |
214 | 0 | auto& q = *mpCurPtResult->mxEntityQuery; |
215 | 0 | q.mosEntityType = rAttribs.getString(XML_entityType); |
216 | 0 | q.mosEntityId = rAttribs.getString(XML_entityId); |
217 | 0 | return nullptr; |
218 | 0 | } |
219 | 0 | } |
220 | 0 | break; |
221 | | |
222 | 0 | case CX_TOKEN(geoChildEntitiesQueryResults): |
223 | 0 | if (nElement == CX_TOKEN(geoChildEntitiesQueryResult)) |
224 | 0 | { |
225 | 0 | auto& rClear = *mrModel.mxGeoCache->mxClear; |
226 | 0 | rClear.maChildResults.emplace_back(); |
227 | 0 | mpCurChildResult = &rClear.maChildResults.back(); |
228 | 0 | return this; |
229 | 0 | } |
230 | 0 | break; |
231 | | |
232 | 0 | case CX_TOKEN(geoChildEntitiesQueryResult): |
233 | 0 | switch (nElement) |
234 | 0 | { |
235 | 0 | case CX_TOKEN(geoChildEntitiesQuery): |
236 | 0 | { |
237 | 0 | mpCurChildResult->mxQuery.emplace(); |
238 | 0 | mpCurChildResult->mxQuery->mosEntityId = rAttribs.getString(XML_entityId); |
239 | 0 | return this; |
240 | 0 | } |
241 | 0 | case CX_TOKEN(geoChildEntities): |
242 | 0 | return this; |
243 | 0 | } |
244 | 0 | break; |
245 | | |
246 | 0 | case CX_TOKEN(geoChildEntitiesQuery): |
247 | 0 | if (nElement == CX_TOKEN(geoChildTypes)) |
248 | 0 | return this; |
249 | 0 | break; |
250 | | |
251 | 0 | case CX_TOKEN(geoChildTypes): |
252 | 0 | if (nElement == CX_TOKEN(entityType)) |
253 | 0 | return this; |
254 | 0 | break; |
255 | | |
256 | 0 | case CX_TOKEN(geoChildEntities): |
257 | 0 | if (nElement == CX_TOKEN(geoHierarchyEntity)) |
258 | 0 | { |
259 | 0 | mpCurChildResult->maEntities.emplace_back(); |
260 | 0 | auto& e = mpCurChildResult->maEntities.back(); |
261 | 0 | e.mosEntityName = rAttribs.getString(XML_entityName); |
262 | 0 | e.mosEntityId = rAttribs.getString(XML_entityId); |
263 | 0 | e.mosEntityType = rAttribs.getString(XML_entityType); |
264 | 0 | return nullptr; |
265 | 0 | } |
266 | 0 | break; |
267 | | |
268 | 0 | case CX_TOKEN(geoParentEntitiesQueryResults): |
269 | 0 | if (nElement == CX_TOKEN(geoParentEntitiesQueryResult)) |
270 | 0 | { |
271 | 0 | auto& rClear = *mrModel.mxGeoCache->mxClear; |
272 | 0 | rClear.maParentResults.emplace_back(); |
273 | 0 | mpCurParentResult = &rClear.maParentResults.back(); |
274 | 0 | return this; |
275 | 0 | } |
276 | 0 | break; |
277 | | |
278 | 0 | case CX_TOKEN(geoParentEntitiesQueryResult): |
279 | 0 | switch (nElement) |
280 | 0 | { |
281 | 0 | case CX_TOKEN(geoParentEntitiesQuery): |
282 | 0 | mpCurParentResult->mxQuery.emplace(); |
283 | 0 | mpCurParentResult->mxQuery->mosEntityId = rAttribs.getString(XML_entityId); |
284 | 0 | return nullptr; |
285 | 0 | case CX_TOKEN(geoEntity): |
286 | 0 | mpCurParentResult->mxEntity.emplace(); |
287 | 0 | mpCurParentResult->mxEntity->mosEntityName = rAttribs.getString(XML_entityName); |
288 | 0 | mpCurParentResult->mxEntity->mosEntityType = rAttribs.getString(XML_entityType); |
289 | 0 | return nullptr; |
290 | 0 | case CX_TOKEN(geoParentEntity): |
291 | 0 | mpCurParentResult->mxParentEntity.emplace(); |
292 | 0 | mpCurParentResult->mxParentEntity->mosEntityId |
293 | 0 | = rAttribs.getString(XML_entityId); |
294 | 0 | return nullptr; |
295 | 0 | } |
296 | 0 | break; |
297 | 0 | } |
298 | 0 | return nullptr; |
299 | 0 | } |
300 | | |
301 | | // Handle character data |
302 | | void GeographyContext::onCharacters(const OUString& rChars) |
303 | 0 | { |
304 | 0 | switch (getCurrentElement()) |
305 | 0 | { |
306 | 0 | case CX_TOKEN(binary): |
307 | 0 | if (mrModel.mxGeoCache.has_value()) |
308 | 0 | mrModel.mxGeoCache->mosBinary = rChars; |
309 | 0 | break; |
310 | 0 | case CX_TOKEN(copyright): |
311 | 0 | if (mpCurDataResult && mpCurDataResult->mxData.has_value()) |
312 | 0 | mpCurDataResult->mxData->maCopyrights.push_back({ rChars }); |
313 | 0 | break; |
314 | 0 | case CX_TOKEN(entityType): |
315 | 0 | if (mpCurChildResult && mpCurChildResult->mxQuery.has_value()) |
316 | 0 | mpCurChildResult->mxQuery->maEntityTypes.push_back(rChars); |
317 | 0 | break; |
318 | 0 | } |
319 | 0 | } |
320 | | |
321 | | } // namespace oox::drawingml::chart |
322 | | |
323 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |