2
Copyright (C) 2002-2009 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 "SoPageInvocation.h"
23
#include "SoClassSecurityInfo.h"
24
#include "SoProduct.h"
25
#include "WOContext+SoObjects.h"
26
#include <NGObjWeb/WOComponent.h>
27
#include <NGObjWeb/WOContext.h>
28
#include <NGObjWeb/WOSession.h>
29
#include <NGObjWeb/WOResponse.h>
30
#include <NGObjWeb/WORequest.h>
31
#include <NGObjWeb/WOResourceManager.h>
32
#include <NGObjWeb/WOApplication.h>
35
@interface WOComponent(UsedPrivates)
36
/* this is defined in WOPageRequestHandler */
37
- (id<WOActionResults>)performActionNamed:(NSString *)_actionName;
38
- (id<WOActionResults>)defaultAction;
39
- (void)setResourceManager:(WOResourceManager *)_rm;
42
@interface WOContext(UsedPrivates)
43
- (void)setPage:(WOComponent *)_page;
46
@implementation SoPageInvocation
48
static int debugOn = 0;
51
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
52
static BOOL didInit = NO;
56
debugOn = [ud boolForKey:@"SoPageInvocationDebugEnabled"] ? 1 : 0;
59
- (id)initWithPageName:(NSString *)_pageName {
60
return [self initWithActionClassName:_pageName];
62
- (id)initWithPageName:(NSString *)_pageName actionName:(NSString *)_action {
63
return [self initWithActionClassName:_pageName actionName:_action];
65
- (id)initWithPageName:(NSString *)_pageName actionName:(NSString *)_action
66
product:(SoProduct *)_product
68
if ((self = [self initWithPageName:_pageName actionName:_action]) != nil) {
69
self->product = _product;
76
- (NSString *)pageName {
77
return [self actionClassName];
79
- (NSString *)defaultActionClassName {
85
- (void)detachFromContainer {
91
- (NSString *)nameInContainer {
92
/* could ask product */
98
- (void)_prepareContext:(id)_ctx withMethodObject:(id)_method {
99
/* make page the "request" page */
100
[_ctx setPage:_method];
103
- (void)_prepareMethod:(id)_method inContext:(id)_ctx {
104
/* apply request parameters */
107
rq = [(id <WOPageGenerationContext>)_ctx request];
108
if ([_method shouldTakeValuesFromRequest:rq inContext:_ctx]) {
109
[[_ctx application] takeValuesFromRequest:rq
114
/* page construction */
116
- (WOComponent *)instantiatePageInContext:(id)_ctx {
117
// Careful: this must return a RETAINED object!
118
WOResourceManager *rm;
123
[self debugWithFormat:@"instantiate page: %@", self->methodObject];
124
if (self->product == nil)
125
[self debugWithFormat:@" no product is set."];
129
[self debugWithFormat:
130
@"Note: got no explicit context for page instantiation, using "
131
@"application context."];
132
_ctx = [[WOApplication application] context];
135
/* lookup available resource manager (product,component,app) */
137
if ((rm = [self->product resourceManager]) == nil) {
138
if ((rm = [[_ctx component] resourceManager]) == nil) {
139
rm = [[_ctx application] resourceManager];
140
if (debugOn) [self debugWithFormat:@" app-rm: %@", rm];
143
if (debugOn) [self debugWithFormat:@" component-rm: %@", rm];
146
if (debugOn) [self debugWithFormat:@" product-rm: %@", rm];
148
/* determine language */
150
languages = [_ctx resourceLookupLanguages];
154
lPage = [rm pageWithName:[self pageName] languages:languages];
155
[lPage ensureAwakeInContext:_ctx];
156
[lPage setResourceManager:rm];
158
if (debugOn) [self debugWithFormat:@" page: %@", lPage];
160
return [lPage retain];
162
- (id)instantiateMethodInContext:(id)_ctx {
163
// Careful: this must return a RETAINED object!
164
/* override default method */
165
return [self instantiatePageInContext:_ctx];
170
- (id)bindToObject:(id)_object inContext:(id)_ctx {
171
SoPageInvocation *inv;
173
if (_object == nil) return nil;
175
// TODO: clean up this section, a bit hackish
176
inv = [[[self class] alloc] initWithActionClassName:self->actionClassName];
177
inv = [inv autorelease];
179
/* Note: product must be set _before_ instantiate! */
180
inv->object = [_object retain];
181
inv->actionName = [self->actionName copy];
182
inv->product = self->product; // non-owned (cannot be detached !!!)
183
inv->argumentSpecifications = [self->argumentSpecifications copy];
185
// Note: instantiateMethodInContext: returns a retained object!
186
inv->methodObject = [inv instantiateMethodInContext:_ctx];
187
if (inv->methodObject == nil) {
188
[self errorWithFormat:@"did not find method '%@'", [self actionClassName]];
194
/* delivering as content (can happen in DAV !) */
196
- (void)appendToResponse:(WOResponse *)_r inContext:(WOContext *)_ctx {
197
[_r appendContentString:@"native component method: "];
198
[_r appendContentHTMLString:[self description]];
203
- (void)appendAttributesToDescription:(NSMutableString *)_ms {
204
[super appendAttributesToDescription:_ms];
205
if (self->product) [_ms appendFormat:@" product=%@", self->product];
210
- (NSString *)loggingPrefix {
211
return [NSString stringWithFormat:@"[so-page 0x%p %@]",
212
self, [self pageName]];
214
- (BOOL)isDebuggingEnabled {
215
return debugOn ? YES : NO;
218
@end /* SoPageInvocation */