Permalink
Browse files

Initial commit

  • Loading branch information...
Michael Waterfall
Michael Waterfall committed May 16, 2010
0 parents commit ed810b051c43cbd64496cbec1a01c8f4733c03af
@@ -0,0 +1,24 @@
+# Ignore some Xcode auto-generated files
+build/
+*~.nib/
+
+# Ignore user specific Xcode files
+# As only 1 developer, don't ignore them (breakpoints, env. vars etc)
+#*.perspective
+#*.perspectivev3
+#*.pbxuser
+#*.mode1v3
+#*.mode2v3
+
+# OS X noise
+.DS_Store
+profile
+
+# Backups created by text editors
+*~
+*.bak
+
+# Object/generated files
+*.o
+*.pyc
+*.pyo
@@ -0,0 +1,23 @@
+//
+// MWFeedInfo.h
+// XML
+//
+// Created by Michael Waterfall on 10/05/2010.
+// Copyright 2010 d3i. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface MWFeedInfo : NSObject {
+
+ NSString *title;
+ NSString *link;
+ NSString *summary;
+
+}
+
+@property (nonatomic, copy) NSString *title;
+@property (nonatomic, copy) NSString *link;
+@property (nonatomic, copy) NSString *summary;
+
+@end
@@ -0,0 +1,23 @@
+//
+// MWFeedInfo.m
+// XML
+//
+// Created by Michael Waterfall on 10/05/2010.
+// Copyright 2010 d3i. All rights reserved.
+//
+
+#import "MWFeedInfo.h"
+
+@implementation MWFeedInfo
+
+@synthesize title, link, summary;
+
+- (NSString *)description {
+ NSMutableString *string = [[NSMutableString alloc] initWithString:@"\nMWFeedInfo\n"];
+ if (title) [string appendFormat:@"Title: %@\n", title];
+ if (link) [string appendFormat:@"Link: %@\n", link];
+ if (summary) [string appendFormat:@"Summary: %@", summary];
+ return [string autorelease];
+}
+
+@end
@@ -0,0 +1,27 @@
+//
+// MWFeedItem.h
+// XML
+//
+// Created by Michael Waterfall on 10/05/2010.
+// Copyright 2010 d3i. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface MWFeedItem : NSObject {
+
+ NSString *title;
+ NSString *link;
+ NSString *summary; // Description of item
+ NSString *content; // More detailed content (if available)
+ NSDate *date;
+
+}
+
+@property (nonatomic, copy) NSString *title;
+@property (nonatomic, copy) NSString *link;
+@property (nonatomic, copy) NSString *summary;
+@property (nonatomic, copy) NSString *content;
+@property (nonatomic, copy) NSDate *date;
+
+@end
@@ -0,0 +1,25 @@
+//
+// MWFeedItem.m
+// XML
+//
+// Created by Michael Waterfall on 10/05/2010.
+// Copyright 2010 d3i. All rights reserved.
+//
+
+#import "MWFeedItem.h"
+
+@implementation MWFeedItem
+
+@synthesize title, link, summary, content, date;
+
+- (NSString *)description {
+ NSMutableString *string = [[NSMutableString alloc] initWithString:@"\nMWFeedItem\n"];
+ if (title) [string appendFormat:@"Title: %@\n", title];
+ if (link) [string appendFormat:@"Link: %@\n", link];
+ if (date) [string appendFormat:@"Date: %@\n", date];
+ if (summary) [string appendFormat:@"Summary: %@\n", summary];
+ if (content) [string appendFormat:@"Content: %@", content];
+ return [string autorelease];
+}
+
+@end
@@ -0,0 +1,101 @@
+//
+// MWFeedParser.h
+// XML
+//
+// Created by Michael Waterfall on 08/05/2010.
+// Copyright 2010 d3i. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "MWFeedInfo.h"
+#import "MWFeedItem.h"
+
+// Debug Logging
+#if 0
+#define MWLog(x, ...) NSLog(x, ## __VA_ARGS__);
+#else
+#define MWLog(x, ...)
+#endif
+
+// Class
+@class MWFeedParser;
+
+// Types
+typedef enum { ConnectionTypeAsynchronously, ConnectionTypeSynchronously } ConnectionType;
+typedef enum { ParseTypeFull, ParseTypeItemsOnly, ParseTypeInfoOnly } ParseType;
+typedef enum { FeedTypeUnknown, FeedTypeRSS, FeedTypeAtom } FeedType;
+
+// Delegate
+@protocol MWFeedParserDelegate <NSObject>
+@optional
+- (void)feedParserDidStart:(MWFeedParser *)parser;
+- (void)feedParser:(MWFeedParser *)parser didParseFeedInfo:(MWFeedInfo *)info;
+- (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item;
+- (void)feedParserDidFinish:(MWFeedParser *)parser;
+- (void)feedParser:(MWFeedParser *)parser didFailWithError:(NSError *)error;
+@end
+
+// Class
+@interface MWFeedParser : NSObject {
+
+ // Required
+ id <MWFeedParserDelegate> delegate;
+ NSString *url;
+
+ // Connection
+ NSURLConnection *urlConnection;
+ NSMutableData *asyncData;
+ ConnectionType connectionType;
+
+ // Parsing
+ ParseType feedParseType;
+ NSXMLParser *feedParser;
+ FeedType feedType;
+ NSDateFormatter *dateFormatterRFC822, *dateFormatterRFC3339;
+ BOOL hasEncounteredItems; // Whether the parser has started parsing items
+ BOOL aborted; // Whether parse stopped due to abort
+
+ // Parsing Data
+ NSString *currentPath;
+ NSMutableString *currentText;
+ NSDictionary *currentElementAttributes;
+ MWFeedItem *item;
+ MWFeedInfo *info;
+
+}
+
+// Properties
+@property (nonatomic, assign) id <MWFeedParserDelegate> delegate;
+@property (nonatomic, copy) NSString *url;
+
+// Feed Downloading Properties
+@property (nonatomic, retain) NSURLConnection *urlConnection;
+@property (nonatomic, retain) NSMutableData *asyncData;
+@property (nonatomic) ConnectionType connectionType;
+
+// Parsing Properties
+@property (nonatomic) ParseType feedParseType;
+@property (nonatomic, retain) NSXMLParser *feedParser;
+@property (nonatomic, retain) NSString *currentPath;
+@property (nonatomic, retain) NSMutableString *currentText;
+@property (nonatomic, retain) NSDictionary *currentElementAttributes;
+@property (nonatomic, retain) MWFeedItem *item;
+@property (nonatomic, retain) MWFeedInfo *info;
+
+// NSObject Methods
+- (id)initWithFeedURL:(NSString *)feedURL;
+
+// Parsing Methods
+- (void)reset;
+- (void)parse;
+- (void)startParsingData:(NSData *)data;
+
+// Misc
+- (void)finishParsing;
+- (NSString *)linkFromAtomLinkAttributes:(NSDictionary *)attributes;
+
+// Dates
+- (NSDate *)dateFromRFC822String:(NSString *)dateString;
+- (NSDate *)dateFromRFC3339String:(NSString *)dateString;
+
+@end
Oops, something went wrong.

0 comments on commit ed810b0

Please sign in to comment.