From f727dadebaa69335d2b7d57d1f3f5cc76641c147 Mon Sep 17 00:00:00 2001 From: helge Date: Sun, 5 Sep 2004 23:36:02 +0000 Subject: [PATCH] code cleanups git-svn-id: http://svn.opengroupware.org/SOPE/trunk@107 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-appserver/NGObjWeb/ChangeLog | 4 + sope-appserver/NGObjWeb/Version | 2 +- sope-appserver/NGObjWeb/WOResourceManager.m | 107 +++++++++++--------- 3 files changed, 62 insertions(+), 51 deletions(-) diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index af2e3678..93b6de51 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,7 @@ +2004-09-06 Helge Hess + + * WOResourceManager.m: minor code cleanups (v4.3.26) + 2004-09-05 Helge Hess * WOResourceRequestHandler.m: added some debug logging, send a 404 diff --git a/sope-appserver/NGObjWeb/Version b/sope-appserver/NGObjWeb/Version index 7dbad158..d147d54e 100644 --- a/sope-appserver/NGObjWeb/Version +++ b/sope-appserver/NGObjWeb/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=25 +SUBMINOR_VERSION:=26 # v4.2.413 requires libSaxObjC v4.2.33 # v4.2.341 requires libNGExtensions v4.2.77 diff --git a/sope-appserver/NGObjWeb/WOResourceManager.m b/sope-appserver/NGObjWeb/WOResourceManager.m index e64888b7..8133b66b 100644 --- a/sope-appserver/NGObjWeb/WOResourceManager.m +++ b/sope-appserver/NGObjWeb/WOResourceManager.m @@ -81,6 +81,7 @@ static Class UrlClass = Nil; static NSString *resourcePrefix = @""; static NSString *rapidTurnAroundPath = nil; +static NSString *suffix = nil; static NSNull *null = nil; static BOOL debugOn = NO; static BOOL debugComponentLookup = NO; @@ -106,7 +107,8 @@ static BOOL genMissingResourceLinks = NO; debugComponentLookup = [ud boolForKey:@"WODebugComponentLookup"]; debugResourceLookup = [ud boolForKey:@"WODebugResourceLookup"]; genMissingResourceLinks = [ud boolForKey:@"WOGenerateMissingResourceLinks"]; - rapidTurnAroundPath = [[ud stringForKey:@"WOProjectDirectory"] copy]; + rapidTurnAroundPath = [[ud stringForKey:@"WOProjectDirectory"] copy]; + suffix = [[ud stringForKey:@"WOApplicationSuffix"] copy]; } static inline BOOL @@ -334,10 +336,13 @@ _pathExists(WOResourceManager *self, NSFileManager *fm, NSString *path) fm = [self fileManager]; langCount = [_languages count]; - if ((w3rp = [self webServerResourcesPath])) { + if ((w3rp = [self webServerResourcesPath]) != nil) { NSString *langPath = nil; unsigned i; + if (debugResourceLookup) + [self logWithFormat:@" WebServerResources: %@", w3rp]; + // first check Language.lproj in WebServerResources for (i = 0; i < langCount; i++) { langPath = [_languages objectAtIndex:i]; @@ -348,7 +353,7 @@ _pathExists(WOResourceManager *self, NSFileManager *fm, NSString *path) if (debugResourceLookup) { [self logWithFormat: @" no language project for '%@' in WebServerResources: %@", - [_languages objectAtIndex:i],resource]; + [_languages objectAtIndex:i], langPath]; } continue; } @@ -423,13 +428,29 @@ _pathExists(WOResourceManager *self, NSFileManager *fm, NSString *path) /* URL methods */ +- (NSString *)_urlForMissingResource:(NSString *)_name request:(WORequest *)_r{ + WOApplication *app; + + app = [WOApplication application]; + + if (!genMissingResourceLinks) + return nil; + + return [NSString stringWithFormat: + @"/missingresource?name=%@&application=%@", + _name, app ? [app name] : [_r applicationName]]; +} + - (NSString *)urlForResourceNamed:(NSString *)_name inFramework:(NSString *)_frameworkName languages:(NSArray *)_languages request:(WORequest *)_request { - WOApplication *app; + WOApplication *app; + NSMutableString *url; NSString *resource = nil, *tmp; + NSString *path = nil, *sbase; + unsigned len; app = [WOApplication application]; @@ -447,65 +468,51 @@ _pathExists(WOResourceManager *self, NSFileManager *fm, NSString *path) #endif #if 0 tmp = [resource stringByStandardizingPath]; - if (tmp) resource = tmp; + if (tmp != nil) resource = tmp; #endif - if (resource) { - NSString *path = nil, *sbase; - unsigned len; - - sbase = self->base; - tmp = [sbase commonPrefixWithString:resource options:0]; + if (resource == nil) { + if (debugResourceLookup) + [self logWithFormat:@"did not find resource (cannot build URL)"]; + return [self _urlForMissingResource:_name request:_request]; + } + + sbase = self->base; + tmp = [sbase commonPrefixWithString:resource options:0]; - len = [tmp length]; - path = [sbase substringFromIndex:len]; - tmp = [resource substringFromIndex:len]; - if (([path length] > 0) && ![tmp hasPrefix:@"/"] && ![tmp hasPrefix:@"\\"]) - path = [path stringByAppendingString:@"/"]; - path = [path stringByAppendingString:tmp]; + len = [tmp length]; + path = [sbase substringFromIndex:len]; + tmp = [resource substringFromIndex:len]; + if (([path length] > 0) && ![tmp hasPrefix:@"/"] && ![tmp hasPrefix:@"\\"]) + path = [path stringByAppendingString:@"/"]; + path = [path stringByAppendingString:tmp]; #ifdef __WIN32__ - { + { NSArray *cs; cs = [path componentsSeparatedByString:@"\\"]; path = [cs componentsJoinedByString:@"/"]; - } + } #endif - if (path) { - static NSString *suffix = nil; - NSMutableString *url = nil; - - if (suffix == nil) { - NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - suffix = [ud stringForKey:@"WOApplicationSuffix"]; - } - - url = [[NSMutableString alloc] initWithCapacity:256]; + if (path == nil) + return [self _urlForMissingResource:_name request:_request]; + + url = [[NSMutableString alloc] initWithCapacity:256]; #if 0 - [url appendString:[_request adaptorPrefix]]; + [url appendString:[_request adaptorPrefix]]; #endif - if (resourcePrefix) - [url appendString:resourcePrefix]; - if (![url hasSuffix:@"/"]) [url appendString:@"/"]; - [url appendString:app ? [app name] : [_request applicationName]]; - [url appendString:suffix]; - if (![path hasPrefix:@"/"]) [url appendString:@"/"]; - [url appendString:path]; + if (resourcePrefix) + [url appendString:resourcePrefix]; + if (![url hasSuffix:@"/"]) [url appendString:@"/"]; + [url appendString:app ? [app name] : [_request applicationName]]; + [url appendString:suffix]; + if (![path hasPrefix:@"/"]) [url appendString:@"/"]; + [url appendString:path]; - path = [url copy]; - [url release]; - - return [path autorelease]; - } - } - - if (genMissingResourceLinks) { - return [NSString stringWithFormat: - @"/missingresource?name=%@&application=%@", - _name, app ? [app name] : [_request applicationName]]; - } - return nil; + path = [url copy]; + [url release]; + return [path autorelease]; } - (NSString *)urlForResourceNamed:(NSString *)_name { -- 2.39.5