Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "parser.h" | |
| 6 | |
| 7 @implementation Parser | |
| 8 | |
| 9 //- (id)initWithXML:(NSData*)omahaResponseXML{ | |
|
Elly Fong-Jones
2016/07/11 16:15:48
you can remove the dead code :)
| |
| 10 // if ((self = [super init])) { | |
| 11 // omahaResponseXML_ = omahaResponseXML; | |
| 12 // } | |
| 13 // return self; | |
| 14 //} | |
| 15 | |
| 16 - (NSMutableArray*)chromeIncompleteDownloadURLs { | |
| 17 return chromeIncompleteDownloadURLs_; | |
| 18 } | |
| 19 | |
| 20 - (NSString*)chromeImageFilename { | |
| 21 return chromeImageFilename_; | |
| 22 } | |
| 23 | |
| 24 // Sets up instance of NSXMLParser and calls on delegate methods to do actual | |
| 25 // parsing work. | |
| 26 - (NSArray*)parseXML:(NSData*)omahaResponseXML error:(NSError**)error { | |
| 27 NSXMLParser* parser = [[NSXMLParser alloc] initWithData:omahaResponseXML]; | |
| 28 [parser setDelegate:self]; | |
| 29 BOOL success = [parser parse]; | |
| 30 if (!success) { | |
| 31 *error = [parser parserError]; | |
| 32 } | |
| 33 | |
| 34 return chromeIncompleteDownloadURLs_; | |
| 35 } | |
| 36 | |
| 37 // Method implementation for XMLParserDelegate. | |
| 38 // Searches the XML data for the tag "URL" and the subsequent "codebase" | |
| 39 // attribute that indicates a URL follows. Copies each URL into an array. | |
| 40 // Note that the URLs in the XML file are incomplete. They need the filename | |
| 41 // appended to end. The second if statement checks for the tag "package" which | |
| 42 // contains the filename we need to complete the URLs. | |
| 43 - (void)parser:(NSXMLParser*)parser | |
| 44 didStartElement:(NSString*)elementName | |
| 45 namespaceURI:(NSString*)namespaceURI | |
| 46 qualifiedName:(NSString*)qName | |
| 47 attributes:(NSDictionary*)attributeDict { | |
| 48 if ([elementName isEqualToString:@"url"]) { | |
| 49 if (!chromeIncompleteDownloadURLs_) { | |
| 50 chromeIncompleteDownloadURLs_ = [[NSMutableArray alloc] init]; | |
| 51 } | |
| 52 NSString* extractedURL = [attributeDict objectForKey:@"codebase"]; | |
| 53 [chromeIncompleteDownloadURLs_ addObject:extractedURL]; | |
| 54 } | |
| 55 if ([elementName isEqualToString:@"package"]) { | |
| 56 chromeImageFilename_ = [[NSString alloc] | |
| 57 initWithFormat:@"%@", [attributeDict objectForKey:@"name"]]; | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 @end | |
| OLD | NEW |