]> err.no Git - sope/blobdiff - sope-appserver/NGObjWeb/WOContext.m
minor code cleanups
[sope] / sope-appserver / NGObjWeb / WOContext.m
index cc757e1f4c690469878f27487e15c9251080767b..a0d76600684da9e4b42dfdb85fb18a18895c2411 100644 (file)
@@ -1,20 +1,20 @@
 /*
-  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.
 */
@@ -49,32 +49,42 @@ static Class WOAppClass = Nil;
 @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;
@@ -82,18 +92,21 @@ static NSString *WOApplicationSuffix = nil;
   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];
     
@@ -323,7 +336,7 @@ static NSString *WOApplicationSuffix = nil;
 }
 
 - (BOOL)savePageRequired {
-  return self->savePageRequired;
+  return self->wcFlags.savePageRequired ? YES : NO;
 }
 
 /* cursors */
@@ -551,10 +564,10 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
 /* 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 {
@@ -650,9 +663,7 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
                      [self  senderID]];
 }
 
-@end /* WOContext */
-
-@implementation WOContext(ElementIDs)
+/* ElementIDs */
 
 - (NSString *)elementID {
   return [self->elementID elementID];
@@ -685,14 +696,26 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
   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;
@@ -757,7 +780,7 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
     NSMutableString *qs;
     NSString *p;
   
-    self->savePageRequired = YES;
+    self->wcFlags.savePageRequired = 1;
     qs = [MutableStrClass stringWithCapacity:64];
   
     [qs appendString:WORequestValueSenderID];
@@ -788,8 +811,8 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
     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:)];
@@ -818,7 +841,7 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
   queryString:(NSString *)_query
 {
   if (testNSURLs) { /* use NSURLs for processing */
-    NSURL    *rqUrl;
+    NSURL *rqUrl;
     
     if ([_path hasPrefix:@"/"]) {
 #if DEBUG
@@ -855,7 +878,7 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
   
     url = [MutableStrClass stringWithCapacity:256];
     addStr = [url methodForSelector:@selector(appendString:)];
-  
+
     /* static part */
     if (self->urlPrefix == nil) {
       if (!relativeURLs) {
@@ -869,7 +892,7 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
          addStr(url, @selector(appendString:), tmp);
        }
       }
-  
+
       addStr(url, @selector(appendString:), [self->request adaptorPrefix]);
       addStr(url, @selector(appendString:), @"/");
       tmp = [[self request] applicationName];
@@ -944,9 +967,15 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
 #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)
@@ -993,24 +1022,22 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
   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:@"_"];
 }