/*
- 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];
}
- (BOOL)savePageRequired {
- return self->savePageRequired;
+ return self->wcFlags.savePageRequired ? YES : NO;
}
/* cursors */
/* 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
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)
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->cycleContext) == nil)
+ 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:@"_"];
}