NCXMLComments.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // NCXMLComments.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 08/08/19.
  6. // Copyright © 2018 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "NCXMLComments.h"
  24. @interface NCXMLComments()
  25. @property (nonatomic, strong) NSMutableString *xmlChars;
  26. @property (nonatomic, strong) NSMutableDictionary *xmlBucket;
  27. @end
  28. @implementation NCXMLComments
  29. /*
  30. * Method that init the parse with the xml data from the server
  31. * @data -> XML webDav data from the owncloud server
  32. */
  33. - (void)initParserWithData: (NSData*)data{
  34. NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
  35. [parser setDelegate:self];
  36. [parser parse];
  37. }
  38. #pragma mark - XML Parser Delegate Methods
  39. /*
  40. * Method that init parse process.
  41. */
  42. - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
  43. if (!self.xmlChars) {
  44. self.xmlChars = [NSMutableString string];
  45. }
  46. [self.xmlChars setString:@""];
  47. if ([elementName isEqualToString:@"ocs"]) {
  48. self.xmlBucket = [NSMutableDictionary dictionary];
  49. }
  50. }
  51. - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
  52. if ([elementName isEqualToString:@"statuscode"]) {
  53. self.statusCode = [self.xmlChars intValue];
  54. }
  55. if ([elementName isEqualToString:@"token"]) {
  56. self.token = [NSString stringWithString:self.xmlChars];
  57. }
  58. if ([elementName isEqualToString:@"message"]) {
  59. self.message = [NSString stringWithString:self.xmlChars];
  60. }
  61. if ([elementName isEqualToString:@"url"]) {
  62. self.url = [NSString stringWithString:self.xmlChars];
  63. }
  64. }
  65. - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
  66. [self.xmlChars appendString:string];
  67. }
  68. - (void)parserDidEndDocument:(NSXMLParser *)parser{
  69. NSLog(@"Finish xml directory list parse");
  70. }
  71. @end