/*
- 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
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id$
#include "WOResourceURLAssociation.h"
#include <NGObjWeb/WOApplication.h>
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 {
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];
? [[ctx session] languages]
: [[ctx request] browserLanguages];
+ if (doDebug) {
+ [self debugWithFormat:@" languages: %@",
+ [langs componentsJoinedByString:@","]];
+ }
+
if ((rm = [_component resourceManager]) == nil) {
WOApplication *app;
[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 {
return [self retain];
}
+/* debugging */
+
+- (BOOL)isDebuggingEnabled {
+ return doDebug;
+}
+- (NSString *)loggingPrefix {
+ return [NSString stringWithFormat:@"[rsrc:url assoc:0x%08X]", self];
+}
+
+/* description */
+
- (NSString *)description {
NSMutableString *str;
@implementation SoProductResourceManager
+static NGBundleManager *bm = nil;
static BOOL debugOn = NO;
+ (void)initialize {
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
+ bm = [[NGBundleManager defaultBundleManager] retain];
debugOn = [ud boolForKey:@"SoProductResourceManagerDebugEnabled"];
}
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 {
NSString *path = nil, *sbase;
unsigned len;
NSString *url;
-
+
if (debugOn) [self debugWithFormat:@"lookup url: '%@'", _name];
if (_languages == nil) _languages = [_request browserLanguages];
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];
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];
- (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 */