|
1 /* |
|
2 * Copyright (c) 2005 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 |
|
21 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
22 #pragma warning(disable: 4786 4250 4503 4541) |
|
23 |
|
24 |
|
25 #include "MLAttributesParse.h" |
|
26 #include "MLCompDataParse.h" // for converting zoom strings |
|
27 |
|
28 #include <akndef.hrh> // for logical font ids |
|
29 |
|
30 #include <sstream> |
|
31 #include <fstream> |
|
32 #include <algorithm> |
|
33 #include <iostream> // !!! for debug output only |
|
34 |
|
35 extern string whiteSpace; |
|
36 |
|
37 |
|
38 // const data |
|
39 // |
|
40 |
|
41 const string KAttributesParseRoot = "LayoutAttributes"; |
|
42 const string KAttributesParseRootAttributeCreatedOn = "createdOn"; |
|
43 |
|
44 const string KAttributesParseNodeAttributeSet = "attributeset"; |
|
45 const string KAttributesParseNodeAttributeSetAttributeId = "compId"; |
|
46 const string KAttributesParseNodeAttributeSetAttributeName = "name"; |
|
47 |
|
48 const string KAttributesParseNodeAttribute = "attribute"; |
|
49 const string KAttributesParseNodeAttributeAttributeId = "id"; |
|
50 const string KAttributesParseNodeAttributeAttributeName = "name"; |
|
51 |
|
52 const string KAttributesParseNodeCalc = "calc"; |
|
53 const string KAttributesParseNodeCalcAttributeValue = "value"; |
|
54 const string KAttributesParseNodeCalcAttributeZoom = "zoom"; |
|
55 |
|
56 |
|
57 // |
|
58 // class TMLAttributeSetParse |
|
59 // |
|
60 TMLAttributeSetParse::TMLAttributeSetParse(TMLAttributes* aAttributes) |
|
61 : |
|
62 TMLAttributeSet(aAttributes), |
|
63 iSaxZoomLevels(0) |
|
64 { |
|
65 |
|
66 } |
|
67 |
|
68 MSaxLayoutAttributesHandler* TMLAttributeSetParse::HandleSax(const std::string& aElement, const TAttribs& aAttribs) |
|
69 { |
|
70 // <attributeset compId="1" name="a0"> |
|
71 if (aElement == KAttributesParseNodeAttributeSet) |
|
72 { |
|
73 iCompId = CdlTkUtil::ParseInt(aAttribs.getValue(KAttributesParseNodeAttributeSetAttributeId)); |
|
74 iName = aAttribs.getValue(KAttributesParseNodeAttributeSetAttributeName); |
|
75 } |
|
76 else if(aElement == KAttributesParseNodeAttribute) |
|
77 { |
|
78 HandleSaxAttribute(aAttribs); |
|
79 } |
|
80 else if(aElement == KAttributesParseNodeCalc) |
|
81 { |
|
82 HandleSaxCalc(aAttribs); |
|
83 } |
|
84 return this; |
|
85 } |
|
86 |
|
87 void TMLAttributeSetParse::HandleSaxEnd(const std::string& aElement) |
|
88 { |
|
89 if (aElement == KAttributesParseNodeAttribute) |
|
90 { |
|
91 insert(make_pair(iId, *iSaxZoomLevels)); |
|
92 delete iSaxZoomLevels; |
|
93 iSaxZoomLevels = 0; |
|
94 } |
|
95 } |
|
96 |
|
97 void TMLAttributeSetParse::HandleSaxAttribute(const TAttribs& aAttribs) |
|
98 { |
|
99 delete iSaxZoomLevels; |
|
100 iSaxZoomLevels = 0; |
|
101 iSaxZoomLevels = new TMLAttributeZoomLevels; |
|
102 |
|
103 // <attribute id="8" name="style 1"> |
|
104 iId = CdlTkUtil::ParseInt(aAttribs.getValue(KAttributesParseNodeAttributeAttributeId)); |
|
105 string attributeName = CdlTkUtil::ToCpp(aAttribs.getValue(KAttributesParseNodeAttributeAttributeName)); |
|
106 iAttributes->iNames.insert(make_pair(attributeName, iId)); |
|
107 } |
|
108 |
|
109 void TMLAttributeSetParse::HandleSaxCalc(const TAttribs& aAttribs) |
|
110 { |
|
111 // <calc value="32"/> |
|
112 // <calc value="28" zoom="-2 zoom"/> |
|
113 // <calc value="38" zoom="+2 zoom"/> |
|
114 // <calc value="30" zoom="-1 zoom"/> |
|
115 // <calc value="36" zoom="+1 zoom"/> |
|
116 |
|
117 string zoomStr = aAttribs.getValue(KAttributesParseNodeCalcAttributeZoom); |
|
118 int zoom = TMLCompDataParseValues::ConvertZoomStr(zoomStr); |
|
119 if(zoom != EAknUiZoomAutomatic) |
|
120 { |
|
121 string& calc = (*iSaxZoomLevels)[zoom]; |
|
122 calc = aAttribs.getValue(KAttributesParseNodeCalcAttributeValue); |
|
123 } |
|
124 } |
|
125 |
|
126 int TMLAttributeSetParse::CompId() const |
|
127 { |
|
128 return iCompId; |
|
129 } |
|
130 |
|
131 string TMLAttributeSetParse::Name() const |
|
132 { |
|
133 return iName; |
|
134 } |
|
135 |
|
136 |
|
137 // |
|
138 // class TMLAttributesParse |
|
139 // |
|
140 auto_ptr<TMLAttributesParse> TMLAttributesParse::Parse(const string& aLayName) |
|
141 { |
|
142 auto_ptr<TMLAttributesParse> layout(new TMLAttributesParse); |
|
143 int pos=0; |
|
144 string layName = aLayName; |
|
145 |
|
146 if (layName.size() >= 2 && layName.substr(0,2) == "-m") |
|
147 { |
|
148 layName = layName.substr(2); |
|
149 layout->iCanBeMirror = true; |
|
150 } |
|
151 layout->iName = layName; |
|
152 |
|
153 // SAX parsing method |
|
154 cout << "reading MLAttributes(SAX) " << layName << endl; |
|
155 TLayoutAttributesSaxParser saxParser(layout.get()); |
|
156 saxParser.Parse(layName); |
|
157 |
|
158 return layout; |
|
159 } |
|
160 |
|
161 TMLAttributesParse::TMLAttributesParse() |
|
162 : |
|
163 iSaxAttributeSet(0) |
|
164 { |
|
165 |
|
166 } |
|
167 |
|
168 MSaxLayoutAttributesHandler* TMLAttributesParse::HandleSax(const std::string& aElement, const TAttribs& aAttribs) |
|
169 { |
|
170 if (aElement == KAttributesParseRoot) |
|
171 { |
|
172 // <LayoutAttributes |
|
173 // createdOn="2005-05-20 00:55:40.185" |
|
174 // LayoutToolVer="2005-05-12 04:10 PM" |
|
175 // MasterId="0.6921563014440754"> |
|
176 iTimestamp = aAttribs.getValue(KAttributesParseRootAttributeCreatedOn); |
|
177 return this; |
|
178 } |
|
179 else if (aElement == KAttributesParseNodeAttributeSet) |
|
180 { |
|
181 delete iSaxAttributeSet; |
|
182 iSaxAttributeSet = 0; |
|
183 iSaxAttributeSet = new TMLAttributeSetParse(this); |
|
184 iSaxAttributeSet->HandleSax(aElement, aAttribs); |
|
185 return iSaxAttributeSet; |
|
186 } |
|
187 else |
|
188 return this; |
|
189 } |
|
190 |
|
191 void TMLAttributesParse::HandleSaxEnd(const std::string& aElement) |
|
192 { |
|
193 if (aElement == KAttributesParseNodeAttributeSet) |
|
194 { |
|
195 TMLAttributeSetComponent& component = (*this)[iSaxAttributeSet->CompId()]; |
|
196 component.insert(make_pair(iSaxAttributeSet->Name(), iSaxAttributeSet)); |
|
197 iSaxAttributeSet = 0; |
|
198 } |
|
199 } |
|
200 |
|
201 |
|
202 // |
|
203 // TLayoutAttributesSaxParser |
|
204 // |
|
205 |
|
206 TLayoutAttributesSaxParser::TLayoutAttributesSaxParser(MSaxLayoutAttributesHandler* aHandler) |
|
207 { |
|
208 iStack.push(aHandler); |
|
209 } |
|
210 |
|
211 void TLayoutAttributesSaxParser::Parse(const std::string& aFileName) |
|
212 { |
|
213 SAX::basic_InputSource<std::string> is(aFileName); |
|
214 SAX::XMLReader<std::string> parser; |
|
215 parser.setContentHandler(*this); |
|
216 parser.setErrorHandler(*this); |
|
217 parser.parse(is); |
|
218 } |
|
219 |
|
220 void TLayoutAttributesSaxParser::startElement(const std::string& /*namespaceURI*/, const std::string& localName, |
|
221 const std::string& /*qName*/, const SAX::basic_Attributes<std::string>& atts) |
|
222 { |
|
223 MSaxLayoutAttributesHandler* handler = iStack.top(); |
|
224 if (!handler) |
|
225 throw GeneralErr("SAX: No element handler"); |
|
226 MSaxLayoutAttributesHandler* next = handler->HandleSax(localName, atts); |
|
227 iStack.push(next); |
|
228 } |
|
229 |
|
230 void TLayoutAttributesSaxParser::endElement(const std::string& /*namespaceURI*/, const std::string& localName, |
|
231 const std::string& /*qName*/) |
|
232 { |
|
233 iStack.pop(); |
|
234 MSaxLayoutAttributesHandler* handler = iStack.top(); |
|
235 if (handler) |
|
236 handler->HandleSaxEnd(localName); |
|
237 } |
|
238 |
|
239 |
|
240 void TLayoutAttributesSaxParser::warning(const TException& aException) |
|
241 { |
|
242 cerr << aException.what(); |
|
243 } |
|
244 |
|
245 void TLayoutAttributesSaxParser::error(const TException& aException) |
|
246 { |
|
247 cerr << aException.what(); |
|
248 } |
|
249 |
|
250 void TLayoutAttributesSaxParser::fatalError(const TException& aException) |
|
251 { |
|
252 cerr << aException.what(); |
|
253 } |
|
254 |
|
255 |
|
256 |
|
257 // End of File |