2 Copyright (C) 2000-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 <NGObjWeb/WEClientCapabilities.h>
24 #include <NGObjWeb/WOResourceManager.h>
25 #include <NGObjWeb/WOSession.h>
26 #include <NGObjWeb/WOResponse.h>
29 @interface WOComponent(RM)
30 - (void)setResourceManager:(WOResourceManager *)_rm;
33 @implementation OFSWebMethod
35 static BOOL debugOn = NO;
38 return [super version] + 0 /* v1 */;
41 static BOOL didInit = NO;
44 NSAssert2([super version] == 1,
45 @"invalid superclass (%@) version %i !",
46 NSStringFromClass([self superclass]), [super version]);
48 debugOn = [[NSUserDefaults standardUserDefaults]
49 boolForKey:@"SoOFSWebMethodDebugEnabled"];
54 [self->component release];
60 - (WOResourceManager *)resourceManagerInContext:(id)_ctx {
61 return [[self container] resourceManagerInContext:_ctx];
64 - (WOComponent *)componentInContext:(WOContext *)_ctx {
65 WOResourceManager *rm;
70 return self->component;
72 [self debugWithFormat:@"should load component: %@", [self storagePath]];
73 if ((rm = [self resourceManagerInContext:_ctx]) == nil) {
74 [self logWithFormat:@"got no resource manager ..."];
78 /* determine language */
80 languages = [_ctx hasSession]
81 ? [(WOSession *)[_ctx session] languages]
82 : [[_ctx request] browserLanguages];
86 lPage = [rm pageWithName:[self nameInContainer] languages:languages];
87 [lPage ensureAwakeInContext:_ctx];
88 [lPage setResourceManager:rm];
90 [self debugWithFormat:@" page: %@", lPage];
92 self->component = [lPage retain];
93 return self->component;
95 - (WOComponent *)component {
96 return [self componentInContext:[[WOApplication application] context]];
101 - (id)rendererForObject:(id)_object inContext:(WOContext *)_ctx {
102 // TODO: should return the component ?
103 // TODO: add OFSWebMethodRenderer which selects on DAV ?
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];
113 - (BOOL)useRendererForComponentCreation {
114 /* will GET/view return the component as a result or self ? */
118 - (id)viewAction:(WOContext *)_ctx {
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.
124 /* the default renderer will recognize that as a component ... */
125 return [self useRendererForComponentCreation]
127 : (id)[self componentInContext:_ctx];
130 - (id)GETAction:(WOContext *)_ctx {
135 translate = [[rq headerForKey:@"translate"] lowercaseString];
137 if ([translate hasPrefix:@"f"]) {
138 /* return the unparsed body */
140 [self debugWithFormat:@"returning unparsed content (translate f)"];
141 return [self getUnparsedContentInContext:_ctx];
144 if ([[rq clientCapabilities] isDAVClient]) {
145 /* return the unparsed body */
147 [self debugWithFormat:@"returning unparsed content (DAV-client)"];
148 return [self getUnparsedContentInContext:_ctx];
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];
155 - (id)POSTAction:(WOContext *)_ctx {
158 if (debugOn) [self debugWithFormat:@"process POST using component ..."];
160 if ((comp = [self componentInContext:_ctx]) == nil)
163 // TODO: should we invoke some action ?
164 // TODO: maybe the renderer should do the takeValues/invoke/... ??
165 [comp takeValuesFromRequest:[_ctx request] inContext:_ctx];
169 - (BOOL)isOFSWebMethod {
173 /* calling (being a method ...) */
179 - (id)callOnObject:(id)_client inContext:(id)_ctx {
182 if ((c = [self componentInContext:_ctx]) == nil)
185 [c setClientObject:_client];
190 return [[[WOApplication application] context] clientObject];
195 - (BOOL)isDebuggingEnabled {
199 @end /* OFSWebMethod */
201 @implementation NSObject(OFSWebMethodClassify)
203 - (BOOL)isOFSWebMethod {
207 @end /* NSObject(OFSWebMethodClassify) */