1
+ //
2
+ // MWFeedParser.h
3
+ // XML
4
+ //
5
+ // Created by Michael Waterfall on 08/05/2010.
6
+ // Copyright 2010 d3i. All rights reserved.
7
+ //
8
+
9
+ #import < Foundation/Foundation.h>
10
+ #import " MWFeedInfo.h"
11
+ #import " MWFeedItem.h"
12
+
13
+ // Debug Logging
14
+ #if 0
15
+ #define MWLog(x, ...) NSLog(x, ## __VA_ARGS__);
16
+ #else
17
+ #define MWLog (x, ...)
18
+ #endif
19
+
20
+ // Class
21
+ @class MWFeedParser;
22
+
23
+ // Types
24
+ typedef enum { ConnectionTypeAsynchronously, ConnectionTypeSynchronously } ConnectionType;
25
+ typedef enum { ParseTypeFull, ParseTypeItemsOnly, ParseTypeInfoOnly } ParseType;
26
+ typedef enum { FeedTypeUnknown, FeedTypeRSS, FeedTypeAtom } FeedType;
27
+
28
+ // Delegate
29
+ @protocol MWFeedParserDelegate <NSObject >
30
+ @optional
31
+ - (void )feedParserDidStart : (MWFeedParser *)parser ;
32
+ - (void )feedParser : (MWFeedParser *)parser didParseFeedInfo : (MWFeedInfo *)info ;
33
+ - (void )feedParser : (MWFeedParser *)parser didParseFeedItem : (MWFeedItem *)item ;
34
+ - (void )feedParserDidFinish : (MWFeedParser *)parser ;
35
+ - (void )feedParser : (MWFeedParser *)parser didFailWithError : (NSError *)error ;
36
+ @end
37
+
38
+ // Class
39
+ @interface MWFeedParser : NSObject {
40
+
41
+ // Required
42
+ id <MWFeedParserDelegate> delegate;
43
+ NSString *url;
44
+
45
+ // Connection
46
+ NSURLConnection *urlConnection;
47
+ NSMutableData *asyncData;
48
+ ConnectionType connectionType;
49
+
50
+ // Parsing
51
+ ParseType feedParseType;
52
+ NSXMLParser *feedParser;
53
+ FeedType feedType;
54
+ NSDateFormatter *dateFormatterRFC822, *dateFormatterRFC3339;
55
+ BOOL hasEncounteredItems; // Whether the parser has started parsing items
56
+ BOOL aborted; // Whether parse stopped due to abort
57
+
58
+ // Parsing Data
59
+ NSString *currentPath;
60
+ NSMutableString *currentText;
61
+ NSDictionary *currentElementAttributes;
62
+ MWFeedItem *item;
63
+ MWFeedInfo *info;
64
+
65
+ }
66
+
67
+ // Properties
68
+ @property (nonatomic , assign ) id <MWFeedParserDelegate> delegate;
69
+ @property (nonatomic , copy ) NSString *url;
70
+
71
+ // Feed Downloading Properties
72
+ @property (nonatomic , retain ) NSURLConnection *urlConnection;
73
+ @property (nonatomic , retain ) NSMutableData *asyncData;
74
+ @property (nonatomic ) ConnectionType connectionType;
75
+
76
+ // Parsing Properties
77
+ @property (nonatomic ) ParseType feedParseType;
78
+ @property (nonatomic , retain ) NSXMLParser *feedParser;
79
+ @property (nonatomic , retain ) NSString *currentPath;
80
+ @property (nonatomic , retain ) NSMutableString *currentText;
81
+ @property (nonatomic , retain ) NSDictionary *currentElementAttributes;
82
+ @property (nonatomic , retain ) MWFeedItem *item;
83
+ @property (nonatomic , retain ) MWFeedInfo *info;
84
+
85
+ // NSObject Methods
86
+ - (id )initWithFeedURL : (NSString *)feedURL ;
87
+
88
+ // Parsing Methods
89
+ - (void )reset ;
90
+ - (void )parse ;
91
+ - (void )startParsingData : (NSData *)data ;
92
+
93
+ // Misc
94
+ - (void )finishParsing ;
95
+ - (NSString *)linkFromAtomLinkAttributes : (NSDictionary *)attributes ;
96
+
97
+ // Dates
98
+ - (NSDate *)dateFromRFC822String : (NSString *)dateString ;
99
+ - (NSDate *)dateFromRFC3339String : (NSString *)dateString ;
100
+
101
+ @end
0 commit comments