/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2000-2005 SKYRIX Software AG
- This file is part of OpenGroupware.org.
+ This file is part of SOPE.
- OGo is free software; you can redistribute it and/or modify it under
+ 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.
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ 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 OGo; see the file COPYING. If not, write to the
+ 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.
*/
@implementation WOContext
+ (int)version {
- return 7;
-}
-
-static Class MutableStrClass = Nil;
-static int contextCount = 0;
-static int logComponents = -1;
-static int relativeURLs = -1;
-static BOOL debugOn = NO;
-static int debugCursor = -1;
-static BOOL debugComponentAwake = NO;
-static BOOL testNSURLs = NO;
-static BOOL newCURLStyle = NO;
+ return 8;
+}
+
+static Class WOContextClass = Nil;
+static Class MutableStrClass = Nil;
+static int contextCount = 0;
+static int logComponents = -1;
+static int relativeURLs = -1;
+static BOOL debugOn = NO;
+static int debugCursor = -1;
+static BOOL debugComponentAwake = NO;
+static BOOL testNSURLs = NO;
+static BOOL newCURLStyle = NO;
static NSString *WOApplicationSuffix = nil;
+ (void)initialize {
- NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
- static BOOL didInitialize = NO;
- if (didInitialize) return;
+ static BOOL didInit = NO;
+ NSUserDefaults *ud;
+ NSString *cn;
+
+ if (didInit) return;
+
+ didInit = YES;
+
+ ud = [NSUserDefaults standardUserDefaults];
if (WOAppClass == Nil)
WOAppClass = [WOApplication class];
if (MutableStrClass == Nil)
MutableStrClass = [NSMutableString class];
- didInitialize = YES;
-
+ cn = [ud stringForKey:@"WOContextClass"];
+ WOContextClass = NSClassFromString(cn);
+ NSAssert1(WOContextClass != Nil,
+ @"Couldn't instantiate WOContextClass (%@)!", cn);
+
logComponents = [[ud objectForKey:@"WOLogComponents"] boolValue] ? 1 : 0;
relativeURLs = [[ud objectForKey:@"WOUseRelativeURLs"] boolValue]? 1 : 0;
debugCursor = [ud boolForKey:@"WODebugCursor"] ? 1 : 0;
WOApplicationSuffix = [[ud stringForKey:@"WOApplicationSuffix"] copy];
}
-+ (id)contextWithRequest:(WORequest *)_request {
- return [[(WOContext *)[self alloc] initWithRequest:_request] autorelease];
++ (id)contextWithRequest:(WORequest *)_r {
+ return [[(WOContext *)[WOContextClass alloc] initWithRequest:_r] autorelease];
}
- (id)initWithRequest:(WORequest *)_request {
if ((self = [super init])) {
unsigned char buf[24];
- self->qpJoin = @"&";
+ self->qpJoin = @"&";
sprintf(buf, "%03x%08x%08x", ++contextCount, (int)time(NULL), (int)self);
self->ctxId = [[NSString alloc] initWithCString:buf];
+ /* per default close tags in XML style */
+ self->wcFlags.xmlStyleEmptyElements = 1;
+
self->elementID = [[WOElementID alloc] init];
self->awakeComponents = [[NSMutableSet alloc] initWithCapacity:64];
/* components */
+- (void)_addAwakeComponent:(WOComponent *)_component {
+ if (_component == nil)
+ return;
+
+ if ([self->awakeComponents containsObject:_component])
+ return;
+
+ /* wake up component */
+ if (debugComponentAwake)
+ [self logWithFormat:@"mark component awake: %@", _component];
+
+ [self->awakeComponents addObject:_component];
+}
+
+- (void)_awakeComponent:(WOComponent *)_component {
+ if (_component == nil)
+ return;
+
+ if ([self->awakeComponents containsObject:_component])
+ return;
+
+ /* wake up component */
+ if (debugComponentAwake)
+ [self logWithFormat:@"awake component: %@", _component];
+
+ [_component _awakeWithContext:self];
+
+ [self _addAwakeComponent:_component];
+
+ if (debugComponentAwake)
+ [self logWithFormat:@"woke up component: %@", _component];
+}
+
- (void)sleepComponents {
NSEnumerator *e;
WOComponent *component;
BOOL sendSleepToPage;
+
+ if (debugComponentAwake) {
+ [self logWithFormat:@"sleep %d components ...",
+ [self->awakeComponents count]];
+ }
sendSleepToPage = YES;
e = [self->awakeComponents objectEnumerator];
while ((component = [e nextObject])) {
if (debugComponentAwake)
- [self logWithFormat:@"sleep component: %@", component];
+ [self logWithFormat:@" sleep component: %@", component];
[component _sleepWithContext:self];
if (component == self->page) sendSleepToPage = NO;
}
if (sendSleepToPage && (self->page != nil)) {
if (debugComponentAwake)
- [self logWithFormat:@"sleep page: %@", self->page];
+ [self logWithFormat:@" sleep page: %@", self->page];
[self->page _sleepWithContext:self];
}
+ if (debugComponentAwake) {
+ [self logWithFormat:@"done sleep %d components.",
+ [self->awakeComponents count]];
+ }
[self->awakeComponents removeAllObjects];
}
}
- (BOOL)savePageRequired {
- return self->savePageRequired;
+ return self->wcFlags.savePageRequired ? YES : NO;
}
/* cursors */
self->contentStack[(int)self->componentStackCount] = [_content retain];
self->componentStackCount++;
- if (![self->awakeComponents containsObject:_component]) {
- /* wake up component */
- if (debugComponentAwake)
- [self logWithFormat:@"awake component: %@", _component];
-
- [_component _awakeWithContext:self];
- [self->awakeComponents addObject:_component];
-
- if (debugComponentAwake)
- [self logWithFormat:@"woke up component: %@", _component];
- }
+ [self _awakeComponent:_component];
if (parent) {
if ([_component synchronizesVariablesWithBindings])
}
if ([serverURL length] == 0) {
- [self logWithFormat:
- @"ERROR: could not find x-webobjects-server-url header !"];
+ [self errorWithFormat:@"could not find x-webobjects-server-url header !"];
return nil;
}
}
- (NSURL *)applicationURL {
- if (self->appURL == nil) {
- NSString *s;
+ NSString *s;
+
+ if (self->appURL != nil)
+ return self->appURL;
- s = [self->request adaptorPrefix];
- if ([s length] > 0) {
- s = [NSString stringWithFormat:@"%@/%@/",
- s, [self->request applicationName]];
- }
- else
- s = [[self->request applicationName] stringByAppendingString:@"/"];
-
- self->appURL =
- [[NSURL URLWithString:s relativeToURL:[self serverURL]] retain];
+ // TODO: we should ensure that the suffix (.woa) is in the URL
+
+ s = [self->request adaptorPrefix];
+ if ([s length] > 0) {
+ s = [[[s stringByAppendingString:@"/"]
+ stringByAppendingString:[self->request applicationName]]
+ stringByAppendingString:@"/"];
}
+ else
+ s = [[self->request applicationName] stringByAppendingString:@"/"];
+
+ self->appURL =
+ [[NSURL URLWithString:s relativeToURL:[self serverURL]] retain];
return self->appURL;
}
- (NSURL *)urlForKey:(NSString *)_key {
/* forms */
- (void)setInForm:(BOOL)_form {
- self->inForm = _form;
+ self->wcFlags.inForm = _form ? 1 : 0;
}
- (BOOL)isInForm {
- return self->inForm;
+ return self->wcFlags.inForm ? YES : NO;
}
- (void)addActiveFormElement:(WOElement *)_formElement {
[self senderID]];
}
-@end /* WOContext */
-
-@implementation WOContext(ElementIDs)
+/* ElementIDs */
- (NSString *)elementID {
return [self->elementID elementID];
return [self->reqElementID consumeElementID];
}
-@end /* WOContext(ElementIDs) */
-
-@implementation WOContext(URLs)
+/* URLs */
- (void)_generateCompleteURLs {
/* described in Apple TIL article 70101 */
}
+- (void)setQueryPathSeparator:(NSString *)_sp {
+ ASSIGNCOPY(self->qpJoin, _sp);
+}
+- (NSString *)queryPathSeparator {
+ return self->qpJoin;
+}
+
+- (void)setGenerateXMLStyleEmptyElements:(BOOL)_flag {
+ self->wcFlags.xmlStyleEmptyElements = _flag ? 1 : 0;
+}
+- (BOOL)generateXMLStyleEmptyElements {
+ return self->wcFlags.xmlStyleEmptyElements ? YES : NO;
+}
+
- (NSString *)queryStringFromDictionary:(NSDictionary *)_queryDict {
NSEnumerator *keys;
NSString *key;
NSMutableString *qs;
NSString *p;
- self->savePageRequired = YES;
+ self->wcFlags.savePageRequired = 1;
qs = [MutableStrClass stringWithCapacity:64];
[qs appendString:WORequestValueSenderID];
static NSMutableString *url = nil; // THREAD
static IMP addStr = NULL;
NSString *s;
-
- self->savePageRequired = YES;
+
+ self->wcFlags.savePageRequired = 1;
if (url == nil) {
url = [[MutableStrClass alloc] initWithCapacity:256];
addStr = [url methodForSelector:@selector(appendString:)];
queryString:(NSString *)_query
{
if (testNSURLs) { /* use NSURLs for processing */
- NSURL *rqUrl;
+ NSURL *rqUrl;
if ([_path hasPrefix:@"/"]) {
#if DEBUG
- [self logWithFormat:@"WARNING: got absolute path '%@'", _path];
+ [self warnWithFormat:@"got absolute path '%@'", _path];
#endif
_path = [_path substringFromIndex:1];
}
url = [MutableStrClass stringWithCapacity:256];
addStr = [url methodForSelector:@selector(appendString:)];
-
+
/* static part */
if (self->urlPrefix == nil) {
if (!relativeURLs) {
addStr(url, @selector(appendString:), tmp);
}
}
-
+
addStr(url, @selector(appendString:), [self->request adaptorPrefix]);
addStr(url, @selector(appendString:), @"/");
tmp = [[self request] applicationName];
#endif
}
-@end /* WOContext(URLs) */
+/* languages for resource lookup (non-WO) */
-@implementation WOContext(DeprecatedMethodsInWO4)
+- (NSArray *)resourceLookupLanguages {
+ return [self hasSession] ? [[self session] languages]
+ : [[self request] browserLanguages];
+}
+
+
+/* DeprecatedMethodsInWO4 */
- (WOApplication *)application {
if (self->application == nil)
#if DEBUG
if ([url length] == 0) {
- NSLog(@"WARNING(%s): could not determine session URL prefix !",
- __PRETTY_FUNCTION__);
+ [self warnWithFormat:@"(%s): could not determine session URL prefix !",
+ __PRETTY_FUNCTION__];
}
#endif
return url;
}
-@end /* WOContext(DeprecatedMethodsInWO4) */
+@end /* WOContext */
+
@implementation WOComponent(Cursors)
- (void)pushCursor:(id)_obj {
- NSMutableArray *ctxStack;
-
if (debugCursor)
[self logWithFormat:@"enter cursor: %@", _obj];
- if ((ctxStack = [self objectForKey:@"_ODCycleCtx"]) == nil) {
- ctxStack = [NSMutableArray arrayWithCapacity:8];
- [self setObject:ctxStack forKey:@"_ODCycleCtx"];
- }
+ if (!self->cycleContext)
+ self->cycleContext = [[NSMutableArray alloc] initWithCapacity:8];
/* add to cursor stack */
- [ctxStack addObject:(_obj ? _obj : [NSNull null])];
+ [self->cycleContext addObject:(_obj ? _obj : [NSNull null])];
/* set active cursor */
- if (![_obj isNotNull]) _obj = nil;
[self setObject:_obj forKey:@"_"];
}
[self setObject:nil forKey:@"_"];
/* restore old ctx */
- if ((ctxStack = [self objectForKey:@"_ODCycleCtx"])) {
+ if ((ctxStack = self->cycleContext) != nil) {
unsigned count;
if ((count = [ctxStack count]) > 0) {
}
#if DEBUG
else {
- [self debugWithFormat:@"WARNING: -popCursor called without cycle ctx !"];
+ [self warnWithFormat:@"-popCursor called without cycle ctx !"];
}
#endif
// TODO: why do we check for _ODCycleCtx, if we query '_' ?
- if ((ctxStack = [self objectForKey:@"_ODCycleCtx"]) == nil)
+ if ((ctxStack = self->cycleContext) == nil)
/* no cycle context setup for component ... */
return self;
if ([ctxStack count] == 0)