|
1 /* |
|
2 * Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
21 #pragma warning(disable: 4786 4250 4503 4541) |
|
22 |
|
23 |
|
24 #include "MLCompDataParse.h" |
|
25 |
|
26 #include <akndef.hrh> |
|
27 |
|
28 #include <sstream> |
|
29 #include <fstream> |
|
30 #include <algorithm> |
|
31 #include <iostream> // !!! for debug output only |
|
32 |
|
33 extern string whiteSpace; |
|
34 |
|
35 |
|
36 // |
|
37 // const data |
|
38 // |
|
39 |
|
40 const string KCompDataParseRoot = "Layout"; |
|
41 |
|
42 const string KCompDataParseRootAttributeMasterName = "MasterName"; |
|
43 const string KCompDataParseRootAttributeLayoutName = "LayoutName"; |
|
44 const string KCompDataParseRootAttributeVariantName = "variant_name"; |
|
45 const string KCompDataParseRootAttributeResolutionHeight = "resolutionHeight"; |
|
46 const string KCompDataParseRootAttributeResolutionWidth = "resolutionWidth"; |
|
47 const string KCompDataParseRootAttributeCreatedOn = "createdOn"; |
|
48 |
|
49 const string KCompDataParseNodeComponent = "Component"; |
|
50 const string KCompDataParseNodeComponentAttributeName = "name"; |
|
51 const string KCompDataParseNodeComponentAttributeId = "id"; |
|
52 const string KCompDataParseNodeComponentAttributeType = "type"; |
|
53 const string KCompDataParseNodeComponentAttributeDrawingOrder = "drawingorder"; |
|
54 const string KCompDataParseNodeComponentAttributeMirror = "mirror"; |
|
55 const string KCompDataParseNodeComponentAttributeMaxVariety = "maxVariety"; |
|
56 |
|
57 const string KCompDataParseTextComponentTypeScreen= "Screen"; |
|
58 const string KCompDataParseTextComponentTypeContainer= "Container"; |
|
59 const string KCompDataParseTextComponentTypePane= "Pane"; |
|
60 const string KCompDataParseTextComponentTypeGraphic= "Graphic"; |
|
61 const string KCompDataParseTextComponentTypeText= "Text"; |
|
62 |
|
63 const string KCompDataParseTextComponentMirrorTrue= "true"; |
|
64 |
|
65 const string KCompDataParseNodeOption = "option"; |
|
66 const string KCompDataParseNodeParentInfo = "ParentInfo"; |
|
67 const string KCompDataParseNodeLayoutInfo = "LayoutInfo"; |
|
68 const string KCompDataParseNodeAttributeInfo = "AttributeInfo"; |
|
69 const string KCompDataParseNodeAttrSets = "attrsets"; |
|
70 |
|
71 const string KCompDataParseNodeParent = "parent"; |
|
72 const string KCompDataParseNodeParentOption = "option"; |
|
73 const string KCompDataParseNodeParentOptionAttributeVariety = "variety"; |
|
74 const string KCompDataParseNodeParentInfoParentAttributeId = "id"; |
|
75 const string KCompDataParseNodeParentInfoParentAttributeVariety = "variety"; |
|
76 |
|
77 const string KCompDataParseNodeLayoutInfoParam = "Param"; |
|
78 const string KCompDataParseNodeLayoutInfoParamAttributeName = "name"; |
|
79 |
|
80 const string KCompDataParseNodeValue = "Value"; |
|
81 const string KCompDataParseNodeVarietyIndex = "varietyIndex"; |
|
82 const string KCompDataParseNodeVarietyIndexValue = "value"; |
|
83 const string KCompDataParseNodeCalc = "calc"; |
|
84 const string KCompDataParseNodeCalcAttributeValue = "value"; |
|
85 const string KCompDataParseNodeCalcAttributeColNumber = "colNumber"; |
|
86 const string KCompDataParseNodeCalcAttributeRowNumber = "rowNumber"; |
|
87 const string KCompDataParseNodeCalcAttributeShowInTable = "showInTable"; |
|
88 const string KCompDataParseNodeCalcAttributeShowInTableTrue = "true"; |
|
89 const string KCompDataParseNodeCalcAttributeShowInTableFalse = "false"; |
|
90 const string KCompDataParseNodeCalcAttributeZoom = "zoom"; |
|
91 const string KCompDataParseNodeCalcAttributeZoomNormal = "normal"; |
|
92 const string KCompDataParseNodeCalcAttributeZoomVerySmall = "-2 zoom"; |
|
93 const string KCompDataParseNodeCalcAttributeZoomSmall = "-1 zoom"; |
|
94 const string KCompDataParseNodeCalcAttributeZoomLarge = "+1 zoom"; |
|
95 const string KCompDataParseNodeCalcAttributeZoomVeryLarge = "+2 zoom"; |
|
96 |
|
97 const string KCompDataParseTextFontPrimary = "qfn_primary"; |
|
98 const string KCompDataParseTextFontSecondary = "qfn_secondary"; |
|
99 const string KCompDataParseTextFontTitle = "qfn_title"; |
|
100 const string KCompDataParseTextFontPrimarySmall = "qfn_primary_small"; // is that the correct text? |
|
101 const string KCompDataParseTextFontDigital = "qfn_digital"; |
|
102 |
|
103 const string KCompDataParseTextParamNameColor = "Color"; |
|
104 const string KCompDataParseTextParamShortNameColor = "C"; |
|
105 const string KCompDataParseTextParamNameLeft = "Left"; |
|
106 const string KCompDataParseTextParamShortNameLeft = "l"; |
|
107 const string KCompDataParseTextParamNameRight = "Right"; |
|
108 const string KCompDataParseTextParamShortNameRight = "r"; |
|
109 const string KCompDataParseTextParamNameTop = "Top"; |
|
110 const string KCompDataParseTextParamShortNameTop = "t"; |
|
111 const string KCompDataParseTextParamNameBottom = "Bottom"; |
|
112 const string KCompDataParseTextParamShortNameBottom = "b"; |
|
113 const string KCompDataParseTextParamNameWidth = "Width"; |
|
114 const string KCompDataParseTextParamShortNameWidth = "W"; |
|
115 const string KCompDataParseTextParamNameHeight = "Height"; |
|
116 const string KCompDataParseTextParamShortNameHeight = "H"; |
|
117 const string KCompDataParseTextParamNameJustification = "Justification"; |
|
118 const string KCompDataParseTextParamShortNameJustification = "J"; |
|
119 const string KCompDataParseTextParamNameType = "Type"; |
|
120 const string KCompDataParseTextParamShortNameType = "Type"; |
|
121 |
|
122 // these have been changed to lower case, so that matching |
|
123 // can be performed independent of case |
|
124 const string KCompDataParseTextParamTypeCalcValueNone = "none"; |
|
125 const string KCompDataParseTextParamTypeCalcValueLeft = "left"; |
|
126 const string KCompDataParseTextParamTypeCalcValueCenter = "center"; |
|
127 const string KCompDataParseTextParamTypeCalcValueRight = "right"; |
|
128 const string KCompDataParseTextParamTypeCalcValueBidi = "bidi"; |
|
129 |
|
130 const string KCompDataParseNodeAttributeInfoOption = "option"; |
|
131 const string KCompDataParseNodeAttributeInfoOptionAttributeVariety = "variety"; |
|
132 const string KCompDataParseNodeAttributeInfoAttributeSet = "attributeset"; |
|
133 const string KCompDataParseNodeAttributeInfoAttributeSetAttributeName = "name"; |
|
134 |
|
135 // |
|
136 // TMLCompDataParseValues |
|
137 // |
|
138 |
|
139 TMLCompDataParseValues::TMLCompDataParseValues(TMLCompDataLine* aLine) |
|
140 : |
|
141 TMLCompDataValues(aLine), |
|
142 iSaxZoomLevels(0), |
|
143 iSaxVariety(-1) |
|
144 { |
|
145 |
|
146 } |
|
147 |
|
148 MSaxLayoutHandler* TMLCompDataParseValues::HandleSax(const std::string& aElement, const TAttribs& aAttribs) |
|
149 { |
|
150 // <Param name="Left"> |
|
151 // <Value> |
|
152 // <varietyIndex value="0"/> |
|
153 // <optionIndex value="0"/> |
|
154 // <calc ... > |
|
155 // ... |
|
156 // </Value> |
|
157 // ... |
|
158 // </Param> |
|
159 |
|
160 if (aElement == KCompDataParseNodeValue) |
|
161 { |
|
162 delete iSaxZoomLevels; |
|
163 iSaxZoomLevels = 0; |
|
164 iSaxZoomLevels = new TMLCompDataZoomLevels; |
|
165 } |
|
166 else if (aElement == KCompDataParseNodeVarietyIndex) |
|
167 { |
|
168 HandleSaxVariety(aElement, aAttribs); |
|
169 } |
|
170 else if (aElement == KCompDataParseNodeCalc) |
|
171 { |
|
172 HandleSaxCalc(aElement, aAttribs); |
|
173 } |
|
174 |
|
175 return this; |
|
176 } |
|
177 |
|
178 void TMLCompDataParseValues::HandleSaxEnd(const std::string& aElement) |
|
179 { |
|
180 if (aElement == KCompDataParseNodeValue) |
|
181 { |
|
182 insert(make_pair(iSaxVariety, *iSaxZoomLevels)); |
|
183 delete iSaxZoomLevels; |
|
184 iSaxZoomLevels = 0; |
|
185 } |
|
186 } |
|
187 |
|
188 void TMLCompDataParseValues::HandleSaxVariety(const std::string& /*aElement*/, const TAttribs& aAttribs) |
|
189 { |
|
190 // <varietyIndex value="0"/> |
|
191 |
|
192 string varietyIndexStr = aAttribs.getValue(KCompDataParseNodeVarietyIndexValue); |
|
193 iSaxVariety = CdlTkUtil::ParseInt(varietyIndexStr); // defaults to zero |
|
194 if(iLine->MaxVariety() < iSaxVariety) |
|
195 { |
|
196 iLine->SetMaxVariety(iSaxVariety); |
|
197 } |
|
198 } |
|
199 |
|
200 void TMLCompDataParseValues::HandleSaxCalc(const std::string& /*aElement*/, const TAttribs& aAttribs) |
|
201 { |
|
202 // <calc value="0"/> |
|
203 // or |
|
204 // <calc value="0" zoom="x_2"/> |
|
205 // or |
|
206 // <calc colNumber="1" rowNumber="1" value="0"/> |
|
207 // or |
|
208 // <calc colNumber="1" rowNumber="1" value="0" zoom="x_2"/> |
|
209 |
|
210 // note that if there is only one calc, but the colNumber and rowNumber attributes are present |
|
211 // then we have to assume that it is a multivalue component, so deduce which kind it is from |
|
212 // the current value name |
|
213 |
|
214 // first the index part |
|
215 int max = 1; |
|
216 int cols = 0; |
|
217 int rows = 0; |
|
218 |
|
219 string colStr = aAttribs.getValue(KCompDataParseNodeCalcAttributeColNumber); |
|
220 if(!colStr.empty()) |
|
221 { |
|
222 cols = CdlTkUtil::ParseInt(colStr); |
|
223 if(TMLCompDataTable::IsHorizontalColumn(iName)) |
|
224 { |
|
225 iLine->SetNeedsCols(true); |
|
226 } |
|
227 } |
|
228 |
|
229 string rowStr = aAttribs.getValue(KCompDataParseNodeCalcAttributeRowNumber); |
|
230 if(!rowStr.empty()) |
|
231 { |
|
232 rows = CdlTkUtil::ParseInt(rowStr); |
|
233 if(TMLCompDataTable::IsVerticalColumn(iName)) |
|
234 { |
|
235 iLine->SetNeedsRows(true); |
|
236 } |
|
237 } |
|
238 |
|
239 // keep the line updated if we have found more rows / cols than it knows about |
|
240 if(iLine->NumCols() < cols) |
|
241 iLine->SetNumCols(cols); |
|
242 if(iLine->NumRows() < rows) |
|
243 iLine->SetNumRows(rows); |
|
244 |
|
245 // each calc is either a row or a col (depending on which axis) |
|
246 if(cols > 1) |
|
247 max = cols; |
|
248 else if(rows > 1) |
|
249 max = rows; |
|
250 |
|
251 // then the value part of the calc |
|
252 string valueStr; |
|
253 valueStr = aAttribs.getValue(KCompDataParseNodeCalcAttributeValue); |
|
254 ConvertValueStr(valueStr); |
|
255 |
|
256 // check whether the calc is a default value (which corresponds to normal zoom) |
|
257 // or if it corresponds to a known zoom factor |
|
258 string zoomStr = aAttribs.getValue(KCompDataParseNodeCalcAttributeZoom); |
|
259 int zoom = ConvertZoomStr(zoomStr); |
|
260 if(zoom != EAknUiZoomAutomatic) |
|
261 { |
|
262 // then put them together |
|
263 int num = max - 1; // change to zero based |
|
264 TMLCompDataCalcs& calcs = (*iSaxZoomLevels)[zoom]; |
|
265 calcs[num] = valueStr; |
|
266 } |
|
267 } |
|
268 |
|
269 void TMLCompDataParseValues::ConvertValueStr(std::string& aValueStr) |
|
270 { |
|
271 int valueInt = 0; |
|
272 if(iName == KCompDataParseTextParamShortNameType) |
|
273 { |
|
274 if(aValueStr == KCompDataParseTextFontPrimary) |
|
275 valueInt = ELayoutCompilerFontCategoryPrimary; |
|
276 else if(aValueStr == KCompDataParseTextFontSecondary) |
|
277 valueInt = ELayoutCompilerFontCategorySecondary; |
|
278 else if(aValueStr == KCompDataParseTextFontTitle) |
|
279 valueInt = ELayoutCompilerFontCategoryTitle; |
|
280 else if(aValueStr == KCompDataParseTextFontPrimarySmall) |
|
281 valueInt = ELayoutCompilerFontCategoryPrimarySmall; |
|
282 else if(aValueStr == KCompDataParseTextFontDigital) |
|
283 valueInt = ELayoutCompilerFontCategoryDigital; |
|
284 else |
|
285 valueInt = ELayoutCompilerFontCategoryUndefined; |
|
286 aValueStr = CdlTkUtil::IntToString(valueInt); |
|
287 } |
|
288 else if(iName == KCompDataParseTextParamShortNameJustification) |
|
289 { |
|
290 // jusitication does not have consistent capitalization |
|
291 string lowerValueStr = CdlTkUtil::ToLower(aValueStr); |
|
292 if(lowerValueStr == KCompDataParseTextParamTypeCalcValueNone) |
|
293 valueInt = ELayoutAlignNone; |
|
294 else if(lowerValueStr == KCompDataParseTextParamTypeCalcValueLeft) |
|
295 valueInt = ELayoutAlignLeft; |
|
296 else if(lowerValueStr == KCompDataParseTextParamTypeCalcValueRight) |
|
297 valueInt = ELayoutAlignRight; |
|
298 else if(lowerValueStr == KCompDataParseTextParamTypeCalcValueCenter) |
|
299 valueInt = ELayoutAlignCenter; |
|
300 else if(lowerValueStr == KCompDataParseTextParamTypeCalcValueBidi) |
|
301 valueInt = ELayoutAlignBidi; |
|
302 else |
|
303 valueInt = ELayoutAlignNone; |
|
304 aValueStr = CdlTkUtil::IntToString(valueInt); |
|
305 } |
|
306 } |
|
307 |
|
308 int TMLCompDataParseValues::ConvertZoomStr(const std::string& aZoomStr) |
|
309 { |
|
310 int zoomInt = EAknUiZoomAutomatic; |
|
311 string lowerZoomStr = CdlTkUtil::ToLower(aZoomStr); |
|
312 if(lowerZoomStr.empty()) |
|
313 zoomInt = EAknUiZoomNormal; |
|
314 else if(lowerZoomStr == KCompDataParseNodeCalcAttributeZoomVerySmall) |
|
315 zoomInt = EAknUiZoomVerySmall; |
|
316 else if(lowerZoomStr == KCompDataParseNodeCalcAttributeZoomSmall) |
|
317 zoomInt = EAknUiZoomSmall; |
|
318 else if(lowerZoomStr == KCompDataParseNodeCalcAttributeZoomLarge) |
|
319 zoomInt = EAknUiZoomLarge; |
|
320 else if(lowerZoomStr == KCompDataParseNodeCalcAttributeZoomVeryLarge) |
|
321 zoomInt = EAknUiZoomVeryLarge; |
|
322 return zoomInt; |
|
323 } |
|
324 |
|
325 |
|
326 // |
|
327 // TMLCompDataParseParentInfo |
|
328 // |
|
329 |
|
330 TMLCompDataParseParentInfo::TMLCompDataParseParentInfo(TMLCompDataLine* aLine) |
|
331 : |
|
332 iSaxParentInfoSelector(0), |
|
333 iSaxVariety(0) |
|
334 { |
|
335 |
|
336 } |
|
337 |
|
338 MSaxLayoutHandler* TMLCompDataParseParentInfo::HandleSax(const std::string& aElement, const TAttribs& aAttribs) |
|
339 { |
|
340 // <ParentInfo> |
|
341 // <option variety="0"> |
|
342 // <parent id="3140" variety="2"/> |
|
343 // </option> |
|
344 // </ParentInfo> |
|
345 |
|
346 if (aElement == KCompDataParseNodeOption) |
|
347 { |
|
348 delete iSaxParentInfoSelector; |
|
349 iSaxParentInfoSelector= 0; |
|
350 iSaxParentInfoSelector = new TMLCompDataParentInfoSelector; |
|
351 HandleSaxVariety(aElement, aAttribs); |
|
352 } |
|
353 else if (aElement == KCompDataParseNodeParent) |
|
354 { |
|
355 HandleSaxParent(aElement, aAttribs); |
|
356 } |
|
357 |
|
358 return this; |
|
359 } |
|
360 |
|
361 void TMLCompDataParseParentInfo::HandleSaxEnd(const std::string& aElement) |
|
362 { |
|
363 if (aElement == KCompDataParseNodeOption) // value |
|
364 { |
|
365 insert(make_pair(iSaxVariety, *iSaxParentInfoSelector)); |
|
366 delete iSaxParentInfoSelector; |
|
367 iSaxParentInfoSelector = 0; |
|
368 } |
|
369 } |
|
370 |
|
371 void TMLCompDataParseParentInfo::HandleSaxParent(const std::string& aElement, const TAttribs& aAttribs) |
|
372 { |
|
373 // <parent id="3140" variety="2"/> |
|
374 string parentIdStr = aAttribs.getValue(KCompDataParseNodeParentInfoParentAttributeId); |
|
375 string parentVarietyStr = aAttribs.getValue(KCompDataParseNodeParentInfoParentAttributeVariety); |
|
376 |
|
377 iSaxParentInfoSelector->iParentId = CdlTkUtil::ParseInt(parentIdStr); |
|
378 iSaxParentInfoSelector->iParentVariety = CdlTkUtil::ParseInt(parentVarietyStr); |
|
379 } |
|
380 |
|
381 void TMLCompDataParseParentInfo::HandleSaxVariety(const std::string& aElement, const TAttribs& aAttribs) |
|
382 { |
|
383 // <option variety="0"> |
|
384 string varietyIndexStr = aAttribs.getValue(KCompDataParseNodeParentOptionAttributeVariety); |
|
385 iSaxVariety = CdlTkUtil::ParseInt(varietyIndexStr); // defaults to zero |
|
386 } |
|
387 |
|
388 // |
|
389 // TMLCompDataParseLayoutLine |
|
390 // |
|
391 |
|
392 TMLCompDataParseLayoutLine::TMLCompDataParseLayoutLine() |
|
393 : |
|
394 TMLCompDataLine(), |
|
395 iSaxValues(0), |
|
396 iSaxParentInfo(0), |
|
397 iSaxAttributeInfo(0) |
|
398 { |
|
399 } |
|
400 |
|
401 MSaxLayoutHandler* TMLCompDataParseLayoutLine::HandleSax(const std::string& aElement, const TAttribs& aAttribs) |
|
402 { |
|
403 if(aElement == KCompDataParseNodeComponent) |
|
404 { |
|
405 HandleSaxAttributes(aAttribs); |
|
406 } |
|
407 else if(aElement == KCompDataParseNodeParentInfo) |
|
408 { |
|
409 return HandleSaxParent(aElement, aAttribs); |
|
410 } |
|
411 else if(aElement == KCompDataParseNodeLayoutInfoParam) |
|
412 { |
|
413 // <LayoutInfo> |
|
414 // <Param name="Left"> |
|
415 // ... |
|
416 // </LayoutInfo> |
|
417 return HandleSaxParam(aElement, aAttribs); |
|
418 } |
|
419 else if(aElement == KCompDataParseNodeAttributeInfo) |
|
420 { |
|
421 return HandleSaxAttributeInfo(aElement, aAttribs); |
|
422 } |
|
423 |
|
424 return this; |
|
425 } |
|
426 |
|
427 |
|
428 void TMLCompDataParseLayoutLine::HandleSaxAttributes(const TAttribs& aAttribs) |
|
429 { |
|
430 // <Component |
|
431 // drawingorder="0" |
|
432 // id="1" |
|
433 // maxVariety="2" |
|
434 // mirror="true" |
|
435 // name="application_window" |
|
436 // type="Container"> |
|
437 |
|
438 iName = aAttribs.getValue(KCompDataParseNodeComponentAttributeName); |
|
439 |
|
440 string idStr = aAttribs.getValue(KCompDataParseNodeComponentAttributeId); |
|
441 iId = CdlTkUtil::ParseInt(idStr); |
|
442 |
|
443 if(iId == 0) |
|
444 { |
|
445 // this must be a dummy component, so have to fabricate a component id |
|
446 // TODO: ensure that layout data contains real component ids |
|
447 if(iName == "text_primary") |
|
448 iId = -1; |
|
449 else if(iName == "text_secondary") |
|
450 iId = -2; |
|
451 else if(iName == "text_title") |
|
452 iId = -3; |
|
453 else if(iName == "text_primary_small") |
|
454 iId = -4; |
|
455 } |
|
456 |
|
457 string typeStr = aAttribs.getValue(KCompDataParseNodeComponentAttributeType); |
|
458 if(typeStr == KCompDataParseTextComponentTypeScreen) |
|
459 { |
|
460 iType = EScreenComponent; |
|
461 } |
|
462 else if(typeStr == KCompDataParseTextComponentTypeContainer) |
|
463 { |
|
464 iType = EContainerComponent; |
|
465 } |
|
466 else if(typeStr == KCompDataParseTextComponentTypePane) |
|
467 { |
|
468 iType = EPaneComponent; |
|
469 } |
|
470 else if(typeStr == KCompDataParseTextComponentTypeGraphic) |
|
471 { |
|
472 iType = EGraphicComponent; |
|
473 } |
|
474 else if(typeStr == KCompDataParseTextComponentTypeText) |
|
475 { |
|
476 iType = ETextComponent; |
|
477 } |
|
478 else |
|
479 { |
|
480 iType = EUnknownComponent; |
|
481 } |
|
482 |
|
483 string drawingOrderStr = aAttribs.getValue(KCompDataParseNodeComponentAttributeDrawingOrder); |
|
484 iDrawingOrder = CdlTkUtil::ParseInt(drawingOrderStr); |
|
485 |
|
486 string mirroredStr = aAttribs.getValue(KCompDataParseNodeComponentAttributeMirror); |
|
487 iIsMirroredHorizontally = (mirroredStr == KCompDataParseTextComponentMirrorTrue); // will be false if empty, eg for a non-mirrored layout |
|
488 |
|
489 string maxVarietyStr = aAttribs.getValue(KCompDataParseNodeComponentAttributeMaxVariety); |
|
490 if(!maxVarietyStr.empty()) // screen doesn't have maxVariety for some reason |
|
491 { |
|
492 int maxVariety = CdlTkUtil::ParseInt(maxVarietyStr) - 2; |
|
493 // we ignore the maxVariety for now, as it will be calculated by parsing the values |
|
494 } |
|
495 } |
|
496 |
|
497 MSaxLayoutHandler* TMLCompDataParseLayoutLine::HandleSaxParent(const std::string& aElement, const TAttribs& aAttribs) |
|
498 { |
|
499 delete iSaxParentInfo; |
|
500 iSaxParentInfo = 0; |
|
501 iSaxParentInfo = new TMLCompDataParseParentInfo(this); |
|
502 return iSaxParentInfo; |
|
503 } |
|
504 |
|
505 MSaxLayoutHandler* TMLCompDataParseLayoutLine::HandleSaxParam(const std::string& /*aElement*/, const TAttribs& aAttribs) |
|
506 { |
|
507 delete iSaxValues; |
|
508 iSaxValues = 0; |
|
509 iSaxValues = new TMLCompDataParseValues(this); |
|
510 |
|
511 string nameStr = aAttribs.getValue(KCompDataParseNodeLayoutInfoParamAttributeName); |
|
512 iSaxValues->iName = ShortParamName(nameStr); |
|
513 |
|
514 return iSaxValues; |
|
515 } |
|
516 |
|
517 void TMLCompDataParseLayoutLine::HandleSaxEnd(const std::string& aElement) |
|
518 { |
|
519 if(aElement == KCompDataParseNodeParentInfo) |
|
520 { |
|
521 iParentInfo = iSaxParentInfo; |
|
522 iSaxParentInfo = 0; |
|
523 } |
|
524 else if(aElement == KCompDataParseNodeLayoutInfoParam) |
|
525 { |
|
526 insert(make_pair(iSaxValues->iName, *iSaxValues)); |
|
527 delete iSaxValues; |
|
528 iSaxValues = 0; |
|
529 } |
|
530 else if(aElement == KCompDataParseNodeAttributeInfo) |
|
531 { |
|
532 iAttributeInfo = iSaxAttributeInfo; |
|
533 iSaxAttributeInfo = 0; |
|
534 } |
|
535 } |
|
536 |
|
537 MSaxLayoutHandler* TMLCompDataParseLayoutLine::HandleSaxAttributeInfo(const std::string& aElement, const TAttribs& aAttribs) |
|
538 { |
|
539 delete iSaxAttributeInfo; |
|
540 iSaxAttributeInfo = 0; |
|
541 iSaxAttributeInfo = new TMLCompDataParseAttributeInfo(this); |
|
542 return iSaxAttributeInfo; |
|
543 } |
|
544 |
|
545 string TMLCompDataParseLayoutLine::ShortParamName(string& aName) |
|
546 { |
|
547 string shortName = aName; |
|
548 if(aName == KCompDataParseTextParamNameColor) |
|
549 shortName = KCompDataParseTextParamShortNameColor; |
|
550 else if(aName == KCompDataParseTextParamNameLeft) |
|
551 shortName = KCompDataParseTextParamShortNameLeft; |
|
552 else if(aName == KCompDataParseTextParamNameRight) |
|
553 shortName = KCompDataParseTextParamShortNameRight; |
|
554 else if(aName == KCompDataParseTextParamNameTop) |
|
555 shortName = KCompDataParseTextParamShortNameTop; |
|
556 else if(aName == KCompDataParseTextParamNameBottom) |
|
557 shortName = KCompDataParseTextParamShortNameBottom; |
|
558 else if(aName == KCompDataParseTextParamNameWidth) |
|
559 shortName = KCompDataParseTextParamShortNameWidth; |
|
560 else if(aName == KCompDataParseTextParamNameHeight) |
|
561 shortName = KCompDataParseTextParamShortNameHeight; |
|
562 else if(aName == KCompDataParseTextParamNameJustification) |
|
563 shortName = KCompDataParseTextParamShortNameJustification; |
|
564 else if(aName == KCompDataParseTextParamNameType) |
|
565 shortName = KCompDataParseTextParamShortNameType; |
|
566 return shortName; |
|
567 } |
|
568 |
|
569 |
|
570 // |
|
571 // TMLCompDataParseAttributeInfo |
|
572 // |
|
573 |
|
574 TMLCompDataParseAttributeInfo::TMLCompDataParseAttributeInfo(TMLCompDataLine* aLine) |
|
575 : |
|
576 iSaxAttributeInfoSelector(0), |
|
577 iSaxVariety(0) |
|
578 { |
|
579 |
|
580 } |
|
581 |
|
582 MSaxLayoutHandler* TMLCompDataParseAttributeInfo::HandleSax(const std::string& aElement, const TAttribs& aAttribs) |
|
583 { |
|
584 // <AttributeInfo> |
|
585 // <option variety="0"> |
|
586 // <attributeset name="a0"/> |
|
587 // </option> |
|
588 // <option variety="1"> |
|
589 // <attributeset name="a1"/> |
|
590 // </option> |
|
591 // </AttributeInfo> |
|
592 |
|
593 if (aElement == KCompDataParseNodeAttributeInfoOption) |
|
594 { |
|
595 delete iSaxAttributeInfoSelector; |
|
596 iSaxAttributeInfoSelector= 0; |
|
597 iSaxAttributeInfoSelector = new TMLCompDataAttributeInfoSelector; |
|
598 HandleSaxVariety(aElement, aAttribs); |
|
599 } |
|
600 else if (aElement == KCompDataParseNodeAttributeInfoAttributeSet) |
|
601 { |
|
602 HandleSaxAttributeSet(aElement, aAttribs); |
|
603 } |
|
604 |
|
605 return this; |
|
606 } |
|
607 |
|
608 void TMLCompDataParseAttributeInfo::HandleSaxEnd(const std::string& aElement) |
|
609 { |
|
610 if (aElement == KCompDataParseNodeAttributeInfoOption) // value |
|
611 { |
|
612 if(!iSaxAttributeInfoSelector->iAttributeSetName.empty()) |
|
613 { |
|
614 insert(make_pair(iSaxVariety, *iSaxAttributeInfoSelector)); |
|
615 } |
|
616 delete iSaxAttributeInfoSelector; |
|
617 iSaxAttributeInfoSelector = 0; |
|
618 } |
|
619 } |
|
620 |
|
621 void TMLCompDataParseAttributeInfo::HandleSaxVariety(const std::string& aElement, const TAttribs& aAttribs) |
|
622 { |
|
623 // <option variety="0"> |
|
624 string varietyIndexStr = aAttribs.getValue(KCompDataParseNodeParentOptionAttributeVariety); |
|
625 iSaxVariety = CdlTkUtil::ParseInt(varietyIndexStr); // defaults to zero |
|
626 } |
|
627 |
|
628 void TMLCompDataParseAttributeInfo::HandleSaxAttributeSet(const std::string& aElement, const TAttribs& aAttribs) |
|
629 { |
|
630 // <attributeset name="a0"/> |
|
631 string attributeSetNameStr = aAttribs.getValue(KCompDataParseNodeAttributeInfoAttributeSetAttributeName); |
|
632 iSaxAttributeInfoSelector->iAttributeSetName = attributeSetNameStr; |
|
633 } |
|
634 |
|
635 |
|
636 |
|
637 // |
|
638 // class TMLCompDataParseLayoutTable |
|
639 // |
|
640 |
|
641 TMLCompDataParseLayoutTable::TMLCompDataParseLayoutTable(TMLCompData* aTables) |
|
642 : TMLCompDataTable(aTables) |
|
643 { |
|
644 } |
|
645 |
|
646 MSaxLayoutHandler* TMLCompDataParseLayoutTable::HandleSax(const std::string& /*aElement*/, const TAttribs& /*aAttribs*/) |
|
647 { |
|
648 return this; |
|
649 } |
|
650 |
|
651 |
|
652 |
|
653 // |
|
654 // class TMLCompDataParseLayout |
|
655 // |
|
656 |
|
657 MSaxLayoutHandler* TMLCompDataParseLayout::HandleSax(const std::string& aElement, const TAttribs& aAttribs) |
|
658 { |
|
659 if (aElement == KCompDataParseRoot) |
|
660 { |
|
661 // <Layout MasterId="0.6821563014440754" |
|
662 // MasterName="m_p" LayoutSetId="1" |
|
663 // LayoutName="D_avkon_port" |
|
664 // VariantId="0.45128997192758025" |
|
665 // variant_name="eur" |
|
666 // variant_abbreviation="e" |
|
667 // ppi="100.0" |
|
668 // ppiUnit="Inches" |
|
669 // resolutionHeight="416" |
|
670 // resolutionWidth="352" |
|
671 // createdOn="2004-08-27 12:37:42.727"> |
|
672 iMasterName = aAttribs.getValue(KCompDataParseRootAttributeMasterName); |
|
673 iLayoutName = aAttribs.getValue(KCompDataParseRootAttributeLayoutName); |
|
674 iVariantName = aAttribs.getValue(KCompDataParseRootAttributeVariantName); |
|
675 iResolutionHeight = aAttribs.getValue(KCompDataParseRootAttributeResolutionHeight); |
|
676 iResolutionWidth = aAttribs.getValue(KCompDataParseRootAttributeResolutionWidth); |
|
677 iTimestamp = aAttribs.getValue(KCompDataParseRootAttributeCreatedOn); |
|
678 return this; |
|
679 } |
|
680 else if (aElement == KCompDataParseNodeComponent) |
|
681 { |
|
682 TMLCompDataParseLayoutLine* line = new TMLCompDataParseLayoutLine(); |
|
683 line->HandleSax(aElement, aAttribs); |
|
684 iComponents.insert(make_pair(line->iId, line)); |
|
685 return line; |
|
686 } |
|
687 else |
|
688 return this; |
|
689 } |
|
690 |
|
691 |
|
692 auto_ptr<TMLCompDataParseLayout> TMLCompDataParseLayout::Parse(const string& aLayName) |
|
693 { |
|
694 auto_ptr<TMLCompDataParseLayout> layout(new TMLCompDataParseLayout); |
|
695 int pos=0; |
|
696 string layName = aLayName; |
|
697 int next = layName.find('+', pos); |
|
698 if (next != string::npos) |
|
699 { |
|
700 throw GeneralErr(layName + " TMLCompDataParseLayout::Parse() - doesn't support multiple files"); |
|
701 } |
|
702 |
|
703 if (layName.size() >= 2 && layName.substr(0,2) == "-m") |
|
704 { |
|
705 layName = layName.substr(2); |
|
706 layout->iCanBeMirror = true; |
|
707 } |
|
708 layout->iName = layName; |
|
709 |
|
710 // SAX parsing method |
|
711 cout << "reading MLCompData(SAX) " << layName << endl; |
|
712 TLayoutSaxParser saxParser(layout.get()); |
|
713 saxParser.Parse(layName); |
|
714 |
|
715 return layout; |
|
716 } |
|
717 |
|
718 |
|
719 |
|
720 TLayoutSaxParser::TLayoutSaxParser(MSaxLayoutHandler* aHandler) |
|
721 { |
|
722 iStack.push(aHandler); |
|
723 } |
|
724 |
|
725 void TLayoutSaxParser::Parse(const std::string& aFileName) |
|
726 { |
|
727 SAX::basic_InputSource<std::string> is(aFileName); |
|
728 SAX::XMLReader<std::string> parser; |
|
729 parser.setContentHandler(*this); |
|
730 parser.setErrorHandler(*this); |
|
731 parser.parse(is); |
|
732 } |
|
733 |
|
734 void TLayoutSaxParser::startElement(const std::string& /*namespaceURI*/, const std::string& localName, |
|
735 const std::string& /*qName*/, const SAX::basic_Attributes<std::string>& atts) |
|
736 { |
|
737 MSaxLayoutHandler* handler = iStack.top(); |
|
738 if (!handler) |
|
739 throw GeneralErr("SAX: No element handler"); |
|
740 MSaxLayoutHandler* next = handler->HandleSax(localName, atts); |
|
741 iStack.push(next); |
|
742 } |
|
743 |
|
744 void TLayoutSaxParser::endElement(const std::string& /*namespaceURI*/, const std::string& localName, |
|
745 const std::string& /*qName*/) |
|
746 { |
|
747 iStack.pop(); |
|
748 MSaxLayoutHandler* handler = iStack.top(); |
|
749 if (handler) |
|
750 handler->HandleSaxEnd(localName); |
|
751 } |
|
752 |
|
753 |
|
754 void TLayoutSaxParser::warning(const TException& aException) |
|
755 { |
|
756 cerr << aException.what(); |
|
757 } |
|
758 |
|
759 void TLayoutSaxParser::error(const TException& aException) |
|
760 { |
|
761 cerr << aException.what(); |
|
762 } |
|
763 |
|
764 void TLayoutSaxParser::fatalError(const TException& aException) |
|
765 { |
|
766 cerr << aException.what(); |
|
767 } |
|
768 |
|
769 |
|
770 // End of File |