From f478705b5f0e078891b10aa2f1b93f1977b2ddfc Mon Sep 17 00:00:00 2001 From: Matt Mower Date: Wed, 18 Feb 2009 13:38:01 +0000 Subject: [PATCH] Updated parsing to work with document based app. --- English.lproj/ParsingProgress.xib | 283 ++++++++++++++++++++++++++++++ LogParser.h | 17 +- LogParser.m | 52 +++--- ParsingProgressController.h | 22 +++ ParsingProgressController.m | 35 ++++ 5 files changed, 379 insertions(+), 30 deletions(-) create mode 100644 English.lproj/ParsingProgress.xib create mode 100644 ParsingProgressController.h create mode 100644 ParsingProgressController.m diff --git a/English.lproj/ParsingProgress.xib b/English.lproj/ParsingProgress.xib new file mode 100644 index 0000000..d29427b --- /dev/null +++ b/English.lproj/ParsingProgress.xib @@ -0,0 +1,283 @@ + + + + 1050 + 9G55 + 677 + 949.43 + 353.00 + + YES + + + YES + com.apple.InterfaceBuilderKit + com.apple.InterfaceBuilder.CocoaPlugin + + + YES + + YES + + + YES + + + + YES + + ParsingProgressController + + + FirstResponder + + + NSApplication + + + 17 + 2 + {{763, 536}, {488, 111}} + -1543502848 + Logile Analysis + NSPanel + + {3.40282e+38, 3.40282e+38} + + + 256 + + YES + + + 1290 + + {{18, 47}, {452, 20}} + + 16392 + 2.000000e+01 + 1.000000e+02 + + + + 268 + {{17, 75}, {110, 17}} + + YES + + 68288064 + 272630784 + Loading logfile... + + LucidaGrande + 1.300000e+01 + 1044 + + + + 6 + System + controlColor + + 3 + MC42NjY2NjY2OQA + + + + 6 + System + controlTextColor + + 3 + MAA + + + + + + {488, 111} + + {{0, 0}, {1920, 1178}} + {3.40282e+38, 3.40282e+38} + + + + + YES + + + panel + + + + 11 + + + + indicator + + + + 12 + + + + window + + + + 13 + + + + + YES + + 0 + + YES + + + + + + -2 + + + RmlsZSdzIE93bmVyA + + + -1 + + + First Responder + + + -3 + + + Application + + + 1 + + + YES + + + + Progress Panel + + + 2 + + + YES + + + + + + + 3 + + + YES + + + + + + 4 + + + + + 5 + + + + + + + YES + + YES + -1.IBPluginDependency + -2.IBPluginDependency + -3.IBPluginDependency + 1.IBEditorWindowLastContentRect + 1.IBWindowTemplateEditedContentRect + 1.NSWindowTemplate.visibleAtLaunch + 2.IBPluginDependency + 3.IBPluginDependency + 4.IBPluginDependency + 5.IBPluginDependency + + + YES + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilderKit + com.apple.InterfaceBuilderKit + {{641, 679}, {488, 111}} + {{641, 679}, {488, 111}} + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + + + YES + + YES + + + YES + + + + + YES + + YES + + + YES + + + + 13 + + + + YES + + ParsingProgressController + NSWindowController + + YES + + YES + indicator + panel + + + YES + NSProgressIndicator + NSPanel + + + + IBProjectSource + ParsingProgressController.h + + + + + 0 + Spike.xcodeproj + 3 + + diff --git a/LogParser.h b/LogParser.h index 33ef848..f2323b8 100644 --- a/LogParser.h +++ b/LogParser.h @@ -9,19 +9,20 @@ #import @class RailsRequest; -@class AppController; +@class LogDocument; @class ParamParser; +@class ParsingProgressController; @interface LogParser : NSObject { - AppController *appController; - NSDateFormatter *dateParser; - ParamParser *paramParser; + LogDocument *document; + NSDateFormatter *dateParser; + ParamParser *paramParser; + + ParsingProgressController *progressController; } -- (id)initWithAppController:(AppController *)theAppController; +- (id)initWithDocument:(LogDocument *)theDocument; -- (NSArray *)parseLogFile:(NSString *)logFileName; -- (NSArray *)parseLogLines:(NSArray *)lines; -- (RailsRequest *)parseRequest:(NSArray *)lines; +- (NSArray *)parseLogData:(NSData *)data; @end diff --git a/LogParser.m b/LogParser.m index 47a4c73..861f6f3 100644 --- a/LogParser.m +++ b/LogParser.m @@ -10,12 +10,15 @@ #import +#import "LogDocument.h" #import "RailsRequest.h" #import "ParamParser.h" #import "Parameter.h" -#import "AppController.h" +#import "ParsingProgressController.h" -@interface LogParser () +@interface LogParser (PrivateMethods) +- (RailsRequest *)parseRequest:(NSArray *)lines; +- (NSArray *)parseLogLines:(NSArray *)lines; - (void)scanProcessing:(NSString *)line intoRequest:(RailsRequest *)request; - (void)scanParameters:(NSString *)line intoRequest:(RailsRequest *)request; - (void)scanSession:(NSString *)line intoRequest:(RailsRequest *)request; @@ -27,9 +30,9 @@ - (void)scanFilter:(NSString *)line intoRequest:(RailsRequest *)request; @implementation LogParser -- (id)initWithAppController:(AppController *)theAppController { +- (id)initWithDocument:(LogDocument *)theDocument { if( ( self = [super init] ) ) { - appController = theAppController; + document = theDocument; dateParser = [[NSDateFormatter alloc] init]; [dateParser setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; @@ -40,25 +43,29 @@ - (id)initWithAppController:(AppController *)theAppController { } -- (NSArray *)parseLogFile:(NSString *)logFileName { - [[appController progressPanel] makeKeyAndOrderFront:self]; - [[appController progressIndicator] setIndeterminate:YES]; - NSArray *logContent = [[NSString stringWithContentsOfFile:logFileName] componentsSeparatedByString:@"\n"]; - return [self parseLogLines:logContent]; +- (NSArray *)parseLogData:(NSData *)data { + progressController = [[ParsingProgressController alloc] init]; + [progressController showWindow:self]; + + NSString *content = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; + + NSArray *lines = [content componentsSeparatedByString:@"\n"]; + NSLog( @"%d lines to parse.", [lines count] ); + [progressController setMin:0 max:[lines count]]; + + NSArray *requests = [self parseLogLines:lines]; + NSLog( @"%d requests parsed.", [requests count] ); + [progressController close]; + + return requests; } - (NSArray *)parseLogLines:(NSArray *)lines { NSMutableArray *requests = [[NSMutableArray alloc] init]; - double linesProcessed = 0.0; - - [[appController progressIndicator] setMinValue:0]; - [[appController progressIndicator] setMaxValue:[lines count]]; - [[appController progressIndicator] setDoubleValue:linesProcessed]; - [[appController progressIndicator] setIndeterminate:NO]; - - NSLog( @"%d lines to parse.", [lines count] ); + double linesProcessed = 0.0; + BOOL hitFirstValidEntry = NO; NSMutableArray *lineGroup = [[NSMutableArray alloc] init]; @@ -72,18 +79,19 @@ - (NSArray *)parseLogLines:(NSArray *)lines { [lineGroup removeAllObjects]; // break; } + + hitFirstValidEntry = YES; } - [lineGroup addObject:line]; + if( hitFirstValidEntry ) { + [lineGroup addObject:line]; + } } linesProcessed += 1; - [[appController progressIndicator] setDoubleValue:linesProcessed]; + [progressController update:linesProcessed]; } - NSLog( @"%d requests parsed.", [requests count] ); - - [[appController progressPanel] orderOut:self]; return requests; } diff --git a/ParsingProgressController.h b/ParsingProgressController.h new file mode 100644 index 0000000..3e8fe91 --- /dev/null +++ b/ParsingProgressController.h @@ -0,0 +1,22 @@ +// +// ParsingProgressController.h +// Spike +// +// Created by Matt Mower on 18/02/2009. +// Copyright 2009 LucidMac Software. All rights reserved. +// + +#import + +@interface ParsingProgressController : NSWindowController { + IBOutlet NSPanel *panel; + IBOutlet NSProgressIndicator *indicator; +} + +@property NSPanel *panel; +@property NSProgressIndicator *indicator; + +- (void)setMin:(double)min max:(double)max; +- (void)update:(double)value; + +@end diff --git a/ParsingProgressController.m b/ParsingProgressController.m new file mode 100644 index 0000000..379768f --- /dev/null +++ b/ParsingProgressController.m @@ -0,0 +1,35 @@ +// +// ParsingProgressController.m +// Spike +// +// Created by Matt Mower on 18/02/2009. +// Copyright 2009 LucidMac Software. All rights reserved. +// + +#import "ParsingProgressController.h" + +@implementation ParsingProgressController + +@synthesize panel; +@synthesize indicator; + +- (id)init { + return [self initWithWindowNibName:@"ParsingProgress"]; +} + +- (void)windowDidLoad { + [indicator setIndeterminate:YES]; +} + +- (void)setMin:(double)min max:(double)max { + [indicator setMinValue:min]; + [indicator setMaxValue:max]; + [indicator setDoubleValue:min]; + [indicator setIndeterminate:NO]; +} + +- (void)update:(double)value { + [indicator setDoubleValue:value]; +} + +@end