]> err.no Git - sope/blob - sope-appserver/NGObjWeb/DynamicElements/WOGenericContainer.m
improved query string handling
[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 #include "WOElement+private.h"
36 #include "decommon.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 - (id)template {
65   return self->template;
66 }
67
68 /* handling requests */
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 /* generate response */
78
79 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
80   WOComponent *sComponent;
81   NSString    *tag;
82   
83   if ([[_ctx request] isFromClientComponent])
84     return;
85   
86   sComponent = [_ctx component];
87   switch (self->tagNameType) {
88     case TagNameType_Assoc:
89       if ((tag = [(id)self->tagName stringValueInComponent:sComponent]) == nil)
90         tag = @"p";
91       break;
92     case TagNameType_String:
93       if ((tag = self->tagName) == nil) tag = @"p";
94       break;
95     case TagNameType_ASCII:
96     default:
97       tag = nil;
98       break;
99   }
100   
101   WOResponse_AddChar(_response, '<');
102   if (tag) {
103     WOResponse_AddString(_response, tag);
104   }
105   else if (self->tagNameType == TagNameType_ASCII) {
106     WOResponse_AddCString(_response, self->tagName);
107   }
108   
109   [self _appendAttributesToResponse:_response inContext:_ctx];
110   
111   if (self->otherTagString) {
112     WOResponse_AddChar(_response, ' ');
113     WOResponse_AddString(_response,
114                          [self->otherTagString stringValueInComponent:
115                            sComponent]);
116   }
117   WOResponse_AddChar(_response, '>');
118   
119   [self->template appendToResponse:_response inContext:_ctx];
120   
121   WOResponse_AddCString(_response, "</");
122   if (tag) {
123     WOResponse_AddString(_response, tag);
124   }
125   else if (self->tagNameType == TagNameType_ASCII) {
126     WOResponse_AddCString(_response, self->tagName);
127   }
128   WOResponse_AddChar(_response, '>');
129 }
130
131 @end /* WOGenericContainer */