2007-05-25 19:30:24 +02:00
|
|
|
/* NSObject+Utilities.m - this file is part of SOGo
|
|
|
|
*
|
2015-08-19 16:39:10 +02:00
|
|
|
* Copyright (C) 2007-2015 Inverse inc.
|
2007-05-25 19:30:24 +02:00
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
#import <Foundation/NSArray.h>
|
2010-04-09 20:45:14 +02:00
|
|
|
#import <Foundation/NSBundle.h>
|
2014-12-23 01:32:17 +01:00
|
|
|
#import <Foundation/NSDebug.h>
|
2010-04-20 23:30:17 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-05-25 19:30:24 +02:00
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
|
|
|
|
#import "NSDictionary+Utilities.h"
|
|
|
|
#import "SOGoUser.h"
|
|
|
|
#import "SOGoUserDefaults.h"
|
|
|
|
|
2007-05-25 19:30:24 +02:00
|
|
|
#import "NSObject+Utilities.h"
|
|
|
|
|
|
|
|
@implementation NSObject (SOGoObjectUtilities)
|
|
|
|
|
|
|
|
- (NSString *) jsonRepresentation
|
|
|
|
{
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) domNode: (id <DOMNode>) node
|
|
|
|
getChildNodesByType: (DOMNodeType ) type
|
|
|
|
{
|
|
|
|
NSMutableArray *nodes;
|
|
|
|
id <DOMNode> currentChild;
|
|
|
|
|
|
|
|
nodes = [NSMutableArray array];
|
|
|
|
|
|
|
|
currentChild = [node firstChild];
|
|
|
|
while (currentChild)
|
|
|
|
{
|
|
|
|
if ([currentChild nodeType] == type)
|
|
|
|
[nodes addObject: currentChild];
|
|
|
|
currentChild = [currentChild nextSibling];
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodes;
|
|
|
|
}
|
|
|
|
|
2010-04-09 20:45:14 +02:00
|
|
|
- (NSArray *) _languagesForLabelsInContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
NSMutableArray *languages;
|
|
|
|
NSArray *browserLanguages;
|
|
|
|
NSString *language;
|
|
|
|
SOGoUser *user;
|
|
|
|
|
|
|
|
#warning the purpose of this method needs to be reviewed
|
|
|
|
languages = [NSMutableArray array];
|
|
|
|
|
|
|
|
user = [context activeUser];
|
|
|
|
if ([user isKindOfClass: [SOGoUser class]])
|
|
|
|
{
|
|
|
|
language = [[user userDefaults] language];
|
|
|
|
[languages addObject: language];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
browserLanguages = [[context request] browserLanguages];
|
|
|
|
[languages addObjectsFromArray: browserLanguages];
|
|
|
|
}
|
|
|
|
|
|
|
|
return languages;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) labelForKey: (NSString *) key
|
|
|
|
inContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
NSString *language, *label;
|
|
|
|
NSArray *paths;
|
|
|
|
NSEnumerator *languages;
|
|
|
|
NSBundle *bundle;
|
|
|
|
NSDictionary *strings;
|
|
|
|
|
|
|
|
label = nil;
|
|
|
|
|
|
|
|
bundle = [NSBundle bundleForClass: [self class]];
|
|
|
|
if (!bundle)
|
|
|
|
bundle = [NSBundle mainBundle];
|
|
|
|
languages = [[self _languagesForLabelsInContext: context] objectEnumerator];
|
|
|
|
|
|
|
|
while (!label && (language = [languages nextObject]))
|
|
|
|
{
|
|
|
|
paths = [bundle pathsForResourcesOfType: @"strings"
|
|
|
|
inDirectory: [NSString stringWithFormat: @"%@.lproj",
|
|
|
|
language]
|
|
|
|
forLocalization: language];
|
|
|
|
if ([paths count] > 0)
|
|
|
|
{
|
|
|
|
strings = [NSDictionary
|
|
|
|
dictionaryFromStringsFile: [paths objectAtIndex: 0]];
|
|
|
|
label = [strings objectForKey: key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!label)
|
|
|
|
label = key;
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2014-12-23 01:59:33 +01:00
|
|
|
//
|
|
|
|
// Set SOGoDebugLeaks = YES in your defaults to enable.
|
|
|
|
//
|
2014-12-23 01:32:17 +01:00
|
|
|
+ (void) memoryStatistics
|
|
|
|
{
|
|
|
|
Class *classList = GSDebugAllocationClassList ();
|
|
|
|
Class *pointer;
|
|
|
|
int i, count, total, peak;
|
|
|
|
NSString *className;
|
|
|
|
|
|
|
|
pointer = classList;
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
printf("Class count total peak\n");
|
|
|
|
while (pointer[i] != NULL)
|
|
|
|
{
|
|
|
|
className = NSStringFromClass (pointer[i]);
|
|
|
|
count = GSDebugAllocationCount (pointer[i]);
|
|
|
|
total = GSDebugAllocationTotal (pointer[i]);
|
|
|
|
peak = GSDebugAllocationPeak (pointer[i]);
|
|
|
|
|
|
|
|
printf("%s %d %d %d\n", [className UTF8String], count, total, peak);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
NSZoneFree(NSDefaultMallocZone(), classList);
|
|
|
|
|
|
|
|
printf("Done!\n");
|
|
|
|
}
|
|
|
|
|
2007-05-25 19:30:24 +02:00
|
|
|
@end
|