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 "OmahaXMLParser.h" |
| 6 |
| 7 @implementation OmahaXMLParser |
| 8 |
| 9 - (NSMutableArray*)chromeIncompleteDownloadURLs { |
| 10 return chromeIncompleteDownloadURLs_; |
| 11 } |
| 12 |
| 13 - (NSString*)chromeImageFilename { |
| 14 return chromeImageFilename_; |
| 15 } |
| 16 |
| 17 // Sets up instance of NSXMLParser and calls on delegate methods to do actual |
| 18 // parsing work. |
| 19 - (NSArray*)parseXML:(NSData*)omahaResponseXML error:(NSError**)error { |
| 20 NSXMLParser* parser = [[NSXMLParser alloc] initWithData:omahaResponseXML]; |
| 21 [parser setDelegate:self]; |
| 22 BOOL success = [parser parse]; |
| 23 if (!success) { |
| 24 *error = [parser parserError]; |
| 25 } |
| 26 |
| 27 return chromeIncompleteDownloadURLs_; |
| 28 } |
| 29 |
| 30 // Method implementation for XMLParserDelegate. |
| 31 // Searches the XML data for the tag "URL" and the subsequent "codebase" |
| 32 // attribute that indicates a URL follows. Copies each URL into an array. |
| 33 // Note that the URLs in the XML file are incomplete. They need the filename |
| 34 // appended to end. The second if statement checks for the tag "package" which |
| 35 // contains the filename we need to complete the URLs. |
| 36 - (void)parser:(NSXMLParser*)parser |
| 37 didStartElement:(NSString*)elementName |
| 38 namespaceURI:(NSString*)namespaceURI |
| 39 qualifiedName:(NSString*)qName |
| 40 attributes:(NSDictionary*)attributeDict { |
| 41 if ([elementName isEqualToString:@"url"]) { |
| 42 if (!chromeIncompleteDownloadURLs_) { |
| 43 chromeIncompleteDownloadURLs_ = [[NSMutableArray alloc] init]; |
| 44 } |
| 45 NSString* extractedURL = [attributeDict objectForKey:@"codebase"]; |
| 46 [chromeIncompleteDownloadURLs_ addObject:extractedURL]; |
| 47 } |
| 48 if ([elementName isEqualToString:@"package"]) { |
| 49 chromeImageFilename_ = [[NSString alloc] |
| 50 initWithFormat:@"%@", [attributeDict objectForKey:@"name"]]; |
| 51 } |
| 52 } |
| 53 |
| 54 @end |
OLD | NEW |