|
@@ -1,81 +0,0 @@
|
|
|
-//
|
|
|
-// OCXMLNotificationsParser.m
|
|
|
-// ownCloud iOS library
|
|
|
-//
|
|
|
-// Created by Marino Faggiana on 23/01/17.
|
|
|
-// Copyright © 2017 ownCloud. All rights reserved.
|
|
|
-//
|
|
|
-
|
|
|
-#import "OCXMLNotificationsParser.h"
|
|
|
-
|
|
|
-@implementation OCXMLNotificationsParser
|
|
|
-
|
|
|
-@synthesize notificationsList =_notificationsList;
|
|
|
-@synthesize currentNotifications =_currentNotifications;
|
|
|
-
|
|
|
-
|
|
|
-/*
|
|
|
- * Method that init the parse with the xml data from the server
|
|
|
- * @data -> XML webDav data from the owncloud server
|
|
|
- */
|
|
|
-- (void)initParserWithData: (NSData*)data{
|
|
|
-
|
|
|
- _notificationsList = [[NSMutableArray alloc]init];
|
|
|
-
|
|
|
- NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
|
|
|
- [parser setDelegate:self];
|
|
|
- [parser parse];
|
|
|
-}
|
|
|
-
|
|
|
-/*
|
|
|
- * Method that init parse process.
|
|
|
- */
|
|
|
-
|
|
|
-- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
|
|
|
-
|
|
|
- if (!_xmlChars) {
|
|
|
- _xmlChars = [NSMutableString string];
|
|
|
- }
|
|
|
-
|
|
|
- //NSLog(@"_xmlChars: %@", _xmlChars);
|
|
|
-
|
|
|
- [_xmlChars setString:@""];
|
|
|
-
|
|
|
- if ([elementName isEqualToString:@"d:response"]) {
|
|
|
- _xmlBucket = [NSMutableDictionary dictionary];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/*
|
|
|
- * Util method to make a NSDate object from a string from xml
|
|
|
- * @dateString -> Data string from xml
|
|
|
- */
|
|
|
-+ (NSDate*)parseDateString:(NSString*)dateString {
|
|
|
- //Parse the date in all the formats
|
|
|
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
- /*In most cases the best locale to choose is "en_US_POSIX", a locale that's specifically designed to yield US English results regardless of both user and system preferences. "en_US_POSIX" is also invariant in time (if the US, at some point in the future, changes the way it formats dates, "en_US" will change to reflect the new behaviour, but "en_US_POSIX" will not). It will behave consistently for all users.*/
|
|
|
- [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
|
|
|
- //This is the format for the concret locale used
|
|
|
- [dateFormatter setDateFormat:@"EEE, dd MMM y HH:mm:ss zzz"];
|
|
|
-
|
|
|
- NSDate *theDate = nil;
|
|
|
- NSError *error = nil;
|
|
|
- if (![dateFormatter getObjectValue:&theDate forString:dateString range:nil error:&error]) {
|
|
|
- NSLog(@"Date '%@' could not be parsed: %@", dateString, error);
|
|
|
- }
|
|
|
-
|
|
|
- return theDate;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-// Decode a percent escape encoded string.
|
|
|
-- (NSString*) decodeFromPercentEscapeString:(NSString *) string {
|
|
|
- return (__bridge NSString *) CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,
|
|
|
- (__bridge CFStringRef) string,
|
|
|
- CFSTR(""),
|
|
|
- kCFStringEncodingUTF8);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-@end
|