author | Sebastian Brannstrom <sebastianb@symbian.org> |
Sat, 13 Nov 2010 13:54:36 +0000 | |
branch | 3rded |
changeset 343 | 9c56bf585696 |
parent 277 | 03ad04f315db |
child 390 | d7abecc9d189 |
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> |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
27 |
#include <e32hashtab.h> |
2 | 28 |
#include "debug.h" |
60 | 29 |
#include "podcastutils.h" |
2 | 30 |
|
31 |
using namespace Xml; |
|
32 |
const TInt KMaxParseBuffer = 1024; |
|
33 |
const TInt KMaxStringBuffer = 100; |
|
34 |
||
35 |
CFeedParser::CFeedParser(MFeedParserObserver& aCallbacks, RFs& aFs) : iCallbacks(aCallbacks), iRfs(aFs) |
|
36 |
{ |
|
37 |
} |
|
38 |
||
39 |
CFeedParser::~CFeedParser() |
|
40 |
{ |
|
41 |
} |
|
42 |
||
43 |
void CFeedParser::ParseFeedL(const TFileName &feedFileName, CFeedInfo *info, TUint aMaxItems) |
|
44 |
{ |
|
45 |
//DP1("ParseFeedL BEGIN: %S", &feedFileName); |
|
46 |
||
47 |
_LIT8(KXmlMimeType, "text/xml"); |
|
48 |
// Contruct the parser object |
|
49 |
CParser* parser = CParser::NewLC(KXmlMimeType, *this); |
|
50 |
iActiveFeed = info; |
|
51 |
iFeedState = EStateRoot; |
|
52 |
iActiveShow = NULL; |
|
53 |
iItemsParsed = 0; |
|
54 |
iMaxItems = aMaxItems; |
|
55 |
iStoppedParsing = EFalse; |
|
56 |
iEncoding = ELatin1; |
|
57 |
||
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
58 |
TEntry entry; |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
59 |
User::LeaveIfError(iRfs.Entry(feedFileName, entry)); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
60 |
iFileSize = entry.iSize; |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
61 |
|
2 | 62 |
ParseL(*parser, iRfs, feedFileName); |
63 |
||
64 |
CleanupStack::PopAndDestroy(parser); |
|
65 |
||
66 |
//DP("ParseFeedL END"); |
|
67 |
} |
|
68 |
||
69 |
// from MContentHandler |
|
70 |
void CFeedParser::OnStartDocumentL(const RDocumentParameters& aDocParam, TInt /*aErrorCode*/) |
|
71 |
{ |
|
72 |
DP("OnStartDocumentL()"); |
|
73 |
HBufC* charset = HBufC::NewLC(KMaxParseBuffer); |
|
74 |
charset->Des().Copy(aDocParam.CharacterSetName().DesC()); |
|
75 |
iEncoding = EUtf8; |
|
76 |
if (charset->CompareF(_L("utf-8")) == 0) { |
|
77 |
DP("setting UTF8"); |
|
78 |
iEncoding = EUtf8; |
|
79 |
} else if (charset->CompareF(_L("ISO-8859-1")) == 0) { |
|
80 |
iEncoding = EUtf8; //Latin1; |
|
81 |
} else { |
|
82 |
DP1("unknown charset: %S", &charset); |
|
83 |
} |
|
84 |
CleanupStack::PopAndDestroy(charset);//buffer |
|
85 |
} |
|
86 |
||
87 |
void CFeedParser::OnEndDocumentL(TInt /*aErrorCode*/) |
|
88 |
{ |
|
89 |
//DP("OnEndDocumentL()"); |
|
90 |
iCallbacks.ParsingCompleteL(iActiveFeed); |
|
91 |
} |
|
92 |
||
93 |
void CFeedParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt /*aErrorCode*/) |
|
94 |
{ |
|
95 |
if (iStoppedParsing) { |
|
96 |
iActiveShow = NULL; |
|
97 |
return; |
|
98 |
} |
|
99 |
||
100 |
TBuf<KMaxStringBuffer> str; |
|
101 |
str.Copy(aElement.LocalName().DesC()); |
|
102 |
//DP2("OnStartElementL START state=%d, element=%S", iFeedState, &str); |
|
103 |
iBuffer.Zero(); |
|
104 |
switch (iFeedState) { |
|
105 |
case EStateRoot: |
|
106 |
// <channel> |
|
107 |
if (str.CompareF(KTagChannel) == 0) { |
|
108 |
iFeedState = EStateChannel; |
|
109 |
} |
|
110 |
break; |
|
111 |
case EStateChannel: |
|
112 |
// <channel> <item> |
|
113 |
if(str.CompareF(KTagItem) == 0) { |
|
114 |
//DP("New item"); |
|
115 |
iFeedState=EStateItem; |
|
116 |
||
117 |
iActiveShow = NULL; |
|
118 |
iActiveShow = CShowInfo::NewL(); |
|
119 |
if (iActiveShow == NULL) { |
|
120 |
DP("Out of memory!"); |
|
121 |
iStoppedParsing = ETrue; |
|
122 |
return; |
|
123 |
} |
|
124 |
iActiveShow->SetFeedUid(iActiveFeed->Uid()); |
|
125 |
||
126 |
// <channel> <lastBuildDate> |
|
127 |
} else if (str.CompareF(KTagLastBuildDate) == 0) { |
|
128 |
DP("LastBuildDate BEGIN"); |
|
129 |
iFeedState=EStateChannelLastBuildDate; |
|
130 |
// <channel> <link> |
|
131 |
}else if (str.CompareF(KTagTitle) == 0) { |
|
132 |
iFeedState=EStateChannelTitle; |
|
133 |
// <channel> <link> |
|
134 |
} else if (str.CompareF(KTagLink) == 0) { |
|
135 |
iFeedState = EStateChannelLink; |
|
136 |
// <channel> <description> |
|
137 |
} else if (str.CompareF(KTagDescription) == 0) { |
|
138 |
iFeedState=EStateChannelDescription; |
|
139 |
// <channel> <image> |
|
140 |
} else if (str.CompareF(KTagImage) == 0) { |
|
141 |
for (int i=0;i<aAttributes.Count();i++) { |
|
142 |
RAttribute attr = aAttributes[i]; |
|
143 |
TBuf<KMaxStringBuffer> attr16; |
|
144 |
attr16.Copy(attr.Attribute().LocalName().DesC().Left(KMaxStringBuffer)); |
|
145 |
HBufC* val16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(attr.Value().DesC().Left(KMaxParseBuffer)); |
|
146 |
CleanupStack::PushL(val16); |
|
147 |
||
148 |
// href=... |
|
149 |
if (attr16.Compare(KTagHref) == 0) { |
|
150 |
iActiveFeed->SetImageUrlL(*val16); |
|
151 |
} |
|
152 |
CleanupStack::PopAndDestroy(val16); |
|
153 |
} |
|
154 |
||
155 |
iFeedState=EStateChannelImage; |
|
156 |
} |
|
157 |
break; |
|
158 |
case EStateChannelImage: |
|
159 |
// <channel> <image> <url> |
|
160 |
if (str.CompareF(KTagUrl) == 0) { |
|
161 |
iFeedState=EStateChannelImageUrl; |
|
162 |
} else { |
|
163 |
iFeedState=EStateChannelImage; |
|
164 |
} |
|
165 |
break; |
|
166 |
case EStateItem: |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
167 |
iUid = 0; |
2 | 168 |
// <channel> <item> <title> |
169 |
if (str.CompareF(KTagTitle) == 0) { |
|
170 |
iFeedState=EStateItemTitle; |
|
171 |
// <channel> <item> <link> |
|
172 |
} else if (str.CompareF(KTagLink) == 0) { |
|
173 |
iFeedState=EStateItemLink; |
|
174 |
// <channel> <item> <enclosure ...> |
|
175 |
} else if (str.CompareF(KTagEnclosure) == 0) { |
|
176 |
//DP("Enclosure START"); |
|
177 |
for (int i=0;i<aAttributes.Count();i++) { |
|
178 |
RAttribute attr = aAttributes[i]; |
|
179 |
TBuf<KMaxStringBuffer> attr16; |
|
180 |
attr16.Copy(attr.Attribute().LocalName().DesC()); |
|
181 |
// url=... |
|
182 |
if (attr16.Compare(KTagUrl) == 0) { |
|
183 |
HBufC* val16 = HBufC::NewLC(KMaxParseBuffer); |
|
184 |
val16->Des().Copy(attr.Value().DesC()); |
|
185 |
iActiveShow->SetUrlL(*val16); |
|
60 | 186 |
|
187 |
if (PodcastUtils::IsVideoShow(*val16)) { |
|
188 |
iActiveShow->SetShowType(EVideoPodcast); |
|
189 |
} |
|
2 | 190 |
CleanupStack::PopAndDestroy(val16); |
191 |
// length=... |
|
192 |
} else if (attr16.Compare(KTagLength) == 0) { |
|
193 |
TLex8 lex(attr.Value().DesC()); |
|
194 |
TUint size = 0; |
|
195 |
lex.Val(size, EDecimal); |
|
196 |
iActiveShow->SetShowSize(size); |
|
197 |
} |
|
198 |
} |
|
199 |
// <channel> <item> <description> |
|
200 |
} else if (str.CompareF(KTagDescription) == 0) { |
|
201 |
iFeedState=EStateItemDescription; |
|
202 |
// <channel> <item> <pubdate> |
|
203 |
} else if (str.CompareF(KTagPubDate) == 0) { |
|
204 |
//DP("LastBuildDate BEGIN"); |
|
205 |
iFeedState = EStateItemPubDate; |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
206 |
// <channel> <item> <guid> |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
207 |
} else if (str.CompareF(KTagGuid) == 0) { |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
208 |
iFeedState = EStateItemGuid; |
2 | 209 |
} |
210 |
break; |
|
211 |
default: |
|
212 |
//DP2("Ignoring tag %S when in state %d", &str, iFeedState); |
|
213 |
break; |
|
214 |
} |
|
215 |
// DP1("OnStartElementL END state=%d", iFeedState); |
|
216 |
} |
|
217 |
||
218 |
void CFeedParser::OnEndElementL(const RTagInfo& aElement, TInt /*aErrorCode*/) |
|
219 |
{ |
|
220 |
||
221 |
if (iStoppedParsing) { |
|
222 |
return; |
|
223 |
} |
|
224 |
||
225 |
iBuffer.Trim(); |
|
226 |
||
227 |
TDesC8 lName = aElement.LocalName().DesC(); |
|
228 |
TBuf<KMaxStringBuffer> str; |
|
229 |
str.Copy(aElement.LocalName().DesC()); |
|
230 |
||
231 |
//DP2("OnEndElementL START state=%d, element=%S", iFeedState, &str); |
|
232 |
||
233 |
switch (iFeedState) { |
|
234 |
case EStateChannelTitle: |
|
235 |
if(str.CompareF(KTagTitle) == 0) { |
|
236 |
if (iActiveFeed->CustomTitle() == EFalse) { |
|
237 |
iActiveFeed->SetTitleL(iBuffer); |
|
238 |
} |
|
239 |
iFeedState = EStateChannel; |
|
240 |
} |
|
241 |
break; |
|
242 |
case EStateChannelLink: |
|
243 |
iActiveFeed->SetLinkL(iBuffer); |
|
244 |
iFeedState = EStateChannel; |
|
245 |
break; |
|
246 |
case EStateChannelDescription: |
|
247 |
iActiveFeed->SetDescriptionL(iBuffer); |
|
248 |
iFeedState = EStateChannel; |
|
249 |
break; |
|
250 |
case EStateChannelLastBuildDate: |
|
251 |
{ |
|
252 |
//DP("LastBuildDate END"); |
|
253 |
TInternetDate internetDate; |
|
254 |
TBuf8<128> temp; |
|
255 |
temp.Copy(iBuffer); |
|
256 |
||
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
257 |
DP2("iFileSize=%d, iActiveFeed->FeedFileSize()=%d", iFileSize, iActiveFeed->FeedFileSize()); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
258 |
|
2 | 259 |
TRAPD(parseError, internetDate.SetDateL(temp)); |
260 |
if(parseError == KErrNone) { |
|
261 |
if (TTime(internetDate.DateTime()) > iActiveFeed->BuildDate()) { |
|
262 |
DP("Successfully parsed build date"); |
|
263 |
iActiveFeed->SetBuildDate(TTime(internetDate.DateTime())); |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
264 |
} else if (iFileSize == iActiveFeed->FeedFileSize()){ |
2 | 265 |
DP("*** Nothing new, aborting parsing"); |
266 |
iStoppedParsing = ETrue; |
|
267 |
} |
|
268 |
} else { |
|
269 |
DP("Failed to parse last build date"); |
|
270 |
} |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
271 |
iActiveFeed->SetFeedFileSize(iFileSize); |
2 | 272 |
iFeedState = EStateChannel; |
273 |
} |
|
274 |
break; |
|
275 |
case EStateChannelImageUrl: |
|
276 |
//DP1("Image url: %S", &iBuffer); |
|
277 |
iActiveFeed->SetImageUrlL(iBuffer); |
|
278 |
iFeedState = EStateChannelImage; |
|
279 |
break; |
|
280 |
case EStateChannelImage: |
|
281 |
if(str.CompareF(KTagImage) == 0) { |
|
282 |
iFeedState = EStateChannel; |
|
283 |
} |
|
284 |
break; |
|
285 |
case EStateItem: |
|
286 |
if (str.CompareF(KTagItem) == 0) |
|
276
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
287 |
{ |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
288 |
// check if we have a valid pubdate |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
289 |
if (iActiveShow->PubDate().Int64() == 0) |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
290 |
{ |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
291 |
// set pubDate to present time |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
292 |
TTime now; |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
293 |
now.UniversalTime(); |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
294 |
|
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
295 |
// but we want reverse sorting, so let's do a little trick... |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
296 |
TTimeIntervalHours delta; |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
297 |
delta = iItemsParsed; |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
298 |
|
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
299 |
// ... remove an hour per show we've parsed so far |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
300 |
now -= delta; |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
301 |
|
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
302 |
iActiveShow->SetPubDate(now); |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
303 |
} |
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
304 |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
305 |
if (iUid) |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
306 |
{ |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
307 |
iActiveShow->SetUid(iUid); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
308 |
} |
276
4357d59592dd
Fix for bug 3540 - show sorting when pubDate is not set in feed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
88
diff
changeset
|
309 |
|
2 | 310 |
iCallbacks.NewShowL(*iActiveShow); |
311 |
||
312 |
delete iActiveShow; |
|
313 |
||
314 |
// We should now be finished with the show. |
|
315 |
iActiveShow = NULL; |
|
316 |
||
317 |
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
|
318 |
DP2("iItemsParsed: %d, iMaxItems: %d", iItemsParsed, iMaxItems); |
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
319 |
if (iItemsParsed >= iMaxItems) |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
320 |
{ |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
321 |
iStoppedParsing = ETrue; |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
322 |
DP("*** Too many items, aborting parsing"); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
323 |
} |
2 | 324 |
|
325 |
iFeedState=EStateChannel; |
|
326 |
} |
|
327 |
break; |
|
328 |
case EStateItemPubDate: |
|
329 |
DP1("PubDate END: iBuffer='%S'", &iBuffer); |
|
330 |
if (str.CompareF(KTagPubDate) == 0) { |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
331 |
DP1("iBuffer.Length()=%d", iBuffer.Length()); |
2 | 332 |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
333 |
if (iBuffer.Length() > 6) |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
334 |
{ |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
335 |
// hack for feeds that don't always write day as two digits |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
336 |
TChar five(iBuffer[5]); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
337 |
TChar six(iBuffer[6]); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
338 |
|
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
339 |
if (five.IsDigit() && !six.IsDigit()) { |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
340 |
TBuf<KMaxStringBuffer> fix; |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
341 |
fix.Copy(iBuffer.Left(4)); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
342 |
fix.Append(_L(" 0")); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
343 |
fix.Append(iBuffer.Mid(5)); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
344 |
iBuffer.Copy(fix); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
345 |
} |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
346 |
// end hack |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
347 |
} |
2 | 348 |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
349 |
if (iBuffer.Length() > 11) |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
350 |
{ |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
351 |
// hack for feeds that write out months in full |
2 | 352 |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
353 |
if (iBuffer[11] != ' ') { |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
354 |
TPtrC midPtr = iBuffer.Mid(8); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
355 |
|
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
356 |
int spacePos = midPtr.Find(_L(" ")); |
2 | 357 |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
358 |
if (spacePos != KErrNotFound) { |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
359 |
//DP1("Month: %S", &midPtr.Left(spacePos)); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
360 |
|
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
361 |
TBuf16<KBufferLength> newBuffer; |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
362 |
newBuffer.Copy(iBuffer.Left(11)); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
363 |
newBuffer.Append(_L(" ")); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
364 |
newBuffer.Append(iBuffer.Mid(11+spacePos)); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
365 |
//DP1("newBuffer: %S", &newBuffer); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
366 |
iBuffer.Copy(newBuffer); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
367 |
} |
2 | 368 |
} |
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
369 |
|
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
370 |
// hack for feeds that write days and months as UPPERCASE |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
371 |
TChar one(iBuffer[1]); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
372 |
TChar two(iBuffer[2]); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
373 |
TChar nine(iBuffer[9]); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
374 |
TChar ten(iBuffer[10]); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
375 |
|
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
376 |
one.LowerCase(); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
377 |
two.LowerCase(); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
378 |
nine.LowerCase(); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
379 |
ten.LowerCase(); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
380 |
|
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
381 |
iBuffer[1] = one; |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
382 |
iBuffer[2] = two; |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
383 |
iBuffer[9] = nine; |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
384 |
iBuffer[10] = ten; |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
385 |
} |
2 | 386 |
|
387 |
TBuf8<128> temp; |
|
388 |
temp.Copy(iBuffer); |
|
389 |
TInternetDate internetDate; |
|
390 |
TRAPD(parseError, internetDate.SetDateL(temp)); |
|
391 |
if(parseError == KErrNone) { |
|
392 |
//DP1("PubDate parse success: '%S'", &iBuffer); |
|
393 |
iActiveShow->SetPubDate(TTime(internetDate.DateTime())); |
|
394 |
||
395 |
||
396 |
DP6("Successfully parsed pubdate %d/%d/%d %d:%d:%d", |
|
397 |
iActiveShow->PubDate().DateTime().Year(), |
|
398 |
iActiveShow->PubDate().DateTime().Month(), |
|
399 |
iActiveShow->PubDate().DateTime().Day(), |
|
400 |
iActiveShow->PubDate().DateTime().Hour(), |
|
401 |
iActiveShow->PubDate().DateTime().Minute(), |
|
402 |
iActiveShow->PubDate().DateTime().Second()); |
|
403 |
||
404 |
} else { |
|
405 |
DP2("Pubdate parse error: '%S', error=%d", &iBuffer, parseError); |
|
406 |
} |
|
407 |
} |
|
408 |
iFeedState=EStateItem; |
|
409 |
break; |
|
343
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
410 |
case EStateItemGuid: |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
411 |
iUid = DefaultHash::Des16(iBuffer); |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
412 |
iFeedState=EStateItem; |
9c56bf585696
Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
277
diff
changeset
|
413 |
break; |
2 | 414 |
case EStateItemTitle: |
415 |
//DP1("title: %S", &iBuffer); |
|
416 |
iActiveShow->SetTitleL(iBuffer); |
|
417 |
iFeedState = EStateItem; |
|
418 |
break; |
|
419 |
case EStateItemLink: |
|
420 |
if (iActiveShow->Url().Length() == 0) { |
|
421 |
iActiveShow->SetUrlL(iBuffer); |
|
60 | 422 |
|
423 |
if (PodcastUtils::IsVideoShow(iBuffer)) { |
|
424 |
iActiveShow->SetShowType(EVideoPodcast); |
|
425 |
} |
|
2 | 426 |
} |
427 |
iFeedState = EStateItem; |
|
428 |
break; |
|
429 |
case EStateItemDescription: |
|
430 |
iActiveShow->SetDescriptionL(iBuffer); |
|
431 |
iFeedState = EStateItem; |
|
432 |
break; |
|
433 |
default: |
|
434 |
// fall back to channel level when in doubt |
|
435 |
iFeedState = EStateChannel; |
|
436 |
//DP2("Don't know how to handle end tag %S when in state %d", &str, iFeedState); |
|
437 |
break; |
|
438 |
} |
|
439 |
||
440 |
//DP1("OnEndElementL END state=%d", iFeedState); |
|
441 |
} |
|
442 |
||
443 |
void CFeedParser::OnContentL(const TDesC8& aBytes, TInt /*aErrorCode*/) |
|
444 |
{ |
|
445 |
TBuf<KBufferLength> temp; |
|
446 |
if (iEncoding == EUtf8) { |
|
447 |
CnvUtfConverter::ConvertToUnicodeFromUtf8(temp, aBytes); |
|
448 |
} else { |
|
449 |
temp.Copy(aBytes); |
|
450 |
} |
|
451 |
||
452 |
if(temp.Length() + iBuffer.Length() < KBufferLength) { |
|
453 |
iBuffer.Append(temp); |
|
454 |
} |
|
455 |
} |
|
456 |
||
457 |
void CFeedParser::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, TInt /*aErrorCode*/) |
|
458 |
{ |
|
459 |
DP("OnStartPrefixMappingL()"); |
|
460 |
} |
|
461 |
||
462 |
void CFeedParser::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/) |
|
463 |
{ |
|
464 |
DP("OnEndPrefixMappingL()"); |
|
465 |
} |
|
466 |
||
467 |
void CFeedParser::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/) |
|
468 |
{ |
|
469 |
DP("OnIgnorableWhiteSpaceL()"); |
|
470 |
} |
|
471 |
||
472 |
void CFeedParser::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/) |
|
473 |
{ |
|
474 |
DP("OnSkippedEntityL()"); |
|
475 |
} |
|
476 |
||
477 |
void CFeedParser::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt /*aErrorCode*/) |
|
478 |
{ |
|
479 |
DP("OnProcessingInstructionL()"); |
|
480 |
} |
|
481 |
||
482 |
void CFeedParser::OnError(TInt aErrorCode) |
|
483 |
{ |
|
484 |
DP1("CFeedParser::OnError %d", aErrorCode); |
|
485 |
} |
|
486 |
||
487 |
TAny* CFeedParser::GetExtendedInterface(const TInt32 /*aUid*/) |
|
488 |
{ |
|
489 |
DP("GetExtendedInterface()"); |
|
490 |
return NULL; |
|
491 |
} |
|
492 |
||
493 |
CFeedInfo& CFeedParser::ActiveFeed() |
|
494 |
{ |
|
495 |
return *iActiveFeed; |
|
496 |
} |