]> err.no Git - sope/blobdiff - sope-appserver/NGObjWeb/WOContext.m
minor code cleanups
[sope] / sope-appserver / NGObjWeb / WOContext.m
index 70dd7c06924a86a8997ffdca159cda33b2035e42..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 {
@@ -689,6 +702,20 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
   /* 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;
@@ -753,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];
@@ -784,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:)];
@@ -940,6 +967,14 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
 #endif
 }
 
+/* languages for resource lookup (non-WO) */
+
+- (NSArray *)resourceLookupLanguages {
+  return [self hasSession] ? [[self session] languages]
+                           : [[self request] browserLanguages];
+}
+
+
 /* DeprecatedMethodsInWO4 */
 
 - (WOApplication *)application {
@@ -987,8 +1022,7 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
   return url;
 }
 
-@end /* WOContext(DeprecatedMethodsInWO4) */
-
+@end /* WOContext */
 
 
 @implementation WOComponent(Cursors)