engine/inc/FeedParser.h
changeset 2 29cda98b007e
equal deleted inserted replaced
1:5f8e5adbbed9 2:29cda98b007e
       
     1 /*
       
     2 * Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
       
     3 *
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of the License "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * EmbedDev AB - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 *
       
    15 * Description:
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef FEEDPARSER_H_
       
    20 #define FEEDPARSER_H_
       
    21 
       
    22 #include "FeedParserObserver.h"
       
    23 #include "FeedInfo.h"
       
    24 #include <xml/parser.h> // for CParser
       
    25 #include <xml/contenthandler.h>	// for Xml::MContentHandler
       
    26 #include <xml/documentparameters.h>
       
    27 
       
    28 _LIT(KTagItem, "item");
       
    29 _LIT(KTagTitle, "title");
       
    30 _LIT(KTagImage, "image");
       
    31 _LIT(KTagLink, "link");
       
    32 _LIT(KTagDescription, "description");
       
    33 _LIT(KTagUrl, "url");
       
    34 _LIT(KTagLength, "length");
       
    35 _LIT(KTagChannel, "channel");
       
    36 _LIT(KTagEnclosure, "enclosure");
       
    37 _LIT(KTagPubDate, "pubDate");
       
    38 _LIT(KTagLastBuildDate, "lastBuildDate");
       
    39 _LIT(KTagHref, "href");
       
    40 
       
    41 enum TFeedState {
       
    42 	EStateRoot,
       
    43 	EStateChannel,
       
    44 	EStateChannelTitle,
       
    45 	EStateChannelLink,
       
    46 	EStateChannelLastBuildDate,
       
    47 	EStateChannelDescription,
       
    48 	EStateChannelImage,
       
    49 	EStateChannelImageUrl,
       
    50 	EStateItem,
       
    51 	EStateItemTitle,
       
    52 	EStateItemLink,
       
    53 	EStateItemEnclosure,
       
    54 	EStateItemDescription,
       
    55 	EStateItemPubDate
       
    56 };
       
    57 
       
    58 enum TEncoding {
       
    59 	EUtf8,
       
    60 	ELatin1
       
    61 };
       
    62 
       
    63 const int KBufferLength = 1024;
       
    64 
       
    65 class CFeedParser : public CBase, public Xml::MContentHandler 
       
    66 {
       
    67 public:
       
    68 	CFeedParser(MFeedParserObserver& aCallbacks, RFs& aFs);
       
    69 	virtual ~CFeedParser();
       
    70 	
       
    71 public:
       
    72 	void ParseFeedL(const TFileName &feedFileName, CFeedInfo *item, TUint aMaxItems);
       
    73 	
       
    74 public: // from MContentHandler
       
    75 	void OnStartDocumentL(const Xml::RDocumentParameters& aDocParam, TInt aErrorCode);
       
    76 	void OnEndDocumentL(TInt aErrorCode);
       
    77 	void OnStartElementL(const Xml::RTagInfo& aElement, const Xml::RAttributeArray& aAttributes, TInt aErrorCode);
       
    78 	void OnEndElementL(const Xml::RTagInfo& aElement, TInt aErrorCode);
       
    79 	void OnContentL(const TDesC8& aBytes, TInt aErrorCode);
       
    80 	void OnStartPrefixMappingL(const RString& aPrefix, const RString& aUri, TInt aErrorCode);
       
    81 	void OnEndPrefixMappingL(const RString& aPrefix, TInt aErrorCode);
       
    82 	void OnIgnorableWhiteSpaceL(const TDesC8& aBytes, TInt aErrorCode);
       
    83 	void OnSkippedEntityL(const RString& aName, TInt aErrorCode);
       
    84 	void OnProcessingInstructionL(const TDesC8& aTarget, const TDesC8& aData, TInt aErrorCode);
       
    85 	void OnError(TInt aErrorCode);
       
    86 	TAny* GetExtendedInterface(const TInt32 aUid);
       
    87 	CFeedInfo& ActiveFeed();
       
    88 private:
       
    89 	MFeedParserObserver& iCallbacks;
       
    90 	TFeedState iFeedState;
       
    91 
       
    92 	CShowInfo* iActiveShow;
       
    93 	CFeedInfo *iActiveFeed;
       
    94 
       
    95 	TBuf<KBufferLength> iBuffer;
       
    96 	
       
    97 	TUint iMaxItems;
       
    98 	TUint iItemsParsed;
       
    99 	TBool iStoppedParsing;
       
   100 	TEncoding iEncoding;
       
   101 	RFs& iRfs;
       
   102 };
       
   103 
       
   104 #endif