|
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: CNcdEntityRefParser implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncd_parser_pp_purchaseoption.h" |
|
20 #include "ncd_parser_pp_download.h" |
|
21 #include "ncd_pp_purchaseoptionimpl.h" |
|
22 #include "ncd_pp_subscriptiondetailsimpl.h" |
|
23 #include "ncd_pp_download.h" |
|
24 #include "ncdparserobserverbundleimpl.h" |
|
25 #include "ncdunknownparser.h" |
|
26 #include "ncdprotocolwords.h" |
|
27 #include "ncdprotocolutils.h" |
|
28 #include "ncdprotocoltypes.h" |
|
29 |
|
30 #include "catalogsdebug.h" |
|
31 |
|
32 |
|
33 CNcdPreminetProtocolPurchaseOptionParser* |
|
34 CNcdPreminetProtocolPurchaseOptionParser::NewL( |
|
35 MNcdParserObserverBundle& aObservers, |
|
36 MNcdSubParserObserver& aSubParserObserver, |
|
37 TInt aDepth, |
|
38 const Xml::RTagInfo& aElement, |
|
39 const Xml::RAttributeArray& aAttributes, |
|
40 const TDesC& aParentId ) |
|
41 { |
|
42 CNcdPreminetProtocolPurchaseOptionParser* self |
|
43 = new(ELeave) CNcdPreminetProtocolPurchaseOptionParser( |
|
44 aObservers, aSubParserObserver, aDepth ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL( aElement, aAttributes, aParentId ); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CNcdPreminetProtocolPurchaseOptionParser::CNcdPreminetProtocolPurchaseOptionParser( |
|
52 MNcdParserObserverBundle& aObservers, |
|
53 MNcdSubParserObserver& aSubParserObserver, |
|
54 TInt aDepth ) |
|
55 : CNcdSubParser( aObservers, aSubParserObserver, aDepth ) |
|
56 { |
|
57 |
|
58 } |
|
59 |
|
60 CNcdPreminetProtocolPurchaseOptionParser::~CNcdPreminetProtocolPurchaseOptionParser() |
|
61 { |
|
62 delete iPurchaseOption; |
|
63 } |
|
64 |
|
65 void CNcdPreminetProtocolPurchaseOptionParser::ConstructL( |
|
66 const Xml::RTagInfo& aElement, |
|
67 const Xml::RAttributeArray& aAttributes, |
|
68 const TDesC& /*aParentId*/ ) |
|
69 { |
|
70 CNcdSubParser::ConstructL( aElement ); |
|
71 |
|
72 DLTRACEIN(("depth=%d tag=%S",iDepth,iTag)); |
|
73 //DLINFO((_L("parent=%S"),&aParentId)); |
|
74 |
|
75 if (!iPurchaseOption) |
|
76 { |
|
77 iPurchaseOption = CNcdPreminetProtocolPurchaseOptionImpl::NewL(); |
|
78 } |
|
79 |
|
80 // read attributes here |
|
81 TPtrC8 id = AttributeValue( KAttrId, aAttributes ); |
|
82 TPtrC8 dependencyId = AttributeValue( KAttrDependencyId, aAttributes ); |
|
83 TPtrC8 name = AttributeValue( KAttrName, aAttributes ); |
|
84 TPtrC8 free = AttributeValue( KAttrFree, aAttributes ); |
|
85 TPtrC8 canBeGift = AttributeValue( KAttrCanBeGift, aAttributes ); |
|
86 TPtrC8 requirePurchaseProcess = |
|
87 AttributeValue( KAttrRequirePurchaseProcess, aAttributes ); |
|
88 |
|
89 NcdProtocolUtils::AssignDesL(iPurchaseOption->iId, id); |
|
90 NcdProtocolUtils::AssignDesL(iPurchaseOption->iDependencyId, dependencyId); |
|
91 NcdProtocolUtils::AssignDesL(iPurchaseOption->iName, name); |
|
92 NcdProtocolUtils::DesToBool(iPurchaseOption->iFree, free); |
|
93 NcdProtocolUtils::DesToBool(iPurchaseOption->iCanBeGift, canBeGift); |
|
94 NcdProtocolUtils::DesToBool(iPurchaseOption->iRequirePurchaseProcess, |
|
95 requirePurchaseProcess); |
|
96 |
|
97 TPtrC8 purchase = AttributeValue( KAttrPurchase, aAttributes ); |
|
98 if ( purchase == KValueContent ) |
|
99 { |
|
100 iPurchaseOption->iPurchase = EContent; |
|
101 } |
|
102 else if ( purchase == KValueSubscription ) |
|
103 { |
|
104 iPurchaseOption->iPurchase = ESubscription; |
|
105 } |
|
106 else if ( purchase == KValuePartOfSubscription ) |
|
107 { |
|
108 iPurchaseOption->iPurchase = EPartOfSubscription; |
|
109 } |
|
110 else if ( purchase == KValueUpgrade ) |
|
111 { |
|
112 iPurchaseOption->iPurchase = EUpgrade; |
|
113 } |
|
114 else |
|
115 { |
|
116 iPurchaseOption->iPurchase = ETypeNotSet; |
|
117 } |
|
118 |
|
119 //NcdProtocolUtils::AssignEmptyDesL(iParentTag); |
|
120 } |
|
121 |
|
122 |
|
123 void CNcdPreminetProtocolPurchaseOptionParser::OnStartElementL( |
|
124 const Xml::RTagInfo& aElement, |
|
125 const Xml::RAttributeArray& aAttributes, |
|
126 TInt aErrorCode) |
|
127 { |
|
128 CNcdSubParser::OnStartElementL( aElement, aAttributes, aErrorCode ); |
|
129 |
|
130 TPtrC8 tag( aElement.LocalName().DesC() ); |
|
131 |
|
132 if( iSubParser == 0 ) |
|
133 { |
|
134 DLTRACEIN(("purchaseOption start tag=%S error=%d depth=%d", |
|
135 &aElement.LocalName().DesC(),aErrorCode,iDepth)); |
|
136 |
|
137 if( tag == KTagDownloadDetails ) |
|
138 { |
|
139 iSubParser = CNcdPreminetProtocolDownloadParser::NewL( |
|
140 *iObservers, *this, iDepth+1, aElement, aAttributes, |
|
141 KNullDesC /*no parent id*/ ); |
|
142 } |
|
143 else if( tag == KTagSubscriptionDetails ) |
|
144 { |
|
145 // skip this tag |
|
146 //*iParentTag = tag; |
|
147 } |
|
148 else if( tag == KTagParentSubscription ) |
|
149 { |
|
150 TPtrC8 entityId = AttributeValue( KAttrEntityId, aAttributes ); |
|
151 NcdProtocolUtils::AssignDesL( |
|
152 iPurchaseOption->iParentSubscriptionEntityId, entityId); |
|
153 TPtrC8 purchaseOptionId = AttributeValue( KAttrPurchaseOptionId, aAttributes ); |
|
154 NcdProtocolUtils::AssignDesL( |
|
155 iPurchaseOption->iParentSubscriptionPurchaseOptionId, purchaseOptionId); |
|
156 } |
|
157 else if( tag == KTagAmountOfCredits /*&& *iParentTag == KTagSubscriptionDetails*/ ) |
|
158 { |
|
159 TPtrC8 currency = AttributeValue( KAttrCurrency, aAttributes ); |
|
160 NcdProtocolUtils::AssignDesL( |
|
161 iPurchaseOption->iSubscriptionDetails->iAmountOfCreditsCurrency, currency); |
|
162 // value saved in OnEndElementL |
|
163 } |
|
164 else if( tag == KTagValidity /*&& *iParentTag == KTagSubscriptionDetails*/ ) |
|
165 { |
|
166 TPtrC8 delta = AttributeValue( KAttrDelta, aAttributes ); |
|
167 iPurchaseOption->iSubscriptionDetails->iValidityDelta = |
|
168 NcdProtocolUtils::DesDecToIntL(delta); |
|
169 TPtrC8 autoUpdate = AttributeValue( KAttrAutoUpdate, aAttributes ); |
|
170 NcdProtocolUtils::DesToBool( |
|
171 iPurchaseOption->iSubscriptionDetails->iValidityAutoUpdate, autoUpdate); |
|
172 } |
|
173 else if( tag == KTagNumberOfDownloads /*&& *iParentTag == KTagSubscriptionDetails*/ ) |
|
174 { |
|
175 // value saved in OnEndElementL |
|
176 } |
|
177 else if( tag == KTagPriceText || tag == KTagCreditPrice ) |
|
178 { |
|
179 // price text is saved in OnEndElementL |
|
180 } |
|
181 else if ( tag == KTagPrice ) |
|
182 { |
|
183 TPtrC8 currency = AttributeValue( KAttrCurrency, aAttributes ); |
|
184 NcdProtocolUtils::AssignDesL(iPurchaseOption->iPriceCurrency, currency); |
|
185 } |
|
186 else |
|
187 { |
|
188 iSubParser = CNcdUnknownParser::NewL( |
|
189 *iObservers, *this, iDepth+1, aElement, aAttributes ); |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 iSubParser->OnStartElementL( aElement, aAttributes, aErrorCode ); |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 |
|
200 void CNcdPreminetProtocolPurchaseOptionParser::OnEndElementL( |
|
201 const Xml::RTagInfo& aElement, TInt aErrorCode) |
|
202 { |
|
203 DLTRACEIN(("")); |
|
204 |
|
205 TPtrC8 tag( aElement.LocalName().DesC() ); |
|
206 |
|
207 if ( iBuffer ) |
|
208 { |
|
209 if ( tag == KTagPriceText ) |
|
210 { |
|
211 NcdProtocolUtils::AssignDesL(iPurchaseOption->iPriceText, *iBuffer); |
|
212 } |
|
213 else if ( tag == KTagPrice ) |
|
214 { |
|
215 iPurchaseOption->iPrice = NcdProtocolUtils::DesDecToRealL(*iBuffer); |
|
216 } |
|
217 else if ( tag == KTagAmountOfCredits ) |
|
218 { |
|
219 iPurchaseOption->iSubscriptionDetails->iAmountOfCredits = |
|
220 NcdProtocolUtils::DesDecToRealL(*iBuffer); |
|
221 } |
|
222 else if ( tag == KTagCreditPrice ) |
|
223 { |
|
224 iPurchaseOption->iCreditPrice = NcdProtocolUtils::DesDecToRealL(*iBuffer); |
|
225 } |
|
226 else if ( tag == KTagNumberOfDownloads && iPurchaseOption->iSubscriptionDetails ) |
|
227 { |
|
228 iPurchaseOption->iSubscriptionDetails->iNumberOfDownloads = |
|
229 NcdProtocolUtils::DesDecToIntL(*iBuffer); |
|
230 } |
|
231 delete iBuffer; |
|
232 iBuffer = 0; |
|
233 } |
|
234 |
|
235 if( iSubParser == 0 && iTag && *iTag == aElement.LocalName().DesC() ) |
|
236 { |
|
237 DLTRACE(("end tag=%S",&aElement.LocalName().DesC())); |
|
238 // Should store finished entity, or let the parent do it with some function? |
|
239 iSubParserObserver->SubParserFinishedL( aElement.LocalName().DesC(), aErrorCode ); |
|
240 } |
|
241 else if( iSubParser ) |
|
242 { |
|
243 iSubParser->OnEndElementL( aElement, aErrorCode ); |
|
244 } |
|
245 else |
|
246 { |
|
247 DLWARNING(("end tag ignored, tag=%S",&aElement.LocalName().DesC())); |
|
248 } |
|
249 } |
|
250 |
|
251 |
|
252 void CNcdPreminetProtocolPurchaseOptionParser::SubParserFinishedL( const TDesC8& aTag, |
|
253 TInt /*aErrorCode*/ ) |
|
254 { |
|
255 DLTRACEIN(("tag=%S subparser=%X",&aTag,iSubParser)); |
|
256 (void) aTag; // suppresses compiler warning |
|
257 |
|
258 // : child entity has been finished. store it as a |
|
259 // a childen to the node this parser is parsing. |
|
260 // Needs nodemanager. |
|
261 if( iSubParser->Tag() == KTagDownloadDetails ) |
|
262 { |
|
263 // A subentity is now ready. Report it. |
|
264 MNcdPreminetProtocolDownload* download = |
|
265 static_cast<CNcdPreminetProtocolDownloadParser*>( iSubParser )->Download(); |
|
266 DLINFO(("subparser download=%X",download)); |
|
267 if( download && iPurchaseOption ) |
|
268 { |
|
269 iPurchaseOption->iDownloadDetails.AppendL(download); |
|
270 } |
|
271 } |
|
272 |
|
273 delete iSubParser; |
|
274 iSubParser = 0; |
|
275 } |
|
276 |
|
277 MNcdPreminetProtocolPurchaseOption* |
|
278 CNcdPreminetProtocolPurchaseOptionParser::PurchaseOption() |
|
279 { |
|
280 MNcdPreminetProtocolPurchaseOption* opt = iPurchaseOption; |
|
281 iPurchaseOption = 0; |
|
282 return opt; |
|
283 } |
|
284 |