Patch fix for custom class substition - TEMPORARY

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@35507 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2012-09-03 20:48:10 +00:00
parent 0520b35f07
commit 040da4f332

View file

@ -1035,61 +1035,111 @@
NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:data NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:data
options:0 options:0
error:NULL]; error:NULL];
if(document != nil) if(document == nil)
{
NSLog(@"%s:DOCUMENT IS NIL: %@\n", __PRETTY_FUNCTION__, document);
}
else
{ {
NSArray *customClassNodes = [document nodesForXPath:@"//dictionary[@key=\"flattenedProperties\"]/" NSArray *customClassNodes = [document nodesForXPath:@"//dictionary[@key=\"flattenedProperties\"]/"
@"string[contains(@key,\"CustomClassName\")]" @"string[contains(@key,\"CustomClassName\")]"
error:NULL]; error:NULL];
if([customClassNodes count] > 0) NSMutableDictionary *customClassDict = [NSMutableDictionary dictionary];
{ if (customClassNodes)
NSArray *objectRecords = nil; {
NSEnumerator *en = [customClassNodes objectEnumerator]; NSDebugLLog(@"PREXIB", @"%s:customClassNodes: %@\n", __PRETTY_FUNCTION__, customClassNodes);
id node = nil;
while((node = [en nextObject]) != nil) // Replace the NSXMLNodes with a dictionary...
{ NSInteger index = 0;
id keyNode = [node attributeForName:@"key"]; for (index = 0; index < [customClassNodes count]; ++index)
NSString *keyValue = [[keyNode stringValue] stringByReplacingOccurrencesOfString:@".CustomClassName" {
withString:@""]; id node = [customClassNodes objectAtIndex:index];
NSString *className = [node stringValue]; if ([node isMemberOfClass:[NSXMLElement class]])
NSString *objectRecordXpath = nil; {
NSString *key = [[node attributeForName:@"key"] stringValue];
if ([key rangeOfString:@"CustomClassName"].location != NSNotFound)
[customClassDict setObject:[node stringValue] forKey:key];
}
}
}
else
{
NSArray *flatProps = [document nodesForXPath:@"//object[@key=\"flattenedProperties\"]" error:NULL];
if ([flatProps count] == 1)
{
NSInteger index = 0;
NSArray *xmlKeys = [[flatProps objectAtIndex:0] nodesForXPath:@"//object[@key=\"flattenedProperties\"]/object[@key=\"dict.sortedKeys\"]/*" error:NULL];
NSArray *xmlObjs = [[flatProps objectAtIndex:0] nodesForXPath:@"//object[@key=\"flattenedProperties\"]/object[@key=\"dict.values\"]/*" error:NULL];
if ([xmlKeys count] != [xmlObjs count])
{
NSLog(@"%s:keys to objs count mismatch - keys: %d objs: %d\n", __PRETTY_FUNCTION__,
[xmlKeys count], [xmlObjs count]);
}
else
{
for (index = 0; index < [xmlKeys count]; ++index)
{
id key = [[xmlKeys objectAtIndex:index] stringValue];
if ([key rangeOfString:@"CustomClassName"].location != NSNotFound)
{
NSString *obj = [[xmlObjs objectAtIndex:index] stringValue];
if ([obj isEqualToString:@"NSSecureTextField"] == NO) // SKIP FOR NOW!!!
[customClassDict setObject:[[xmlObjs objectAtIndex:index] stringValue] forKey:key];
}
}
}
}
}
NSDebugLLog(@"PREXIB", @"%s:customClassDict: %@\n", __PRETTY_FUNCTION__, customClassDict);
if([customClassDict count] > 0)
{
NSArray *objectRecords = nil;
NSEnumerator *en = [[customClassDict allKeys] objectEnumerator];
NSString *key = nil;
objectRecordXpath = [NSString stringWithFormat:@"//object[@class=\"IBObjectRecord\"]/" while((key = [en nextObject]) != nil)
@"int[@key=\"objectID\"][text()=\"%@\"]/../reference", {
keyValue]; NSString *keyValue = [key stringByReplacingOccurrencesOfString:@".CustomClassName" withString:@""];
NSString *className = [customClassDict objectForKey:key];
NSString *objectRecordXpath = nil;
objectRecords = [document nodesForXPath:objectRecordXpath objectRecordXpath = [NSString stringWithFormat:@"//object[@class=\"IBObjectRecord\"]/"
error:NULL]; @"int[@key=\"objectID\"][text()=\"%@\"]/../reference",
NSString *refId = nil; keyValue];
if([objectRecords count] > 0)
{
id record = nil;
NSEnumerator *oen = [objectRecords objectEnumerator];
while((record = [oen nextObject]) != nil)
{
if([[[record attributeForName:@"key"] stringValue] isEqualToString:@"object"])
{
NSArray *classNodes = nil;
id classNode = nil;
NSString *refXpath = nil;
refId = [[record attributeForName:@"ref"] stringValue]; objectRecords = [document nodesForXPath:objectRecordXpath error:NULL];
// NSLog(@"Reference Id = %@",refId); NSString *refId = nil;
refXpath = [NSString stringWithFormat:@"//object[@id=\"%@\"]",refId]; if([objectRecords count] > 0)
classNodes = [document nodesForXPath:refXpath {
error:NULL]; id record = nil;
if([classNodes count] > 0) NSEnumerator *oen = [objectRecords objectEnumerator];
{ while((record = [oen nextObject]) != nil)
classNode = [classNodes objectAtIndex:0]; {
// NSLog(@"%@",classNode); if ([record isMemberOfClass:[NSXMLElement class]])
[[classNode attributeForName:@"class"] setStringValue:className]; {
// NSLog(@"Changed %@",classNode); if([[[record attributeForName:@"key"] stringValue] isEqualToString:@"object"])
} {
} NSArray *classNodes = nil;
} id classNode = nil;
} NSString *refXpath = nil;
}
} refId = [[record attributeForName:@"ref"] stringValue];
refXpath = [NSString stringWithFormat:@"//object[@id=\"%@\"]",refId];
classNodes = [document nodesForXPath:refXpath
error:NULL];
if([classNodes count] > 0)
{
classNode = [classNodes objectAtIndex:0];
[[classNode attributeForName:@"class"] setStringValue:className];
}
}
}
}
}
}
}
result = [document XMLData]; result = [document XMLData];
} }