]> err.no Git - sope/blob - sope-appserver/NGObjWeb/DynamicElements/WOGenericContainer.m
Add libxml2-dev to libsope-xml4.7-dev deps
[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 isRenderingDisabled] || [[_ctx request] isFromClientComponent]) {
84     [self->template appendToResponse:_response inContext:_ctx];
85     return;
86   }
87
88   sComponent = [_ctx component];
89   switch (self->tagNameType) {
90     case TagNameType_Assoc:
91       if ((tag = [(id)self->tagName stringValueInComponent:sComponent]) == nil)
92         tag = @"p";
93       break;
94     case TagNameType_String:
95       if ((tag = self->tagName) == nil) tag = @"p";
96       break;
97     case TagNameType_ASCII:
98     default:
99       tag = nil;
100       break;
101   }
102   
103   WOResponse_AddChar(_response, '<');
104   if (tag) {
105     WOResponse_AddString(_response, tag);
106   }
107   else if (self->tagNameType == TagNameType_ASCII) {
108     WOResponse_AddCString(_response, self->tagName);
109   }
110   
111   [self _appendAttributesToResponse:_response inContext:_ctx];
112   
113   if (self->otherTagString) {
114     WOResponse_AddChar(_response, ' ');
115     WOResponse_AddString(_response,
116                          [self->otherTagString stringValueInComponent:
117                            sComponent]);
118   }
119   WOResponse_AddChar(_response, '>');
120   
121   [self->template appendToResponse:_response inContext:_ctx];
122   
123   WOResponse_AddCString(_response, "</");
124   if (tag) {
125     WOResponse_AddString(_response, tag);
126   }
127   else if (self->tagNameType == TagNameType_ASCII) {
128     WOResponse_AddCString(_response, self->tagName);
129   }
130   WOResponse_AddChar(_response, '>');
131 }
132
133 @end /* WOGenericContainer */