mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 09:21:22 +00:00
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:
parent
0520b35f07
commit
040da4f332
1 changed files with 97 additions and 47 deletions
|
@ -1035,61 +1035,111 @@
|
|||
NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:data
|
||||
options:0
|
||||
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\"]/"
|
||||
@"string[contains(@key,\"CustomClassName\")]"
|
||||
error:NULL];
|
||||
if([customClassNodes count] > 0)
|
||||
{
|
||||
NSArray *objectRecords = nil;
|
||||
NSEnumerator *en = [customClassNodes objectEnumerator];
|
||||
id node = nil;
|
||||
NSMutableDictionary *customClassDict = [NSMutableDictionary dictionary];
|
||||
if (customClassNodes)
|
||||
{
|
||||
NSDebugLLog(@"PREXIB", @"%s:customClassNodes: %@\n", __PRETTY_FUNCTION__, customClassNodes);
|
||||
|
||||
while((node = [en nextObject]) != nil)
|
||||
{
|
||||
id keyNode = [node attributeForName:@"key"];
|
||||
NSString *keyValue = [[keyNode stringValue] stringByReplacingOccurrencesOfString:@".CustomClassName"
|
||||
withString:@""];
|
||||
NSString *className = [node stringValue];
|
||||
NSString *objectRecordXpath = nil;
|
||||
// Replace the NSXMLNodes with a dictionary...
|
||||
NSInteger index = 0;
|
||||
for (index = 0; index < [customClassNodes count]; ++index)
|
||||
{
|
||||
id node = [customClassNodes objectAtIndex:index];
|
||||
if ([node isMemberOfClass:[NSXMLElement class]])
|
||||
{
|
||||
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\"]/"
|
||||
@"int[@key=\"objectID\"][text()=\"%@\"]/../reference",
|
||||
keyValue];
|
||||
while((key = [en nextObject]) != nil)
|
||||
{
|
||||
NSString *keyValue = [key stringByReplacingOccurrencesOfString:@".CustomClassName" withString:@""];
|
||||
NSString *className = [customClassDict objectForKey:key];
|
||||
NSString *objectRecordXpath = nil;
|
||||
|
||||
objectRecords = [document nodesForXPath:objectRecordXpath
|
||||
error:NULL];
|
||||
NSString *refId = nil;
|
||||
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;
|
||||
objectRecordXpath = [NSString stringWithFormat:@"//object[@class=\"IBObjectRecord\"]/"
|
||||
@"int[@key=\"objectID\"][text()=\"%@\"]/../reference",
|
||||
keyValue];
|
||||
|
||||
refId = [[record attributeForName:@"ref"] stringValue];
|
||||
// NSLog(@"Reference Id = %@",refId);
|
||||
refXpath = [NSString stringWithFormat:@"//object[@id=\"%@\"]",refId];
|
||||
classNodes = [document nodesForXPath:refXpath
|
||||
error:NULL];
|
||||
if([classNodes count] > 0)
|
||||
{
|
||||
classNode = [classNodes objectAtIndex:0];
|
||||
// NSLog(@"%@",classNode);
|
||||
[[classNode attributeForName:@"class"] setStringValue:className];
|
||||
// NSLog(@"Changed %@",classNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
objectRecords = [document nodesForXPath:objectRecordXpath error:NULL];
|
||||
NSString *refId = nil;
|
||||
if([objectRecords count] > 0)
|
||||
{
|
||||
id record = nil;
|
||||
NSEnumerator *oen = [objectRecords objectEnumerator];
|
||||
while((record = [oen nextObject]) != nil)
|
||||
{
|
||||
if ([record isMemberOfClass:[NSXMLElement class]])
|
||||
{
|
||||
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];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue