Source/DCMessageContextDisplayPlugin.m
changeset 2822 2a385da3eace
parent 2821 fa988de96a94
child 2823 24c471ce6c9e
     1.1 --- a/Source/DCMessageContextDisplayPlugin.m	Wed Nov 25 22:34:07 2009 -0500
     1.2 +++ b/Source/DCMessageContextDisplayPlugin.m	Wed Nov 25 22:41:51 2009 -0500
     1.3 @@ -164,6 +164,9 @@
     1.4  	//Initialize a place to store found messages
     1.5  	NSMutableArray *outerFoundContentContexts = [NSMutableArray arrayWithCapacity:linesLeftToFind]; 
     1.6  
     1.7 +	// These set of file's autorelease pool.
     1.8 +	NSAutoreleasePool *parsingAutoreleasePool = [[NSAutoreleasePool alloc] init];
     1.9 +	
    1.10  	//Iterate over the elements of the log path array.
    1.11  	NSEnumerator *pathsEnumerator = [logPaths objectEnumerator];
    1.12  	NSString *logPath = nil;
    1.13 @@ -193,8 +196,8 @@
    1.14  		}
    1.15  
    1.16  		//Initialize the found messages array and element stack for us-as-delegate
    1.17 -		foundMessages = [NSMutableArray arrayWithCapacity:linesLeftToFind];
    1.18 -		elementStack = [NSMutableArray array];
    1.19 +		NSMutableArray *foundMessages = [NSMutableArray arrayWithCapacity:linesLeftToFind];
    1.20 +		NSMutableArray *elementStack = [NSMutableArray array];
    1.21  
    1.22  		//Create the parser and set ourselves as the delegate
    1.23  		LMXParser *parser = [LMXParser parser];
    1.24 @@ -216,6 +219,8 @@
    1.25  						   chat, @"Chat",
    1.26  						   decoder, @"AIHTMLDecoder",
    1.27  						   [NSValue valueWithPointer:&linesLeftToFind], @"LinesLeftToFindValue",
    1.28 +						   foundMessages, @"FoundMessages",
    1.29 +						   elementStack, @"ElementStack",
    1.30  						   nil];
    1.31  			[parser setContextInfo:(void *)contextInfo];
    1.32  		}
    1.33 @@ -232,8 +237,6 @@
    1.34  		off_t offset = [file offsetInFile];
    1.35  		enum LMXParseResult result = LMXParsedIncomplete;
    1.36  
    1.37 -		parsingAutoreleasePool = [[NSAutoreleasePool alloc] init];
    1.38 -
    1.39  		do {
    1.40  			//Calculate the new offset
    1.41  			offset = (offset <= readSize) ? 0 : offset - readSize;
    1.42 @@ -252,8 +255,8 @@
    1.43  		//Continue to parse as long as we need more elements, we have data to read, and LMX doesn't think we're done.
    1.44  		} while ([foundMessages count] < linesLeftToFind && offset > 0 && result != LMXParsedCompletely);
    1.45  
    1.46 -		//Pop our autorelease pool.
    1.47 -		[parsingAutoreleasePool release]; parsingAutoreleasePool = nil;
    1.48 +		//Drain our autorelease pool.
    1.49 +		[parsingAutoreleasePool drain];
    1.50  
    1.51  		//Be a good citizen and close the file
    1.52  		[file closeFile];
    1.53 @@ -263,6 +266,8 @@
    1.54  		linesLeftToFind -= [outerFoundContentContexts count];
    1.55  	}
    1.56  	
    1.57 +	[parsingAutoreleasePool release];
    1.58 +	
    1.59  	if (linesLeftToFind > 0) {
    1.60  		AILogWithSignature(@"Unable to find %d logs for %@", linesLeftToFind, chat);
    1.61  	}
    1.62 @@ -274,6 +279,9 @@
    1.63  
    1.64  - (void)parser:(LMXParser *)parser elementEnded:(NSString *)elementName
    1.65  {
    1.66 +	NSMutableDictionary *contextInfo = [parser contextInfo];
    1.67 +	NSMutableArray *elementStack = [contextInfo objectForKey:@"ElementStack"];
    1.68 +	
    1.69  	if ([elementName isEqualToString:@"message"]) {
    1.70  		[elementStack insertObject:[AIXMLElement elementWithName:elementName] atIndex:0U];
    1.71  	}
    1.72 @@ -286,20 +294,27 @@
    1.73  
    1.74  - (void)parser:(LMXParser *)parser foundCharacters:(NSString *)string
    1.75  {
    1.76 +	NSMutableDictionary *contextInfo = [parser contextInfo];
    1.77 +	NSMutableArray *elementStack = [contextInfo objectForKey:@"ElementStack"];
    1.78 +	
    1.79  	if ([elementStack count])
    1.80  		[(AIXMLElement *)[elementStack objectAtIndex:0U] insertObject:string atIndex:0U];
    1.81  }
    1.82  
    1.83  - (void)parser:(LMXParser *)parser elementStarted:(NSString *)elementName attributes:(NSDictionary *)attributes
    1.84  {
    1.85 +	NSMutableDictionary *contextInfo = [parser contextInfo];
    1.86 +	NSMutableArray *elementStack = [contextInfo objectForKey:@"ElementStack"];
    1.87 +	
    1.88  	if ([elementStack count]) {
    1.89  		AIXMLElement *element = [elementStack objectAtIndex:0U];
    1.90  		if (attributes) {
    1.91  			[element setAttributeNames:[attributes allKeys] values:[attributes allValues]];
    1.92  		}
    1.93  		
    1.94 -		NSMutableDictionary *contextInfo = [parser contextInfo];
    1.95 -
    1.96 +		NSMutableArray	*foundMessages = [contextInfo objectForKey:@"FoundMessagesValue"];
    1.97 +		NSInteger	 *linesLeftToFind = [[contextInfo objectForKey:@"LinesLeftToFindValue"] pointerValue];
    1.98 +		
    1.99  		if ([elementName isEqualToString:@"message"]) {
   1.100  			//A message element has started!
   1.101  			//This means that we have all of this message now, and therefore can create a single content object from the AIXMLElement tree and then throw away that tree.
   1.102 @@ -353,8 +368,6 @@
   1.103  			}
   1.104  		}
   1.105  		
   1.106 -		NSInteger	 *linesLeftToFind = [[contextInfo objectForKey:@"LinesLeftToFindValue"] pointerValue];
   1.107 -
   1.108  		[elementStack removeObjectAtIndex:0U];
   1.109  		if ([foundMessages count] == *linesLeftToFind) {
   1.110  			if ([elementStack count]) [elementStack removeAllObjects];