inContext:(WOContext *)_ctx
info:(WETableViewInfo *)_info
{
- if (!_info->isGroup) {
- WOComponent *cmp = [_ctx component];
- NSString *bg = [self->bgColor stringValueInComponent:cmp];
- NSString *a = [self->align stringValueInComponent:cmp];
- NSString *va = [self->valign stringValueInComponent:cmp];
- NSString *tC, *tF, *tS; // text font attrtibutes
- BOOL hasFont;
+ WOComponent *cmp;
+ NSString *bg, *a, *va;
+ NSString *tC, *tF, *tS; // text font attrtibutes
+ BOOL hasFont;
+
+ if (_info->isGroup)
+ return;
+
+ cmp = [_ctx component];
+ bg = [self->bgColor stringValueInComponent:cmp];
+ a = [self->align stringValueInComponent:cmp];
+ va = [self->valign stringValueInComponent:cmp];
- tC = [_ctx objectForKey:WETableView_fontColor];
- tF = [_ctx objectForKey:WETableView_fontFace];
- tS = [_ctx objectForKey:WETableView_fontSize];
- hasFont = (tC || tF || tS) ? YES : NO;
+ tC = [_ctx objectForKey:WETableView_fontColor];
+ tF = [_ctx objectForKey:WETableView_fontFace];
+ tS = [_ctx objectForKey:WETableView_fontSize];
+ hasFont = (tC || tF || tS) ? YES : NO;
- if (bg == nil) {
- bg = (_info->isEven)
- ? [_ctx objectForKey:WETableView_evenColor]
- : [_ctx objectForKey:WETableView_oddColor];
- }
+ if (bg == nil) {
+ bg = (_info->isEven)
+ ? [_ctx objectForKey:WETableView_evenColor]
+ : [_ctx objectForKey:WETableView_oddColor];
+ }
- [_response appendContentString:@"<td "]; // <td...>
- if (bg) {
- [_response appendContentString:@" bgcolor=\""];
- [_response appendContentString:bg];
- [_response appendContentCharacter:'"'];
- }
- if (_info->rowSpan > 1) {
- switch (_info->rowSpan) {
- case 0:
- [_response appendContentString:@" rowspan=\"0\""];
- break;
- case 1:
- [_response appendContentString:@" rowspan=\"1\""];
- break;
- case 2:
- [_response appendContentString:@" rowspan=\"2\""];
- break;
- default: {
- NSString *s;
- s = [[NSString alloc] initWithFormat:@"%i", _info->rowSpan];
- [_response appendContentString:@" rowspan=\""];
- [_response appendContentString:s];
- [_response appendContentCharacter:'"'];
- [s release];
- break; }
- }
- }
- if (a) {
- [_response appendContentString:@" align=\""];
- [_response appendContentString:a];
- [_response appendContentCharacter:'"'];
- }
- if (va) {
- [_response appendContentString:@" valign=\""];
- [_response appendContentString:va];
+ [_response appendContentString:@"<td "]; // <td...>
+ if (bg) {
+ [_response appendContentString:@" bgcolor=\""];
+ [_response appendContentString:bg];
+ [_response appendContentCharacter:'"'];
+ }
+ if (_info->rowSpan > 1) {
+ switch (_info->rowSpan) {
+ case 0:
+ [_response appendContentString:@" rowspan=\"0\""];
+ break;
+ case 1:
+ [_response appendContentString:@" rowspan=\"1\""];
+ break;
+ case 2:
+ [_response appendContentString:@" rowspan=\"2\""];
+ break;
+ default: {
+ NSString *s;
+ s = [[NSString alloc] initWithFormat:@"%i", _info->rowSpan];
+ [_response appendContentString:@" rowspan=\""];
+ [_response appendContentString:s];
[_response appendContentCharacter:'"'];
+ [s release];
+ break; }
}
- [self appendExtraAttributesToResponse:_response inContext:_ctx];
- [_response appendContentCharacter:'>'];
+ }
+ if (a) {
+ [_response appendContentString:@" align=\""];
+ [_response appendContentString:a];
+ [_response appendContentCharacter:'"'];
+ }
+ if (va) {
+ [_response appendContentString:@" valign=\""];
+ [_response appendContentString:va];
+ [_response appendContentCharacter:'"'];
+ }
+ [self appendExtraAttributesToResponse:_response inContext:_ctx];
+ [_response appendContentCharacter:'>'];
- if (hasFont)
- WEAppendFont(_response, tC, tF, tS); // <font...>
- [self->template appendToResponse:_response inContext:_ctx];
+ if (hasFont)
+ WEAppendFont(_response, tC, tF, tS); // <font...>
+ [self->template appendToResponse:_response inContext:_ctx];
- [self _appendStringContentToResponse:_response inContext:_ctx];
- if (hasFont)
- [_response appendContentString:@"</font>"]; // </font>
+ [self _appendStringContentToResponse:_response inContext:_ctx];
+ if (hasFont)
+ [_response appendContentString:@"</font>"]; // </font>
- [_response appendContentString:@"</td>"]; // </td>
- }
+ [_response appendContentString:@"</td>"]; // </td>
}
/* responder */
}
}
-- (void)takeValuesFromRequest:(WORequest *)_request
- inContext:(WOContext *)_ctx
-{
- if ([[_ctx objectForKey:WETableView_DataMode] boolValue] ||
+- (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
+ if ([[_ctx objectForKey:WETableView_DataMode] boolValue] ||
[[_ctx objectForKey:WETableView_HeaderMode] boolValue]) {
- [super takeValuesFromRequest:_request inContext:_ctx];
+ [super takeValuesFromRequest:_rq inContext:_ctx];
}
}
/* check formats */
{
int num = 0;
- if (self->formatter) num++;
- if (self->numberformat) num++;
- if (self->dateformat) num++;
+ if (self->formatter != nil) num++;
+ if (self->numberformat != nil) num++;
+ if (self->dateformat != nil) num++;
if (num > 1)
NSLog(@"WARNING: more than one formats specified in element %@", self);
}
}
- (void)dealloc {
- RELEASE(self->formatter);
- RELEASE(self->numberformat);
- RELEASE(self->dateformat);
- RELEASE(self->string);
- RELEASE(self->value);
- RELEASE(self->action);
+ [self->formatter release];
+ [self->numberformat release];
+ [self->dateformat release];
+ [self->string release];
+ [self->value release];
+ [self->action release];
[super dealloc];
}
+/* generate response */
+
+- (NSFormatter *)retainedFormatterInContext:(id)_ctx {
+ NSFormatter *fmt;
+ id s;
+
+ if (self->numberformat != nil) {
+ fmt = [[NSNumberFormatter alloc] init];
+ s = [self->numberformat valueInComponent:[_ctx component]];
+ [(NSNumberFormatter *)fmt setFormat:s];
+ return fmt;
+ }
+
+ if (self->dateformat != nil) {
+ s = [self->dateformat valueInComponent:[_ctx component]];
+ fmt = [[NSDateFormatter alloc] initWithDateFormat:s
+ allowNaturalLanguage:NO];
+ return fmt;
+ }
+
+ if (self->formatter != nil) {
+ fmt = [self->formatter valueInComponent:[_ctx component]];
+#ifdef DEBUG
+ if (fmt && ![fmt respondsToSelector:@selector(stringForObjectValue:)]) {
+ [self logWithFormat:@"invalid formatter determined by keypath %@: %@",
+ self->formatter, fmt];
+ }
+#endif
+ return [fmt retain];
+ }
+
+ return nil;
+}
+
- (void)_appendStringContentToResponse:(WOResponse *)_response
inContext:(WOContext *)_ctx
{
/* add value */
- if (self->value) {
+ if (self->value != nil) {
NSFormatter *fmt = nil;
id obj;
obj = [self->value valueInComponent:cmp];
-
- if (self->numberformat) {
- fmt = AUTORELEASE([[NSNumberFormatter alloc] init]);
- [(NSNumberFormatter *)fmt setFormat:
- [self->numberformat valueInComponent:cmp]];
- }
- else if (self->dateformat) {
- fmt = [[NSDateFormatter alloc]
- initWithDateFormat:
- [self->dateformat valueInComponent:
- cmp]
- allowNaturalLanguage:NO];
- fmt = AUTORELEASE(fmt);
- }
- else if (self->formatter) {
- fmt = [self->formatter valueInComponent:cmp];
-#ifdef DEBUG
- if (fmt && ![fmt respondsToSelector:@selector(stringForObjectValue:)]) {
- [cmp logWithFormat:
- @"invalid formatter determined by keypath %@: %@",
- self->formatter,
- fmt];
- }
-#endif
- }
- if (fmt)
- obj = [fmt stringForObjectValue:obj];
-
- s = [obj stringValue];
+ if ((fmt = [self retainedFormatterInContext:_ctx]) != nil) {
+ s = [fmt stringForObjectValue:obj];
+ [fmt release];
+ }
+ else
+ s = [obj stringValue];
- if (s) [_response appendContentHTMLString:s];
+ if (s != nil) [_response appendContentHTMLString:s];
}
/* add string */
- if (self->string) {
+ if (self->string != nil) {
s = [self->string stringValueInComponent:cmp];
[_response appendContentHTMLString:s];
}
if (hasFont)
[_response appendContentString:@"</font>"]; // </font>
- if (self->action) {
+ if (self->action != nil) {
[_ctx deleteLastElementIDComponent]; // delete 'act'
[_response appendContentString:@"</a>"];
}