1 /* WODirectAction+SOGo.m - this file is part of SOGo
3 * Copyright (C) 2007 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSBundle.h>
25 #import <NGObjWeb/WOContext+SoObjects.h>
26 #import <NGObjWeb/WOResponse.h>
28 #import <SoObjects/SOGo/NSObject+Utilities.h>
29 #import <SoObjects/SOGo/NSDictionary+Utilities.h>
30 #import <SoObjects/SOGo/SOGoUser.h>
32 #import "WODirectAction+SOGo.h"
34 @implementation WODirectAction (SOGoExtension)
36 - (WOResponse *) responseWithStatus: (unsigned int) status
40 response = [context response];
41 [response setStatus: status];
46 - (WOResponse *) responseWithStatus: (unsigned int) status
47 andString: (NSString *) contentString
51 response = [self responseWithStatus: status];
52 [response appendContentString: contentString];
57 - (WOResponse *) responseWithStatus: (unsigned int) status
58 andJSONRepresentation: (NSObject *) contentObject;
60 return [self responseWithStatus: status
61 andString: [contentObject jsonRepresentation]];
64 - (WOResponse *) responseWith204
66 return [self responseWithStatus: 204];
69 - (WOResponse *) redirectToLocation: (NSString *) newLocation
73 response = [self responseWithStatus: 302];
74 [response setHeader: newLocation forKey: @"location"];
79 - (NSString *) labelForKey: (NSString *) key
81 NSString *userLanguage, *label;
84 NSDictionary *strings;
86 bundle = [NSBundle bundleForClass: [self class]];
88 bundle = [NSBundle mainBundle];
90 userLanguage = [[context activeUser] language];
91 paths = [bundle pathsForResourcesOfType: @"strings"
92 inDirectory: [NSString stringWithFormat: @"%@.lproj",
94 forLocalization: userLanguage];
95 if ([paths count] > 0)
97 strings = [NSDictionary
98 dictionaryFromStringsFile: [paths objectAtIndex: 0]];
99 label = [strings objectForKey: key];