From 018fcdf3f2527c242ffe1de301dc123af7a339f1 Mon Sep 17 00:00:00 2001 From: znek Date: Tue, 4 Jan 2005 16:18:08 +0000 Subject: [PATCH] Useful new features for WOContext git-svn-id: http://svn.opengroupware.org/SOPE/trunk@483 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- .../Associations/WOLabelAssociation.m | 6 +-- .../Associations/WOResourceURLAssociation.m | 4 +- sope-appserver/NGObjWeb/ChangeLog | 18 +++++++ sope-appserver/NGObjWeb/Defaults.plist | 1 + .../NGObjWeb/DynamicElements/WOBody.m | 4 +- .../DynamicElements/WOEmbeddedObject.m | 12 ++--- .../NGObjWeb/DynamicElements/WOImageButton.m | 4 +- .../NGObjWeb/DynamicElements/WOJavaScript.m | 8 ++- .../NGObjWeb/DynamicElements/WOResourceURL.m | 12 ++--- .../DynamicElements/_WOComplexHyperlink.m | 4 +- .../DynamicElements/_WOConstResourceImage.m | 4 +- sope-appserver/NGObjWeb/NGObjWeb/WOContext.h | 10 +++- .../NGObjWeb/SoObjects/SoPageInvocation.m | 4 +- .../SoObjects/SoProductResourceManager.m | 4 +- sope-appserver/NGObjWeb/Version | 2 +- sope-appserver/NGObjWeb/WOApplication.m | 10 ++-- sope-appserver/NGObjWeb/WOComponent.m | 27 ++++------ .../NGObjWeb/WOComponentDefinition.m | 10 ++-- sope-appserver/NGObjWeb/WOContext.m | 53 ++++++++++++------- sope-appserver/NGObjWeb/WOStats.m | 13 +++-- 20 files changed, 109 insertions(+), 101 deletions(-) diff --git a/sope-appserver/NGObjWeb/Associations/WOLabelAssociation.m b/sope-appserver/NGObjWeb/Associations/WOLabelAssociation.m index 16b1ece0..0e19bc8e 100644 --- a/sope-appserver/NGObjWeb/Associations/WOLabelAssociation.m +++ b/sope-appserver/NGObjWeb/Associations/WOLabelAssociation.m @@ -117,10 +117,8 @@ /* lookup languages */ - ctx = [_component context]; - languages = [ctx hasSession] - ? [[ctx session] languages] - : [[ctx request] browserLanguages]; + ctx = [_component context]; + languages = [ctx resourceLookupLanguages]; /* find resource manager */ diff --git a/sope-appserver/NGObjWeb/Associations/WOResourceURLAssociation.m b/sope-appserver/NGObjWeb/Associations/WOResourceURLAssociation.m index 194e72c0..8fcc28bc 100644 --- a/sope-appserver/NGObjWeb/Associations/WOResourceURLAssociation.m +++ b/sope-appserver/NGObjWeb/Associations/WOResourceURLAssociation.m @@ -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: %@", diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 3710d7b0..fb281eea 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,5 +1,23 @@ 2005-01-04 Marcus Mueller + * 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 diff --git a/sope-appserver/NGObjWeb/Defaults.plist b/sope-appserver/NGObjWeb/Defaults.plist index 54b8ff68..4dae0de5 100644 --- a/sope-appserver/NGObjWeb/Defaults.plist +++ b/sope-appserver/NGObjWeb/Defaults.plist @@ -17,6 +17,7 @@ WOComponentRequestHandlerKey = "wo"; WOCompoundElementPool = NO; WOContactSNS = NO; + WOContextClass = WOContext; WOCoreOnApplicationException = NO; WOCoreOnAwakeComponentInCtxDealloc = NO; WOCoreOnHTTPAdaptorException = NO; diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOBody.m b/sope-appserver/NGObjWeb/DynamicElements/WOBody.m index 8774f818..d3ba1f29 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOBody.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOBody.m @@ -108,9 +108,7 @@ 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]; diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOEmbeddedObject.m b/sope-appserver/NGObjWeb/DynamicElements/WOEmbeddedObject.m index d917f750..0ddd11c6 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOEmbeddedObject.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOEmbeddedObject.m @@ -158,13 +158,11 @@ 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]); diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOImageButton.m b/sope-appserver/NGObjWeb/DynamicElements/WOImageButton.m index 88daa734..8e3bd41b 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOImageButton.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOImageButton.m @@ -209,9 +209,7 @@ 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){ diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOJavaScript.m b/sope-appserver/NGObjWeb/DynamicElements/WOJavaScript.m index 95c56ae2..af5f5d70 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOJavaScript.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOJavaScript.m @@ -86,11 +86,9 @@ 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 */ diff --git a/sope-appserver/NGObjWeb/DynamicElements/WOResourceURL.m b/sope-appserver/NGObjWeb/DynamicElements/WOResourceURL.m index c3451ba3..2c4ce878 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/WOResourceURL.m +++ b/sope-appserver/NGObjWeb/DynamicElements/WOResourceURL.m @@ -131,13 +131,11 @@ 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]); diff --git a/sope-appserver/NGObjWeb/DynamicElements/_WOComplexHyperlink.m b/sope-appserver/NGObjWeb/DynamicElements/_WOComplexHyperlink.m index 2347ade8..4af6b506 100644 --- a/sope-appserver/NGObjWeb/DynamicElements/_WOComplexHyperlink.m +++ b/sope-appserver/NGObjWeb/DynamicElements/_WOComplexHyperlink.m @@ -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, ")_ctx request] browserLanguages]; + languages = [_ctx resourceLookupLanguages]; /* instantiate */ diff --git a/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m b/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m index a59cbb6b..64607bec 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m +++ b/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m @@ -256,9 +256,7 @@ static BOOL debugOn = NO; /* ask resource-manager (self) for path */ - languages = [_ctx hasSession] - ? [(WOSession *)[_ctx session] languages] - : [[(id )_ctx request] browserLanguages]; + languages = [_ctx resourceLookupLanguages]; p = [self pathForResourceNamed:_key inFramework:[b bundlePath] diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index b6aef3db..27a018f8 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -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 diff --git a/sope-appserver/NGObjWeb/WOApplication.m b/sope-appserver/NGObjWeb/WOApplication.m index 7e82ea06..ea8f4af5 100644 --- a/sope-appserver/NGObjWeb/WOApplication.m +++ b/sope-appserver/NGObjWeb/WOApplication.m @@ -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]; diff --git a/sope-appserver/NGObjWeb/WOComponent.m b/sope-appserver/NGObjWeb/WOComponent.m index 09ab7fd2..a21d60fe 100644 --- a/sope-appserver/NGObjWeb/WOComponent.m +++ b/sope-appserver/NGObjWeb/WOComponent.m @@ -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; } diff --git a/sope-appserver/NGObjWeb/WOComponentDefinition.m b/sope-appserver/NGObjWeb/WOComponentDefinition.m index c41ceedb..1339f275 100644 --- a/sope-appserver/NGObjWeb/WOComponentDefinition.m +++ b/sope-appserver/NGObjWeb/WOComponentDefinition.m @@ -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]; } diff --git a/sope-appserver/NGObjWeb/WOContext.m b/sope-appserver/NGObjWeb/WOContext.m index 0f72aa89..c65423da 100644 --- a/sope-appserver/NGObjWeb/WOContext.m +++ b/sope-appserver/NGObjWeb/WOContext.m @@ -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) diff --git a/sope-appserver/NGObjWeb/WOStats.m b/sope-appserver/NGObjWeb/WOStats.m index 904336ee..e13b3105 100644 --- a/sope-appserver/NGObjWeb/WOStats.m +++ b/sope-appserver/NGObjWeb/WOStats.m @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -139,13 +140,11 @@ 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; -- 2.39.5