]> err.no Git - sope/blob - skyrix-sope/samples/iCalPortal/iCalPortalPage.m
added svn:keywords and svn:ignore where appropriate. removed CVS artifacts.
[sope] / skyrix-sope / samples / iCalPortal / iCalPortalPage.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "iCalPortalPage.h"
24 #include "common.h"
25
26 @interface iCalLabelDispatcher : NSObject
27 {
28   iCalPortalPage *component;
29 }
30
31 - (id)initWithComponent:(iCalPortalPage *)_comp;
32
33 @end
34
35 @implementation iCalPortalPage
36
37 + (int)version {
38   return [super version] + 0 /* v2 */;
39 }
40 + (void)initialize {
41   NSAssert2([super version] == 2,
42             @"invalid superclass (%@) version %i !",
43             NSStringFromClass([self superclass]), [super version]);
44 }
45
46 - (void)dealloc {
47   [super dealloc];
48 }
49
50 /* accessors */
51
52 - (iCalPortalDatabase *)database {
53   return [(id)[self application] database];
54 }
55
56 - (iCalPortalUser *)user {
57   if (![self hasSession])
58     return nil;
59   
60   return [[self session] objectForKey:@"user"];
61 }
62
63 /* actions */
64
65 - (BOOL)isSessionProtectedPage {
66   return YES;
67 }
68
69 - (id<WOActionResults>)indexPage {
70   NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
71   WOSession *sn;
72   
73   if ((sn = [self existingSession])) {
74     [sn removeObjectForKey:@"user"];
75     [sn terminate];
76   }
77   
78   if ([[ud objectForKey:@"DevMode"] boolValue]) {
79     return [[self pageWithName:@"iCalPortalWelcomePage"] performPage];
80   }
81   else {
82     WOResponse *r;
83     
84     r = [WOResponse responseWithRequest:[[self context] request]];
85     
86     [r setStatus:302];
87     [r setHeader:@"/en/index.xhtml" forKey:@"location"];
88     
89     return r;
90   }
91 }
92
93 - (id)performPage {
94   id result;
95   
96   if ([self isSessionProtectedPage]) {
97     if (![self hasSession]) {
98       [self logWithFormat:
99               @"tried to access login protected page without session !"];
100       return [self indexPage];
101     }
102   }
103   
104   result = [self run];
105   
106   return result;
107 }
108
109 - (id)run {
110   return self;
111 }
112
113 /* labels */
114
115 - (id)label {
116   return [[[iCalLabelDispatcher alloc] initWithComponent:self] autorelease];
117 }
118
119 - (NSString *)stringForKey:(NSString *)_key {
120   NSString *s;
121   NSArray  *langs;
122
123   langs = [self hasSession]
124     ? [[self session] languages]
125     : [[[self context] request] browserLanguages];
126   
127   s = [[self resourceManager] 
128              stringForKey:_key inTableNamed:@"main" withDefaultValue:_key
129              languages:langs];
130   return s;
131 }
132
133 - (NSString *)localizedTitle {
134   return [self stringForKey:[self name]];
135 }
136
137 @end /* iCalPortalPage */
138
139 @implementation iCalLabelDispatcher
140
141 - (id)initWithComponent:(iCalPortalPage *)_comp {
142   self->component = _comp;
143   return self;
144 }
145
146 - (id)valueForKey:(NSString *)_key {
147   if ([_key length] == 0)
148     return _key;
149   
150   return [self->component stringForKey:_key];
151 }
152
153 @end /* iCalLabelDispatcher */