]> err.no Git - sope/commitdiff
Useful new features for WOContext
authorznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Tue, 4 Jan 2005 16:18:08 +0000 (16:18 +0000)
committerznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Tue, 4 Jan 2005 16:18:08 +0000 (16:18 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@483 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

20 files changed:
sope-appserver/NGObjWeb/Associations/WOLabelAssociation.m
sope-appserver/NGObjWeb/Associations/WOResourceURLAssociation.m
sope-appserver/NGObjWeb/ChangeLog
sope-appserver/NGObjWeb/Defaults.plist
sope-appserver/NGObjWeb/DynamicElements/WOBody.m
sope-appserver/NGObjWeb/DynamicElements/WOEmbeddedObject.m
sope-appserver/NGObjWeb/DynamicElements/WOImageButton.m
sope-appserver/NGObjWeb/DynamicElements/WOJavaScript.m
sope-appserver/NGObjWeb/DynamicElements/WOResourceURL.m
sope-appserver/NGObjWeb/DynamicElements/_WOComplexHyperlink.m
sope-appserver/NGObjWeb/DynamicElements/_WOConstResourceImage.m
sope-appserver/NGObjWeb/NGObjWeb/WOContext.h
sope-appserver/NGObjWeb/SoObjects/SoPageInvocation.m
sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m
sope-appserver/NGObjWeb/Version
sope-appserver/NGObjWeb/WOApplication.m
sope-appserver/NGObjWeb/WOComponent.m
sope-appserver/NGObjWeb/WOComponentDefinition.m
sope-appserver/NGObjWeb/WOContext.m
sope-appserver/NGObjWeb/WOStats.m

index 16b1ece0cb37c32e7dda8e1119b9a789016fe408..0e19bc8ee5ee67c295c1a7e3d46524806eec44bd 100644 (file)
 
   /* lookup languages */
   
-  ctx = [_component context];
-  languages = [ctx hasSession]
-    ? [[ctx session] languages]
-    : [[ctx request] browserLanguages];
+  ctx       = [_component context];
+  languages = [ctx resourceLookupLanguages];
 
   /* find resource manager */
   
index 194e72c06e0ae97602430cfd446ad0f2a4b0476e..8fcc28bc6ad1879a8bb55ecdb8ab19115a9b6643 100644 (file)
@@ -96,9 +96,7 @@ static BOOL doDebug = NO;
   if ((ctx = [_component context]) == nil)
     ctx = [[WOApplication application] context];
   rq    = [ctx request];
-  langs = [ctx hasSession]
-    ? [[ctx session] languages]
-    : [[ctx request] browserLanguages];
+  langs = [ctx resourceLookupLanguages];
   
   if (doDebug) {
     [self debugWithFormat:@"  languages: %@", 
index 3710d7b0883af72be91c17778f78c75680c3cf25..fb281eea3ea3c081a52fb9b3e3f28cea5150f320 100644 (file)
@@ -1,5 +1,23 @@
 2005-01-04  Marcus Mueller  <znek@mulle-kybernetik.com>
 
+       * v4.5.106
+
+       * Defaults.plist: added new default "WOContextClass".
+
+       * WOContext.[hm]: Factory method +contextWithRequest: observes new user
+         default "WOContextClass" to chose proper class for new contexts.
+          New method -resourceLookupLanguages, aggregates the
+         current lookup strategy in one place. Ideal place for overriding the
+         lookup behaviour in conjunction with new WOContextClass default.
+
+       * WOApplication.m, WOComponentDefinition.m, WOStats.m, WOComponent.m,
+         DynamicElements/{_WOComplexHyperlink.m, WOImageButton.m,
+         _WOConstResourceImage.m, WOJavaScript.m, WOResourceURL.m,
+         WOEmbeddedObject.m, WOBody.m}, SoObjects/{SoPageInvocation.m,
+         SoProductResourceManager.m},
+         Associations/{WOResourceURLAssociation.m, WOLabelAssociation.m}:
+         use new -resourceLookupLanguages API.
+
        * v4.5.105
 
        * NGObjWeb.xcode: removed target "SoProducts" from "all". By using a
index 54b8ff68ae0c7f115062b4f6e012e11a5576bd92..4dae0de50dc2fef6b761080bf2088cd39dc2f79a 100644 (file)
@@ -17,6 +17,7 @@
   WOComponentRequestHandlerKey          = "wo";
   WOCompoundElementPool                 = NO;
   WOContactSNS                          = NO;
+  WOContextClass                        = WOContext;
   WOCoreOnApplicationException          = NO;
   WOCoreOnAwakeComponentInCtxDealloc    = NO;
   WOCoreOnHTTPAdaptorException          = NO;
index 8774f818eb4bb497b3b2179868c70e63f5a7a29b..d3ba1f29ff2bfa157deed0ed6669b2789da9513c 100644 (file)
 
     WOResponse_AddCString(_response, " background=\"");
       
-    languages = [_ctx hasSession]
-      ? [[_ctx session] languages]
-      : [[_ctx request] browserLanguages];
+    languages = [_ctx resourceLookupLanguages];
       
     if ((rm = [[_ctx component] resourceManager]) == nil)
       rm = [[_ctx application] resourceManager];
index d917f75073effed9bb075d6b6040a86242c33069..0ddd11c69cee8905dc469c43c10673f0c523a092 100644 (file)
       else
         frameworkName = [[_ctx component] frameworkName];
       
-      languages = [_ctx hasSession]
-        ? [[_ctx session] languages]
-        : [[_ctx request] browserLanguages];
-      uFi = [rm urlForResourceNamed:uFi
-                inFramework:frameworkName
-                languages:languages
-                request:[_ctx request]];
+      languages = [_ctx resourceLookupLanguages];
+      uFi       = [rm urlForResourceNamed:uFi
+                      inFramework:frameworkName
+                      languages:languages
+                      request:[_ctx request]];
       if (uFi == nil) {
         NSLog(@"%@: did not find resource '%@'", sComponent,
               [self->filename stringValueInComponent:sComponent]);
index 88daa7341051f1a2ea7b27d53dc1e3c7c10eee4b..8e3bd41b2ec7e188f8a972d027d93ff6f4b018a9 100644 (file)
     if ((rm = [[_ctx component] resourceManager]) == nil)
       rm = [[_ctx application] resourceManager];
 
-    langs = [_ctx hasSession]
-      ? [[_ctx session] languages]
-      : [[_ctx request] browserLanguages];
+    langs = [_ctx resourceLookupLanguages];
     
     /* If 'framework' binding is not set, use parent component's framework */
     if (self->framework){
index 95c56ae256b9d567771bcd900544b71175ad4814..af5f5d707834e3cb9457353d78b80f6a60026135 100644 (file)
     if ((rm = [[_ctx component] resourceManager]) == nil)
       rm = [[_ctx application] resourceManager];
     
-    languages = [_ctx hasSession]
-      ? [[_ctx session] languages]
-      : [[_ctx request] browserLanguages];
-    s = [rm pathForResourceNamed:s inFramework:nil languages:languages];
-    if (s) s = [[NSString alloc] initWithContentsOfFile:s];
+    languages = [_ctx resourceLookupLanguages];
+    s         = [rm pathForResourceNamed:s inFramework:nil languages:languages];
+    if (s)  s = [[NSString alloc] initWithContentsOfFile:s];
   }
 
   /* append to response */
index c3451ba31e87b64b5d133998ad900b1656316c55..2c4ce8789050d24d1a3c514ed4f553e9906b6cee 100644 (file)
     else
       frameworkName = [sComponent frameworkName];
     
-    languages = [_ctx hasSession]
-      ? [[_ctx session] languages]
-      : [[_ctx request] browserLanguages];
-    uFi = [rm urlForResourceNamed:uFi
-              inFramework:frameworkName
-              languages:languages
-              request:[_ctx request]];
+    languages = [_ctx resourceLookupLanguages];
+    uFi       = [rm urlForResourceNamed:uFi
+                    inFramework:frameworkName
+                    languages:languages
+                     request:[_ctx request]];
     if (uFi == nil) {
       NSLog(@"%@: did not find resource '%@'", sComponent,
             [self->filename stringValueInComponent:sComponent]);
index 2347ade8b6282b136ae2a672632464b1b5cd10b3..4af6b5068d76feadfcc737570c7289e7a0cfd92b 100644 (file)
@@ -221,9 +221,7 @@ static Class NSURLClass = Nil;
   if (!((uFi != nil) || (uUri != nil))) 
     return;
 
-  languages = [_ctx hasSession]
-    ? [[_ctx session] languages]
-    : [[_ctx request] browserLanguages];
+  languages = [_ctx resourceLookupLanguages];
         
   WOResponse_AddCString(_resp, "<img src=\"");
   
index 9fafb654a016df8894fb43064a30db85016e1d8d..12da3b705828b0e6488802a091d21268eb0e9a98 100644 (file)
@@ -94,9 +94,7 @@ static BOOL debugOn = NO;
   if ((rm = [[_ctx component] resourceManager]) == nil)
     rm = [[_ctx application] resourceManager];
   
-  languages = [_ctx hasSession]
-    ? [[_ctx session] languages]
-    : [[_ctx request] browserLanguages];
+  languages = [_ctx resourceLookupLanguages];
 
   if (debugOn) {
     [self debugWithFormat:@"WOImage: filename '%@'\n  rm %@\n  languages %@",
index 2e9869b32c76a113ecc460407ee5d60589c2e2f2..b656c8f48bb30b03f1a5fe4a268f23519d969d34 100644 (file)
@@ -35,7 +35,7 @@
 */
 
 @class NSString, NSMutableDictionary, NSMutableArray, NSMutableSet;
-@class NSDictionary, NSURL;
+@class NSArray, NSDictionary, NSURL;
 @class WOApplication, WOSession, WOComponent, WORequest, WOResponse;
 @class WOElementID;
 
 
 @end
 
+@interface WOContext(SOPEAdditions)
+
+/* languages for resource lookup (non-WO) */
+
+- (NSArray *)resourceLookupLanguages;
+
+@end
+
 #endif /* __NGObjWeb_WOContext_H__ */
index d3472e75e088c8130d8f313264d63ef2dd38053c..ef2bca853167b8c2c2eff8fd3b40aa887045b54d 100644 (file)
@@ -146,9 +146,7 @@ static int debugOn = 0;
   
   /* determine language */
   
-  languages = [_ctx hasSession]
-    ? [(WOSession *)[_ctx session] languages]
-    : [[(id <WOPageGenerationContext>)_ctx request] browserLanguages];
+  languages = [_ctx resourceLookupLanguages];
 
   /* instantiate */
   
index a59cbb6b7d4b1bb3d404523c8428e3aa40493c33..64607becd6eb1765d92539de6fe120b782b2c445 100644 (file)
@@ -256,9 +256,7 @@ static BOOL debugOn = NO;
 
   /* ask resource-manager (self) for path */
   
-  languages = [_ctx hasSession]
-    ? [(WOSession *)[_ctx session] languages]
-    : [[(id <WOPageGenerationContext>)_ctx request] browserLanguages];
+  languages = [_ctx resourceLookupLanguages];
   
   p = [self pathForResourceNamed:_key 
            inFramework:[b bundlePath]
index b6aef3db06a6125179c84d54078fe4a11205ec0c..27a018f88e0d43461c56949e114b8d6e7ab7b84a 100644 (file)
@@ -1,6 +1,6 @@
 # version file
 
-SUBMINOR_VERSION:=105
+SUBMINOR_VERSION:=106
 
 # v4.5.91  requires libNGExtensions v4.5.134
 # v4.5.84  requires libNGExtensions v4.5.127
index 7e82ea069c7016c439b54f2efe2991b1c2694441..ea8f4af586e8baa4005c2ff89dc75a417b37dbca 100644 (file)
@@ -1024,17 +1024,15 @@ static NSString *rapidTurnAroundPath = nil;
   start = [self memoryStatistics];
 #endif
   
-  pool = [[NSAutoreleasePool alloc] init];
+  pool      = [[NSAutoreleasePool alloc] init];
   
-  languages = [_ctx hasSession]
-    ? [(WOSession *)[_ctx session] languages]
-    : [[_ctx request] browserLanguages];
+  languages = [_ctx resourceLookupLanguages];
 
   if ((rm = [[_ctx component] resourceManager]) == nil)
     rm = [self resourceManager];
   
-  page = [rm pageWithName:(_name != nil ? _name : @"Main")
-             languages:languages];
+  page      = [rm pageWithName:(_name != nil ? _name : @"Main")
+                  languages:languages];
   [page ensureAwakeInContext:_ctx];
   
   page = [page retain];
index 09ab7fd2efb19ae3412ba5eb05b68114480bb59e..a21d60feca8122608294768e73cd29c14e18263e 100644 (file)
@@ -344,9 +344,7 @@ static inline id _getExtraVar(WOComponent *self, NSString *_key) {
   NSArray *languages = nil;
   
 #if 0 // the component might not yet be awake !
-  languages = [self hasSession]
-    ? [[self session] languages]
-    : [[[self context] request] browserLanguages];
+  languages = [[self context] resourceLookupLanguages];
 #endif
   
   return [[self resourceManager]
@@ -440,16 +438,13 @@ static inline id _getExtraVar(WOComponent *self, NSString *_key) {
 }
 
 - (WOComponent *)pageWithName:(NSString *)_name {
-  NSArray *languages = nil;
+  NSArray           *languages;
   WOResourceManager *rm;
   WOComponent       *component;
   
-  languages = [self hasSession]
-    ? [(WOSession *)[self session] languages]
-    : [[[self context] request] browserLanguages];
-  
-  rm = [self resourceManager];
-  
+  languages = [[self context] resourceLookupLanguages];
+  rm        = [self resourceManager];
+
   /* 
      Note: this API is somewhat broken since the component expects the
            -initWithContext: message for initialization yet we pass no
@@ -476,9 +471,7 @@ static inline id _getExtraVar(WOComponent *self, NSString *_key) {
   NSArray *langs;
   IS_DEPRECATED;
   
-  langs = [self hasSession]
-    ? [(WOSession *)[self session] languages]
-    : [[[self context] request] browserLanguages];
+  langs = [[self context] resourceLookupLanguages];
   
   return [[[self application]
                  resourceManager]
@@ -660,11 +653,9 @@ static inline id _getExtraVar(WOComponent *self, NSString *_key) {
     return nil;
   }
   
-  languages = [self hasSession]
-    ? [(WOSession *)[self  session] languages]
-    : [[[self context] request] browserLanguages];
-  
-  tmpl = [resourceManager templateWithName:_name languages:languages];
+  languages = [[self context] resourceLookupLanguages];
+  tmpl      = [resourceManager templateWithName:_name languages:languages];
+
   if (debugTemplates) [self debugWithFormat:@"found template: %@", tmpl];
   return tmpl;
 }
index c41ceedb84e3c95c712222739679e649a89921b3..1339f275f9794d5086fa64313ca34f751c331f5b 100644 (file)
@@ -145,14 +145,12 @@ static NSNumber *noNum      = nil;
   [self setName:_cname];
   if ((self = [self initWithContext:_ctx])) {
     NSMutableDictionary *childComponents;
-    NSArray *langs;
-    
-    langs = [self hasSession]
-      ? [[self session] languages]
-      : [[_ctx request] browserLanguages];
+    NSArray             *langs;
+
+    langs = [[self context] resourceLookupLanguages];
     
     childComponents = [self instantiateChildComponentsInTemplate:_template
-                           languages:langs];
+                                             languages:langs];
     [self setSubComponents:childComponents];
     [self setTemplate:_template];
   }
index 0f72aa890a6b68aad1d22567868385a48fc73209..c65423da22a4b16af916899088048c420ba07d79 100644 (file)
@@ -52,29 +52,39 @@ static Class WOAppClass = Nil;
   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;
+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,8 +92,8 @@ 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 {
@@ -940,6 +950,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 +1005,7 @@ void WOContext_leaveComponent(WOContext *self, WOComponent *_component) {
   return url;
 }
 
-@end /* WOContext(DeprecatedMethodsInWO4) */
-
+@end /* WOContext */
 
 
 @implementation WOComponent(Cursors)
index 904336ee801a59ec731eafc73efec8c3f256b91e..e13b3105886de6c64ffe51f509a0f8cfc98cd4e2 100644 (file)
@@ -22,6 +22,7 @@
 #include <NGObjWeb/WODirectAction.h>
 #include <NGObjWeb/WOApplication.h>
 #include <NGObjWeb/WOResourceManager.h>
+#include <NGObjWeb/WOContext.h>
 #include <NGObjWeb/WORequest.h>
 #include <NGObjWeb/WOResponse.h>
 #include <NGObjWeb/WOSession.h>
 
   xslPath = [[NSUserDefaults standardUserDefaults]
                              stringForKey:@"WOStatsStylesheetName"];
-  languages = [self existingSession] != nil
-    ? [[self session] languages]
-    : [[self request] browserLanguages];
-  xslPath = [[app resourceManager] urlForResourceNamed:xslPath
-                                   inFramework:nil
-                                   languages:languages
-                                   request:[self request]];
+  languages = [[self context] resourceLookupLanguages];
+  xslPath   = [[app resourceManager] urlForResourceNamed:xslPath
+                                     inFramework:nil
+                                     languages:languages
+                                     request:[self request]];
   if ([xslPath hasPrefix:@"/missingresource"])
     xslPath = nil;