|
1 /* |
|
2 * Copyright (c) 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: CNcdConfigurationParser implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdprotocolutils.h" |
|
20 #include "ncdconfigurationparser.h" |
|
21 #include "ncdparserobserver.h" |
|
22 #include "catalogsdebug.h" |
|
23 #include "ncdprotocolutils.h" |
|
24 |
|
25 _LIT8( KXmlType, "text/xml" ); |
|
26 |
|
27 |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CNcdConfigurationParser* CNcdConfigurationParser::NewL( |
|
34 MNcdConfigurationParserObserver& aObserver ) |
|
35 { |
|
36 CNcdConfigurationParser* self = CNcdConfigurationParser::NewLC( |
|
37 aObserver ); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CNcdConfigurationParser* CNcdConfigurationParser::NewLC( |
|
48 MNcdConfigurationParserObserver& aObserver ) |
|
49 { |
|
50 CNcdConfigurationParser* self = new(ELeave) CNcdConfigurationParser( |
|
51 aObserver ); |
|
52 CleanupStack::PushL( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CNcdConfigurationParser::CNcdConfigurationParser( |
|
62 MNcdConfigurationParserObserver& aObserver ) |
|
63 : iObserver( aObserver ) |
|
64 { |
|
65 } |
|
66 |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CNcdConfigurationParser::~CNcdConfigurationParser() |
|
73 { |
|
74 delete iXmlParser; |
|
75 iXmlParser = NULL; |
|
76 } |
|
77 |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CNcdConfigurationParser::ParseL( const TDesC16& aData ) |
|
84 { |
|
85 DLTRACEIN(("16-bit parse, length=%d",aData.Length())); |
|
86 HBufC8* utf8 = NcdProtocolUtils::ConvertUnicodeToUtf8L( aData ); |
|
87 CleanupStack::PushL( utf8 ); |
|
88 ParseL( *utf8 ); |
|
89 CleanupStack::PopAndDestroy( utf8 ); |
|
90 |
|
91 } |
|
92 |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CNcdConfigurationParser::ParseL( const TDesC8& aData ) |
|
99 { |
|
100 DLTRACEIN(("")); |
|
101 iXmlParser = Xml::CParser::NewL( KXmlType, *this ); |
|
102 iXmlParser->ParseBeginL(); |
|
103 |
|
104 iXmlParser->ParseL( aData ); |
|
105 iXmlParser->ParseEndL(); |
|
106 |
|
107 } |
|
108 |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 void CNcdConfigurationParser::OnStartDocumentL( |
|
115 const Xml::RDocumentParameters& /*aDocParam*/, TInt aErrorCode) |
|
116 { |
|
117 DLTRACE(("error=%d",aErrorCode)); |
|
118 (void) aErrorCode; // suppresses compiler warning |
|
119 // iDocParam.Open( aDocParam.CharacterSetName() ); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CNcdConfigurationParser::OnEndDocumentL(TInt /*aErrorCode*/) |
|
127 { |
|
128 // DLTRACE(("tag=%S error=%d",iTag,aErrorCode)); |
|
129 // iDocParam.Close(); |
|
130 } |
|
131 |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 void CNcdConfigurationParser::OnStartElementL( |
|
138 const Xml::RTagInfo& aElement, |
|
139 const Xml::RAttributeArray& aAttributes, |
|
140 TInt aErrorCode ) |
|
141 { |
|
142 DLTRACE(("Start tag: %S, error=%d", |
|
143 &aElement.LocalName().DesC(), aErrorCode )); |
|
144 (void) aErrorCode; // suppresses compiler warning |
|
145 |
|
146 iObserver.ConfigurationElementStartL( aElement.LocalName().DesC() ); |
|
147 |
|
148 DLTRACE(("Handling %d attributes", aAttributes.Count() )); |
|
149 for ( TInt i = 0; i < aAttributes.Count(); ++i ) |
|
150 { |
|
151 iObserver.ConfigurationAttributeL( aElement.LocalName().DesC(), |
|
152 aAttributes[i].Attribute().LocalName().DesC(), |
|
153 aAttributes[i].Value().DesC() ); |
|
154 } |
|
155 |
|
156 delete iBuffer; |
|
157 iBuffer = NULL; |
|
158 } |
|
159 |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CNcdConfigurationParser::OnEndElementL( |
|
166 const Xml::RTagInfo& aElement, |
|
167 TInt /* aErrorCode */ ) |
|
168 { |
|
169 DLTRACEIN(("")); |
|
170 if ( iBuffer ) |
|
171 { |
|
172 DLTRACE(("Handling element data")); |
|
173 iObserver.ConfigurationElementEndL( aElement.LocalName().DesC(), |
|
174 *iBuffer ); |
|
175 delete iBuffer; |
|
176 iBuffer = NULL; |
|
177 } |
|
178 else |
|
179 { |
|
180 DLTRACE(("Handling empty element data")); |
|
181 iObserver.ConfigurationElementEndL( aElement.LocalName().DesC(), |
|
182 KNullDesC8 ); |
|
183 |
|
184 } |
|
185 } |
|
186 |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 void CNcdConfigurationParser::OnContentL( |
|
193 const TDesC8& aBytes, |
|
194 TInt /*aErrorCode*/ ) |
|
195 { |
|
196 DLTRACEIN(( "content size=%d",aBytes.Length() )); |
|
197 // if( aBytes.Length() < 1000 ) |
|
198 // { |
|
199 // DLINFODUMP(aBytes.Ptr(),aBytes.Length(),1024) ; |
|
200 // DLINFO(("data=%S",&aBytes)); |
|
201 // } |
|
202 if ( iBuffer ) |
|
203 { |
|
204 TInt oldLength = iBuffer->Length(); |
|
205 iBuffer = iBuffer->ReAllocL( oldLength + aBytes.Length() ); |
|
206 } |
|
207 else |
|
208 { |
|
209 iBuffer = HBufC8::NewL( aBytes.Length() ); |
|
210 } |
|
211 |
|
212 iBuffer->Des().Append( aBytes ); |
|
213 DLTRACEOUT(( "buffer=%X size=%d", this, iBuffer->Length() )); |
|
214 } |
|
215 |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CNcdConfigurationParser::OnStartPrefixMappingL( |
|
222 const RString& /*aPrefix*/, const RString& /*aUri*/, |
|
223 TInt aErrorCode ) |
|
224 { |
|
225 DLTRACE(("error=%d",aErrorCode)); |
|
226 (void) aErrorCode; // suppresses compiler warning |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 void CNcdConfigurationParser::OnEndPrefixMappingL( |
|
234 const RString& /*aPrefix*/, TInt aErrorCode ) |
|
235 { |
|
236 DLTRACE(("error=%d",aErrorCode)); |
|
237 (void) aErrorCode; // suppresses compiler warning |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CNcdConfigurationParser::OnIgnorableWhiteSpaceL( |
|
245 const TDesC8& /*aBytes*/, TInt aErrorCode ) |
|
246 { |
|
247 DLTRACE(("error=%d",aErrorCode)); |
|
248 (void) aErrorCode; // suppresses compiler warning |
|
249 } |
|
250 |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 void CNcdConfigurationParser::OnSkippedEntityL( |
|
257 const RString& /*aName*/, TInt aErrorCode ) |
|
258 { |
|
259 DLTRACE(("error=%d",aErrorCode)); |
|
260 (void) aErrorCode; // suppresses compiler warning |
|
261 } |
|
262 |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 void CNcdConfigurationParser::OnProcessingInstructionL( |
|
269 const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt aErrorCode ) |
|
270 { |
|
271 DLTRACE(("error=%d",aErrorCode)); |
|
272 (void) aErrorCode; // suppresses compiler warning |
|
273 } |
|
274 |
|
275 |
|
276 // When the CParser gives OnError(), it will not continue even if further |
|
277 // data is fed to it. |
|
278 void CNcdConfigurationParser::OnError(TInt aErrorCode) |
|
279 { |
|
280 DLTRACE(("error=%d",aErrorCode)); |
|
281 iObserver.ConfigurationError( aErrorCode ); |
|
282 } |
|
283 |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 TAny* CNcdConfigurationParser::GetExtendedInterface(const TInt32 /*aUid*/) |
|
290 { |
|
291 DLTRACE(("")); |
|
292 return 0; |
|
293 } |