From: helge Date: Fri, 10 Sep 2004 15:36:36 +0000 (+0000) Subject: fixed resource lookup in SoProductResourceManager, added debug logs X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2331443157420cdd43e3df4500b1bda2c5b1bd12;p=sope fixed resource lookup in SoProductResourceManager, added debug logs git-svn-id: http://svn.opengroupware.org/SOPE/trunk@128 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-appserver/NGObjWeb/Associations/WOResourceURLAssociation.m b/sope-appserver/NGObjWeb/Associations/WOResourceURLAssociation.m index 3c7d69d5..2243ea1a 100644 --- a/sope-appserver/NGObjWeb/Associations/WOResourceURLAssociation.m +++ b/sope-appserver/NGObjWeb/Associations/WOResourceURLAssociation.m @@ -1,7 +1,7 @@ /* - Copyright (C) 2000-2003 SKYRIX Software AG + Copyright (C) 2000-2004 SKYRIX Software AG - This file is part of OGo + This file is part of OpenGroupware.org. OGo 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 @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #include "WOResourceURLAssociation.h" #include @@ -37,9 +36,12 @@ static BOOL doDebug = NO; return [super version] + 0 /* v2 */; } + (void)initialize { + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; NSAssert2([super version] == 2, @"invalid superclass (%@) version %i !", NSStringFromClass([self superclass]), [super version]); + + doDebug = [ud boolForKey:@"WOResourceURLAssociationDebugEnabled"]; } - (id)initWithString:(NSString *)_name { @@ -86,6 +88,10 @@ static BOOL doDebug = NO; WOContext *ctx; NSArray *langs; WORequest *rq; + id url; + + if (doDebug) + [self debugWithFormat:@"lookup resource: %@", [self resourceName]]; if ((ctx = [_component context]) == nil) ctx = [[WOApplication application] context]; @@ -94,6 +100,11 @@ static BOOL doDebug = NO; ? [[ctx session] languages] : [[ctx request] browserLanguages]; + if (doDebug) { + [self debugWithFormat:@" languages: %@", + [langs componentsJoinedByString:@","]]; + } + if ((rm = [_component resourceManager]) == nil) { WOApplication *app; @@ -106,11 +117,19 @@ static BOOL doDebug = NO; [self logWithFormat:@"WARNING: found no resource manager!"]; return nil; } + if (doDebug) [self debugWithFormat:@" resource-manager: %@", rm]; - return [rm urlForResourceNamed:[self resourceName] - inFramework:[self frameworkName] - languages:langs - request:rq]; + url = [rm urlForResourceNamed:[self resourceName] + inFramework:[self frameworkName] + languages:langs + request:rq]; + if (doDebug) { + if (url != nil) + [self debugWithFormat:@" => URL: %@", url]; + else + [self debugWithFormat:@" => resource not found!"]; + } + return url; } - (BOOL)isValueConstant { @@ -127,6 +146,17 @@ static BOOL doDebug = NO; return [self retain]; } +/* debugging */ + +- (BOOL)isDebuggingEnabled { + return doDebug; +} +- (NSString *)loggingPrefix { + return [NSString stringWithFormat:@"[rsrc:url assoc:0x%08X]", self]; +} + +/* description */ + - (NSString *)description { NSMutableString *str; diff --git a/sope-appserver/NGObjWeb/ChangeLog b/sope-appserver/NGObjWeb/ChangeLog index 06a95e40..1dc71591 100644 --- a/sope-appserver/NGObjWeb/ChangeLog +++ b/sope-appserver/NGObjWeb/ChangeLog @@ -1,3 +1,16 @@ +2004-09-10 Helge Hess + + * v4.3.34 + + * SoObjects/SoProductResourceManager.m: added an implementation of + -pathForResourceNamed:inFramework:languages: which checks the + product bundle resources (also required to make the URL lookup work), + improved debug logging + + * Associations/WOResourceURLAssociation.m, Defaults.plist: added + WOResourceURLAssociationDebugEnabled default and a set of debug + logs + 2004-09-09 Helge Hess * DynamicElements/WOBrowser.m: deprecated 'selection' binding and diff --git a/sope-appserver/NGObjWeb/Defaults.plist b/sope-appserver/NGObjWeb/Defaults.plist index ba15c644..9ec5f0c2 100644 --- a/sope-appserver/NGObjWeb/Defaults.plist +++ b/sope-appserver/NGObjWeb/Defaults.plist @@ -85,6 +85,7 @@ WOProfileResponse = NO; WOProjectSearchPath = (); WOResourceRequestHandlerKey = "y"; + WOResourceURLAssociationDebugEnabled = NO; WORunMultithreaded = NO; WOSMTPHost = "mail"; WOSendMail = "/usr/lib/sendmail"; diff --git a/sope-appserver/NGObjWeb/SoObjects/SoProduct.h b/sope-appserver/NGObjWeb/SoObjects/SoProduct.h index 8a32c7ce..ad1bda65 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoProduct.h +++ b/sope-appserver/NGObjWeb/SoObjects/SoProduct.h @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __SoObjects_SoProduct_H__ #define __SoObjects_SoProduct_H__ diff --git a/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.h b/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.h index df725b2b..23178803 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.h +++ b/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.h @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #ifndef __SoObjects_SoProductResourceManager_H__ #define __SoObjects_SoProductResourceManager_H__ diff --git a/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m b/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m index a06e4306..735dc3f2 100644 --- a/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m +++ b/sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m @@ -38,11 +38,13 @@ @implementation SoProductResourceManager +static NGBundleManager *bm = nil; static BOOL debugOn = NO; + (void)initialize { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + bm = [[NGBundleManager defaultBundleManager] retain]; debugOn = [ud boolForKey:@"SoProductResourceManagerDebugEnabled"]; } @@ -65,6 +67,63 @@ static BOOL debugOn = NO; return @"Resources"; } +/* lookup resources */ + +- (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 + NSBundle *bundle; + NSString *path; + + if (debugOn) [self debugWithFormat:@"lookup resource: '%@'", _name]; + + /* determine product bundle or explicitly requested framework/bundle */ + + if ([_frameworkName length] > 0) { + if ([_frameworkName hasPrefix:@"/"]) { + bundle = [bm bundleWithPath:_frameworkName]; + } + else { + bundle = [bm bundleWithName: + [_frameworkName stringByDeletingPathExtension] + type:[_frameworkName pathExtension]]; + } + if (bundle == nil) { + [self debugWithFormat:@"WARNING: missing bundle for framework: '%@'", + _frameworkName]; + goto fallback; + } + } + else { + if ((bundle = [self->product bundle]) == nil) { + [self debugWithFormat:@"WARNING: missing bundle for product: %@", + self->product]; + goto fallback; + } + } + + if (debugOn) [self debugWithFormat:@" bundle: %@", bundle]; + + /* lookup resource in bundle */ + + // TODO: what about the languages?! + path = [bundle pathForResource:[_name stringByDeletingPathExtension] + ofType:[_name pathExtension]]; + if (path != nil) { + if (debugOn) [self debugWithFormat:@" => found: %@", path]; + return path; + } + if (debugOn) [self debugWithFormat:@" resource not found in bundle ..."]; + + /* fall back to WOResourceManager lookup */ + fallback: + return [super pathForResourceNamed:_name inFramework:_frameworkName + languages:_languages]; +} + /* generate URL for resources (eg filename binding in WOImage) */ - (NSString *)webServerResourcesPath { @@ -82,7 +141,7 @@ static BOOL debugOn = NO; NSString *path = nil, *sbase; unsigned len; NSString *url; - + if (debugOn) [self debugWithFormat:@"lookup url: '%@'", _name]; if (_languages == nil) _languages = [_request browserLanguages]; @@ -96,11 +155,18 @@ static BOOL debugOn = NO; withString:@""]; } #endif - //tmp = [resource stringByStandardizingPath]; - //if (tmp) resource = tmp; - - if (resource == nil) +#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]; @@ -127,7 +193,7 @@ static BOOL debugOn = NO; else if ([path hasPrefix:@"Resources/"]) path = [path substringFromIndex:10]; - /* Note: cannot use -stringByAppendingPathComponent: on OSX ! */ + /* Note: cannot use -stringByAppendingPathComponent: on OSX! */ url = [self baseURLInContext:[[WOApplication application] context]]; if (debugOn) [self debugWithFormat:@" base: '%@'", url]; @@ -245,5 +311,20 @@ static BOOL debugOn = NO; - (BOOL)isDebuggingEnabled { return debugOn; } +- (NSString *)loggingPrefix { + return [NSString stringWithFormat:@"[RM:%@]", [self->product productName]]; +} + +/* description */ + +- (NSString *)description { + NSMutableString *str; + + str = [NSMutableString stringWithCapacity:64]; + [str appendFormat:@"<%@[0x%08X]:", NSStringFromClass([self class]), self]; + [str appendFormat:@" product='%@'", [self->product productName]]; + [str appendString:@">"]; + return str; +} @end /* SoProductResourceManager */ diff --git a/sope-appserver/NGObjWeb/WOHttpAdaptor/WOHttpAdaptor.m b/sope-appserver/NGObjWeb/WOHttpAdaptor/WOHttpAdaptor.m index 74375834..e5e3cb6e 100644 --- a/sope-appserver/NGObjWeb/WOHttpAdaptor/WOHttpAdaptor.m +++ b/sope-appserver/NGObjWeb/WOHttpAdaptor/WOHttpAdaptor.m @@ -101,6 +101,8 @@ static BOOL debugOn = NO; WOHttpAdaptor_LogStream = [ud boolForKey:@"WOHttpAdaptor_LogStream"]; HTTP_PERFLOG = [[ud objectForKey:@"WOProfileHttpAdaptor"] boolValue]; + + // TODO: those two should be queried on demand to allow different defaults WOPort = [[ud stringForKey:@"WOPort"] copy]; WOContactSNS = [[ud objectForKey:@"WOContactSNS"] boolValue]; diff --git a/sope-core/NGExtensions/FdExt.subproj/NSObject+Logs.m b/sope-core/NGExtensions/FdExt.subproj/NSObject+Logs.m index 792bce31..0297de05 100644 --- a/sope-core/NGExtensions/FdExt.subproj/NSObject+Logs.m +++ b/sope-core/NGExtensions/FdExt.subproj/NSObject+Logs.m @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// $Id$ #include "NSObject+Logs.h" #include "common.h"