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;
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
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];
if (debugResourceLookup) {
[self logWithFormat:
@" no language project for '%@' in WebServerResources: %@",
- [_languages objectAtIndex:i],resource];
+ [_languages objectAtIndex:i], langPath];
}
continue;
}
/* 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];
#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 {