From b6bbd5b0cb81f28eab56f1b7b66efaf9fb6d7af1 Mon Sep 17 00:00:00 2001 From: David Ayers Date: Mon, 6 Apr 2009 22:22:14 +0000 Subject: [PATCH] * GSWeb.framework/GSWeb.h (GSWImageInfo): Foward declare. * GSWeb.framework/GSWHTMLDynamicElement.h/m (-/+[_frameworkNameForAssociation:inComponent:]): Convert to class method. Cleanup implementation. * GSWeb.framework/GSWImage.m (+[_appendFilenameToResponse:inContext:framework:filename:width:height:]): Add handling for image url and cleanup implementation. (-[_appendFilenameToResponse:inContext:]): Delegate to class method. * GSWeb.framework/GSWResourceManager.h/m (-[_imageInfoForUrl:fileName:framework:languages:]): New method. (-[errorMessageUrlForResourceNamed:inFramework:]): Reformat. (-[_cacheData:]): Ditto. * Examples/WebBookStore1/BookStore.eomodeld/index.eomodeld: Update adaptor name. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@28182 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 18 ++ .../BookStore.eomodeld/index.eomodeld | 2 +- GSWeb.framework/GSWHTMLDynamicElement.h | 5 +- GSWeb.framework/GSWHTMLDynamicElement.m | 58 ++-- GSWeb.framework/GSWImage.m | 301 ++++++++---------- GSWeb.framework/GSWResourceManager.h | 4 + GSWeb.framework/GSWResourceManager.m | 46 ++- GSWeb.framework/GSWeb.h | 1 + 8 files changed, 216 insertions(+), 219 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b8a1d0..5e52897 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2009-04-07 David Ayers + + * GSWeb.framework/GSWeb.h (GSWImageInfo): Foward declare. + * GSWeb.framework/GSWHTMLDynamicElement.h/m + (-/+[_frameworkNameForAssociation:inComponent:]): Convert to class + method. Cleanup implementation. + * GSWeb.framework/GSWImage.m + (+[_appendFilenameToResponse:inContext:framework:filename:width:height:]): + Add handling for image url and cleanup implementation. + (-[_appendFilenameToResponse:inContext:]): Delegate to class method. + * GSWeb.framework/GSWResourceManager.h/m + (-[_imageInfoForUrl:fileName:framework:languages:]): New method. + (-[errorMessageUrlForResourceNamed:inFramework:]): Reformat. + (-[_cacheData:]): Ditto. + + * Examples/WebBookStore1/BookStore.eomodeld/index.eomodeld: + Update adaptor name. + 2009-04-05 David Ayers * GSWeb.framework/GSWImageInfo.h/m: New files. diff --git a/Examples/WebBookStore1/BookStore.eomodeld/index.eomodeld b/Examples/WebBookStore1/BookStore.eomodeld/index.eomodeld index 96f3c47..3601d91 100644 --- a/Examples/WebBookStore1/BookStore.eomodeld/index.eomodeld +++ b/Examples/WebBookStore1/BookStore.eomodeld/index.eomodeld @@ -1,6 +1,6 @@ { EOModelVersion = 2; - adaptorName = Postgres95; + adaptorName = PostgreSQL; connectionDictionary = { databaseName = BookStore; }; diff --git a/GSWeb.framework/GSWHTMLDynamicElement.h b/GSWeb.framework/GSWHTMLDynamicElement.h index 4a2bee0..506da8e 100644 --- a/GSWeb.framework/GSWHTMLDynamicElement.h +++ b/GSWeb.framework/GSWHTMLDynamicElement.h @@ -48,6 +48,9 @@ GSWAssociation * _secure; } ++ (NSString*) _frameworkNameForAssociation: (GSWAssociation*)association + inComponent: (GSWComponent *) component; + - (NSDictionary*) computeQueryDictionaryWithActionClassAssociation: (GSWAssociation*)actionClass directActionNameAssociation: (GSWAssociation*)directActionName queryDictionaryAssociation: (GSWAssociation*)queryDictionary @@ -83,8 +86,6 @@ - (NSString*) constantAttributesRepresentation; -- (NSString*) _frameworkNameForAssociation: (GSWAssociation*)association - inComponent: (GSWComponent *) component; - (NSString*) elementName; - (BOOL) secureInContext:(GSWContext*) context; diff --git a/GSWeb.framework/GSWHTMLDynamicElement.m b/GSWeb.framework/GSWHTMLDynamicElement.m index e5f7b38..7624cc1 100644 --- a/GSWeb.framework/GSWHTMLDynamicElement.m +++ b/GSWeb.framework/GSWHTMLDynamicElement.m @@ -309,39 +309,41 @@ static inline BOOL _needQuote(NSString* str_needQuote) } // _frameworkNameInComponent -- (NSString*) _frameworkNameForAssociation: (GSWAssociation*)association ++ (NSString*) _frameworkNameForAssociation: (GSWAssociation*)association inComponent: (GSWComponent *) component { - NSString * s = nil; + NSString *name = nil; - if (association != nil) { - s = [association valueInComponent:component]; - if (s != nil) { - if ([[s lowercaseString] isEqual:@"app"]) { - s = nil; - } - } else { + if (association != nil) + { + name = [association valueInComponent:component]; + if (name) + { + if ([@"app" caseInsensativeCompare: name]) + { + name = nil; + } + } + else + { + if (component != nil) + { + name = [component frameworkName]; + } + + [GSWApp debugWithFormat:@"%s evaluated to nil. Defaulting to %@", + __PRETTY_FUNCTION__, + (name ? name : @"app")]; + } + } + else + { if (component != nil) - { - s = [component frameworkName]; - } - NSString * tmpStr; - - if ((s != nil)) { - tmpStr = s; - } else { - tmpStr = @"app"; - } - [GSWApp debugWithFormat:@"%s evaluated to nil. Defaulting to %@", - __PRETTY_FUNCTION__, - tmpStr]; + { + name = [component frameworkName]; + } } - } else { - if (component != nil) { - s = [component frameworkName]; - } - } - return s; + return name; } // computeActionStringInContext in wo5 diff --git a/GSWeb.framework/GSWImage.m b/GSWeb.framework/GSWImage.m index cb46837..ed9f2bb 100644 --- a/GSWeb.framework/GSWImage.m +++ b/GSWeb.framework/GSWImage.m @@ -94,10 +94,10 @@ RCS_ID("$Id$") }; -// GSWImage._appendFilenameToResponseInContext(woresponse, wocontext, _framework, _filename, _width, _height); - - - +/* This class method does not actually exist in WO45 yet it seems subsequent + * versions implement it to factor out code replicated by mutliple classes + * across the class hierarchy. + */ + (void) _appendFilenameToResponse:(GSWResponse *) response inContext:(GSWContext *) context framework:(GSWAssociation*) framework @@ -105,89 +105,114 @@ RCS_ID("$Id$") width:(GSWAssociation*) width height:(GSWAssociation*) height { - id widthValue = nil; - id heightValue = nil; - BOOL hasNoWidth = NO; - BOOL hasNoHeight = NO; - NSString * frameworkName; + GSWResourceManager *resourcemanager; + GSWComponent *component; + NSString *fileNameValue; + NSString *frameworkName = nil; + NSString *resourceURL; - GSWResourceManager * resourcemanager = [GSWApp resourceManager]; + resourcemanager = [GSWApp resourceManager]; + component = GSWContext_component(context); + fileNameValue = [filename valueInComponent:component]; + frameworkName + = [GSWHTMLDynamicElement _frameworkNameForAssociation: framework + inComponent: component]; - GSWComponent * component = GSWContext_component(context); - - NSString* fileNameValue = [filename valueInComponent:component]; + resourceURL = [context _urlForResourceNamed: fileNameValue + inFramework: frameworkName]; - // i think we have to use component, because we are in a '+' method here. dw - - frameworkName = [(GSWHTMLDynamicElement*) component _frameworkNameForAssociation: framework - inComponent: component]; + if (resourceURL != nil) + { + NSString *widthStr = nil; + NSString *heightStr = nil; + BOOL calculateWidth = NO; + BOOL calculateHeight = NO; - NSString * resourceURL = [context _urlForResourceNamed:frameworkName inFramework: frameworkName]; + if (width != nil || height != nil) + { + if (width != nil) + { + id widthValue; + widthValue = [width valueInComponent:component]; + if (widthValue) + { + widthStr = NSStringWithObject(widthValue); + } + calculateWidth = (widthStr == nil || [widthStr isEqual:@"*"]); + } + if (height != nil) + { + id heightValue; + heightValue = [height valueInComponent:component]; + if (heightValue) + { + heightStr = NSStringWithObject(heightValue); + } + calculateHeight = (heightStr == nil || [heightStr isEqual:@"*"]); + } + } + else + { + calculateWidth = YES; + calculateHeight = YES; - if (resourceURL != nil) { - NSString * widthStr = nil; - NSString * heightStr = nil; - if (width != nil || height != nil) { - if (width != nil) { - widthValue = [width valueInComponent:component]; - widthStr = widthValue != nil ? widthValue : nil; // stringValue? - hasNoWidth = (widthStr == nil || [widthStr isEqual:@"*"]); - } - if (height != nil) { - heightValue = [height valueInComponent:component]; - heightStr = heightValue != nil ? heightValue : nil; // stringValue? - hasNoHeight = (heightStr == nil || [heightStr isEqual:@"*"]); - } - } else { - hasNoWidth = YES; - hasNoHeight = YES; - // do we really need that log? dw. - // NSLog("%@: No height or width information provided for '%@'. If possible, this information should be provided for best performance.", [self class], fileNameValue); + GSOnceMLog(@"%@: No height or width information provided for '%@'. If possible, this information should be provided for best performance.", + NSStringFromClass([self class]), fileNameValue); + } + + if (calculateWidth || calculateHeight) + { + GSWImageInfo * imageinfo; + + imageinfo = [resourcemanager _imageInfoForUrl: resourceURL + fileName: fileNameValue + framework: frameworkName + languages: [context languages]]; + if (imageinfo != nil) + { + if (calculateWidth) + { + widthStr = [imageinfo widthString]; + } + if (calculateHeight) + { + heightStr = [imageinfo heightString]; + } + } + else + { + NSLog(@"%@: Could not get height/width information for image at '%@' '%@' '%@'", + NSStringFromClass([self class]), resourceURL, + fileNameValue, frameworkName); + } + } + + [response _appendTagAttribute: @"src" + value: resourceURL + escapingHTMLAttributeValue: NO]; + + if (widthStr != nil) + { + [response _appendTagAttribute: @"width" + value: widthStr + escapingHTMLAttributeValue: NO]; + } + if (heightStr != nil) + { + [response _appendTagAttribute: @"height" + value: heightStr + escapingHTMLAttributeValue: NO]; + } } - // GSWeb does not have that jet. -// -// if (hasNoWidth || hasNoHeight) { -// GSWImageInfo * imageinfo = [resourcemanager _imageInfoForUrl: resourceURL -// fileName: fileNameValue -// framework: frameworkName -// languages: [context _languages]]); -// if (imageinfo != nil) { -// if (hasNoWidth) -// { -// widthStr = imageinfo.widthString(); -// } -// if (hasNoHeight) -// { -// heightStr = imageinfo.heightString(); -// } -// } else -// { -// NSLog("%@: could not get height/width information for image at '%@/%@/%@'", -// [self class], resourceURL, fileNameValue, frameworkName); -// } -// } - - [response _appendTagAttribute: @"src" - value: resourceURL - escapingHTMLAttributeValue: NO]; - - if (widthStr != nil) { - [response _appendTagAttribute: @"width" - value: widthStr - escapingHTMLAttributeValue: NO]; + else + { + NSString *message + = [resourcemanager errorMessageUrlForResourceNamed: fileNameValue + inFramework: frameworkName]; + [response _appendTagAttribute:@"src" + value: message + escapingHTMLAttributeValue:NO]; } - if (heightStr != nil) { - [response _appendTagAttribute: @"height" - value: heightStr - escapingHTMLAttributeValue: NO]; - } - } else { - - [response _appendTagAttribute:@"src" - value:[resourcemanager errorMessageUrlForResourceNamed: fileNameValue - inFramework: frameworkName] - escapingHTMLAttributeValue:NO]; - } } // used from GSWActiveImage @@ -221,102 +246,21 @@ RCS_ID("$Id$") } } +/* This function exists in WO45 and its implementation coresponds + * to the class method. Yet insubesquent versions of WO it has + * been consolidated into the class method. We keep this method + * to remain compatible yet internally take advantage of the class method + * where applicable. + */ - (void) _appendFilenameToResponse:(GSWResponse *) response inContext:(GSWContext *) context { - id widthValue = nil; - id heightValue = nil; - BOOL hasNoWidth = NO; - BOOL hasNoHeight = NO; - - GSWResourceManager * resourcemanager = [GSWApp resourceManager]; - - GSWComponent * component = GSWContext_component(context); - - NSString* fileNameValue = [_filename valueInComponent:component]; - - NSString * frameworkName = [self _frameworkNameForAssociation: _framework - inComponent: component]; - - NSString * resourceURL = [context _urlForResourceNamed:frameworkName inFramework: frameworkName]; - - if (resourceURL != nil) { - NSString * widthStr = nil; - NSString * heightStr = nil; - - NSLog(@"%s resourceURL:%@",__PRETTY_FUNCTION__, resourceURL); - - if (_width != nil || _height != nil) { - if (_width != nil) { - widthValue = [_width valueInComponent:component]; - if (widthValue != nil) { - widthStr = NSStringWithObject(widthValue); - } - - hasNoWidth = (widthStr == nil || [widthStr isEqual:@"*"]); - } - if (_height != nil) { - heightValue = [_height valueInComponent:component]; - if (heightValue != nil) { - heightStr = NSStringWithObject(heightValue); - } - - hasNoHeight = (heightStr == nil || [heightStr isEqual:@"*"]); - } - } else { - hasNoWidth = YES; - hasNoHeight = YES; - // do we really need that log? dw. - // NSLog("%@: No height or width information provided for '%@'. If possible, this information should be provided for best performance.", [self class], fileNameValue); - } - // GSWeb does not have that jet. -// -// if (hasNoWidth || hasNoHeight) { -// GSWImageInfo * imageinfo = [resourcemanager _imageInfoForUrl: resourceURL -// fileName: fileNameValue -// framework: frameworkName -// languages: [context _languages]]); -// if (imageinfo != nil) { -// if (hasNoWidth) -// { -// widthStr = imageinfo.widthString(); -// } -// if (hasNoHeight) -// { -// heightStr = imageinfo.heightString(); -// } -// } else -// { -// NSLog("%@: could not get height/width information for image at '%@/%@/%@'", -// [self class], resourceURL, fileNameValue, frameworkName); -// } -// } - - [response _appendTagAttribute: @"src" - value: resourceURL - escapingHTMLAttributeValue: NO]; - - if (widthStr != nil) { - GSWResponse_appendTagAttributeValueEscapingHTMLAttributeValue(response, - width__Key, - widthStr, - NO); - } - if (heightStr != nil) { - GSWResponse_appendTagAttributeValueEscapingHTMLAttributeValue(response, - height__Key, - heightStr, - NO); - } - } else { // resourceURL is nil - - NSLog(@"%s resourceURL is nil self:%@",__PRETTY_FUNCTION__, self); - - [response _appendTagAttribute:@"src" - value:[resourcemanager errorMessageUrlForResourceNamed: fileNameValue - inFramework: frameworkName] - escapingHTMLAttributeValue:NO]; - } + [GSWImage _appendFilenameToResponse: response + inContext: context + framework: _framework + filename: _filename + width: _width + height: _height]; } -(void) _appendCloseTagToResponse:(GSWResponse *) response @@ -325,4 +269,15 @@ RCS_ID("$Id$") // do nothing! } +/* This function exists in WO45 and its implementation coresponds + * to the class method of GSWHTMLDynamicElement. Yet insubesquent + * versions of WO it has been consolidated into the class method. + * We keep this method to remain compatible yet internally take + * advantage of the class method where applicable. + */ +- (NSString*) _frameworkNameInComponent: (GSWComponent *) component +{ + return [GSWHTMLDynamicElement _frameworkNameForAssociation: _framework + inComponent: component]; +} @end diff --git a/GSWeb.framework/GSWResourceManager.h b/GSWeb.framework/GSWResourceManager.h index 993f38e..64c8ce5 100644 --- a/GSWeb.framework/GSWResourceManager.h +++ b/GSWeb.framework/GSWResourceManager.h @@ -220,6 +220,10 @@ bundle if none is found inFramework:(NSString *) frameworkName; - (void) _cacheData:(GSWURLValuedElementData *) aData; +- (GSWImageInfo *) _imageInfoForUrl:(NSString *)resourceURL + fileName:(NSString *)filename + framework:(NSString *)frameworkName + languages:(NSArray *)languages; @end diff --git a/GSWeb.framework/GSWResourceManager.m b/GSWeb.framework/GSWResourceManager.m index 8c871aa..271b136 100644 --- a/GSWeb.framework/GSWResourceManager.m +++ b/GSWeb.framework/GSWResourceManager.m @@ -1780,30 +1780,46 @@ bundle if none is found }; // wo -- (NSString*) errorMessageUrlForResourceNamed:(NSString *) resourceName - inFramework:(NSString *) frameworkName +- (NSString *) errorMessageUrlForResourceNamed:(NSString *) resourceName + inFramework:(NSString *) frameworkName { NSString * url = nil; - if( resourceName == nil) { - resourceName = @"nil"; - } - if (frameworkName != nil) { - url = [NSString stringWithFormat:@"/ERROR/NOT_FOUND/framework=%@/filename=%@", frameworkName, resourceName]; - } else { - NSString * s3 = [GSWApp name]; - url = [NSString stringWithFormat:@"/ERROR/NOT_FOUND/app=%@/filename=%@", s3, resourceName]; - } + if( resourceName == nil) + { + resourceName = @"nil"; + } + if (frameworkName != nil) + { + url = [NSString stringWithFormat:@"/ERROR/NOT_FOUND/framework=%@/filename=%@", frameworkName, resourceName]; + } + else + { + NSString * s3 = [GSWApp name]; + url = [NSString stringWithFormat:@"/ERROR/NOT_FOUND/app=%@/filename=%@", s3, resourceName]; + } return url; } // checkme: locking?? davew - (void) _cacheData:(GSWURLValuedElementData *) aData { - if (aData != nil) { - [_urlValuedElementsData setObject: aData - forKey: [aData key]]; - } + if (aData != nil) + { + [_urlValuedElementsData setObject: aData + forKey: [aData key]]; + } } +- (GSWImageInfo *) _imageInfoForUrl:(NSString *)resourceURL + fileName:(NSString *)filename + framework:(NSString *)frameworkName + languages:(NSArray *)languages +{ + NSString *path = [self pathForResourceNamed:filename + inFramework:(NSString*)frameworkName + languages:(NSArray*)languages]; + + return [GSWImageInfo imageInfoWithFile: path]; +} @end diff --git a/GSWeb.framework/GSWeb.h b/GSWeb.framework/GSWeb.h index 7796c7e..fae1799 100644 --- a/GSWeb.framework/GSWeb.h +++ b/GSWeb.framework/GSWeb.h @@ -149,6 +149,7 @@ @class GSWMonitorXMLDecoder; @class GSWRecording; @class GSWInputStreamData; +@class GSWImageInfo; #include "GSWDefines.h" #include "GSWConstants.h"