validateTakeValue: forKeyPath:

fix for paths where an object in the path is nil



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@30607 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
dwetzel 2010-06-07 18:49:24 +00:00
parent 8279f5933e
commit ea5e6beb9a
2 changed files with 45 additions and 8 deletions

View file

@ -1,10 +1,15 @@
2010-05-05 David Wetzel <dave@turbocat.de>
2010-06-07 David Wetzel <dave@turbocat.de>
* GSWeb.framework/GSWComponent.m
validateTakeValue: forKeyPath:
fix for paths where an object in the path is nil
2010-06-05 David Wetzel <dave@turbocat.de>
* GSWeb.framework/GSWApplication.m
fixed typo in include
* GSWeb.framework/GSWString.m
removed unused IMP caching
2010-05-05 David Wetzel <dave@turbocat.de>
2010-06-05 David Wetzel <dave@turbocat.de>
* GSWExtensionsGSW.framework/GSWFileUploadComponent.m
* GSWExtensionsGSW.framework/GSWLogin.m
removed logs

View file

@ -1387,21 +1387,53 @@ Call this method before using a component which was cached in a variable.
**/
- (id)validateTakeValue:(id)value forKeyPath:(NSString *)path
{
NSError *outError = nil;
BOOL ok = [self validateValue:&value
forKeyPath:path
error:&outError];
NSError * outError = nil;
BOOL ok = NO;
NSRange dotRange;
NSString * errorStr = @"unknown reason";
if (!path) {
errorStr = @"keyPath must not be nil";
} else {
id targetObject = self;
dotRange = [path rangeOfString:@"."
options:NSBackwardsSearch];
if (dotRange.location != NSNotFound) {
NSString * newPath = [path substringToIndex:dotRange.location];
targetObject = [self valueForKeyPath:newPath];
if (!targetObject) {
// If there is no object to set a value, we cannot do any validation.
// There is nothing to set on a non-existing object, so just go.
return nil;
}
path = [path substringFromIndex: dotRange.location];
NSLog(@"paths '%@'", path);
}
ok = [targetObject validateValue:&value
forKeyPath:path
error:&outError];
}
if (ok) { // value is ok
[self setValue:value
forKeyPath:path];
forKeyPath:path];
return value;
} else {
NSException * exception=nil;
NSDictionary * uInfo;
NSString * errorStr = @"unknown reason";
uInfo = [NSDictionary dictionaryWithObjectsAndKeys:
(value ? value : (id)@"nil"), @"EOValidatedObjectUserInfoKey",