+2005-02-17 Helge Hess <helge.hess@opengroupware.org>
+
+ * v4.5.118
+
+ * SoObjects/SoProductResourceManager.m:
+ - if a resource could not be found, continue lookup using
+ WOApplication resource manager instead of calling super
+ - fixed a major issue in the bundle resource lookup code
+ - use resource manager of other product when looking up a file of
+ that (instead of directly querying the bundle)
+
+ * WOResourceManager.m: minor code cleanups
+
+ * SoObjects/SoComponent.m: fixed a typo
+
2005-02-17 Helge Hess <helge.hess@skyrix.com>
* WOApplication.m: the resource manager class to be used for a SOPE
tmpl = [self templateWithName:[self name]];
if (tmpl == nil) {
- [self warnWithFormat:@"found not template named '%@' for component.",
+ [self warnWithFormat:@"found no template named '%@' for component.",
[self name]];
}
return tmpl;
#include "SoProduct.h"
#include "SoObject.h"
#include "SoClassSecurityInfo.h"
+#include "SoProductRegistry.h"
#include <NGObjWeb/WOApplication.h>
#include <NGObjWeb/WOContext.h>
#include <NGObjWeb/WOResponse.h>
return @"Resources";
}
+- (WOResourceManager *)fallbackResourceManager {
+ WOResourceManager *rm;
+
+ rm = [[WOApplication application] resourceManager];
+ return (rm == self) ? nil : rm; /* avoid recursion */
+}
+
/* lookup resources */
+- (NSBundle *)bundleForFrameworkName:(NSString *)_fwName {
+ NSBundle *bundle;
+
+ if ([_fwName length] == 0) {
+ if ((bundle = [self->product bundle]) == nil)
+ [self warnWithFormat:@"missing bundle for product: %@", self->product];
+ return bundle;
+ }
+
+ if ([_fwName hasPrefix:@"/"]) {
+ bundle = [bm bundleWithPath:_fwName];
+ }
+ else {
+ bundle = [bm bundleWithName:[_fwName stringByDeletingPathExtension]
+ type:[_fwName pathExtension]];
+ }
+ if (bundle == nil)
+ [self warnWithFormat:@"missing bundle for framework: '%@'", _fwName];
+
+ return bundle;
+}
+
- (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;
+ 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) {
- if ([_frameworkName hasPrefix:@"/"]) {
- bundle = [bm bundleWithPath:_frameworkName];
- }
- else {
- bundle = [bm bundleWithName:
- [_frameworkName stringByDeletingPathExtension]
- type:[_frameworkName pathExtension]];
- }
- if (bundle == nil) {
- [self warnWithFormat:@"missing bundle for framework: '%@'",
- _frameworkName];
- goto fallback;
- }
- }
- else {
- if ((bundle = [self->product bundle]) == nil) {
- [self warnWithFormat:@"missing bundle for product: %@", self->product];
- goto fallback;
- }
- }
+ if ((bundle = [self bundleForFrameworkName:_frameworkName]) == nil)
+ goto fallback;
+
+ bproduct = [[SoProductRegistry sharedProductRegistry]
+ productForBundle:bundle];
+ rm = [bproduct resourceManager];
- if (debugOn) [self debugWithFormat:@" bundle: %@", bundle];
+ if (debugOn) {
+ [self debugWithFormat:
+ @" fwname %@\n bundle: %@\n product: %@",
+ _frameworkName, bundle, bproduct];
+ }
/* lookup resource in bundle */
- path = [bundle pathForResource:[_name stringByDeletingPathExtension]
- ofType:[_name pathExtension]
- inDirectory:nil
- languages:_languages];
+ 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];
+ }
+ }
+ else {
+ /* delegate lookup to resource manager of other product */
+ path = [rm pathForResourceNamed:_name inFramework:_frameworkName
+ languages:_languages];
+ if (debugOn && path == nil)
+ [self debugWithFormat:@" resource %@ not found in rm: %@", _name, rm];
+ }
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];
+
+ rm = [self fallbackResourceManager];
+ if (rm != nil) {
+ return [rm pathForResourceNamed:_name inFramework:_frameworkName
+ languages:_languages];
+ }
+ else {
+ return [super pathForResourceNamed:_name inFramework:_frameworkName
+ languages:_languages];
+ }
}
/* generate URL for resources (eg filename binding in WOImage) */
- (NSString *)webServerResourcesPath {
/* to avoid warning that WebServerResources path does not exist ... */
- return [[[WOApplication application] resourceManager]
- webServerResourcesPath];
+ return [[self fallbackResourceManager] webServerResourcesPath];
}
- (NSString *)urlForResourceNamed:(NSString *)_name
return url;
}
+- (NSString *)pathToComponentNamed:(NSString *)_name
+ inFramework:(NSString *)_fwname
+ languages:(NSArray *)_langs
+{
+ NSString *p;
+
+ p = [super pathToComponentNamed:_name inFramework:_fwname languages:_langs];
+ if (![p isNotNull] || [p length] == 0 ) {
+ [self logWithFormat:@"LOOKUP FAILED: %@", _name];
+ p = [[self fallbackResourceManager] pathToComponentNamed:_name
+ inFramework:_fwname
+ languages:_langs];
+ [self logWithFormat:@" PARENT SAID: %@", p];
+ }
+ return p;
+}
+
- (WOElement *)templateWithName:(NSString *)_name
languages:(NSArray *)_languages
{
- [self logWithFormat:@"lookup template with name '%@' (languages=%@)",
+ WOResourceManager *arm;
+ WOElement *e;
+
+ if (debugOn) {
+ [self logWithFormat:@"lookup template with name '%@' (languages=%@)",
_name, [_languages componentsJoinedByString:@","]];
- return [super templateWithName:_name languages:_languages];
+ }
+ if ((e = [super templateWithName:_name languages:_languages]) != nil) {
+ if (debugOn) [self logWithFormat:@" found: %@", e];
+ return e;
+ }
+
+ arm = [self fallbackResourceManager];
+ if (arm == self) return nil;
+
+ if (debugOn) [self logWithFormat:@" lookup in parent RM: %@", arm];
+ if ((e = [arm templateWithName:_name languages:_languages]) != nil) {
+ if (debugOn) [self logWithFormat:@" found: %@", e];
+ return e;
+ }
+
+ if (debugOn) [self logWithFormat:@"did not find template %@", _name];
+ return nil;
}
/* resource manager as a SoObject */
# version file
-SUBMINOR_VERSION:=117
+SUBMINOR_VERSION:=118
# v4.5.91 requires libNGExtensions v4.5.134
# v4.5.84 requires libNGExtensions v4.5.127
_nameOrURL, _framework];
}
+ /* look for .wox component */
- /* look for .wox component */
+ path = [self pathForResourceNamed:
+ [self resourceNameForComponentNamed:*name_]
+ inFramework:_framework
+ languages:_languages];
- path = [self pathForResourceNamed:
- [self resourceNameForComponentNamed:*name_]
- inFramework:_framework
- languages:_languages];
-
- if (debugComponentLookup)
- [self logWithFormat:@" path: '%@'", path];
+ if (debugComponentLookup)
+ [self logWithFormat:@" .wox path: '%@'", path];
- /* look for .wo component */
+ /* look for .wo component */
- if ([path length] == 0) {
- path = [self pathToComponentNamed:*name_
- inFramework:_framework
- languages:_languages];
- if (debugComponentLookup)
- [self logWithFormat:@" path: '%@'", path];
- }
+ if ([path length] == 0) {
+ path = [self pathToComponentNamed:*name_
+ inFramework:_framework
+ languages:_languages];
+ if (debugComponentLookup)
+ [self logWithFormat:@" .wo path: '%@'", path];
+ }
- /* make URL from path */
+ /* make URL from path */
- *url_ = ([path length] > 0)
- ? [[[UrlClass alloc] initFileURLWithPath:path] autorelease]
- : nil;
+ *url_ = ([path length] > 0)
+ ? [[[UrlClass alloc] initFileURLWithPath:path] autorelease]
+ : nil;
}
- (WOComponentDefinition *)definitionForFileURL:(NSURL *)componentURL
WOComponentDefinition *cdef;
cdef = [self __definitionForComponent:_name languages:_languages];
- if (cdef == nil) return nil;
+ if (cdef == nil)
+ return nil;
return (WOElement *)[cdef template];
}
/* description */
- (NSString *)description {
- return [NSString stringWithFormat:@"<%@[0x%08X]: path=%@>",
- [self class], self, self->base];
-
+ NSMutableString *ms;
+
+ ms = [NSMutableString stringWithCapacity:32];
+ [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
+ if ([self->base length] > 0)
+ [ms appendFormat:@" path='%@'", self->base];
+ [ms appendString:@">"];
+ return ms;
}
/* KeyedData */
+2005-02-17 Helge Hess <helge.hess@opengroupware.org>
+
+ * v4.5.67
+
+ * WEResourceManager.m: removed special handling of components.cfg (only
+ required by OGo for legacy reasons)
+
+ * GNUmakefile: properly export the WEResourceManager.h header file
+
2005-02-17 Helge Hess <helge.hess@skyrix.com>
* added a modified variant of the OGoResourceManager and the required
libWEExtensions_HEADER_FILES_INSTALL_DIR = /WEExtensions
libWEExtensions_HEADER_FILES = \
- WEContextConditional.h
+ WEContextConditional.h \
+ WEResourceManager.h \
libWEExtensions_OBJC_FILES = \
JSClipboard.m \
# version file
-SUBMINOR_VERSION:=66
+SUBMINOR_VERSION:=67
# v4.5.65 requires libNGObjWeb v4.5.106
if (debugOn)
NSLog(@"template pathes: %@", templatePathes);
if ([templatePathes count] == 0)
- NSLog(@"WARNING: found no directories containing SOPE templates!");
+ NSLog(@"Note: found no directories containing flat templates.");
}
+ (NSArray *)availableThemes {
/* locate Resources */
-- (NSString *)_checkPath:(NSString *)_p forResourceNamed:(NSString *)_name
+- (NSString *)_weCheckPath:(NSString *)_p forResourceNamed:(NSString *)_name
inFramework:(NSString *)_frameworkName
language:(NSString *)_language
{
return path;
}
-- (NSString *)_checkPathes:(NSArray *)_p forResourceNamed:(NSString *)_name
+- (NSString *)_weCheckPathes:(NSArray *)_p forResourceNamed:(NSString *)_name
inFramework:(NSString *)_frameworkName
language:(NSString *)_language
{
e = [_p objectEnumerator];
while ((path = [e nextObject]) != nil) {
- path = [self _checkPath:path forResourceNamed:_name
+ path = [self _weCheckPath:path forResourceNamed:_name
inFramework:_frameworkName language:_language];
if (path != nil) {
if (debugOn) [self debugWithFormat:@"FOUND: '%@'", path];
return nil;
}
-- (NSString *)_pathForResourceNamed:(NSString *)_name
+- (NSString *)_wePathForResourceNamed:(NSString *)_name
inFramework:(NSString *)_fwName
language:(NSString *)_lang
searchPathes:(NSArray *)_pathes
if (debugOn)
[self debugWithFormat:@"check framework resources ..."];
- path = [self _checkPathes:_pathes forResourceNamed:_name
+ path = [self _weCheckPathes:_pathes forResourceNamed:_name
inFramework:_fwName language:_lang];
if (path != nil) {
[self cacheValue:path inCache:self->keyToPath];
// TODO: where is the difference, same call like above?
if (debugOn) [self debugWithFormat:@"check global resources ..."];
- path = [self _checkPathes:_pathes forResourceNamed:_name
+ path = [self _weCheckPathes:_pathes forResourceNamed:_name
inFramework:_fwName language:_lang];
if (path != nil) {
[self cacheValue:path inCache:self->keyToPath];
return YES;
}
-- (NSString *)_pathForResourceNamed:(NSString *)_name
+- (NSString *)_wePathForResourceNamed:(NSString *)_name
inFramework:(NSString *)_fwName
language:(NSString *)_lang
{
/* check in webserver resources */
if ([self shouldLookupResourceInWebServerResources:_name]) {
- p = [self _pathForResourceNamed:_name inFramework:_fwName
+ p = [self _wePathForResourceNamed:_name inFramework:_fwName
language:_lang searchPathes:wsPathes];
if (p != nil) return p;
}
return nil;
}
-- (NSString *)lookupComponentsConfigInFramework:(NSString *)_fwName
- theme:(NSString *)_theme
-{
- NSString *path;
- NSEnumerator *e;
-
- /* check cache */
-
- path = checkCache(self->keyToPath, self->cachedKey, @"components.cfg",
- _fwName, _theme);
- if (path != nil) {
- if (debugOn) [self debugWithFormat:@" found in cache: %@", path];
- return [path isNotNull] ? path : nil;
- }
-
- /* traverse template dirs */
-
- e = [templatePathes objectEnumerator];
- while ((path = [e nextObject]) != nil) {
- if (_theme != nil) {
- path = [path stringByAppendingPathComponent:themesDirName];
- path = [path stringByAppendingPathComponent:_theme];
- }
- if (_fwName != nil)
- path = [path stringByAppendingPathComponent:_fwName];
- path = [path stringByAppendingPathComponent:@"components.cfg"];
-
- if ([fm fileExistsAtPath:path]) {
-#if 0
- [self logWithFormat:@"components.cfg theme %@ fw %@: %@",
- _theme, _fwName, path];
-#endif
- [self cacheValue:path inCache:self->keyToPath];
- return path;
- }
- }
-
- /* cache miss */
- [self cacheValue:nil inCache:self->keyToPath];
- return nil;
-}
-
-- (NSString *)lookupComponentsConfigInFramework:(NSString *)_fwName
- languages:(NSArray *)_langs
-{
- NSEnumerator *e;
- NSString *rpath;
-
- if (![_fwName isNotNull])
- _fwName = [[WOApplication application] name];
-
- if (debugOn) {
- [self debugWithFormat:@"lookup components cfg: %@/%@", _fwName,
- [_langs componentsJoinedByString:@","]];
- }
-
- /* check themes */
-
- e = [_langs objectEnumerator];
- while ((rpath = [e nextObject]) != nil) {
- NSRange r;
- NSString *theme;
-
- r = [rpath rangeOfString:@"_"];
- theme = (r.length > 0)
- ? [rpath substringFromIndex:(r.location + r.length)]
- : nil; /* default theme */
-
- rpath = [self lookupComponentsConfigInFramework:_fwName theme:theme];
- if (rpath != nil)
- return rpath;
-
- [self logWithFormat:@"Note: did not find components.cfg(%@) for theme: %@",
- _fwName, (theme != nil ? theme : @"default-theme")];
- }
-
- /* look using OWResourceManager */
-
- rpath = [super pathForResourceNamed:@"components.cfg"
- inFramework:_fwName
- languages:_langs];
-
- /* not found */
-
- if (rpath == nil) {
- [self logWithFormat:@"Note: did not find components.cfg: %@/%@",
- _fwName ? _fwName : @"[app]",
- [_langs componentsJoinedByString:@","]];
- }
- return rpath;
+- (BOOL)isTemplateResourceName:(NSString *)_name {
+ // TODO: non-extensible
+ return [_name hasSuffix:@".wox"];
}
- (NSString *)pathForResourceNamed:(NSString *)_name
NSString *rpath;
if ([_name length] == 0) {
- if (debugOn) [self logWithFormat:@"got no name for resource lookup?!"];
+ [self debugWithFormat:@"got no name for resource lookup?!"];
return nil;
}
- /* special handling for components.cfg */
-
- if ([_name isEqualToString:@"components.cfg"])
- return [self lookupComponentsConfigInFramework:_fwName languages:_langs];
-
if (debugOn) {
[self debugWithFormat:@"pathForResourceNamed: %@/%@ (languages: %@)",
_name, _fwName, [_langs componentsJoinedByString:@","]];
}
+
+ if ([self isTemplateResourceName:_name]) {
+ if (debugOn) [self debugWithFormat:@" is template resource .."];
+ return [self pathToComponentNamed:[_name stringByDeletingPathExtension]
+ inFramework:_fwName
+ languages:_langs];
+ }
/* check languages */
e = [_langs objectEnumerator];
- while ((language = [e nextObject])) {
+ while ((language = [e nextObject]) != nil) {
NSString *rpath;
if (debugOn)
[self logWithFormat:@" check language (%@): '%@'", _name, language];
- rpath = [self _pathForResourceNamed:_name inFramework:_fwName
+ rpath = [self _wePathForResourceNamed:_name inFramework:_fwName
language:language];
if (rpath != nil) {
- if (debugOn) [self logWithFormat:@" FOUND: %@", rpath];
+ if (debugOn) [self debugWithFormat:@" FOUND: %@", rpath];
return rpath;
}
}
/* check without language */
- rpath = [self _pathForResourceNamed:_name inFramework:_fwName
- language:nil];
+ rpath = [self _wePathForResourceNamed:_name inFramework:_fwName
+ language:nil];
if (rpath != nil)
return rpath;
@"did not find resource, try super lookup: '%@'", _name];
}
- /* look using OWResourceManager */
+ /* look using WOResourceManager */
rpath = [super pathForResourceNamed:_name inFramework:_fwName
languages:_langs];
NSEnumerator *e;
NSString *path;
+ if (debugComponents) {
+ [self logWithFormat:@"lookup component in std pathes: %@|%@|%@",
+ _name, _framework, _theme];
+ }
+
+ if ([_theme isNotNull] && [_theme length] == 0)
+ _theme = nil;
+ if ([_framework isNotNull] && [_framework length] == 0)
+ _framework = nil;
+
e = [templatePathes objectEnumerator];
- while ((path = [e nextObject])) {
+ while ((path = [e nextObject]) != nil) {
NSString *pe;
-
+
if (_theme != nil) {
// TODO: should be lower case for FHS? or use a different path?
path = [path stringByAppendingPathComponent:themesDirName];
path = [path stringByAppendingPathComponent:_theme];
}
- if ([_framework length] > 0) {
+ if (_framework != nil) {
NSString *pureName;
pureName = [_framework lastPathComponent];
path = [path stringByAppendingPathComponent:_name];
pe = [path stringByAppendingPathExtension:@"wox"];
+ if (debugComponents) [self logWithFormat:@"CHECK %@", pe];
+
if ([fm fileExistsAtPath:pe])
return pe;
NSString *path;
NSString *theme;
+ if (debugComponents) {
+ [self logWithFormat:@"lookup component in std pathes(langs): %@|%@",
+ _name, _framework];
+ }
+
/* extract theme from language array (we do not support nested themes ATM) */
theme = nil;
theme:nil];
if (path != nil)
return path;
+
+ /* check without framework subdir */
+
+ if ([_framework length] > 0) {
+ path = [self lookupComponentInStandardPathes:_name inFramework:nil
+ theme:nil];
+ if (path != nil)
+ return path;
+ }
return nil;
}
NSString *wrapper = nil;
NSBundle *bundle = nil;
NSString *path;
+
+ if (debugComponents)
+ [self logWithFormat:@"lookup component using bundle manager: %@", _name];
bundle = [[self bundleManager]
bundleProvidingResource:_name
{
// TODO: what about languages in lookup?
NSString *path;
-
+
if (debugComponents) {
[self logWithFormat:@"%s: lookup component: %@|%@",
__PRETTY_FUNCTION__, _name, _fw];
/* try to find component by standard NGObjWeb method */
+ if (debugComponents)
+ [self logWithFormat:@"lookup component using WOResourceManager ..."];
path = [super pathToComponentNamed:_name inFramework:_fw languages:_langs];
if (path != nil) {
if (debugComponents)
- [self logWithFormat:@" found using OWResourceManager: %@", path];
+ [self logWithFormat:@" found using WOResourceManager: %@", path];
goto done;
}