]> err.no Git - sope/blob - sope-appserver/SoOFS/OFSWebMethodRenderer.m
added strict OSX bundle dependencies
[sope] / sope-appserver / SoOFS / OFSWebMethodRenderer.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 "OFSWebMethodRenderer.h"
23 #include "OFSWebMethod.h"
24 #include <NGObjWeb/WOResponse.h>
25 #include "common.h"
26
27 @interface OFSWebMethod(Privates)
28 - (WOComponent *)componentInContext:(WOContext *)_ctx;
29 @end
30
31 @implementation OFSWebMethodRenderer
32
33 + (id)sharedRenderer {
34   static OFSWebMethodRenderer *singleton = nil;
35   if (singleton == nil)
36     singleton = [[OFSWebMethodRenderer alloc] init];
37   return singleton;
38 }
39
40 /* rendering */
41
42 - (NSException *)renderComponent:(WOComponent *)_c inContext:(WOContext *)_ctx{
43   WOResponse *r = [_ctx response];
44   
45   [r setHeader:@"text/html" forKey:@"content-type"];
46   [_ctx setPage:_c];
47   [_ctx enterComponent:_c content:nil];
48   [_c appendToResponse:r inContext:_ctx];
49   [_ctx leaveComponent:_c];
50   return nil;
51 }
52
53 - (NSException *)renderObject:(id)_object inContext:(WOContext *)_ctx {
54   WOComponent *component;
55   
56   if (![_object isOFSWebMethod])
57     return [NSException exceptionWithHTTPStatus:500 /* server error */];
58   
59   if ((component = [_object componentInContext:_ctx]) == nil)
60     return [NSException exceptionWithHTTPStatus:500 /* server error */];
61   
62   return [self renderComponent:component inContext:_ctx];
63 }
64
65 - (BOOL)canRenderObject:(id)_object inContext:(WOContext *)_ctx {
66   return [_object isOFSWebMethod];
67 }
68
69 /* debugging */
70
71 - (NSString *)loggingPrefix {
72   return @"[so-component-renderer]";
73 }
74
75 @end /* OFSWebMethodRenderer */