瀏覽代碼

OCNotifications

Marino Faggiana 8 年之前
父節點
當前提交
d8c65cc2d0

+ 0 - 10
Libraries external/OCCommunicationLib/OCCommunicationLib/OCCommunication.h

@@ -767,15 +767,5 @@ typedef enum {
 /// @name Get the server Notification
 ///-----------------------------------
 
-/**
- * Method read the capabilities of the server
- *
- * @param serverPath  -> NSString server
- * @param sharedOCCommunication -> OCCommunication Singleton of communication to add the operation on the queue.
- *
- * @return capabilities -> OCCapabilities
- *
- */
-
 - (void) getNotificationsOfTheServer:(NSString*)serverPath onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, OCCapabilities *capabilities, NSString *redirectedServer)) successRequest failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest;
 @end

+ 50 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCNotifications.h

@@ -0,0 +1,50 @@
+//
+//  OCNotifications.h
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 23/01/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface OCNotificationsAction : NSObject
+
+@property (nonatomic, strong) NSString *label;
+@property (nonatomic, strong) NSString *link;
+@property (nonatomic, strong) NSString *type;
+@property BOOL primary;
+
+@end
+
+@interface OCRichObjectStrings : NSObject
+
+@property (nonatomic, strong) NSString *idObject;
+@property (nonatomic, strong) NSString *type;
+@property (nonatomic, strong) NSString *name;
+@property (nonatomic, strong) NSString *path;
+@property (nonatomic, strong) NSString *link;
+@property (nonatomic, strong) NSString *server;
+
+@end
+
+@interface OCNotifications : NSObject
+
+@property NSInteger idNotification;
+@property (nonatomic, strong) NSString *app;
+@property (nonatomic, strong) NSString *user;
+@property long date;
+@property (nonatomic, strong) NSString *typeObject;
+@property (nonatomic, strong) NSString *idObject;
+@property (nonatomic, strong) NSString *subject;
+@property (nonatomic, strong) NSString *subjectRich;
+@property (nonatomic, strong) OCRichObjectStrings *subjectRichParameters;
+@property (nonatomic, strong) NSString *message;
+@property (nonatomic, strong) NSString *messageRich;
+@property (nonatomic, strong) OCRichObjectStrings *messageRichParameters;
+@property (nonatomic, strong) NSString *link;
+@property (nonatomic, strong) NSString *icon;
+@property (nonatomic, strong) OCNotificationsAction *action;
+
+@end
+

+ 13 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCNotifications.m

@@ -0,0 +1,13 @@
+//
+//  OCNotifications.m
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 23/01/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import "OCNotifications.h"
+
+@implementation OCNotifications
+
+@end

+ 27 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCXMLNotificationsParser.h

@@ -0,0 +1,27 @@
+//
+//  OCXMLNotificationsParser.h
+//  ownCloud iOS library
+//
+//  Created by Marino Faggiana on 23/01/17.
+//  Copyright © 2017 ownCloud. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "OCNotifications.h"
+
+@interface OCXMLNotificationsParser : NSObject <NSXMLParserDelegate> {
+
+    NSMutableString *_xmlChars;
+    NSMutableDictionary *_xmlBucket;
+    NSMutableArray *_notificationList;
+    OCNotifications *_currentNotification;
+    BOOL isNotFirstFileOfList;
+}
+
+@property(nonatomic,strong) NSMutableArray *notificationList;
+@property(nonatomic,strong) OCNotifications *currentNotification;
+
+- (void)initParserWithData: (NSData*)data;
+
+
+@end

+ 81 - 0
Libraries external/OCCommunicationLib/OCCommunicationLib/OCXMLNotificationsParser.m

@@ -0,0 +1,81 @@
+//
+//  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 notificationList=_notificationList;
+@synthesize currentNotification=_currentNotification;
+
+
+/*
+ * Method that init the parse with the xml data from the server
+ * @data -> XML webDav data from the owncloud server
+ */
+- (void)initParserWithData: (NSData*)data{
+    
+    _notificationList = [[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

+ 12 - 0
Libraries external/OCCommunicationLib/ownCloud iOS library.xcodeproj/project.pbxproj

@@ -48,6 +48,8 @@
 		EAABAB39185B353100909831 /* test.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = EAABAB38185B353100909831 /* test.jpeg */; };
 		EAABAB3C185EE33B00909831 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAABAB3B185EE33B00909831 /* UIKit.framework */; };
 		EAABAB40185F225300909831 /* video.MOV in Resources */ = {isa = PBXBuildFile; fileRef = EAABAB3F185F225300909831 /* video.MOV */; };
+		F71DB38D1E35FAD80057BEE3 /* OCNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = F71DB38C1E35FAD80057BEE3 /* OCNotifications.m */; };
+		F71DB3901E36111E0057BEE3 /* OCXMLNotificationsParser.m in Sources */ = {isa = PBXBuildFile; fileRef = F71DB38F1E36111E0057BEE3 /* OCXMLNotificationsParser.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -135,6 +137,10 @@
 		EAABAB38185B353100909831 /* test.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; name = test.jpeg; path = Resources/test.jpeg; sourceTree = "<group>"; };
 		EAABAB3B185EE33B00909831 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
 		EAABAB3F185F225300909831 /* video.MOV */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; name = video.MOV; path = Resources/video.MOV; sourceTree = "<group>"; };
+		F71DB38B1E35FAD80057BEE3 /* OCNotifications.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCNotifications.h; sourceTree = "<group>"; };
+		F71DB38C1E35FAD80057BEE3 /* OCNotifications.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCNotifications.m; sourceTree = "<group>"; };
+		F71DB38E1E36111E0057BEE3 /* OCXMLNotificationsParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCXMLNotificationsParser.h; sourceTree = "<group>"; };
+		F71DB38F1E36111E0057BEE3 /* OCXMLNotificationsParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCXMLNotificationsParser.m; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -164,6 +170,8 @@
 		13AA8637187C331F00A10927 /* Parsers */ = {
 			isa = PBXGroup;
 			children = (
+				F71DB38E1E36111E0057BEE3 /* OCXMLNotificationsParser.h */,
+				F71DB38F1E36111E0057BEE3 /* OCXMLNotificationsParser.m */,
 				131C67B7187C3E360009030E /* OCXMLSharedParser.h */,
 				131C67B8187C3E360009030E /* OCXMLSharedParser.m */,
 				13AA863E187C3B9700A10927 /* OCXMLParser.h */,
@@ -211,6 +219,8 @@
 			children = (
 				EAABAA30183E688900909831 /* OCFileDto.h */,
 				EAABAA31183E688900909831 /* OCFileDto.m */,
+				F71DB38B1E35FAD80057BEE3 /* OCNotifications.h */,
+				F71DB38C1E35FAD80057BEE3 /* OCNotifications.m */,
 				EA0599981BB96D14002C2864 /* OCShareUser.h */,
 				EA0599991BB96D14002C2864 /* OCShareUser.m */,
 				13AA8634187C211900A10927 /* OCSharedDto.h */,
@@ -426,10 +436,12 @@
 				1345E4601884213400153F14 /* OCXMLShareByLinkParser.m in Sources */,
 				59A5B720191907F100724BE3 /* AFSecurityPolicy.m in Sources */,
 				EAABAA32183E688900909831 /* OCFileDto.m in Sources */,
+				F71DB38D1E35FAD80057BEE3 /* OCNotifications.m in Sources */,
 				EA7CC934183E150000B6A4B4 /* OCCommunication.m in Sources */,
 				131C67B9187C3E360009030E /* OCXMLSharedParser.m in Sources */,
 				13AA8640187C3B9700A10927 /* OCXMLParser.m in Sources */,
 				EA7CC912183E146000B6A4B4 /* UtilsFramework.m in Sources */,
+				F71DB3901E36111E0057BEE3 /* OCXMLNotificationsParser.m in Sources */,
 				EA7CC92A183E14A100B6A4B4 /* NSDate+RFC1123.m in Sources */,
 				13AA8636187C211900A10927 /* OCSharedDto.m in Sources */,
 				EA7CC928183E14A100B6A4B4 /* NSDate+ISO8601.m in Sources */,