2
Copyright (C) 2002-2005 SKYRIX Software AG
4
This file is part of SOPE.
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
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.
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
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>
30
@interface WOComponent(RM)
31
- (void)setResourceManager:(WOResourceManager *)_rm;
34
@implementation OFSWebMethod
36
static BOOL debugOn = NO;
39
return [super version] + 0 /* v1 */;
42
static BOOL didInit = NO;
45
NSAssert2([super version] == 1,
46
@"invalid superclass (%@) version %i !",
47
NSStringFromClass([self superclass]), [super version]);
49
debugOn = [[NSUserDefaults standardUserDefaults]
50
boolForKey:@"SoOFSWebMethodDebugEnabled"];
55
[self->component release];
61
- (WOResourceManager *)resourceManagerInContext:(id)_ctx {
62
return [[self container] resourceManagerInContext:_ctx];
65
- (WOComponent *)componentInContext:(WOContext *)_ctx {
66
WOResourceManager *rm;
71
return self->component;
73
[self debugWithFormat:@"should load component: %@", [self storagePath]];
74
if ((rm = [self resourceManagerInContext:_ctx]) == nil) {
75
[self logWithFormat:@"got no resource manager ..."];
79
/* determine language */
81
languages = [_ctx hasSession]
82
? [(WOSession *)[_ctx session] languages]
83
: [[_ctx request] browserLanguages];
87
lPage = [rm pageWithName:[self nameInContainer] languages:languages];
88
[lPage ensureAwakeInContext:_ctx];
89
[lPage setResourceManager:rm];
91
[self debugWithFormat:@" page: %@", lPage];
93
self->component = [lPage retain];
94
return self->component;
96
- (WOComponent *)component {
97
return [self componentInContext:[[WOApplication application] context]];
102
- (id)rendererForObject:(id)_object inContext:(WOContext *)_ctx {
103
// TODO: should return the component ?
104
// TODO: add OFSWebMethodRenderer which selects on DAV ?
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];
114
- (BOOL)useRendererForComponentCreation {
115
/* will GET/view return the component as a result or self ? */
119
- (id)viewAction:(WOContext *)_ctx {
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.
125
/* the default renderer will recognize that as a component ... */
126
return [self useRendererForComponentCreation]
128
: (id)[self componentInContext:_ctx];
131
- (id)GETAction:(WOContext *)_ctx {
136
translate = [[rq headerForKey:@"translate"] lowercaseString];
138
if ([translate hasPrefix:@"f"]) {
139
/* return the unparsed body */
141
[self debugWithFormat:@"returning unparsed content (translate f)"];
142
return [self getUnparsedContentInContext:_ctx];
145
if ([[rq clientCapabilities] isDAVClient]) {
146
/* return the unparsed body */
148
[self debugWithFormat:@"returning unparsed content (DAV-client)"];
149
return [self getUnparsedContentInContext:_ctx];
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];
156
- (id)POSTAction:(WOContext *)_ctx {
159
if (debugOn) [self debugWithFormat:@"process POST using component ..."];
161
if ((comp = [self componentInContext:_ctx]) == nil)
164
// TODO: should we invoke some action ?
165
// TODO: maybe the renderer should do the takeValues/invoke/... ??
166
[comp takeValuesFromRequest:[_ctx request] inContext:_ctx];
170
- (BOOL)isOFSWebMethod {
174
/* calling (being a method ...) */
180
- (id)callOnObject:(id)_client inContext:(id)_ctx {
183
if ((c = [self componentInContext:_ctx]) == nil)
186
[c setClientObject:_client];
191
return [[[WOApplication application] context] clientObject];
196
- (BOOL)isDebuggingEnabled {
200
@end /* OFSWebMethod */
202
@implementation NSObject(OFSWebMethodClassify)
204
- (BOOL)isOFSWebMethod {
208
@end /* NSObject(OFSWebMethodClassify) */