]> err.no Git - sope/blob - sope-appserver/NGObjWeb/Templates/WOTemplate.m
renamed packages as discussed in the developer list
[sope] / sope-appserver / NGObjWeb / Templates / WOTemplate.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include <NGObjWeb/WOTemplateBuilder.h>
24 #include "common.h"
25
26 @implementation WOTemplate
27
28 + (int)version {
29   return [super version] + 1 /* v3 */;
30 }
31 + (void)initialize {
32   NSAssert2([super version] == 2,
33             @"invalid superclass (%@) version %i !",
34             NSStringFromClass([self superclass]), [super version]);
35 }
36
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];
42   }
43   return self;
44 }
45
46 - (void)dealloc {
47   [self->kvcTemplateVars   release];
48   [self->componentScript   release];
49   [self->subcomponentInfos release];
50   [self->loadDate          release];
51   [self->rootElement       release];
52   [self->url               release];
53   [super dealloc];
54 }
55
56 /* component info */
57
58 - (void)setComponentScript:(WOComponentScript *)_script {
59   ASSIGN(self->componentScript, _script);
60 }
61 - (WOComponentScript *)componentScript {
62   return self->componentScript;
63 }
64
65 - (void)setKeyValueArchivedTemplateVariables:(NSDictionary *)_vars {
66   ASSIGN(self->kvcTemplateVars, _vars);
67 }
68 - (NSDictionary *)keyValueArchivedTemplateVariables {
69   return self->kvcTemplateVars;
70 }
71
72 /* component info */
73
74 /* subcomponent info */
75
76 - (BOOL)hasSubcomponentInfos {
77   return [self->subcomponentInfos count] > 0 ? YES : NO;
78 }
79
80 - (NSEnumerator *)infoKeyEnumerator {
81   return [self->subcomponentInfos keyEnumerator];
82 }
83 - (WOSubcomponentInfo *)subcomponentInfoForKey:(NSString *)_key {
84   if (_key == nil) return nil;
85   return [self->subcomponentInfos objectForKey:_key];
86 }
87
88 - (void)addSubcomponentWithKey:(NSString *)_key
89   name:(NSString *)_name
90   bindings:(NSDictionary *)_bindings
91 {
92   WOSubcomponentInfo *info;
93   
94   info = [[WOSubcomponentInfo alloc] initWithName:_name bindings:_bindings];
95   if (info == nil)
96     return;
97
98   if (self->subcomponentInfos == nil)
99     self->subcomponentInfos = [[NSMutableDictionary alloc] initWithCapacity:4];
100     
101   [self->subcomponentInfos setObject:info forKey:_key];
102   [info release];
103 }
104
105 /* accessors */
106
107 - (void)setRootElement:(WOElement *)_element {
108   ASSIGN(self->rootElement, _element);
109 }
110 - (WOElement *)rootElement {
111   return self->rootElement;
112 }
113
114 - (NSURL *)url {
115     return self->url;
116 }
117
118 /* WOElement methods */
119
120 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
121   [self->rootElement takeValuesFromRequest:_req inContext:_ctx];
122 }
123
124 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
125   return [self->rootElement invokeActionForRequest:_req inContext:_ctx];
126 }
127
128 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
129   [self->rootElement appendToResponse:_response inContext:_ctx];
130 }
131
132 /* description */
133
134 - (NSString *)description {
135   NSMutableString *ms = [NSMutableString stringWithCapacity:128];
136   
137   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
138   
139   if (self->url) {
140     if ([self->url isFileURL])
141       [ms appendFormat:@" path=%@", [self->url path]];
142     else
143       [ms appendFormat:@" url=%@", [self->url absoluteString]];
144   }
145   if (self->subcomponentInfos)
146     [ms appendFormat:@" #subcomponents=%i", [self->subcomponentInfos count]];
147   
148   [ms appendString:@">"];
149   return ms;
150 }
151
152 @end /* WOTemplate */