]> err.no Git - sope/commitdiff
major work on resource lookups
authorhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Wed, 23 Feb 2005 17:14:10 +0000 (17:14 +0000)
committerhelge <helge@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Wed, 23 Feb 2005 17:14:10 +0000 (17:14 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@590 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-appserver/NGObjWeb/ChangeLog
sope-appserver/NGObjWeb/SoObjects/SoProductResourceManager.m
sope-appserver/NGObjWeb/Version
sope-appserver/WEExtensions/ChangeLog
sope-appserver/WEExtensions/Version
sope-appserver/WEExtensions/WEResourceManager.h
sope-appserver/WEExtensions/WEResourceManager.m

index 5de3e360577cc1d33d68554ee346c7ab654d65eb..5295c990db7b331e0b69976c58f1282560f90231 100644 (file)
@@ -1,3 +1,9 @@
+2005-02-23  Helge Hess  <helge.hess@opengroupware.org>
+
+       * 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  <helge.hess@opengroupware.org>
 
        * v4.5.119
index 0b3c58777734c1d7b631abe83391955336626b56..ca1fefe7bde402a8a5feb3fff5931eb1d0ec35fe 100644 (file)
 #include <NGExtensions/NSString+Ext.h>
 #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;
index f34e1bd4166fbd622aaea824b1d9d22425472795..fc05a789b699840edd1b136e9a9a4b4bdf47a079 100644 (file)
@@ -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
index d9e02f277a2bd36756ca7962336af1ed9faca2e5..ff572242323b476114efc1ba3db9525498a18e45 100644 (file)
@@ -1,3 +1,9 @@
+2005-02-23  Helge Hess  <helge.hess@opengroupware.org>
+
+       * WEResourceManager.m: lookup web resources in
+         Library/AppName/WebServerResources, fixed an incorrect reference to
+         OGo (w4.5.68)
+
 2005-02-17  Helge Hess  <helge.hess@opengroupware.org>
 
        * v4.5.67
index cc5862656ed0916a5e2b33230093b9f4dfaa7990..853c2846d5f9ad8805302886656e4a92e41a6405 100644 (file)
@@ -1,5 +1,5 @@
 # version file
 
-SUBMINOR_VERSION:=67
+SUBMINOR_VERSION:=68
 
 # v4.5.65 requires libNGObjWeb v4.5.106
index ff9a07497082296eac0ce728193753fb17887593..96acc7718ee28765dfd4ed69ef4f414cd68ee92b 100644 (file)
@@ -62,6 +62,7 @@
 
 - (NSString *)shareDirectoryName;
 - (NSString *)gsTemplatesDirectoryName;
+- (NSString *)gsWebDirectoryName;
 
 @end
 
index 23ea6bb5d5c591826912c8b8a9459c03a5011d64..5cdf74abc4b224cbba163c606d361558ef260599 100644 (file)
@@ -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) */