@try {
OFAutoreleasePool *pool = [OFAutoreleasePool new];
- OFXMLParser *parser = [OFXMLParser parser];
- OFXMLElementBuilder *builder =
- [OFXMLElementBuilder elementBuilder];
-
- parser.delegate = builder;
- builder.delegate = self;
-
- [parser parseFile: file];
+ OFXMLElement *element = [OFXMLElement elementWithFile: file];
+
+ if (![element.name isEqual: @"config"] ||
+ ![element.namespace isEqual: CONFIG_NS]) {
+ // TODO: load default config
+ [pool release];
+ return self;
+ }
+
+ // TODO: Add error handling for missing elements
+ of_log(@"Parsed file: %@", element);
+ domain = [[[element
+ elementForName: @"domain"
+ namespace: CONFIG_NS] stringValue] copy];
+ server = [[[element
+ elementForName: @"server"
+ namespace: CONFIG_NS] stringValue] copy];
+ username = [[[element
+ elementForName: @"username"
+ namespace: CONFIG_NS] stringValue] copy];
+ password = [[[element
+ elementForName: @"password"
+ namespace: CONFIG_NS] stringValue] copy];
[pool release];
} @catch (id e) {
[super dealloc];
}
-
-- (void)elementBuilder: (OFXMLElementBuilder*)builder
- didBuildElement: (OFXMLElement*)element
-{
- // TODO: At error handling for missing elements
- of_log(@"Parsed file: %@", element);
- domain = [[[element elementForName: @"domain"
- namespace: CONFIG_NS] stringValue] copy];
- server = [[[element elementForName: @"server"
- namespace: CONFIG_NS] stringValue] copy];
- username = [[[element elementForName: @"username"
- namespace: CONFIG_NS] stringValue] copy];
- password = [[[element elementForName: @"password"
- namespace: CONFIG_NS] stringValue] copy];
-}
@end