engine/src/FeedParser.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Sat, 13 Nov 2010 13:54:36 +0000
branch3rded
changeset 343 9c56bf585696
parent 277 03ad04f315db
child 390 d7abecc9d189
permissions -rw-r--r--
Catching up with 5th edition
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     1
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     2
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     3
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     4
* All rights reserved.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     5
* This component and the accompanying materials are made available
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     6
* under the terms of the License "Eclipse Public License v1.0"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     7
* which accompanies this distribution, and is available
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     8
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     9
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    10
* Initial Contributors:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    11
* EmbedDev AB - initial contribution.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    12
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    13
* Contributors:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    15
* Description:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    16
*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    17
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    18
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    19
#include "FeedParser.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
#include <f32file.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
#include <bautils.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
#include <s32file.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
#include <charconv.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
#include <xml/stringdictionarycollection.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
#include <utf.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
#include "debug.h"
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 2
diff changeset
    29
#include "podcastutils.h"
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
using namespace Xml;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
const TInt KMaxParseBuffer = 1024;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
const TInt KMaxStringBuffer = 100;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
CFeedParser::CFeedParser(MFeedParserObserver& aCallbacks, RFs& aFs) : 	iCallbacks(aCallbacks), iRfs(aFs)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
CFeedParser::~CFeedParser()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
{	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
void CFeedParser::ParseFeedL(const TFileName &feedFileName, CFeedInfo *info, TUint aMaxItems)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
	//DP1("ParseFeedL BEGIN: %S", &feedFileName);		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
	_LIT8(KXmlMimeType, "text/xml");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
	// Contruct the parser object
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
	CParser* parser = CParser::NewLC(KXmlMimeType, *this);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
	iActiveFeed = info;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
	iFeedState = EStateRoot;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
	iActiveShow = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
	iItemsParsed = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
	iMaxItems = aMaxItems;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
	iStoppedParsing = EFalse;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
	iEncoding = ELatin1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
	ParseL(*parser, iRfs, feedFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
	CleanupStack::PopAndDestroy(parser);	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
	//DP("ParseFeedL END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
// from MContentHandler
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
void CFeedParser::OnStartDocumentL(const RDocumentParameters& aDocParam, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
	DP("OnStartDocumentL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
	HBufC* charset = HBufC::NewLC(KMaxParseBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
	charset->Des().Copy(aDocParam.CharacterSetName().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
	iEncoding = EUtf8;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
	if (charset->CompareF(_L("utf-8")) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
		DP("setting UTF8");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
		iEncoding = EUtf8;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
	} else if (charset->CompareF(_L("ISO-8859-1")) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
		iEncoding = EUtf8; //Latin1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
	} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
		DP1("unknown charset: %S", &charset);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
	CleanupStack::PopAndDestroy(charset);//buffer
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
void CFeedParser::OnEndDocumentL(TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
	//DP("OnEndDocumentL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
	iCallbacks.ParsingCompleteL(iActiveFeed);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
void CFeedParser::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& aAttributes, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
	if (iStoppedParsing) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
		iActiveShow = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
		return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
	TBuf<KMaxStringBuffer> str;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
	str.Copy(aElement.LocalName().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
	//DP2("OnStartElementL START state=%d, element=%S", iFeedState, &str);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
	iBuffer.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
	switch (iFeedState) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
	case EStateRoot:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
		// <channel>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
		if (str.CompareF(KTagChannel) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
			iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
		break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
	case EStateChannel:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
		// <channel> <item>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
		if(str.CompareF(KTagItem) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
			//DP("New item");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
			iFeedState=EStateItem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
			iActiveShow = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
			iActiveShow = CShowInfo::NewL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
			if (iActiveShow == NULL) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
				DP("Out of memory!");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
				iStoppedParsing = ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
				return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
			iActiveShow->SetFeedUid(iActiveFeed->Uid());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
		// <channel> <lastBuildDate>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
		} else if (str.CompareF(KTagLastBuildDate) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
			DP("LastBuildDate BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
			iFeedState=EStateChannelLastBuildDate;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
		// <channel> <link>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
		}else if (str.CompareF(KTagTitle) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
			iFeedState=EStateChannelTitle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
		// <channel> <link>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
		} else if (str.CompareF(KTagLink) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
			iFeedState = EStateChannelLink;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
		// <channel> <description>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
		} else if (str.CompareF(KTagDescription) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
			iFeedState=EStateChannelDescription;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
		// <channel> <image>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
		} else if (str.CompareF(KTagImage) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
			for (int i=0;i<aAttributes.Count();i++) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
				RAttribute attr = aAttributes[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
				TBuf<KMaxStringBuffer> attr16;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
				attr16.Copy(attr.Attribute().LocalName().DesC().Left(KMaxStringBuffer));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
				HBufC* val16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L(attr.Value().DesC().Left(KMaxParseBuffer));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
				CleanupStack::PushL(val16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
						
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
				// href=...
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
				if (attr16.Compare(KTagHref) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
					iActiveFeed->SetImageUrlL(*val16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
				CleanupStack::PopAndDestroy(val16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
			iFeedState=EStateChannelImage;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
		break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
	case EStateChannelImage:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
		// <channel> <image> <url>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
		if (str.CompareF(KTagUrl) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
			iFeedState=EStateChannelImageUrl;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
		} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
			iFeedState=EStateChannelImage;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
		break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
	case EStateItem:
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 277
diff changeset
   167
		iUid = 0;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
		// <channel> <item> <title>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
		if (str.CompareF(KTagTitle) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
			iFeedState=EStateItemTitle;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
		// <channel> <item> <link>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
		} else if (str.CompareF(KTagLink) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
			iFeedState=EStateItemLink;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
		// <channel> <item> <enclosure ...>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
		} else if (str.CompareF(KTagEnclosure) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
			//DP("Enclosure START");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
			for (int i=0;i<aAttributes.Count();i++) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
				RAttribute attr = aAttributes[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
				TBuf<KMaxStringBuffer> attr16;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
				attr16.Copy(attr.Attribute().LocalName().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
				// url=...
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
				if (attr16.Compare(KTagUrl) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
					HBufC* val16 = HBufC::NewLC(KMaxParseBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
					val16->Des().Copy(attr.Value().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
					iActiveShow->SetUrlL(*val16);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 2
diff changeset
   186
					
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 2
diff changeset
   187
					if (PodcastUtils::IsVideoShow(*val16)) {
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 2
diff changeset
   188
						iActiveShow->SetShowType(EVideoPodcast);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 2
diff changeset
   189
					}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
					CleanupStack::PopAndDestroy(val16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
				// length=...
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
				} else if (attr16.Compare(KTagLength) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
					TLex8 lex(attr.Value().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
					TUint size = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
					lex.Val(size, EDecimal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
					iActiveShow->SetShowSize(size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
		// <channel> <item> <description>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
		} else if (str.CompareF(KTagDescription) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
			iFeedState=EStateItemDescription;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
		// <channel> <item> <pubdate>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
		} else if (str.CompareF(KTagPubDate) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
			//DP("LastBuildDate BEGIN");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
		break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
	default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
		//DP2("Ignoring tag %S when in state %d", &str, iFeedState);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
		break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
//	DP1("OnStartElementL END state=%d", iFeedState);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
void CFeedParser::OnEndElementL(const RTagInfo& aElement, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
	if (iStoppedParsing) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
		return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
	iBuffer.Trim();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
	TDesC8 lName = aElement.LocalName().DesC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
	TBuf<KMaxStringBuffer> str;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
	str.Copy(aElement.LocalName().DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
	//DP2("OnEndElementL START state=%d, element=%S", iFeedState, &str);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
	switch (iFeedState) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
		case EStateChannelTitle:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
			if(str.CompareF(KTagTitle) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
				if (iActiveFeed->CustomTitle() == EFalse) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
					iActiveFeed->SetTitleL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
				iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
		case EStateChannelLink:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
			iActiveFeed->SetLinkL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
			iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
		case EStateChannelDescription:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
			iActiveFeed->SetDescriptionL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
			iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
		case EStateChannelLastBuildDate:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
			//DP("LastBuildDate END");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
			TInternetDate internetDate;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
			TBuf8<128> temp;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
			temp.Copy(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
			TRAPD(parseError, internetDate.SetDateL(temp));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
			if(parseError == KErrNone) {				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
				if (TTime(internetDate.DateTime()) > iActiveFeed->BuildDate()) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
					DP("Successfully parsed build date");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
					DP("*** Nothing new, aborting parsing");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
					iStoppedParsing = ETrue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
			} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
				DP("Failed to parse last build date");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
			}
343
9c56bf585696 Catching up with 5th edition
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 277
diff changeset
   271
			iActiveFeed->SetFeedFileSize(iFileSize);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
			iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
		case EStateChannelImageUrl:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
			//DP1("Image url: %S", &iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
			iActiveFeed->SetImageUrlL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
			iFeedState = EStateChannelImage;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
		case EStateChannelImage:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
			if(str.CompareF(KTagImage) == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
				iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   285
		case EStateItem:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
				iCallbacks.NewShowL(*iActiveShow);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   311
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
				delete iActiveShow;				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
				// We should now be finished with the show.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
				iActiveShow = NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
				iFeedState=EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   327
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   328
		case EStateItemPubDate:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
			DP1("PubDate END: iBuffer='%S'", &iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   386
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   387
				TBuf8<128> temp;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   388
				temp.Copy(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   389
				TInternetDate internetDate;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   390
				TRAPD(parseError, internetDate.SetDateL(temp));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   391
				if(parseError == KErrNone) {				
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   392
					//DP1("PubDate parse success: '%S'", &iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   393
					iActiveShow->SetPubDate(TTime(internetDate.DateTime()));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   394
			
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   395
					
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   396
					DP6("Successfully parsed pubdate %d/%d/%d %d:%d:%d",
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   397
							iActiveShow->PubDate().DateTime().Year(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   398
							iActiveShow->PubDate().DateTime().Month(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   399
							iActiveShow->PubDate().DateTime().Day(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   400
							iActiveShow->PubDate().DateTime().Hour(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   401
							iActiveShow->PubDate().DateTime().Minute(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
							iActiveShow->PubDate().DateTime().Second());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
							
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
				} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   405
					DP2("Pubdate parse error: '%S', error=%d", &iBuffer, parseError);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   406
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   407
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   408
			iFeedState=EStateItem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   414
		case EStateItemTitle:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   415
			//DP1("title: %S", &iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   416
			iActiveShow->SetTitleL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   417
			iFeedState = EStateItem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   418
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
		case EStateItemLink:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
			if (iActiveShow->Url().Length() == 0) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
				iActiveShow->SetUrlL(iBuffer);
60
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 2
diff changeset
   422
				
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 2
diff changeset
   423
				if (PodcastUtils::IsVideoShow(iBuffer)) {
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 2
diff changeset
   424
					iActiveShow->SetShowType(EVideoPodcast);
4d230e702aa3 Moved development branch from MCL to FCL
teknolog
parents: 2
diff changeset
   425
				}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   426
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   427
			iFeedState = EStateItem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   428
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   429
		case EStateItemDescription:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
			iActiveShow->SetDescriptionL(iBuffer);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
			iFeedState = EStateItem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
		default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
			// fall back to channel level when in doubt
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   435
			iFeedState = EStateChannel;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
			//DP2("Don't know how to handle end tag %S when in state %d", &str, iFeedState);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   437
			break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   438
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
	//DP1("OnEndElementL END state=%d", iFeedState);	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   443
void CFeedParser::OnContentL(const TDesC8& aBytes, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   444
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   445
	TBuf<KBufferLength> temp;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   446
	if (iEncoding == EUtf8) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   447
		CnvUtfConverter::ConvertToUnicodeFromUtf8(temp, aBytes);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
	} else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   449
		temp.Copy(aBytes);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   450
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   452
	if(temp.Length() + iBuffer.Length() < KBufferLength) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   453
		iBuffer.Append(temp);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   454
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   455
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   456
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   457
void CFeedParser::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   458
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   459
	DP("OnStartPrefixMappingL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   460
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   461
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   462
void CFeedParser::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   463
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   464
	DP("OnEndPrefixMappingL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   465
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   466
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   467
void CFeedParser::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   468
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   469
	DP("OnIgnorableWhiteSpaceL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   470
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   471
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   472
void CFeedParser::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   473
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
	DP("OnSkippedEntityL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   475
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   476
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   477
void CFeedParser::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt /*aErrorCode*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   478
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   479
	DP("OnProcessingInstructionL()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   480
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   482
void CFeedParser::OnError(TInt aErrorCode)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   483
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   484
	DP1("CFeedParser::OnError %d", aErrorCode);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   485
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   486
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   487
TAny* CFeedParser::GetExtendedInterface(const TInt32 /*aUid*/)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   488
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   489
	DP("GetExtendedInterface()");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   490
	return NULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   491
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   492
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   493
CFeedInfo& CFeedParser::ActiveFeed()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   494
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   495
		return *iActiveFeed;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   496
	}