]> git.babelmonkeys.de Git - jubjub.git/blob - src/core/JubConfig.m
33fe2c5d82f33ac3a6f84e1681c31304291b3f9c
[jubjub.git] / src / core / JubConfig.m
1 #import "JubConfig.h"
2
3 @implementation JubConfig
4 @synthesize domain, server;
5 @synthesize username;
6 @synthesize password;
7
8 - initWithFile: (OFString*)file
9 {
10         self = [super init];
11
12         @try {
13                 OFAutoreleasePool *pool = [OFAutoreleasePool new];
14                 OFXMLParser *parser = [OFXMLParser parser];
15                 OFXMLElementBuilder *builder =
16                     [OFXMLElementBuilder elementBuilder];
17
18                 parser.delegate = builder;
19                 builder.delegate = self;
20
21                 [parser parseFile: file];
22
23                 [pool release];
24         } @catch (id e) {
25                 [self release];
26                 @throw e;
27         }
28
29         return self;
30 }
31
32 - (void)dealloc
33 {
34         [domain release];
35         [server release];
36         [username release];
37         [password release];
38
39         [super dealloc];
40 }
41
42 - (void)elementBuilder: (OFXMLElementBuilder*)builder
43        didBuildElement: (OFXMLElement*)element
44 {
45         // TODO: At error handling for missing elements
46         of_log(@"Parsed file: %@", element);
47         domain = [[[element elementForName: @"domain"
48                                  namespace: CONFIG_NS] stringValue] copy];
49         server = [[[element elementForName: @"server"
50                                  namespace: CONFIG_NS] stringValue] copy];
51         username = [[[element elementForName: @"username"
52                                    namespace: CONFIG_NS] stringValue] copy];
53         password = [[[element elementForName: @"password"
54                                    namespace: CONFIG_NS] stringValue] copy];
55 }
56 @end