1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/*
Copyright (C) 2000-2005 SKYRIX Software AG
This file is part of SOPE.
SOPE is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#include "WOComponentContent.h"
#include "WOContext+private.h"
#include <NGObjWeb/WOComponent.h>
#include <NGObjWeb/WOResponse.h>
#include "decommon.h"
@interface WOContext(ComponentStackCount)
- (unsigned)componentStackCount;
@end
@implementation WOComponentContent
static int profileComponents = -1;
static Class NSDateClass = Nil;
+ (void)initialize {
if (profileComponents == -1) {
profileComponents = [[[NSUserDefaults standardUserDefaults]
objectForKey:@"WOProfileComponents"]
boolValue] ? 1 : 0;
}
if (NSDateClass == Nil)
NSDateClass = [NSDate class];
}
// responder
- (void)takeValuesFromRequest:(WORequest *)_request
inContext:(WOContext *)_ctx
{
WOElement *content;
content = [_ctx componentContent]; // content (valid in parent)
if (content) {
NSTimeInterval st = 0.0;
WOComponent *component = [_ctx component]; // reusable component
component = RETAIN(component);
content = RETAIN(content);
if (profileComponents)
st = [[NSDateClass date] timeIntervalSince1970];
[_ctx leaveComponent:component];
[content takeValuesFromRequest:_request inContext:_ctx];
[_ctx enterComponent:component content:content];
if (profileComponents) {
NSTimeInterval diff;
int i;
diff = [[NSDateClass date] timeIntervalSince1970] - st;
for (i = [_ctx componentStackCount]; i >= 0; i--)
printf(" ");
printf("content: [%s %s]: %0.3fs\n",
[[component name] cString],
sel_getName(_cmd),
diff);
}
[content release];
[component release];
}
}
- (id)invokeActionForRequest:(WORequest *)_request inContext:(WOContext *)_ctx {
WOElement *content = [_ctx componentContent]; // content (valid in parent)
if (content) {
NSTimeInterval st = 0.0;
WOComponent *component = [_ctx component]; // reusable component
id result;
component = [component retain];
content = [content retain];
if (profileComponents)
st = [[NSDateClass date] timeIntervalSince1970];
[_ctx leaveComponent:component];
result = [content invokeActionForRequest:_request inContext:_ctx];
result = [result retain];
[_ctx enterComponent:component content:content];
if (profileComponents) {
NSTimeInterval diff;
int i;
diff = [[NSDateClass date] timeIntervalSince1970] - st;
for (i = [_ctx componentStackCount]; i >= 0; i--)
printf(" ");
printf("content: [%s %s]: %0.3fs\n",
[[component name] cString],
sel_getName(_cmd),
diff);
}
[content release];
[component release];
return [result autorelease];
}
return nil;
}
- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
WOElement *content;
content = [_ctx componentContent]; // content (valid in parent)
if (content) {
NSTimeInterval st = 0.0;
WOComponent *component;
component = [_ctx component]; // reusable component
component = [component retain];
content = [content retain];
#if DEBUG && 0
[_response appendContentHTMLString:@" Component:"];
[_response appendContentHTMLString:[component description]];
[_response appendContentHTMLString:@" Content:"];
[_response appendContentHTMLString:[content description]];
#endif
if (profileComponents)
st = [[NSDateClass date] timeIntervalSince1970];
[_ctx leaveComponent:component];
[content appendToResponse:_response inContext:_ctx];
[_ctx enterComponent:component content:content];
if (profileComponents) {
NSTimeInterval diff;
int i;
diff = [[NSDateClass date] timeIntervalSince1970] - st;
for (i = [_ctx componentStackCount]; i >= 0; i--)
printf(" ");
printf("content: [%s %s]: %0.3fs\n",
[[component name] cString],
sel_getName(_cmd),
diff);
}
[content release];
[component release];
}
else {
#if DEBUG && 0
[_response appendContentHTMLString:@" Missing content in component: "];
[_response appendContentHTMLString:[[_ctx component] description]];
#endif
}
}
@end /* WOComponentContent */
|