OCXMLShareByLinkParser.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // OCXMLShareByLinkParser.m
  3. // OCCommunicationLib
  4. //
  5. // Created by Javier González on 1/13/14.
  6. // Copyright (c) 2014 ownCloud. All rights reserved.
  7. //
  8. // Copyright (C) 2016, ownCloud GmbH. ( http://www.owncloud.org/ )
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining a copy
  11. // of this software and associated documentation files (the "Software"), to deal
  12. // in the Software without restriction, including without limitation the rights
  13. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. // copies of the Software, and to permit persons to whom the Software is
  15. // furnished to do so, subject to the following conditions:
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. // THE SOFTWARE.
  25. //
  26. #import "OCXMLShareByLinkParser.h"
  27. @interface OCXMLShareByLinkParser()
  28. @property (nonatomic, strong) NSMutableString *xmlChars;
  29. @property (nonatomic, strong) NSMutableDictionary *xmlBucket;
  30. @end
  31. @implementation OCXMLShareByLinkParser
  32. /*
  33. * Method that init the parse with the xml data from the server
  34. * @data -> XML webDav data from the owncloud server
  35. */
  36. - (void)initParserWithData: (NSData*)data{
  37. NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
  38. [parser setDelegate:self];
  39. [parser parse];
  40. }
  41. #pragma mark - XML Parser Delegate Methods
  42. /*
  43. * Method that init parse process.
  44. */
  45. - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
  46. if (!self.xmlChars) {
  47. self.xmlChars = [NSMutableString string];
  48. }
  49. [self.xmlChars setString:@""];
  50. if ([elementName isEqualToString:@"ocs"]) {
  51. self.xmlBucket = [NSMutableDictionary dictionary];
  52. }
  53. }
  54. - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
  55. if ([elementName isEqualToString:@"statuscode"]) {
  56. self.statusCode = [self.xmlChars intValue];
  57. }
  58. if ([elementName isEqualToString:@"token"]) {
  59. self.token = [NSString stringWithString:self.xmlChars];
  60. }
  61. if ([elementName isEqualToString:@"message"]) {
  62. self.message = [NSString stringWithString:self.xmlChars];
  63. }
  64. if ([elementName isEqualToString:@"url"]) {
  65. self.url = [NSString stringWithString:self.xmlChars];
  66. }
  67. }
  68. - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
  69. [self.xmlChars appendString:string];
  70. }
  71. - (void)parserDidEndDocument:(NSXMLParser *)parser{
  72. NSLog(@"Finish xml directory list parse");
  73. }
  74. @end