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