|
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: CNcdPreminetProtocolResponseParser implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdprotocolwords.h" |
|
20 #include "ncdunknownparser.h" |
|
21 #include "ncdparserobserver.h" |
|
22 #include "ncdprotocolutils.h" |
|
23 #include "ncd_parser_pp_response.h" |
|
24 #include "ncd_parser_pp_entityref.h" |
|
25 #include "ncd_parser_pp_embeddeddata.h" |
|
26 #include "ncd_parser_pp_purchase.h" |
|
27 #include "ncd_parser_pp_subscriptionreport.h" |
|
28 #include "ncd_parser_pp_information.h" |
|
29 #include "ncd_parser_cp_error.h" |
|
30 #include "ncdprotocolutils.h" |
|
31 #include "ncd_pp_folderref.h" |
|
32 #include "ncd_pp_itemref.h" |
|
33 #include "ncd_pp_informationimpl.h" |
|
34 #include "catalogsdebug.h" |
|
35 |
|
36 |
|
37 CNcdPreminetProtocolResponseParser* CNcdPreminetProtocolResponseParser::NewL( |
|
38 MNcdParserObserverBundle& aObservers, |
|
39 MNcdSubParserObserver& aSubParserObserver, |
|
40 TInt aDepth, |
|
41 const Xml::RTagInfo& aElement, |
|
42 const Xml::RAttributeArray& aAttributes ) |
|
43 { |
|
44 CNcdPreminetProtocolResponseParser* self |
|
45 = new(ELeave) CNcdPreminetProtocolResponseParser( |
|
46 aObservers, aSubParserObserver, aDepth ); |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL( aElement, aAttributes ); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 CNcdPreminetProtocolResponseParser::CNcdPreminetProtocolResponseParser( |
|
54 MNcdParserObserverBundle& aObservers, |
|
55 MNcdSubParserObserver& aSubParserObserver, |
|
56 TInt aDepth ) |
|
57 : CNcdSubParser( aObservers, aSubParserObserver, aDepth ) |
|
58 { |
|
59 |
|
60 } |
|
61 |
|
62 CNcdPreminetProtocolResponseParser::~CNcdPreminetProtocolResponseParser() |
|
63 { |
|
64 delete iResponseNamespace; |
|
65 } |
|
66 |
|
67 |
|
68 void CNcdPreminetProtocolResponseParser::ConstructL( |
|
69 const Xml::RTagInfo& aElement, |
|
70 const Xml::RAttributeArray& aAttributes ) |
|
71 { |
|
72 DLTRACEIN(("")); |
|
73 CNcdSubParser::ConstructL( aElement ); |
|
74 |
|
75 // handle attributes |
|
76 TPtrC8 responseNamespace = AttributeValue( KAttrNamespace, aAttributes ); |
|
77 NcdProtocolUtils::AssignDesL( iResponseNamespace, responseNamespace ); |
|
78 |
|
79 DLINFO(("namespace=%S",&responseNamespace)); |
|
80 TPtrC8 id = AttributeValue( KAttrId, aAttributes ); |
|
81 DLINFO(("id=%S",&id)); |
|
82 TPtrC8 version = AttributeValue( KAttrVersion, aAttributes ); |
|
83 DLINFO(("version=%S",&version)); |
|
84 |
|
85 TPtrC8 session = AttributeValue( KAttrSession, aAttributes ); |
|
86 if( session != KNullDesC8 ) |
|
87 { |
|
88 if( iObservers->SessionObserver() ) |
|
89 { |
|
90 HBufC* data = NcdProtocolUtils::ConvertUtf8ToUnicodeLC( session ); |
|
91 iObservers->SessionObserver()->SessionL( |
|
92 *data, iObservers->SessionOrigin(), *iResponseNamespace ); |
|
93 CleanupStack::PopAndDestroy( data ); |
|
94 } |
|
95 } |
|
96 |
|
97 } |
|
98 |
|
99 |
|
100 void CNcdPreminetProtocolResponseParser::OnStartElementL( |
|
101 const Xml::RTagInfo& aElement, |
|
102 const Xml::RAttributeArray& aAttributes, |
|
103 TInt aErrorCode) |
|
104 { |
|
105 |
|
106 TPtrC8 tag( aElement.LocalName().DesC() ); |
|
107 |
|
108 if( iSubParser == 0 ) |
|
109 { |
|
110 DLTRACEIN(("preminet start tag=%S error=%d depth=%d",&aElement.LocalName().DesC(),aErrorCode,iDepth)); |
|
111 if( tag == KTagEntity ) |
|
112 { |
|
113 iSubParser = CNcdPreminetProtocolEntityRefParser::NewL( |
|
114 *iObservers, *this, iDepth+1, aElement, aAttributes, |
|
115 KNullDesC /*no parent id*/, *iResponseNamespace ); |
|
116 } |
|
117 else if( tag == KTagEmbeddedData ) |
|
118 { |
|
119 iSubParser = CNcdPreminetProtocolEmbeddedDataParser::NewL( |
|
120 *iObservers, *this, iDepth+1, aElement, aAttributes, |
|
121 *iResponseNamespace ); |
|
122 // no handling needed in SubParserFinishedL |
|
123 } |
|
124 else if( tag == KTagPurchase ) |
|
125 { |
|
126 iSubParser = CNcdPreminetProtocolPurchaseParser::NewL( |
|
127 *iObservers, *this, iDepth+1, aElement, aAttributes, |
|
128 KNullDesC /*no parent id*/ ); |
|
129 // no handling needed in SubParserFinishedL |
|
130 } |
|
131 else if( tag == KTagSubscriptionReport ) |
|
132 { |
|
133 iSubParser = CNcdPreminetProtocolSubscriptionReportParser::NewL( |
|
134 *iObservers, *this, iDepth+1, aElement, aAttributes, |
|
135 KNullDesC /*no parent id*/, *iResponseNamespace ); |
|
136 // no handling needed in SubParserFinishedL |
|
137 } |
|
138 else if( tag == KTagInformation ) |
|
139 { |
|
140 iSubParser = CNcdPreminetProtocolInformationParser::NewL( |
|
141 *iObservers, *this, iDepth+1, aElement, aAttributes ); |
|
142 } |
|
143 else if( tag == KTagError ) |
|
144 { |
|
145 iSubParser = CNcdConfigurationProtocolErrorParser::NewL( |
|
146 *iObservers, *this, iDepth+1, aElement, aAttributes ); |
|
147 } |
|
148 else |
|
149 { |
|
150 iSubParser = CNcdUnknownParser::NewL( |
|
151 *iObservers, *this, iDepth+1, aElement, aAttributes ); |
|
152 } |
|
153 } |
|
154 else |
|
155 { |
|
156 iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode ); |
|
157 } |
|
158 } |
|
159 |
|
160 |
|
161 |
|
162 void CNcdPreminetProtocolResponseParser::OnEndElementL( |
|
163 const Xml::RTagInfo& aElement, TInt aErrorCode) |
|
164 { |
|
165 DLTRACEIN(("")); |
|
166 if( iSubParser == 0 && iTag && *iTag == aElement.LocalName().DesC() ) |
|
167 { |
|
168 DLTRACE(("end tag=%S",&aElement.LocalName().DesC())); |
|
169 iSubParserObserver->SubParserFinishedL( |
|
170 aElement.LocalName().DesC(), aErrorCode ); |
|
171 } |
|
172 else if( iSubParser ) |
|
173 { |
|
174 iSubParser->OnEndElementL( aElement, aErrorCode ); |
|
175 } |
|
176 else |
|
177 { |
|
178 DLWARNING(("end tag ignored, tag=%S",&aElement.LocalName().DesC())); |
|
179 } |
|
180 } |
|
181 |
|
182 |
|
183 void CNcdPreminetProtocolResponseParser::OnContentL( |
|
184 const TDesC8& aBytes, TInt aErrorCode) |
|
185 { |
|
186 DLTRACEIN(("")); |
|
187 if( iSubParser ) |
|
188 { |
|
189 iSubParser->OnContentL( aBytes, aErrorCode ); |
|
190 } |
|
191 } |
|
192 |
|
193 void CNcdPreminetProtocolResponseParser::SubParserFinishedL( |
|
194 const TDesC8& aTag, TInt /*aErrorCode*/ ) |
|
195 { |
|
196 DLTRACEIN(("tag=%S subparser=%X",&aTag,iSubParser)); |
|
197 |
|
198 if( iSubParser->Type() == EParserEntityRef && |
|
199 iObservers->EntityObserver() && |
|
200 aTag == KTagEntity ) |
|
201 { |
|
202 MNcdPreminetProtocolItemRef* itemRef = |
|
203 static_cast<CNcdPreminetProtocolEntityRefParser*> |
|
204 ( iSubParser )->ItemRef(); |
|
205 MNcdPreminetProtocolFolderRef* folderRef = |
|
206 static_cast<CNcdPreminetProtocolEntityRefParser*> |
|
207 ( iSubParser )->FolderRef(); |
|
208 DLINFO(("subparser itemref=%X folderref=%X",itemRef,folderRef)); |
|
209 if( itemRef ) |
|
210 { |
|
211 iObservers->EntityObserver()->ItemRefL( itemRef ); |
|
212 } |
|
213 if( folderRef ) |
|
214 { |
|
215 DLINFO((_L("folder id=%S"),&folderRef->Id())); |
|
216 iObservers->EntityObserver()->FolderRefL( folderRef ); |
|
217 } |
|
218 } |
|
219 else if( aTag == KTagInformation ) |
|
220 { |
|
221 MNcdParserInformationObserver* observer = iObservers->InformationObserver(); |
|
222 |
|
223 if( observer ) |
|
224 { |
|
225 MNcdPreminetProtocolInformation* information = |
|
226 static_cast<CNcdPreminetProtocolInformationParser*>( iSubParser )->Information(); |
|
227 CNcdPreminetProtocolInformationImpl* info = |
|
228 static_cast<CNcdPreminetProtocolInformationImpl*>(information); |
|
229 NcdProtocolUtils::AssignDesL( info->iNamespace, *iResponseNamespace ); |
|
230 observer->InformationL( information ); |
|
231 } |
|
232 } |
|
233 |
|
234 else if( aTag == KTagError ) |
|
235 { |
|
236 MNcdParserErrorObserver* observer = iObservers->ErrorObserver(); |
|
237 |
|
238 if( observer ) |
|
239 { |
|
240 MNcdPreminetProtocolError* error = |
|
241 static_cast<CNcdConfigurationProtocolErrorParser*>( iSubParser )->PreminetProtocolError(); |
|
242 observer->ErrorL( error ); |
|
243 } |
|
244 } |
|
245 |
|
246 delete iSubParser; |
|
247 iSubParser = 0; |
|
248 } |