2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include <NGObjWeb/WOTemplateBuilder.h>
26 @implementation WOTemplate
29 return [super version] + 1 /* v3 */;
32 NSAssert2([super version] == 2,
33 @"invalid superclass (%@) version %i !",
34 NSStringFromClass([self superclass]), [super version]);
37 - (id)initWithURL:(NSURL *)_url rootElement:(WOElement *)_element {
38 if ((self = [super init])) {
39 self->url = [_url copy];
40 self->rootElement = [_element retain];
41 self->loadDate = [[NSDate alloc] init];
47 [self->kvcTemplateVars release];
48 [self->componentScript release];
49 [self->subcomponentInfos release];
50 [self->loadDate release];
51 [self->rootElement release];
58 - (void)setComponentScript:(WOComponentScript *)_script {
59 ASSIGN(self->componentScript, _script);
61 - (WOComponentScript *)componentScript {
62 return self->componentScript;
65 - (void)setKeyValueArchivedTemplateVariables:(NSDictionary *)_vars {
66 ASSIGN(self->kvcTemplateVars, _vars);
68 - (NSDictionary *)keyValueArchivedTemplateVariables {
69 return self->kvcTemplateVars;
74 /* subcomponent info */
76 - (BOOL)hasSubcomponentInfos {
77 return [self->subcomponentInfos count] > 0 ? YES : NO;
80 - (NSEnumerator *)infoKeyEnumerator {
81 return [self->subcomponentInfos keyEnumerator];
83 - (WOSubcomponentInfo *)subcomponentInfoForKey:(NSString *)_key {
84 if (_key == nil) return nil;
85 return [self->subcomponentInfos objectForKey:_key];
88 - (void)addSubcomponentWithKey:(NSString *)_key
89 name:(NSString *)_name
90 bindings:(NSDictionary *)_bindings
92 WOSubcomponentInfo *info;
94 info = [[WOSubcomponentInfo alloc] initWithName:_name bindings:_bindings];
98 if (self->subcomponentInfos == nil)
99 self->subcomponentInfos = [[NSMutableDictionary alloc] initWithCapacity:4];
101 [self->subcomponentInfos setObject:info forKey:_key];
107 - (void)setRootElement:(WOElement *)_element {
108 ASSIGN(self->rootElement, _element);
110 - (WOElement *)rootElement {
111 return self->rootElement;
118 /* WOElement methods */
120 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
121 [self->rootElement takeValuesFromRequest:_req inContext:_ctx];
124 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
125 return [self->rootElement invokeActionForRequest:_req inContext:_ctx];
128 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
129 [self->rootElement appendToResponse:_response inContext:_ctx];
134 - (NSString *)description {
135 NSMutableString *ms = [NSMutableString stringWithCapacity:128];
137 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
140 if ([self->url isFileURL])
141 [ms appendFormat:@" path=%@", [self->url path]];
143 [ms appendFormat:@" url=%@", [self->url absoluteString]];
145 if (self->subcomponentInfos)
146 [ms appendFormat:@" #subcomponents=%i", [self->subcomponentInfos count]];
148 [ms appendString:@">"];
152 @end /* WOTemplate */