~ubuntu-branches/ubuntu/saucy/sope/saucy

« back to all changes in this revision

Viewing changes to sope-appserver/NGObjWeb/SoObjects/SoPageInvocation.m

  • Committer: Package Import Robot
  • Author(s): Jeroen Dekkers
  • Date: 2012-05-09 15:39:17 UTC
  • Revision ID: package-import@ubuntu.com-20120509153917-nr4jlm8mktma1yv3
Tags: upstream-1.3.14
ImportĀ upstreamĀ versionĀ 1.3.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2002-2009 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 "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>
 
33
#include "common.h"
 
34
 
 
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;
 
40
@end
 
41
 
 
42
@interface WOContext(UsedPrivates)
 
43
- (void)setPage:(WOComponent *)_page;
 
44
@end
 
45
 
 
46
@implementation SoPageInvocation
 
47
 
 
48
static int debugOn = 0;
 
49
 
 
50
+ (void)initialize {
 
51
  NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
 
52
  static BOOL didInit = NO;
 
53
  if (didInit) return;
 
54
  didInit = YES;
 
55
    
 
56
  debugOn = [ud boolForKey:@"SoPageInvocationDebugEnabled"] ? 1 : 0;
 
57
}
 
58
 
 
59
- (id)initWithPageName:(NSString *)_pageName {
 
60
  return [self initWithActionClassName:_pageName];
 
61
}
 
62
- (id)initWithPageName:(NSString *)_pageName actionName:(NSString *)_action {
 
63
  return [self initWithActionClassName:_pageName actionName:_action];
 
64
}
 
65
- (id)initWithPageName:(NSString *)_pageName actionName:(NSString *)_action
 
66
  product:(SoProduct *)_product
 
67
{
 
68
  if ((self = [self initWithPageName:_pageName actionName:_action]) != nil) {
 
69
    self->product = _product;
 
70
  }
 
71
  return self;
 
72
}
 
73
 
 
74
/* accessors */
 
75
 
 
76
- (NSString *)pageName {
 
77
  return [self actionClassName];
 
78
}
 
79
- (NSString *)defaultActionClassName {
 
80
  return @"Main";
 
81
}
 
82
 
 
83
/* containment */
 
84
 
 
85
- (void)detachFromContainer {
 
86
  self->product = nil;
 
87
}
 
88
- (id)container {
 
89
  return self->product;
 
90
}
 
91
- (NSString *)nameInContainer {
 
92
  /* could ask product */
 
93
  return nil;
 
94
}
 
95
 
 
96
/* calling */
 
97
 
 
98
- (void)_prepareContext:(id)_ctx withMethodObject:(id)_method {
 
99
  /* make page the "request" page */
 
100
  [_ctx setPage:_method];
 
101
}
 
102
 
 
103
- (void)_prepareMethod:(id)_method inContext:(id)_ctx {
 
104
  /* apply request parameters */
 
105
  WORequest *rq;
 
106
  
 
107
  rq = [(id <WOPageGenerationContext>)_ctx request];
 
108
  if ([_method shouldTakeValuesFromRequest:rq inContext:_ctx]) {
 
109
    [[_ctx application] takeValuesFromRequest:rq
 
110
                        inContext:_ctx];
 
111
  }
 
112
}
 
113
 
 
114
/* page construction */
 
115
 
 
116
- (WOComponent *)instantiatePageInContext:(id)_ctx {
 
117
  // Careful: this must return a RETAINED object!
 
118
  WOResourceManager *rm;
 
119
  WOComponent *lPage;
 
120
  NSArray     *languages;
 
121
  
 
122
  if (debugOn) {
 
123
    [self debugWithFormat:@"instantiate page: %@", self->methodObject];
 
124
    if (self->product == nil)
 
125
      [self debugWithFormat:@"  no product is set."];
 
126
  }
 
127
 
 
128
  if (_ctx == nil) {
 
129
    [self debugWithFormat:
 
130
            @"Note: got no explicit context for page instantiation, using "
 
131
            @"application context."];
 
132
    _ctx = [[WOApplication application] context];
 
133
  }
 
134
  
 
135
  /* lookup available resource manager (product,component,app) */
 
136
  
 
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];
 
141
    }
 
142
    else
 
143
      if (debugOn) [self debugWithFormat:@"   component-rm: %@", rm];
 
144
  }
 
145
  else
 
146
    if (debugOn) [self debugWithFormat:@"   product-rm: %@", rm];
 
147
  
 
148
  /* determine language */
 
149
  
 
150
  languages = [_ctx resourceLookupLanguages];
 
151
 
 
152
  /* instantiate */
 
153
  
 
154
  lPage = [rm pageWithName:[self pageName] languages:languages];
 
155
  [lPage ensureAwakeInContext:_ctx];
 
156
  [lPage setResourceManager:rm];
 
157
  
 
158
  if (debugOn) [self debugWithFormat:@"   page: %@", lPage];
 
159
  
 
160
  return [lPage retain];
 
161
}
 
162
- (id)instantiateMethodInContext:(id)_ctx {
 
163
  // Careful: this must return a RETAINED object!
 
164
  /* override default method */
 
165
  return [self instantiatePageInContext:_ctx];
 
166
}
 
167
 
 
168
/* binding */
 
169
 
 
170
- (id)bindToObject:(id)_object inContext:(id)_ctx {
 
171
  SoPageInvocation *inv;
 
172
  
 
173
  if (_object == nil) return nil;
 
174
  
 
175
  // TODO: clean up this section, a bit hackish
 
176
  inv = [[[self class] alloc] initWithActionClassName:self->actionClassName];
 
177
  inv = [inv autorelease];
 
178
  
 
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];
 
184
  
 
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]];
 
189
    return nil;
 
190
  }
 
191
  return inv;
 
192
}
 
193
 
 
194
/* delivering as content (can happen in DAV !) */
 
195
 
 
196
- (void)appendToResponse:(WOResponse *)_r inContext:(WOContext *)_ctx {
 
197
  [_r appendContentString:@"native component method: "];
 
198
  [_r appendContentHTMLString:[self description]];
 
199
}
 
200
 
 
201
/* description */
 
202
 
 
203
- (void)appendAttributesToDescription:(NSMutableString *)_ms {
 
204
  [super appendAttributesToDescription:_ms];
 
205
  if (self->product) [_ms appendFormat:@" product=%@", self->product];
 
206
}
 
207
 
 
208
/* Logging */
 
209
 
 
210
- (NSString *)loggingPrefix {
 
211
  return [NSString stringWithFormat:@"[so-page 0x%p %@]", 
 
212
                     self, [self pageName]];
 
213
}
 
214
- (BOOL)isDebuggingEnabled {
 
215
  return debugOn ? YES : NO;
 
216
}
 
217
 
 
218
@end /* SoPageInvocation */