~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-appserver/SoOFS/OFSWebMethod.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

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