diff -r f42c9de433f2 -r cc1be3797632 engine/src/FeedParser.cpp --- a/engine/src/FeedParser.cpp Wed Jul 07 23:27:49 2010 +0100 +++ b/engine/src/FeedParser.cpp Fri Jul 09 11:34:00 2010 +0100 @@ -28,24 +28,73 @@ #include "podcastutils.h" using namespace Xml; + const TInt KMaxParseBuffer = 1024; const TInt KMaxStringBuffer = 100; +const TInt KFileBufferSize = 1024; // buffer size for file reading +_LIT8( KXmlMimeType, "text/xml" ); -CFeedParser::CFeedParser(MFeedParserObserver& aCallbacks, RFs& aFs) : iCallbacks(aCallbacks), iRfs(aFs) +CFeedParser* CFeedParser::NewL(MFeedParserObserver& aCallbacks, RFs& aFs) + { + CFeedParser* self = CFeedParser::NewLC(aCallbacks, aFs); + CleanupStack::Pop(); + return self; + } + +CFeedParser* CFeedParser::NewLC(MFeedParserObserver& aCallbacks, RFs& aFs) + { + CFeedParser* self = new ( ELeave ) CFeedParser(aCallbacks, aFs); + CleanupStack::PushL( self); + self->ConstructL(); + return self; + } + +CFeedParser::CFeedParser(MFeedParserObserver& aCallbacks, RFs& aFs) : CActive(EPriorityLow), + iCallbacks(aCallbacks), iRfs(aFs) { + CActiveScheduler::Add( this); } CFeedParser::~CFeedParser() { } +void CFeedParser::ParseFeedAoL(const TFileName &feedFileName, CFeedInfo *item, TUint aMaxItems) + { + DP("CFeedParser::ParseFeedAoL BEGIN"); + // Remember to cancel any outstanding request first. + if ( IsActive()) + { + Cancel(); + } + + iActiveFeed = item; + iFeedState = EStateRoot; + iActiveShow = NULL; + iItemsParsed = 0; + iMaxItems = aMaxItems; + iStoppedParsing = EFalse; + iEncoding = ELatin1; + iFileName.Copy(feedFileName); + + User::LeaveIfError( iFile.Open( iRfs, feedFileName, EFileRead)); + + delete iXmlBuffer; + iXmlBuffer = 0; + iXmlBuffer = HBufC8::NewL( KFileBufferSize); + TPtr8 bufferPtr( iXmlBuffer->Des()); + iFile.Read( bufferPtr, KFileBufferSize, iStatus); + SetActive(); + + iParser->ParseBeginL(); + DP("CFeedParser::ParseFeedAoL END"); + } + + void CFeedParser::ParseFeedL(const TFileName &feedFileName, CFeedInfo *info, TUint aMaxItems) { - //DP1("ParseFeedL BEGIN: %S", &feedFileName); - - _LIT8(KXmlMimeType, "text/xml"); - // Contruct the parser object - CParser* parser = CParser::NewLC(KXmlMimeType, *this); + DP1("ParseFeedL BEGIN: %S", &feedFileName); + iActiveFeed = info; iFeedState = EStateRoot; iActiveShow = NULL; @@ -53,12 +102,14 @@ iMaxItems = aMaxItems; iStoppedParsing = EFalse; iEncoding = ELatin1; + iFileName.Copy(feedFileName); + CParser* parser = CParser::NewLC(KXmlMimeType, *this); ParseL(*parser, iRfs, feedFileName); CleanupStack::PopAndDestroy(parser); - //DP("ParseFeedL END"); + DP("ParseFeedL END"); } // from MContentHandler @@ -81,7 +132,7 @@ void CFeedParser::OnEndDocumentL(TInt /*aErrorCode*/) { - //DP("OnEndDocumentL()"); + DP("OnEndDocumentL()"); iCallbacks.ParsingCompleteL(iActiveFeed); } @@ -94,7 +145,7 @@ TBuf str; str.Copy(aElement.LocalName().DesC()); - //DP2("OnStartElementL START state=%d, element=%S", iFeedState, &str); + DP2("OnStartElementL START state=%d, element=%S", iFeedState, &str); iBuffer.Zero(); switch (iFeedState) { case EStateRoot: @@ -219,7 +270,7 @@ TBuf str; str.Copy(aElement.LocalName().DesC()); - //DP2("OnEndElementL START state=%d, element=%S", iFeedState, &str); + DP2("OnEndElementL START state=%d, element=%S", iFeedState, &str); switch (iFeedState) { case EStateChannelTitle: @@ -449,3 +500,52 @@ { return *iActiveFeed; } + +void CFeedParser::ConstructL() + { + iParser = CParser::NewL( KXmlMimeType, *this); + } + +void CFeedParser::DoCancel() + { + + } + +void CFeedParser::RunL() + { + if ( KErrNone == iStatus.Int()) + { + if ( iXmlBuffer->Length()== 0) // end of the file. + { + iParser->ParseEndL(); + iFile.Close(); + BaflUtils::DeleteFile(iRfs,iFileName); + + delete iXmlBuffer; + iXmlBuffer = 0; + } + else + {// Otherwise, we continue reading the next chunk of the XML file. + // Parse the next "part" of the XML document. + iParser->ParseL( *iXmlBuffer); + + // Read the next chunk of the file. + TPtr8 bufferPtr( iXmlBuffer->Des()); + iFile.Read( bufferPtr, KFileBufferSize, iStatus); + + // Don't forget to call this... :) + SetActive(); + } + } + else + { + // Do something if error happens. + } + } + +TInt CFeedParser::RunError(TInt aError) + { + + } + +