engine/inc/FeedParser.h
author William Roberts <williamr@symbian.org>
Thu, 22 Jul 2010 16:33:34 +0100
branchGCC_SURGE
changeset 192 b436ab77eac1
parent 2 29cda98b007e
child 171 cc1be3797632
child 247 60621d146c19
child 343 9c56bf585696
permissions -rw-r--r--
Catchup to latest Symbian^4

/*
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
*
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* EmbedDev AB - initial contribution.
*
* Contributors:
*
* Description:
*
*/

#ifndef FEEDPARSER_H_
#define FEEDPARSER_H_

#include "FeedParserObserver.h"
#include "FeedInfo.h"
#include <xml/parser.h> // for CParser
#include <xml/contenthandler.h>	// for Xml::MContentHandler
#include <xml/documentparameters.h>

_LIT(KTagItem, "item");
_LIT(KTagTitle, "title");
_LIT(KTagImage, "image");
_LIT(KTagLink, "link");
_LIT(KTagDescription, "description");
_LIT(KTagUrl, "url");
_LIT(KTagLength, "length");
_LIT(KTagChannel, "channel");
_LIT(KTagEnclosure, "enclosure");
_LIT(KTagPubDate, "pubDate");
_LIT(KTagLastBuildDate, "lastBuildDate");
_LIT(KTagHref, "href");

enum TFeedState {
	EStateRoot,
	EStateChannel,
	EStateChannelTitle,
	EStateChannelLink,
	EStateChannelLastBuildDate,
	EStateChannelDescription,
	EStateChannelImage,
	EStateChannelImageUrl,
	EStateItem,
	EStateItemTitle,
	EStateItemLink,
	EStateItemEnclosure,
	EStateItemDescription,
	EStateItemPubDate
};

enum TEncoding {
	EUtf8,
	ELatin1
};

const int KBufferLength = 1024;

class CFeedParser : public CBase, public Xml::MContentHandler 
{
public:
	CFeedParser(MFeedParserObserver& aCallbacks, RFs& aFs);
	virtual ~CFeedParser();
	
public:
	void ParseFeedL(const TFileName &feedFileName, CFeedInfo *item, TUint aMaxItems);
	
public: // from MContentHandler
	void OnStartDocumentL(const Xml::RDocumentParameters& aDocParam, TInt aErrorCode);
	void OnEndDocumentL(TInt aErrorCode);
	void OnStartElementL(const Xml::RTagInfo& aElement, const Xml::RAttributeArray& aAttributes, TInt aErrorCode);
	void OnEndElementL(const Xml::RTagInfo& aElement, TInt aErrorCode);
	void OnContentL(const TDesC8& aBytes, TInt aErrorCode);
	void OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode);
	void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode);
	void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode);
	void OnSkippedEntityL(const RString& aName, TInt aErrorCode);
	void OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, TInt aErrorCode);
	void OnError(TInt aErrorCode);
	TAny* GetExtendedInterface(const TInt32 aUid);
	CFeedInfo& ActiveFeed();
private:
	MFeedParserObserver& iCallbacks;
	TFeedState iFeedState;

	CShowInfo* iActiveShow;
	CFeedInfo *iActiveFeed;

	TBuf<KBufferLength> iBuffer;
	
	TUint iMaxItems;
	TUint iItemsParsed;
	TBool iStoppedParsing;
	TEncoding iEncoding;
	RFs& iRfs;
};

#endif