From a98ddcc77c1be66ecf644be1b3ba497df010367c Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 23 Feb 2005 17:14:10 +0000 Subject: [PATCH] major work on resource lookups git-svn-id: http://svn.opengroupware.org/SOPE/trunk@590 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 6 + .../SoObjects/SoProductResourceManager.m | 200 ++++++++++++------ sope-appserver/NGObjWeb/Version | 2 +- sope-appserver/WEExtensions/ChangeLog | 6 + sope-appserver/WEExtensions/Version | 2 +- .../WEExtensions/WEResourceManager.h | 1 + .../WEExtensions/WEResourceManager.m | 29 +-- 7 files changed, 163 insertions(+), 83 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 5de3e360..5295c990 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,9 @@ +2005-02-23 Helge Hess + + * SoObjects/SoProductResourceManager.m: major fixes in resource + processing, properly relay URL requests to the fallback or product + resource managers (v4.5.120) + 2005-02-22 Helge Hess * v4.5.119 diff --git a/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m b/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m index 0b3c5877..ca1fefe7 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m +++ b/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m @@ -32,6 +32,18 @@ #include #include "common.h" +/* + How is resource lookup supposed to work? + + First, we need to determine whether the resource being asked for is a + resource contained in the product bundle. If thats the case, this resource + manager will take of it. + + If not, there are two options: + a) the resource is from a different product, so we direct lookup to that + b) the resource is a "global" resource, so we ask the WOApplication manager +*/ + @interface WOResourceManager(UsedPrivates) - (NSString *)webServerResourcesPath; - (NSString *)resourcesPath; @@ -99,70 +111,89 @@ static BOOL debugOn = NO; return bundle; } -- (NSString *)pathForResourceNamed:(NSString *)_name +- (WOResourceManager *)resourceManagerForResourceNamed:(NSString *)_name inFramework:(NSString *)_frameworkName - languages:(NSArray *)_languages { - // TODO: should we do acquisition? (hm, don't think so!, done in lookup) - // but maybe we should not fall back to WOApplication resources - WOResourceManager *rm; SoProduct *bproduct; NSBundle *bundle; - NSString *path; - - if (debugOn) [self debugWithFormat:@"lookup resource: '%@'", _name]; /* determine product bundle or explicitly requested framework/bundle */ + + if ([_frameworkName length] == 0) + return self; if ((bundle = [self bundleForFrameworkName:_frameworkName]) == nil) - goto fallback; + return nil; bproduct = [[SoProductRegistry sharedProductRegistry] productForBundle:bundle]; - rm = [bproduct resourceManager]; if (debugOn) { [self debugWithFormat: - @" fwname %@\n bundle: %@\n product: %@", + @" fwname: '%@'\n bundle: '%@'\n product: '%@'", _frameworkName, bundle, bproduct]; } + return (bproduct == self->product) + ? self : (id)[bproduct resourceManager]; +} + +- (NSString *)primaryLookupPathForResourceNamed:(NSString *)_name + languages:(NSArray *)_l +{ + NSString *path; + + path = [[self->product bundle] + pathForResource:[_name stringByDeletingPathExtension] + ofType:[_name pathExtension] + inDirectory:@"Resources" + languages:_l]; + if (debugOn && path == nil) { + [self debugWithFormat:@" resource %@/%@ not found.", + _name, [_l componentsJoinedByString:@","]]; + } + return path; +} + +- (NSString *)pathForResourceNamed:(NSString *)_name + inFramework:(NSString *)_frameworkName + languages:(NSArray *)_languages +{ + // TODO: should we do acquisition? (hm, don't think so!, done in lookup) + // but maybe we should not fall back to WOApplication resources + WOResourceManager *rm; + NSString *path; - /* lookup resource in bundle */ + if (debugOn) [self debugWithFormat:@"lookup resource: '%@'", _name]; - if (bproduct == self->product || rm == self) { - path = [bundle pathForResource:[_name stringByDeletingPathExtension] - ofType:[_name pathExtension] - inDirectory:@"Resources" - languages:_languages]; - if (debugOn && path == nil) { - [self debugWithFormat:@" resource %@/%@ not found in bundle: %@", - _name, [_languages componentsJoinedByString:@","], bundle]; - } + /* determine resource manager to be actually used */ + + rm = [self resourceManagerForResourceNamed:_name inFramework:_frameworkName]; + + /* lookup resource */ + + if (rm == self) { + path = [self primaryLookupPathForResourceNamed:_name languages:_languages]; } - else { - /* delegate lookup to resource manager of other product */ + else if (rm != nil) { + /* delegate lookup to resource manager of other products */ path = [rm pathForResourceNamed:_name inFramework:_frameworkName languages:_languages]; if (debugOn && path == nil) [self debugWithFormat:@" resource %@ not found in rm: %@", _name, rm]; } + else + path = nil; + if (path != nil) { if (debugOn) [self debugWithFormat:@" => found: %@", path]; return path; } - /* fall back to WOResourceManager lookup */ - fallback: - - rm = [self fallbackResourceManager]; - if (rm != nil) { - return [rm pathForResourceNamed:_name inFramework:_frameworkName - languages:_languages]; - } - else { - return [super pathForResourceNamed:_name inFramework:_frameworkName - languages:_languages]; - } + /* fall back to global resource manager */ + + return [[self fallbackResourceManager] + pathForResourceNamed:_name inFramework:_frameworkName + languages:_languages]; } /* generate URL for resources (eg filename binding in WOImage) */ @@ -172,42 +203,12 @@ static BOOL debugOn = NO; return [[self fallbackResourceManager] webServerResourcesPath]; } -- (NSString *)urlForResourceNamed:(NSString *)_name - inFramework:(NSString *)_frameworkName - languages:(NSArray *)_languages - request:(WORequest *)_request -{ - NSString *resource = nil, *tmp; +- (NSString *)urlForProductRelativeResourcePath:(NSString *)resource { + NSString *tmp; NSString *path = nil, *sbase; unsigned len; NSString *url; - if (debugOn) [self debugWithFormat:@"lookup url: '%@'", _name]; - - if (_languages == nil) _languages = [_request browserLanguages]; - - resource = [self pathForResourceNamed:_name - inFramework:_frameworkName - languages:_languages]; -#if APPLE_Foundation_LIBRARY || NeXT_Foundation_LIBRARY - if ([resource rangeOfString:@"/Contents/"].length > 0) { - resource = [resource stringByReplacingString:@"/Contents" - withString:@""]; - } -#endif -#if 0 - tmp = [resource stringByStandardizingPath]; - if (tmp) resource = tmp; -#endif - - if (resource == nil) { - if (debugOn) { - [self debugWithFormat:@" => not found '%@' (fw=%@,langs=%@)", - _name, _frameworkName, [_languages componentsJoinedByString:@","]]; - } - return nil; - } - sbase = self->base; tmp = [sbase commonPrefixWithString:resource options:0]; @@ -239,6 +240,71 @@ static BOOL debugOn = NO; if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"]; url = [url stringByAppendingString:path]; + return url; +} + +- (NSString *)fixupResourcePath:(NSString *)resource { +#if APPLE_Foundation_LIBRARY || NeXT_Foundation_LIBRARY + if ([resource rangeOfString:@"/Contents/"].length > 0) { + resource = [resource stringByReplacingString:@"/Contents" + withString:@""]; + } +#endif +#if 0 + if ((tmp = [resource stringByStandardizingPath]) != nil) + resource = tmp; +#endif + return resource; +} + +- (NSString *)urlForResourceNamed:(NSString *)_name + inFramework:(NSString *)_frameworkName + languages:(NSArray *)_languages + request:(WORequest *)_request +{ + WOResourceManager *rm; + NSString *url; + + if (debugOn) [self debugWithFormat:@"lookup url: '%@'", _name]; + + if (_languages == nil) _languages = [_request browserLanguages]; + + /* determine resource manager to be actually used */ + + rm = [self resourceManagerForResourceNamed:_name inFramework:_frameworkName]; + + /* lookup resource */ + + url = nil; + if (rm == self) { /* handle it directly */ + NSString *resource; + + resource = [self primaryLookupPathForResourceNamed:_name + languages:_languages]; + resource = [self fixupResourcePath:resource]; + if (debugOn) [self debugWithFormat:@" resource to URL: %@", resource]; + + if (resource != nil) { + url = [self urlForProductRelativeResourcePath:resource]; + } + else if (debugOn) { + [self debugWithFormat:@" => not found '%@' (fw=%@,langs=%@)", + _name, _frameworkName, + [_languages componentsJoinedByString:@","]]; + } + } + else if (rm != nil) { /* delegate to other product */ + if (debugOn) [self debugWithFormat:@" lookup with rm: %@", rm]; + url = [rm urlForResourceNamed:_name inFramework:_frameworkName + languages:_languages request:_request]; + } + + if (url == nil) { /* fallback */ + rm = [self fallbackResourceManager]; + if (debugOn) [self debugWithFormat:@" fallback: %@", rm]; + url = [rm urlForResourceNamed:_name inFramework:_frameworkName + languages:_languages request:_request]; + } if (debugOn) [self debugWithFormat:@" => '%@'", url]; return url; diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index f34e1bd4..fc05a789 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=119 +SUBMINOR_VERSION:=120 # v4.5.91 requires libNGExtensions v4.5.134 # v4.5.84 requires libNGExtensions v4.5.127 diff --git a/sope-appserver/WEExtensions/ChangeLog b/sope-appserver/WEExtensions/ChangeLog index d9e02f27..ff572242 100644 --- a/sope-appserver/WEExtensions/ChangeLog +++ b/sope-appserver/WEExtensions/ChangeLog @@ -1,3 +1,9 @@ +2005-02-23 Helge Hess + + * WEResourceManager.m: lookup web resources in + Library/AppName/WebServerResources, fixed an incorrect reference to + OGo (w4.5.68) + 2005-02-17 Helge Hess * v4.5.67 diff --git a/sope-appserver/WEExtensions/Version b/sope-appserver/WEExtensions/Version index cc586265..853c2846 100644 --- a/sope-appserver/WEExtensions/Version +++ b/sope-appserver/WEExtensions/Version @@ -1,5 +1,5 @@ # version file -SUBMINOR_VERSION:=67 +SUBMINOR_VERSION:=68 # v4.5.65 requires libNGObjWeb v4.5.106 diff --git a/sope-appserver/WEExtensions/WEResourceManager.h b/sope-appserver/WEExtensions/WEResourceManager.h index ff9a0749..96acc771 100644 --- a/sope-appserver/WEExtensions/WEResourceManager.h +++ b/sope-appserver/WEExtensions/WEResourceManager.h @@ -62,6 +62,7 @@ - (NSString *)shareDirectoryName; - (NSString *)gsTemplatesDirectoryName; +- (NSString *)gsWebDirectoryName; @end diff --git a/sope-appserver/WEExtensions/WEResourceManager.m b/sope-appserver/WEExtensions/WEResourceManager.m index 23ea6bb5..5cdf74ab 100644 --- a/sope-appserver/WEExtensions/WEResourceManager.m +++ b/sope-appserver/WEExtensions/WEResourceManager.m @@ -51,16 +51,18 @@ static NSString *themesDirName = @"Themes"; } + (NSString *)gsTemplatesSubpath { - static NSString *gsTemplatesSubpath = nil; NSString *p; - if (gsTemplatesSubpath != nil) - return gsTemplatesSubpath; - p = [[WOApplication application] gsTemplatesDirectoryName]; p = [@"Library/" stringByAppendingString:p]; - gsTemplatesSubpath = [p copy]; - return gsTemplatesSubpath; + return p; +} ++ (NSString *)gsWebSubpath { + NSString *p; + + p = [[WOApplication application] gsWebDirectoryName]; + p = [@"Library/" stringByAppendingString:p]; + return p; } /* locate resource directories */ @@ -156,7 +158,7 @@ static NSString *themesDirName = @"Themes"; prefix = [[ud stringForKey:@"WOResourcePrefix"] copy]; wsPathes = [[self findResourceDirectoryPathesWithName: - @"WebServerResources/" fhsName:@"www/"] copy]; + [self gsWebSubpath] fhsName:@"www/"] copy]; if (debugOn) NSLog(@"WebServerResources pathes: %@", wsPathes); @@ -480,10 +482,6 @@ checkCache(NSDictionary *_cache, WEResourceKey *_key, NSEnumerator *e; NSString *path; - // TODO: some kind of hack ... - need to decide how we want to deal with - // the bundle less main component - _appName = @"OpenGroupware10a"; - if (debugOn) { [self logWithFormat:@"lookup URL of resource: '%@'/%@/%@", _name, _fwName, _lang]; @@ -638,9 +636,9 @@ checkCache(NSDictionary *_cache, WEResourceKey *_key, [_langs componentsJoinedByString:@","]]; } - appName = [(WOApplication *)[WOApplication application] name]; + appName = [_request applicationName]; if (appName == nil) - appName = [_request applicationName]; + appName = [(WOApplication *)[WOApplication application] name]; /* check languages */ @@ -653,7 +651,7 @@ checkCache(NSDictionary *_cache, WEResourceKey *_key, inFramework:_fwName language:language applicationName:appName]; - if (url) { + if (url != nil) { if (debugOn) [self logWithFormat:@" FOUND: %@", url]; return url; } @@ -935,5 +933,8 @@ checkCache(NSDictionary *_cache, WEResourceKey *_key, - (NSString *)gsTemplatesDirectoryName { return [[self name] stringByAppendingString:@"/Templates/"]; } +- (NSString *)gsWebDirectoryName { + return [[self name] stringByAppendingString:@"/WebServerResources/"]; +} @end /* WOApplication(WEResourceManager) */ -- 2.39.5