author | Sebastian Brannstrom <sebastianb@symbian.org> |
Fri, 09 Jul 2010 11:34:00 +0100 | |
branch | asynchparser |
changeset 171 | cc1be3797632 |
parent 88 | f4b512d870e8 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB |
|
3 |
* |
|
4 |
* All rights reserved. |
|
5 |
* This component and the accompanying materials are made available |
|
6 |
* under the terms of the License "Eclipse Public License v1.0" |
|
7 |
* which accompanies this distribution, and is available |
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 |
* |
|
10 |
* Initial Contributors: |
|
11 |
* EmbedDev AB - initial contribution. |
|
12 |
* |
|
13 |
* Contributors: |
|
14 |
* |
|
15 |
* Description: |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
#include "FeedParser.h" |
|
20 |
#include <f32file.h> |
|
21 |
#include <bautils.h> |
|
22 |
#include <s32file.h> |
|
23 |
#include <charconv.h> |
|
24 |
#include <xml/stringdictionarycollection.h> |
|
25 |
#include <utf.h> |
|
26 |
#include <tinternetdate.h> |
|
27 |
#include "debug.h" |
|
60 | 28 |
#include "podcastutils.h" |
2 | 29 |
|
30 |
using namespace Xml; |
|
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
31 |
|
2 | 32 |
const TInt KMaxParseBuffer = 1024; |
33 |
const TInt KMaxStringBuffer = 100; |
|
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
34 |
const TInt KFileBufferSize = 1024; // buffer size for file reading |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
35 |
_LIT8( KXmlMimeType, "text/xml" ); |
2 | 36 |
|
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
37 |
CFeedParser* CFeedParser::NewL(MFeedParserObserver& aCallbacks, RFs& aFs) |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
38 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
39 |
CFeedParser* self = CFeedParser::NewLC(aCallbacks, aFs); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
40 |
CleanupStack::Pop(); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
41 |
return self; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
42 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
43 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
44 |
CFeedParser* CFeedParser::NewLC(MFeedParserObserver& aCallbacks, RFs& aFs) |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
45 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
46 |
CFeedParser* self = new ( ELeave ) CFeedParser(aCallbacks, aFs); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
47 |
CleanupStack::PushL( self); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
48 |
self->ConstructL(); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
49 |
return self; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
50 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
51 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
52 |
CFeedParser::CFeedParser(MFeedParserObserver& aCallbacks, RFs& aFs) : CActive(EPriorityLow), |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
53 |
iCallbacks(aCallbacks), iRfs(aFs) |
2 | 54 |
{ |
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
55 |
CActiveScheduler::Add( this); |
2 | 56 |
} |
57 |
||
58 |
CFeedParser::~CFeedParser() |
|
59 |
{ |
|
60 |
} |
|
61 |
||
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
62 |
void CFeedParser::ParseFeedAoL(const TFileName &feedFileName, CFeedInfo *item, TUint aMaxItems) |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
63 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
64 |
DP("CFeedParser::ParseFeedAoL BEGIN"); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
65 |
// Remember to cancel any outstanding request first. |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
66 |
if ( IsActive()) |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
67 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
68 |
Cancel(); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
69 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
70 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
71 |
iActiveFeed = item; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
72 |
iFeedState = EStateRoot; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
73 |
iActiveShow = NULL; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
74 |
iItemsParsed = 0; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
75 |
iMaxItems = aMaxItems; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
76 |
iStoppedParsing = EFalse; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
77 |
iEncoding = ELatin1; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
78 |
iFileName.Copy(feedFileName); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
79 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
80 |
User::LeaveIfError( iFile.Open( iRfs, feedFileName, EFileRead)); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
81 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
82 |
delete iXmlBuffer; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
83 |
iXmlBuffer = 0; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
84 |
iXmlBuffer = HBufC8::NewL( KFileBufferSize); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
85 |
TPtr8 bufferPtr( iXmlBuffer->Des()); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
86 |
iFile.Read( bufferPtr, KFileBufferSize, iStatus); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
87 |
SetActive(); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
88 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
89 |
iParser->ParseBeginL(); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
90 |
DP("CFeedParser::ParseFeedAoL END"); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
91 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
92 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
93 |
|
2 | 94 |
void CFeedParser::ParseFeedL(const TFileName &feedFileName, CFeedInfo *info, TUint aMaxItems) |
95 |
{ |
|
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
96 |
DP1("ParseFeedL BEGIN: %S", &feedFileName); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
97 |
|
2 | 98 |
iActiveFeed = info; |
99 |
iFeedState = EStateRoot; |
|
100 |
iActiveShow = NULL; |
|
101 |
iItemsParsed = 0; |
|
102 |
iMaxItems = aMaxItems; |
|
103 |
iStoppedParsing = EFalse; |
|
104 |
iEncoding = ELatin1; |
|
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
105 |
iFileName.Copy(feedFileName); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
106 |
CParser* parser = CParser::NewLC(KXmlMimeType, *this); |
2 | 107 |
|
108 |
ParseL(*parser, iRfs, feedFileName); |
|
109 |
||
110 |
CleanupStack::PopAndDestroy(parser); |
|
111 |
||
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
112 |
DP("ParseFeedL END"); |
2 | 113 |
} |
114 |
||
115 |
// from MContentHandler |
|
116 |
void CFeedParser::OnStartDocumentL(const RDocumentParameters& aDocParam, TInt /*aErrorCode*/) |
|
117 |
{ |
|
118 |
DP("OnStartDocumentL()"); |
|
119 |
HBufC* charset = HBufC::NewLC(KMaxParseBuffer); |
|
120 |
charset->Des().Copy(aDocParam.CharacterSetName().DesC()); |
|
121 |
iEncoding = EUtf8; |
|
122 |
if (charset->CompareF(_L("utf-8")) == 0) { |
|
123 |
DP("setting UTF8"); |
|
124 |
iEncoding = EUtf8; |
|
125 |
} else if (charset->CompareF(_L("ISO-8859-1")) == 0) { |
|
126 |
iEncoding = EUtf8; //Latin1; |
|
127 |
} else { |
|
128 |
DP1("unknown charset: %S", &charset); |
|
129 |
} |
|
130 |
CleanupStack::PopAndDestroy(charset);//buffer |
|
131 |
} |
|
132 |
||
133 |
void CFeedParser::OnEndDocumentL(TInt /*aErrorCode*/) |
|
134 |
{ |
|
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
135 |
DP("OnEndDocumentL()"); |
2 | 136 |
iCallbacks.ParsingCompleteL(iActiveFeed); |
137 |
} |
|
138 |
||
139 |
void CFeedParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt /*aErrorCode*/) |
|
140 |
{ |
|
141 |
if (iStoppedParsing) { |
|
142 |
iActiveShow = NULL; |
|
143 |
return; |
|
144 |
} |
|
145 |
||
146 |
TBuf<KMaxStringBuffer> str; |
|
147 |
str.Copy(aElement.LocalName().DesC()); |
|
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
148 |
DP2("OnStartElementL START state=%d, element=%S", iFeedState, &str); |
2 | 149 |
iBuffer.Zero(); |
150 |
switch (iFeedState) { |
|
151 |
case EStateRoot: |
|
152 |
// <channel> |
|
153 |
if (str.CompareF(KTagChannel) == 0) { |
|
154 |
iFeedState = EStateChannel; |
|
155 |
} |
|
156 |
break; |
|
157 |
case EStateChannel: |
|
158 |
// <channel> <item> |
|
159 |
if(str.CompareF(KTagItem) == 0) { |
|
160 |
//DP("New item"); |
|
161 |
iFeedState=EStateItem; |
|
162 |
||
163 |
iActiveShow = NULL; |
|
164 |
iActiveShow = CShowInfo::NewL(); |
|
165 |
if (iActiveShow == NULL) { |
|
166 |
DP("Out of memory!"); |
|
167 |
iStoppedParsing = ETrue; |
|
168 |
return; |
|
169 |
} |
|
170 |
iActiveShow->SetFeedUid(iActiveFeed->Uid()); |
|
171 |
||
172 |
// <channel> <lastBuildDate> |
|
173 |
} else if (str.CompareF(KTagLastBuildDate) == 0) { |
|
174 |
DP("LastBuildDate BEGIN"); |
|
175 |
iFeedState=EStateChannelLastBuildDate; |
|
176 |
// <channel> <link> |
|
177 |
}else if (str.CompareF(KTagTitle) == 0) { |
|
178 |
iFeedState=EStateChannelTitle; |
|
179 |
// <channel> <link> |
|
180 |
} else if (str.CompareF(KTagLink) == 0) { |
|
181 |
iFeedState = EStateChannelLink; |
|
182 |
// <channel> <description> |
|
183 |
} else if (str.CompareF(KTagDescription) == 0) { |
|
184 |
iFeedState=EStateChannelDescription; |
|
185 |
// <channel> <image> |
|
186 |
} else if (str.CompareF(KTagImage) == 0) { |
|
187 |
for (int i=0;i<aAttributes.Count();i++) { |
|
188 |
RAttribute attr = aAttributes[i]; |
|
189 |
TBuf<KMaxStringBuffer> attr16; |
|
190 |
attr16.Copy(attr.Attribute().LocalName().DesC().Left(KMaxStringBuffer)); |
|
191 |
HBufC* val16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(attr.Value().DesC().Left(KMaxParseBuffer)); |
|
192 |
CleanupStack::PushL(val16); |
|
193 |
||
194 |
// href=... |
|
195 |
if (attr16.Compare(KTagHref) == 0) { |
|
196 |
iActiveFeed->SetImageUrlL(*val16); |
|
197 |
} |
|
198 |
CleanupStack::PopAndDestroy(val16); |
|
199 |
} |
|
200 |
||
201 |
iFeedState=EStateChannelImage; |
|
202 |
} |
|
203 |
break; |
|
204 |
case EStateChannelImage: |
|
205 |
// <channel> <image> <url> |
|
206 |
if (str.CompareF(KTagUrl) == 0) { |
|
207 |
iFeedState=EStateChannelImageUrl; |
|
208 |
} else { |
|
209 |
iFeedState=EStateChannelImage; |
|
210 |
} |
|
211 |
break; |
|
212 |
case EStateItem: |
|
213 |
// <channel> <item> <title> |
|
214 |
if (str.CompareF(KTagTitle) == 0) { |
|
215 |
iFeedState=EStateItemTitle; |
|
216 |
// <channel> <item> <link> |
|
217 |
} else if (str.CompareF(KTagLink) == 0) { |
|
218 |
iFeedState=EStateItemLink; |
|
219 |
// <channel> <item> <enclosure ...> |
|
220 |
} else if (str.CompareF(KTagEnclosure) == 0) { |
|
221 |
//DP("Enclosure START"); |
|
222 |
for (int i=0;i<aAttributes.Count();i++) { |
|
223 |
RAttribute attr = aAttributes[i]; |
|
224 |
TBuf<KMaxStringBuffer> attr16; |
|
225 |
attr16.Copy(attr.Attribute().LocalName().DesC()); |
|
226 |
// url=... |
|
227 |
if (attr16.Compare(KTagUrl) == 0) { |
|
228 |
HBufC* val16 = HBufC::NewLC(KMaxParseBuffer); |
|
229 |
val16->Des().Copy(attr.Value().DesC()); |
|
230 |
iActiveShow->SetUrlL(*val16); |
|
60 | 231 |
|
232 |
if (PodcastUtils::IsVideoShow(*val16)) { |
|
233 |
iActiveShow->SetShowType(EVideoPodcast); |
|
234 |
} |
|
2 | 235 |
CleanupStack::PopAndDestroy(val16); |
236 |
// length=... |
|
237 |
} else if (attr16.Compare(KTagLength) == 0) { |
|
238 |
TLex8 lex(attr.Value().DesC()); |
|
239 |
TUint size = 0; |
|
240 |
lex.Val(size, EDecimal); |
|
241 |
iActiveShow->SetShowSize(size); |
|
242 |
} |
|
243 |
} |
|
244 |
// <channel> <item> <description> |
|
245 |
} else if (str.CompareF(KTagDescription) == 0) { |
|
246 |
iFeedState=EStateItemDescription; |
|
247 |
// <channel> <item> <pubdate> |
|
248 |
} else if (str.CompareF(KTagPubDate) == 0) { |
|
249 |
//DP("LastBuildDate BEGIN"); |
|
250 |
iFeedState = EStateItemPubDate; |
|
251 |
} |
|
252 |
break; |
|
253 |
default: |
|
254 |
//DP2("Ignoring tag %S when in state %d", &str, iFeedState); |
|
255 |
break; |
|
256 |
} |
|
257 |
// DP1("OnStartElementL END state=%d", iFeedState); |
|
258 |
} |
|
259 |
||
260 |
void CFeedParser::OnEndElementL(const RTagInfo& aElement, TInt /*aErrorCode*/) |
|
261 |
{ |
|
262 |
||
263 |
if (iStoppedParsing) { |
|
264 |
return; |
|
265 |
} |
|
266 |
||
267 |
iBuffer.Trim(); |
|
268 |
||
269 |
TDesC8 lName = aElement.LocalName().DesC(); |
|
270 |
TBuf<KMaxStringBuffer> str; |
|
271 |
str.Copy(aElement.LocalName().DesC()); |
|
272 |
||
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
273 |
DP2("OnEndElementL START state=%d, element=%S", iFeedState, &str); |
2 | 274 |
|
275 |
switch (iFeedState) { |
|
276 |
case EStateChannelTitle: |
|
277 |
if(str.CompareF(KTagTitle) == 0) { |
|
278 |
if (iActiveFeed->CustomTitle() == EFalse) { |
|
279 |
iActiveFeed->SetTitleL(iBuffer); |
|
280 |
} |
|
281 |
iFeedState = EStateChannel; |
|
282 |
} |
|
283 |
break; |
|
284 |
case EStateChannelLink: |
|
285 |
iActiveFeed->SetLinkL(iBuffer); |
|
286 |
iFeedState = EStateChannel; |
|
287 |
break; |
|
288 |
case EStateChannelDescription: |
|
289 |
iActiveFeed->SetDescriptionL(iBuffer); |
|
290 |
iFeedState = EStateChannel; |
|
291 |
break; |
|
292 |
case EStateChannelLastBuildDate: |
|
293 |
{ |
|
294 |
//DP("LastBuildDate END"); |
|
295 |
TInternetDate internetDate; |
|
296 |
TBuf8<128> temp; |
|
297 |
temp.Copy(iBuffer); |
|
298 |
||
299 |
TRAPD(parseError, internetDate.SetDateL(temp)); |
|
300 |
if(parseError == KErrNone) { |
|
301 |
if (TTime(internetDate.DateTime()) > iActiveFeed->BuildDate()) { |
|
302 |
DP("Successfully parsed build date"); |
|
303 |
iActiveFeed->SetBuildDate(TTime(internetDate.DateTime())); |
|
304 |
} else { |
|
305 |
DP("*** Nothing new, aborting parsing"); |
|
306 |
iStoppedParsing = ETrue; |
|
307 |
} |
|
308 |
} else { |
|
309 |
DP("Failed to parse last build date"); |
|
310 |
} |
|
311 |
iFeedState = EStateChannel; |
|
312 |
} |
|
313 |
break; |
|
314 |
case EStateChannelImageUrl: |
|
315 |
//DP1("Image url: %S", &iBuffer); |
|
316 |
iActiveFeed->SetImageUrlL(iBuffer); |
|
317 |
iFeedState = EStateChannelImage; |
|
318 |
break; |
|
319 |
case EStateChannelImage: |
|
320 |
if(str.CompareF(KTagImage) == 0) { |
|
321 |
iFeedState = EStateChannel; |
|
322 |
} |
|
323 |
break; |
|
324 |
case EStateItem: |
|
325 |
if (str.CompareF(KTagItem) == 0) |
|
326 |
{ |
|
327 |
iCallbacks.NewShowL(*iActiveShow); |
|
328 |
||
329 |
delete iActiveShow; |
|
330 |
||
331 |
// We should now be finished with the show. |
|
332 |
iActiveShow = NULL; |
|
333 |
||
334 |
iItemsParsed++; |
|
88
f4b512d870e8
Moved call to DeleteOldShowsByFeedL to when a feed is listed. This prevents a race condition which likely caused
teknolog
parents:
60
diff
changeset
|
335 |
DP2("iItemsParsed: %d, iMaxItems: %d", iItemsParsed, iMaxItems); |
f4b512d870e8
Moved call to DeleteOldShowsByFeedL to when a feed is listed. This prevents a race condition which likely caused
teknolog
parents:
60
diff
changeset
|
336 |
if (iItemsParsed >= iMaxItems) |
2 | 337 |
{ |
338 |
iStoppedParsing = ETrue; |
|
339 |
DP("*** Too many items, aborting parsing"); |
|
340 |
} |
|
341 |
||
342 |
iFeedState=EStateChannel; |
|
343 |
} |
|
344 |
break; |
|
345 |
case EStateItemPubDate: |
|
346 |
DP1("PubDate END: iBuffer='%S'", &iBuffer); |
|
347 |
if (str.CompareF(KTagPubDate) == 0) { |
|
348 |
// hack for feeds that don't always write day as two digits |
|
349 |
TChar five(iBuffer[5]); |
|
350 |
TChar six(iBuffer[6]); |
|
351 |
||
352 |
if (five.IsDigit() && !six.IsDigit()) { |
|
353 |
TBuf<KMaxStringBuffer> fix; |
|
354 |
fix.Copy(iBuffer.Left(4)); |
|
355 |
fix.Append(_L(" 0")); |
|
356 |
fix.Append(iBuffer.Mid(5)); |
|
357 |
iBuffer.Copy(fix); |
|
358 |
} |
|
359 |
// end hack |
|
360 |
||
361 |
// hack for feeds that write out months in full |
|
362 |
||
363 |
if (iBuffer[11] != ' ') { |
|
364 |
TPtrC midPtr = iBuffer.Mid(8); |
|
365 |
||
366 |
int spacePos = midPtr.Find(_L(" ")); |
|
367 |
||
368 |
if (spacePos != KErrNotFound) { |
|
369 |
//DP1("Month: %S", &midPtr.Left(spacePos)); |
|
370 |
||
371 |
TBuf16<KBufferLength> newBuffer; |
|
372 |
newBuffer.Copy(iBuffer.Left(11)); |
|
373 |
newBuffer.Append(_L(" ")); |
|
374 |
newBuffer.Append(iBuffer.Mid(11+spacePos)); |
|
375 |
//DP1("newBuffer: %S", &newBuffer); |
|
376 |
iBuffer.Copy(newBuffer); |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
// hack for feeds that write days and months as UPPERCASE |
|
381 |
TChar one(iBuffer[1]); |
|
382 |
TChar two(iBuffer[2]); |
|
383 |
TChar nine(iBuffer[9]); |
|
384 |
TChar ten(iBuffer[10]); |
|
385 |
||
386 |
one.LowerCase(); |
|
387 |
two.LowerCase(); |
|
388 |
nine.LowerCase(); |
|
389 |
ten.LowerCase(); |
|
390 |
||
391 |
iBuffer[1] = one; |
|
392 |
iBuffer[2] = two; |
|
393 |
iBuffer[9] = nine; |
|
394 |
iBuffer[10] = ten; |
|
395 |
||
396 |
TBuf8<128> temp; |
|
397 |
temp.Copy(iBuffer); |
|
398 |
||
399 |
TInternetDate internetDate; |
|
400 |
TRAPD(parseError, internetDate.SetDateL(temp)); |
|
401 |
if(parseError == KErrNone) { |
|
402 |
//DP1("PubDate parse success: '%S'", &iBuffer); |
|
403 |
iActiveShow->SetPubDate(TTime(internetDate.DateTime())); |
|
404 |
||
405 |
||
406 |
DP6("Successfully parsed pubdate %d/%d/%d %d:%d:%d", |
|
407 |
iActiveShow->PubDate().DateTime().Year(), |
|
408 |
iActiveShow->PubDate().DateTime().Month(), |
|
409 |
iActiveShow->PubDate().DateTime().Day(), |
|
410 |
iActiveShow->PubDate().DateTime().Hour(), |
|
411 |
iActiveShow->PubDate().DateTime().Minute(), |
|
412 |
iActiveShow->PubDate().DateTime().Second()); |
|
413 |
||
414 |
} else { |
|
415 |
DP2("Pubdate parse error: '%S', error=%d", &iBuffer, parseError); |
|
416 |
} |
|
417 |
} |
|
418 |
iFeedState=EStateItem; |
|
419 |
break; |
|
420 |
case EStateItemTitle: |
|
421 |
//DP1("title: %S", &iBuffer); |
|
422 |
iActiveShow->SetTitleL(iBuffer); |
|
423 |
iFeedState = EStateItem; |
|
424 |
break; |
|
425 |
case EStateItemLink: |
|
426 |
if (iActiveShow->Url().Length() == 0) { |
|
427 |
iActiveShow->SetUrlL(iBuffer); |
|
60 | 428 |
|
429 |
if (PodcastUtils::IsVideoShow(iBuffer)) { |
|
430 |
iActiveShow->SetShowType(EVideoPodcast); |
|
431 |
} |
|
2 | 432 |
} |
433 |
iFeedState = EStateItem; |
|
434 |
break; |
|
435 |
case EStateItemDescription: |
|
436 |
iActiveShow->SetDescriptionL(iBuffer); |
|
437 |
iFeedState = EStateItem; |
|
438 |
break; |
|
439 |
default: |
|
440 |
// fall back to channel level when in doubt |
|
441 |
iFeedState = EStateChannel; |
|
442 |
//DP2("Don't know how to handle end tag %S when in state %d", &str, iFeedState); |
|
443 |
break; |
|
444 |
} |
|
445 |
||
446 |
//DP1("OnEndElementL END state=%d", iFeedState); |
|
447 |
} |
|
448 |
||
449 |
void CFeedParser::OnContentL(const TDesC8& aBytes, TInt /*aErrorCode*/) |
|
450 |
{ |
|
451 |
TBuf<KBufferLength> temp; |
|
452 |
if (iEncoding == EUtf8) { |
|
453 |
CnvUtfConverter::ConvertToUnicodeFromUtf8(temp, aBytes); |
|
454 |
} else { |
|
455 |
temp.Copy(aBytes); |
|
456 |
} |
|
457 |
||
458 |
if(temp.Length() + iBuffer.Length() < KBufferLength) { |
|
459 |
iBuffer.Append(temp); |
|
460 |
} |
|
461 |
} |
|
462 |
||
463 |
void CFeedParser::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, TInt /*aErrorCode*/) |
|
464 |
{ |
|
465 |
DP("OnStartPrefixMappingL()"); |
|
466 |
} |
|
467 |
||
468 |
void CFeedParser::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/) |
|
469 |
{ |
|
470 |
DP("OnEndPrefixMappingL()"); |
|
471 |
} |
|
472 |
||
473 |
void CFeedParser::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/) |
|
474 |
{ |
|
475 |
DP("OnIgnorableWhiteSpaceL()"); |
|
476 |
} |
|
477 |
||
478 |
void CFeedParser::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/) |
|
479 |
{ |
|
480 |
DP("OnSkippedEntityL()"); |
|
481 |
} |
|
482 |
||
483 |
void CFeedParser::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt /*aErrorCode*/) |
|
484 |
{ |
|
485 |
DP("OnProcessingInstructionL()"); |
|
486 |
} |
|
487 |
||
488 |
void CFeedParser::OnError(TInt aErrorCode) |
|
489 |
{ |
|
490 |
DP1("CFeedParser::OnError %d", aErrorCode); |
|
491 |
} |
|
492 |
||
493 |
TAny* CFeedParser::GetExtendedInterface(const TInt32 /*aUid*/) |
|
494 |
{ |
|
495 |
DP("GetExtendedInterface()"); |
|
496 |
return NULL; |
|
497 |
} |
|
498 |
||
499 |
CFeedInfo& CFeedParser::ActiveFeed() |
|
500 |
{ |
|
501 |
return *iActiveFeed; |
|
502 |
} |
|
171
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
503 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
504 |
void CFeedParser::ConstructL() |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
505 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
506 |
iParser = CParser::NewL( KXmlMimeType, *this); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
507 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
508 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
509 |
void CFeedParser::DoCancel() |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
510 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
511 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
512 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
513 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
514 |
void CFeedParser::RunL() |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
515 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
516 |
if ( KErrNone == iStatus.Int()) |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
517 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
518 |
if ( iXmlBuffer->Length()== 0) // end of the file. |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
519 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
520 |
iParser->ParseEndL(); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
521 |
iFile.Close(); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
522 |
BaflUtils::DeleteFile(iRfs,iFileName); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
523 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
524 |
delete iXmlBuffer; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
525 |
iXmlBuffer = 0; |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
526 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
527 |
else |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
528 |
{// Otherwise, we continue reading the next chunk of the XML file. |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
529 |
// Parse the next "part" of the XML document. |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
530 |
iParser->ParseL( *iXmlBuffer); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
531 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
532 |
// Read the next chunk of the file. |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
533 |
TPtr8 bufferPtr( iXmlBuffer->Des()); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
534 |
iFile.Read( bufferPtr, KFileBufferSize, iStatus); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
535 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
536 |
// Don't forget to call this... :) |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
537 |
SetActive(); |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
538 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
539 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
540 |
else |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
541 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
542 |
// Do something if error happens. |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
543 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
544 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
545 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
546 |
TInt CFeedParser::RunError(TInt aError) |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
547 |
{ |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
548 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
549 |
} |
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
550 |
|
cc1be3797632
First implementation of asynchronous feed parser
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
551 |