// $Id$

#include <NGObjWeb/SoComponent.h>
#include <NGObjWeb/SoHTTPAuthenticator.h>
#include <NGObjWeb/SoUser.h>


@interface UIxPageFrame : SoComponent
{
    NSString *title;
    NSString *rootURL;
    NSString *userRootURL;
}

- (SoUser *)user;
- (NSString *)rootURL;
- (NSString *)userRootURL;
- (NSString *)calendarRootURL;

@end

#include "common.h"

@implementation UIxPageFrame

- (void)dealloc {
  [self->title release];
  [self->rootURL release];
  [self->userRootURL release];
  [super dealloc];
}

/* accessors */

- (void)setTitle:(NSString *)_value {
  ASSIGN(self->title, _value);
}
- (NSString *)title {
  return self->title;
}

- (SoUser *)user {
    WOContext *ctx;
    
    ctx = [self context];
    return [[[self clientObject] authenticatorInContext:ctx]
                                 userInContext:ctx];
}

- (NSString *)rootURL {
    WOContext *ctx;
    NSArray *traversalObjects;

    if(self->rootURL)
        return self->rootURL;

    ctx = [self context];
    traversalObjects = [ctx objectTraversalStack];
    self->rootURL = [[[traversalObjects objectAtIndex:0]
                                        rootURLInContext:ctx]
                                        retain];
    return self->rootURL;
}

- (NSString *)userRootURL {
    WOContext *ctx;
    NSArray *traversalObjects;

    if(self->userRootURL)
        return self->userRootURL;

    ctx = [self context];
    traversalObjects = [ctx objectTraversalStack];
    self->userRootURL = [[[[traversalObjects objectAtIndex:1]
                                             baseURLInContext:ctx]
                                             stringByAppendingString:@"/"]
                                             retain];
    return self->userRootURL;
}

- (NSString *)calendarRootURL {
    return [[self userRootURL] stringByAppendingString:@"Calendar/"];
}


@end /* UIxPageFrame */
