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