From 3743b78fffb1ff4832209767e7b1ebd6fb01cf53 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 26 Oct 2010 18:20:46 +0000 Subject: [PATCH] Monotone-Parent: 652fb1324338399d044d5f01bb158d94080a27c0 Monotone-Revision: ea84b0da49761a54044bb70c2502171c1b981e86 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-10-26T18:20:46 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 12 ++++++++++ SoObjects/SOGo/NSDictionary+BSJSONAdditions.h | 6 ----- SoObjects/SOGo/NSDictionary+BSJSONAdditions.m | 21 ------------------ SoObjects/SOGo/NSString+Utilities.h | 3 +++ SoObjects/SOGo/NSString+Utilities.m | 22 ++++++++++++++++++- SoObjects/SOGo/SOGoCASSession.m | 2 +- SoObjects/SOGo/SOGoCache.m | 3 ++- SoObjects/SOGo/SOGoUserManager.m | 9 ++++---- SoObjects/SOGo/SOGoUserProfile.m | 2 +- UI/MainUI/SOGoRootPage.m | 5 ++--- UI/Scheduler/UIxComponentEditor.m | 5 ++--- 11 files changed, 49 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index e087f1f66..86066e5f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2010-10-26 Wolfgang Sourdeau + + * SoObjects/SOGo/NSString+Utilities.m (-objectFromJSONString): new + method replacing the one below in a more generic way. I.e. the + method will accept any JSON object as input and not only + dictionaries. + + * SoObjects/SOGo/NSDictionary+BSJSONAdditions.m + (+dictionaryWithJSONString:): removed method, replaced with + the more generic -[NSString objectFromJSONString] in + NSString+Utilities. + 2010-10-25 Wolfgang Sourdeau * SoObjects/SOGo/SOGoUserDefaults.m (-setContactCategories) diff --git a/SoObjects/SOGo/NSDictionary+BSJSONAdditions.h b/SoObjects/SOGo/NSDictionary+BSJSONAdditions.h index cf7f348d6..5d34e045d 100644 --- a/SoObjects/SOGo/NSDictionary+BSJSONAdditions.h +++ b/SoObjects/SOGo/NSDictionary+BSJSONAdditions.h @@ -41,9 +41,3 @@ extern const int jsonDoNotIndent; - (NSString *)jsonIndentStringForLevel:(int)level; @end - -@interface NSMutableDictionary (BSJSONAdditions) - -+ (NSMutableDictionary *)dictionaryWithJSONString:(NSString *)jsonString; - -@end diff --git a/SoObjects/SOGo/NSDictionary+BSJSONAdditions.m b/SoObjects/SOGo/NSDictionary+BSJSONAdditions.m index ba1dd9958..147493ee4 100644 --- a/SoObjects/SOGo/NSDictionary+BSJSONAdditions.m +++ b/SoObjects/SOGo/NSDictionary+BSJSONAdditions.m @@ -188,24 +188,3 @@ const int jsonDoNotIndent = -1; } @end - -@implementation NSMutableDictionary (BSJSONAdditions) - -+ (NSMutableDictionary *) dictionaryWithJSONString: (NSString *) jsonString -{ - NSScanner *scanner; - NSMutableDictionary *dictionary; - - dictionary = nil; - - if ([jsonString length] > 0) - { - scanner = [[NSScanner alloc] initWithString: jsonString]; - [scanner scanJSONObject:&dictionary]; - [scanner autorelease]; - } - - return dictionary; -} - -@end diff --git a/SoObjects/SOGo/NSString+Utilities.h b/SoObjects/SOGo/NSString+Utilities.h index d13892776..ab4199290 100644 --- a/SoObjects/SOGo/NSString+Utilities.h +++ b/SoObjects/SOGo/NSString+Utilities.h @@ -26,6 +26,7 @@ #import @class NSDictionary; +@class NSObject; @interface NSString (SOGoURLExtension) @@ -65,6 +66,8 @@ - (BOOL) isJSONString; +- (id) objectFromJSONString; + @end #endif /* NSSTRING_URL_H */ diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index b59b58291..0e37d761e 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -34,6 +34,7 @@ #import "NSArray+Utilities.h" #import "NSDictionary+BSJSONAdditions.h" #import "NSDictionary+URL.h" +#import "NSScanner+BSJSONAdditions.h" #import "NSString+Utilities.h" @@ -505,9 +506,28 @@ static NSMutableCharacterSet *safeLDIFStartChars = nil; NSDictionary *jsonData; #warning this method is a quick and dirty way of detecting the file-format - jsonData = [NSMutableDictionary dictionaryWithJSONString: self]; + jsonData = [self objectFromJSONString]; return (jsonData != nil); } +- (id) objectFromJSONString +{ + NSScanner *scanner; + NSObject *object; + + object = nil; + + if ([self length] > 0) + { + scanner = [[NSScanner alloc] initWithString: self]; + if (![scanner scanJSONValue: &object]) + object = nil; + [scanner autorelease]; + } + + return object; +} + + @end diff --git a/SoObjects/SOGo/SOGoCASSession.m b/SoObjects/SOGo/SOGoCASSession.m index 9cf96e79e..dbefa1683 100644 --- a/SoObjects/SOGo/SOGoCASSession.m +++ b/SoObjects/SOGo/SOGoCASSession.m @@ -141,7 +141,7 @@ jsonSession = [cache CASSessionWithTicket: ticket]; if ([jsonSession length]) { - sessionDict = [NSMutableDictionary dictionaryWithJSONString: jsonSession]; + sessionDict = [jsonSession objectFromJSONString]; ASSIGN (login, [sessionDict objectForKey: @"login"]); ASSIGN (pgt, [sessionDict objectForKey: @"pgt"]); ASSIGN (identifier, [sessionDict objectForKey: @"identifier"]); diff --git a/SoObjects/SOGo/SOGoCache.m b/SoObjects/SOGo/SOGoCache.m index 9b8b8203b..9d64d21a4 100644 --- a/SoObjects/SOGo/SOGoCache.m +++ b/SoObjects/SOGo/SOGoCache.m @@ -49,6 +49,7 @@ #import #import "NSDictionary+BSJSONAdditions.h" +#import "NSString+Utilities.h" #import "SOGoObject.h" #import "SOGoSystemDefaults.h" #import "SOGoUser.h" @@ -498,7 +499,7 @@ static memcached_st *handle = NULL; s = [self _valuesOfType: @"acl" forKey: thePath]; if (s) - return [NSMutableDictionary dictionaryWithJSONString: s]; + return [s objectFromJSONString]; return nil; } diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index 2ce189cbf..274bc9ee7 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -29,8 +29,9 @@ #import #import -#import "NSDictionary+BSJSONAdditions.h" #import "NSArray+Utilities.h" +#import "NSDictionary+BSJSONAdditions.h" +#import "NSString+Utilities.h" #import "SOGoDomainDefaults.h" #import "SOGoSource.h" #import "SOGoSystemDefaults.h" @@ -416,7 +417,7 @@ BOOL checkOK; jsonUser = [[SOGoCache sharedCache] userAttributesForLogin: _login]; - currentUser = [NSMutableDictionary dictionaryWithJSONString: jsonUser]; + currentUser = [jsonUser objectFromJSONString]; dictPassword = [currentUser objectForKey: @"password"]; if (currentUser && dictPassword) checkOK = ([dictPassword isEqualToString: _pwd]); @@ -458,7 +459,7 @@ BOOL didChange; jsonUser = [[SOGoCache sharedCache] userAttributesForLogin: login]; - currentUser = [NSMutableDictionary dictionaryWithJSONString: jsonUser]; + currentUser = [jsonUser objectFromJSONString]; dictPassword = [currentUser objectForKey: @"password"]; if ([self _sourceChangePasswordForLogin: login @@ -638,7 +639,7 @@ // Remove the "@" prefix used to identified groups in the ACL tables. aUID = [uid hasPrefix: @"@"] ? [uid substringFromIndex: 1] : uid; jsonUser = [[SOGoCache sharedCache] userAttributesForLogin: aUID]; - currentUser = [NSMutableDictionary dictionaryWithJSONString: jsonUser]; + currentUser = [jsonUser objectFromJSONString]; if (!([currentUser objectForKey: @"emails"] && [currentUser objectForKey: @"cn"])) { diff --git a/SoObjects/SOGo/SOGoUserProfile.m b/SoObjects/SOGo/SOGoUserProfile.m index 4a655f2ca..27d07f6a7 100644 --- a/SoObjects/SOGo/SOGoUserProfile.m +++ b/SoObjects/SOGo/SOGoUserProfile.m @@ -195,7 +195,7 @@ defFlags.modified = NO; [values release]; jsonValue = [self jsonRepresentation]; - values = [NSMutableDictionary dictionaryWithJSONString: jsonValue]; + values = [jsonValue objectFromJSONString]; if (values) [values retain]; else diff --git a/UI/MainUI/SOGoRootPage.m b/UI/MainUI/SOGoRootPage.m index 842da7402..3d537eec8 100644 --- a/UI/MainUI/SOGoRootPage.m +++ b/UI/MainUI/SOGoRootPage.m @@ -43,8 +43,7 @@ #import -#import -#import +#import #import #import #import @@ -408,7 +407,7 @@ WOCookie *authCookie; request = [context request]; - message = [NSMutableDictionary dictionaryWithJSONString: [request contentAsString]]; + message = [[request contentAsString] objectFromJSONString]; username = [message objectForKey: @"userName"]; password = [message objectForKey: @"password"]; newPassword = [message objectForKey: @"newPassword"]; diff --git a/UI/Scheduler/UIxComponentEditor.m b/UI/Scheduler/UIxComponentEditor.m index 165cc9de2..6c44fda8c 100644 --- a/UI/Scheduler/UIxComponentEditor.m +++ b/UI/Scheduler/UIxComponentEditor.m @@ -55,7 +55,6 @@ #import #import #import -#import #import #import #import @@ -1727,8 +1726,8 @@ RANGE(2); if ([json length]) { attendees = [NSArray array]; - attendeesData = [NSMutableDictionary dictionaryWithJSONString: json]; - if (attendeesData) + attendeesData = [json objectFromJSONString]; + if (attendeesData && [attendeesData isKindOfClass: [NSDictionary class]]) { newAttendees = [NSMutableArray array]; attendees = [attendeesData allValues];