]> err.no Git - sope/blob - sope-appserver/WEExtensions/WETableMatrixContent.m
added strict OSX bundle dependencies
[sope] / sope-appserver / WEExtensions / WETableMatrixContent.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 <NGObjWeb/WODynamicElement.h>
23
24 @interface WETableMatrixContentImp : WODynamicElement
25 {
26   WOAssociation *elementName;
27   WOAssociation *rowspan;     /* a write variable */
28   WOAssociation *colspan;     /* a write variable */
29   
30   WOElement     *template;
31 }
32 @end
33
34 @interface WETableMatrixContent : WETableMatrixContentImp
35 @end
36
37 @interface WETableMatrixNoContent : WETableMatrixContentImp
38 @end
39
40 #include <NGObjWeb/NGObjWeb.h>
41 #include "common.h"
42
43 @implementation WETableMatrixContentImp
44
45 - (id)initWithName:(NSString *)_name
46   associations:(NSDictionary *)_config
47   template:(WOElement *)_subs
48 {
49   if ((self = [super initWithName:_name associations:_config template:_subs])) {
50     self->elementName = WOExtGetProperty(_config, @"elementName");
51     self->rowspan     = WOExtGetProperty(_config, @"rowspan");
52     self->colspan     = WOExtGetProperty(_config, @"colspan");
53     
54     self->template = [_subs retain];
55   }
56   return self;
57 }
58
59 - (void)dealloc {
60   RELEASE(self->rowspan);
61   RELEASE(self->colspan);
62   RELEASE(self->elementName);
63   RELEASE(self->template);
64   [super dealloc];
65 }
66
67 /* accessors */
68
69 - (NSString *)modeKey {
70   [self logWithFormat:@"ERROR: subclasses should override -modeKey!"];
71   return nil;
72 }
73
74 /* response generation */
75
76 - (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
77   id       tmp;
78   NSString *tag;
79   int      cspan, rspan;
80   
81   if ((tmp = [_ctx valueForKey:@"WETableMatrix_Query"])) {
82     [tmp addObject:[self modeKey]];
83     return;
84   }
85   
86   if ((tmp = [_ctx valueForKey:@"WETableMatrix_Mode"]) == nil)
87     return;
88
89   if (![tmp isEqualToString:[self modeKey]])
90     return;
91
92   cspan = [[_ctx objectForKey:@"WETableMatrix_ColSpan"] intValue];
93   if (cspan < 1) cspan = 1;
94   rspan = [[_ctx objectForKey:@"WETableMatrix_RowSpan"] intValue];
95   if (rspan < 1) rspan = 1;
96   
97   if ([self->colspan isValueSettable]) {
98     [self->colspan setValue:[NSNumber numberWithInt:cspan]
99                    inComponent:[_ctx component]];
100   }
101   if ([self->rowspan isValueSettable]) {
102     [self->rowspan setValue:[NSNumber numberWithInt:rspan]
103                    inComponent:[_ctx component]];
104   }
105   
106   tag = [self->elementName stringValueInComponent:[_ctx component]];
107
108   if (tag) {
109     NSString *s;
110     char buf[64];
111     
112     [_response appendContentString:@"<"];
113     [_response appendContentString:tag];
114
115     if (cspan > 1) {
116       sprintf(buf, "%i", cspan);
117       s = [[NSString alloc] initWithCString:buf];
118       [_response appendContentString:@" colspan=\""];
119       [_response appendContentString:s];
120       [_response appendContentString:@"\""];
121       [s release];
122     }
123     if (rspan > 1) {
124       sprintf(buf, "%i", rspan);
125       s = [[NSString alloc] initWithCString:buf];
126       [_response appendContentString:@" rowspan=\""];
127       [_response appendContentString:s];
128       [_response appendContentString:@"\""];
129       [s release];
130     }
131
132     [self appendExtraAttributesToResponse:_response inContext:_ctx];
133     
134     [_response appendContentString:@">"];
135   }
136   
137   [self->template appendToResponse:_response inContext:_ctx];
138
139   if (tag) {
140     [_response appendContentString:@"</"];
141     [_response appendContentString:tag];
142     [_response appendContentString:@">"];
143   }
144 }
145
146 @end /* WETableMatrixContentImp */
147
148 @implementation WETableMatrixContent
149
150 - (NSString *)modeKey {
151   return @"content";
152 }
153
154 @end /* WETableMatrixContent */
155
156 @implementation WETableMatrixNoContent
157
158 - (NSString *)modeKey {
159   return @"empty";
160 }
161
162 @end /* WETableMatrixNoContent */