2007-08-15 22:58:11 +02:00
|
|
|
/* WODirectAction+SOGo.m - this file is part of SOGo
|
|
|
|
*
|
2008-09-27 03:13:41 +02:00
|
|
|
* Copyright (C) 2007 Inverse inc.
|
2007-08-15 22:58:11 +02:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-11-26 18:40:44 +01:00
|
|
|
#import <Foundation/NSBundle.h>
|
2007-08-15 22:58:11 +02:00
|
|
|
|
2007-11-26 18:40:44 +01:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2007-08-15 22:58:11 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
|
2007-12-13 20:25:01 +01:00
|
|
|
#import <SoObjects/SOGo/NSObject+Utilities.h>
|
2007-11-26 18:40:44 +01:00
|
|
|
#import <SoObjects/SOGo/NSDictionary+Utilities.h>
|
|
|
|
#import <SoObjects/SOGo/SOGoUser.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoUserDefaults.h>
|
2007-11-26 18:40:44 +01:00
|
|
|
|
2007-08-15 22:58:11 +02:00
|
|
|
#import "WODirectAction+SOGo.h"
|
|
|
|
|
|
|
|
@implementation WODirectAction (SOGoExtension)
|
|
|
|
|
2007-09-11 21:34:52 +02:00
|
|
|
- (WOResponse *) responseWithStatus: (unsigned int) status
|
2007-08-15 22:58:11 +02:00
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [context response];
|
2007-09-11 21:34:52 +02:00
|
|
|
[response setStatus: status];
|
2009-02-19 23:20:21 +01:00
|
|
|
[response setHeader: @"text/plain; charset=utf-8"
|
2009-07-01 21:27:34 +02:00
|
|
|
forKey: @"content-type"];
|
2007-09-11 21:34:52 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-12-13 20:25:01 +01:00
|
|
|
- (WOResponse *) responseWithStatus: (unsigned int) status
|
|
|
|
andString: (NSString *) contentString
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [self responseWithStatus: status];
|
|
|
|
[response appendContentString: contentString];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) responseWithStatus: (unsigned int) status
|
|
|
|
andJSONRepresentation: (NSObject *) contentObject;
|
|
|
|
{
|
|
|
|
return [self responseWithStatus: status
|
|
|
|
andString: [contentObject jsonRepresentation]];
|
|
|
|
}
|
|
|
|
|
2007-09-11 21:34:52 +02:00
|
|
|
- (WOResponse *) responseWith204
|
|
|
|
{
|
2009-01-21 17:20:11 +01:00
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [self responseWithStatus: 204];
|
|
|
|
|
|
|
|
return response;
|
2007-09-11 21:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) redirectToLocation: (NSString *) newLocation
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [self responseWithStatus: 302];
|
2007-08-15 22:58:11 +02:00
|
|
|
[response setHeader: newLocation forKey: @"location"];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-11-26 18:40:44 +01:00
|
|
|
- (NSString *) labelForKey: (NSString *) key
|
|
|
|
{
|
|
|
|
NSString *userLanguage, *label;
|
|
|
|
NSArray *paths;
|
|
|
|
NSBundle *bundle;
|
|
|
|
NSDictionary *strings;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2007-11-26 18:40:44 +01:00
|
|
|
|
|
|
|
bundle = [NSBundle bundleForClass: [self class]];
|
|
|
|
if (!bundle)
|
|
|
|
bundle = [NSBundle mainBundle];
|
2007-09-11 21:34:52 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
userLanguage = [ud language];
|
2007-11-26 18:40:44 +01:00
|
|
|
paths = [bundle pathsForResourcesOfType: @"strings"
|
|
|
|
inDirectory: [NSString stringWithFormat: @"%@.lproj",
|
|
|
|
userLanguage]
|
|
|
|
forLocalization: userLanguage];
|
|
|
|
if ([paths count] > 0)
|
|
|
|
{
|
|
|
|
strings = [NSDictionary
|
|
|
|
dictionaryFromStringsFile: [paths objectAtIndex: 0]];
|
|
|
|
label = [strings objectForKey: key];
|
|
|
|
if (!label)
|
|
|
|
label = key;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
label = key;
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
2007-08-15 22:58:11 +02:00
|
|
|
@end
|