]> err.no Git - scalable-opengroupware.org/blob - UI/Common/WODirectAction+SOGo.m
Install libs to /usr/lib
[scalable-opengroupware.org] / UI / Common / WODirectAction+SOGo.m
1 /* WODirectAction+SOGo.m - this file is part of SOGo
2  *
3  * Copyright (C) 2007 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
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)
10  * any later version.
11  *
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.
16  *
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.
21  */
22
23 #import <Foundation/NSBundle.h>
24
25 #import <NGObjWeb/WOContext+SoObjects.h>
26 #import <NGObjWeb/WOResponse.h>
27
28 #import <SoObjects/SOGo/NSObject+Utilities.h>
29 #import <SoObjects/SOGo/NSDictionary+Utilities.h>
30 #import <SoObjects/SOGo/SOGoUser.h>
31
32 #import "WODirectAction+SOGo.h"
33
34 @implementation WODirectAction (SOGoExtension)
35
36 - (WOResponse *) responseWithStatus: (unsigned int) status
37 {
38   WOResponse *response;
39
40   response = [context response];
41   [response setStatus: status];
42
43   return response;
44 }
45
46 - (WOResponse *) responseWithStatus: (unsigned int) status
47                           andString: (NSString *) contentString
48 {
49   WOResponse *response;
50
51   response = [self responseWithStatus: status];
52   [response appendContentString: contentString];
53
54   return response;
55 }
56
57 - (WOResponse *) responseWithStatus: (unsigned int) status
58               andJSONRepresentation: (NSObject *) contentObject;
59 {
60   return [self responseWithStatus: status
61                andString: [contentObject jsonRepresentation]];
62 }
63
64 - (WOResponse *) responseWith204
65 {
66   return [self responseWithStatus: 204];
67 }
68
69 - (WOResponse *) redirectToLocation: (NSString *) newLocation
70 {
71   WOResponse *response;
72
73   response = [self responseWithStatus: 302];
74   [response setHeader: newLocation forKey: @"location"];
75
76   return response;
77 }
78
79 - (NSString *) labelForKey: (NSString *) key
80 {
81   NSString *userLanguage, *label;
82   NSArray *paths;
83   NSBundle *bundle;
84   NSDictionary *strings;
85
86   bundle = [NSBundle bundleForClass: [self class]];
87   if (!bundle)
88     bundle = [NSBundle mainBundle];
89
90   userLanguage = [[context activeUser] language];
91   paths = [bundle pathsForResourcesOfType: @"strings"
92                   inDirectory: [NSString stringWithFormat: @"%@.lproj",
93                                          userLanguage]
94                   forLocalization: userLanguage];
95   if ([paths count] > 0)
96     {
97       strings = [NSDictionary
98                   dictionaryFromStringsFile: [paths objectAtIndex: 0]];
99       label = [strings objectForKey: key];
100       if (!label)
101         label = key;
102     }
103   else
104     label = key;
105   
106   return label;
107 }
108 @end