]> err.no Git - sope/blob - sope-appserver/SoOFS/OFSWebMethod.m
added strict OSX bundle dependencies
[sope] / sope-appserver / SoOFS / OFSWebMethod.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE 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   SOPE 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 SOPE; 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
22 #include "OFSWebMethod.h"
23 #include <NGObjWeb/WEClientCapabilities.h>
24 #include <NGObjWeb/WOResourceManager.h>
25 #include <NGObjWeb/WOSession.h>
26 #include <NGObjWeb/WOResponse.h>
27 #include "common.h"
28
29 @interface WOComponent(RM)
30 - (void)setResourceManager:(WOResourceManager *)_rm;
31 @end
32
33 @implementation OFSWebMethod
34
35 static BOOL debugOn = NO;
36
37 + (int)version {
38   return [super version] + 0 /* v1 */;
39 }
40 + (void)initialize {
41   static BOOL didInit = NO;
42   if (!didInit) {
43     didInit = YES;
44     NSAssert2([super version] == 1,
45               @"invalid superclass (%@) version %i !",
46               NSStringFromClass([self superclass]), [super version]);
47     
48     debugOn = [[NSUserDefaults standardUserDefaults] 
49                                boolForKey:@"SoOFSWebMethodDebugEnabled"];
50   }
51 }
52
53 - (void)dealloc {
54   [self->component release];
55   [super dealloc];
56 }
57
58 /* page */
59
60 - (WOResourceManager *)resourceManagerInContext:(id)_ctx {
61   return [[self container] resourceManagerInContext:_ctx];
62 }
63
64 - (WOComponent *)componentInContext:(WOContext *)_ctx {
65   WOResourceManager *rm;
66   WOComponent *lPage;
67   NSArray     *languages;
68   
69   if (self->component)
70     return self->component;
71   
72   [self debugWithFormat:@"should load component: %@", [self storagePath]];
73   if ((rm = [self resourceManagerInContext:_ctx]) == nil) {
74     [self logWithFormat:@"got no resource manager ..."];
75     return nil;
76   }
77     
78   /* determine language */
79     
80   languages = [_ctx hasSession]
81     ? [(WOSession *)[_ctx session] languages]
82     : [[_ctx request] browserLanguages];
83     
84   /* instantiate */
85     
86   lPage = [rm pageWithName:[self nameInContainer] languages:languages];
87   [lPage ensureAwakeInContext:_ctx];
88   [lPage setResourceManager:rm];
89   
90   [self debugWithFormat:@"   page: %@", lPage];
91   
92   self->component = [lPage retain];
93   return self->component;
94 }
95 - (WOComponent *)component {
96   return [self componentInContext:[[WOApplication application] context]];
97 }
98
99 /* actions */
100
101 - (id)rendererForObject:(id)_object inContext:(WOContext *)_ctx {
102   // TODO: should return the component ?
103   // TODO: add OFSWebMethodRenderer which selects on DAV ?
104   return nil;
105 }
106
107 - (id)getUnparsedContentInContext:(WOContext *)_ctx {
108   /* this method should not be publically available ! */
109   // TODO: check permission for source-view !
110   return [super GETAction:_ctx];
111 }
112
113 - (BOOL)useRendererForComponentCreation {
114   /* will GET/view return the component as a result or self ? */
115   return NO;
116 }
117
118 - (id)viewAction:(WOContext *)_ctx {
119   /* 
120      The difference to get is, that view always renders the content, so
121      you can get a rendered representation even with a WebDAV client.
122   */
123   
124   /* the default renderer will recognize that as a component ... */
125   return [self useRendererForComponentCreation]
126     ? self 
127     : (id)[self componentInContext:_ctx];
128 }
129
130 - (id)GETAction:(WOContext *)_ctx {
131   WORequest *rq;
132   NSString  *translate;
133   
134   rq = [_ctx request];
135   translate = [[rq headerForKey:@"translate"] lowercaseString];
136   
137   if ([translate hasPrefix:@"f"]) {
138     /* return the unparsed body */
139     if (debugOn)
140       [self debugWithFormat:@"returning unparsed content (translate f)"];
141     return [self getUnparsedContentInContext:_ctx];
142   }
143   
144   if ([[rq clientCapabilities] isDAVClient]) {
145     /* return the unparsed body */
146     if (debugOn)
147       [self debugWithFormat:@"returning unparsed content (DAV-client)"];
148     return [self getUnparsedContentInContext:_ctx];
149   }
150   
151   /* the default renderer will recognize that as a component ... */
152   if (debugOn) [self debugWithFormat:@"return component object for GET ..."];
153   return [self viewAction:_ctx];
154 }
155 - (id)POSTAction:(WOContext *)_ctx {
156   WOComponent *comp;
157   
158   if (debugOn) [self debugWithFormat:@"process POST using component ..."];
159   
160   if ((comp = [self componentInContext:_ctx]) == nil)
161     return nil;
162   
163   // TODO: should we invoke some action ?
164   // TODO: maybe the renderer should do the takeValues/invoke/... ??
165   [comp takeValuesFromRequest:[_ctx request] inContext:_ctx];
166   return comp;
167 }
168
169 - (BOOL)isOFSWebMethod {
170   return YES;
171 }
172
173 /* calling (being a method ...) */
174
175 - (BOOL)isCallable {
176   return YES;
177 }
178
179 - (id)callOnObject:(id)_client inContext:(id)_ctx {
180   WOComponent *c;
181   
182   if ((c = [self componentInContext:_ctx]) == nil)
183     return nil;
184   
185   [c setClientObject:_client];
186   return c;
187 }
188
189 - (id)clientObject {
190   return [[[WOApplication application] context] clientObject];
191 }
192
193 /* debugging */
194
195 - (BOOL)isDebuggingEnabled {
196   return debugOn;
197 }
198
199 @end /* OFSWebMethod */
200
201 @implementation NSObject(OFSWebMethodClassify)
202
203 - (BOOL)isOFSWebMethod {
204   return NO;
205 }
206
207 @end /* NSObject(OFSWebMethodClassify) */