]> err.no Git - sope/blob - sope-appserver/NGObjWeb/DynamicElements/WOGenericContainer.m
fixed copyrights for 2005
[sope] / sope-appserver / NGObjWeb / DynamicElements / WOGenericContainer.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE 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   SOPE 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 SOPE; 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
22 #include "WOGenericElement.h"
23
24 @interface WOGenericContainer : WOGenericElement
25 {
26   // WODynamicElement:   extraAttributes
27   // WODynamicElement:   otherTagString
28   // WOGenericContainer: tagName
29 @protected
30   WOElement *template;
31 }
32
33 @end
34
35 #import "WOElement+private.h"
36 #import "common.h"
37
38 // TODO(perf): ASCII Tags (appendContentCString)
39 // TODO(perf): constant tags
40
41 #define TagNameType_Assoc  0
42 #define TagNameType_String 1
43 #define TagNameType_ASCII  2
44
45 @implementation WOGenericContainer
46
47 - (id)initWithName:(NSString *)_name
48   associations:(NSDictionary *)_config
49   template:(WOElement *)_c
50 {
51   if ((self = [super initWithName:_name associations:_config template:_c])) {
52     self->template = [_c retain];
53   }
54   return self;
55 }
56
57 - (void)dealloc {
58   [self->template release];
59   [super dealloc];
60 }
61
62 /* accessors */
63
64 - (WOElement *)template {
65   return self->template;
66 }
67
68 // ******************** responder ********************
69
70 - (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
71   [self->template takeValuesFromRequest:_req inContext:_ctx];
72 }
73 - (id)invokeActionForRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
74   return [self->template invokeActionForRequest:_req inContext:_ctx];
75 }
76
77 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
78   WOComponent *sComponent;
79   NSString    *tag;
80   
81   if ([[_ctx request] isFromClientComponent])
82     return;
83   
84   sComponent = [_ctx component];
85   switch (self->tagNameType) {
86     case TagNameType_Assoc:
87       if ((tag = [(id)self->tagName stringValueInComponent:sComponent]) == nil)
88         tag = @"p";
89       break;
90     case TagNameType_String:
91       if ((tag = self->tagName) == nil) tag = @"p";
92       break;
93     case TagNameType_ASCII:
94     default:
95       tag = nil;
96       break;
97   }
98   
99   WOResponse_AddChar(_response, '<');
100   if (tag) {
101     WOResponse_AddString(_response, tag);
102   }
103   else if (self->tagNameType == TagNameType_ASCII) {
104     WOResponse_AddCString(_response, self->tagName);
105   }
106   
107   [self _appendAttributesToResponse:_response inContext:_ctx];
108   
109   if (self->otherTagString) {
110     WOResponse_AddChar(_response, ' ');
111     WOResponse_AddString(_response,
112                          [self->otherTagString stringValueInComponent:
113                            sComponent]);
114   }
115   WOResponse_AddChar(_response, '>');
116   
117   [self->template appendToResponse:_response inContext:_ctx];
118   
119   WOResponse_AddCString(_response, "</");
120   if (tag) {
121     WOResponse_AddString(_response, tag);
122   }
123   else if (self->tagNameType == TagNameType_ASCII) {
124     WOResponse_AddCString(_response, self->tagName);
125   }
126   WOResponse_AddChar(_response, '>');
127 }
128
129 @end /* WOGenericContainer */