#import "JubConfig.h"

@implementation JubConfig
@synthesize domain, server;
@synthesize username;
@synthesize password;

- initWithFile: (OFString*)file
{
	self = [super init];

	@try {
		OFAutoreleasePool *pool = [OFAutoreleasePool new];
		OFXMLParser *parser = [OFXMLParser parser];
		OFXMLElementBuilder *builder =
		    [OFXMLElementBuilder elementBuilder];

		parser.delegate = builder;
		builder.delegate = self;

		[parser parseFile: file];

		[pool release];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[domain release];
	[server release];
	[username release];
	[password release];

	[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
